From 8ee95a5ab38ccf452dfc7fd8f2d4e507fa467772 Mon Sep 17 00:00:00 2001 From: "Mr. Dragon" Date: Mon, 13 May 2019 00:48:29 +0530 Subject: [PATCH] UI : Improve Menus --- .../store/activity/DownloadsActivity.java | 6 +- .../aurora/store/adapter/AppMenuAdapter.java | 172 ------------------ .../store/adapter/DownloadMenuAdapter.java | 134 -------------- .../store/adapter/DownloadsAdapter.java | 28 ++- .../store/adapter/InstalledAppsAdapter.java | 20 +- .../store/adapter/UpdatableAppsAdapter.java | 22 ++- .../store/events/AppInstalledEvent.java | 18 ++ .../java/com/aurora/store/events/Events.java | 3 +- .../store/fragment/InstalledFragment.java | 2 - .../store/fragment/UpdatesFragment.java | 2 - .../com/aurora/store/installer/Installer.java | 3 + .../com/aurora/store/sheet/AppMenuSheet.java | 106 +++++++++-- .../aurora/store/sheet/DownloadMenuSheet.java | 97 ++++++---- app/src/main/res/drawable/ic_cancel.xml | 4 +- app/src/main/res/layout/sheet_app_menu.xml | 80 ++++++++ ...sheet_menu.xml => sheet_download_menu.xml} | 44 ++++- app/src/main/res/menu/menu_app_endless.xml | 31 ---- app/src/main/res/menu/menu_app_single.xml | 37 ---- app/src/main/res/values/styles_widget.xml | 12 ++ 19 files changed, 363 insertions(+), 458 deletions(-) delete mode 100644 app/src/main/java/com/aurora/store/adapter/AppMenuAdapter.java delete mode 100644 app/src/main/java/com/aurora/store/adapter/DownloadMenuAdapter.java create mode 100644 app/src/main/java/com/aurora/store/events/AppInstalledEvent.java create mode 100644 app/src/main/res/layout/sheet_app_menu.xml rename app/src/main/res/layout/{sheet_menu.xml => sheet_download_menu.xml} (51%) delete mode 100644 app/src/main/res/menu/menu_app_endless.xml delete mode 100644 app/src/main/res/menu/menu_app_single.xml diff --git a/app/src/main/java/com/aurora/store/activity/DownloadsActivity.java b/app/src/main/java/com/aurora/store/activity/DownloadsActivity.java index 02a87428e..6e8405de6 100644 --- a/app/src/main/java/com/aurora/store/activity/DownloadsActivity.java +++ b/app/src/main/java/com/aurora/store/activity/DownloadsActivity.java @@ -116,7 +116,7 @@ public class DownloadsActivity extends AppCompatActivity { } else { ViewUtil.showWithAnimation(mRecyclerView); ViewUtil.hideWithAnimation(placeholder); - setupRecycler(downloadList); + setupRecycler(); } }); } @@ -178,8 +178,8 @@ public class DownloadsActivity extends AppCompatActivity { } } - private void setupRecycler(List downloadList) { - downloadsAdapter = new DownloadsAdapter(this, downloadList); + private void setupRecycler() { + downloadsAdapter = new DownloadsAdapter(this); mRecyclerView.setAdapter(downloadsAdapter); mRecyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false)); DividerItemDecoration itemDecorator = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL); diff --git a/app/src/main/java/com/aurora/store/adapter/AppMenuAdapter.java b/app/src/main/java/com/aurora/store/adapter/AppMenuAdapter.java deleted file mode 100644 index 4a592943d..000000000 --- a/app/src/main/java/com/aurora/store/adapter/AppMenuAdapter.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Aurora Store - * Copyright (C) 2019, Rahul Kumar Patel - * - * Aurora Store is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * Aurora Store is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Aurora Store. If not, see . - * - * - */ - -package com.aurora.store.adapter; - -import android.content.Context; -import android.content.Intent; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - -import com.aurora.store.ListType; -import com.aurora.store.R; -import com.aurora.store.activity.ManualDownloadActivity; -import com.aurora.store.fragment.DetailsFragment; -import com.aurora.store.installer.Installer; -import com.aurora.store.manager.BlacklistManager; -import com.aurora.store.manager.FavouriteListManager; -import com.aurora.store.model.App; -import com.aurora.store.model.MenuEntry; -import com.aurora.store.sheet.AppMenuSheet; -import com.aurora.store.utility.ApkCopier; -import com.aurora.store.utility.ViewUtil; - -import java.util.List; - -import butterknife.BindView; -import butterknife.ButterKnife; - -public class AppMenuAdapter extends RecyclerView.Adapter { - - private AppMenuSheet menuSheet; - private ListType listType; - private Context context; - private List menuEntryList; - private App app; - - public AppMenuAdapter(AppMenuSheet menuSheet, App app, ListType listType) { - this.menuSheet = menuSheet; - this.context = menuSheet.getContext(); - this.app = app; - this.listType = listType; - switch (listType) { - case INSTALLED: - case UPDATES: - menuEntryList = ViewUtil.parseMenu(context, R.menu.menu_app_single); - break; - case ENDLESS: - menuEntryList = ViewUtil.parseMenu(context, R.menu.menu_app_endless); - break; - } - } - - @NonNull - @Override - public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View itemView = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_sheet_menu, parent, false); - return new ViewHolder(itemView); - } - - @Override - public void onBindViewHolder(@NonNull final ViewHolder holder, int position) { - final MenuEntry menuEntry = menuEntryList.get(position); - holder.menu_title.setText(menuEntry.getTitle()); - attachMenuAction(menuEntry, holder); - } - - private void attachMenuAction(MenuEntry menuEntry, ViewHolder holder) { - View view = holder.itemView; - switch (menuEntry.getResId()) { - case R.id.action_favourite: - FavouriteListManager favouriteListManager = new FavouriteListManager(context); - if (favouriteListManager.contains(app.getPackageName())) { - holder.menu_title.setText(R.string.details_favourite_remove); - view.setOnClickListener(v -> { - favouriteListManager.remove(app.getPackageName()); - menuSheet.dismissAllowingStateLoss(); - }); - } else { - holder.menu_title.setText(R.string.details_favourite_add); - view.setOnClickListener(v -> { - favouriteListManager.add(app.getPackageName()); - menuSheet.dismissAllowingStateLoss(); - }); - } - break; - case R.id.action_uninstall: - view.setOnClickListener(v -> { - new Installer(context).uninstall(app); - menuSheet.dismissAllowingStateLoss(); - }); - break; - case R.id.action_blacklist: - final BlacklistManager blacklistManager = new BlacklistManager(context); - if (blacklistManager.contains(app.getPackageName())) { - holder.menu_title.setText(R.string.action_whitelist); - view.setOnClickListener(v -> { - blacklistManager.remove(app.getPackageName()); - menuSheet.dismissAllowingStateLoss(); - Toast.makeText(context, context.getString(R.string.toast_apk_whitelisted), - Toast.LENGTH_SHORT).show(); - }); - } else { - holder.menu_title.setText(R.string.action_blacklist); - view.setOnClickListener(v -> { - blacklistManager.add(app.getPackageName()); - menuSheet.dismissAllowingStateLoss(); - Toast.makeText(context, context.getString(R.string.toast_apk_blacklisted), - Toast.LENGTH_SHORT).show(); - }); - } - break; - case R.id.action_manual: - view.setOnClickListener(v -> { - DetailsFragment.app = app; - context.startActivity(new Intent(context, ManualDownloadActivity.class)); - menuSheet.dismissAllowingStateLoss(); - }); - break; - case R.id.action_getLocal: - view.setOnClickListener(v -> { - ApkCopier apkCopier = new ApkCopier(); - boolean success = apkCopier.copy(app); - Toast.makeText(context, success - ? context.getString(R.string.toast_apk_copy_success) - : context.getString(R.string.toast_apk_copy_failure), Toast.LENGTH_SHORT) - .show(); - menuSheet.dismissAllowingStateLoss(); - }); - break; - } - } - - @Override - public int getItemCount() { - return menuEntryList.size(); - } - - class ViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.menu_title) - TextView menu_title; - - ViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - } - } -} - diff --git a/app/src/main/java/com/aurora/store/adapter/DownloadMenuAdapter.java b/app/src/main/java/com/aurora/store/adapter/DownloadMenuAdapter.java deleted file mode 100644 index 38cfafa90..000000000 --- a/app/src/main/java/com/aurora/store/adapter/DownloadMenuAdapter.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Aurora Store - * Copyright (C) 2019, Rahul Kumar Patel - * - * Aurora Store is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * Aurora Store is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Aurora Store. If not, see . - * - * - */ - -package com.aurora.store.adapter; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - -import com.aurora.store.R; -import com.aurora.store.model.MenuEntry; -import com.aurora.store.utility.ViewUtil; -import com.tonyodev.fetch2.Download; -import com.tonyodev.fetch2.Status; - -import java.util.List; - -import butterknife.BindView; -import butterknife.ButterKnife; - -public class DownloadMenuAdapter extends RecyclerView.Adapter { - - private Context context; - private Download download; - private List menuEntryList; - private MenuClickListener listener; - - public DownloadMenuAdapter(Context context, Download download, MenuClickListener listener) { - this.context = context; - this.download = download; - this.listener = listener; - menuEntryList = ViewUtil.parseMenu(context, R.menu.menu_download_single); - } - - @NonNull - @Override - public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View itemView = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_sheet_menu_iconed, parent, false); - return new ViewHolder(itemView, listener); - } - - @Override - public void onBindViewHolder(@NonNull final ViewHolder holder, int position) { - final MenuEntry menuEntry = menuEntryList.get(position); - holder.menu_icon.setImageDrawable(menuEntry.getIcon()); - holder.menu_title.setText(menuEntry.getTitle()); - attachMenuAction(menuEntry, holder.itemView); - } - - private void attachMenuAction(MenuEntry menuEntry, View view) { - switch (menuEntry.getResId()) { - case R.id.action_pause: - if (download.getStatus() == Status.PAUSED - || download.getStatus() == Status.COMPLETED - || download.getStatus() == Status.CANCELLED) { - view.setEnabled(false); - view.setAlpha(.5f); - } - break; - case R.id.action_resume: - if (download.getStatus() == Status.DOWNLOADING - || download.getStatus() == Status.COMPLETED - || download.getStatus() == Status.QUEUED) { - view.setEnabled(false); - view.setAlpha(.5f); - } - break; - case R.id.action_cancel: - if (download.getStatus() == Status.COMPLETED - || download.getStatus() == Status.CANCELLED) { - view.setAlpha(.5f); - view.setEnabled(false); - } - break; - } - } - - @Override - public int getItemCount() { - return menuEntryList.size(); - } - - public interface MenuClickListener { - void onMenuClicked(int position); - } - - class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { - @BindView(R.id.menu_icon) - ImageView menu_icon; - @BindView(R.id.menu_title) - TextView menu_title; - - private MenuClickListener listener; - - ViewHolder(@NonNull View itemView, MenuClickListener listener) { - super(itemView); - ButterKnife.bind(this, itemView); - this.listener = listener; - itemView.setOnClickListener(this); - } - - @Override - public void onClick(View v) { - if (listener != null) { - listener.onMenuClicked(getAdapterPosition()); - } - } - } -} - diff --git a/app/src/main/java/com/aurora/store/adapter/DownloadsAdapter.java b/app/src/main/java/com/aurora/store/adapter/DownloadsAdapter.java index 933422e24..36bb9af6a 100644 --- a/app/src/main/java/com/aurora/store/adapter/DownloadsAdapter.java +++ b/app/src/main/java/com/aurora/store/adapter/DownloadsAdapter.java @@ -21,6 +21,7 @@ package com.aurora.store.adapter; import android.content.Context; +import android.content.Intent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -33,6 +34,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.aurora.store.GlideApp; import com.aurora.store.R; +import com.aurora.store.activity.DetailsActivity; import com.aurora.store.activity.DownloadsActivity; import com.aurora.store.download.DownloadManager; import com.aurora.store.sheet.DownloadMenuSheet; @@ -51,6 +53,7 @@ import com.tonyodev.fetch2.Status; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.List; import butterknife.BindView; @@ -58,19 +61,24 @@ import butterknife.ButterKnife; public class DownloadsAdapter extends RecyclerView.Adapter { - private List downloadList; + private List downloadList = new ArrayList<>(); private Context context; private Fetch fetch; + private DownloadMenuSheet menuSheet; - public DownloadsAdapter(Context context, List downloadList) { + public DownloadsAdapter(Context context) { this.context = context; - this.downloadList = downloadList; + this.menuSheet = new DownloadMenuSheet(); fetch = DownloadManager.getFetchInstance(context); + DownloadManager.getFetchInstance(context).getDownloads(fetchDownloadList -> { + this.downloadList = fetchDownloadList; + notifyDataSetChanged(); + }); } public void refreshList() { - fetch.getDownloads(result -> { - downloadList = result; + fetch.getDownloads(fetchDownloadList -> { + downloadList = fetchDownloadList; notifyDataSetChanged(); }); } @@ -88,7 +96,7 @@ public class DownloadsAdapter extends RecyclerView.Adapter { - final DownloadMenuSheet menuSheet = new DownloadMenuSheet(); + Intent intent = new Intent(context, DetailsActivity.class); + intent.putExtra("INTENT_PACKAGE_NAME", download.getTag()); + context.startActivity(intent); + }); + + viewHolder.itemView.setOnLongClickListener(v -> { menuSheet.setTitle(displayName); menuSheet.setDownload(download); menuSheet.setDownloadsAdapter(this); menuSheet.show(((DownloadsActivity) context).getSupportFragmentManager(), "DOWNLOAD_SHEET"); + return false; }); } diff --git a/app/src/main/java/com/aurora/store/adapter/InstalledAppsAdapter.java b/app/src/main/java/com/aurora/store/adapter/InstalledAppsAdapter.java index bbe7e3883..863c5d940 100644 --- a/app/src/main/java/com/aurora/store/adapter/InstalledAppsAdapter.java +++ b/app/src/main/java/com/aurora/store/adapter/InstalledAppsAdapter.java @@ -55,10 +55,12 @@ public class InstalledAppsAdapter extends RecyclerView.Adapter appList = new ArrayList<>(); private Context context; private ListType listType; + private AppMenuSheet menuSheet; public InstalledAppsAdapter(Context context, ListType listType) { this.context = context; this.listType = listType; + this.menuSheet = new AppMenuSheet(); } public void add(int position, App app) { @@ -75,6 +77,21 @@ public class InstalledAppsAdapter extends RecyclerView.Adapter appList) { this.appList.clear(); this.appList = appList; @@ -114,9 +131,8 @@ public class InstalledAppsAdapter extends RecyclerView.Adapter { - final AppMenuSheet menuSheet = new AppMenuSheet(); menuSheet.setApp(app); - menuSheet.setListType(listType); + menuSheet.setAdapter(this); menuSheet.show(getFragmentManager(), "BOTTOM_MENU_SHEET"); return false; }); diff --git a/app/src/main/java/com/aurora/store/adapter/UpdatableAppsAdapter.java b/app/src/main/java/com/aurora/store/adapter/UpdatableAppsAdapter.java index 11c07a998..f19088b7b 100644 --- a/app/src/main/java/com/aurora/store/adapter/UpdatableAppsAdapter.java +++ b/app/src/main/java/com/aurora/store/adapter/UpdatableAppsAdapter.java @@ -57,11 +57,11 @@ public class UpdatableAppsAdapter extends RecyclerView.Adapter appList = new ArrayList<>(); private Context context; - private ListType listType; + private AppMenuSheet menuSheet; public UpdatableAppsAdapter(Context context, ListType listType) { this.context = context; - this.listType = listType; + this.menuSheet = new AppMenuSheet(); } public void add(int position, App app) { @@ -78,6 +78,21 @@ public class UpdatableAppsAdapter extends RecyclerView.Adapter appList) { this.appList.clear(); this.appList = appList; @@ -119,9 +134,8 @@ public class UpdatableAppsAdapter extends RecyclerView.Adapter { - final AppMenuSheet menuSheet = new AppMenuSheet(); menuSheet.setApp(app); - menuSheet.setListType(listType); + menuSheet.setAdapter(this); menuSheet.show(((AuroraActivity) context).getSupportFragmentManager(), "BOTTOM_MENU_SHEET"); return false; diff --git a/app/src/main/java/com/aurora/store/events/AppInstalledEvent.java b/app/src/main/java/com/aurora/store/events/AppInstalledEvent.java new file mode 100644 index 000000000..a526b0583 --- /dev/null +++ b/app/src/main/java/com/aurora/store/events/AppInstalledEvent.java @@ -0,0 +1,18 @@ +package com.aurora.store.events; + +public class AppInstalledEvent { + + private String packageName; + + public AppInstalledEvent(String packageName) { + this.packageName = packageName; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } +} diff --git a/app/src/main/java/com/aurora/store/events/Events.java b/app/src/main/java/com/aurora/store/events/Events.java index dbc2f29c7..272dacab5 100644 --- a/app/src/main/java/com/aurora/store/events/Events.java +++ b/app/src/main/java/com/aurora/store/events/Events.java @@ -7,5 +7,6 @@ public enum Events { TOKEN_EXPIRED, NET_CONNECTED, NET_DISCONNECTED, - PERMANENT_FAIL + PERMANENT_FAIL, + BLACKLIST } diff --git a/app/src/main/java/com/aurora/store/fragment/InstalledFragment.java b/app/src/main/java/com/aurora/store/fragment/InstalledFragment.java index 472d34993..0b2e2f743 100644 --- a/app/src/main/java/com/aurora/store/fragment/InstalledFragment.java +++ b/app/src/main/java/com/aurora/store/fragment/InstalledFragment.java @@ -123,8 +123,6 @@ public class InstalledFragment extends BaseFragment { @Override public void onDestroy() { super.onDestroy(); - disposable.clear(); - disposableBus.clear(); installedAppTask = null; adapter = null; } diff --git a/app/src/main/java/com/aurora/store/fragment/UpdatesFragment.java b/app/src/main/java/com/aurora/store/fragment/UpdatesFragment.java index 290f45d63..eec595df7 100644 --- a/app/src/main/java/com/aurora/store/fragment/UpdatesFragment.java +++ b/app/src/main/java/com/aurora/store/fragment/UpdatesFragment.java @@ -90,7 +90,6 @@ import static com.aurora.store.notification.NotificationBase.INTENT_PACKAGE_NAME public class UpdatesFragment extends BaseFragment { private static final int UPDATE_GROUP_ID = 1337; - @BindView(R.id.swipe_layout) CustomSwipeToRefresh customSwipeToRefresh; @BindView(R.id.recycler) @@ -155,7 +154,6 @@ public class UpdatesFragment extends BaseFragment { @Override public void onDestroy() { super.onDestroy(); - disposable.clear(); updatableAppTask = null; adapter = null; } diff --git a/app/src/main/java/com/aurora/store/installer/Installer.java b/app/src/main/java/com/aurora/store/installer/Installer.java index 421adf105..7d1a6dc82 100644 --- a/app/src/main/java/com/aurora/store/installer/Installer.java +++ b/app/src/main/java/com/aurora/store/installer/Installer.java @@ -36,6 +36,8 @@ import androidx.core.content.FileProvider; import com.aurora.store.Constants; import com.aurora.store.R; import com.aurora.store.activity.DetailsActivity; +import com.aurora.store.events.AppInstalledEvent; +import com.aurora.store.events.RxBus; import com.aurora.store.model.App; import com.aurora.store.notification.QuickNotification; import com.aurora.store.utility.Log; @@ -134,6 +136,7 @@ public class Installer { if (Util.shouldDeleteApk(context)) clearInstallationFiles(apkFiles); unregisterReceiver(installer); + RxBus.publish(new AppInstalledEvent(packageName)); break; } }); diff --git a/app/src/main/java/com/aurora/store/sheet/AppMenuSheet.java b/app/src/main/java/com/aurora/store/sheet/AppMenuSheet.java index e73b63f00..683c22e20 100644 --- a/app/src/main/java/com/aurora/store/sheet/AppMenuSheet.java +++ b/app/src/main/java/com/aurora/store/sheet/AppMenuSheet.java @@ -20,22 +20,32 @@ package com.aurora.store.sheet; +import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import com.aurora.store.ListType; import com.aurora.store.R; -import com.aurora.store.adapter.AppMenuAdapter; +import com.aurora.store.activity.ManualDownloadActivity; +import com.aurora.store.adapter.InstalledAppsAdapter; +import com.aurora.store.adapter.UpdatableAppsAdapter; +import com.aurora.store.fragment.DetailsFragment; +import com.aurora.store.installer.Installer; +import com.aurora.store.manager.BlacklistManager; +import com.aurora.store.manager.FavouriteListManager; import com.aurora.store.model.App; +import com.aurora.store.utility.ApkCopier; +import com.aurora.store.utility.PackageUtil; import com.aurora.store.view.CustomBottomSheetDialogFragment; +import com.google.android.material.button.MaterialButton; import butterknife.BindView; import butterknife.ButterKnife; @@ -44,21 +54,26 @@ public class AppMenuSheet extends CustomBottomSheetDialogFragment { @BindView(R.id.menu_title) TextView txtTitle; - @BindView(R.id.menu_recycler) - RecyclerView recyclerView; + @BindView(R.id.btn_fav) + MaterialButton btnFav; + @BindView(R.id.btn_blacklist) + MaterialButton btnBlacklist; + @BindView(R.id.btn_local_apk) + MaterialButton btnLocal; + @BindView(R.id.btn_manual) + MaterialButton btnManual; + @BindView(R.id.btn_uninstall) + MaterialButton btnUninstall; private App app; - private ListType listType; + private Context context; + private RecyclerView.Adapter adapter; public AppMenuSheet() { } - public ListType getListType() { - return listType; - } - - public void setListType(ListType listType) { - this.listType = listType; + public void setAdapter(RecyclerView.Adapter adapter) { + this.adapter = adapter; } public App getApp() { @@ -69,9 +84,15 @@ public class AppMenuSheet extends CustomBottomSheetDialogFragment { this.app = app; } + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + this.context = context; + } + @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.sheet_menu, container, false); + View view = inflater.inflate(R.layout.sheet_app_menu, container, false); ButterKnife.bind(this, view); return view; } @@ -80,8 +101,61 @@ public class AppMenuSheet extends CustomBottomSheetDialogFragment { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); txtTitle.setText(app.getDisplayName()); - recyclerView.setNestedScrollingEnabled(false); - recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false)); - recyclerView.setAdapter(new AppMenuAdapter(this, getApp(), getListType())); + + btnUninstall.setVisibility(PackageUtil.isInstalled(context, app) ? View.VISIBLE : View.GONE); + btnLocal.setVisibility(PackageUtil.isInstalled(context, app) ? View.VISIBLE : View.GONE); + + final FavouriteListManager favouriteListManager = new FavouriteListManager(context); + boolean isFav = favouriteListManager.contains(app.getPackageName()); + btnFav.setText(isFav ? R.string.details_favourite_remove : R.string.details_favourite_add); + btnFav.setOnClickListener(v -> { + if (isFav) { + favouriteListManager.remove(app.getPackageName()); + } else { + favouriteListManager.add(app.getPackageName()); + } + dismissAllowingStateLoss(); + }); + + final BlacklistManager blacklistManager = new BlacklistManager(context); + boolean isBlacklisted = blacklistManager.contains(app.getPackageName()); + btnBlacklist.setText(isBlacklisted ? R.string.action_whitelist : R.string.action_blacklist); + btnBlacklist.setOnClickListener(v -> { + if (isBlacklisted) { + blacklistManager.remove(app.getPackageName()); + Toast.makeText(context, context.getString(R.string.toast_apk_whitelisted), + Toast.LENGTH_SHORT).show(); + } else { + blacklistManager.add(app.getPackageName()); + Toast.makeText(context, context.getString(R.string.toast_apk_blacklisted), + Toast.LENGTH_SHORT).show(); + if (adapter instanceof InstalledAppsAdapter) + ((InstalledAppsAdapter) adapter).remove(app); + if (adapter instanceof UpdatableAppsAdapter) + ((UpdatableAppsAdapter) adapter).remove(app); + } + dismissAllowingStateLoss(); + }); + + btnLocal.setOnClickListener(v -> { + final ApkCopier apkCopier = new ApkCopier(); + boolean success = apkCopier.copy(app); + Toast.makeText(context, success + ? context.getString(R.string.toast_apk_copy_success) + : context.getString(R.string.toast_apk_copy_failure), Toast.LENGTH_SHORT) + .show(); + dismissAllowingStateLoss(); + }); + + btnManual.setOnClickListener(v -> { + DetailsFragment.app = app; + context.startActivity(new Intent(context, ManualDownloadActivity.class)); + dismissAllowingStateLoss(); + }); + + btnUninstall.setOnClickListener(v -> { + new Installer(context).uninstall(app); + dismissAllowingStateLoss(); + }); } } diff --git a/app/src/main/java/com/aurora/store/sheet/DownloadMenuSheet.java b/app/src/main/java/com/aurora/store/sheet/DownloadMenuSheet.java index 01a1ebd0d..49befb781 100644 --- a/app/src/main/java/com/aurora/store/sheet/DownloadMenuSheet.java +++ b/app/src/main/java/com/aurora/store/sheet/DownloadMenuSheet.java @@ -30,15 +30,13 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import com.aurora.store.R; -import com.aurora.store.adapter.DownloadMenuAdapter; import com.aurora.store.adapter.DownloadsAdapter; import com.aurora.store.download.DownloadManager; import com.aurora.store.utility.Util; import com.aurora.store.view.CustomBottomSheetDialogFragment; +import com.google.android.material.button.MaterialButton; import com.tonyodev.fetch2.Download; import com.tonyodev.fetch2.Fetch; import com.tonyodev.fetch2.Status; @@ -46,12 +44,20 @@ import com.tonyodev.fetch2.Status; import butterknife.BindView; import butterknife.ButterKnife; -public class DownloadMenuSheet extends CustomBottomSheetDialogFragment implements DownloadMenuAdapter.MenuClickListener { +public class DownloadMenuSheet extends CustomBottomSheetDialogFragment { @BindView(R.id.menu_title) TextView downloadTitle; - @BindView(R.id.menu_recycler) - RecyclerView menuRecyclerView; + @BindView(R.id.btn_copy) + MaterialButton btnCopy; + @BindView(R.id.btn_pause) + MaterialButton btnPause; + @BindView(R.id.btn_resume) + MaterialButton btnResume; + @BindView(R.id.btn_cancel) + MaterialButton btnCancel; + @BindView(R.id.btn_clear) + MaterialButton btnClear; private String title; private Context context; @@ -94,7 +100,7 @@ public class DownloadMenuSheet extends CustomBottomSheetDialogFragment implement @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.sheet_menu, container, false); + View view = inflater.inflate(R.layout.sheet_download_menu, container, false); ButterKnife.bind(this, view); return view; } @@ -104,40 +110,53 @@ public class DownloadMenuSheet extends CustomBottomSheetDialogFragment implement super.onViewCreated(view, savedInstanceState); fetch = DownloadManager.getFetchInstance(context); downloadTitle.setText(getTitle()); - menuRecyclerView.setNestedScrollingEnabled(false); - menuRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false)); - menuRecyclerView.setAdapter(new DownloadMenuAdapter(context, download, this)); - } - @Override - public void onMenuClicked(int position) { - switch (position) { - case 0: - Util.copyToClipBoard(context, download.getUrl()); - Toast.makeText(context, context.getString(R.string.action_copied), Toast.LENGTH_LONG).show(); - notifyAndDismiss(); - break; - case 1: - fetch.pause(download.getId()); - notifyAndDismiss(); - break; - case 2: - if (download.getStatus() == Status.FAILED - || download.getStatus() == Status.CANCELLED) - fetch.retry(download.getId()); - else - fetch.resume(download.getId()); - notifyAndDismiss(); - break; - case 3: - fetch.cancel(download.getId()); - notifyAndDismiss(); - break; - case 4: - fetch.delete(download.getId()); - notifyAndDismiss(); - break; + if (download.getStatus() == Status.PAUSED + || download.getStatus() == Status.COMPLETED + || download.getStatus() == Status.CANCELLED) { + btnPause.setVisibility(View.GONE); } + + if (download.getStatus() == Status.DOWNLOADING + || download.getStatus() == Status.COMPLETED + || download.getStatus() == Status.QUEUED) { + btnResume.setVisibility(View.GONE); + } + + if (download.getStatus() == Status.COMPLETED + || download.getStatus() == Status.CANCELLED) { + btnCancel.setVisibility(View.GONE); + } + + btnCopy.setOnClickListener(v -> { + Util.copyToClipBoard(context, download.getUrl()); + Toast.makeText(context, context.getString(R.string.action_copied), Toast.LENGTH_LONG).show(); + notifyAndDismiss(); + }); + + btnPause.setOnClickListener(v -> { + fetch.pause(download.getId()); + notifyAndDismiss(); + }); + + btnResume.setOnClickListener(v -> { + if (download.getStatus() == Status.FAILED + || download.getStatus() == Status.CANCELLED) + fetch.retry(download.getId()); + else + fetch.resume(download.getId()); + notifyAndDismiss(); + }); + + btnCancel.setOnClickListener(v -> { + fetch.cancel(download.getId()); + notifyAndDismiss(); + }); + + btnClear.setOnClickListener(v -> { + fetch.delete(download.getId()); + notifyAndDismiss(); + }); } private void notifyAndDismiss() { diff --git a/app/src/main/res/drawable/ic_cancel.xml b/app/src/main/res/drawable/ic_cancel.xml index 385f0f2ec..5605fc031 100644 --- a/app/src/main/res/drawable/ic_cancel.xml +++ b/app/src/main/res/drawable/ic_cancel.xml @@ -25,10 +25,10 @@ android:viewportHeight="24"> diff --git a/app/src/main/res/layout/sheet_app_menu.xml b/app/src/main/res/layout/sheet_app_menu.xml new file mode 100644 index 000000000..8cbce9a81 --- /dev/null +++ b/app/src/main/res/layout/sheet_app_menu.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/sheet_menu.xml b/app/src/main/res/layout/sheet_download_menu.xml similarity index 51% rename from app/src/main/res/layout/sheet_menu.xml rename to app/src/main/res/layout/sheet_download_menu.xml index 9994c2f38..f5e2b6e1a 100644 --- a/app/src/main/res/layout/sheet_menu.xml +++ b/app/src/main/res/layout/sheet_download_menu.xml @@ -38,12 +38,44 @@ android:paddingHorizontal="@dimen/margin_normal" android:textAppearance="@style/TextAppearance.Aurora.DialogTitle" /> - + android:orientation="vertical"> + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_app_endless.xml b/app/src/main/res/menu/menu_app_endless.xml deleted file mode 100644 index 01e835ead..000000000 --- a/app/src/main/res/menu/menu_app_endless.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/menu_app_single.xml b/app/src/main/res/menu/menu_app_single.xml deleted file mode 100644 index 68ffedf9c..000000000 --- a/app/src/main/res/menu/menu_app_single.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/styles_widget.xml b/app/src/main/res/values/styles_widget.xml index 606cdf635..a8beecb93 100644 --- a/app/src/main/res/values/styles_widget.xml +++ b/app/src/main/res/values/styles_widget.xml @@ -20,6 +20,18 @@ + + +