Skip to content

Commit

Permalink
更新依赖与模版示例
Browse files Browse the repository at this point in the history
  • Loading branch information
jenly1314 committed Jul 23, 2024
1 parent 37c761c commit 1ff5d62
Show file tree
Hide file tree
Showing 57 changed files with 273 additions and 366 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/issues-stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'Close stale issues and PRs'
on:
schedule:
- cron: '0 16 * * *'

jobs:
stale:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v5
with:
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
days-before-stale: 30
days-before-close: 5
exempt-all-pr-milestones: true
exempt-issue-labels: 'help wanted'
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ dependencies {
implementation "com.github.jenly1314:SuperTextView:$versions.superTextView"
implementation "com.github.jenly1314:logx:$versions.logx"

implementation "com.github.CymChad:BaseRecyclerViewAdapterHelper:$versions.brvah"
implementation "io.github.cymchad:BaseRecyclerViewAdapterHelper:$versions.brvah"

implementation "io.github.scwang90:refresh-layout-kernel:$versions.smartRefreshLayout"
implementation "io.github.scwang90:refresh-header-material:$versions.smartRefreshLayout"
Expand All @@ -157,6 +157,8 @@ dependencies {

implementation "com.github.AndroidUtil:AndroidUtil:$versions.androidutil"

implementation "androidx.startup:startup-runtime:$versions.startup"

implementation "com.github.jenly1314:kvcache:$versions.kvcache"

implementation "com.github.jenly1314:imageviewer:$versions.imageviewer"
Expand All @@ -168,7 +170,6 @@ dependencies {
//
// debugImplementation "com.amitshekhar.android:debug-db:$versions.debugDb"

implementation project(":lib-component")
implementation project(":lib-umeng")

}
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
6 changes: 0 additions & 6 deletions app/src/main/java/com/king/template/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.king.frame.mvvmframe.base.BaseApplication
import com.king.kvcache.KVCache
import com.king.logx.LogX
import com.king.template.app.Constants
import com.king.template.component.ComponentAppManager
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.MaterialHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
Expand All @@ -19,8 +18,6 @@ import timber.log.Timber
@HiltAndroidApp
class App : BaseApplication() {

val componentAppManager by lazy { ComponentAppManager() }

init {
SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout ->
layout.setPrimaryColorsId(R.color.colorPrimary, R.color.white)
Expand All @@ -35,8 +32,6 @@ class App : BaseApplication() {
super.onCreate()
initLogger()
KVCache.initialize(this)
// Bugly.init(this, Constants.BUGLY_APP_ID, BuildConfig.DEBUG)
//
// NeverCrash.init { t, e ->
// CrashReport.postCatchedException(e)
// }
Expand All @@ -45,7 +40,6 @@ class App : BaseApplication() {
BaseUrlManager.getInstance().urlInfo = UrlInfo(Constants.BASE_URL)
}
}
componentAppManager.initComponentApp(this)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.king.frame.mvvmframe.data.Repository
import com.king.template.app.base.BaseViewModel
import com.king.template.bean.Login
import com.king.template.data.model.Login
import com.king.template.dict.VerifyCodeScene
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.king.template.R
import com.king.template.bean.BannerImage
import com.king.template.data.model.BannerImage
import com.king.template.glide.ImageLoader
import com.youth.banner.adapter.BannerAdapter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import com.king.template.BR
*/
open class BaseBindingAdapter<T>(layoutResId: Int, data: MutableList<T>? = null) : BaseQuickAdapter<T, BindingViewHolder<*>>(layoutResId, data) {

override fun convert(helper: BindingViewHolder<*>, item: T) {
helper.mBinding?.let {
override fun convert(holder: BindingViewHolder<*>, item: T) {
holder.mBinding?.let {
it.setVariable(BR.data,item)
it.executePendingBindings()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class BindingViewHolder<VDB: ViewDataBinding>(view: View) : BaseViewHolder(view)
var mBinding: VDB? = null

init {
try {
kotlin.runCatching {
mBinding = DataBindingUtil.bind(view)
}catch(e: Exception){

}
}
}
5 changes: 3 additions & 2 deletions app/src/main/java/com/king/template/app/base/BaseViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import com.king.frame.mvvmframe.base.BaseAndroidViewModel
import com.king.frame.mvvmframe.data.Repository
import com.king.kvcache.KVCache
import com.king.template.R
import com.king.template.api.ApiService
import com.king.template.data.remote.service.ApiService
import com.king.template.app.Constants
import com.king.template.bean.Result
import com.king.template.data.model.Result
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import timber.log.Timber
Expand All @@ -26,6 +26,7 @@ open class BaseViewModel @Inject constructor(
application: Application
) : BaseAndroidViewModel(application) {

//TODO 这里只是演示,逻辑复杂一点的,可单独定义Repository,去获取apiService;比如:SearchHistoryRepository
val apiService: ApiService by lazy { repository.getRetrofitService(ApiService::class.java) }

//TODO Token 获取来源
Expand Down
34 changes: 12 additions & 22 deletions app/src/main/java/com/king/template/app/home/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.king.template.app.home
import android.os.Bundle
import android.util.SparseArray
import android.view.View
import androidx.core.util.forEach
import androidx.activity.addCallback
import androidx.core.util.size
import androidx.core.util.valueIterator
import androidx.fragment.app.Fragment
Expand All @@ -28,20 +28,19 @@ class HomeActivity : BaseActivity<HomeViewModel, HomeActivityBinding>() {
SparseArray<Fragment>()
}

var lastTime: Long = 0
private var lastTime: Long = 0

override fun initData(savedInstanceState: Bundle?) {
super.initData(savedInstanceState)

if (savedInstanceState == null) {
showFragment(HomeMenu.MENU1)
} else {
for (index in 0 until fragments.size) {
supportFragmentManager.also {
it.findFragmentByTag(index.toString())?.also { fragment ->
fragments.put(index, fragment)
}
}
showFragment(HomeMenu.MENU1)

onBackPressedDispatcher.addCallback(this) {
if (lastTime < System.currentTimeMillis() - Constants.DOUBLE_CLICK_EXIT_TIME) {
lastTime = System.currentTimeMillis()
showToast(R.string.tips_double_click_exit)
} else {
finish()
}
}
}
Expand All @@ -50,15 +49,6 @@ class HomeActivity : BaseActivity<HomeViewModel, HomeActivityBinding>() {
return R.layout.home_activity
}

override fun onBackPressed() {
if (lastTime < System.currentTimeMillis() - Constants.DOUBLE_CLICK_EXIT_TIME) {
lastTime = System.currentTimeMillis()
showToast(R.string.tips_double_click_exit)
return
}
super.onBackPressed()
}


private fun hideAllFragment(fragmentTransaction: FragmentTransaction) {
fragments.valueIterator().forEach {
Expand All @@ -80,12 +70,12 @@ class HomeActivity : BaseActivity<HomeViewModel, HomeActivityBinding>() {
var fragment: Fragment? = fragments[menu]
if (fragment == null) {
fragment = createFragment(menu)
fragment?.let {
fragment.let {
fragmentTransaction.add(R.id.fragmentContent, it, menu.toString())
fragments.put(menu, it)
}
}
return fragment!!
return fragment
}

/**
Expand Down
7 changes: 2 additions & 5 deletions app/src/main/java/com/king/template/app/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.king.template.app.home

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -14,14 +12,13 @@ import com.king.template.app.Constants
import com.king.template.app.adapter.BannerImageAdapter
import com.king.template.app.adapter.BaseBindingAdapter
import com.king.template.app.base.BaseFragment
import com.king.template.bean.BannerBean
import com.king.template.bean.Bean
import com.king.template.data.model.BannerBean
import com.king.template.data.model.Bean
import com.king.template.databinding.HomeFragmentBinding
import com.youth.banner.Banner
import com.youth.banner.config.IndicatorConfig
import com.youth.banner.indicator.CircleIndicator
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber

/**
* @author <a href="mailto:[email protected]">Jenly</a>
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/com/king/template/app/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.lifecycle.MutableLiveData
import com.king.frame.mvvmframe.data.Repository
import com.king.template.app.Constants
import com.king.template.app.base.BaseViewModel
import com.king.template.bean.BannerBean
import com.king.template.bean.Bean
import com.king.template.data.model.BannerBean
import com.king.template.data.model.Bean
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import javax.inject.Inject
Expand All @@ -27,10 +27,10 @@ class HomeViewModel @Inject constructor(repository: Repository, application: App
launch {
// TODO 模拟请求
val data = arrayOf(
"${Constants.BASE_URL}medias/banner/1.jpg",
"${Constants.BASE_URL}medias/banner/2.jpg",
"${Constants.BASE_URL}medias/banner/3.jpg",
"${Constants.BASE_URL}medias/banner/4.jpg"
"https://jenly.pages.dev/medias/banner/1.jpg",
"https://jenly.pages.dev/medias/banner/2.jpg",
"https://jenly.pages.dev/medias/banner/3.jpg",
"https://jenly.pages.dev/medias/banner/4.jpg"
)
delay(1000)
liveDataBanner.value = data.map { BannerBean(it) }
Expand All @@ -43,7 +43,7 @@ class HomeViewModel @Inject constructor(repository: Repository, application: App
var start = (curPage - 1) * pageSize + 1
var end = (curPage) * pageSize
if (curPage > 1) {
end -= pageSize / 2
end = end.coerceAtMost(30)
}
var data = ArrayList<Bean>()
for (index in start..end) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.king.android.ktx.fragment.argument
import com.king.template.R
import com.king.template.app.base.ListFragment
import com.king.template.bean.ImgMenu
import com.king.template.data.model.ImgMenu
import com.king.template.databinding.MenuListFragmentBinding
import com.king.template.dict.MenuType
import com.scwang.smart.refresh.layout.SmartRefreshLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.king.template.app.home
import android.app.Application
import com.king.frame.mvvmframe.data.Repository
import com.king.template.app.base.ListViewModel
import com.king.template.bean.ImgMenu
import com.king.template.data.model.ImgMenu
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.king.frame.mvvmframe.data.Repository
import com.king.template.app.base.BaseViewModel
import com.king.template.bean.Bean
import com.king.template.data.model.Bean
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/king/template/app/me/MeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.king.frame.mvvmframe.data.Repository
import com.king.template.app.base.BaseViewModel
import com.king.template.bean.Bean
import com.king.template.data.model.Bean
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.king.frame.mvvmframe.data.Repository
import com.king.template.app.base.BaseViewModel
import com.king.template.bean.Bean
import com.king.template.data.model.Bean
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/king/template/data/local/AppDatabase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.king.template.data.local

import androidx.room.Database
import androidx.room.RoomDatabase
import com.king.template.data.local.dao.SearchHistoryDao
import com.king.template.data.model.entity.SearchHistory

/**
* 数据库
*
* @author <a href="mailto:[email protected]">Jenly</a>
* <p>
* <a href="https://github.com/jenly1314">Follow me</a>
*/
@Database(entities = [SearchHistory::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {

/**
* SearchHistoryDao
*/
abstract val searchHistoryDao: SearchHistoryDao
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.king.template.data.local.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.king.template.data.model.entity.SearchHistory
import kotlinx.coroutines.flow.Flow

/**
* 搜索历史
*
* @author <a href="mailto:[email protected]">Jenly</a>
* <p>
* <a href="https://github.com/jenly1314">Follow me</a>
*/
@Dao
interface SearchHistoryDao {
/**
* 插入一条历史数据
* @param searchHistory
*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(searchHistory: SearchHistory)

/**
* 删除所有历史数据
*/
@Query("DELETE FROM SearchHistory")
suspend fun deleteAll()

/**
* 获取历史数据对应的[Flow]
*
* @param count 获取历史记录的条数
*/
@Query("SELECT * FROM SearchHistory ORDER BY timestamp DESC LIMIT :count")
fun getHistoryFlow(count: Int): Flow<List<SearchHistory>?>
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.king.template.bean
package com.king.template.data.model

import com.king.image.imageviewer.ImageDataSource

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.king.template.bean
package com.king.template.data.model

/**
* @author <a href="mailto:[email protected]">Jenly</a>
Expand Down
Loading

0 comments on commit 1ff5d62

Please sign in to comment.