1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-29 15:51:17 +00:00

Improve "share to syncthing" and self-to-service binding (#162)

Related issues:
#158 - FolderActivity not correctly disposed after dialog close
#161 - mRunconditionmonitor not running after config import/export
#163 - "Share to syncthing-folder" doesn't work when syncthing is not running

* import/export Config: Only shutdown native if it is running (fixes #161)

* Remove FolderPickerActivity#kitkat_external_storage_warning

* Remove SyncthingActivity#registerOnServiceConnectedListener

* Make "share to folder" available when syncthing is online or offline (fixes #163)

Improve service connection

* Add script to forward web UI port of an AVD

Update README.md

* SettingsActivity: Improve service connection

* Correct self-class reference in FolderActivity (fixes #158)

* Correct self-class reference in DeviceActivity (fixes #158)

* Correct self-class reference in ShareActivity (fixes #158)

* Remove unused string 1/2

* Remove unused string 2/2
This commit is contained in:
Catfriend1 2018-12-30 15:58:39 +01:00 committed by GitHub
parent b1c614cf21
commit 0fcd84da0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 224 additions and 288 deletions

View file

@ -66,6 +66,16 @@ To clean up all files generated during build, use the following commands:
`./gradlew clean`
### Development Notes
It is recommended to change the GUI and Listen Address ports for the debug app, e.g. to 8385 and 22001 respectively.
The Syncthing native used for this android application provides a web interface by default. It can be accessed via the Settings menu -> 'Web GUI'. It is quite helpful to access this web interface from your development machine. Read android documentation on how to access the network of your emulator. Or use the following command to connect to the single currently running emulator/AVD.
adb forward tcp:18384 tcp:8384
Start Syncthing app on your emulator and access the web interface from you favorite browser of your development machine via https://127.0.0.1:18384
# License
The project is licensed under the [MPLv2](LICENSE).

7
adb_forward_webui.cmd Normal file
View file

@ -0,0 +1,7 @@
@echo off
REM
REM adb forward local_port to emulator_port
echo Running ADB to setup port forwarding on the emulated Android device ...
adb forward tcp:18384 tcp:8384
echo Done.
timeout 3

View file

@ -1,12 +1,14 @@
package com.nutomic.syncthingandroid.activities;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SwitchCompat;
@ -32,6 +34,7 @@ import com.nutomic.syncthingandroid.model.Device;
import com.nutomic.syncthingandroid.service.Constants;
import com.nutomic.syncthingandroid.service.RestApi;
import com.nutomic.syncthingandroid.service.SyncthingService;
import com.nutomic.syncthingandroid.service.SyncthingServiceBinder;
import com.nutomic.syncthingandroid.SyncthingApp;
import com.nutomic.syncthingandroid.util.Compression;
import com.nutomic.syncthingandroid.util.ConfigRouter;
@ -57,7 +60,6 @@ import static com.nutomic.syncthingandroid.util.Compression.METADATA;
public class DeviceActivity extends SyncthingActivity
implements
View.OnClickListener,
SyncthingActivity.OnServiceConnectedListener,
SyncthingService.OnServiceStateChangeListener {
public static final String EXTRA_NOTIFICATION_ID =
@ -197,7 +199,6 @@ public class DeviceActivity extends SyncthingActivity
mIsCreateMode = getIntent().getBooleanExtra(EXTRA_IS_CREATE, false);
setTitle(mIsCreateMode ? R.string.add_device : R.string.edit_device);
registerOnServiceConnectedListener(this);
mIdContainer = findViewById(R.id.idContainer);
mIdView = findViewById(R.id.id);
@ -263,82 +264,16 @@ public class DeviceActivity extends SyncthingActivity
}
}
@Override
public void onDestroy() {
super.onDestroy();
SyncthingService syncthingService = getService();
if (syncthingService != null) {
syncthingService.getNotificationHandler().cancelConsentNotification(getIntent().getIntExtra(EXTRA_NOTIFICATION_ID, 0));
syncthingService.unregisterOnServiceStateChangeListener(this::onServiceStateChange);
}
mIdView.removeTextChangedListener(mIdTextWatcher);
mNameView.removeTextChangedListener(mNameTextWatcher);
mAddressesView.removeTextChangedListener(mAddressesTextWatcher);
}
@Override
public void onPause() {
super.onPause();
// We don't want to update every time a TextView's character changes,
// so we hold off until the view stops being visible to the user.
if (mDeviceNeedsToUpdate) {
updateDevice();
}
}
/**
* Save current settings in case we are in create mode and they aren't yet stored in the config.
*/
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("device", new Gson().toJson(mDevice));
if (mIsCreateMode){
outState.putBoolean(IS_SHOWING_DISCARD_DIALOG, mDiscardDialog != null && mDiscardDialog.isShowing());
Util.dismissDialogSafe(mDiscardDialog, this);
}
outState.putBoolean(IS_SHOWING_COMPRESSION_DIALOG, mCompressionDialog != null && mCompressionDialog.isShowing());
Util.dismissDialogSafe(mCompressionDialog, this);
outState.putBoolean(IS_SHOWING_DELETE_DIALOG, mDeleteDialog != null && mDeleteDialog.isShowing());
Util.dismissDialogSafe(mDeleteDialog, this);
}
/**
* Register for service state change events.
*/
@Override
public void onServiceConnected() {
Log.v(TAG, "onServiceConnected");
SyncthingService syncthingService = (SyncthingService) getService();
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
super.onServiceConnected(componentName, iBinder);
SyncthingServiceBinder syncthingServiceBinder = (SyncthingServiceBinder) iBinder;
SyncthingService syncthingService = (SyncthingService) syncthingServiceBinder.getService();
syncthingService.getNotificationHandler().cancelConsentNotification(getIntent().getIntExtra(EXTRA_NOTIFICATION_ID, 0));
syncthingService.registerOnServiceStateChangeListener(this);
}
/**
* Sets version and current address of the device.
* NOTE: This is only called once on startup, should be called more often to properly display
* version/address changes.
*/
private void onReceiveConnections(Connections connections) {
if (connections == null || connections.connections == null) {
Log.e(TAG, "onReceiveConnections: connections == null || connections.connections == null");
return;
}
if (mDevice == null) {
Log.e(TAG, "onReceiveConnections: mDevice == null");
return;
}
boolean viewsExist = mSyncthingVersionView != null && mCurrentAddressView != null;
if (viewsExist && connections.connections.containsKey(mDevice.deviceID)) {
mCurrentAddressView.setVisibility(VISIBLE);
mSyncthingVersionView.setVisibility(VISIBLE);
mCurrentAddressView.setText(connections.connections.get(mDevice.deviceID).address);
mSyncthingVersionView.setText(connections.connections.get(mDevice.deviceID).clientVersion);
}
syncthingService.registerOnServiceStateChangeListener(DeviceActivity.this);
}
@Override
@ -366,6 +301,83 @@ public class DeviceActivity extends SyncthingActivity
updateViewsAndSetListeners();
}
@Override
public void onBackPressed() {
if (mIsCreateMode) {
showDiscardDialog();
}
else {
super.onBackPressed();
}
}
@Override
public void onPause() {
super.onPause();
// We don't want to update every time a TextView's character changes,
// so we hold off until the view stops being visible to the user.
if (mDeviceNeedsToUpdate) {
updateDevice();
}
}
@Override
public void onDestroy() {
super.onDestroy();
SyncthingService syncthingService = getService();
if (syncthingService != null) {
syncthingService.getNotificationHandler().cancelConsentNotification(getIntent().getIntExtra(EXTRA_NOTIFICATION_ID, 0));
syncthingService.unregisterOnServiceStateChangeListener(DeviceActivity.this);
}
mIdView.removeTextChangedListener(mIdTextWatcher);
mNameView.removeTextChangedListener(mNameTextWatcher);
mAddressesView.removeTextChangedListener(mAddressesTextWatcher);
}
/**
* Save current settings in case we are in create mode and they aren't yet stored in the config.
*/
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("device", new Gson().toJson(mDevice));
if (mIsCreateMode){
outState.putBoolean(IS_SHOWING_DISCARD_DIALOG, mDiscardDialog != null && mDiscardDialog.isShowing());
Util.dismissDialogSafe(mDiscardDialog, this);
}
outState.putBoolean(IS_SHOWING_COMPRESSION_DIALOG, mCompressionDialog != null && mCompressionDialog.isShowing());
Util.dismissDialogSafe(mCompressionDialog, this);
outState.putBoolean(IS_SHOWING_DELETE_DIALOG, mDeleteDialog != null && mDeleteDialog.isShowing());
Util.dismissDialogSafe(mDeleteDialog, this);
}
/**
* Sets version and current address of the device.
* NOTE: This is only called once on startup, should be called more often to properly display
* version/address changes.
*/
private void onReceiveConnections(Connections connections) {
if (connections == null || connections.connections == null) {
Log.e(TAG, "onReceiveConnections: connections == null || connections.connections == null");
return;
}
if (mDevice == null) {
Log.e(TAG, "onReceiveConnections: mDevice == null");
return;
}
boolean viewsExist = mSyncthingVersionView != null && mCurrentAddressView != null;
if (viewsExist && connections.connections.containsKey(mDevice.deviceID)) {
mCurrentAddressView.setVisibility(VISIBLE);
mSyncthingVersionView.setVisibility(VISIBLE);
mCurrentAddressView.setText(connections.connections.get(mDevice.deviceID).address);
mSyncthingVersionView.setText(connections.connections.get(mDevice.deviceID).clientVersion);
}
}
private void updateViewsAndSetListeners() {
mIdView.removeTextChangedListener(mIdTextWatcher);
mNameView.removeTextChangedListener(mNameTextWatcher);
@ -609,16 +621,6 @@ public class DeviceActivity extends SyncthingActivity
shareIntent, context.getString(R.string.send_device_id_to)));
}
@Override
public void onBackPressed() {
if (mIsCreateMode) {
showDiscardDialog();
}
else {
super.onBackPressed();
}
}
private void showDiscardDialog(){
mDiscardDialog = createDiscardDialog();
mDiscardDialog.show();

View file

@ -4,11 +4,13 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.provider.DocumentFile;
import android.support.v7.widget.SwitchCompat;
import android.text.Editable;
@ -35,6 +37,7 @@ import com.nutomic.syncthingandroid.model.FolderIgnoreList;
import com.nutomic.syncthingandroid.service.Constants;
import com.nutomic.syncthingandroid.service.RestApi;
import com.nutomic.syncthingandroid.service.SyncthingService;
import com.nutomic.syncthingandroid.service.SyncthingServiceBinder;
import com.nutomic.syncthingandroid.SyncthingApp;
import com.nutomic.syncthingandroid.util.ConfigRouter;
import com.nutomic.syncthingandroid.util.FileUtils;
@ -60,7 +63,7 @@ import static com.nutomic.syncthingandroid.service.SyncthingService.State.ACTIVE
* Shows folder details and allows changing them.
*/
public class FolderActivity extends SyncthingActivity
implements SyncthingActivity.OnServiceConnectedListener, SyncthingService.OnServiceStateChangeListener {
implements SyncthingService.OnServiceStateChangeListener {
public static final String EXTRA_NOTIFICATION_ID =
"com.nutomic.syncthingandroid.activities.FolderActivity.NOTIFICATION_ID";
@ -181,7 +184,6 @@ public class FolderActivity extends SyncthingActivity
mIsCreateMode = getIntent().getBooleanExtra(EXTRA_IS_CREATE, false);
setTitle(mIsCreateMode ? R.string.create_folder : R.string.edit_folder);
registerOnServiceConnectedListener(this);
mLabelView = findViewById(R.id.label);
mIdView = findViewById(R.id.id);
@ -339,16 +341,13 @@ public class FolderActivity extends SyncthingActivity
}
@Override
public void onDestroy() {
super.onDestroy();
SyncthingService syncthingService = getService();
if (syncthingService != null) {
syncthingService.getNotificationHandler().cancelConsentNotification(getIntent().getIntExtra(EXTRA_NOTIFICATION_ID, 0));
syncthingService.unregisterOnServiceStateChangeListener(this::onServiceStateChange);
public void onBackPressed() {
if (mIsCreateMode) {
showDiscardDialog();
}
else {
super.onBackPressed();
}
mLabelView.removeTextChangedListener(mTextWatcher);
mIdView.removeTextChangedListener(mTextWatcher);
mEditIgnoreListContent.removeTextChangedListener(mTextWatcher);
}
@Override
@ -369,6 +368,19 @@ public class FolderActivity extends SyncthingActivity
}
}
@Override
public void onDestroy() {
super.onDestroy();
SyncthingService syncthingService = getService();
if (syncthingService != null) {
syncthingService.getNotificationHandler().cancelConsentNotification(getIntent().getIntExtra(EXTRA_NOTIFICATION_ID, 0));
syncthingService.unregisterOnServiceStateChangeListener(FolderActivity.this);
}
mLabelView.removeTextChangedListener(mTextWatcher);
mIdView.removeTextChangedListener(mTextWatcher);
mEditIgnoreListContent.removeTextChangedListener(mTextWatcher);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@ -385,11 +397,12 @@ public class FolderActivity extends SyncthingActivity
* Register for service state change events.
*/
@Override
public void onServiceConnected() {
Log.v(TAG, "onServiceConnected");
SyncthingService syncthingService = (SyncthingService) getService();
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
super.onServiceConnected(componentName, iBinder);
SyncthingServiceBinder syncthingServiceBinder = (SyncthingServiceBinder) iBinder;
SyncthingService syncthingService = (SyncthingService) syncthingServiceBinder.getService();
syncthingService.getNotificationHandler().cancelConsentNotification(getIntent().getIntExtra(EXTRA_NOTIFICATION_ID, 0));
syncthingService.registerOnServiceStateChangeListener(this);
syncthingService.registerOnServiceStateChangeListener(FolderActivity.this);
}
@Override
@ -755,16 +768,6 @@ public class FolderActivity extends SyncthingActivity
mConfig.updateFolder(restApi, mFolder);
}
@Override
public void onBackPressed() {
if (mIsCreateMode) {
showDiscardDialog();
}
else {
super.onBackPressed();
}
}
private void showDiscardDialog(){
mDiscardDialog = createDiscardDialog();
mDiscardDialog.show();

View file

@ -98,12 +98,6 @@ public class FolderPickerActivity extends SyncthingActivity
} else {
displayRoot();
}
Boolean prefUseRoot = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.PREF_USE_ROOT, false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && !prefUseRoot) {
Toast.makeText(this, R.string.kitkat_external_storage_warning, Toast.LENGTH_LONG)
.show();
}
}
/**

View file

@ -2,12 +2,14 @@ package com.nutomic.syncthingandroid.activities;
import android.Manifest;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
@ -34,6 +36,7 @@ import com.nutomic.syncthingandroid.service.Constants;
import com.nutomic.syncthingandroid.service.NotificationHandler;
import com.nutomic.syncthingandroid.service.RestApi;
import com.nutomic.syncthingandroid.service.SyncthingService;
import com.nutomic.syncthingandroid.service.SyncthingServiceBinder;
import com.nutomic.syncthingandroid.util.Languages;
import com.nutomic.syncthingandroid.util.Util;
import com.nutomic.syncthingandroid.views.WifiSsidPreference;
@ -49,18 +52,22 @@ import eu.chainfire.libsuperuser.Shell;
public class SettingsActivity extends SyncthingActivity {
private static final String TAG = "SettingsActivity";
private SettingsFragment mSettingsFragment;
public static final String EXTRA_OPEN_SUB_PREF_SCREEN =
"com.nutomic.syncthingandroid.activities.SettingsActivity.OPEN_SUB_PREF_SCREEN";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SettingsFragment settingsFragment = new SettingsFragment();
mSettingsFragment = new SettingsFragment();
Bundle bundle = new Bundle();
bundle.putString(EXTRA_OPEN_SUB_PREF_SCREEN, getIntent().getStringExtra(EXTRA_OPEN_SUB_PREF_SCREEN));
settingsFragment.setArguments(bundle);
mSettingsFragment.setArguments(bundle);
getFragmentManager().beginTransaction()
.replace(android.R.id.content, settingsFragment)
.replace(android.R.id.content, mSettingsFragment)
.commit();
}
@ -84,10 +91,19 @@ public class SettingsActivity extends SyncthingActivity {
}
}
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
super.onServiceConnected(componentName, iBinder);
SyncthingServiceBinder syncthingServiceBinder = (SyncthingServiceBinder) iBinder;
SyncthingService syncthingService = (SyncthingService) syncthingServiceBinder.getService();
mSettingsFragment.setService(syncthingService);
syncthingService.registerOnServiceStateChangeListener(mSettingsFragment);
}
public static class SettingsFragment extends PreferenceFragment
implements SyncthingActivity.OnServiceConnectedListener,
SyncthingService.OnServiceStateChangeListener, Preference.OnPreferenceChangeListener,
Preference.OnPreferenceClickListener {
implements SyncthingService.OnServiceStateChangeListener,
Preference.OnPreferenceChangeListener,
Preference.OnPreferenceClickListener {
private static final String TAG = "SettingsFragment";
private static final String KEY_EXPORT_CONFIG = "export_config";
@ -150,7 +166,6 @@ public class SettingsActivity extends SyncthingActivity {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((SyncthingApp) getActivity().getApplication()).component().inject(this);
((SyncthingActivity) getActivity()).registerOnServiceConnectedListener(this);
}
/**
@ -304,14 +319,8 @@ public class SettingsActivity extends SyncthingActivity {
}
}
@Override
public void onServiceConnected() {
Log.v(TAG, "onServiceConnected");
if (getActivity() == null)
return;
mSyncthingService = ((SyncthingActivity) getActivity()).getService();
mSyncthingService.registerOnServiceStateChangeListener(this);
public void setService(SyncthingService syncthingService) {
mSyncthingService = syncthingService;
}
@Override

View file

@ -1,12 +1,14 @@
package com.nutomic.syncthingandroid.activities;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.text.TextUtils;
@ -24,7 +26,10 @@ import android.widget.Toast;
import com.google.common.io.Files;
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.model.Folder;
import com.nutomic.syncthingandroid.service.RestApi;
import com.nutomic.syncthingandroid.service.SyncthingService;
import com.nutomic.syncthingandroid.service.SyncthingServiceBinder;
import com.nutomic.syncthingandroid.util.ConfigRouter;
import com.nutomic.syncthingandroid.util.Util;
import java.io.File;
@ -46,23 +51,33 @@ import java.util.Map;
* ownCloud Android {@see https://github.com/owncloud/android/blob/79664304fdb762b2e04f1ac505f50d0923ddd212/src/com/owncloud/android/utils/UriUtils.java#L193}
*/
public class ShareActivity extends SyncthingActivity
implements SyncthingActivity.OnServiceConnectedListener, SyncthingService.OnServiceStateChangeListener {
implements SyncthingService.OnServiceStateChangeListener {
private static final String TAG = "ShareActivity";
private static final String PREF_PREVIOUSLY_SELECTED_SYNCTHING_FOLDER = "previously_selected_syncthing_folder";
public static final String PREF_FOLDER_SAVED_SUBDIRECTORY = "saved_sub_directory_";
private TextView mSubDirectoryTextView;
private ConfigRouter mConfig;
private Spinner mFoldersSpinner;
private SyncthingService mSyncthingService = null;
private TextView mSubDirectoryTextView;
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
super.onServiceConnected(componentName, iBinder);
SyncthingServiceBinder syncthingServiceBinder = (SyncthingServiceBinder) iBinder;
SyncthingService syncthingService = (SyncthingService) syncthingServiceBinder.getService();
syncthingService.registerOnServiceStateChangeListener(ShareActivity.this);
mSyncthingService = syncthingService;
}
@Override
public void onServiceStateChange(SyncthingService.State currentState) {
if (currentState != SyncthingService.State.ACTIVE || getApi() == null)
return;
List<Folder> folders = getApi().getFolders();
List<Folder> folders = mConfig.getFolders(getApi());
// Get the index of the previously selected folder.
int folderIndex = 0;
@ -84,11 +99,6 @@ public class ShareActivity extends SyncthingActivity
sItems.setSelection(folderIndex);
}
@Override
public void onServiceConnected() {
getService().registerOnServiceStateChangeListener(this);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
@ -100,10 +110,9 @@ public class ShareActivity extends SyncthingActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mConfig = new ConfigRouter(ShareActivity.this);
setContentView(R.layout.activity_share);
registerOnServiceConnectedListener(this);
Button mShareButton = findViewById(R.id.share_button);
Button mCancelButton = findViewById(R.id.cancel_button);
Button browseButton = findViewById(R.id.browse_button);
@ -113,7 +122,6 @@ public class ShareActivity extends SyncthingActivity
mSubDirectoryTextView = findViewById(R.id.sub_directory_Textview);
mFoldersSpinner = findViewById(R.id.folders);
// TODO: add support for EXTRA_TEXT (notes, memos sharing)
ArrayList<Uri> extrasToCopy = new ArrayList<>();
if (getIntent().getAction().equals(Intent.ACTION_SEND)) {
Uri uri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
@ -179,6 +187,42 @@ public class ShareActivity extends SyncthingActivity
mSubDirectoryTextView.setText(getSavedSubDirectory());
}
@Override
protected void onPause() {
super.onPause();
if (mFoldersSpinner.getSelectedItem() != null) {
Folder selectedFolder = (Folder) mFoldersSpinner.getSelectedItem();
PreferenceManager.getDefaultSharedPreferences(this).edit()
.putString(PREF_PREVIOUSLY_SELECTED_SYNCTHING_FOLDER, selectedFolder.id)
.apply();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FolderPickerActivity.DIRECTORY_REQUEST_CODE && resultCode == RESULT_OK) {
Folder selectedFolder = (Folder) mFoldersSpinner.getSelectedItem();
String folderDirectory = Util.formatPath(selectedFolder.path);
String subDirectory = data.getStringExtra(FolderPickerActivity.EXTRA_RESULT_DIRECTORY);
//Remove the parent directory from the string, so it is only the Sub directory that is displayed to the user.
subDirectory = subDirectory.replace(folderDirectory, "");
mSubDirectoryTextView.setText(subDirectory);
PreferenceManager.getDefaultSharedPreferences(this)
.edit().putString(PREF_FOLDER_SAVED_SUBDIRECTORY + selectedFolder.id, subDirectory)
.apply();
}
}
@Override
protected void onDestroy() {
if (mSyncthingService != null) {
mSyncthingService.unregisterOnServiceStateChangeListener(ShareActivity.this);
}
super.onDestroy();
}
/**
* Generate file name for new file.
*/
@ -357,32 +401,4 @@ public class ShareActivity extends SyncthingActivity
shareActivity.finish();
}
}
@Override
protected void onPause() {
super.onPause();
if (mFoldersSpinner.getSelectedItem() != null) {
Folder selectedFolder = (Folder) mFoldersSpinner.getSelectedItem();
PreferenceManager.getDefaultSharedPreferences(this).edit()
.putString(PREF_PREVIOUSLY_SELECTED_SYNCTHING_FOLDER, selectedFolder.id)
.apply();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FolderPickerActivity.DIRECTORY_REQUEST_CODE && resultCode == RESULT_OK) {
Folder selectedFolder = (Folder) mFoldersSpinner.getSelectedItem();
String folderDirectory = Util.formatPath(selectedFolder.path);
String subDirectory = data.getStringExtra(FolderPickerActivity.EXTRA_RESULT_DIRECTORY);
//Remove the parent directory from the string, so it is only the Sub directory that is displayed to the user.
subDirectory = subDirectory.replace(folderDirectory, "");
mSubDirectoryTextView.setText(subDirectory);
PreferenceManager.getDefaultSharedPreferences(this)
.edit().putString(PREF_FOLDER_SAVED_SUBDIRECTORY + selectedFolder.id, subDirectory)
.apply();
}
}
}

