Improve layout
This commit is contained in:
parent
cae158d489
commit
9d330bf07f
|
@ -54,14 +54,24 @@ public class MyTrackersListAdapter extends RecyclerView.Adapter<MyTrackersListAd
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull MyTrackersListAdapter.TrackerListViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull MyTrackersListAdapter.TrackerListViewHolder holder, int position) {
|
||||||
MyTracker myTracker = myTrackers.get(position);
|
|
||||||
if (myTrackers != null) {
|
if (myTrackers != null) {
|
||||||
|
MyTracker myTracker = myTrackers.get(position);
|
||||||
holder.viewDataBinding.trackerName.setText(myTracker.tracker.name);
|
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));
|
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.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() {
|
holder.viewDataBinding.percent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onGlobalLayout() {
|
public void onGlobalLayout() {
|
||||||
|
|
|
@ -45,11 +45,13 @@
|
||||||
app:layout_constraintTop_toBottomOf="@+id/percent" />
|
app:layout_constraintTop_toBottomOf="@+id/percent" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:paddingStart="5dp"
|
||||||
|
android:paddingEnd="5dp"
|
||||||
android:id="@+id/tracker_count"
|
android:id="@+id/tracker_count"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:textSize="18sp"
|
android:textColor="@color/textColorWhite"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toEndOf="@+id/tracker_name"
|
app:layout_constraintStart_toEndOf="@+id/tracker_name"
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
<string name="title_apps">My apps</string>
|
<string name="title_apps">My apps</string>
|
||||||
<string name="title_trackers">Trackers</string>
|
<string name="title_trackers">Trackers</string>
|
||||||
<string name="list_of_apps">See the list of apps</string>
|
<string name="list_of_apps">See the list of apps</string>
|
||||||
|
<string name="apps">%1$s apps</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue