mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-12 09:16:34 +02:00
Auto-refresh when a device finishes syncing activity data
This commit is contained in:
parent
4f5e7f0b03
commit
22b2dcfaef
@ -16,7 +16,10 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -32,6 +35,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentContainerView;
|
import androidx.fragment.app.FragmentContainerView;
|
||||||
import androidx.gridlayout.widget.GridLayout;
|
import androidx.gridlayout.widget.GridLayout;
|
||||||
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
|
|
||||||
import com.google.android.material.card.MaterialCardView;
|
import com.google.android.material.card.MaterialCardView;
|
||||||
|
|
||||||
@ -51,6 +55,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardGoalsW
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardSleepWidget;
|
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardSleepWidget;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardStepsWidget;
|
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardStepsWidget;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardTodayWidget;
|
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardTodayWidget;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.DashboardUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.DashboardUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
@ -70,6 +75,19 @@ public class DashboardFragment extends Fragment {
|
|||||||
private DashboardSleepWidget sleepWidget;
|
private DashboardSleepWidget sleepWidget;
|
||||||
private DashboardData dashboardData = new DashboardData();
|
private DashboardData dashboardData = new DashboardData();
|
||||||
|
|
||||||
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
if (action != null && action.equals(GBDevice.ACTION_DEVICE_CHANGED)) {
|
||||||
|
GBDevice dev = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||||
|
if (dev != null && !dev.isBusy()) {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
super.onCreateView(inflater, container, savedInstanceState);
|
super.onCreateView(inflater, container, savedInstanceState);
|
||||||
@ -109,20 +127,23 @@ public class DashboardFragment extends Fragment {
|
|||||||
// This prevents a hard crash when replacing the fragment in createWidget() via a FragmentManager.
|
// This prevents a hard crash when replacing the fragment in createWidget() via a FragmentManager.
|
||||||
if (isVisible) refresh();
|
if (isVisible) refresh();
|
||||||
|
|
||||||
|
IntentFilter filterLocal = new IntentFilter();
|
||||||
|
filterLocal.addAction(GBDevice.ACTION_DEVICE_CHANGED);
|
||||||
|
LocalBroadcastManager.getInstance(requireContext()).registerReceiver(mReceiver, filterLocal);
|
||||||
|
|
||||||
return dashboardView;
|
return dashboardView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
gridLayout.removeAllViews();
|
fullRefresh();
|
||||||
todayWidget = null;
|
}
|
||||||
goalsWidget = null;
|
|
||||||
stepsWidget = null;
|
@Override
|
||||||
distanceWidget = null;
|
public void onDestroy() {
|
||||||
activeTimeWidget = null;
|
LocalBroadcastManager.getInstance(requireContext()).unregisterReceiver(mReceiver);
|
||||||
sleepWidget = null;
|
super.onDestroy();
|
||||||
refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -162,6 +183,10 @@ public class DashboardFragment extends Fragment {
|
|||||||
day.setTimeInMillis(timeMillis);
|
day.setTimeInMillis(timeMillis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fullRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fullRefresh() {
|
||||||
gridLayout.removeAllViews();
|
gridLayout.removeAllViews();
|
||||||
todayWidget = null;
|
todayWidget = null;
|
||||||
goalsWidget = null;
|
goalsWidget = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user