mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Load activity details async
This commit is contained in:
parent
b2c88b47d5
commit
32615126d1
@ -29,6 +29,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.util.TypedValue;
|
||||
@ -48,6 +49,7 @@ import androidx.gridlayout.widget.GridLayout;
|
||||
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
@ -74,6 +76,7 @@ import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
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.ActivitySummaryParser;
|
||||
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.messages.FitRecord;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
||||
@ -226,8 +230,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
public boolean onLongClick(View v) {
|
||||
workoutValueFormatter.toggleRawData();
|
||||
if (currentItem != null) {
|
||||
makeSummaryHeader(currentItem);
|
||||
makeSummaryContent(currentItem);
|
||||
refreshFromCurrentItem();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -256,11 +259,10 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String name = input.getText().toString();
|
||||
if (name.length() < 1) name = null;
|
||||
if (name.isEmpty()) name = null;
|
||||
currentItem.setName(name);
|
||||
currentItem.update();
|
||||
makeSummaryHeader(currentItem);
|
||||
makeSummaryContent(currentItem);
|
||||
refreshFromCurrentItem();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
|
||||
@ -362,8 +364,14 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
}
|
||||
|
||||
private void refreshFromCurrentItem() {
|
||||
// Update the summary header right away - but it will be refreshed once the item is reloaded
|
||||
makeSummaryHeader(currentItem);
|
||||
makeSummaryContent(currentItem);
|
||||
|
||||
DetailsAsyncTask detailsAsyncTask = new DetailsAsyncTask();
|
||||
detailsAsyncTask.execute(currentItem);
|
||||
|
||||
ProgressBar loadingProgressbar = findViewById(R.id.loading_progressbar);
|
||||
loadingProgressbar.setVisibility(View.VISIBLE);
|
||||
|
||||
activitySummariesChartFragment.setDateAndGetData(
|
||||
getTrackFile(),
|
||||
@ -425,14 +433,10 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
return list;
|
||||
}
|
||||
|
||||
private void makeSummaryContent(BaseActivitySummary item) {
|
||||
final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator();
|
||||
final ActivitySummaryParser summaryParser = coordinator.getActivitySummaryParser(gbDevice, this);
|
||||
|
||||
private void makeSummaryContent(final ActivitySummaryJsonSummary activitySummaryJsonSummary) {
|
||||
//make view of data from summaryData of item
|
||||
LinearLayout fieldLayout = findViewById(R.id.summaryDetails);
|
||||
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
|
||||
if (data == null) return;
|
||||
|
||||
@ -760,4 +764,23 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
||||
.findFirst()
|
||||
.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -165,6 +165,15 @@
|
||||
android:layout_height="match_parent"
|
||||
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
|
||||
android:id="@+id/summaryDetails"
|
||||
android:layout_width="fill_parent"
|
||||
@ -174,12 +183,12 @@
|
||||
<FrameLayout
|
||||
android:id="@+id/chartsFragmentHolder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="300dp"></FrameLayout>
|
||||
android:layout_height="300dp" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/gpsFragmentHolder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="300dp"></FrameLayout>
|
||||
android:layout_height="300dp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
Loading…
Reference in New Issue
Block a user