Use databinding in place of all findViewById

This commit is contained in:
Schoumi 2018-04-11 15:27:05 +02:00
parent 9c619c2135
commit 357500df9a
9 changed files with 360 additions and 363 deletions

View File

@ -21,6 +21,9 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
dataBinding {
enabled = true
}
} }
dependencies { dependencies {
@ -28,9 +31,9 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
}) })
compile 'com.android.support:appcompat-v7:27.0.2' compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:27.0.2' compile 'com.android.support:design:27.1.0'
compile 'com.android.support:recyclerview-v7:27.0.2' compile 'com.android.support:recyclerview-v7:27.1.0'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }

View File

@ -20,11 +20,13 @@ package org.eu.exodus_privacy.exodusprivacy;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
import android.databinding.DataBindingUtil;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationListAdapter; import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationListAdapter;
import org.eu.exodus_privacy.exodusprivacy.databinding.MainBinding;
import org.eu.exodus_privacy.exodusprivacy.fragments.AppListFragment; import org.eu.exodus_privacy.exodusprivacy.fragments.AppListFragment;
import org.eu.exodus_privacy.exodusprivacy.fragments.ReportFragment; import org.eu.exodus_privacy.exodusprivacy.fragments.ReportFragment;
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener; import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
@ -37,7 +39,7 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.main); final MainBinding mainBinding = DataBindingUtil.setContentView(this,R.layout.main);
NetworkListener networkListener = new NetworkListener() { NetworkListener networkListener = new NetworkListener() {
@Override @Override
@ -45,7 +47,7 @@ public class MainActivity extends AppCompatActivity {
runOnUiThread(() -> { runOnUiThread(() -> {
appList.updateComplete(); appList.updateComplete();
if(report != null) if(report != null)
report.updateComplete(null); report.updateComplete();
}); });
} }
@ -54,7 +56,7 @@ public class MainActivity extends AppCompatActivity {
public void onError(String error) { public void onError(String error) {
runOnUiThread(() -> { runOnUiThread(() -> {
appList.updateComplete(); appList.updateComplete();
Snackbar bar = Snackbar.make(findViewById(R.id.fragment_container),error,Snackbar.LENGTH_LONG); Snackbar bar = Snackbar.make(mainBinding.fragmentContainer,error,Snackbar.LENGTH_LONG);
bar.show(); bar.show();
}); });
} }

View File

@ -18,8 +18,10 @@
package org.eu.exodus_privacy.exodusprivacy.adapters; package org.eu.exodus_privacy.exodusprivacy.adapters;
import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -28,6 +30,7 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.eu.exodus_privacy.exodusprivacy.R; import org.eu.exodus_privacy.exodusprivacy.R;
import org.eu.exodus_privacy.exodusprivacy.databinding.AppItemBinding;
import org.eu.exodus_privacy.exodusprivacy.manager.DatabaseManager; import org.eu.exodus_privacy.exodusprivacy.manager.DatabaseManager;
import org.eu.exodus_privacy.exodusprivacy.objects.Report; import org.eu.exodus_privacy.exodusprivacy.objects.Report;
import org.eu.exodus_privacy.exodusprivacy.objects.Tracker; import org.eu.exodus_privacy.exodusprivacy.objects.Tracker;
@ -44,7 +47,7 @@ public class ApplicationListAdapter extends android.support.v7.widget.RecyclerVi
private List<PackageInfo> packages; private List<PackageInfo> packages;
private PackageManager packageManager; private PackageManager packageManager;
private OnAppClickListener onAppClickListener; private OnAppClickListener onAppClickListener;
private final String gStore = "com.android.vending"; private static final String gStore = "com.android.vending";
private Comparator<PackageInfo> alphaPackageComparator = new Comparator<PackageInfo>() { private Comparator<PackageInfo> alphaPackageComparator = new Comparator<PackageInfo>() {
@Override @Override
@ -55,10 +58,9 @@ public class ApplicationListAdapter extends android.support.v7.widget.RecyclerVi
} }
}; };
public ApplicationListAdapter(List<PackageInfo> installedPackages, PackageManager manager, OnAppClickListener listener) { public ApplicationListAdapter(PackageManager manager, OnAppClickListener listener) {
packageManager = manager;
onAppClickListener = listener; onAppClickListener = listener;
setInstalledPackages(installedPackages); setPackageManager(manager);
} }
private void setInstalledPackages(List<PackageInfo> installedPackages) { private void setInstalledPackages(List<PackageInfo> installedPackages) {
@ -80,8 +82,8 @@ public class ApplicationListAdapter extends android.support.v7.widget.RecyclerVi
@Override @Override
public ApplicationListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public ApplicationListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.app_item,parent,false); AppItemBinding appItemBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),R.layout.app_item,parent,false);
return new ApplicationListViewHolder(v); return new ApplicationListViewHolder(appItemBinding);
} }
@Override @Override
@ -102,35 +104,31 @@ public class ApplicationListAdapter extends android.support.v7.widget.RecyclerVi
public void setPackageManager(PackageManager manager) { public void setPackageManager(PackageManager manager) {
packageManager = manager; packageManager = manager;
if(packageManager != null) {
List<PackageInfo> installedPackages = packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
setInstalledPackages(installedPackages);
}
} }
class ApplicationListViewHolder extends RecyclerView.ViewHolder { class ApplicationListViewHolder extends RecyclerView.ViewHolder {
ImageView app_logo;
TextView app_name;
TextView app_permission_nb;
TextView app_tracker_nb;
TextView tested;
TextView analysed;
PackageInfo packageInfo; PackageInfo packageInfo;
AppItemBinding appItemBinding;
ApplicationListViewHolder(View itemView) { ApplicationListViewHolder(AppItemBinding binding) {
super(itemView); super(binding.getRoot());
app_logo = itemView.findViewById(R.id.app_logo); appItemBinding = binding;
app_name = itemView.findViewById(R.id.app_name);
app_permission_nb = itemView.findViewById(R.id.app_permission_nb);
app_tracker_nb = itemView.findViewById(R.id.app_tracker_nb);
tested = itemView.findViewById(R.id.other_version);
analysed = itemView.findViewById(R.id.analysed);
} }
public void setData(PackageInfo data) { public void setData(PackageInfo data) {
packageInfo = data; packageInfo = data;
Context context = appItemBinding.getRoot().getContext();
//reinit view state //reinit view state
tested.setVisibility(View.GONE); appItemBinding.otherVersion.setVisibility(View.GONE);
analysed.setVisibility(View.GONE); appItemBinding.analysed.setVisibility(View.GONE);
app_tracker_nb.setVisibility(View.VISIBLE); appItemBinding.appTrackerNb.setVisibility(View.VISIBLE);
String packageName = packageInfo.packageName; String packageName = packageInfo.packageName;
@ -138,31 +136,31 @@ public class ApplicationListAdapter extends android.support.v7.widget.RecyclerVi
//get logo //get logo
try { try {
app_logo.setImageDrawable(packageManager.getApplicationIcon(packageName)); appItemBinding.appLogo.setImageDrawable(packageManager.getApplicationIcon(packageName));
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
//get name //get name
app_name.setText(packageManager.getApplicationLabel(packageInfo.applicationInfo)); appItemBinding.appName.setText(packageManager.getApplicationLabel(packageInfo.applicationInfo));
//get permissions //get permissions
if(packageInfo.requestedPermissions != null) { if(packageInfo.requestedPermissions != null) {
app_permission_nb.setText(app_name.getContext().getString(R.string.permissions) + " " + String.valueOf(data.requestedPermissions.length)); appItemBinding.appPermissionNb.setText(context.getString(R.string.permissions) + " " + String.valueOf(data.requestedPermissions.length));
} else { } else {
app_permission_nb.setText(app_name.getContext().getString(R.string.permissions) + " " + String.valueOf(0)); appItemBinding.appPermissionNb.setText(context.getString(R.string.permissions) + " " + String.valueOf(0));
} }
//get reports //get reports
Report report = DatabaseManager.getInstance(app_logo.getContext()).getReportFor(packageName, versionName); Report report = DatabaseManager.getInstance(context).getReportFor(packageName, versionName);
if(report != null) { if(report != null) {
Set<Tracker> trackers = DatabaseManager.getInstance(app_logo.getContext()).getTrackers(report.trackers); Set<Tracker> trackers = DatabaseManager.getInstance(context).getTrackers(report.trackers);
app_tracker_nb.setText(app_name.getContext().getString(R.string.trackers) + " " + trackers.size()); appItemBinding.appTrackerNb.setText(context.getString(R.string.trackers) + " " + trackers.size());
if(!report.version.equals(data.versionName)) { if(!report.version.equals(data.versionName)) {
tested.setVisibility(View.VISIBLE); appItemBinding.otherVersion.setVisibility(View.VISIBLE);
} }
} else { } else {
app_tracker_nb.setVisibility(View.GONE); appItemBinding.appTrackerNb.setVisibility(View.GONE);
analysed.setVisibility(View.VISIBLE); appItemBinding.analysed.setVisibility(View.VISIBLE);
} }
} }
} }

View File

@ -23,6 +23,7 @@ import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
@ -37,6 +38,7 @@ import android.widget.TextView;
import org.eu.exodus_privacy.exodusprivacy.R; import org.eu.exodus_privacy.exodusprivacy.R;
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationListAdapter; import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationListAdapter;
import org.eu.exodus_privacy.exodusprivacy.databinding.ApplistBinding;
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener; import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
import org.eu.exodus_privacy.exodusprivacy.manager.NetworkManager; import org.eu.exodus_privacy.exodusprivacy.manager.NetworkManager;
@ -50,6 +52,7 @@ public class AppListFragment extends Fragment {
private NetworkListener networkListener; private NetworkListener networkListener;
private ApplicationListAdapter.OnAppClickListener onAppClickListener; private ApplicationListAdapter.OnAppClickListener onAppClickListener;
private boolean startupRefresh; private boolean startupRefresh;
private ApplistBinding applistBinding;
public static AppListFragment newInstance(NetworkListener networkListener, ApplicationListAdapter.OnAppClickListener appClickListener) { public static AppListFragment newInstance(NetworkListener networkListener, ApplicationListAdapter.OnAppClickListener appClickListener) {
AppListFragment fragment = new AppListFragment(); AppListFragment fragment = new AppListFragment();
@ -66,68 +69,58 @@ public class AppListFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.applist,container,false); applistBinding = DataBindingUtil.inflate(inflater,R.layout.applist,container,false);
return applistBinding.getRoot();
} }
@Override @Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) { public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
View v = getView(); if(applistBinding == null)
if(v == null)
return; return;
RecyclerView app_list = v.findViewById(R.id.app_list); Context context = applistBinding.getRoot().getContext();
SwipeRefreshLayout refresh = v.findViewById(R.id.swipe_refresh); applistBinding.swipeRefresh.setOnRefreshListener(() -> startRefresh());
refresh.setOnRefreshListener(() -> startRefresh(getView()));
if (packageManager == null) if (packageManager == null)
packageManager = v.getContext().getPackageManager(); packageManager = context.getPackageManager();
app_list.setLayoutManager(new LinearLayoutManager(v.getContext())); applistBinding.appList.setLayoutManager(new LinearLayoutManager(context));
TextView nopm = v.findViewById(R.id.no_package_manager);
TextView noappfound = v.findViewById(R.id.no_app_found);
if (packageManager != null) { if (packageManager != null) {
if(startupRefresh) { if(startupRefresh) {
startRefresh(v); startRefresh();
startupRefresh = false; startupRefresh = false;
} }
nopm.setVisibility(View.GONE); applistBinding.noPackageManager.setVisibility(View.GONE);
noappfound.setVisibility(View.GONE); applistBinding.noAppFound.setVisibility(View.GONE);
ApplicationListAdapter adapter = new ApplicationListAdapter(packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS), packageManager, onAppClickListener); ApplicationListAdapter adapter = new ApplicationListAdapter(packageManager, onAppClickListener);
if(adapter.getItemCount() == 0) { if(adapter.getItemCount() == 0) {
noappfound.setVisibility(View.VISIBLE); applistBinding.noAppFound.setVisibility(View.VISIBLE);
} else { } else {
app_list.setAdapter(adapter); applistBinding.appList.setAdapter(adapter);
} }
} else { } else {
nopm.setVisibility(View.VISIBLE); applistBinding.noPackageManager.setVisibility(View.VISIBLE);
} }
} }
public void startRefresh(View v){ public void startRefresh(){
if(v == null) if(applistBinding == null)
return; return;
LinearLayout layout = v.findViewById(R.id.layout_progress); applistBinding.layoutProgress.setVisibility(View.VISIBLE);
layout.setVisibility(View.VISIBLE); applistBinding.swipeRefresh.setRefreshing(true);
SwipeRefreshLayout refresh = v.findViewById(R.id.swipe_refresh);
refresh.setRefreshing(true);
List<PackageInfo> packageInstalled = packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS); List<PackageInfo> packageInstalled = packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
ArrayList<String> packageList = new ArrayList<>(); ArrayList<String> packageList = new ArrayList<>();
for(PackageInfo pkgInfo : packageInstalled) for(PackageInfo pkgInfo : packageInstalled)
packageList.add(pkgInfo.packageName); packageList.add(pkgInfo.packageName);
NetworkManager.getInstance().getReports(v.getContext(),networkListener,packageList); NetworkManager.getInstance().getReports(applistBinding.getRoot().getContext(),networkListener,packageList);
} }
public void updateComplete() { public void updateComplete() {
View v = getView(); if(applistBinding != null) {
if(v != null) { applistBinding.layoutProgress.setVisibility(View.GONE);
LinearLayout layout = v.findViewById(R.id.layout_progress); applistBinding.swipeRefresh.setRefreshing(false);
layout.setVisibility(View.GONE); if(packageManager != null && applistBinding.appList.getAdapter() != null) {
SwipeRefreshLayout refresh = v.findViewById(R.id.swipe_refresh); ((ApplicationListAdapter) applistBinding.appList.getAdapter()).setPackageManager(packageManager);
refresh.setRefreshing(false);
RecyclerView app_list = v.findViewById(R.id.app_list);
if(packageManager != null && app_list.getAdapter() != null) {
((ApplicationListAdapter) app_list.getAdapter()).setPackageManager(packageManager);
app_list.getAdapter().notifyDataSetChanged();
} }
} }
} }
@ -155,17 +148,14 @@ public class AppListFragment extends Fragment {
if(activity == null) if(activity == null)
return; return;
activity.runOnUiThread(() -> { activity.runOnUiThread(() -> {
View v = getView(); if (applistBinding == null)
if (v == null)
return; return;
TextView status = v.findViewById(R.id.status_progress);
if(maxProgress > 0) if(maxProgress > 0)
status.setText(getString(resourceId)+" "+progress+"/"+maxProgress); applistBinding.statusProgress.setText(getString(resourceId)+" "+progress+"/"+maxProgress);
else else
status.setText(getString(resourceId)); applistBinding.statusProgress.setText(getString(resourceId));
ProgressBar progressBar = v.findViewById(R.id.progress); applistBinding.progress.setMax(maxProgress);
progressBar.setMax(maxProgress); applistBinding.progress.setProgress(progress);
progressBar.setProgress(progress);
}); });
} }

