From 0217487362a133117f65e4278abda8cd5ffe5e89 Mon Sep 17 00:00:00 2001 From: tornaco Date: Fri, 26 May 2023 14:47:22 +0800 Subject: [PATCH] Add fallbackAppItemLongClickListener --- .../java/github/tornaco/android/thanos/ThanosApp.kt | 11 +++++++++++ .../thanos/common/CommonAppListFilterAdapter.java | 8 ++++++++ .../common/CommonFuncToggleAppListFilterAdapter.java | 9 +++++++++ .../src/main/res/layout/item_common_checkable_app.xml | 4 ++++ 4 files changed, 32 insertions(+) diff --git a/android/app/src/main/java/github/tornaco/android/thanos/ThanosApp.kt b/android/app/src/main/java/github/tornaco/android/thanos/ThanosApp.kt index fe96a8f95..1c8370ca6 100644 --- a/android/app/src/main/java/github/tornaco/android/thanos/ThanosApp.kt +++ b/android/app/src/main/java/github/tornaco/android/thanos/ThanosApp.kt @@ -26,6 +26,9 @@ import dev.enro.core.controller.navigationController import dev.enro.core.plugins.EnroLogger import github.tornaco.android.thanos.app.FeatureAccessStats import github.tornaco.android.thanos.app.Init +import github.tornaco.android.thanos.apps.AppDetailsActivity +import github.tornaco.android.thanos.common.AppItemViewLongClickListener +import github.tornaco.android.thanos.common.CommonAppListFilterAdapter import github.tornaco.android.thanos.core.app.AppGlobals import github.tornaco.thanos.android.noroot.NoRootSupport import github.tornaco.thanos.module.component.manager.initRules @@ -59,11 +62,19 @@ class ThanosApp : MultipleModulesApp(), NavigationApplication { if (BuildProp.THANOS_BUILD_DEBUG) { DeveloperDiag.diag(this) } + Init.init(this) FeatureAccessStats.init(this) initRules(this.applicationContext) NoRootSupport.install() XposedScope.init() + + CommonAppListFilterAdapter.fallbackAppItemLongClickListener = + AppItemViewLongClickListener { _, model -> + model?.appInfo?.let { + AppDetailsActivity.start(this@ThanosApp, it) + } + } } companion object { diff --git a/android/modules/module_common/src/main/java/github/tornaco/android/thanos/common/CommonAppListFilterAdapter.java b/android/modules/module_common/src/main/java/github/tornaco/android/thanos/common/CommonAppListFilterAdapter.java index a942cae39..f53bc86b1 100644 --- a/android/modules/module_common/src/main/java/github/tornaco/android/thanos/common/CommonAppListFilterAdapter.java +++ b/android/modules/module_common/src/main/java/github/tornaco/android/thanos/common/CommonAppListFilterAdapter.java @@ -19,11 +19,14 @@ import github.tornaco.android.thanos.module.common.databinding.ItemCommonAppBinding; import util.Consumer; + public class CommonAppListFilterAdapter extends RecyclerView.Adapter implements Consumer>, FastScrollRecyclerView.SectionedAdapter, FastScrollRecyclerView.MeasurableAdapter { + public static AppItemViewLongClickListener fallbackAppItemLongClickListener; + private final List listModels = new ArrayList<>(); @Nullable @@ -104,6 +107,11 @@ public void onBindViewHolder(@NonNull VH holder, int position) { holder.binding.setLongClickListener(appInfo -> { if (itemViewLongClickListener != null) { itemViewLongClickListener.onAppItemLongClick(holder.itemView, model); + } else { + // Fallback go to app details. + if (fallbackAppItemLongClickListener != null) { + fallbackAppItemLongClickListener.onAppItemLongClick(holder.itemView, model); + } } return true; }); diff --git a/android/modules/module_common/src/main/java/github/tornaco/android/thanos/common/CommonFuncToggleAppListFilterAdapter.java b/android/modules/module_common/src/main/java/github/tornaco/android/thanos/common/CommonFuncToggleAppListFilterAdapter.java index 50d159421..d634b0522 100644 --- a/android/modules/module_common/src/main/java/github/tornaco/android/thanos/common/CommonFuncToggleAppListFilterAdapter.java +++ b/android/modules/module_common/src/main/java/github/tornaco/android/thanos/common/CommonFuncToggleAppListFilterAdapter.java @@ -1,5 +1,7 @@ package github.tornaco.android.thanos.common; +import static github.tornaco.android.thanos.common.CommonAppListFilterAdapter.fallbackAppItemLongClickListener; + import android.view.LayoutInflater; import android.view.ViewGroup; @@ -68,6 +70,13 @@ public void onAppItemSwitchStateChange(AppInfo appInfo, boolean checked) { } } }); + holder.binding.setLongClickListener(appInfo -> { + // Fallback go to app details. + if (fallbackAppItemLongClickListener != null) { + fallbackAppItemLongClickListener.onAppItemLongClick(holder.itemView, model); + } + return true; + }); holder.binding.setBadge1(model.badge); holder.binding.setBadge2(model.badge2); holder.binding.setDescription(model.description); diff --git a/android/modules/module_common/src/main/res/layout/item_common_checkable_app.xml b/android/modules/module_common/src/main/res/layout/item_common_checkable_app.xml index 79441c7ec..dc7706d33 100644 --- a/android/modules/module_common/src/main/res/layout/item_common_checkable_app.xml +++ b/android/modules/module_common/src/main/res/layout/item_common_checkable_app.xml @@ -34,6 +34,9 @@ name="listener" type="github.tornaco.android.thanos.common.AppItemActionListener" /> + @@ -44,6 +47,7 @@ android:background="?selectableItemBackground" android:minHeight="@dimen/list_item_height" android:onClick="@{() -> listener.onAppItemClick(app)}" + android:onLongClick="@{() -> longClickListener.onAppItemLongClick(app)}" android:soundEffectsEnabled="false">