Use data from ApplicationViewModel in ReportDisplay and ReportFragment
This commit is contained in:
parent
2ceb256f06
commit
9290d71cb0
|
@ -39,17 +39,18 @@ import androidx.fragment.app.FragmentTransaction;
|
|||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationListAdapter;
|
||||
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationViewModel;
|
||||
import org.eu.exodus_privacy.exodusprivacy.databinding.MainBinding;
|
||||
import org.eu.exodus_privacy.exodusprivacy.fragments.HomeFragment;
|
||||
import org.eu.exodus_privacy.exodusprivacy.fragments.ReportFragment;
|
||||
import org.eu.exodus_privacy.exodusprivacy.fragments.Updatable;
|
||||
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
|
||||
import org.eu.exodus_privacy.exodusprivacy.manager.DatabaseManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private ReportFragment report;
|
||||
private List<Updatable> fragments;
|
||||
private SearchView searchView;
|
||||
private Menu toolbarMenu;
|
||||
|
@ -69,7 +70,14 @@ public class MainActivity extends AppCompatActivity {
|
|||
public void onSuccess() {
|
||||
runOnUiThread(() -> {
|
||||
for(Updatable updatable : fragments){
|
||||
|
||||
if(updatable instanceof ReportFragment) {
|
||||
ApplicationViewModel model = ((ReportFragment) updatable).getModel();
|
||||
if(model.versionName == null)
|
||||
model.report = DatabaseManager.getInstance(MainActivity.this).getReportFor(model.packageName, model.versionCode);
|
||||
else
|
||||
model.report = DatabaseManager.getInstance(MainActivity.this).getReportFor(model.packageName,model.versionName);
|
||||
model.trackers = DatabaseManager.getInstance(MainActivity.this).getTrackers(model.report.trackers);
|
||||
}
|
||||
updatable.onUpdateComplete();
|
||||
}
|
||||
});
|
||||
|
@ -97,7 +105,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
PackageManager pm = getPackageManager();
|
||||
PackageInfo packageInfo = pm.getPackageInfo(vm.packageName, PackageManager.GET_PERMISSIONS);
|
||||
|
||||
report = ReportFragment.newInstance(pm,packageInfo);
|
||||
ReportFragment report = ReportFragment.newInstance(pm,vm,packageInfo);
|
||||
fragments.add(report);
|
||||
FragmentManager manager = getSupportFragmentManager();
|
||||
FragmentTransaction transaction = manager.beginTransaction();
|
||||
|
|
|
@ -39,6 +39,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||
|
||||
import org.eu.exodus_privacy.exodusprivacy.R;
|
||||
import org.eu.exodus_privacy.exodusprivacy.ReportViewModel;
|
||||
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationViewModel;
|
||||
import org.eu.exodus_privacy.exodusprivacy.adapters.PermissionListAdapter;
|
||||
import org.eu.exodus_privacy.exodusprivacy.adapters.TrackerListAdapter;
|
||||
import org.eu.exodus_privacy.exodusprivacy.databinding.ReportBinding;
|
||||
|
@ -48,14 +49,19 @@ public class ReportFragment extends Fragment implements Updatable {
|
|||
private PackageManager packageManager;
|
||||
private PackageInfo packageInfo = null;
|
||||
private ReportBinding reportBinding;
|
||||
private ApplicationViewModel model;
|
||||
|
||||
public static ReportFragment newInstance(PackageManager packageManager, PackageInfo packageInfo) {
|
||||
public static ReportFragment newInstance(PackageManager packageManager,ApplicationViewModel model, PackageInfo packageInfo) {
|
||||
ReportFragment fragment = new ReportFragment();
|
||||
fragment.setPackageManager(packageManager);
|
||||
fragment.setPackageInfo(packageInfo);
|
||||
fragment.setApplicationViewModel(model);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
private void setApplicationViewModel(ApplicationViewModel model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -81,9 +87,13 @@ public class ReportFragment extends Fragment implements Updatable {
|
|||
|
||||
@Override
|
||||
public void onUpdateComplete() {
|
||||
onUpdateComplete(model);
|
||||
}
|
||||
|
||||
public void onUpdateComplete(ApplicationViewModel model) {
|
||||
Context context = reportBinding.getRoot().getContext();
|
||||
|
||||
ReportDisplay reportDisplay = ReportDisplay.buildReportDisplay(context,packageManager,packageInfo);
|
||||
ReportDisplay reportDisplay = ReportDisplay.buildReportDisplay(context,model,packageManager,packageInfo);
|
||||
ReportViewModel viewModel = new ReportViewModel();
|
||||
viewModel.setReportDisplay(reportDisplay);
|
||||
reportBinding.setReportInfo(viewModel);
|
||||
|
@ -146,4 +156,8 @@ public class ReportFragment extends Fragment implements Updatable {
|
|||
MenuItem item = menu.findItem(R.id.action_filter);
|
||||
item.setVisible(false);
|
||||
}
|
||||
|
||||
public ApplicationViewModel getModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.content.pm.PermissionInfo;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
||||
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationViewModel;
|
||||
import org.eu.exodus_privacy.exodusprivacy.manager.DatabaseManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -31,20 +32,16 @@ public class ReportDisplay {
|
|||
|
||||
}
|
||||
|
||||
public static ReportDisplay buildReportDisplay(Context context, PackageManager manager, PackageInfo info) {
|
||||
public static ReportDisplay buildReportDisplay(Context context, ApplicationViewModel model, PackageManager manager, PackageInfo info) {
|
||||
ReportDisplay reportDisplay = new ReportDisplay();
|
||||
reportDisplay.packageName = info.packageName;
|
||||
reportDisplay.versionName = info.versionName;
|
||||
reportDisplay.versionCode = info.versionCode;
|
||||
reportDisplay.displayName = manager.getApplicationLabel(info.applicationInfo).toString();
|
||||
reportDisplay.packageName = model.packageName;
|
||||
reportDisplay.versionName = model.versionName;
|
||||
reportDisplay.versionCode = model.versionCode;
|
||||
reportDisplay.displayName = model.label.toString();
|
||||
|
||||
if(reportDisplay.versionName != null)
|
||||
reportDisplay.report = DatabaseManager.getInstance(context).getReportFor(reportDisplay.packageName,reportDisplay.versionName);
|
||||
else
|
||||
reportDisplay.report = DatabaseManager.getInstance(context).getReportFor(reportDisplay.packageName, reportDisplay.versionCode);
|
||||
reportDisplay.report = model.report;
|
||||
|
||||
if(reportDisplay.report != null)
|
||||
reportDisplay.trackers = DatabaseManager.getInstance(context).getTrackers(reportDisplay.report.trackers);
|
||||
reportDisplay.trackers = model.trackers;
|
||||
|
||||
if (reportDisplay.report != null)
|
||||
reportDisplay.creator = DatabaseManager.getInstance(context).getCreator(reportDisplay.report.appId);
|
||||
|
@ -78,11 +75,7 @@ public class ReportDisplay {
|
|||
}
|
||||
reportDisplay.permissions = requestedPermissions;
|
||||
|
||||
try {
|
||||
reportDisplay.logo = manager.getApplicationIcon(reportDisplay.packageName);
|
||||
} catch (PackageManager.NameNotFoundException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
reportDisplay.logo = model.icon;
|
||||
|
||||
return reportDisplay;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue