UI : Improve Menus

This commit is contained in:
Mr. Dragon
2019-05-13 00:48:29 +05:30
parent e20372d0f6
commit 8ee95a5ab3
19 changed files with 363 additions and 458 deletions

View File

@@ -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<Download> 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);

View File

@@ -1,172 +0,0 @@
/*
* Aurora Store
* Copyright (C) 2019, Rahul Kumar Patel <whyorean@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*
*/
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<AppMenuAdapter.ViewHolder> {
private AppMenuSheet menuSheet;
private ListType listType;
private Context context;
private List<MenuEntry> 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);
}
}
}

View File

@@ -1,134 +0,0 @@
/*
* Aurora Store
* Copyright (C) 2019, Rahul Kumar Patel <whyorean@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*
*/
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<DownloadMenuAdapter.ViewHolder> {
private Context context;
private Download download;
private List<MenuEntry> 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());
}
}
}
}

View File

@@ -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<DownloadsAdapter.ViewHolder> {
private List<Download> downloadList;
private List<Download> downloadList = new ArrayList<>();
private Context context;
private Fetch fetch;
private DownloadMenuSheet menuSheet;
public DownloadsAdapter(Context context, List<Download> 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<DownloadsAdapter.View
final Download download = downloadList.get(position);
final String displayName = PackageUtil.getDisplayName(context, download.getTag());
final String iconURL = PackageUtil.getIconURL(context, download.getTag());
final Fetch fetch = DownloadManager.getFetchInstance(context);
fetch.addListener(getFetchListener(download.getId(), viewHolder));
GlideApp
@@ -116,11 +124,17 @@ public class DownloadsAdapter extends RecyclerView.Adapter<DownloadsAdapter.View
}
viewHolder.itemView.setOnClickListener(v -> {
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;
});
}

View File

@@ -55,10 +55,12 @@ public class InstalledAppsAdapter extends RecyclerView.Adapter<InstalledAppsAdap
public List<App> 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<InstalledAppsAdap
notifyItemRemoved(position);
}
public void remove(String packageName) {
for (App app : appList) {
if (app.getPackageName().equals(packageName)) {
appList.remove(app);
notifyDataSetChanged();
break;
}
}
}
public void remove(App app) {
appList.remove(app);
notifyDataSetChanged();
}
public void addData(List<App> appList) {
this.appList.clear();
this.appList = appList;
@@ -114,9 +131,8 @@ public class InstalledAppsAdapter extends RecyclerView.Adapter<InstalledAppsAdap
});
holder.itemView.setOnLongClickListener(v -> {
final AppMenuSheet menuSheet = new AppMenuSheet();
menuSheet.setApp(app);
menuSheet.setListType(listType);
menuSheet.setAdapter(this);
menuSheet.show(getFragmentManager(), "BOTTOM_MENU_SHEET");
return false;
});

View File

@@ -57,11 +57,11 @@ public class UpdatableAppsAdapter extends RecyclerView.Adapter<UpdatableAppsAdap
private List<App> 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<UpdatableAppsAdap
notifyItemRemoved(position);
}
public void remove(String packageName) {
for (App app : appList) {
if (app.getPackageName().equals(packageName)) {
appList.remove(app);
notifyDataSetChanged();
break;
}
}
}
public void remove(App app) {
appList.remove(app);
notifyDataSetChanged();
}
public void addData(List<App> appList) {
this.appList.clear();
this.appList = appList;
@@ -119,9 +134,8 @@ public class UpdatableAppsAdapter extends RecyclerView.Adapter<UpdatableAppsAdap
});
viewHolder.itemView.setOnLongClickListener(v -> {
final AppMenuSheet menuSheet = new AppMenuSheet();
menuSheet.setApp(app);
menuSheet.setListType(listType);
menuSheet.setAdapter(this);
menuSheet.show(((AuroraActivity) context).getSupportFragmentManager(),
"BOTTOM_MENU_SHEET");
return false;

View File

@@ -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;
}
}

View File

@@ -7,5 +7,6 @@ public enum Events {
TOKEN_EXPIRED,
NET_CONNECTED,
NET_DISCONNECTED,
PERMANENT_FAIL
PERMANENT_FAIL,
BLACKLIST
}

View File

@@ -123,8 +123,6 @@ public class InstalledFragment extends BaseFragment {
@Override
public void onDestroy() {
super.onDestroy();
disposable.clear();
disposableBus.clear();
installedAppTask = null;
adapter = null;
}

View File

@@ -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;
}

View File

@@ -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;
}
});

View File

@@ -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();
});
}
}

View File

