Some cleaning
This commit is contained in:
parent
555f108853
commit
62467a3fe1
|
@ -18,16 +18,16 @@
|
|||
|
||||
package org.eu.exodus_privacy.exodusprivacy;
|
||||
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.SearchView;
|
||||
|
||||
|
@ -57,7 +57,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
private List<Updatable> fragments;
|
||||
private SearchView searchView;
|
||||
private Menu toolbarMenu;
|
||||
private MenuItem settingsMenuItem;
|
||||
private String packageName;
|
||||
private MainBinding binding;
|
||||
private ApplicationListAdapter.OnAppClickListener onAppClickListener;
|
||||
|
@ -67,7 +66,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.main);
|
||||
final MainBinding mainBinding = binding;
|
||||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().setTitle(R.string.app_title);
|
||||
}
|
||||
fragments = new ArrayList<>();
|
||||
|
||||
NetworkListener networkListener = new NetworkListener() {
|
||||
|
@ -192,12 +193,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
settingsMenuItem = menu.findItem(R.id.action_settings);
|
||||
MenuItem settingsMenuItem = menu.findItem(R.id.action_settings);
|
||||
Updatable fragment = fragments.get(fragments.size() - 1);
|
||||
if (fragment instanceof ReportFragment)
|
||||
settingsMenuItem.setVisible(true);
|
||||
else
|
||||
settingsMenuItem.setVisible(false);
|
||||
settingsMenuItem.setVisible(fragment instanceof ReportFragment);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.eu.exodus_privacy.exodusprivacy;
|
|||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.databinding.BaseObservable;
|
||||
import androidx.databinding.Bindable;
|
||||
|
@ -174,5 +173,4 @@ public class ReportViewModel extends BaseObservable {
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -115,7 +115,10 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
builder.append("<li> ");
|
||||
int beginIndex = line.indexOf(starter)+starter.length();
|
||||
int beginIndex = 0;
|
||||
if (starter != null) {
|
||||
beginIndex = line.indexOf(starter) + starter.length();
|
||||
}
|
||||
line = line.substring(beginIndex);
|
||||
closeTags.add("</li>");
|
||||
} else {
|
||||
|
@ -127,7 +130,7 @@ public class Utils {
|
|||
closeTags.add("</p>");
|
||||
}
|
||||
while (!line.isEmpty()) {
|
||||
Pattern pattern = Pattern.compile("^\\[(.+?)(?=\\]\\()\\]\\((http.+?)(?=\\))\\)");
|
||||
Pattern pattern = Pattern.compile("^\\[(.+?)(?=]\\()]\\((http.+?)(?=\\))\\)");
|
||||
//Pattern pattern = Pattern.compile("^\\[(.*)\\]\\((http.*)\\)");
|
||||
Matcher matcher = pattern.matcher(line);
|
||||
if (matcher.find()) {
|
||||
|
@ -147,7 +150,10 @@ public class Utils {
|
|||
builder.append("\">");
|
||||
builder.append(matcher.group(1));
|
||||
builder.append("</a>");
|
||||
line = line.substring(matcher.group(1).length());
|
||||
String sub = matcher.group(1);
|
||||
if (sub != null) {
|
||||
line = line.substring(sub.length());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
pattern = Pattern.compile("^[*_]{2}(.+)[*_]{2}");
|
||||
|
@ -156,21 +162,19 @@ public class Utils {
|
|||
if (line.startsWith("*")) {
|
||||
line = line.replaceFirst("\\*\\*", "<b>");
|
||||
formatStarter.add("**");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
line = line.replaceFirst("__", "<b>");
|
||||
formatStarter.add("__");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
pattern = Pattern.compile("^[*_]{1}(.+)");
|
||||
pattern = Pattern.compile("^[*_](.+)");
|
||||
matcher = pattern.matcher(line);
|
||||
if (matcher.find()) {
|
||||
if (line.startsWith("*")) {
|
||||
line = line.replaceFirst("\\*", "<i>");
|
||||
formatStarter.add("*");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
line = line.replaceFirst("_", "<i>");
|
||||
formatStarter.add("_");
|
||||
}
|
||||
|
|
|
@ -40,19 +40,12 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ApplicationListAdapter extends RecyclerView.Adapter {
|
||||
public class ApplicationListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private List<ApplicationViewModel> applicationViewModels;
|
||||
private OnAppClickListener onAppClickListener;
|
||||
private Object filter = "";
|
||||
private AppListFragment.Type filterType = AppListFragment.Type.NAME;
|
||||
private final OnAppClickListener onAppClickListener;
|
||||
private final int HIDDEN_APP = 0;
|
||||
private final int DISPLAYED_APP = 1;
|
||||
private int displayedApp = 0;
|
||||
|
||||
private Comparator<ApplicationViewModel> alphaPackageComparator = new Comparator<ApplicationViewModel>() {
|
||||
@Override
|
||||
public int compare(ApplicationViewModel app1, ApplicationViewModel app2) {
|
||||
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)
|
||||
|
@ -61,10 +54,13 @@ public class ApplicationListAdapter extends RecyclerView.Adapter {
|
|||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
private List<ApplicationViewModel> applicationViewModels;
|
||||
private Object filter = "";
|
||||
private AppListFragment.Type filterType = AppListFragment.Type.NAME;
|
||||
private int displayedApp = 0;
|
||||
|
||||
public ApplicationListAdapter(Context context, OnAppClickListener listener) {
|
||||
public ApplicationListAdapter(OnAppClickListener listener) {
|
||||
applicationViewModels = new ArrayList<>();
|
||||
onAppClickListener = listener;
|
||||
}
|
||||
|
@ -97,7 +93,8 @@ public class ApplicationListAdapter extends RecyclerView.Adapter {
|
|||
onAppClickListener.onAppClick(vm);
|
||||
}
|
||||
});
|
||||
}else {
|
||||
} else //noinspection RedundantSuppression
|
||||
{
|
||||
//noinspection unused
|
||||
final ApplicationEmptyViewHolder holder = (ApplicationEmptyViewHolder) viewHolder;
|
||||
//If something should be done for app that are hidden, it's here
|
||||
|
@ -119,6 +116,44 @@ public class ApplicationListAdapter extends RecyclerView.Adapter {
|
|||
return displayedApp;
|
||||
}
|
||||
|
||||
public void filter(AppListFragment.Type type, Object filterObject) {
|
||||
displayedApp = 0;
|
||||
if (type.equals(AppListFragment.Type.NAME)) {
|
||||
filter = filterObject;
|
||||
filterType = type;
|
||||
String filterStr = (String) filterObject;
|
||||
|
||||
Pattern p = Pattern.compile(Pattern.quote(filterStr.trim()), Pattern.CASE_INSENSITIVE);
|
||||
for (ApplicationViewModel app : applicationViewModels) {
|
||||
app.isVisible = p.matcher(app.label).find();
|
||||
if (app.isVisible)
|
||||
displayedApp++;
|
||||
}
|
||||
} else if (type.equals(AppListFragment.Type.TRACKER)) {
|
||||
filter = filterObject;
|
||||
filterType = type;
|
||||
Long filterLng = (Long) filterObject;
|
||||
|
||||
for (ApplicationViewModel app : applicationViewModels) {
|
||||
app.isVisible = false;
|
||||
if (app.trackers != null) {
|
||||
for (Tracker tracker : app.trackers) {
|
||||
if (tracker.id == filterLng) {
|
||||
app.isVisible = true;
|
||||
displayedApp++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public interface OnAppClickListener {
|
||||
void onAppClick(ApplicationViewModel vm);
|
||||
}
|
||||
|
||||
static class ApplicationEmptyViewHolder extends RecyclerView.ViewHolder {
|
||||
ApplicationEmptyViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
@ -192,42 +227,4 @@ public class ApplicationListAdapter extends RecyclerView.Adapter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnAppClickListener {
|
||||
void onAppClick(ApplicationViewModel vm);
|
||||
}
|
||||
|
||||
public void filter(AppListFragment.Type type, Object filterObject) {
|
||||
displayedApp = 0;
|
||||
if (type.equals(AppListFragment.Type.NAME)) {
|
||||
filter = filterObject;
|
||||
filterType = type;
|
||||
String filterStr = (String) filterObject;
|
||||
|
||||
Pattern p = Pattern.compile(Pattern.quote(filterStr.trim()), Pattern.CASE_INSENSITIVE);
|
||||
for (ApplicationViewModel app : applicationViewModels) {
|
||||
app.isVisible = p.matcher(app.label).find();
|
||||
if(app.isVisible)
|
||||
displayedApp++;
|
||||
}
|
||||
} else if(type.equals(AppListFragment.Type.TRACKER)) {
|
||||
filter = filterObject;
|
||||
filterType = type;
|
||||
Long filterLng = (Long) filterObject;
|
||||
|
||||
for (ApplicationViewModel app : applicationViewModels) {
|
||||
app.isVisible = false;
|
||||
if (app.trackers != null) {
|
||||
for (Tracker tracker : app.trackers) {
|
||||
if (tracker.id == filterLng) {
|
||||
app.isVisible = true;
|
||||
displayedApp++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class PermissionListAdapter extends RecyclerView.Adapter<PermissionListAd
|
|||
}
|
||||
|
||||
|
||||
class TrackerListViewHolder extends RecyclerView.ViewHolder {
|
||||
static class TrackerListViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
PermissionItemBinding permissionItemBinding;
|
||||
|
||||
|
@ -64,8 +64,7 @@ public class PermissionListAdapter extends RecyclerView.Adapter<PermissionListAd
|
|||
if (permission.name != null) {
|
||||
permissionItemBinding.permissionShort.setText(permission.name);
|
||||
permissionItemBinding.permissionShort.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else
|
||||
} else
|
||||
permissionItemBinding.permissionShort.setVisibility(View.GONE);
|
||||
|
||||
permissionItemBinding.permissionName.setText(permission.fullName.substring(permission.fullName.lastIndexOf(".") + 1));
|
||||
|
@ -77,15 +76,14 @@ public class PermissionListAdapter extends RecyclerView.Adapter<PermissionListAd
|
|||
else
|
||||
permissionItemBinding.dangerous.setVisibility(View.VISIBLE);
|
||||
manageExpanded(permission);
|
||||
permissionItemBinding.mainLayout.setOnClickListener((View.OnClickListener) v -> {
|
||||
permissionItemBinding.mainLayout.setOnClickListener(v -> {
|
||||
if (permission.description != null && permission.description.trim().length() > 0) {
|
||||
permission.expanded = !permission.expanded;
|
||||
manageExpanded(permission);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
permissionItemBinding.permissionName.setText(R.string.no_permissions);
|
||||
permissionItemBinding.arrow.setText(" ");
|
||||
permissionItemBinding.permissionShort.setVisibility(View.GONE);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.eu.exodus_privacy.exodusprivacy.adapters;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
|
@ -22,9 +21,10 @@ import java.util.Set;
|
|||
|
||||
public class TrackerListAdapter extends RecyclerView.Adapter<TrackerListAdapter.TrackerListViewHolder> {
|
||||
|
||||
private final OnTrackerClickListener trackerClickListener;
|
||||
private final int layout;
|
||||
private final Comparator<Tracker> alphaTrackerComparator = (track1, track2) -> track1.name.compareToIgnoreCase(track2.name);
|
||||
private List<Tracker> trackersList;
|
||||
private OnTrackerClickListener trackerClickListener;
|
||||
private int layout;
|
||||
|
||||
public TrackerListAdapter(Set<Tracker> trackerList, int resource, OnTrackerClickListener listener) {
|
||||
setTrackers(trackerList);
|
||||
|
@ -55,8 +55,6 @@ public class TrackerListAdapter extends RecyclerView.Adapter<TrackerListAdapter.
|
|||
return trackersList.size();
|
||||
}
|
||||
|
||||
private Comparator<Tracker> alphaTrackerComparator = (track1, track2) -> track1.name.compareToIgnoreCase(track2.name);
|
||||
|
||||
public void setTrackers(Set<Tracker> trackers) {
|
||||
if (trackers != null) {
|
||||
trackersList = new ArrayList<>(trackers);
|
||||
|
@ -64,6 +62,10 @@ public class TrackerListAdapter extends RecyclerView.Adapter<TrackerListAdapter.
|
|||
}
|
||||
}
|
||||
|
||||
public interface OnTrackerClickListener {
|
||||
void onTrackerClick(long trackerId);
|
||||
}
|
||||
|
||||
class TrackerListViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
ViewDataBinding viewDataBinding;
|
||||
|
@ -77,20 +79,13 @@ public class TrackerListAdapter extends RecyclerView.Adapter<TrackerListAdapter.
|
|||
if (viewDataBinding instanceof TrackerItemBinding) {
|
||||
TrackerItemBinding binding = (TrackerItemBinding) viewDataBinding;
|
||||
if (tracker != null) {
|
||||
binding.trackerName.setText(tracker.name + " ➤");
|
||||
binding.getRoot().setOnClickListener(v -> {
|
||||
trackerClickListener.onTrackerClick(tracker.id);
|
||||
});
|
||||
}
|
||||
else
|
||||
binding.trackerName.setText(String.format("%s ➤", tracker.name));
|
||||
binding.getRoot().setOnClickListener(v -> trackerClickListener.onTrackerClick(tracker.id));
|
||||
} else
|
||||
binding.trackerName.setText(R.string.no_trackers);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnTrackerClickListener{
|
||||
public void onTrackerClick(long trackerId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public class AppListFragment extends Fragment {
|
|||
//configure list
|
||||
applistBinding.appList.setLayoutManager(new LinearLayoutManager(context));
|
||||
applistBinding.appList.setVerticalScrollBarEnabled(scrollbarEnabled);
|
||||
adapter = new ApplicationListAdapter(context, onAppClickListener);
|
||||
adapter = new ApplicationListAdapter(onAppClickListener);
|
||||
adapter.displayAppList(applications);
|
||||
adapter.filter(filterType, filterObject);
|
||||
applistBinding.appList.setAdapter(adapter);
|
||||
|
|
|
@ -16,16 +16,11 @@ import java.util.Map;
|
|||
|
||||
class ComputeAppListTask extends AsyncTask<Void, Void, List<ApplicationViewModel>> {
|
||||
|
||||
interface Listener {
|
||||
void onAppsComputed(List<ApplicationViewModel> apps);
|
||||
}
|
||||
|
||||
private static final String gStore = "com.android.vending";
|
||||
private static final String fdroid = "ord.fdroid.fdroid";
|
||||
|
||||
private WeakReference<PackageManager> packageManagerRef;
|
||||
private WeakReference<DatabaseManager> databaseManagerRef;
|
||||
private WeakReference<Listener> listenerRef;
|
||||
private final WeakReference<PackageManager> packageManagerRef;
|
||||
private final WeakReference<DatabaseManager> databaseManagerRef;
|
||||
private final WeakReference<Listener> listenerRef;
|
||||
|
||||
ComputeAppListTask(WeakReference<PackageManager> packageManagerRef,
|
||||
WeakReference<DatabaseManager> databaseManagerRef,
|
||||
|
@ -135,4 +130,8 @@ class ComputeAppListTask extends AsyncTask<Void, Void, List<ApplicationViewModel
|
|||
return result;
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
void onAppsComputed(List<ApplicationViewModel> apps);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.eu.exodus_privacy.exodusprivacy.adapters.PermissionListAdapter;
|
|||
import org.eu.exodus_privacy.exodusprivacy.adapters.TrackerListAdapter;
|
||||
import org.eu.exodus_privacy.exodusprivacy.databinding.ReportBinding;
|
||||
import org.eu.exodus_privacy.exodusprivacy.objects.ReportDisplay;
|
||||
|
||||
public class ReportFragment extends Fragment implements Updatable {
|
||||
|
||||
private PackageManager packageManager;
|
||||
|
@ -81,7 +82,7 @@ public class ReportFragment extends Fragment implements Updatable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
reportBinding = DataBindingUtil.inflate(inflater, R.layout.report, container, false);
|
||||
onUpdateComplete();
|
||||
return reportBinding.getRoot();
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
@ -75,7 +76,7 @@ public class TrackerFragment extends Fragment implements ComputeAppListTask.List
|
|||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
trackerBinding = DataBindingUtil.inflate(inflater, R.layout.tracker, container, false);
|
||||
if (applications == null)
|
||||
applications = new ArrayList<>();
|
||||
|
@ -142,7 +143,7 @@ public class TrackerFragment extends Fragment implements ComputeAppListTask.List
|
|||
else
|
||||
trackerBinding.trackerPresenceNb.setBackgroundResource(R.drawable.square_light_blue);
|
||||
|
||||
trackerBinding.trackerPresenceNb.setText(percent+"%");
|
||||
trackerBinding.trackerPresenceNb.setText(String.format("%s%%", percent));
|
||||
Context context = trackerBinding.getRoot().getContext();
|
||||
String presence = context.getResources().getString(R.string.tracker_presence, displayedApps);
|
||||
trackerBinding.trackerPresence.setText(presence);
|
||||
|
|
|
@ -25,6 +25,8 @@ import java.util.EventListener;
|
|||
*/
|
||||
public interface NetworkListener extends EventListener {
|
||||
void onSuccess();
|
||||
|
||||
void onError(String error);
|
||||
|
||||
void onProgress(int resourceId, int progress, int maxProgress);
|
||||
}
|
||||
|
|
|
@ -136,8 +136,7 @@ public class DatabaseManager extends SQLiteOpenHelper {
|
|||
if (!existTracker(db, tracker.id)) {
|
||||
values.put("id", tracker.id);
|
||||
db.insert("trackers", null, values);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
String where = "id = ?";
|
||||
String[] whereArgs = {String.valueOf(tracker.id)};
|
||||
db.update("trackers", values, where, whereArgs);
|
||||
|
@ -188,8 +187,7 @@ public class DatabaseManager extends SQLiteOpenHelper {
|
|||
if (!existReport(db, report.id)) {
|
||||
values.put("id", report.id);
|
||||
db.insert("reports", null, values);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
String where = "id = ?";
|
||||
String[] whereArgs = {String.valueOf(report.id)};
|
||||
db.update("reports", values, where, whereArgs);
|
||||
|
@ -371,8 +369,7 @@ public class DatabaseManager extends SQLiteOpenHelper {
|
|||
String[] whereArgs = {String.valueOf(trackerId)};
|
||||
Cursor cursor = db.query("trackers", null, where, whereArgs, null, null, null, null);
|
||||
Tracker tracker = null;
|
||||
if(cursor.moveToFirst())
|
||||
{
|
||||
if (cursor.moveToFirst()) {
|
||||
tracker = new Tracker();
|
||||
int col = 0;
|
||||
tracker.id = cursor.getLong(col++);
|
||||
|
@ -412,8 +409,7 @@ public class DatabaseManager extends SQLiteOpenHelper {
|
|||
String[] columns = {"sources"};
|
||||
Cursor cursor = getReadableDatabase().query("applications", columns, where, whereArgs, null, null, null, null);
|
||||
String sourcesStr = "";
|
||||
if(cursor.moveToFirst())
|
||||
{
|
||||
if (cursor.moveToFirst()) {
|
||||
sourcesStr = cursor.getString(0);
|
||||
}
|
||||
cursor.close();
|
||||
|
|
|
@ -22,6 +22,12 @@ import android.content.Context;
|
|||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.eu.exodus_privacy.exodusprivacy.R;
|
||||
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
|
||||
import org.eu.exodus_privacy.exodusprivacy.objects.Application;
|
||||
import org.eu.exodus_privacy.exodusprivacy.objects.Report;
|
||||
import org.eu.exodus_privacy.exodusprivacy.objects.Tracker;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
@ -36,9 +42,7 @@ import java.text.DateFormat;
|
|||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -46,17 +50,9 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import org.eu.exodus_privacy.exodusprivacy.R;
|
||||
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
|
||||
import org.eu.exodus_privacy.exodusprivacy.objects.Application;
|
||||
import org.eu.exodus_privacy.exodusprivacy.objects.Report;
|
||||
import org.eu.exodus_privacy.exodusprivacy.objects.Tracker;
|
||||
|
||||
/*
|
||||
Singleton that handle all network connection
|
||||
*/
|
||||
|
@ -84,11 +80,6 @@ public class NetworkManager {
|
|||
addMessageToQueue(mes);
|
||||
}
|
||||
|
||||
private enum Message_Type {
|
||||
GET_REPORTS,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
private void addMessageToQueue(Message mes) {
|
||||
if (thread == null || thread.getState() == Thread.State.TERMINATED || !thread.isRunning)
|
||||
thread = new NetworkProcessingThread();
|
||||
|
@ -97,11 +88,16 @@ public class NetworkManager {
|
|||
thread.start();
|
||||
}
|
||||
|
||||
private enum Message_Type {
|
||||
GET_REPORTS,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
private class NetworkProcessingThread extends Thread {
|
||||
private List<Message> messageQueue;
|
||||
private Semaphore sem;
|
||||
boolean isRunning;
|
||||
private final String apiUrl = "https://reports.exodus-privacy.eu.org/api/";
|
||||
private final List<Message> messageQueue;
|
||||
private final Semaphore sem;
|
||||
boolean isRunning;
|
||||
|
||||
NetworkProcessingThread() {
|
||||
messageQueue = new ArrayList<>();
|
||||
|
@ -164,8 +160,7 @@ public class NetworkManager {
|
|||
String jsonStr = getJSON(inStream);
|
||||
try {
|
||||
object = new JSONObject(jsonStr);
|
||||
} catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -196,9 +191,11 @@ public class NetworkManager {
|
|||
try {
|
||||
JSONObject trackers = object.getJSONObject("trackers");
|
||||
List<Tracker> trackersList = new ArrayList<>();
|
||||
for(int i = 0; i<trackers.names().length(); i++) {
|
||||
mes.listener.onProgress(R.string.parse_trackers,i+1,trackers.names().length());
|
||||
String trackerId = trackers.names().get(i).toString();
|
||||
JSONArray trackerNames = trackers.names();
|
||||
if (trackerNames != null) {
|
||||
for (int i = 0; i < trackerNames.length(); i++) {
|
||||
mes.listener.onProgress(R.string.parse_trackers, i + 1, trackerNames.length());
|
||||
String trackerId = trackerNames.get(i).toString();
|
||||
JSONObject tracker = trackers.getJSONObject(trackerId);
|
||||
Tracker track = parseTracker(tracker, trackerId);
|
||||
trackersList.add(track);
|
||||
|
@ -207,6 +204,7 @@ public class NetworkManager {
|
|||
trackersList.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!trackersList.isEmpty())
|
||||
DatabaseManager.getInstance(mes.context).insertOrUpdateTrackers(trackersList);
|
||||
trackersList.clear();
|
||||
|
@ -229,7 +227,6 @@ public class NetworkManager {
|
|||
mes.listener.onProgress(R.string.get_reports, 0, 0);
|
||||
|
||||
|
||||
|
||||
if (object != null) {
|
||||
Map<String, Map<String, String>> handles = new HashMap<>();
|
||||
ArrayList<String> packages = mes.args.getStringArrayList("packages");
|
||||
|
@ -407,9 +404,7 @@ public class NetworkManager {
|
|||
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
|
||||
if (networkInfo != null) {
|
||||
NetworkInfo.State networkState = networkInfo.getState();
|
||||
if (networkState.equals(NetworkInfo.State.CONNECTED)) {
|
||||
return true;
|
||||
}
|
||||
return networkState.equals(NetworkInfo.State.CONNECTED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.eu.exodus_privacy.exodusprivacy.objects;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class Application {
|
||||
|
|
|
@ -7,7 +7,6 @@ import android.content.pm.PackageManager;
|
|||
import android.content.pm.PermissionGroupInfo;
|
||||
import android.content.pm.PermissionInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
||||
import org.eu.exodus_privacy.exodusprivacy.R;
|
||||
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationViewModel;
|
||||
|
|
|
@ -9,7 +9,7 @@ buildscript {
|
|||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.0.0'
|
||||
classpath 'com.android.tools.build:gradle:4.1.0'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#Tue Jul 07 01:06:44 CEST 2020
|
||||
#Mon Dec 07 08:49:24 CET 2020
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||
|
|
Loading…
Reference in New Issue