Converted LogManagerControlActivity to use the SdServer LogManager instance rather than a separate one - just in case it causes problems...

This commit is contained in:
Graham Jones
2022-01-10 19:40:20 +00:00
parent fefca589dd
commit 783abd93f0
2 changed files with 74 additions and 37 deletions

View File

@@ -7,6 +7,7 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.Handler;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
@@ -27,6 +28,9 @@ public class LogManagerControlActivity extends AppCompatActivity {
private Context mContext; private Context mContext;
private UiTimer mUiTimer; private UiTimer mUiTimer;
private ArrayList<HashMap<String, String>> mEventsList; private ArrayList<HashMap<String, String>> mEventsList;
private SdServiceConnection mConnection;
private OsdUtil mUtil;
final Handler serverStatusHandler = new Handler();
@Override @Override
@@ -34,6 +38,10 @@ public class LogManagerControlActivity extends AppCompatActivity {
Log.v(TAG, "onCreate()"); Log.v(TAG, "onCreate()");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mContext = this; mContext = this;
mUtil = new OsdUtil(this, serverStatusHandler);
mConnection = new SdServiceConnection(this);
mUtil.bindToServer(this, mConnection);
setContentView(R.layout.activity_log_manager_control); setContentView(R.layout.activity_log_manager_control);
Button authBtn = Button authBtn =
@@ -51,17 +59,19 @@ public class LogManagerControlActivity extends AppCompatActivity {
ListView lv = (ListView) findViewById(R.id.eventLogListView); ListView lv = (ListView) findViewById(R.id.eventLogListView);
lv.setOnItemClickListener(onEventListClick); lv.setOnItemClickListener(onEventListClick);
mLm = new LogManager(this);
updateUi();
} }
@Override @Override
protected void onStart() { protected void onStart() {
Log.v(TAG, "onStart()");
super.onStart(); super.onStart();
startUiTimer(); //startUiTimer();
}
@Override
protected void onStop() {
super.onStop();
mUtil.unbindFromServer(this, mConnection);
} }
@Override @Override
@@ -70,11 +80,32 @@ public class LogManagerControlActivity extends AppCompatActivity {
stopUiTimer(); stopUiTimer();
} }
@Override
protected void onResume() {
Log.v(TAG,"onResume()");
super.onResume();
startUiTimer();
// We want the UI to update as soon as it is displayed, but it takes a finite time for
// the mConnection to bind to the service, so we delay half a second to give it chance
// to connect before trying to update the UI for the first time (it happens again periodically using the uiTimer)
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Log.v(TAG,"onResume(): Updating UI after delay");
updateUi();
}
}, 100);
}
private void updateUi() { private void updateUi() {
//Log.v(TAG,"updateUi()"); //Log.v(TAG,"updateUi()");
TextView tv; TextView tv;
Button btn; Button btn;
if (mConnection.mBound) {
mLm = mConnection.mSdServer.mLm;
// Local Database Information // Local Database Information
tv = (TextView) findViewById(R.id.num_local_events_tv); tv = (TextView) findViewById(R.id.num_local_events_tv);
int eventCount = mLm.getLocalEventsCount(true); int eventCount = mLm.getLocalEventsCount(true);
@@ -105,7 +136,13 @@ public class LogManagerControlActivity extends AppCompatActivity {
tv.setText("NOT AUTHENTICATED"); tv.setText("NOT AUTHENTICATED");
btn.setText("Log In"); btn.setText("Log In");
} }
} else {
Log.e(TAG, "ERROR: Not connected to SDServer - not updating UI");
} }
}
//updateUi();
View.OnClickListener onAuth = View.OnClickListener onAuth =
new View.OnClickListener() { new View.OnClickListener() {
@@ -196,17 +233,17 @@ public class LogManagerControlActivity extends AppCompatActivity {
}; };
/* /*
* Start the timer that will upload data to the remote server after a given period. * Start the timer that will update the user interface every 5 seconds..
*/ */
private void startUiTimer() { private void startUiTimer() {
if (mUiTimer != null) { if (mUiTimer != null) {
Log.v(TAG, "startRemoteLogTimer -timer already running - cancelling it"); Log.v(TAG, "startUiTimer -timer already running - cancelling it");
mUiTimer.cancel(); mUiTimer.cancel();
mUiTimer = null; mUiTimer = null;
} }
Log.v(TAG, "startRemoteLogTimer() - starting RemoteLogTimer"); Log.v(TAG, "startUiTimer() - starting UiTimer");
mUiTimer = mUiTimer =
new UiTimer(5000, 1000); new UiTimer(2000, 1000);
mUiTimer.start(); mUiTimer.start();
} }

View File

@@ -143,7 +143,7 @@ public class SdServer extends Service implements SdDataReceiver {
private final IBinder mBinder = new SdBinder(); private final IBinder mBinder = new SdBinder();
private LogManager mLm; public LogManager mLm;
/** /**
* class to handle binding the MainApp activity to this service * class to handle binding the MainApp activity to this service