use of com.nutomic.syncthingandroid.service.RestApi in project syncthing-android by syncthing.
the class DrawerFragment method updateGui.
/**
* Invokes status callbacks.
*/
private void updateGui() {
MainActivity mainActivity = (MainActivity) getActivity();
if (mainActivity == null) {
return;
}
if (mainActivity.isFinishing()) {
return;
}
RestApi mApi = mainActivity.getApi();
if (mApi != null) {
mApi.getSystemInfo(this::onReceiveSystemInfo);
mApi.getSystemVersion(this::onReceiveSystemVersion);
mApi.getConnections(this::onReceiveConnections);
}
}
use of com.nutomic.syncthingandroid.service.RestApi in project syncthing-android by syncthing.
the class DrawerFragment method showQrCode.
/**
* Gets QRCode and displays it in a Dialog.
*/
private void showQrCode() {
RestApi restApi = mActivity.getApi();
if (restApi == null) {
Toast.makeText(mActivity, R.string.syncthing_terminated, Toast.LENGTH_SHORT).show();
return;
}
try {
String apiKey = restApi.getGui().apiKey;
String deviceId = restApi.getLocalDevice().deviceID;
URL url = restApi.getUrl();
// The QRCode request takes one paramteer called "text", which is the text to be converted to a QRCode.
new ImageGetRequest(mActivity, url, ImageGetRequest.QR_CODE_GENERATOR, apiKey, ImmutableMap.of("text", deviceId), qrCodeBitmap -> {
mActivity.showQrCodeDialog(deviceId, qrCodeBitmap);
mActivity.closeDrawer();
}, error -> Toast.makeText(mActivity, R.string.could_not_access_deviceid, Toast.LENGTH_SHORT).show());
} catch (Exception e) {
Log.e(TAG, "showQrCode", e);
}
}
use of com.nutomic.syncthingandroid.service.RestApi in project syncthing-android by syncthing.
the class MainActivity method onServiceStateChange.
/**
* Handles various dialogs based on current state.
*/
@Override
public void onServiceStateChange(SyncthingService.State currentState) {
switch(currentState) {
case STARTING:
break;
case ACTIVE:
getIntent().putExtra(this.EXTRA_KEY_GENERATION_IN_PROGRESS, false);
showBatteryOptimizationDialogIfNecessary();
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
mDrawerFragment.requestGuiUpdate();
// Check if the usage reporting minimum delay passed by.
Boolean usageReportingDelayPassed = (new Date().getTime() > getFirstStartTime() + USAGE_REPORTING_DIALOG_DELAY);
RestApi restApi = getApi();
if (usageReportingDelayPassed && restApi != null && !restApi.isUsageReportingDecided()) {
showUsageReportingDialog(restApi);
}
break;
case ERROR:
finish();
break;
case DISABLED:
break;
}
}
use of com.nutomic.syncthingandroid.service.RestApi in project syncthing-android by syncthing.
the class MainActivity method showUsageReportingDialog.
/**
* Displays dialog asking user to accept/deny usage reporting.
*/
private void showUsageReportingDialog(RestApi restApi) {
final DialogInterface.OnClickListener listener = (dialog, which) -> {
try {
switch(which) {
case DialogInterface.BUTTON_POSITIVE:
restApi.setUsageReporting(true);
restApi.saveConfigAndRestart();
break;
case DialogInterface.BUTTON_NEGATIVE:
restApi.setUsageReporting(false);
restApi.saveConfigAndRestart();
break;
case DialogInterface.BUTTON_NEUTRAL:
Uri uri = Uri.parse("https://data.syncthing.net");
startActivity(new Intent(Intent.ACTION_VIEW, uri));
break;
}
} catch (Exception e) {
Log.e(TAG, "showUsageReportingDialog:OnClickListener", e);
}
};
restApi.getUsageReport(report -> {
@SuppressLint("InflateParams") View v = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog_usage_reporting, null);
TextView tv = v.findViewById(R.id.example);
tv.setText(report);
Util.getAlertDialogBuilder(MainActivity.this).setTitle(R.string.usage_reporting_dialog_title).setView(v).setPositiveButton(R.string.yes, listener).setNegativeButton(R.string.no, listener).setNeutralButton(R.string.open_website, listener).show();
});
}
use of com.nutomic.syncthingandroid.service.RestApi in project syncthing-android by syncthing.
the class DeviceListFragment method updateList.
/**
* Refreshes ListView by updating devices and info.
*
* Also creates adapter if it doesn't exist yet.
*/
private void updateList() {
SyncthingActivity activity = (SyncthingActivity) getActivity();
if (activity == null || getView() == null || activity.isFinishing()) {
return;
}
RestApi restApi = activity.getApi();
if (restApi == null || !restApi.isConfigLoaded()) {
return;
}
List<Device> devices = restApi.getDevices(false);
if (devices == null) {
return;
}
if (mAdapter == null) {
mAdapter = new DevicesAdapter(activity);
setListAdapter(mAdapter);
}
// Prevent scroll position reset due to list update from clear().
mAdapter.setNotifyOnChange(false);
mAdapter.clear();
Collections.sort(devices, DEVICES_COMPARATOR);
mAdapter.addAll(devices);
mAdapter.updateConnections(restApi);
mAdapter.notifyDataSetChanged();
setListShown(true);
}
Aggregations