mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
retroshare-service android check better status
The code is a bit clumsy but it report more accurate information this way
This commit is contained in:
parent
7113eb7bfc
commit
4a5d5762b7
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* RetroShare
|
||||
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@altermundi.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@ -20,9 +20,9 @@ package org.retroshare.service;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import org.retroshare.service.R;
|
||||
|
||||
|
||||
public class RetroShareServiceControlActivity extends Activity
|
||||
@ -39,14 +39,19 @@ public class RetroShareServiceControlActivity extends Activity
|
||||
{
|
||||
if (RetroShareServiceAndroid.isRunning(RetroShareServiceControlActivity.this))
|
||||
{
|
||||
serviceStarting = false;
|
||||
serviceStopping = true;
|
||||
button.setText("Stopping...");
|
||||
RetroShareServiceAndroid.stop(RetroShareServiceControlActivity.this);
|
||||
button.setText("Start");
|
||||
}
|
||||
else
|
||||
{
|
||||
button.setText("Starting...");
|
||||
RetroShareServiceAndroid.start(RetroShareServiceControlActivity.this);
|
||||
button.setText("Stop");
|
||||
serviceStarting = true;
|
||||
serviceStopping = false;
|
||||
}
|
||||
mStatusUpdateHandler.postDelayed(mUpdateStatusTask, 500);
|
||||
}
|
||||
});
|
||||
|
||||
@ -60,5 +65,44 @@ public class RetroShareServiceControlActivity extends Activity
|
||||
|
||||
final Button button = (Button) findViewById(R.id.startStopButton);
|
||||
button.setText(RetroShareServiceAndroid.isRunning(this) ? "Stop" : "Start");
|
||||
|
||||
mStatusUpdateHandler.removeCallbacks(mUpdateStatusTask);
|
||||
mStatusUpdateHandler.postDelayed(mUpdateStatusTask, 500);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
mStatusUpdateHandler.removeCallbacks(mUpdateStatusTask);
|
||||
}
|
||||
|
||||
public void updateServiceStatus()
|
||||
{
|
||||
final Button button = (Button) findViewById(R.id.startStopButton);
|
||||
|
||||
if(serviceStarting && RetroShareServiceAndroid.isRunning(this))
|
||||
{
|
||||
mStatusUpdateHandler.removeCallbacks(mUpdateStatusTask);
|
||||
serviceStarting = false;
|
||||
serviceStopping = false;
|
||||
button.setText("Stop");
|
||||
}
|
||||
else if (serviceStopping && !RetroShareServiceAndroid.isRunning(this))
|
||||
{
|
||||
mStatusUpdateHandler.removeCallbacks(mUpdateStatusTask);
|
||||
serviceStarting = false;
|
||||
serviceStopping = false;
|
||||
button.setText("Start");
|
||||
}
|
||||
else if(serviceStarting || serviceStopping)
|
||||
mStatusUpdateHandler.postDelayed(mUpdateStatusTask, 500);
|
||||
}
|
||||
|
||||
private Runnable mUpdateStatusTask = new Runnable()
|
||||
{ public void run() { updateServiceStatus(); } };
|
||||
|
||||
private boolean serviceStarting = false;
|
||||
private boolean serviceStopping = false;
|
||||
private Handler mStatusUpdateHandler = new Handler();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user