mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 10:35:50 +01:00
Amazfit Bip: add option to reset the last fetched activity (timestamp)
Show a datepicker to reset the date after which the next activity will be fetched. Also add .gpx extension to fetched activity track (if present) and make the menu entries translatable. Close #1057
This commit is contained in:
parent
134905ed6a
commit
8f6d287592
@ -1,9 +1,11 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||
|
||||
import android.app.DatePickerDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
@ -17,12 +19,14 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -63,6 +67,27 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
|
||||
getMenuInflater().inflate(R.menu.activity_list_menu, menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
boolean processed = false;
|
||||
switch (item.getItemId()) {
|
||||
case R.id.activity_action_manage_timestamp:
|
||||
resetFetchTimestampToChosenDate();
|
||||
processed = true;
|
||||
break;
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Bundle extras = getIntent().getExtras();
|
||||
@ -107,7 +132,7 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.activity_list_menu, menu);
|
||||
getMenuInflater().inflate(R.menu.activity_list_context_menu, menu);
|
||||
findViewById(R.id.fab).setVisibility(View.INVISIBLE);
|
||||
return true;
|
||||
}
|
||||
@ -188,6 +213,23 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
|
||||
});
|
||||
}
|
||||
|
||||
public void resetFetchTimestampToChosenDate() {
|
||||
final Calendar currentDate = Calendar.getInstance();
|
||||
new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
|
||||
@Override
|
||||
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
Calendar date = Calendar.getInstance();
|
||||
date.set(year, monthOfYear, dayOfMonth);
|
||||
|
||||
Long timestamp = date.getTimeInMillis() - 1000;
|
||||
SharedPreferences.Editor editor = GBApplication.getPrefs().getPreferences().edit();
|
||||
editor.remove(mGBDevice.getAddress() + "_" + "lastSportsActivityTimeMillis"); //FIXME: key reconstruction is BAD
|
||||
editor.putLong(mGBDevice.getAddress() + "_" + "lastSportsActivityTimeMillis", timestamp);
|
||||
editor.commit();
|
||||
}
|
||||
}, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||
|
@ -98,7 +98,7 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
|
||||
try {
|
||||
ActivityTrack track = parser.parse(buffer.toByteArray());
|
||||
ActivityTrackExporter exporter = createExporter();
|
||||
String fileName = FileUtils.makeValidFileName("gadgetbridge-track-" + DateTimeUtils.formatIso8601(summary.getStartTime()));
|
||||
String fileName = FileUtils.makeValidFileName("gadgetbridge-track-" + DateTimeUtils.formatIso8601(summary.getStartTime()) + ".gpx");
|
||||
File targetFile = new File(FileUtils.getExternalFilesDir(), fileName);
|
||||
|
||||
try {
|
||||
|
5
app/src/main/res/drawable/ic_reset.xml
Normal file
5
app/src/main/res/drawable/ic_reset.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M13,3c-4.97,0 -9,4.03 -9,9L1,12l3.89,3.89 0.07,0.14L9,12L6,12c0,-3.87 3.13,-7 7,-7s7,3.13 7,7 -3.13,7 -7,7c-1.93,0 -3.68,-0.79 -4.94,-2.06l-1.42,1.42C8.27,19.99 10.51,21 13,21c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,8v5l4.28,2.54 0.72,-1.21 -3.5,-2.08L13.5,8L12,8z"/>
|
||||
</vector>
|
24
app/src/main/res/menu/activity_list_context_menu.xml
Normal file
24
app/src/main/res/menu/activity_list_context_menu.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
|
||||
<item
|
||||
android:id="@+id/activity_action_select_all"
|
||||
android:icon="@drawable/ic_select_all"
|
||||
android:title="@string/select_all"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/activity_action_export"
|
||||
android:icon="@drawable/ic_share"
|
||||
android:title="@string/share"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/activity_action_delete"
|
||||
android:icon="@drawable/ic_delete_cross"
|
||||
android:title="@string/Delete"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
</menu>
|
@ -2,23 +2,9 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
|
||||
<item
|
||||
android:id="@+id/activity_action_select_all"
|
||||
android:icon="@drawable/ic_select_all"
|
||||
android:title="SELECT ALL"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/activity_action_export"
|
||||
android:icon="@drawable/ic_share"
|
||||
android:title="EXPORT"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/activity_action_delete"
|
||||
android:icon="@drawable/ic_delete_cross"
|
||||
android:title="@string/Delete"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
android:id="@+id/activity_action_manage_timestamp"
|
||||
android:icon="@drawable/ic_reset"
|
||||
android:title="@string/reset_index"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
@ -521,6 +521,9 @@
|
||||
<string name="activity_summaries">Activities</string>
|
||||
<string name="activity_type_biking">Biking</string>
|
||||
<string name="activity_type_treadmill">Treadmill</string>
|
||||
<string name="select_all">Select all</string>
|
||||
<string name="share">Share</string>
|
||||
<string name="reset_index">Reset fetch date</string>
|
||||
|
||||
<string name="kind_firmware">Firmware</string>
|
||||
<string name="kind_invalid">Invalid data</string>
|
||||
|
Loading…
Reference in New Issue
Block a user