Use databinding in place of all findViewById
This commit is contained in:
parent
9c619c2135
commit
357500df9a
|
@ -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'
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
<?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"
|
||||||
|
>
|
||||||
|
<data/>
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center">
|
android:gravity="center">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
@ -66,3 +71,4 @@
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
</layout>
|
|
@ -1,11 +1,15 @@
|
||||||
<?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"
|
||||||
|
tools:context="org.eu.exodus_privacy.exodusprivacy.MainActivity"
|
||||||
|
>
|
||||||
|
<data/>
|
||||||
|
<android.support.constraint.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="org.eu.exodus_privacy.exodusprivacy.MainActivity">
|
>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:id="@+id/layout_progress"
|
android:id="@+id/layout_progress"
|
||||||
|
@ -69,3 +73,4 @@
|
||||||
</android.support.v4.widget.SwipeRefreshLayout>
|
</android.support.v4.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
</android.support.constraint.ConstraintLayout>
|
</android.support.constraint.ConstraintLayout>
|
||||||
|
</layout>
|
|
@ -1,11 +1,12 @@
|
||||||
<?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"
|
||||||
|
@ -20,5 +21,4 @@
|
||||||
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>
|
|
|
@ -1,6 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
>
|
||||||
|
<data/>
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
@ -61,37 +65,41 @@
|
||||||
/>
|
/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<ScrollView
|
<LinearLayout
|
||||||
android:layout_below="@id/base_info"
|
android:layout_below="@id/base_info"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_alignParentBottom="true"
|
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"
|
||||||
>
|
>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="50"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:background="@color/colorPrimary"
|
|
||||||
android:id="@+id/trackers_title"
|
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="wrap_content"
|
||||||
android:textColor="@android:color/white"
|
android:background="@color/colorPrimary"
|
||||||
/>
|
android:text="@string/trackers"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
android:textColor="@android:color/white" />
|
||||||
|
|
||||||
<WebView
|
<WebView
|
||||||
android:id="@+id/trackers"
|
android:id="@+id/trackers"
|
||||||
android:layout_marginBottom="10dp"
|
|
||||||
android:layout_marginTop="10dp"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content" />
|
||||||
android:layout_below="@id/trackers_title"
|
</LinearLayout>
|
||||||
/>
|
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_weight="50"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
<TextView
|
<TextView
|
||||||
android:background="@color/colorPrimary"
|
android:background="@color/colorPrimary"
|
||||||
android:id="@+id/permissions_title"
|
android:id="@+id/permissions_title"
|
||||||
|
@ -99,7 +107,6 @@
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/trackers"
|
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -108,9 +115,8 @@
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/permissions_title"
|
|
||||||
/>
|
/>
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</ScrollView>
|
</layout>
|
||||||
|
|
||||||
</RelativeLayout>
|
|
Loading…
Reference in New Issue