1
0
mirror of https://github.com/stom79/exodus-android-app synced 2024-12-18 02:58:26 +01:00

Some improvements

This commit is contained in:
Thomas 2020-12-15 16:53:36 +01:00
parent efe9a88209
commit cae158d489
3 changed files with 14 additions and 7 deletions

View File

@ -156,6 +156,7 @@ public class MainActivity extends AppCompatActivity {
}
binding.fragmentContainer.setVisibility(View.GONE);
}
}
@Override
@ -268,6 +269,8 @@ public class MainActivity extends AppCompatActivity {
if (fragments.size() > 0) {
Updatable fragment = fragments.get(fragments.size() - 1);
settingsMenuItem.setVisible(fragment instanceof ReportFragment);
} else {
settingsMenuItem.setVisible(false);
}
return true;
}

View File

@ -35,13 +35,14 @@ public class MyTrackersListAdapter extends RecyclerView.Adapter<MyTrackersListAd
private final TrackerClickListener trackerClickListener;
private final List<MyTracker> myTrackers;
private final int max;
private final int max, installedApps;
private int viewWidth = 0;
public MyTrackersListAdapter(List<MyTracker> mTrackers, TrackerClickListener listener, int maxValue) {
public MyTrackersListAdapter(List<MyTracker> mTrackers, TrackerClickListener listener, int maxValue, int appInstalled) {
myTrackers = mTrackers;
trackerClickListener = listener;
max = maxValue;
installedApps = appInstalled;
}
@NonNull
@ -57,12 +58,10 @@ public class MyTrackersListAdapter extends RecyclerView.Adapter<MyTrackersListAd
if (myTrackers != null) {
holder.viewDataBinding.trackerName.setText(myTracker.tracker.name);
holder.viewDataBinding.trackerCount.setText(String.valueOf(myTracker.number));
holder.viewDataBinding.getRoot().setOnClickListener(v -> {
trackerClickListener.onTrackerClick(myTracker.tracker.id);
});
holder.viewDataBinding.getRoot().setOnClickListener(v -> trackerClickListener.onTrackerClick(myTracker.tracker.id));
float percent = (float) myTracker.number / max;
holder.viewDataBinding.percent.getLayoutParams().width = (int) (viewWidth * percent);
holder.viewDataBinding.percentVal.setText(String.format("%s %%", myTracker.number * 100 / myTrackers.size()));
holder.viewDataBinding.percentVal.setText(String.format("%s %%", myTracker.number * 100 / installedApps));
holder.viewDataBinding.percent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {

View File

@ -34,6 +34,7 @@ import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import org.eu.exodus_privacy.exodusprivacy.R;
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationViewModel;
import org.eu.exodus_privacy.exodusprivacy.adapters.MyTrackersListAdapter;
import org.eu.exodus_privacy.exodusprivacy.adapters.TrackerListAdapter;
import org.eu.exodus_privacy.exodusprivacy.databinding.MyTrackersBinding;
@ -47,6 +48,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
public class MyTrackersFragment extends Fragment implements MyTrackersListAdapter.TrackerClickListener {
private Context context;
@ -79,6 +81,9 @@ public class MyTrackersFragment extends Fragment implements MyTrackersListAdapte
List<MyTracker> myTrackers = new ArrayList<>();
List<String> added = new ArrayList<>();
int maxValue = 0;
List<ApplicationViewModel> vms = ComputeAppList.compute(packageManager, DatabaseManager.getInstance(getActivity()), null);
int appInstalled = vms.size();
for (PackageInfo pkgInfo : packageInstalled) {
Report report;
if (pkgInfo.versionName != null)
@ -114,7 +119,7 @@ public class MyTrackersFragment extends Fragment implements MyTrackersListAdapte
int finalMaxValue = maxValue;
Runnable myRunnable = () -> {
Collections.sort(myTrackers, (obj1, obj2) -> Integer.compare(obj2.number, obj1.number));
MyTrackersListAdapter myTrackersListAdapter = new MyTrackersListAdapter(myTrackers, MyTrackersFragment.this, finalMaxValue);
MyTrackersListAdapter myTrackersListAdapter = new MyTrackersListAdapter(myTrackers, MyTrackersFragment.this, finalMaxValue, appInstalled);
trackerBinding.trackers.setAdapter(myTrackersListAdapter);
trackerBinding.trackers.setLayoutManager(new LinearLayoutManager(context));
trackerBinding.trackers.setVisibility(View.VISIBLE);