Load activity details async

This commit is contained in:
José Rebelo 2024-10-05 22:08:21 +01:00
parent b2c88b47d5
commit 32615126d1
2 changed files with 45 additions and 13 deletions

View File

@ -29,6 +29,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.util.TypedValue; import android.util.TypedValue;
@ -48,6 +49,7 @@ import androidx.gridlayout.widget.GridLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TableRow; import android.widget.TableRow;
import android.widget.TextView; import android.widget.TextView;
@ -74,6 +76,7 @@ import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -95,6 +98,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryItems;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryJsonSummary; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryJsonSummary;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryParser; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryParser;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack; import nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack;
import nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.FitFile; import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.FitFile;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.messages.FitRecord; import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.messages.FitRecord;
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils; import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
@ -226,8 +230,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
workoutValueFormatter.toggleRawData(); workoutValueFormatter.toggleRawData();
if (currentItem != null) { if (currentItem != null) {
makeSummaryHeader(currentItem); refreshFromCurrentItem();
makeSummaryContent(currentItem);
} }
return false; return false;
} }
@ -256,11 +259,10 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String name = input.getText().toString(); String name = input.getText().toString();
if (name.length() < 1) name = null; if (name.isEmpty()) name = null;
currentItem.setName(name); currentItem.setName(name);
currentItem.update(); currentItem.update();
makeSummaryHeader(currentItem); refreshFromCurrentItem();
makeSummaryContent(currentItem);
} }
}) })
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
@ -362,8 +364,14 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
} }
private void refreshFromCurrentItem() { private void refreshFromCurrentItem() {
// Update the summary header right away - but it will be refreshed once the item is reloaded
makeSummaryHeader(currentItem); makeSummaryHeader(currentItem);
makeSummaryContent(currentItem);
DetailsAsyncTask detailsAsyncTask = new DetailsAsyncTask();
detailsAsyncTask.execute(currentItem);
ProgressBar loadingProgressbar = findViewById(R.id.loading_progressbar);
loadingProgressbar.setVisibility(View.VISIBLE);
activitySummariesChartFragment.setDateAndGetData( activitySummariesChartFragment.setDateAndGetData(
getTrackFile(), getTrackFile(),
@ -425,14 +433,10 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
return list; return list;
} }
private void makeSummaryContent(BaseActivitySummary item) { private void makeSummaryContent(final ActivitySummaryJsonSummary activitySummaryJsonSummary) {
final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator();
final ActivitySummaryParser summaryParser = coordinator.getActivitySummaryParser(gbDevice, this);
//make view of data from summaryData of item //make view of data from summaryData of item
LinearLayout fieldLayout = findViewById(R.id.summaryDetails); LinearLayout fieldLayout = findViewById(R.id.summaryDetails);
fieldLayout.removeAllViews(); //remove old widgets fieldLayout.removeAllViews(); //remove old widgets
ActivitySummaryJsonSummary activitySummaryJsonSummary = new ActivitySummaryJsonSummary(summaryParser, item);
Map<String, List<Pair<String, ActivitySummaryEntry>>> data = activitySummaryJsonSummary.getSummaryGroupedList(); //get list, grouped by groups Map<String, List<Pair<String, ActivitySummaryEntry>>> data = activitySummaryJsonSummary.getSummaryGroupedList(); //get list, grouped by groups
if (data == null) return; if (data == null) return;
@ -760,4 +764,23 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
.findFirst() .findFirst()
.orElse(null); .orElse(null);
} }
private class DetailsAsyncTask extends AsyncTask<BaseActivitySummary, Void, ActivitySummaryJsonSummary> {
@Override
protected ActivitySummaryJsonSummary doInBackground(final BaseActivitySummary... baseActivitySummaries) {
final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator();
final ActivitySummaryParser summaryParser = coordinator.getActivitySummaryParser(gbDevice, ActivitySummaryDetail.this);
final ActivitySummaryJsonSummary activitySummaryJsonSummary = new ActivitySummaryJsonSummary(summaryParser, baseActivitySummaries[0]);
activitySummaryJsonSummary.getSummaryGroupedList();
return activitySummaryJsonSummary;
}
@Override
protected void onPostExecute(final ActivitySummaryJsonSummary activitySummaryJsonSummary) {
makeSummaryContent(activitySummaryJsonSummary);
findViewById(R.id.loading_progressbar).setVisibility(View.GONE);
}
}
} }

View File

@ -165,6 +165,15 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<ProgressBar
android:id="@+id/loading_progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:indeterminate="true"
android:indeterminateOnly="true" />
<LinearLayout <LinearLayout
android:id="@+id/summaryDetails" android:id="@+id/summaryDetails"
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -174,12 +183,12 @@
<FrameLayout <FrameLayout
android:id="@+id/chartsFragmentHolder" android:id="@+id/chartsFragmentHolder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="300dp"></FrameLayout> android:layout_height="300dp" />
<FrameLayout <FrameLayout
android:id="@+id/gpsFragmentHolder" android:id="@+id/gpsFragmentHolder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="300dp"></FrameLayout> android:layout_height="300dp" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>