mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-16 05:34:05 +02:00
show comment if available
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
package com.health.openscale.gui.overview;
|
package com.health.openscale.gui.overview;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.app.Activity;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
@@ -12,6 +12,7 @@ import android.widget.ImageView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.navigation.Navigation;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.google.android.flexbox.AlignItems;
|
import com.google.android.flexbox.AlignItems;
|
||||||
@@ -20,17 +21,18 @@ import com.google.android.flexbox.FlexboxLayoutManager;
|
|||||||
import com.google.android.flexbox.JustifyContent;
|
import com.google.android.flexbox.JustifyContent;
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||||
|
import com.health.openscale.gui.measurement.MeasurementEntryFragment;
|
||||||
import com.health.openscale.gui.measurement.WeightMeasurementView;
|
import com.health.openscale.gui.measurement.WeightMeasurementView;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class OverviewAdapter extends RecyclerView.Adapter<OverviewAdapter.ViewHolder> {
|
class OverviewAdapter extends RecyclerView.Adapter<OverviewAdapter.ViewHolder> {
|
||||||
private Context context;
|
private Activity activity;
|
||||||
private List<ScaleMeasurement> scaleMeasurementList;
|
private List<ScaleMeasurement> scaleMeasurementList;
|
||||||
|
|
||||||
public OverviewAdapter(Context aContext, List<ScaleMeasurement> scaleMeasurementList) {
|
public OverviewAdapter(Activity activity, List<ScaleMeasurement> scaleMeasurementList) {
|
||||||
this.context = aContext;
|
this.activity = activity;
|
||||||
this.scaleMeasurementList = scaleMeasurementList;
|
this.scaleMeasurementList = scaleMeasurementList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,16 +61,35 @@ class OverviewAdapter extends RecyclerView.Adapter<OverviewAdapter.ViewHolder> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(context);
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
OverviewFragmentDirections.ActionNavOverviewToNavDataentry action = OverviewFragmentDirections.actionNavOverviewToNavDataentry();
|
||||||
|
action.setMeasurementId(scaleMeasurement.getId());
|
||||||
|
action.setMode(MeasurementEntryFragment.DATA_ENTRY_MODE.VIEW);
|
||||||
|
Navigation.findNavController(activity, R.id.nav_host_fragment).navigate(action);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!scaleMeasurement.getComment().isEmpty()) {
|
||||||
|
holder.commentTextView.setVisibility(View.VISIBLE);
|
||||||
|
holder.commentIconView.setVisibility(View.VISIBLE);
|
||||||
|
holder.commentTextView.setText(scaleMeasurement.getComment());
|
||||||
|
} else {
|
||||||
|
holder.commentTextView.setVisibility(View.GONE);
|
||||||
|
holder.commentIconView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(activity);
|
||||||
layoutManager.setFlexDirection(FlexDirection.ROW);
|
layoutManager.setFlexDirection(FlexDirection.ROW);
|
||||||
layoutManager.setJustifyContent(JustifyContent.SPACE_AROUND);
|
layoutManager.setJustifyContent(JustifyContent.SPACE_AROUND);
|
||||||
layoutManager.setAlignItems(AlignItems.CENTER);
|
layoutManager.setAlignItems(AlignItems.CENTER);
|
||||||
holder.measurementRecyclerView.setLayoutManager(layoutManager);
|
holder.measurementRecyclerView.setLayoutManager(layoutManager);
|
||||||
holder.measurementRecyclerView.setHasFixedSize(true);
|
holder.measurementRecyclerView.setHasFixedSize(true);
|
||||||
holder.measurementRecyclerView.setNestedScrollingEnabled(false);
|
holder.measurementRecyclerView.setNestedScrollingEnabled(false);
|
||||||
holder.measurementRecyclerView.setAdapter(new MeasurementAdapter(context, scaleMeasurement, prevScaleMeasurement));
|
holder.measurementRecyclerView.setAdapter(new MeasurementAdapter(activity, scaleMeasurement, prevScaleMeasurement));
|
||||||
|
|
||||||
WeightMeasurementView weightMeasurementView = new WeightMeasurementView(context);
|
WeightMeasurementView weightMeasurementView = new WeightMeasurementView(activity);
|
||||||
weightMeasurementView.loadFrom(scaleMeasurement, prevScaleMeasurement);
|
weightMeasurementView.loadFrom(scaleMeasurement, prevScaleMeasurement);
|
||||||
SpannableStringBuilder weightValue = new SpannableStringBuilder();
|
SpannableStringBuilder weightValue = new SpannableStringBuilder();
|
||||||
weightValue.append("◆ ");
|
weightValue.append("◆ ");
|
||||||
@@ -99,6 +120,8 @@ class OverviewAdapter extends RecyclerView.Adapter<OverviewAdapter.ViewHolder> {
|
|||||||
TextView weightView;
|
TextView weightView;
|
||||||
ImageView expandMoreView;
|
ImageView expandMoreView;
|
||||||
RecyclerView measurementRecyclerView;
|
RecyclerView measurementRecyclerView;
|
||||||
|
ImageView commentIconView;
|
||||||
|
TextView commentTextView;
|
||||||
|
|
||||||
public ViewHolder(@NonNull View itemView) {
|
public ViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
@@ -107,6 +130,8 @@ class OverviewAdapter extends RecyclerView.Adapter<OverviewAdapter.ViewHolder> {
|
|||||||
weightView = itemView.findViewById(R.id.weightView);
|
weightView = itemView.findViewById(R.id.weightView);
|
||||||
expandMoreView = itemView.findViewById(R.id.expandMoreView);
|
expandMoreView = itemView.findViewById(R.id.expandMoreView);
|
||||||
measurementRecyclerView = itemView.findViewById(R.id.measurementRecyclerView);
|
measurementRecyclerView = itemView.findViewById(R.id.measurementRecyclerView);
|
||||||
|
commentIconView = itemView.findViewById(R.id.commentIconView);
|
||||||
|
commentTextView = itemView.findViewById(R.id.commentTextView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -269,7 +269,7 @@ public class OverviewFragment extends Fragment {
|
|||||||
markedMeasurement = scaleMeasurementList.get(0);
|
markedMeasurement = scaleMeasurementList.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
overviewAdapter = new OverviewAdapter(getContext(), scaleMeasurementList);
|
overviewAdapter = new OverviewAdapter(getActivity(), scaleMeasurementList);
|
||||||
recyclerView.setAdapter(overviewAdapter);
|
recyclerView.setAdapter(overviewAdapter);
|
||||||
|
|
||||||
updateUserSelection();
|
updateUserSelection();
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/dateView"
|
android:id="@+id/dateView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="TextView"
|
android:text="TextView"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
@@ -44,11 +44,10 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:tint="?attr/colorControlNormal"
|
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/weightView"
|
app:layout_constraintBottom_toBottomOf="@+id/weightView"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="@+id/weightView"
|
app:srcCompat="@drawable/ic_expand_more"
|
||||||
app:srcCompat="@drawable/ic_expand_more" />
|
app:tint="?attr/colorControlNormal" />
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/measurementRecyclerView"
|
android:id="@+id/measurementRecyclerView"
|
||||||
@@ -56,7 +55,32 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/weightView" />
|
app:layout_constraintTop_toBottomOf="@+id/weightView" >
|
||||||
|
|
||||||
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/commentIconView"
|
||||||
|
android:layout_width="20dp"
|
||||||
|
android:layout_height="20dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:tint="?attr/colorControlNormal"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/measurementRecyclerView"
|
||||||
|
app:srcCompat="@drawable/ic_comment" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/commentTextView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:text="TextView"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/commentIconView"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/commentIconView"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/commentIconView" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
Reference in New Issue
Block a user