Rework timer in tunnel detail
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
8dbd464fa4
commit
c3d97acb31
@ -34,18 +34,6 @@ public class TunnelDetailFragment extends BaseFragment {
|
|||||||
@Nullable private Timer timer;
|
@Nullable private Timer timer;
|
||||||
@Nullable private State lastState = State.TOGGLE;
|
@Nullable private State lastState = State.TOGGLE;
|
||||||
|
|
||||||
private static class StatsTimerTask extends TimerTask {
|
|
||||||
final TunnelDetailFragment tdf;
|
|
||||||
private StatsTimerTask(final TunnelDetailFragment tdf) {
|
|
||||||
this.tdf = tdf;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
tdf.updateStats();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -70,7 +58,12 @@ public class TunnelDetailFragment extends BaseFragment {
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
timer = new Timer();
|
timer = new Timer();
|
||||||
timer.scheduleAtFixedRate(new StatsTimerTask(this), 0, 1000);
|
timer.scheduleAtFixedRate(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
updateStats();
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -127,11 +120,14 @@ public class TunnelDetailFragment extends BaseFragment {
|
|||||||
private void updateStats() {
|
private void updateStats() {
|
||||||
if (binding == null || !isResumed())
|
if (binding == null || !isResumed())
|
||||||
return;
|
return;
|
||||||
final State state = binding.getTunnel().getState();
|
final Tunnel tunnel = binding.getTunnel();
|
||||||
|
if (tunnel == null)
|
||||||
|
return;
|
||||||
|
final State state = tunnel.getState();
|
||||||
if (state != State.UP && lastState == state)
|
if (state != State.UP && lastState == state)
|
||||||
return;
|
return;
|
||||||
lastState = state;
|
lastState = state;
|
||||||
binding.getTunnel().getStatisticsAsync().whenComplete((statistics, throwable) -> {
|
tunnel.getStatisticsAsync().whenComplete((statistics, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
for (int i = 0; i < binding.peersLayout.getChildCount(); ++i) {
|
for (int i = 0; i < binding.peersLayout.getChildCount(); ++i) {
|
||||||
final TunnelDetailPeerBinding peer = DataBindingUtil.getBinding(binding.peersLayout.getChildAt(i));
|
final TunnelDetailPeerBinding peer = DataBindingUtil.getBinding(binding.peersLayout.getChildAt(i));
|
||||||
|
Loading…
Reference in New Issue
Block a user