@@ -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() {

View File

@@ -25,10 +25,10 @@
android:viewportHeight="24">
<path
android:fillAlpha="0.3"
android:fillColor="#FF000000"
android:fillColor="?android:attr/colorAccent"
android:pathData="M12,4c-4.41,0 -8,3.59 -8,8s3.59,8 8,8 8,-3.59 8,-8 -3.59,-8 -8,-8zM17,15.59L15.59,17 12,13.41 8.41,17 7,15.59 10.59,12 7,8.41 8.41,7 12,10.59 15.59,7 17,8.41 13.41,12 17,15.59z"
android:strokeAlpha="0.3" />
<path
android:fillColor="#FF000000"
android:fillColor="?android:attr/colorAccent"
android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM15.59,7L12,10.59 8.41,7 7,8.41 10.59,12 7,15.59 8.41,17 12,13.41 15.59,17 17,15.59 13.41,12 17,8.41z" />
</vector>

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Aurora Store
~ Copyright (C) 2019, Rahul Kumar Patel <whyorean@gmail.com>
~
~ 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 <http://www.gnu.org/licenses/>.
~
~
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:targetApi="o">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/menu_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/margin_normal"
android:layout_marginBottom="@dimen/margin_small"
android:ellipsize="end"
android:maxLines="1"
android:paddingHorizontal="@dimen/margin_normal"
android:textAppearance="@style/TextAppearance.Aurora.DialogTitle" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_fav"
style="@style/Widget.Button.Aurora.Menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/details_favourite_add" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_blacklist"
style="@style/Widget.Button.Aurora.Menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_blacklist" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_local_apk"
style="@style/Widget.Button.Aurora.Menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_get_local_apk" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_manual"
style="@style/Widget.Button.Aurora.Menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_manual" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_uninstall"
style="@style/Widget.Button.Aurora.Menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_uninstall" />
</LinearLayout>
</LinearLayout>

View File

@@ -38,12 +38,44 @@
android:paddingHorizontal="@dimen/margin_normal"
android:textAppearance="@style/TextAppearance.Aurora.DialogTitle" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/menu_recycler"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_small"
android:layout_marginBottom="@dimen/margin_small"
android:nestedScrollingEnabled="false"
android:paddingHorizontal="@dimen/margin_small" />
android:orientation="vertical">
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_copy"
style="@style/Widget.Button.Aurora.Menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_copy" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_pause"
style="@style/Widget.Button.Aurora.Menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_pause" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_resume"
style="@style/Widget.Button.Aurora.Menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_resume" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_cancel"
style="@style/Widget.Button.Aurora.Menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_cancel" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_clear"
style="@style/Widget.Button.Aurora.Menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_clear" />
</LinearLayout>
</LinearLayout>

View File

@@ -1,31 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Aurora Store
~ Copyright (C) 2019, Rahul Kumar Patel <whyorean@gmail.com>
~
~ 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 <http://www.gnu.org/licenses/>.
~
~
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_favourite"
android:title="@string/details_favourite_add" />
<item
android:id="@+id/action_blacklist"
android:title="@string/action_blacklist" />
<item
android:id="@+id/action_manual"
android:title="@string/action_manual" />
</menu>

View File

@@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Aurora Store
~ Copyright (C) 2019, Rahul Kumar Patel <whyorean@gmail.com>
~
~ 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 <http://www.gnu.org/licenses/>.
~
~
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_favourite"
android:title="@string/details_favourite_add" />
<item
android:id="@+id/action_blacklist"
android:title="@string/action_blacklist" />
<item
android:id="@+id/action_getLocal"
android:title="@string/action_get_local_apk" />
<item
android:id="@+id/action_manual"
android:title="@string/action_manual" />
<item
android:id="@+id/action_uninstall"
android:title="@string/action_uninstall" />
</menu>

View File

@@ -20,6 +20,18 @@
<resources>
<!--Button Style-->
<style name="Widget.Button.Aurora.Menu" parent="@style/Widget.MaterialComponents.Button.TextButton">
<item name="android:textAppearance">?android:textAppearanceListItem</item>
<item name="android:textAlignment">viewStart</item>
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:paddingStart">@dimen/margin_normal</item>
<item name="android:paddingEnd">@dimen/margin_normal</item>
<item name="iconPadding">@dimen/margin_normal</item>
<item name="cornerRadius">0dp</item>
<item name="rippleColor">@color/colorScrim</item>
</style>
<!-- RatingBar Style -->
<style name="RatingBar" parent="Theme.MaterialComponents">
<item name="colorControlNormal">@color/colorGrey</item>