android: bug fix, Preference tab stuck in loading when first data retrieval failed. Retry.

This commit is contained in:
Joachim Fritzsch 2013-07-15 12:02:03 +02:00
parent d473c25162
commit ee3c036f65
1 changed files with 33 additions and 0 deletions

View File

@ -32,8 +32,11 @@ import edu.berkeley.boinc.client.Monitor;
import edu.berkeley.boinc.rpc.GlobalPreferences; import edu.berkeley.boinc.rpc.GlobalPreferences;
import edu.berkeley.boinc.rpc.HostInfo; import edu.berkeley.boinc.rpc.HostInfo;
import android.app.Dialog; import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -64,6 +67,8 @@ public class PrefsActivity extends FragmentActivity {
private AppPreferences appPrefs = null; //Android specific preferences, singleton of monitor private AppPreferences appPrefs = null; //Android specific preferences, singleton of monitor
private HostInfo hostinfo = null; private HostInfo hostinfo = null;
private Boolean layoutLoading = true;
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
doBindService(); doBindService();
@ -89,6 +94,31 @@ public class PrefsActivity extends FragmentActivity {
} }
}; };
private BroadcastReceiver mClientStatusChangeRec = new BroadcastReceiver() {
@Override
public void onReceive(Context context,Intent intent) {
if(layoutLoading) {
// layout was previously loading, i.e. data retrieval failed, retry!
if(Logging.DEBUG) Log.d(Logging.TAG,"PrefsActivity.onReceive: previous loading failed, re-try.");
populateLayout();
}
}
};
private IntentFilter ifcsc = new IntentFilter("edu.berkeley.boinc.clientstatuschange");
@Override
public void onResume() {
super.onResume();
registerReceiver(mClientStatusChangeRec,ifcsc);
}
@Override
public void onPause() {
unregisterReceiver(mClientStatusChangeRec);
super.onPause();
}
private void doBindService() { private void doBindService() {
if(!mIsBound) { if(!mIsBound) {
getApplicationContext().bindService(new Intent(this, Monitor.class), mConnection, 0); //calling within Tab needs getApplicationContext() for bindService to work! getApplicationContext().bindService(new Intent(this, Monitor.class), mConnection, 0); //calling within Tab needs getApplicationContext() for bindService to work!
@ -142,6 +172,7 @@ public class PrefsActivity extends FragmentActivity {
if(!getPrefs() || appPrefs == null || !getHostInfo()) { if(!getPrefs() || appPrefs == null || !getHostInfo()) {
if(Logging.DEBUG) Log.d(Logging.TAG, "populateLayout returns, data is not present"); if(Logging.DEBUG) Log.d(Logging.TAG, "populateLayout returns, data is not present");
setLayoutLoading(); setLayoutLoading();
return; return;
} }
@ -150,6 +181,7 @@ public class PrefsActivity extends FragmentActivity {
lv = (ListView) findViewById(R.id.listview); lv = (ListView) findViewById(R.id.listview);
listAdapter = new PrefsListAdapter(PrefsActivity.this,R.id.listview,data); listAdapter = new PrefsListAdapter(PrefsActivity.this,R.id.listview,data);
lv.setAdapter(listAdapter); lv.setAdapter(listAdapter);
layoutLoading = false;
data.clear(); data.clear();
@ -220,6 +252,7 @@ public class PrefsActivity extends FragmentActivity {
setContentView(R.layout.generic_layout_loading); setContentView(R.layout.generic_layout_loading);
TextView loadingHeader = (TextView)findViewById(R.id.loading_header); TextView loadingHeader = (TextView)findViewById(R.id.loading_header);
loadingHeader.setText(R.string.prefs_loading); loadingHeader.setText(R.string.prefs_loading);
layoutLoading = true;
} }
// onClick of listview items with prefs_layout_listitem_bool // onClick of listview items with prefs_layout_listitem_bool