Skip to content

Commit

Permalink
[app] app set item click
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed Apr 28, 2022
1 parent 8ba53d8 commit 9bbc169
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,26 +131,21 @@ 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;
},
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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,8 @@ public class CommonAppListFilterAdapter extends RecyclerView.Adapter<CommonAppLi
private AppItemClickListener itemClickListener;
@Nullable
private AppItemViewClickListener itemViewClickListener;
@Nullable
private AppItemViewLongClickListener itemViewLongClickListener;

private StateImageProvider stateImageProvider;

Expand All @@ -42,6 +45,12 @@ public CommonAppListFilterAdapter(@Nullable AppItemViewClickListener itemViewCli
this.itemViewClickListener = itemViewClickListener;
}

public CommonAppListFilterAdapter(@Nullable AppItemViewClickListener itemViewClickListener,
@Nullable AppItemViewLongClickListener appItemViewLongClickListener) {
this.itemViewClickListener = itemViewClickListener;
this.itemViewLongClickListener = appItemViewLongClickListener;
}

public CommonAppListFilterAdapter(
@Nullable AppItemClickListener itemClickListener, boolean iconCheckable) {
this.itemClickListener = itemClickListener;
Expand Down Expand Up @@ -92,6 +101,12 @@ public void onBindViewHolder(@NonNull VH holder, int position) {
itemClickListener.onAppItemClick(appInfo);
}
});
holder.binding.setLongClickListener(appInfo -> {
if (itemViewLongClickListener != null) {
itemViewLongClickListener.onAppItemLongClick(holder.itemView, model);
}
return true;
});

// Badge
holder.binding.setBadge1(model.badge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
name="listener"
type="github.tornaco.android.thanos.common.AppItemClickListener" />

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

</data>


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

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

0 comments on commit 9bbc169

Please sign in to comment.