refreshing overview plugin

This commit is contained in:
Milos Kozak 2016-06-17 16:14:04 +02:00
parent d74d54931b
commit fbb4f1973c

View file

@ -4,6 +4,7 @@ import android.app.Activity;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -45,6 +46,10 @@ public class OverviewFragment extends Fragment implements PluginBase {
TextView deltaView; TextView deltaView;
GraphView bgGraph; GraphView bgGraph;
boolean visibleNow = false;
Handler loopHandler = new Handler();
Runnable refreshLoop = null;
public OverviewFragment() { public OverviewFragment() {
super(); super();
registerBus(); registerBus();
@ -93,6 +98,25 @@ public class OverviewFragment extends Fragment implements PluginBase {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (refreshLoop == null) {
refreshLoop = new Runnable() {
@Override
public void run() {
if (visibleNow) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateData();
}
});
}
loopHandler.postDelayed(refreshLoop, 60 * 1000l);
}
};
loopHandler.postDelayed(refreshLoop, 60 * 1000l);
}
} }
@Override @Override
@ -270,9 +294,9 @@ public class OverviewFragment extends Fragment implements PluginBase {
if (isVisibleToUser) { if (isVisibleToUser) {
updateData(); updateData();
log.debug("Overview visible"); visibleNow = true;
} else { } else {
log.debug("Overview hidden"); visibleNow = false;
} }
} }