View file

@ -8,6 +8,7 @@ import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
// import android.util.Log;
import com.annimon.stream.Stream;
import com.nutomic.syncthingandroid.R;
@ -22,17 +23,10 @@ import java.util.LinkedList;
*/
public abstract class SyncthingActivity extends AppCompatActivity implements ServiceConnection {
private static final String TAG = "SyncthingActivity";
private SyncthingService mSyncthingService;
private final LinkedList<OnServiceConnectedListener> mServiceConnectedListeners = new LinkedList<>();
/**
* To be used for Fragments.
*/
public interface OnServiceConnectedListener {
void onServiceConnected();
}
/**
* Look for a Toolbar in the layout and bind it as the activity's actionbar with reasonable
* defaults.
@ -69,8 +63,6 @@ public abstract class SyncthingActivity extends AppCompatActivity implements Ser
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
SyncthingServiceBinder syncthingServiceBinder = (SyncthingServiceBinder) iBinder;
mSyncthingService = syncthingServiceBinder.getService();
Stream.of(mServiceConnectedListeners).forEach(OnServiceConnectedListener::onServiceConnected);
mServiceConnectedListeners.clear();
}
@Override
@ -78,17 +70,6 @@ public abstract class SyncthingActivity extends AppCompatActivity implements Ser
mSyncthingService = null;
}
/**
* Used for Fragments to use the Activity's service connection.
*/
void registerOnServiceConnectedListener(OnServiceConnectedListener listener) {
if (mSyncthingService != null) {
listener.onServiceConnected();
} else {
mServiceConnectedListeners.addLast(listener);
}
}
/**
* Returns service object (or null if not bound).
*/

View file

@ -756,8 +756,10 @@ public class SyncthingService extends Service {
Boolean failSuccess = true;
Log.v(TAG, "exportConfig BEGIN");
// Shutdown synchronously.
shutdown(State.DISABLED);
if (mCurrentState != State.DISABLED) {
// Shutdown synchronously.
shutdown(State.DISABLED);
}
// Copy config, privateKey and/or publicKey to export path.
Constants.EXPORT_PATH_OBJ.mkdirs();
@ -858,8 +860,10 @@ public class SyncthingService extends Service {
Boolean failSuccess = true;
Log.v(TAG, "importConfig BEGIN");
// Shutdown synchronously.
shutdown(State.DISABLED);
if (mCurrentState != State.DISABLED) {
// Shutdown synchronously.
shutdown(State.DISABLED);
}
// Import config, privateKey and/or publicKey.
try {

View file

@ -288,9 +288,6 @@
<!-- Activity title -->
<string name="folder_picker_title">Избор на папка</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Внимание: Версията на Android не позволява синхронизиране с външни устройства за съхранение на данни</string>
<!-- ListView empty text -->
<string name="directory_empty">Директорията е празна</string>

View file

@ -543,9 +543,6 @@ Ens podeu informar dels problemes que trobeu a través de Github.</string>
<!-- Activity title -->
<string name="folder_picker_title">Selector de carpetes</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Avís: la vostra versió de l\'Android no us permet sincronitzar a dispositius d\'emmagatzematge externs</string>
<!-- ListView empty text -->
<string name="directory_empty">El directori és buit</string>

View file

@ -334,9 +334,6 @@ Všechny zaznamenané chyby prosím hlašte přes Github.</string>
<!-- Activity title -->
<string name="folder_picker_title">Výběr adresáře</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Varování: Tato verze Androidu nepovoluje synchronizaci na externí úložiště</string>
<!-- ListView empty text -->
<string name="directory_empty">Adresář je prázdný</string>

View file

@ -330,9 +330,6 @@ Vær venlig at rapportere ethvert problem, du støder på, via Github. </string>
<!-- Activity title -->
<string name="folder_picker_title">Mappe Vælger</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Advarsel: Din Android version tillader ikke at synkronisere til eksterne lagringsenheder</string>
<!-- ListView empty text -->
<string name="directory_empty">Katalog er Tomt</string>

View file

@ -565,9 +565,6 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
<!-- Activity title -->
<string name="folder_picker_title">Verzeichnisauswahl</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Warnung: Deine Andoid-Version erlaubt kein Synchronisieren auf externe Datenträger</string>
<!-- ListView empty text -->
<string name="directory_empty">Verzeichnis ist leer</string>

View file

@ -330,9 +330,6 @@
<!-- Activity title -->
<string name="folder_picker_title">Επιλογέας φακέλων</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Προσοχή: η έκδοση του Android σας δεν επιτρέπει τον συγχρονισμό προς εξωτερικές συσκευές αποθήκευσης</string>
<!-- ListView empty text -->
<string name="directory_empty">Ο φάκελος είναι κενός</string>

View file

@ -262,9 +262,6 @@
<!-- Activity title -->
<string name="folder_picker_title">Seleccionador de Carpetas</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Advertencia: Su versión de Android no permite sincronizar con dispositivos de almacenamiento externo</string>
<!-- ListView empty text -->
<string name="directory_empty">El directorio está vacío</string>

View file

@ -299,9 +299,6 @@
<!-- Activity title -->
<string name="folder_picker_title">Seleccionador de carpetas</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Aviso: Tu versión de Android no permite la sincronización con dispositivos de almacenamiento externos</string>
<!-- ListView empty text -->
<string name="directory_empty">El directorio esta vacío</string>

View file

@ -314,9 +314,6 @@ Ilmoitathan ystävällisesti kaikista havaitsemistasi ongelmista Githubin kautta
<!-- Activity title -->
<string name="folder_picker_title">Kansionvalitsin</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Varoitus: Käytössä oleva Android-versio ei salli synkronointia ulkoisille massamuisteille.</string>
<!-- ListView empty text -->
<string name="directory_empty">Hakemisto on tyhjä</string>

View file

@ -396,9 +396,6 @@ S\'il vous plaît, soumettez les problèmes que vous rencontrez via Github.</str
<!-- Activity title -->
<string name="folder_picker_title">Sélection du répertoire</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Attention: votre version Android n\'autorise pas la synchronisation avec des périphériques de stockages externes.</string>
<!-- ListView empty text -->
<string name="directory_empty">Le répertoire est vide</string>

View file

@ -392,9 +392,6 @@ VIGYÁZAT! Más alkalmazások kiolvashatják a backupból a titkos kulcsot, és
<!-- Activity title -->
<string name="folder_picker_title">Mappaválasztó</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Figyelem: Az általad használt Android verzió nem támogatja a külső eszközre (pl. memóriakártyára) történő szinkronizálást</string>
<!-- ListView empty text -->
<string name="directory_empty">A mappa üres</string>

View file

@ -311,9 +311,6 @@ Jika ada masalah silakan laporkan lewat Github.</string>
<!-- Activity title -->
<string name="folder_picker_title">Pemilih Folder</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Peringatan: Versi Android anda tidak mengijinkan penyelarasan ke perangkat storage eksternal</string>
<!-- ListView empty text -->
<string name="directory_empty">Direktori ini Kosong</string>

View file

@ -393,9 +393,6 @@ Si prega di segnalare eventuali problemi che si incontrano via Github.</string>
<!-- Activity title -->
<string name="folder_picker_title">Selezione Cartella</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Attenzione: La tua versione di Android non permette la sincronizzazione con dispositivi esterni di archiviazione</string>
<!-- ListView empty text -->
<string name="directory_empty">Cartella Vuota</string>

View file

@ -331,9 +331,6 @@
<!-- Activity title -->
<string name="folder_picker_title">フォルダーを選択</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">警告: お使いの Android のバージョンは外部ストレージに同期することができません</string>
<!-- ListView empty text -->
<string name="directory_empty">ディレクトリーは空です</string>

View file

@ -329,9 +329,6 @@
<!-- Activity title -->
<string name="folder_picker_title">폴더 선택기</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">경고: 사용하는 Android 버전에서는 외부 저장소에의 동기화를 지원하지 않습니다</string>
<!-- ListView empty text -->
<string name="directory_empty">디렉토리가 비어 있습니다</string>

View file

@ -271,9 +271,6 @@
<!-- Activity title -->
<string name="folder_picker_title">Mappe-velger</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Advarsel: Din versjon av Android tillater ikke synkronisering til eksterne lagringsenheter. </string>
<!-- ListView empty text -->
<string name="directory_empty">Katalogen er tom</string>

View file

@ -415,9 +415,6 @@ Als je problemen tegenkomt, meld ze dan via GitHub.</string>
<!-- Activity title -->
<string name="folder_picker_title">Mapkiezer</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Waarschuwing: je Android-versie laat synchroniseren naar externe opslagapparaten niet toe</string>
<!-- ListView empty text -->
<string name="directory_empty">Map is leeg</string>

View file

@ -271,9 +271,6 @@
<!-- Activity title -->
<string name="folder_picker_title">Mappeveljar</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Åtvaring: Din versjon av Android tillèt ikkje synkronisering av eksterne lagringseiningar. </string>
<!-- ListView empty text -->
<string name="directory_empty">Mappa er tom</string>

View file

@ -334,9 +334,6 @@ Proszę zgłaszać napotkane błędy programu za pośrednictwem serwisu Github.<
<!-- Activity title -->
<string name="folder_picker_title">Wybieranie katalogu</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Ostrzeżenie: aktualna wersja systemu Android nie pozwala na synchronizowanie zewnętrznych pamięci masowych</string>
<!-- ListView empty text -->
<string name="directory_empty">Katalog jest pusty</string>

View file

@ -375,9 +375,6 @@ Por favor, nos avise sobre quaisquer problemas que você encontrar via Github.</
<!-- Activity title -->
<string name="folder_picker_title">Seletor de pasta</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Aviso: a versão do seu Android não suporta sincronização de dispositivos externos de armazenamento</string>
<!-- ListView empty text -->
<string name="directory_empty">A pasta está vazia</string>

View file

@ -297,9 +297,6 @@ Reporte, através do Github, quaisquer problemas que encontre, por favor.</strin
<!-- Activity title -->
<string name="folder_picker_title">Selector de pasta</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Aviso: A sua versão de Android não permite sincronizar com dispositivos de armazenamento externo</string>
<!-- ListView empty text -->
<string name="directory_empty">A pasta está vazia</string>

View file

@ -425,9 +425,6 @@ Vă rugăm să raportați orice problemă întâlniți, prin intermediul GitHub.
<!-- Activity title -->
<string name="folder_picker_title">Selector de director</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Atenție: Versiunea dumneavoastră de Android nu permite sincronizarea la locațiile de stocare externe</string>
<!-- ListView empty text -->
<string name="directory_empty">Directorul este gol</string>

View file

@ -451,9 +451,6 @@
<!-- Activity title -->
<string name="folder_picker_title">Выбор Папки</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Внимание: Ваша версия Android не позволяет синхронизацию на внешние хранилища</string>
<!-- ListView empty text -->
<string name="directory_empty">Папка пуста</string>

View file

@ -240,9 +240,6 @@
<!-- Activity title -->
<string name="folder_picker_title">Výver Adresára</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Varovanie: Verzia Androidu na Vašom zariadení nedovoľuje synchronizáciu externého úložiska</string>
<!-- ListView empty text -->
<string name="directory_empty">Adresár je Prázdny</string>

View file

@ -510,9 +510,6 @@ Vänligen rapportera eventuella problem du stöter på via Github.</string>
<!-- Activity title -->
<string name="folder_picker_title">Mappväljare</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Varning: Din Android version tillåter inte synkronisering till externa lagringsenheter</string>
<!-- ListView empty text -->
<string name="directory_empty">Katalogen är tom</string>

View file

@ -288,9 +288,6 @@ Eğer herhangi bir sorunla karşılaşırsan Github aracılığıyla bildir.</st
<!-- Activity title -->
<string name="folder_picker_title">Klasör Seçici</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Uyarı: Android sürümünüz, harici depolama aygıtlarına eşzamanlama yapılmasına izin vermiyor.</string>
<!-- ListView empty text -->
<string name="directory_empty">Dizin Boş</string>

View file

@ -262,9 +262,6 @@
<!-- Activity title -->
<string name="folder_picker_title">Trình chọn th.mục</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Cảnh báo: Ph.bản Android của bạn không cho phép đ.bộ vào các th.bị lưu trữ ngoại vi</string>
<!-- ListView empty text -->
<string name="directory_empty">Thư mục rỗng</string>

View file

@ -333,9 +333,6 @@
<!-- Activity title -->
<string name="folder_picker_title">文件夹选择器</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">警告:您的系统版本不允许同步文件至外部存储器</string>
<!-- ListView empty text -->
<string name="directory_empty">目录为空</string>

View file

@ -329,9 +329,6 @@
<!-- Activity title -->
<string name="folder_picker_title">資料夾選擇器</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">警告:你的 Android 版本不允許同步外部儲存裝置</string>
<!-- ListView empty text -->
<string name="directory_empty">資料夾為空</string>

View file

@ -573,9 +573,6 @@ Please report any problems you encounter via Github.</string>
<!-- Activity title -->
<string name="folder_picker_title">Folder Picker</string>
<!-- Toast shown on devices with kitkat or higher -->
<string name="kitkat_external_storage_warning">Warning: Your Android version does not allow syncing to external storage devices</string>
<!-- ListView empty text -->
<string name="directory_empty">Directory is Empty</string>