View File

@ -23,6 +23,7 @@ import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -32,6 +33,7 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.eu.exodus_privacy.exodusprivacy.R; import org.eu.exodus_privacy.exodusprivacy.R;
import org.eu.exodus_privacy.exodusprivacy.databinding.ReportBinding;
import org.eu.exodus_privacy.exodusprivacy.manager.DatabaseManager; import org.eu.exodus_privacy.exodusprivacy.manager.DatabaseManager;
import org.eu.exodus_privacy.exodusprivacy.objects.Report; import org.eu.exodus_privacy.exodusprivacy.objects.Report;
import org.eu.exodus_privacy.exodusprivacy.objects.Tracker; import org.eu.exodus_privacy.exodusprivacy.objects.Tracker;
@ -45,6 +47,7 @@ public class ReportFragment extends Fragment {
private PackageManager packageManager; private PackageManager packageManager;
private PackageInfo packageInfo; private PackageInfo packageInfo;
private ReportBinding reportBinding;
public static ReportFragment newInstance(PackageManager packageManager, PackageInfo packageInfo) { public static ReportFragment newInstance(PackageManager packageManager, PackageInfo packageInfo) {
ReportFragment fragment = new ReportFragment(); ReportFragment fragment = new ReportFragment();
@ -62,70 +65,57 @@ public class ReportFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.report, container, false); reportBinding = DataBindingUtil.inflate(inflater,R.layout.report,container,false);
updateComplete(v); updateComplete();
return v; return reportBinding.getRoot();
} }
public void updateComplete(View v) { public void updateComplete() {
if(v == null) { Context context = reportBinding.getRoot().getContext();
v = getView();
if (v == null)
return;
}
Context context = v.getContext();
String packageName = packageInfo.packageName; String packageName = packageInfo.packageName;
String versionName = packageInfo.versionName; String versionName = packageInfo.versionName;
//setup logo //setup logo
ImageView app_logo = v.findViewById(R.id.logo);
try { try {
app_logo.setImageDrawable(packageManager.getApplicationIcon(packageName)); reportBinding.logo.setImageDrawable(packageManager.getApplicationIcon(packageName));
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
//setup name //setup name
TextView app_name = v.findViewById(R.id.name); reportBinding.name.setText(packageManager.getApplicationLabel(packageInfo.applicationInfo));
app_name.setText(packageManager.getApplicationLabel(packageInfo.applicationInfo));
//setup permissions number //setup permissions number
TextView permissions_title = v.findViewById(R.id.permissions_title);
String permissions_text; String permissions_text;
if (packageInfo.requestedPermissions != null && packageInfo.requestedPermissions.length > 0) if (packageInfo.requestedPermissions != null && packageInfo.requestedPermissions.length > 0)
permissions_text = context.getString(R.string.permissions) + " " + String.valueOf(packageInfo.requestedPermissions.length); permissions_text = context.getString(R.string.permissions) + " " + String.valueOf(packageInfo.requestedPermissions.length);
else else
permissions_text = context.getString(R.string.permissions); permissions_text = context.getString(R.string.permissions);
permissions_title.setText(permissions_text); reportBinding.permissionsTitle.setText(permissions_text);
//setup permissions list //setup permissions list
WebView permissionList = v.findViewById(R.id.permissions);
//Build html permissions list //Build html permissions list
if (packageInfo.requestedPermissions != null && packageInfo.requestedPermissions.length > 0) { if (packageInfo.requestedPermissions != null && packageInfo.requestedPermissions.length > 0) {
List<String> requestedPermissions = Arrays.asList(packageInfo.requestedPermissions); List<String> requestedPermissions = Arrays.asList(packageInfo.requestedPermissions);
String html = buildHtmlList(requestedPermissions); String html = buildHtmlList(requestedPermissions);
permissionList.loadData(html,"text/html","UTF-8"); reportBinding.permissions.loadData(html,"text/html","UTF-8");
} else { } else {
permissionList.loadData(getString(R.string.no_permissions),"text/plain", "UTF-8"); reportBinding.permissions.loadData(getString(R.string.no_permissions),"text/plain", "UTF-8");
} }
TextView analysed = v.findViewById(R.id.analysed); reportBinding.analysed.setVisibility(View.GONE);
TextView trackers_title = v.findViewById(R.id.trackers_title); reportBinding.trackersTitle.setVisibility(View.VISIBLE);
WebView trackersList = v.findViewById(R.id.trackers); reportBinding.trackers.setVisibility(View.VISIBLE);
analysed.setVisibility(View.GONE);
trackers_title.setVisibility(View.VISIBLE);
trackersList.setVisibility(View.VISIBLE);
//get trackers //get trackers
Report report = DatabaseManager.getInstance(context).getReportFor(packageName,versionName); Report report = DatabaseManager.getInstance(context).getReportFor(packageName,versionName);
Set<Tracker> trackers = null; Set<Tracker> trackers = null;
if(report != null) { if(report != null) {
trackers = DatabaseManager.getInstance(context).getTrackers(report.trackers); trackers = DatabaseManager.getInstance(context).getTrackers(report.trackers);
} else { } else {
analysed.setVisibility(View.VISIBLE); reportBinding.analysed.setVisibility(View.VISIBLE);
trackers_title.setVisibility(View.GONE); reportBinding.trackersTitle.setVisibility(View.GONE);
trackersList.setVisibility(View.GONE); reportBinding.trackers.setVisibility(View.GONE);
} }
//setup trackers report //setup trackers report
String trackers_text; String trackers_text;
@ -133,7 +123,7 @@ public class ReportFragment extends Fragment {
trackers_text = context.getString(R.string.trackers)+" "+String.valueOf(trackers.size()); trackers_text = context.getString(R.string.trackers)+" "+String.valueOf(trackers.size());
else else
trackers_text = context.getString(R.string.trackers); trackers_text = context.getString(R.string.trackers);
trackers_title.setText(trackers_text); reportBinding.trackersTitle.setText(trackers_text);
//setup trackers lists //setup trackers lists
//build html tracker list //build html tracker list
@ -143,36 +133,33 @@ public class ReportFragment extends Fragment {
trackersName.add(tracker.name); trackersName.add(tracker.name);
} }
String html = buildHtmlList(trackersName); String html = buildHtmlList(trackersName);
trackersList.loadData(html,"text/html","UTF-8"); reportBinding.trackers.loadData(html,"text/html","UTF-8");
} else { } else {
trackersList.loadData(getString(R.string.no_trackers),"text/plain","UTF-8"); reportBinding.trackers.loadData(getString(R.string.no_trackers),"text/plain","UTF-8");
} }
//setup creator //setup creator
TextView creators = v.findViewById(R.id.creator);
if(report != null) if(report != null)
creators.setText(DatabaseManager.getInstance(context).getCreator(report.appId)); reportBinding.creator.setText(DatabaseManager.getInstance(context).getCreator(report.appId));
else else
creators.setVisibility(View.GONE); reportBinding.creator.setVisibility(View.GONE);
//setup installed //setup installed
TextView installed = v.findViewById(R.id.installed_version);
String installed_str = context.getString(R.string.installed) +" "+ versionName; String installed_str = context.getString(R.string.installed) +" "+ versionName;
installed.setText(installed_str); reportBinding.installedVersion.setText(installed_str);
//setup reportversion //setup reportversion
TextView reportVersion = v.findViewById(R.id.report_version); reportBinding.reportVersion.setVisibility(View.VISIBLE);
if(report != null && !report.version.equals(versionName)) { if(report != null && !report.version.equals(versionName)) {
String report_str = context.getString(R.string.report_version)+" "+report.version; String report_str = context.getString(R.string.report_version)+" "+report.version;
reportVersion.setText(report_str); reportBinding.reportVersion.setText(report_str);
} }
else else
reportVersion.setVisibility(View.GONE); reportBinding.reportVersion.setVisibility(View.GONE);
//setup report url //setup report url
TextView url = v.findViewById(R.id.report_url);
if(report != null) if(report != null)
url.setText("https://reports.exodus-privacy.eu.org/reports/"+report.id+"/"); reportBinding.reportUrl.setText("https://reports.exodus-privacy.eu.org/reports/"+report.id+"/");
} }
private String buildHtmlList(List<String> list) { private String buildHtmlList(List<String> list) {

View File

@ -1,68 +1,74 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <layout
android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center"> >
<data/>
<RelativeLayout <RelativeLayout
android:id="@+id/base_info"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
<ImageView android:gravity="center">
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/app_logo"
android:contentDescription="@string/app_logo"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"/>
<LinearLayout
android:id="@+id/layout_infos"
android:orientation="vertical"
android:layout_centerInParent="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/app_tracker_nb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/app_permission_nb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout> <RelativeLayout
android:id="@+id/base_info"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/app_logo"
android:contentDescription="@string/app_logo"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"/>
<LinearLayout
android:id="@+id/layout_infos"
android:orientation="vertical"
android:layout_centerInParent="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/app_tracker_nb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/app_permission_nb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:layout_centerInParent="true"
android:layout_toRightOf="@+id/app_logo"
android:layout_toEndOf="@+id/app_logo"
android:layout_toLeftOf="@+id/layout_infos"
android:layout_toStartOf="@+id/layout_infos"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:id="@+id/app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
<TextView <TextView
android:layout_centerInParent="true" android:layout_below="@+id/base_info"
android:layout_toRightOf="@+id/app_logo" android:id="@+id/other_version"
android:layout_toEndOf="@+id/app_logo" android:text="@string/tested"
android:layout_toLeftOf="@+id/layout_infos"
android:layout_toStartOf="@+id/layout_infos"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:id="@+id/app_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<TextView
android:layout_below="@+id/other_version"
android:id="@+id/analysed"
android:text="@string/analysed"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_below="@+id/analysed"
android:layout_alignParentBottom="true"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="10dp" />
</RelativeLayout> </RelativeLayout>
<TextView </layout>
android:layout_below="@+id/base_info"
android:id="@+id/other_version"
android:text="@string/tested"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_below="@+id/other_version"
android:id="@+id/analysed"
android:text="@string/analysed"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_below="@+id/analysed"
android:layout_alignParentBottom="true"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="10dp" />
</RelativeLayout>

View File

@ -1,71 +1,76 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" tools:context="org.eu.exodus_privacy.exodusprivacy.MainActivity"
android:layout_height="match_parent" >
tools:context="org.eu.exodus_privacy.exodusprivacy.MainActivity"> <data/>
<android.support.constraint.ConstraintLayout
<LinearLayout
android:visibility="gone"
android:id="@+id/layout_progress"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_margin="10dp" <LinearLayout
app:layout_constraintRight_toRightOf="parent" android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"> android:id="@+id/layout_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_marginBottom="5dp"
android:id="@+id/status_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ProgressBar
android:id="@+id/progress"
style="@android:style/Widget.ProgressBar.Horizontal"
android:progressDrawable="@drawable/progressbar"
android:layout_width="match_parent"
android:layout_height="5dp" />
</LinearLayout>
<TextView <TextView
android:layout_marginBottom="5dp" android:id="@+id/no_package_manager"
android:id="@+id/status_progress"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="match_parent"
android:gravity="center"
android:text="@string/no_package_manager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar <TextView
android:id="@+id/progress" android:id="@+id/no_app_found"
style="@android:style/Widget.ProgressBar.Horizontal"
android:progressDrawable="@drawable/progressbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="5dp" /> android:layout_height="match_parent"
</LinearLayout> android:gravity="center"
android:text="@string/no_app_found"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/no_package_manager" android:id="@+id/swipe_refresh"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="0dp"
android:gravity="center" app:layout_constraintLeft_toLeftOf="parent"
android:text="@string/no_package_manager" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toBottomOf="@+id/layout_progress"
app:layout_constraintRight_toRightOf="parent" >
app:layout_constraintTop_toTopOf="parent" />
<TextView <android.support.v7.widget.RecyclerView
android:id="@+id/no_app_found" android:id="@+id/app_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
android:gravity="center" </android.support.v4.widget.SwipeRefreshLayout>
android:text="@string/no_app_found"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v4.widget.SwipeRefreshLayout </android.support.constraint.ConstraintLayout>
android:id="@+id/swipe_refresh" </layout>
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/layout_progress"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/app_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.constraint.ConstraintLayout>

View File

@ -1,24 +1,24 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" tools:context="org.eu.exodus_privacy.exodusprivacy.MainActivity"
android:layout_height="match_parent" >
tools:context="org.eu.exodus_privacy.exodusprivacy.MainActivity"> <data/>
<FrameLayout
<FrameLayout android:layout_marginRight="10dp"
android:layout_marginRight="10dp" android:layout_marginEnd="10dp"
android:layout_marginEnd="10dp" android:layout_marginLeft="10dp"
android:layout_marginLeft="10dp" android:layout_marginStart="10dp"
android:layout_marginStart="10dp" android:layout_marginTop="5dp"
android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
android:layout_marginBottom="5dp" android:id="@+id/fragment_container"
android:id="@+id/fragment_container" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_height="match_parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent" /> </layout>
</android.support.constraint.ConstraintLayout>

View File

@ -1,116 +1,122 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"> >
<LinearLayout <data/>
android:orientation="horizontal" <RelativeLayout
android:id="@+id/base_info"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="match_parent">
<ImageView
android:id="@+id/logo"
android:layout_width="100dp"
android:layout_height="100dp"
/>
<LinearLayout <LinearLayout
android:layout_marginLeft="2dp" android:orientation="horizontal"
android:layout_marginStart="2dp" android:id="@+id/base_info"
android:orientation="vertical" android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
> <ImageView
<TextView android:id="@+id/logo"
android:id="@+id/name" android:layout_width="100dp"
android:text="test" android:layout_height="100dp"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <LinearLayout
<TextView android:layout_marginLeft="2dp"
android:text="Creator" android:layout_marginStart="2dp"
android:id="@+id/creator" android:orientation="vertical"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="installed version"
android:id="@+id/installed_version"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="Report version"
android:id="@+id/report_version"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/report_url"
android:autoLink="web"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/analysed"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/analysed" >
android:textAppearance="@style/TextAppearance.AppCompat.Medium" <TextView
/> android:id="@+id/name"
android:text="test"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="Creator"
android:id="@+id/creator"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="installed version"
android:id="@+id/installed_version"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="Report version"
android:id="@+id/report_version"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/report_url"
android:autoLink="web"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/analysed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/analysed"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
/>
</LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> <LinearLayout
<ScrollView android:layout_below="@id/base_info"
android:layout_below="@id/base_info" android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
>
<RelativeLayout
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
> >
<TextView <LinearLayout
android:background="@color/colorPrimary"
android:id="@+id/trackers_title"
android:text="@string/trackers"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:textColor="@android:color/white" android:layout_weight="50"
/> android:orientation="vertical">
<WebView <TextView
android:id="@+id/trackers" android:id="@+id/trackers_title"
android:layout_marginBottom="10dp" android:layout_width="match_parent"
android:layout_marginTop="10dp" android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:text="@string/trackers"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@android:color/white" />
<WebView
android:id="@+id/trackers"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="50"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent">
android:layout_below="@id/trackers_title" <TextView
/> android:background="@color/colorPrimary"
android:id="@+id/permissions_title"
android:text="@string/permissions"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
/>
<TextView <WebView
android:background="@color/colorPrimary" android:id="@+id/permissions"
android:id="@+id/permissions_title" android:layout_marginTop="10dp"
android:text="@string/permissions" android:layout_width="match_parent"
android:textAppearance="@style/TextAppearance.AppCompat.Large" android:layout_height="wrap_content"
android:layout_width="match_parent" />
android:layout_height="wrap_content" </LinearLayout>
android:layout_below="@id/trackers" </LinearLayout>
android:textColor="@android:color/white" </RelativeLayout>
/> </layout>
<WebView
android:id="@+id/permissions"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/permissions_title"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>