Display options menu only once web gui is online.

This commit is contained in:
Felix Ableitner 2014-05-27 14:51:33 +02:00
parent 1c1b1e6aa6
commit 51309ef984
4 changed files with 12 additions and 11 deletions

View File

@ -114,6 +114,11 @@ public class WebGuiActivity extends Activity implements SyncthingService.OnWebGu
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
return mSyncthingService != null && mSyncthingService.isWebGuiAvailable();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {

View File

@ -12,14 +12,11 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
private static final String TAG = "RestApi";
private Context mContext;
private String mVersion;
private String mUrl;
public RestApi(Context context, String url) {
mContext = context;
public RestApi(String url) {
mUrl = url;
}
@ -45,9 +42,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
* Returns the version name, or a (text) error message on failure.
*/
public String getVersion() {
return (mVersion != null)
? mVersion
: mContext.getString(R.string.syncthing_version_error);
return mVersion;
}
/**

View File

@ -259,7 +259,7 @@ public class SyncthingService extends Service {
throw new RuntimeException("Failed to read gui url, aborting", e);
}
finally {
mApi = new RestApi(SyncthingService.this, "http://" + syncthingUrl);
mApi = new RestApi("http://" + syncthingUrl);
Log.i(TAG, "Web GUI will be available at " + mApi.getUrl());
registerOnWebGuiAvailableListener(mApi);
}
@ -284,6 +284,10 @@ public class SyncthingService extends Service {
mApi.shutdown();
}
public boolean isWebGuiAvailable() {
return mIsWebGuiAvailable;
}
/**
* Register a listener for the web gui becoming available..
*

View File

@ -40,7 +40,4 @@ Please report any problems you encounter.
<!-- Title of the preference showing upstream version name -->
<string name="syncthing_version_title">Syncthing Version</string>
<!-- Displayed instead of the version string if it could not be read -->
<string name="syncthing_version_error">Could not read version</string>
</resources>