1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-22 12:21:15 +00:00

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>