prepare ordering

This commit is contained in:
Thomas 2020-12-07 17:00:45 +01:00
parent acfc183eec
commit 53553940d3
3 changed files with 17 additions and 10 deletions

View File

@ -22,15 +22,15 @@ class ComputeAppListTask extends AsyncTask<Void, Void, List<ApplicationViewModel
private final WeakReference<DatabaseManager> databaseManagerRef; private final WeakReference<DatabaseManager> databaseManagerRef;
private final WeakReference<Listener> listenerRef; private final WeakReference<Listener> listenerRef;
order userOrderChoice; List<order> userOrderChoices;
ComputeAppListTask(WeakReference<PackageManager> packageManagerRef, ComputeAppListTask(WeakReference<PackageManager> packageManagerRef,
WeakReference<DatabaseManager> databaseManagerRef, WeakReference<DatabaseManager> databaseManagerRef,
WeakReference<Listener> listenerRef, order orderCoice) { WeakReference<Listener> listenerRef, List<order> orderChoices) {
this.packageManagerRef = packageManagerRef; this.packageManagerRef = packageManagerRef;
this.databaseManagerRef = databaseManagerRef; this.databaseManagerRef = databaseManagerRef;
this.listenerRef = listenerRef; this.listenerRef = listenerRef;
userOrderChoice = orderCoice; userOrderChoices = orderChoices;
} }
protected List<ApplicationViewModel> doInBackground(Void... params) { protected List<ApplicationViewModel> doInBackground(Void... params) {
@ -44,12 +44,19 @@ class ComputeAppListTask extends AsyncTask<Void, Void, List<ApplicationViewModel
convertPackagesToViewModels(vms, databaseManager, packageManager); convertPackagesToViewModels(vms, databaseManager, packageManager);
} }
//Reordering should done here //Reordering should done here
if (userOrderChoice != order.DEFAULT) { if (userOrderChoices != null) {
vms = order(vms, userOrderChoices);
} }
return vms; return vms;
} }
private List<ApplicationViewModel> order(List<ApplicationViewModel> vms, List<order> orderChoices) {
List<ApplicationViewModel> applicationViewModels = new ArrayList<>();
return applicationViewModels;
}
public enum order { public enum order {
DEFAULT, DEFAULT,
MOST_TRACKERS, MOST_TRACKERS,

View File

@ -77,7 +77,7 @@ public class HomeFragment extends Fragment implements ComputeAppListTask.Listene
onAppsComputed(applications); onAppsComputed(applications);
if (applications.isEmpty()) if (applications.isEmpty())
displayAppListAsync(); displayAppListAsync(null);
if (startRefreshAsked && last_refresh == null) if (startRefreshAsked && last_refresh == null)
startRefresh(); startRefresh();
else if (refreshInProgress) { else if (refreshInProgress) {
@ -127,7 +127,7 @@ public class HomeFragment extends Fragment implements ComputeAppListTask.Listene
refreshInProgress = false; refreshInProgress = false;
homeBinding.layoutProgress.setVisibility(View.GONE); homeBinding.layoutProgress.setVisibility(View.GONE);
homeBinding.swipeRefresh.setRefreshing(false); homeBinding.swipeRefresh.setRefreshing(false);
displayAppListAsync(); displayAppListAsync(null);
} }
public void setNetworkListener(NetworkListener listener) { public void setNetworkListener(NetworkListener listener) {
@ -180,7 +180,7 @@ public class HomeFragment extends Fragment implements ComputeAppListTask.Listene
appListFragment.setFilter(AppListFragment.Type.NAME, filter); appListFragment.setFilter(AppListFragment.Type.NAME, filter);
} }
private void displayAppListAsync() { private void displayAppListAsync(List<ComputeAppListTask.order> orderList) {
homeBinding.noAppFound.setVisibility(View.GONE); homeBinding.noAppFound.setVisibility(View.GONE);
if (applications.isEmpty()) { if (applications.isEmpty()) {
homeBinding.retrieveApp.setVisibility(View.VISIBLE); homeBinding.retrieveApp.setVisibility(View.VISIBLE);
@ -190,7 +190,7 @@ public class HomeFragment extends Fragment implements ComputeAppListTask.Listene
new ComputeAppListTask( new ComputeAppListTask(
new WeakReference<>(packageManager), new WeakReference<>(packageManager),
new WeakReference<>(DatabaseManager.getInstance(getActivity())), new WeakReference<>(DatabaseManager.getInstance(getActivity())),
new WeakReference<>(this), ComputeAppListTask.order.DEFAULT new WeakReference<>(this), orderList
).execute(); ).execute();
} }

View File

@ -115,7 +115,7 @@ public class TrackerFragment extends Fragment implements ComputeAppListTask.List
new ComputeAppListTask( new ComputeAppListTask(
new WeakReference<>(packageManager), new WeakReference<>(packageManager),
new WeakReference<>(DatabaseManager.getInstance(getActivity())), new WeakReference<>(DatabaseManager.getInstance(getActivity())),
new WeakReference<>(this), ComputeAppListTask.order.DEFAULT new WeakReference<>(this), null
).execute(); ).execute();
} }