Improve layout

This commit is contained in:
Thomas 2020-12-15 17:24:46 +01:00
parent cae158d489
commit 9d330bf07f
3 changed files with 18 additions and 5 deletions

View File

@ -54,14 +54,24 @@ public class MyTrackersListAdapter extends RecyclerView.Adapter<MyTrackersListAd
@Override
public void onBindViewHolder(@NonNull MyTrackersListAdapter.TrackerListViewHolder holder, int position) {
MyTracker myTracker = myTrackers.get(position);
if (myTrackers != null) {
MyTracker myTracker = myTrackers.get(position);
holder.viewDataBinding.trackerName.setText(myTracker.tracker.name);
holder.viewDataBinding.trackerCount.setText(String.valueOf(myTracker.number));
holder.viewDataBinding.trackerCount.setText(holder.viewDataBinding.trackerCount.getContext().getString(R.string.apps, String.valueOf(myTracker.number)));
holder.viewDataBinding.getRoot().setOnClickListener(v -> trackerClickListener.onTrackerClick(myTracker.tracker.id));
float percent = (float) myTracker.number / max;
float percent = (float) myTracker.number / (float) max;
int percentApp = myTracker.number * 100 / installedApps;
holder.viewDataBinding.percent.getLayoutParams().width = (int) (viewWidth * percent);
holder.viewDataBinding.percentVal.setText(String.format("%s %%", myTracker.number * 100 / installedApps));
holder.viewDataBinding.percentVal.setText(String.format("%s %%", percentApp));
if (percentApp >= 50)
holder.viewDataBinding.trackerCount.setBackgroundResource(R.drawable.square_red);
else if (percentApp >= 33)
holder.viewDataBinding.trackerCount.setBackgroundResource(R.drawable.square_dark_orange);
else if (percentApp >= 20)
holder.viewDataBinding.trackerCount.setBackgroundResource(R.drawable.square_yellow);
else
holder.viewDataBinding.trackerCount.setBackgroundResource(R.drawable.square_light_blue);
holder.viewDataBinding.percent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {

View File

@ -45,11 +45,13 @@
app:layout_constraintTop_toBottomOf="@+id/percent" />
<TextView
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:id="@+id/tracker_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textSize="18sp"
android:textColor="@color/textColorWhite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/tracker_name"

View File

@ -65,6 +65,7 @@
<string name="title_apps">My apps</string>
<string name="title_trackers">Trackers</string>
<string name="list_of_apps">See the list of apps</string>
<string name="apps">%1$s apps</string>
</resources>