mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 06:11:19 +00:00
Display options menu only once web gui is online.
This commit is contained in:
parent
1c1b1e6aa6
commit
51309ef984
4 changed files with 12 additions and 11 deletions
|
@ -114,6 +114,11 @@ public class WebGuiActivity extends Activity implements SyncthingService.OnWebGu
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
|
return mSyncthingService != null && mSyncthingService.isWebGuiAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
|
|
|
@ -12,14 +12,11 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
|
|
||||||
private static final String TAG = "RestApi";
|
private static final String TAG = "RestApi";
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
private String mVersion;
|
private String mVersion;
|
||||||
|
|
||||||
private String mUrl;
|
private String mUrl;
|
||||||
|
|
||||||
public RestApi(Context context, String url) {
|
public RestApi(String url) {
|
||||||
mContext = context;
|
|
||||||
mUrl = url;
|
mUrl = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +42,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
* Returns the version name, or a (text) error message on failure.
|
* Returns the version name, or a (text) error message on failure.
|
||||||
*/
|
*/
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return (mVersion != null)
|
return mVersion;
|
||||||
? mVersion
|
|
||||||
: mContext.getString(R.string.syncthing_version_error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -259,7 +259,7 @@ public class SyncthingService extends Service {
|
||||||
throw new RuntimeException("Failed to read gui url, aborting", e);
|
throw new RuntimeException("Failed to read gui url, aborting", e);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
mApi = new RestApi(SyncthingService.this, "http://" + syncthingUrl);
|
mApi = new RestApi("http://" + syncthingUrl);
|
||||||
Log.i(TAG, "Web GUI will be available at " + mApi.getUrl());
|
Log.i(TAG, "Web GUI will be available at " + mApi.getUrl());
|
||||||
registerOnWebGuiAvailableListener(mApi);
|
registerOnWebGuiAvailableListener(mApi);
|
||||||
}
|
}
|
||||||
|
@ -284,6 +284,10 @@ public class SyncthingService extends Service {
|
||||||
mApi.shutdown();
|
mApi.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isWebGuiAvailable() {
|
||||||
|
return mIsWebGuiAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a listener for the web gui becoming available..
|
* Register a listener for the web gui becoming available..
|
||||||
*
|
*
|
||||||
|
|
|
@ -40,7 +40,4 @@ Please report any problems you encounter.
|
||||||
<!-- Title of the preference showing upstream version name -->
|
<!-- Title of the preference showing upstream version name -->
|
||||||
<string name="syncthing_version_title">Syncthing Version</string>
|
<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>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue