Skip to content

Commit

Permalink
Add fallbackAppItemLongClickListener
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed May 26, 2023
1 parent b8e8e8c commit 0217487
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
import github.tornaco.android.thanos.module.common.databinding.ItemCommonAppBinding;
import util.Consumer;


public class CommonAppListFilterAdapter extends RecyclerView.Adapter<CommonAppListFilterAdapter.VH>
implements Consumer<List<AppListModel>>,
FastScrollRecyclerView.SectionedAdapter,
FastScrollRecyclerView.MeasurableAdapter<CommonAppListFilterAdapter.VH> {

public static AppItemViewLongClickListener fallbackAppItemLongClickListener;

private final List<AppListModel> listModels = new ArrayList<>();

@Nullable
Expand Down Expand Up @@ -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;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
name="listener"
type="github.tornaco.android.thanos.common.AppItemActionListener" />

<variable
name="longClickListener"
type="github.tornaco.android.thanos.common.AppItemLongClickListener" />
</data>


Expand All @@ -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">

<github.tornaco.android.thanos.widget.checkable.CheckableImageView
Expand Down

0 comments on commit 0217487

Please sign in to comment.