1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-27 13:21:30 +00:00

Change constants from repo/node to folder/device.

This commit is contained in:
Felix Ableitner 2016-03-19 21:53:35 +01:00
parent f9c8a7dc8c
commit ab19944383
8 changed files with 32 additions and 36 deletions

View file

@ -14,15 +14,13 @@ import com.nutomic.syncthingandroid.fragments.SettingsFragment;
*/
public class SettingsActivity extends SyncthingActivity {
public static final String ACTION_APP_SETTINGS_FRAGMENT = "app_settings_fragment";
public static final String ACTION_NODE_SETTINGS_FRAGMENT = "device_settings_fragment";
public static final String ACTION_REPO_SETTINGS_FRAGMENT = "folder_settings_fragment";
public static final String ACTION_APP_SETTINGS = "app_settings_fragment";
public static final String ACTION_DEVICE_SETTINGS = "device_settings_fragment";
public static final String ACTION_FOLDER_SETTINGS = "folder_settings_fragment";
/**
* Must be set for {@link #ACTION_NODE_SETTINGS_FRAGMENT} and
* {@link #ACTION_REPO_SETTINGS_FRAGMENT} to determine if an existing folder/device should be
* Must be set for {@link #ACTION_DEVICE_SETTINGS} and
* {@link #ACTION_FOLDER_SETTINGS} to determine if an existing folder/device should be
* edited or a new one created.
*/
public static final String EXTRA_IS_CREATE = "create";
@ -41,17 +39,17 @@ public class SettingsActivity extends SyncthingActivity {
savedInstanceState.getString("fragment_name"));
} else if (getIntent().getAction() != null) {
switch (getIntent().getAction()) {
case ACTION_APP_SETTINGS_FRAGMENT:
case ACTION_APP_SETTINGS:
setTitle(R.string.settings_title);
mFragment = new SettingsFragment();
break;
case ACTION_NODE_SETTINGS_FRAGMENT:
case ACTION_DEVICE_SETTINGS:
mFragment = new DeviceFragment();
if (!getIntent().hasExtra(EXTRA_IS_CREATE)) {
throw new IllegalArgumentException("EXTRA_IS_CREATE must be set");
}
break;
case ACTION_REPO_SETTINGS_FRAGMENT:
case ACTION_FOLDER_SETTINGS:
mFragment = new FolderFragment();
if (!getIntent().hasExtra(EXTRA_IS_CREATE)) {
throw new IllegalArgumentException("EXTRA_IS_CREATE must be set");

View file

@ -54,7 +54,7 @@ public class DeviceFragment extends Fragment implements
SyncthingService.OnApiChangeListener, RestApi.OnDeviceIdNormalizedListener,
View.OnClickListener {
public static final String EXTRA_NODE_ID = "device_id";
public static final String EXTRA_DEVICE_ID = "device_id";
private static final String TAG = "DeviceSettingsFragment";
@ -269,7 +269,7 @@ public class DeviceFragment extends Fragment implements
mDevice = null;
for (int i = 0; i < devices.size(); i++) {
if (devices.get(i).deviceID.equals(
getActivity().getIntent().getStringExtra(EXTRA_NODE_ID))) {
getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID))) {
mDevice = devices.get(i);
break;
}
@ -375,7 +375,7 @@ public class DeviceFragment extends Fragment implements
private void initDevice() {
mDevice = new RestApi.Device();
mDevice.name = "";
mDevice.deviceID = getActivity().getIntent().getStringExtra(EXTRA_NODE_ID);
mDevice.deviceID = getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID);
mDevice.addresses = DYNAMIC_ADDRESS;
mDevice.compression = METADATA.getValue(getActivity());
mDevice.introducer = false;

View file

@ -11,7 +11,6 @@ import android.widget.AdapterView;
import android.widget.ListView;
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.activities.MainActivity;
import com.nutomic.syncthingandroid.activities.SettingsActivity;
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
@ -103,9 +102,9 @@ public class DeviceListFragment extends ListFragment implements SyncthingService
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(getActivity(), SettingsActivity.class);
intent.setAction(SettingsActivity.ACTION_NODE_SETTINGS_FRAGMENT);
intent.setAction(SettingsActivity.ACTION_DEVICE_SETTINGS);
intent.putExtra(SettingsActivity.EXTRA_IS_CREATE, false);
intent.putExtra(DeviceFragment.EXTRA_NODE_ID, mAdapter.getItem(i).deviceID);
intent.putExtra(DeviceFragment.EXTRA_DEVICE_ID, mAdapter.getItem(i).deviceID);
startActivity(intent);
}
@ -119,7 +118,7 @@ public class DeviceListFragment extends ListFragment implements SyncthingService
switch (item.getItemId()) {
case R.id.add_device:
Intent intent = new Intent(getActivity(), SettingsActivity.class)
.setAction(SettingsActivity.ACTION_NODE_SETTINGS_FRAGMENT)
.setAction(SettingsActivity.ACTION_DEVICE_SETTINGS)
.putExtra(SettingsActivity.EXTRA_IS_CREATE, true);
startActivity(intent);
return true;

View file

@ -202,7 +202,7 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
break;
case R.id.drawerActionSettings:
startActivity(new Intent(mActivity, SettingsActivity.class)
.setAction(SettingsActivity.ACTION_APP_SETTINGS_FRAGMENT));
.setAction(SettingsActivity.ACTION_APP_SETTINGS));
mActivity.closeDrawer();
break;
case R.id.drawerActionRestart:

View file

@ -52,7 +52,7 @@ import static java.lang.String.valueOf;
public class FolderFragment extends Fragment
implements SyncthingActivity.OnServiceConnectedListener, SyncthingService.OnApiChangeListener {
public static final String EXTRA_REPO_ID = "folder_id";
public static final String EXTRA_FOLDER_ID = "folder_id";
public static final String EXTRA_DEVICE_ID = "device_id";
@ -84,7 +84,7 @@ public class FolderFragment extends Fragment
@Override
public void afterTextChanged(Editable s) {
mFolder.id = s.toString();
updateRepo();
updateFolder();
}
};
@ -99,7 +99,7 @@ public class FolderFragment extends Fragment
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
mFolder.readOnly = isChecked;
updateRepo();
updateFolder();
}
};
@ -112,7 +112,7 @@ public class FolderFragment extends Fragment
} else {
mFolder.deviceIds.remove(device.deviceID);
}
updateRepo();
updateFolder();
}
};
@ -127,7 +127,7 @@ public class FolderFragment extends Fragment
((SimpleVersioning) mFolder.versioning).setParams(intValue);
mVersioningKeepView.setText(valueOf(intValue));
}
updateRepo();
updateFolder();
}
};
@ -231,7 +231,7 @@ public class FolderFragment extends Fragment
if (!mIsCreateMode) {
List<RestApi.Folder> folders = mSyncthingService.getApi().getFolders();
String passedId = getActivity().getIntent().getStringExtra(EXTRA_REPO_ID);
String passedId = getActivity().getIntent().getStringExtra(EXTRA_FOLDER_ID);
mFolder = null;
for (RestApi.Folder currentFolder : folders) {
if (currentFolder.id.equals(passedId)) {
@ -341,13 +341,13 @@ public class FolderFragment extends Fragment
if (resultCode == Activity.RESULT_OK && requestCode == DIRECTORY_REQUEST_CODE) {
mFolder.path = data.getStringExtra(FolderPickerActivity.EXTRA_RESULT_DIRECTORY);
mPathView.setText(mFolder.path);
updateRepo();
updateFolder();
}
}
private void initFolder() {
mFolder = new RestApi.Folder();
mFolder.id = getActivity().getIntent().getStringExtra(EXTRA_REPO_ID);
mFolder.id = getActivity().getIntent().getStringExtra(EXTRA_FOLDER_ID);
mFolder.path = "";
mFolder.rescanIntervalS = 259200; // Scan every 3 days (in case inotify dropped some changes)
mFolder.deviceIds = new ArrayList<>();
@ -385,7 +385,7 @@ public class FolderFragment extends Fragment
deviceView.setOnCheckedChangeListener(mOnShareChangeListener);
}
private void updateRepo() {
private void updateFolder() {
if (!mIsCreateMode) {
mSyncthingService.getApi().editFolder(mFolder, false, getActivity());
}

View file

@ -103,9 +103,9 @@ public class FolderListFragment extends ListFragment implements SyncthingService
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(getActivity(), SettingsActivity.class)
.setAction(SettingsActivity.ACTION_REPO_SETTINGS_FRAGMENT)
.setAction(SettingsActivity.ACTION_FOLDER_SETTINGS)
.putExtra(SettingsActivity.EXTRA_IS_CREATE, false)
.putExtra(FolderFragment.EXTRA_REPO_ID, mAdapter.getItem(i).id);
.putExtra(FolderFragment.EXTRA_FOLDER_ID, mAdapter.getItem(i).id);
startActivity(intent);
}
@ -131,7 +131,7 @@ public class FolderListFragment extends ListFragment implements SyncthingService
switch (item.getItemId()) {
case R.id.add_folder:
Intent intent = new Intent(getActivity(), SettingsActivity.class)
.setAction(SettingsActivity.ACTION_REPO_SETTINGS_FRAGMENT)
.setAction(SettingsActivity.ACTION_FOLDER_SETTINGS)
.putExtra(SettingsActivity.EXTRA_IS_CREATE, true);
startActivity(intent);
return true;

View file

@ -22,7 +22,6 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.Random;
import java.util.concurrent.TimeUnit;
/**
@ -97,9 +96,9 @@ public class EventProcessor implements SyncthingService.OnWebGuiAvailableListene
Log.d(TAG, "Unknwon device " + deviceId + " wants to connect");
Intent intent = new Intent(mContext, SettingsActivity.class)
.setAction(SettingsActivity.ACTION_NODE_SETTINGS_FRAGMENT)
.setAction(SettingsActivity.ACTION_DEVICE_SETTINGS)
.putExtra(SettingsActivity.EXTRA_IS_CREATE, true)
.putExtra(DeviceFragment.EXTRA_NODE_ID, deviceId);
.putExtra(DeviceFragment.EXTRA_DEVICE_ID, deviceId);
PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
String title = mContext.getString(R.string.device_rejected,
@ -113,10 +112,10 @@ public class EventProcessor implements SyncthingService.OnWebGuiAvailableListene
Log.d(TAG, "Device " + deviceId + " wants to share folder " + folderId);
intent = new Intent(mContext, SettingsActivity.class)
.setAction(SettingsActivity.ACTION_REPO_SETTINGS_FRAGMENT)
.setAction(SettingsActivity.ACTION_FOLDER_SETTINGS)
.putExtra(SettingsActivity.EXTRA_IS_CREATE, true)
.putExtra(FolderFragment.EXTRA_DEVICE_ID, deviceId)
.putExtra(FolderFragment.EXTRA_REPO_ID, folderId);
.putExtra(FolderFragment.EXTRA_FOLDER_ID, folderId);
pi = PendingIntent.getActivity(mContext, 0, intent, 0);
String deviceName = null;

View file

@ -557,7 +557,7 @@ public class SyncthingService extends Service implements
public void onClick(DialogInterface dialogInterface, int i) {
activity.finish();
Intent intent = new Intent(activity, SettingsActivity.class)
.setAction(SettingsActivity.ACTION_APP_SETTINGS_FRAGMENT);
.setAction(SettingsActivity.ACTION_APP_SETTINGS);
activity.startActivity(intent);
}
}