From 9bbc16940f20bc2b5095cf44180fb00441bed13d Mon Sep 17 00:00:00 2001 From: tornaco Date: Thu, 28 Apr 2022 21:16:52 +0800 Subject: [PATCH] [app] app set item click --- .../thanos/apps/PackageSetEditorActivity.java | 8 +++++--- .../thanos/apps/PackageSetListActivity.java | 15 +++++---------- .../thanos/common/AppItemLongClickListener.java | 7 +++++++ .../thanos/common/CommonAppListFilterAdapter.java | 15 +++++++++++++++ .../src/main/res/layout/item_common_app.xml | 5 +++++ 5 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 android/modules/module_common/src/main/java/github/tornaco/android/thanos/common/AppItemLongClickListener.java diff --git a/android/app/src/main/java/github/tornaco/android/thanos/apps/PackageSetEditorActivity.java b/android/app/src/main/java/github/tornaco/android/thanos/apps/PackageSetEditorActivity.java index e01c5dd3d..8edb573ec 100644 --- a/android/app/src/main/java/github/tornaco/android/thanos/apps/PackageSetEditorActivity.java +++ b/android/app/src/main/java/github/tornaco/android/thanos/apps/PackageSetEditorActivity.java @@ -23,6 +23,7 @@ import java.util.stream.Collectors; import github.tornaco.android.thanos.R; +import github.tornaco.android.thanos.common.AppItemViewLongClickListener; import github.tornaco.android.thanos.common.AppListItemDescriptionComposer; import github.tornaco.android.thanos.common.AppListModel; import github.tornaco.android.thanos.common.CommonAppListFilterActivity; @@ -188,11 +189,12 @@ protected CommonAppListFilterViewModel.ListModelLoader onCreateListModelLoader() @Override protected CommonAppListFilterAdapter onCreateCommonAppListFilterAdapter() { adapter = new CommonAppListFilterAdapter((appInfo, itemView) -> { - if (packageSet == null || packageSet.isPrebuilt()) { - AppDetailsActivity.start(thisActivity(), appInfo); + AppDetailsActivity.start(thisActivity(), appInfo); + }, (itemView, model) -> { + AppInfo appInfo = model.appInfo; + if (packageSet.isPrebuilt()) { return; } - QuickDropdown.show( thisActivity(), itemView, diff --git a/android/app/src/main/java/github/tornaco/android/thanos/apps/PackageSetListActivity.java b/android/app/src/main/java/github/tornaco/android/thanos/apps/PackageSetListActivity.java index 7217d6fd0..04742b279 100644 --- a/android/app/src/main/java/github/tornaco/android/thanos/apps/PackageSetListActivity.java +++ b/android/app/src/main/java/github/tornaco/android/thanos/apps/PackageSetListActivity.java @@ -131,16 +131,14 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten @Override protected CommonAppListFilterAdapter onCreateCommonAppListFilterAdapter() { return new CommonAppListFilterAdapter( - (appInfo, itemView) -> { + (appInfo, itemView) -> PackageSetEditorActivity.start(PackageSetListActivity.this, (String) appInfo.getObj(), REQ_CODE_EDIT), + (view, model) -> { + AppInfo appInfo = model.appInfo; boolean isPrebuilt = appInfo.isSelected(); - if (isPrebuilt) { - PackageSetEditorActivity.start(PackageSetListActivity.this, (String) appInfo.getObj(), REQ_CODE_EDIT); - } else { - QuickDropdown.show(thisActivity(), itemView, index -> { + if (!isPrebuilt) { + QuickDropdown.show(thisActivity(), view, index -> { switch (index) { case 0: - return getString(R.string.title_package_edit_set); - case 1: return getString(R.string.title_package_delete_set); } return null; @@ -148,9 +146,6 @@ protected CommonAppListFilterAdapter onCreateCommonAppListFilterAdapter() { id -> { switch (id) { case 0: - PackageSetEditorActivity.start(PackageSetListActivity.this, (String) appInfo.getObj(), REQ_CODE_EDIT); - break; - case 1: ThanosManager.from(thisActivity()) .getPkgManager() .removePackageSet((String) appInfo.getObj()); diff --git a/android/modules/module_common/src/main/java/github/tornaco/android/thanos/common/AppItemLongClickListener.java b/android/modules/module_common/src/main/java/github/tornaco/android/thanos/common/AppItemLongClickListener.java new file mode 100644 index 000000000..29aff7878 --- /dev/null +++ b/android/modules/module_common/src/main/java/github/tornaco/android/thanos/common/AppItemLongClickListener.java @@ -0,0 +1,7 @@ +package github.tornaco.android.thanos.common; + +import github.tornaco.android.thanos.core.pm.AppInfo; + +public interface AppItemLongClickListener { + boolean onAppItemLongClick(AppInfo appInfo); +} 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 0d46f8dff..a942cae39 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 @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.List; +import github.tornaco.android.thanos.core.pm.AppInfo; import github.tornaco.android.thanos.core.util.function.Predicate; import github.tornaco.android.thanos.module.common.R; import github.tornaco.android.thanos.module.common.databinding.ItemCommonAppBinding; @@ -29,6 +30,8 @@ public class CommonAppListFilterAdapter extends RecyclerView.Adapter { + if (itemViewLongClickListener != null) { + itemViewLongClickListener.onAppItemLongClick(holder.itemView, model); + } + return true; + }); // Badge holder.binding.setBadge1(model.badge); diff --git a/android/modules/module_common/src/main/res/layout/item_common_app.xml b/android/modules/module_common/src/main/res/layout/item_common_app.xml index b0ed540da..a9b31d08d 100644 --- a/android/modules/module_common/src/main/res/layout/item_common_app.xml +++ b/android/modules/module_common/src/main/res/layout/item_common_app.xml @@ -34,6 +34,10 @@ name="listener" type="github.tornaco.android.thanos.common.AppItemClickListener" /> + + @@ -44,6 +48,7 @@ android:background="?selectableItemBackground" android:minHeight="@dimen/list_item_height" android:onClick="@{() -> listener.onAppItemClick(app)}" + android:onLongClick="@{() -> longClickListener.onAppItemLongClick(app)}" android:soundEffectsEnabled="false">