Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
anjiemo committed Feb 9, 2024
2 parents ad11787 + a7041a7 commit b6755c7
Show file tree
Hide file tree
Showing 40 changed files with 266 additions and 254 deletions.
18 changes: 9 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ static def generateMD5(final file) {
// api 与 implementation 的区别:https://www.jianshu.com/p/8962d6ba936e
dependencies {
def paging_version = "3.2.0"
def nav_version = "2.6.0"
def nav_version = "2.7.7"
def emoji2_version = "1.0.0-beta01"
def room_version = "2.5.2"
def work_version = "2.8.1"
def room_version = "2.6.1"
def work_version = "2.9.0"
def markwon_version = "4.6.2"
def prism_version = "2.0.0"
def qmui_arch_version = '2.0.1'
Expand All @@ -227,10 +227,10 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.activity:activity-ktx:1.7.2'
implementation 'androidx.fragment:fragment-ktx:1.6.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.activity:activity-ktx:1.8.2'
implementation 'androidx.fragment:fragment-ktx:1.6.2'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.7.0'

// Room 数据库:https://developer.android.com/jetpack/androidx/releases/room
// CodeLab:https://developer.android.com/codelabs/android-room-with-a-view-kotlin#0
Expand Down Expand Up @@ -266,11 +266,11 @@ dependencies {
// 网络请求框架:https://github.com/getActivity/EasyHttp
implementation 'com.github.getActivity:EasyHttp:10.2'
// OkHttp 框架:https://github.com/square/okhttp
compileOnly 'com.squareup.okhttp3:okhttp:4.11.0'
compileOnly 'com.squareup.okhttp3:okhttp:4.12.0'
// Android网络请求库:https://github.com/square/retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.11.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'

// Json 解析框架:https://github.com/google/gson
implementation 'com.google.code.gson:gson:2.10.1'
Expand Down
28 changes: 16 additions & 12 deletions app/src/main/java/cn/cqautotest/sunnybeach/app/AppApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ import cn.cqautotest.sunnybeach.http.model.RequestHandler
import cn.cqautotest.sunnybeach.http.model.RequestServer
import cn.cqautotest.sunnybeach.ktx.resetConfiguration
import cn.cqautotest.sunnybeach.manager.ActivityManager
import cn.cqautotest.sunnybeach.other.*
import cn.cqautotest.sunnybeach.other.AppConfig
import cn.cqautotest.sunnybeach.other.CrashHandler
import cn.cqautotest.sunnybeach.other.DebugLoggerTree
import cn.cqautotest.sunnybeach.other.SmartBallPulseFooter
import cn.cqautotest.sunnybeach.other.TitleBarStyle
import cn.cqautotest.sunnybeach.other.ToastStyle
import cn.cqautotest.sunnybeach.util.PushHelper
import cn.cqautotest.sunnybeach.work.CacheCleanupWorker
import com.bumptech.glide.Glide
Expand Down Expand Up @@ -71,20 +76,21 @@ class AppApplication : Application(), Configuration.Provider {
override fun onLowMemory() {
super.onLowMemory()
// 清理所有图片内存缓存
GlideApp.get(this).onLowMemory()
GlideApp[this].onLowMemory()
}

override fun onTrimMemory(level: Int) {
super.onTrimMemory(level)
// 根据手机内存剩余情况清理图片内存缓存
GlideApp.get(this).onTrimMemory(level)
GlideApp[this].onTrimMemory(level)
}

override fun getWorkManagerConfiguration(): Configuration = Configuration.Builder().also {
if (AppConfig.isDebug()) {
it.setMinimumLoggingLevel(android.util.Log.INFO)
}
}.build()
override val workManagerConfiguration: Configuration
get() = Configuration.Builder().also {
if (AppConfig.isDebug()) {
it.setMinimumLoggingLevel(android.util.Log.INFO)
}
}.build()

override fun getResources(): Resources = super.getResources().apply {
resetConfiguration()
Expand All @@ -94,15 +100,13 @@ class AppApplication : Application(), Configuration.Provider {

private lateinit var mApp: AppApplication
private lateinit var database: CookieRoomDatabase
private const val sWeatherApiToken = "7xoSm4k7GIK8X8E1"
private const val WEATHER_API_TOKEN = "7xoSm4k7GIK8X8E1"

fun getInstance() = mApp

fun getDatabase() = database

fun getWeatherApiToken(): String {
return sWeatherApiToken
}
fun getWeatherApiToken(): String = WEATHER_API_TOKEN

/**
* 初始化一些第三方框架
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import cn.cqautotest.sunnybeach.ktx.startActivity
import cn.cqautotest.sunnybeach.ktx.toJson
import cn.cqautotest.sunnybeach.model.Bookmark
import cn.cqautotest.sunnybeach.model.RefreshStatus
import cn.cqautotest.sunnybeach.other.IntentKey
import cn.cqautotest.sunnybeach.ui.adapter.CollectionDetailListAdapter
import cn.cqautotest.sunnybeach.ui.adapter.delegate.AdapterDelegate
import cn.cqautotest.sunnybeach.viewmodel.CollectionViewModel
Expand Down Expand Up @@ -49,7 +50,7 @@ class CollectionDetailListActivity : PagingActivity() {
}

override suspend fun loadListData() {
mCollectionViewModel.loadCollectionDetailListById(collectionItem.id).collectLatest { mCollectionDetailListAdapter.submitData(it) }
mCollectionViewModel.collectionDetailListFlow.collectLatest { mCollectionDetailListAdapter.submitData(it) }
}

override fun initEvent() {
Expand All @@ -71,6 +72,7 @@ class CollectionDetailListActivity : PagingActivity() {

fun start(context: Context, item: Bookmark.Content) {
context.startActivity<CollectionDetailListActivity> {
putExtra(IntentKey.ID, item.id)
putExtra(COLLECTION_ITEM, item.toJson())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CollectionListActivity : PagingActivity() {

override fun getLayoutId(): Int = R.layout.collection_list_activity

override suspend fun loadListData() = mCollectionViewModel.loadCollectionList().collectLatest { getPagingAdapter().submitData(it) }
override suspend fun loadListData() = mCollectionViewModel.collectionListFlow.collectLatest { getPagingAdapter().submitData(it) }

override fun initView() {
super.initView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,30 @@ import cn.cqautotest.sunnybeach.execption.NotLoginException
import cn.cqautotest.sunnybeach.execption.ServiceException
import cn.cqautotest.sunnybeach.http.network.CourseNetwork
import cn.cqautotest.sunnybeach.http.network.Repository
import cn.cqautotest.sunnybeach.ktx.*
import cn.cqautotest.sunnybeach.ktx.dp
import cn.cqautotest.sunnybeach.ktx.fromJson
import cn.cqautotest.sunnybeach.ktx.getOrNull
import cn.cqautotest.sunnybeach.ktx.isZero
import cn.cqautotest.sunnybeach.ktx.setFixOnClickListener
import cn.cqautotest.sunnybeach.ktx.snapshotList
import cn.cqautotest.sunnybeach.ktx.startActivity
import cn.cqautotest.sunnybeach.ktx.toJson
import cn.cqautotest.sunnybeach.ktx.tryShowLoginDialog
import cn.cqautotest.sunnybeach.manager.UserManager
import cn.cqautotest.sunnybeach.model.course.Course
import cn.cqautotest.sunnybeach.model.course.CourseChapter
import cn.cqautotest.sunnybeach.other.IntentKey
import cn.cqautotest.sunnybeach.ui.adapter.CourseChapterListAdapter
import cn.cqautotest.sunnybeach.ui.adapter.delegate.AdapterDelegate
import cn.cqautotest.sunnybeach.viewmodel.CourseViewModel
import cn.cqautotest.sunnybeach.widget.recyclerview.SimpleLinearSpaceItemDecoration
import com.bumptech.glide.Glide
import com.dylanc.longan.intentExtras
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch
import timber.log.Timber

Expand Down Expand Up @@ -63,8 +75,7 @@ class CourseDetailActivity : PagingActivity() {
}

override suspend fun loadListData() {
val courseId = courseItem.id
mCourseViewModel.getCourseChapterList(courseId).collectLatest { mCourseChapterListAdapter.submitData(it) }
mCourseViewModel.courseChapterListFlow.collectLatest { mCourseChapterListAdapter.submitData(it) }
}

override fun initEvent() {
Expand Down Expand Up @@ -142,6 +153,7 @@ class CourseDetailActivity : PagingActivity() {
@Log
fun start(context: Context, courseItem: Course.CourseItem) {
context.startActivity<CourseDetailActivity> {
putExtra(IntentKey.ID, courseItem.id)
putExtra(COURSE_ITEM, courseItem.toJson())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.*
import android.text.TextUtils
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
Expand All @@ -24,7 +23,13 @@ import cn.cqautotest.sunnybeach.aop.Log
import cn.cqautotest.sunnybeach.app.AppActivity
import cn.cqautotest.sunnybeach.databinding.FishPondDetailActivityBinding
import cn.cqautotest.sunnybeach.databinding.FishPondListItemBinding
import cn.cqautotest.sunnybeach.ktx.*
import cn.cqautotest.sunnybeach.ktx.clearItemAnimator
import cn.cqautotest.sunnybeach.ktx.context
import cn.cqautotest.sunnybeach.ktx.dp
import cn.cqautotest.sunnybeach.ktx.getLocationInWindowPoint
import cn.cqautotest.sunnybeach.ktx.ifNullOrEmpty
import cn.cqautotest.sunnybeach.ktx.setDefaultEmojiParser
import cn.cqautotest.sunnybeach.ktx.setFixOnClickListener
import cn.cqautotest.sunnybeach.manager.UserManager
import cn.cqautotest.sunnybeach.model.Fish
import cn.cqautotest.sunnybeach.model.FishPondComment
Expand All @@ -48,7 +53,7 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import java.text.SimpleDateFormat
import java.util.*
import java.util.Locale
import javax.inject.Inject

/**
Expand Down Expand Up @@ -105,7 +110,7 @@ class FishPondDetailActivity : AppActivity(), StatusAction {
}

private suspend fun loadListData() {
mFishPondViewModel.getFishCommendListById(mMomentId).collectLatest {
mFishPondViewModel.fishCommendListFlow.collectLatest {
mBinding.pagingRecyclerView.scrollToPosition(0)
mFishPondDetailCommendListAdapter.submitData(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ import cn.cqautotest.sunnybeach.R
import cn.cqautotest.sunnybeach.aop.CheckNet
import cn.cqautotest.sunnybeach.app.PagingActivity
import cn.cqautotest.sunnybeach.databinding.FishTopicActivityBinding
import cn.cqautotest.sunnybeach.ktx.*
import cn.cqautotest.sunnybeach.ktx.dp
import cn.cqautotest.sunnybeach.ktx.fromJson
import cn.cqautotest.sunnybeach.ktx.setFixOnClickListener
import cn.cqautotest.sunnybeach.ktx.snapshotList
import cn.cqautotest.sunnybeach.ktx.startActivity
import cn.cqautotest.sunnybeach.ktx.toJson
import cn.cqautotest.sunnybeach.model.Fish
import cn.cqautotest.sunnybeach.model.FishPondTopicList
import cn.cqautotest.sunnybeach.model.RefreshStatus
import cn.cqautotest.sunnybeach.other.IntentKey
import cn.cqautotest.sunnybeach.other.RoundRectDrawable
import cn.cqautotest.sunnybeach.ui.adapter.FishListAdapter
import cn.cqautotest.sunnybeach.ui.adapter.delegate.AdapterDelegate
Expand All @@ -34,7 +40,11 @@ import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
Expand Down Expand Up @@ -85,6 +95,7 @@ class FishTopicActivity : PagingActivity(), RequestListener<Drawable> {
}

override fun initData() {

lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { getFollowedTopicList() } }
lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { loadListData() } }
}
Expand All @@ -106,7 +117,7 @@ class FishTopicActivity : PagingActivity(), RequestListener<Drawable> {
}

override suspend fun loadListData() {
mFishPondViewModel.getFishListByCategoryId(mTopicItem.id).collectLatest {
mFishPondViewModel.fishListFlow.collectLatest {
mFishListAdapter.submitData(it)
}
}
Expand Down Expand Up @@ -205,6 +216,7 @@ class FishTopicActivity : PagingActivity(), RequestListener<Drawable> {

fun start(context: Context, item: FishPondTopicList.TopicItem) {
context.startActivity<FishTopicActivity> {
putExtra(IntentKey.ID, item.id)
putExtra(FISH_TOPIC_ITEM, item.toJson())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import cn.cqautotest.sunnybeach.action.OnDoubleClickListener
import cn.cqautotest.sunnybeach.app.AppActivity
import cn.cqautotest.sunnybeach.app.AppFragment
import cn.cqautotest.sunnybeach.ktx.hideSupportActionBar
import cn.cqautotest.sunnybeach.ktx.tryShowLoginDialog
import cn.cqautotest.sunnybeach.manager.ActivityManager
import cn.cqautotest.sunnybeach.manager.UserManager
import cn.cqautotest.sunnybeach.model.AppUpdateInfo
Expand Down Expand Up @@ -86,6 +87,9 @@ class HomeActivity : AppActivity(), NavigationAdapter.OnNavigationListener, OnDo
setOnNavigationListener(this@HomeActivity)
navigationView?.adapter = this
}
takeUnless { UserManager.isLogin() }?.let {
tryShowLoginDialog()
}
}

private fun NavigationAdapter.addMenuItem(text: String, drawable: Drawable) {
Expand Down Expand Up @@ -165,11 +169,9 @@ class HomeActivity : AppActivity(), NavigationAdapter.OnNavigationListener, OnDo
}

private fun switchFragment(fragmentIndex: Int) {
if (fragmentIndex == -1) {
return
}
takeIf { fragmentIndex == -1 }?.let { return }
when (fragmentIndex) {
0, 1, 2, 3, 4 -> {
in 0..4 -> {
val lastIndex = viewPager2?.currentItem ?: 0
// 是否为相邻的两个 item,只有相邻的两个 item 才执行平滑过渡动画
val isAdjacent = abs(fragmentIndex - lastIndex) == 1
Expand All @@ -189,13 +191,14 @@ class HomeActivity : AppActivity(), NavigationAdapter.OnNavigationListener, OnDo
*/
override fun onNavigationItemSelected(position: Int): Boolean {
return when (position) {
0, 1, 2, 3, 4 -> {
in 0..4 -> {
val lastIndex = viewPager2?.currentItem ?: 0
// 是否为相邻的两个 item,只有相邻的两个 item 才执行平滑过渡动画
val isAdjacent = abs(position - lastIndex) == 1
viewPager2?.setCurrentItem(position, isAdjacent)
true
}

else -> false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import cn.cqautotest.sunnybeach.app.PagingActivity
import cn.cqautotest.sunnybeach.ktx.snapshotList
import cn.cqautotest.sunnybeach.model.RefreshStatus
import cn.cqautotest.sunnybeach.model.UserArticle
import cn.cqautotest.sunnybeach.other.IntentKey
import cn.cqautotest.sunnybeach.ui.adapter.UserArticleAdapter
import cn.cqautotest.sunnybeach.ui.adapter.delegate.AdapterDelegate
import cn.cqautotest.sunnybeach.ui.dialog.ShareDialog
Expand Down Expand Up @@ -34,8 +35,13 @@ class HotArticleListActivity : PagingActivity() {

override fun getLayoutId() = R.layout.hot_article_list_activity

override fun initData() {
intent.putExtra(IntentKey.ID, "1204736502274318336")
super.initData()
}

override suspend fun loadListData() {
mHotArticleViewModel.getUserArticleList("1204736502274318336").collectLatest {
mHotArticleViewModel.userArticleListFlow.collectLatest {
mHotArticleAdapter.submitData(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RichListActivity : PagingActivity() {
override fun getLayoutId(): Int = R.layout.rich_list_activity

override suspend fun loadListData() {
mUserViewModel.getRichList().collectLatest { mRichListAdapter.submitData(it) }
mUserViewModel.richListFlow.collectLatest { mRichListAdapter.submitData(it) }
}

override fun showLoading(id: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ScanCodeActivity : ScanKitActivity(), Init {
val options = HmsScanAnalyzerOptions.Creator()
.setHmsScanTypes(HmsScan.QRCODE_SCAN_TYPE)
.create()
val hmsScans = ScanUtil.decodeWithBitmap(this@ScanCodeActivity, bitmap, options)
val hmsScans = ScanUtil.decodeWithBitmap(this, bitmap, options)
setResultAndFinish(hmsScans)
}
}
Expand Down
Loading

0 comments on commit b6755c7

Please sign in to comment.