final trigger icon position, clean up, extreact strings...

This commit is contained in:
vanous 2022-07-29 23:11:44 +02:00
parent c592597f84
commit ef424a2bb9
12 changed files with 137 additions and 105 deletions

View File

@ -24,6 +24,7 @@ import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.fragment.app.FragmentManager;
@ -41,7 +42,6 @@ import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -73,7 +73,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
private TextView mBalanceView;
private int mOffsetHours = getOffsetHours();
FloatingActionButton stepsStreaksFAB;
ImageView stepsStreaksButton;
@Override
protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
@ -107,16 +107,15 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
//disable the streak FAB once we move away from today
Calendar day = Calendar.getInstance();
day.setTime(getChartsHost().getEndDate());
stepsStreaksFAB.setAlpha((float) 1.0);
if (DateUtils.isToday(day.getTimeInMillis()) && enableStepStreaksFAB()){
stepsStreaksFAB.setVisibility(View.VISIBLE);
if (DateUtils.isToday(day.getTimeInMillis()) && enableStepStreaksButton()){
stepsStreaksButton.setVisibility(View.VISIBLE);
}else
{
stepsStreaksFAB.setVisibility(View.GONE);
stepsStreaksButton.setVisibility(View.GONE);
}
}
private boolean enableStepStreaksFAB(){
private boolean enableStepStreaksButton(){
return this.getClass().getSimpleName().equals("WeekStepsChartFragment");
}
@ -257,12 +256,11 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
setupWeekChart();
setupTodayPieChart();
stepsStreaksFAB = rootView.findViewById(R.id.fab_steps_streaks);
if (enableStepStreaksFAB()) {
stepsStreaksFAB.setOnClickListener(new View.OnClickListener() {
stepsStreaksButton = rootView.findViewById(R.id.steps_streaks_button);
if (enableStepStreaksButton()) {
stepsStreaksButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stepsStreaksFAB.setAlpha((float) 0.5);
FragmentManager fm = getActivity().getSupportFragmentManager();
StepStreaksDashboard stepStreaksDashboard = StepStreaksDashboard.newInstance(getGoal(), getChartsHost().getDevice());
stepStreaksDashboard.show(fm, "steps_streaks_dashboard");

View File

@ -1,6 +1,7 @@
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
@ -33,35 +34,41 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class StepStreaksDashboard extends DialogFragment {
protected static final Logger LOG = LoggerFactory.getLogger(StepStreaksDashboard.class);
GBDevice gbDevice;
int goal;
int stepsGoal;
boolean cancelTasks = false;
boolean backgroundFinished = false;
boolean backgroundTaskFinished = false;
private View fragmentView;
private StepsStreaks stepsStreaks = new StepsStreaks();
private final StepsStreaks stepsStreaks = new StepsStreaks();
private static final String GOAL = "goal";
private static final String PERIOD_CURRENT = "current";
private static final String PERIOD_TOTALS = "totals";
private static final int MAX_YEAR = 2015;
public StepStreaksDashboard() {
}
//Calculates some stats for longest streak (daily steps goal being reached for subsequent days
//without interruption (day with steps less then goal)
//Possible improvements/nice to haves:
//- cache values until new activity fetch is performed
//- create a parcel to allow screen rotation without recalculation
//- read the goals from the USER_ATTRIBUTES table. But, this would also require to be able
//to edit/add values there...
public static StepStreaksDashboard newInstance(int goal, GBDevice device) {
StepStreaksDashboard fragment = new StepStreaksDashboard();
Bundle args = new Bundle();
args.putInt("goal", goal);
args.putInt(GOAL, goal);
args.putParcelable(GBDevice.EXTRA_DEVICE, device);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.steps_streaks_dashboard, container);
}
@Override
@ -81,21 +88,21 @@ public class StepStreaksDashboard extends DialogFragment {
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
goal = getArguments().getInt("goal", 0);
stepsGoal = getArguments().getInt(GOAL, 0);
gbDevice = getArguments().getParcelable(GBDevice.EXTRA_DEVICE);
fragmentView = view;
if (gbDevice == null) {
throw new IllegalArgumentException("Must provide a device when invoking this activity");
}
createTaskCalculateLatestStepsStreak("Visualizing data current", getActivity(), "current").execute();
createTaskCalculateLatestStepsStreak("Visualizing data maximum", getActivity(), "totals").execute();
createTaskCalculateLatestStepsStreak("Visualizing data current", getActivity(), PERIOD_CURRENT).execute();
createTaskCalculateLatestStepsStreak("Visualizing data maximum", getActivity(), PERIOD_TOTALS).execute();
}
void indicate_progress(boolean inProgress) {
ProgressBar step_streak_dashboard_loading_circle = fragmentView.findViewById(R.id.step_streak_dashboard_loading_circle);
if (inProgress) {
step_streak_dashboard_loading_circle.setAlpha(0.5f);
step_streak_dashboard_loading_circle.setAlpha(0.4f); //make it a bit softer
} else {
step_streak_dashboard_loading_circle.setAlpha(0);
}
@ -120,6 +127,7 @@ public class StepStreaksDashboard extends DialogFragment {
TextView days_total_label = total.findViewById(R.id.step_streak_days_label);
TextView total_total = total.findViewById(R.id.step_streak_total_value);
TextView date_total_value = total.findViewById(R.id.step_streak_total_date_value);
TextView date_total_label = total.findViewById(R.id.step_streak_total_label);
if (stepsStreaks.current.days > 0) {
@ -127,7 +135,10 @@ public class StepStreaksDashboard extends DialogFragment {
days_current.setText(Integer.toString(stepsStreaks.current.days));
average_current.setText(Integer.toString(stepsStreaks.current.steps / stepsStreaks.current.days));
total_current.setText(Integer.toString(stepsStreaks.current.steps));
date_current_value.setText(String.format("From %s", DateTimeUtils.formatDate(new Date(stepsStreaks.current.timestamp * 1000l))));
Date startDate = new Date(stepsStreaks.current.timestamp * 1000L);
Date endDate = DateTimeUtils.shiftByDays(startDate, stepsStreaks.current.days - 1); //first day is 1 not 0
date_current_value.setText(DateTimeUtils.formatDateRange(startDate, endDate));
}
if (stepsStreaks.maximum.days > 0) {
@ -136,22 +147,31 @@ public class StepStreaksDashboard extends DialogFragment {
average_maximum.setText(Integer.toString(stepsStreaks.maximum.steps / stepsStreaks.maximum.days));
total_maximum.setText(Integer.toString(stepsStreaks.maximum.steps));
Date startDate = new Date(stepsStreaks.maximum.timestamp * 1000l);
Date startDate = new Date(stepsStreaks.maximum.timestamp * 1000L);
Date endDate = DateTimeUtils.shiftByDays(startDate, stepsStreaks.maximum.days - 1); //first day is 1 not 0
//date_maximum_value.setText(DateTimeUtils.formatDate(new Date(stepsStreaks.maximum.timestamp * 1000l)));
date_maximum_value.setText(DateTimeUtils.formatDateRange(startDate, endDate));
}
if (stepsStreaks.total.steps > 0 || backgroundFinished) {
if (stepsStreaks.total.steps > 0 || backgroundTaskFinished) {
total.setVisibility(View.VISIBLE);
days_total_label.setText("Achievement\n rate");
days_total_label.setText(R.string.steps_streaks_achievement_rate);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//labels here have diferent meaning, so we must also add proper hint
days_total_label.setTooltipText(getString(R.string.steps_streaks_total_days_hint_totals));
days_total.setTooltipText(getString(R.string.steps_streaks_total_days_hint_totals));
date_total_label.setTooltipText(getString(R.string.steps_streaks_total_steps_hint_totals));
}
days_total.setText(String.format("%.1f%%", 0.0));
if (stepsStreaks.total.total_days > 0) {
days_total.setText(String.format("%.1f%%", (float) stepsStreaks.total.days / stepsStreaks.total.total_days * 100));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
total_total.setTooltipText(String.format(getString(R.string.steps_streaks_total_steps_average_hint), stepsStreaks.total.steps / stepsStreaks.total.total_days));
}
}
if (stepsStreaks.total.timestamp > 0) {
date_total_value.setVisibility(View.VISIBLE);
date_total_value.setText(String.format("Since %s", DateTimeUtils.formatDate(new Date(stepsStreaks.total.timestamp * 1000l))));
date_total_value.setText(String.format(getString(R.string.steps_streaks_since_date), DateTimeUtils.formatDate(new Date(stepsStreaks.total.timestamp * 1000L))));
} else {
date_total_value.setVisibility(View.GONE);
}
@ -174,12 +194,12 @@ public class StepStreaksDashboard extends DialogFragment {
@Override
protected void doInBackground(DBHandler db) {
switch (period) {
case "current":
calculateStreakData(db, "current", gbDevice, goal);
case PERIOD_CURRENT:
calculateStreakData(db, PERIOD_CURRENT, gbDevice, stepsGoal);
break;
case "totals":
calculateStreakData(db, "totals", gbDevice, goal);
case PERIOD_TOTALS:
calculateStreakData(db, PERIOD_TOTALS, gbDevice, stepsGoal);
break;
}
}
@ -194,8 +214,8 @@ public class StepStreaksDashboard extends DialogFragment {
super.onPostExecute(o);
FragmentActivity activity = getActivity();
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
if (period.equals("totals")) {
backgroundFinished = true;
if (period.equals(PERIOD_TOTALS)) {
backgroundTaskFinished = true;
indicate_progress(false);
}
populateData();
@ -219,7 +239,7 @@ public class StepStreaksDashboard extends DialogFragment {
DailyTotals dailyTotals = new DailyTotals();
ActivitySample firstSample = dailyTotals.getFirstSample(db, device);
Calendar firstDate = Calendar.getInstance();
firstDate.setTime(DateTimeUtils.shiftByDays(new Date(firstSample.getTimestamp() * 1000l), -1));
firstDate.setTime(DateTimeUtils.shiftByDays(new Date(firstSample.getTimestamp() * 1000L), -1));
//go one day back, to ensure we are before the first day, to calculate first day data as well
while (true) {
@ -250,12 +270,12 @@ public class StepStreaksDashboard extends DialogFragment {
Date newDate = DateTimeUtils.shiftByDays(new Date(day.getTimeInMillis()), -1);
day.setTime(newDate);
} else {
if (period.equals("current")) {
if (period.equals(PERIOD_CURRENT)) {
stepsStreaks.current.days = streak_days;
stepsStreaks.current.steps = streak_steps;
stepsStreaks.current.timestamp = timestamp;
return;
} else if (period.equals("totals")) {
} else if (period.equals(PERIOD_TOTALS)) {
//reset max
if (streak_days > stepsStreaks.maximum.days) {
stepsStreaks.maximum.steps = streak_steps;
@ -271,7 +291,7 @@ public class StepStreaksDashboard extends DialogFragment {
streak_steps = 0;
Date newDate = DateTimeUtils.shiftByDays(new Date(day.getTimeInMillis()), -1);
day.setTime(newDate);
if (day.before(firstDate) || day.get(Calendar.YEAR) < 2015) { //avoid rolling back too far, if the data has a timestamp 0 (Fossil...)
if (day.before(firstDate) || day.get(Calendar.YEAR) < MAX_YEAR) { //avoid rolling back too far, if the data has a timestamp 0 (Fossil...)
return;
}
}

View File

@ -43,20 +43,16 @@
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_steps_streaks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
<ImageView
android:id="@+id/steps_streaks_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|end"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="0dp"
android:layout_weight="0"
android:visibility="gone"
app:srcCompat="@drawable/ic_events_gold" />
android:layout_marginStart="5dp"
android:layout_marginEnd="0dp"
android:visibility="visible"
app:srcCompat="@drawable/ic_events" />
</RelativeLayout>

View File

@ -29,19 +29,16 @@
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_steps_streaks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/steps_streaks_button"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|end"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="0dp"
android:visibility="gone"
app:srcCompat="@drawable/ic_events_gold" />
android:layout_alignParentTop="true"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:visibility="visible"
app:srcCompat="@drawable/ic_events" />
</RelativeLayout>

View File

@ -17,11 +17,11 @@
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="Average\n steps"
android:tooltipText="Average steps per day"
android:text="@string/steps_streaks_average_steps"
android:textAllCaps="true"
android:textColor="@color/accent"
android:textStyle="bold" />
android:textStyle="bold"
android:tooltipText="@string/step_streak_average_steps_hint" />
<TextView
android:id="@+id/step_streak_average_value"
@ -33,6 +33,7 @@
android:maxLines="1"
android:scrollHorizontally="false"
android:text="15000"
android:textSize="24sp" />
android:textSize="24sp"
android:tooltipText="@string/step_streak_average_steps_hint" />
</LinearLayout>

View File

@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="20dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<TextView
@ -17,7 +17,7 @@
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="Ongoing"
android:text="@string/step_streak_ongoing"
android:textAllCaps="true"
android:textSize="24sp"
android:textStyle="bold" />
@ -32,8 +32,7 @@
android:layout_weight="1"
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="date" />
android:scrollHorizontally="false" />
<LinearLayout
android:layout_width="match_parent"

View File

@ -19,11 +19,11 @@
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="Days\n"
android:tooltipText="Number of consecutive days with steps goal being reached"
android:text="@string/steps_streaks_streak_days"
android:textAllCaps="true"
android:textColor="@color/accent"
android:textStyle="bold" />
android:textStyle="bold"
android:tooltipText="@string/step_streak_days_hint" />
<TextView
android:id="@+id/step_streak_days_value"
@ -35,6 +35,7 @@
android:maxLines="1"
android:scrollHorizontally="false"
android:text="9150000"
android:textSize="24sp" />
android:textSize="24sp"
android:tooltipText="@string/step_streak_days_hint" />
</LinearLayout>

View File

@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="20dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<TextView
@ -17,7 +17,7 @@
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="Longest"
android:text="@string/step_streak_longest"
android:textAllCaps="true"
android:textSize="24sp"
android:textStyle="bold" />
@ -32,8 +32,7 @@
android:layout_weight="1"
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="date" />
android:scrollHorizontally="false" />
<LinearLayout

View File

@ -11,17 +11,18 @@
<TextView
android:id="@+id/step_streak_total_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="Total\n steps"
android:tooltipText="Total number of steps in the whole streak"
android:text="@string/steps_streaks_total_steps"
android:textAllCaps="true"
android:textColor="@color/accent"
android:textStyle="bold" />
android:textStyle="bold"
android:tooltipText="@string/steps_streaks_total_steps_hint" />
<TextView
android:id="@+id/step_streak_total_value"
@ -33,6 +34,8 @@
android:maxLines="1"
android:scrollHorizontally="false"
android:text="9150000"
android:textSize="24sp" />
android:textSize="24sp"
android:tooltipText="@string/steps_streaks_total_steps_hint" />
</LinearLayout>

View File

@ -5,8 +5,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:orientation="vertical"
>
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
@ -18,7 +17,7 @@
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="Total"
android:text="@string/step_streak_total"
android:textAllCaps="true"
android:textSize="24sp"
android:textStyle="bold" />
@ -33,8 +32,7 @@
android:layout_weight="1"
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="date" />
android:scrollHorizontally="false" />
<LinearLayout
android:layout_width="match_parent"

View File

@ -8,8 +8,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:gravity="center|center_vertical"
android:minWidth="1000dp"
android:orientation="vertical">
@ -24,24 +24,29 @@
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="Steps streaks"
android:tooltipText="Series of consecutive days without interruption with steps goal being reached"
android:text="@string/steps_streaks"
android:textAllCaps="true"
android:textSize="24sp"
android:textStyle="bold" />
android:textStyle="bold"
android:tooltipText="@string/steps_streaks_hint" />
<include layout="@layout/steps_streak_current_line_layout"
android:visibility="gone"/>
<include
layout="@layout/steps_streak_current_line_layout"
android:visibility="gone" />
<include layout="@layout/steps_streak_maximum_line_layout" android:visibility="gone" />
<include
layout="@layout/steps_streak_maximum_line_layout"
android:visibility="gone" />
<include layout="@layout/steps_streak_total_line_layout" android:visibility="gone" />
<include
layout="@layout/steps_streak_total_line_layout"
android:visibility="gone" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:layout_marginBottom="0dp"
android:gravity="center"
android:orientation="vertical">
@ -57,7 +62,6 @@
android:layout_width="171dp"
android:layout_height="171dp"
android:indeterminate="true" />
</RelativeLayout>

View File

@ -1730,5 +1730,21 @@
<string name="connection_over_bt_classic">Connection over Bluetooth classic</string>
<string name="autoconnect_from_device_title">Connect on connection from device</string>
<string name="autoconnect_from_device_summary">Establish a connection when connection is initiated by device, like headphones</string>
<string name="stepsStreakCalculating">Calculating steps data</string>
<!-- related to steps streak view -->
<string name="steps_streaks_since_date">Since %s</string>
<string name="steps_streaks_achievement_rate">Achievement\n rate</string>
<string name="steps_streaks_total_days_hint_totals">Percentage of days with achieved goal in relation to all days with steps</string>
<string name="steps_streaks_total_steps_hint_totals">Total number of steps ever recorded</string>
<string name="steps_streaks_total_steps_average_hint">Total average %d steps per day</string>
<string name="step_streak_days_hint">Number of consecutive days with steps goal being reached</string>
<string name="steps_streaks_total_steps_hint">Total number of steps in the whole streak</string>
<string name="step_streak_average_steps_hint">Average steps per day of the streak</string>
<string name="step_streak_ongoing">Ongoing</string>
<string name="step_streak_longest">Longest</string>
<string name="step_streak_total">Total</string>
<string name="steps_streaks">Steps streaks</string>
<string name="steps_streaks_hint">Series of consecutive days without interruption with steps goal being reached</string>
<string name="steps_streaks_total_steps">Total\nsteps</string>
<string name="steps_streaks_streak_days">Streak\nDays</string>
<string name="steps_streaks_average_steps">Average\nsteps</string>
</resources>