Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaobozhen committed Mar 9, 2024
1 parent f7c2973 commit 487dab7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class XposedInfoDialogFragment : BaseBottomSheetViewDialogFragment<XposedInfoBot
XposedInfoBottomSheetView(requireContext())

override fun init() {
root.post {
maxPeekSize = ((dialog?.window?.decorView?.height ?: 0) * 0.67).toInt()
}
val pi = runCatching {
PackageUtils.getPackageInfo(packageName, PackageManager.GET_META_DATA)
}.getOrNull() ?: run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.zhanghai.android.fastscroll.FastScrollerBuilder
Expand All @@ -64,6 +65,7 @@ class AppListFragment :
SearchView.OnQueryTextListener {

private val appAdapter = AppAdapter()
private var updateItemsJob: Job? = null
private var delayShowNavigationJob: Job? = null
private var advancedMenuBSDFragment: AdvancedMenuBSDFragment? = null
private var isFirstLaunch = !Once.beenDone(Once.THIS_APP_INSTALL, OnceTag.FIRST_LAUNCH)
Expand Down Expand Up @@ -369,7 +371,12 @@ class AppListFragment :
}.launchIn(lifecycleScope)
}

private fun updateItems(highlightRefresh: Boolean = false) =
private fun updateItems(highlightRefresh: Boolean = false) {
updateItemsJob?.cancel()
updateItemsJob = updateItemsImpl(highlightRefresh)
}

private fun updateItemsImpl(highlightRefresh: Boolean = false) =
lifecycleScope.launch(Dispatchers.IO) {
Timber.d("updateItems")
var filterList: MutableList<LCItem> = Repositories.lcRepository.getLCItems().toMutableList()
Expand Down Expand Up @@ -422,6 +429,9 @@ class AppListFragment :
filterList.sortByDescending { it.targetApi }
}

if (!isActive) {
return@launch
}
withContext(Dispatchers.Main) {
appAdapter.apply {
setDiffNewData(filterList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.zhanghai.android.fastscroll.FastScrollerBuilder
Expand Down Expand Up @@ -312,38 +313,40 @@ class LibReferenceFragment :

searchUpdateJob?.cancel()
searchUpdateJob = lifecycleScope.launch(Dispatchers.IO) {
homeViewModel.savedRefList?.let { list ->
val filter = list.filter {
it.libName.contains(newText, ignoreCase = true) || it.rule?.label?.contains(
newText,
ignoreCase = true
) ?: false
}
LibReferenceAdapter.highlightText = newText
val savedRefList = homeViewModel.savedRefList ?: return@launch
val filter = savedRefList.filter {
it.libName.contains(newText, ignoreCase = true) || it.rule?.label?.contains(
newText,
ignoreCase = true
) ?: false
}
LibReferenceAdapter.highlightText = newText

withContext(Dispatchers.Main) {
if (isFragmentVisible()) {
(activity as? INavViewContainer)?.showProgressBar()
}
refAdapter.setDiffNewData(filter.toMutableList()) {
doOnMainThreadIdle {
//noinspection NotifyDataSetChanged
refAdapter.notifyDataSetChanged()
}
}
binding.list.post {
(activity as? INavViewContainer)?.hideProgressBar()
if (!isActive) {
return@launch
}
withContext(Dispatchers.Main) {
if (isFragmentVisible()) {
(activity as? INavViewContainer)?.showProgressBar()
}
refAdapter.setDiffNewData(filter.toMutableList()) {
doOnMainThreadIdle {
//noinspection NotifyDataSetChanged
refAdapter.notifyDataSetChanged()
}
}

if (newText.equals("Easter Egg", true)) {
context?.showToast("🥚")
Analytics.trackEvent(
Constants.Event.EASTER_EGG,
EventProperties().set("EASTER_EGG", "Lib Reference Search")
)
binding.list.post {
(activity as? INavViewContainer)?.hideProgressBar()
}
}

if (newText.equals("Easter Egg", true)) {
context?.showToast("🥚")
Analytics.trackEvent(
Constants.Event.EASTER_EGG,
EventProperties().set("EASTER_EGG", "Lib Reference Search")
)
}
}
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.absinthe.libchecker.R
import com.absinthe.libchecker.constant.GlobalValues
import com.absinthe.libchecker.utils.OsUtils
import rikka.material.app.MaterialActivity
import timber.log.Timber

abstract class BaseActivity<VB : ViewBinding> : MaterialActivity(), IBinding<VB> {

Expand All @@ -20,6 +21,16 @@ abstract class BaseActivity<VB : ViewBinding> : MaterialActivity(), IBinding<VB>
}
}

override fun invalidateMenu() {
// It will somehow cause a crash when calling super.invalidateMenu() in some cases
// java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
runCatching {
super.invalidateMenu()
}.onFailure {
Timber.e(it)
}
}

override fun shouldApplyTranslucentSystemBars(): Boolean {
return true
}
Expand Down

0 comments on commit 487dab7

Please sign in to comment.