mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 12:56:49 +01:00
Add filter to Sports Activities
This commit is contained in:
parent
e9563057de
commit
f4bf457232
@ -35,6 +35,10 @@ public abstract class AbstractListActivity<T> extends AbstractGBActivity {
|
||||
this.itemAdapter.loadItems();
|
||||
}
|
||||
|
||||
public void setActivityKindFilter(int activityKind){
|
||||
this.itemAdapter.setActivityKindFilter(activityKind);
|
||||
}
|
||||
|
||||
public AbstractItemAdapter<T> getItemAdapter() {
|
||||
return itemAdapter;
|
||||
}
|
||||
|
@ -32,8 +32,10 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.content.FileProvider;
|
||||
@ -46,6 +48,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -54,6 +57,7 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.adapter.ActivitySummariesAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummary;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
||||
@ -67,6 +71,7 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ActivitySummariesActivity.class);
|
||||
private GBDevice mGBDevice;
|
||||
private SwipeRefreshLayout swipeLayout;
|
||||
LinkedHashMap<String , Integer> activityKindMap = new LinkedHashMap<>(1);
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
@ -125,7 +130,8 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setItemAdapter(new ActivitySummariesAdapter(this, mGBDevice));
|
||||
int activityFilter=0;
|
||||
setItemAdapter(new ActivitySummariesAdapter(this, mGBDevice,activityFilter));
|
||||
|
||||
getItemListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
@ -233,6 +239,51 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
|
||||
fetchTrackData();
|
||||
}
|
||||
});
|
||||
|
||||
activityKindMap = fillKindMap();
|
||||
addItemsOnSpinner();
|
||||
addListenerOnSpinnerItemSelection();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private LinkedHashMap fillKindMap(){
|
||||
LinkedHashMap<String , Integer> newMap = new LinkedHashMap<>(1); //reset
|
||||
newMap.put("All Activities", 0);
|
||||
for (BaseActivitySummary item : getItemAdapter().getItems()) {
|
||||
String activityName = ActivityKind.asString(item.getActivityKind(), this);
|
||||
if (!newMap.containsKey(item.getActivityKind())) {
|
||||
newMap.put(activityName, item.getActivityKind());
|
||||
}
|
||||
}
|
||||
return newMap;
|
||||
}
|
||||
|
||||
public void addListenerOnSpinnerItemSelection() {
|
||||
Spinner spinner = (Spinner) findViewById(R.id.select_kind);
|
||||
spinner.setOnItemSelectedListener(new CustomOnItemSelectedListener());
|
||||
}
|
||||
|
||||
public class CustomOnItemSelectedListener implements AdapterView.OnItemSelectedListener {
|
||||
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
|
||||
setActivityKindFilter(activityKindMap.get(parent.getItemAtPosition(pos)));
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addItemsOnSpinner() {
|
||||
Spinner spinner = (Spinner) findViewById(R.id.select_kind);
|
||||
ArrayList<String> spinnerArray = new ArrayList<>(activityKindMap.keySet());
|
||||
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
|
||||
android.R.layout.simple_spinner_dropdown_item, spinnerArray);
|
||||
spinner.setAdapter(dataAdapter);
|
||||
}
|
||||
|
||||
public void resetFetchTimestampToChosenDate() {
|
||||
@ -278,14 +329,6 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
|
||||
startActivity(ActivitySummaryDetailIntent);
|
||||
}
|
||||
|
||||
private void showTrack(String gpxTrack) {
|
||||
try {
|
||||
AndroidUtils.viewFile(gpxTrack, Intent.ACTION_VIEW, this);
|
||||
} catch (IOException e) {
|
||||
GB.toast(this, "Unable to display GPX track: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchTrackData() {
|
||||
if (mGBDevice.isInitialized() && !mGBDevice.isBusy()) {
|
||||
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_GPS_TRACKS);
|
||||
@ -315,4 +358,7 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -59,6 +59,10 @@ public abstract class AbstractItemAdapter<T> extends ArrayAdapter<T> {
|
||||
this.horizontalAlignment = horizontalAlignment;
|
||||
}
|
||||
|
||||
public void setActivityKindFilter(int activityKind){
|
||||
this.setActivityKindFilter(activityKind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup parent) {
|
||||
T item = getItem(position);
|
||||
|
@ -37,10 +37,12 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
public class ActivitySummariesAdapter extends AbstractItemAdapter<BaseActivitySummary> {
|
||||
private final GBDevice device;
|
||||
private int activityKindFilter;
|
||||
|
||||
public ActivitySummariesAdapter(Context context, GBDevice device) {
|
||||
public ActivitySummariesAdapter(Context context, GBDevice device, int activityKindFilter) {
|
||||
super(context);
|
||||
this.device = device;
|
||||
this.activityKindFilter = activityKindFilter;
|
||||
loadItems();
|
||||
}
|
||||
|
||||
@ -51,7 +53,17 @@ public class ActivitySummariesAdapter extends AbstractItemAdapter<BaseActivitySu
|
||||
Device dbDevice = DBHelper.findDevice(device, handler.getDaoSession());
|
||||
|
||||
QueryBuilder<BaseActivitySummary> qb = summaryDao.queryBuilder();
|
||||
qb.where(BaseActivitySummaryDao.Properties.DeviceId.eq(dbDevice.getId())).orderDesc(BaseActivitySummaryDao.Properties.StartTime);
|
||||
if (activityKindFilter !=0){
|
||||
qb.where(
|
||||
BaseActivitySummaryDao.Properties.DeviceId.eq(dbDevice.getId()),
|
||||
BaseActivitySummaryDao.Properties.ActivityKind.eq(activityKindFilter))
|
||||
.orderDesc(BaseActivitySummaryDao.Properties.StartTime);
|
||||
}else{
|
||||
qb.where(
|
||||
BaseActivitySummaryDao.Properties.DeviceId.eq(
|
||||
dbDevice.getId())).orderDesc(BaseActivitySummaryDao.Properties.StartTime);
|
||||
}
|
||||
|
||||
List<BaseActivitySummary> allSummaries = qb.build().list();
|
||||
setItems(allSummaries, true);
|
||||
} catch (Exception e) {
|
||||
@ -59,6 +71,10 @@ public class ActivitySummariesAdapter extends AbstractItemAdapter<BaseActivitySu
|
||||
}
|
||||
}
|
||||
|
||||
public void setActivityKindFilter(int filter){
|
||||
this.activityKindFilter=filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName(BaseActivitySummary item) {
|
||||
|
||||
|
@ -4,17 +4,29 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/list_activity_swipe_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/itemListView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<Spinner
|
||||
android:id="@+id/select_kind"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:spinnerMode="dialog" />
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/list_activity_swipe_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/itemListView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
|
Loading…
Reference in New Issue
Block a user