mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 11:26:47 +01:00
Amazfit Bip: limit the activities to the currently selected device in Control Center
Also don't reverse the results, but sort in the query
This commit is contained in:
parent
b1e337d9b7
commit
5af353d6dc
@ -77,7 +77,7 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
|
|||||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setItemAdapter(new ActivitySummariesAdapter(this));
|
setItemAdapter(new ActivitySummariesAdapter(this, mGBDevice));
|
||||||
|
|
||||||
getItemListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
getItemListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,29 +3,35 @@ package nodomain.freeyourgadget.gadgetbridge.adapter;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.greenrobot.dao.query.QueryBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
|
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao;
|
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
public class ActivitySummariesAdapter extends AbstractItemAdapter<BaseActivitySummary> {
|
public class ActivitySummariesAdapter extends AbstractItemAdapter<BaseActivitySummary> {
|
||||||
public ActivitySummariesAdapter(Context context) {
|
public ActivitySummariesAdapter(Context context, GBDevice device) {
|
||||||
super(context);
|
super(context);
|
||||||
loadItems();
|
loadItems(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadItems() {
|
public void loadItems(GBDevice device) {
|
||||||
try (DBHandler handler = GBApplication.acquireDB()) {
|
try (DBHandler handler = GBApplication.acquireDB()) {
|
||||||
BaseActivitySummaryDao summaryDao = handler.getDaoSession().getBaseActivitySummaryDao();
|
BaseActivitySummaryDao summaryDao = handler.getDaoSession().getBaseActivitySummaryDao();
|
||||||
List<BaseActivitySummary> allSummaries = summaryDao.loadAll();
|
Device dbDevice = DBHelper.findDevice(device, handler.getDaoSession());
|
||||||
Collections.reverse(allSummaries); //we fetch by swiping down, hence it makes sense to have most recent activities on top
|
|
||||||
|
QueryBuilder<BaseActivitySummary> qb = summaryDao.queryBuilder();
|
||||||
|
qb.where(BaseActivitySummaryDao.Properties.DeviceId.eq(dbDevice.getId())).orderDesc(BaseActivitySummaryDao.Properties.StartTime);
|
||||||
|
List<BaseActivitySummary> allSummaries = qb.build().list();
|
||||||
setItems(allSummaries, true);
|
setItems(allSummaries, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
GB.toast("Error loading activity summaries.", Toast.LENGTH_SHORT, GB.ERROR, e);
|
GB.toast("Error loading activity summaries.", Toast.LENGTH_SHORT, GB.ERROR, e);
|
||||||
|
Loading…
Reference in New Issue
Block a user