Filter apps
This commit is contained in:
parent
501e0ae9f4
commit
22e1cbb221
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="exodus">9c6106a229bc5f34b5802e5861bcb87d1626617d</string>
|
<string name="exodus">16f8c1a973ecb6622a606daaef35736dc3521e30</string>
|
||||||
<string name="app_title">AMAL</string>
|
<string name="app_title">AMAL</string>
|
||||||
<string name="app_name">AMAL</string>
|
<string name="app_name">AMAL</string>
|
||||||
</resources>
|
</resources>
|
|
@ -28,8 +28,10 @@ import android.provider.Settings;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.PopupMenu;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.SearchView;
|
import androidx.appcompat.widget.SearchView;
|
||||||
|
@ -43,6 +45,7 @@ import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationListAdapter;
|
||||||
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationViewModel;
|
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationViewModel;
|
||||||
import org.eu.exodus_privacy.exodusprivacy.adapters.TrackerListAdapter;
|
import org.eu.exodus_privacy.exodusprivacy.adapters.TrackerListAdapter;
|
||||||
import org.eu.exodus_privacy.exodusprivacy.databinding.MainBinding;
|
import org.eu.exodus_privacy.exodusprivacy.databinding.MainBinding;
|
||||||
|
import org.eu.exodus_privacy.exodusprivacy.fragments.ComputeAppListTask;
|
||||||
import org.eu.exodus_privacy.exodusprivacy.fragments.HomeFragment;
|
import org.eu.exodus_privacy.exodusprivacy.fragments.HomeFragment;
|
||||||
import org.eu.exodus_privacy.exodusprivacy.fragments.ReportFragment;
|
import org.eu.exodus_privacy.exodusprivacy.fragments.ReportFragment;
|
||||||
import org.eu.exodus_privacy.exodusprivacy.fragments.TrackerFragment;
|
import org.eu.exodus_privacy.exodusprivacy.fragments.TrackerFragment;
|
||||||
|
@ -61,6 +64,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
private String packageName;
|
private String packageName;
|
||||||
private MainBinding binding;
|
private MainBinding binding;
|
||||||
private ApplicationListAdapter.OnAppClickListener onAppClickListener;
|
private ApplicationListAdapter.OnAppClickListener onAppClickListener;
|
||||||
|
private static ComputeAppListTask.order order = ComputeAppListTask.order.DEFAULT;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -175,6 +179,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.main, menu);
|
inflater.inflate(R.menu.main, menu);
|
||||||
MenuItem actionFilterItem = menu.findItem(R.id.action_filter);
|
MenuItem actionFilterItem = menu.findItem(R.id.action_filter);
|
||||||
|
|
||||||
searchView = (SearchView) actionFilterItem.getActionView();
|
searchView = (SearchView) actionFilterItem.getActionView();
|
||||||
searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
|
searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
|
||||||
if (hasFocus) {
|
if (hasFocus) {
|
||||||
|
@ -208,13 +213,13 @@ public class MainActivity extends AppCompatActivity {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
MenuItem settingsMenuItem = menu.findItem(R.id.action_settings);
|
MenuItem settingsMenuItem = menu.findItem(R.id.action_settings);
|
||||||
Updatable fragment = fragments.get(fragments.size() - 1);
|
Updatable fragment = fragments.get(fragments.size() - 1);
|
||||||
settingsMenuItem.setVisible(fragment instanceof ReportFragment);
|
settingsMenuItem.setVisible(fragment instanceof ReportFragment);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if (item.getItemId() == R.id.action_settings) {
|
if (item.getItemId() == R.id.action_settings) {
|
||||||
|
@ -227,7 +232,53 @@ public class MainActivity extends AppCompatActivity {
|
||||||
bar.show();
|
bar.show();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
} else if (item.getItemId() == R.id.action_filter_options) {
|
||||||
|
View menuItemView = findViewById(R.id.action_filter_options);
|
||||||
|
PopupMenu popup = new PopupMenu(binding.fragmentContainer.getContext(), menuItemView);
|
||||||
|
popup.getMenuInflater()
|
||||||
|
.inflate(R.menu.popup_menu_filter, popup.getMenu());
|
||||||
|
MenuItem filterByNameMI = popup.getMenu().findItem(R.id.filter_by_name);
|
||||||
|
MenuItem lessTrackersMI = popup.getMenu().findItem(R.id.having_less_trackers);
|
||||||
|
MenuItem mostTrackersMI = popup.getMenu().findItem(R.id.having_most_trackers);
|
||||||
|
MenuItem lessPermissionsMI = popup.getMenu().findItem(R.id.having_less_permissions);
|
||||||
|
MenuItem mostPermissionsMI = popup.getMenu().findItem(R.id.having_most_permissions);
|
||||||
|
switch (order) {
|
||||||
|
case LESS_TRACKERS:
|
||||||
|
lessTrackersMI.setChecked(true);
|
||||||
|
break;
|
||||||
|
case MOST_TRACKERS:
|
||||||
|
mostTrackersMI.setChecked(true);
|
||||||
|
break;
|
||||||
|
case LESS_PERMISSIONS:
|
||||||
|
lessPermissionsMI.setChecked(true);
|
||||||
|
break;
|
||||||
|
case MOST_PERMISSIONS:
|
||||||
|
mostPermissionsMI.setChecked(true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
filterByNameMI.setChecked(true);
|
||||||
|
}
|
||||||
|
popup.setOnMenuItemClickListener(filter_item -> {
|
||||||
|
if (filter_item.getItemId() == R.id.filter_by_name) {
|
||||||
|
order = ComputeAppListTask.order.DEFAULT;
|
||||||
|
} else if (filter_item.getItemId() == R.id.having_less_trackers) {
|
||||||
|
order = ComputeAppListTask.order.LESS_TRACKERS;
|
||||||
|
} else if (filter_item.getItemId() == R.id.having_most_trackers) {
|
||||||
|
order = ComputeAppListTask.order.MOST_TRACKERS;
|
||||||
|
} else if (filter_item.getItemId() == R.id.having_most_permissions) {
|
||||||
|
order = ComputeAppListTask.order.MOST_PERMISSIONS;
|
||||||
|
} else if (filter_item.getItemId() == R.id.having_less_permissions) {
|
||||||
|
order = ComputeAppListTask.order.LESS_PERMISSIONS;
|
||||||
|
}
|
||||||
|
if (fragments != null && fragments.size() > 0 && fragments.get(0) instanceof HomeFragment) {
|
||||||
|
HomeFragment home = (HomeFragment) fragments.get(0);
|
||||||
|
home.displayAppListAsync(order);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
popup.show();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,6 @@ import org.eu.exodus_privacy.exodusprivacy.objects.Report;
|
||||||
import org.eu.exodus_privacy.exodusprivacy.objects.Tracker;
|
import org.eu.exodus_privacy.exodusprivacy.objects.Tracker;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -45,16 +43,6 @@ public class ApplicationListAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
private final OnAppClickListener onAppClickListener;
|
private final OnAppClickListener onAppClickListener;
|
||||||
private final int HIDDEN_APP = 0;
|
private final int HIDDEN_APP = 0;
|
||||||
private final int DISPLAYED_APP = 1;
|
private final int DISPLAYED_APP = 1;
|
||||||
private final Comparator<ApplicationViewModel> alphaPackageComparator = (app1, app2) -> {
|
|
||||||
if (app1.label != null && app2.label != null)
|
|
||||||
return app1.label.toString().compareToIgnoreCase(app2.label.toString());
|
|
||||||
else if (app2.label != null)
|
|
||||||
return -1;
|
|
||||||
else if (app1.label != null)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
private List<ApplicationViewModel> applicationViewModels;
|
private List<ApplicationViewModel> applicationViewModels;
|
||||||
private Object filter = "";
|
private Object filter = "";
|
||||||
private AppListFragment.Type filterType = AppListFragment.Type.NAME;
|
private AppListFragment.Type filterType = AppListFragment.Type.NAME;
|
||||||
|
@ -102,7 +90,6 @@ public class ApplicationListAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
|
|
||||||
public void displayAppList(List<ApplicationViewModel> applications) {
|
public void displayAppList(List<ApplicationViewModel> applications) {
|
||||||
applicationViewModels = applications;
|
applicationViewModels = applications;
|
||||||
Collections.sort(applicationViewModels, alphaPackageComparator);
|
|
||||||
filter(filterType, filter);
|
filter(filterType, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,11 +66,10 @@ public class AppListFragment extends Fragment {
|
||||||
onAppClickListener = listener;
|
onAppClickListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setApplications(List<ApplicationViewModel> applicationList) {
|
public void setApplications(List<ApplicationViewModel> applicationList) {
|
||||||
applications = applicationList;
|
applications = applicationList;
|
||||||
if (adapter != null)
|
if (adapter != null)
|
||||||
|
|
||||||
|
|
||||||
adapter.displayAppList(applications);
|
adapter.displayAppList(applications);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,11 @@ import org.eu.exodus_privacy.exodusprivacy.manager.DatabaseManager;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
class ComputeAppListTask extends AsyncTask<Void, Void, List<ApplicationViewModel>> {
|
public class ComputeAppListTask extends AsyncTask<Void, Void, List<ApplicationViewModel>> {
|
||||||
|
|
||||||
private static final String gStore = "com.android.vending";
|
private static final String gStore = "com.android.vending";
|
||||||
private static final String fdroid = "ord.fdroid.fdroid";
|
private static final String fdroid = "ord.fdroid.fdroid";
|
||||||
|
@ -22,15 +23,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;
|
||||||
|
|
||||||
List<order> userOrderChoices;
|
order userOrderChoice;
|
||||||
|
|
||||||
ComputeAppListTask(WeakReference<PackageManager> packageManagerRef,
|
ComputeAppListTask(WeakReference<PackageManager> packageManagerRef,
|
||||||
WeakReference<DatabaseManager> databaseManagerRef,
|
WeakReference<DatabaseManager> databaseManagerRef,
|
||||||
WeakReference<Listener> listenerRef, List<order> orderChoices) {
|
WeakReference<Listener> listenerRef, order orderChoice) {
|
||||||
this.packageManagerRef = packageManagerRef;
|
this.packageManagerRef = packageManagerRef;
|
||||||
this.databaseManagerRef = databaseManagerRef;
|
this.databaseManagerRef = databaseManagerRef;
|
||||||
this.listenerRef = listenerRef;
|
this.listenerRef = listenerRef;
|
||||||
userOrderChoices = orderChoices;
|
userOrderChoice = orderChoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<ApplicationViewModel> doInBackground(Void... params) {
|
protected List<ApplicationViewModel> doInBackground(Void... params) {
|
||||||
|
@ -44,18 +45,32 @@ 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 (userOrderChoices != null) {
|
if (userOrderChoice == null) {
|
||||||
vms = order(vms, userOrderChoices);
|
userOrderChoice = order.DEFAULT;
|
||||||
|
}
|
||||||
|
vms = order(vms, userOrderChoice);
|
||||||
|
return vms;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ApplicationViewModel> order(List<ApplicationViewModel> vms, order orderChoice) {
|
||||||
|
if (orderChoice == order.LESS_TRACKERS) {
|
||||||
|
Collections.sort(vms, (obj1, obj2) -> Integer.compare(obj1.requestedPermissions != null ? obj1.requestedPermissions.length : 0, obj2.requestedPermissions != null ? obj2.requestedPermissions.length : 0));
|
||||||
|
Collections.sort(vms, (obj1, obj2) -> Integer.compare(obj1.trackers != null ? obj1.trackers.size() : 0, obj2.trackers != null ? obj2.trackers.size() : 0));
|
||||||
|
} else if (orderChoice == order.MOST_TRACKERS) {
|
||||||
|
Collections.sort(vms, (obj1, obj2) -> Integer.compare(obj2.requestedPermissions != null ? obj2.requestedPermissions.length : 0, obj1.requestedPermissions != null ? obj1.requestedPermissions.length : 0));
|
||||||
|
Collections.sort(vms, (obj1, obj2) -> Integer.compare(obj2.trackers != null ? obj2.trackers.size() : 0, obj1.trackers != null ? obj1.trackers.size() : 0));
|
||||||
|
} else if (orderChoice == order.LESS_PERMISSIONS) {
|
||||||
|
Collections.sort(vms, (obj1, obj2) -> Integer.compare(obj1.trackers != null ? obj1.trackers.size() : 0, obj2.trackers != null ? obj2.trackers.size() : 0));
|
||||||
|
Collections.sort(vms, (obj1, obj2) -> Integer.compare(obj1.requestedPermissions != null ? obj1.requestedPermissions.length : 0, obj2.requestedPermissions != null ? obj2.requestedPermissions.length : 0));
|
||||||
|
} else if (orderChoice == order.MOST_PERMISSIONS) {
|
||||||
|
Collections.sort(vms, (obj1, obj2) -> Integer.compare(obj2.trackers != null ? obj2.trackers.size() : 0, obj1.trackers != null ? obj1.trackers.size() : 0));
|
||||||
|
Collections.sort(vms, (obj1, obj2) -> Integer.compare(obj2.requestedPermissions != null ? obj2.requestedPermissions.length : 0, obj1.requestedPermissions != null ? obj1.requestedPermissions.length : 0));
|
||||||
|
} else {
|
||||||
|
Collections.sort(vms, (obj1, obj2) -> String.valueOf(obj1.label).compareToIgnoreCase(String.valueOf(obj2.label)));
|
||||||
}
|
}
|
||||||
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,
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class HomeFragment extends Fragment implements ComputeAppListTask.Listene
|
||||||
appListFragment.setFilter(AppListFragment.Type.NAME, filter);
|
appListFragment.setFilter(AppListFragment.Type.NAME, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayAppListAsync(List<ComputeAppListTask.order> orderList) {
|
public void displayAppListAsync(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);
|
||||||
|
|
|
@ -24,6 +24,7 @@ import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import org.eu.exodus_privacy.exodusprivacy.BuildConfig;
|
||||||
import org.eu.exodus_privacy.exodusprivacy.R;
|
import org.eu.exodus_privacy.exodusprivacy.R;
|
||||||
import org.eu.exodus_privacy.exodusprivacy.Utils;
|
import org.eu.exodus_privacy.exodusprivacy.Utils;
|
||||||
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
|
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
|
||||||
|
@ -99,7 +100,8 @@ public class NetworkManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class NetworkProcessingThread extends Thread {
|
private static class NetworkProcessingThread extends Thread {
|
||||||
private final String apiUrl = "https://reports.exodus-privacy.eu.org/api/";
|
private final String domain = BuildConfig.FLAVOR.compareTo("exodus") == 0 ? "reports.exodus-privacy.eu.org" : "exodus.phm.education.gouv.fr";
|
||||||
|
private final String apiUrl = "https://" + domain + "/api/";
|
||||||
private final List<Message> messageQueue;
|
private final List<Message> messageQueue;
|
||||||
private final Semaphore sem;
|
private final Semaphore sem;
|
||||||
boolean isRunning;
|
boolean isRunning;
|
||||||
|
@ -117,7 +119,7 @@ public class NetworkManager {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
Message mes = null;
|
Message mes;
|
||||||
while (isRunning) {
|
while (isRunning) {
|
||||||
try {
|
try {
|
||||||
sem.acquire();
|
sem.acquire();
|
||||||
|
@ -283,7 +285,6 @@ public class NetworkManager {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
mes.listener.onError(mes.context.getString(R.string.json_error));
|
mes.listener.onError(mes.context.getString(R.string.json_error));
|
||||||
}
|
}
|
||||||
object = null;
|
|
||||||
getReports(mes, handles, packages);
|
getReports(mes, handles, packages);
|
||||||
}
|
}
|
||||||
mes.listener.onSuccess();
|
mes.listener.onSuccess();
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<group
|
||||||
|
android:id="@+id/filter_by_name_grp"
|
||||||
|
android:checkableBehavior="single">
|
||||||
|
<item
|
||||||
|
android:id="@+id/filter_by_name"
|
||||||
|
android:title="@string/filter_by_name" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/having_less_trackers"
|
||||||
|
android:title="@string/having_less_trackers" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/having_most_trackers"
|
||||||
|
android:title="@string/having_most_trackers" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/having_less_permissions"
|
||||||
|
android:title="@string/having_less_permissions" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/having_most_permissions"
|
||||||
|
android:title="@string/having_most_permissions" />
|
||||||
|
</group>
|
||||||
|
</menu>
|
|
@ -53,4 +53,12 @@
|
||||||
<string name="menu_action_filter">Filter</string>
|
<string name="menu_action_filter">Filter</string>
|
||||||
<string name="menu_action_settings">Application Settings</string>
|
<string name="menu_action_settings">Application Settings</string>
|
||||||
|
|
||||||
|
<!-- Filters -->
|
||||||
|
<string name="filter_by_name">Filter by name</string>
|
||||||
|
<string name="having_most_trackers">Having most trackers</string>
|
||||||
|
<string name="having_less_trackers">Having less trackers</string>
|
||||||
|
<string name="having_most_permissions">Having most permissions</string>
|
||||||
|
<string name="having_less_permissions">Having less permissions</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue