mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-23 04:41:16 +00:00
Added support for folder labels.
This commit is contained in:
parent
6f77e4912b
commit
12997d6b36
12 changed files with 89 additions and 54 deletions
|
@ -68,57 +68,52 @@ public class FolderFragment extends Fragment
|
||||||
|
|
||||||
private RestApi.Folder mFolder;
|
private RestApi.Folder mFolder;
|
||||||
|
|
||||||
|
private EditText mLabelView;
|
||||||
private EditText mIdView;
|
private EditText mIdView;
|
||||||
|
|
||||||
private TextView mPathView;
|
private TextView mPathView;
|
||||||
|
|
||||||
private SwitchCompat mFolderMasterView;
|
private SwitchCompat mFolderMasterView;
|
||||||
|
|
||||||
private ViewGroup mDevicesContainer;
|
private ViewGroup mDevicesContainer;
|
||||||
|
|
||||||
private TextView mVersioningKeepView;
|
private TextView mVersioningKeepView;
|
||||||
|
|
||||||
private boolean mIsCreateMode;
|
private boolean mIsCreateMode;
|
||||||
|
private boolean mFolderNeedsToUpdate;
|
||||||
|
|
||||||
private KeepVersionsDialogFragment mKeepVersionsDialogFragment = new KeepVersionsDialogFragment();
|
private KeepVersionsDialogFragment mKeepVersionsDialogFragment = new KeepVersionsDialogFragment();
|
||||||
|
|
||||||
private TextWatcher mIdTextWatcher = new TextWatcherAdapter() {
|
private TextWatcher mTextWatcher = new TextWatcherAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
mFolder.id = s.toString();
|
mFolder.label = mLabelView.getText().toString();
|
||||||
updateFolder();
|
mFolder.id = mIdView.getText().toString();
|
||||||
|
mFolder.path = mPathView.getText().toString();
|
||||||
|
mFolderNeedsToUpdate = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private TextWatcher mPathTextWatcher = new TextWatcherAdapter() {
|
private CompoundButton.OnCheckedChangeListener mCheckedListener =
|
||||||
@Override
|
new CompoundButton.OnCheckedChangeListener() {
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
mFolder.path = s.toString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private CompoundButton.OnCheckedChangeListener mMasterCheckedListener = new CompoundButton.OnCheckedChangeListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
|
||||||
mFolder.readOnly = isChecked;
|
switch (view.getId()) {
|
||||||
updateFolder();
|
case R.id.master:
|
||||||
}
|
mFolder.readOnly = isChecked;
|
||||||
};
|
mFolderNeedsToUpdate = true;
|
||||||
|
break;
|
||||||
private CompoundButton.OnCheckedChangeListener mOnShareChangeListener = new CompoundButton.OnCheckedChangeListener() {
|
case R.id.share_device_id:
|
||||||
@Override
|
RestApi.Device device = (RestApi.Device) view.getTag();
|
||||||
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
|
if (isChecked) {
|
||||||
RestApi.Device device = (RestApi.Device) view.getTag();
|
mFolder.deviceIds.add(device.deviceID);
|
||||||
if (isChecked) {
|
} else {
|
||||||
mFolder.deviceIds.add(device.deviceID);
|
mFolder.deviceIds.remove(device.deviceID);
|
||||||
} else {
|
}
|
||||||
mFolder.deviceIds.remove(device.deviceID);
|
mFolderNeedsToUpdate = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
updateFolder();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private KeepVersionsDialogFragment.OnValueChangeListener mOnValueChangeListener = new KeepVersionsDialogFragment.OnValueChangeListener() {
|
private KeepVersionsDialogFragment.OnValueChangeListener mOnValueChangeListener =
|
||||||
|
new KeepVersionsDialogFragment.OnValueChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onValueChange(int intValue) {
|
public void onValueChange(int intValue) {
|
||||||
if (intValue == 0) {
|
if (intValue == 0) {
|
||||||
|
@ -129,7 +124,7 @@ public class FolderFragment extends Fragment
|
||||||
((SimpleVersioning) mFolder.versioning).setParams(intValue);
|
((SimpleVersioning) mFolder.versioning).setParams(intValue);
|
||||||
mVersioningKeepView.setText(valueOf(intValue));
|
mVersioningKeepView.setText(valueOf(intValue));
|
||||||
}
|
}
|
||||||
updateFolder();
|
mFolderNeedsToUpdate = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -144,13 +139,6 @@ public class FolderFragment extends Fragment
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private View.OnClickListener mVersioningContainerClickListener = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
mKeepVersionsDialogFragment.show(getFragmentManager(), KEEP_VERSIONS_DIALOG_TAG);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -179,6 +167,17 @@ public class FolderFragment extends Fragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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 (mFolderNeedsToUpdate) {
|
||||||
|
updateFolder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save current settings in case we are in create mode and they aren't yet stored in the config.
|
* Save current settings in case we are in create mode and they aren't yet stored in the config.
|
||||||
*/
|
*/
|
||||||
|
@ -197,6 +196,7 @@ public class FolderFragment extends Fragment
|
||||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
mLabelView = (EditText) view.findViewById(R.id.label);
|
||||||
mIdView = (EditText) view.findViewById(R.id.id);
|
mIdView = (EditText) view.findViewById(R.id.id);
|
||||||
mPathView = (TextView) view.findViewById(R.id.directory);
|
mPathView = (TextView) view.findViewById(R.id.directory);
|
||||||
mFolderMasterView = (SwitchCompat) view.findViewById(R.id.master);
|
mFolderMasterView = (SwitchCompat) view.findViewById(R.id.master);
|
||||||
|
@ -204,9 +204,17 @@ public class FolderFragment extends Fragment
|
||||||
mDevicesContainer = (ViewGroup) view.findViewById(R.id.devicesContainer);
|
mDevicesContainer = (ViewGroup) view.findViewById(R.id.devicesContainer);
|
||||||
|
|
||||||
mPathView.setOnClickListener(mPathViewClickListener);
|
mPathView.setOnClickListener(mPathViewClickListener);
|
||||||
view.findViewById(R.id.versioningContainer).setOnClickListener(mVersioningContainerClickListener);
|
view.findViewById(R.id.versioningContainer).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
mKeepVersionsDialogFragment.show(getFragmentManager(), KEEP_VERSIONS_DIALOG_TAG);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (!mIsCreateMode) {
|
if (mIsCreateMode) {
|
||||||
|
// Open keyboard on label view in edit mode.
|
||||||
|
mLabelView.requestFocus();
|
||||||
|
} else {
|
||||||
prepareEditMode();
|
prepareEditMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,8 +222,9 @@ public class FolderFragment extends Fragment
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
mIdView.removeTextChangedListener(mIdTextWatcher);
|
mLabelView.removeTextChangedListener(mTextWatcher);
|
||||||
mPathView.removeTextChangedListener(mPathTextWatcher);
|
mIdView.removeTextChangedListener(mTextWatcher);
|
||||||
|
mPathView.removeTextChangedListener(mTextWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -252,21 +261,23 @@ public class FolderFragment extends Fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateViewsAndSetListeners() {
|
private void updateViewsAndSetListeners() {
|
||||||
mIdView.removeTextChangedListener(mIdTextWatcher);
|
mLabelView.removeTextChangedListener(mTextWatcher);
|
||||||
mPathView.removeTextChangedListener(mPathTextWatcher);
|
mIdView.removeTextChangedListener(mTextWatcher);
|
||||||
|
mPathView.removeTextChangedListener(mTextWatcher);
|
||||||
mFolderMasterView.setOnCheckedChangeListener(null);
|
mFolderMasterView.setOnCheckedChangeListener(null);
|
||||||
mKeepVersionsDialogFragment.setOnValueChangeListener(null);
|
mKeepVersionsDialogFragment.setOnValueChangeListener(null);
|
||||||
|
|
||||||
// Update views
|
// Update views
|
||||||
|
mLabelView.setText(mFolder.label);
|
||||||
mIdView.setText(mFolder.id);
|
mIdView.setText(mFolder.id);
|
||||||
mPathView.setText(mFolder.path);
|
mPathView.setText(mFolder.path);
|
||||||
mFolderMasterView.setChecked(mFolder.readOnly);
|
mFolderMasterView.setChecked(mFolder.readOnly);
|
||||||
List<RestApi.Device> devicesList = mSyncthingService.getApi().getDevices(false);
|
List<RestApi.Device> devicesList = mSyncthingService.getApi().getDevices(false);
|
||||||
|
|
||||||
|
mDevicesContainer.removeAllViews();
|
||||||
if (devicesList.isEmpty()) {
|
if (devicesList.isEmpty()) {
|
||||||
addEmptyDeviceListView();
|
addEmptyDeviceListView();
|
||||||
} else {
|
} else {
|
||||||
mDevicesContainer.removeAllViews();
|
|
||||||
for (RestApi.Device n : devicesList) {
|
for (RestApi.Device n : devicesList) {
|
||||||
addDeviceViewAndSetListener(n, LayoutInflater.from(getActivity()));
|
addDeviceViewAndSetListener(n, LayoutInflater.from(getActivity()));
|
||||||
}
|
}
|
||||||
|
@ -283,9 +294,10 @@ public class FolderFragment extends Fragment
|
||||||
mKeepVersionsDialogFragment.setValue(versions);
|
mKeepVersionsDialogFragment.setValue(versions);
|
||||||
|
|
||||||
// Keep state updated
|
// Keep state updated
|
||||||
mIdView.addTextChangedListener(mIdTextWatcher);
|
mLabelView.addTextChangedListener(mTextWatcher);
|
||||||
mPathView.addTextChangedListener(mPathTextWatcher);
|
mIdView.addTextChangedListener(mTextWatcher);
|
||||||
mFolderMasterView.setOnCheckedChangeListener(mMasterCheckedListener);
|
mPathView.addTextChangedListener(mTextWatcher);
|
||||||
|
mFolderMasterView.setOnCheckedChangeListener(mCheckedListener);
|
||||||
mKeepVersionsDialogFragment.setOnValueChangeListener(mOnValueChangeListener);
|
mKeepVersionsDialogFragment.setOnValueChangeListener(mOnValueChangeListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +355,7 @@ public class FolderFragment extends Fragment
|
||||||
if (resultCode == Activity.RESULT_OK && requestCode == DIRECTORY_REQUEST_CODE) {
|
if (resultCode == Activity.RESULT_OK && requestCode == DIRECTORY_REQUEST_CODE) {
|
||||||
mFolder.path = data.getStringExtra(FolderPickerActivity.EXTRA_RESULT_DIRECTORY);
|
mFolder.path = data.getStringExtra(FolderPickerActivity.EXTRA_RESULT_DIRECTORY);
|
||||||
mPathView.setText(mFolder.path);
|
mPathView.setText(mFolder.path);
|
||||||
updateFolder();
|
mFolderNeedsToUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,7 +396,7 @@ public class FolderFragment extends Fragment
|
||||||
deviceView.setChecked(mFolder.deviceIds.contains(device.deviceID));
|
deviceView.setChecked(mFolder.deviceIds.contains(device.deviceID));
|
||||||
deviceView.setText(RestApi.getDeviceDisplayName(device));
|
deviceView.setText(RestApi.getDeviceDisplayName(device));
|
||||||
deviceView.setTag(device);
|
deviceView.setTag(device);
|
||||||
deviceView.setOnCheckedChangeListener(mOnShareChangeListener);
|
deviceView.setOnCheckedChangeListener(mCheckedListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFolder() {
|
private void updateFolder() {
|
||||||
|
|
|
@ -84,6 +84,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
|
|
||||||
public static class Folder implements Serializable {
|
public static class Folder implements Serializable {
|
||||||
public String path;
|
public String path;
|
||||||
|
public String label;
|
||||||
public String id;
|
public String id;
|
||||||
public String invalid;
|
public String invalid;
|
||||||
public List<String> deviceIds;
|
public List<String> deviceIds;
|
||||||
|
@ -473,6 +474,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
JSONObject json = folders.getJSONObject(i);
|
JSONObject json = folders.getJSONObject(i);
|
||||||
Folder r = new Folder();
|
Folder r = new Folder();
|
||||||
r.path = json.getString("path");
|
r.path = json.getString("path");
|
||||||
|
r.label = json.getString("label");
|
||||||
r.id = json.getString("id");
|
r.id = json.getString("id");
|
||||||
// TODO: Field seems to be missing sometimes.
|
// TODO: Field seems to be missing sometimes.
|
||||||
// https://github.com/syncthing/syncthing-android/issues/291
|
// https://github.com/syncthing/syncthing-android/issues/291
|
||||||
|
@ -872,6 +874,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r.put("path", folder.path);
|
r.put("path", folder.path);
|
||||||
|
r.put("label", folder.label);
|
||||||
r.put("id", folder.id);
|
r.put("id", folder.id);
|
||||||
r.put("ignorePerms", true);
|
r.put("ignorePerms", true);
|
||||||
r.put("readOnly", folder.readOnly);
|
r.put("readOnly", folder.readOnly);
|
||||||
|
|
|
@ -232,6 +232,7 @@ public class ConfigXml {
|
||||||
.replace(" ", "_")
|
.replace(" ", "_")
|
||||||
.toLowerCase(Locale.US)
|
.toLowerCase(Locale.US)
|
||||||
.replaceAll("[^a-z0-9_-]", "");
|
.replaceAll("[^a-z0-9_-]", "");
|
||||||
|
folder.setAttribute("label", mContext.getString(R.string.default_folder_label));
|
||||||
folder.setAttribute("id", mContext.getString(R.string.default_folder_id, model));
|
folder.setAttribute("id", mContext.getString(R.string.default_folder_id, model));
|
||||||
folder.setAttribute("path", Environment
|
folder.setAttribute("path", Environment
|
||||||
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
|
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class FoldersAdapter extends ArrayAdapter<RestApi.Folder>
|
||||||
if (convertView == null)
|
if (convertView == null)
|
||||||
convertView = mInflater.inflate(R.layout.item_folder_list, parent, false);
|
convertView = mInflater.inflate(R.layout.item_folder_list, parent, false);
|
||||||
|
|
||||||
TextView id = (TextView) convertView.findViewById(R.id.id);
|
TextView label = (TextView) convertView.findViewById(R.id.label);
|
||||||
TextView state = (TextView) convertView.findViewById(R.id.state);
|
TextView state = (TextView) convertView.findViewById(R.id.state);
|
||||||
TextView directory = (TextView) convertView.findViewById(R.id.directory);
|
TextView directory = (TextView) convertView.findViewById(R.id.directory);
|
||||||
TextView items = (TextView) convertView.findViewById(R.id.items);
|
TextView items = (TextView) convertView.findViewById(R.id.items);
|
||||||
|
@ -46,7 +46,7 @@ public class FoldersAdapter extends ArrayAdapter<RestApi.Folder>
|
||||||
|
|
||||||
RestApi.Folder folder = getItem(position);
|
RestApi.Folder folder = getItem(position);
|
||||||
RestApi.Model model = mModels.get(folder.id);
|
RestApi.Model model = mModels.get(folder.id);
|
||||||
id.setText(folder.id);
|
label.setText(TextUtils.isEmpty(folder.label) ? folder.id : folder.label);
|
||||||
state.setTextColor(getContext().getResources().getColor(R.color.text_green));
|
state.setTextColor(getContext().getResources().getColor(R.color.text_green));
|
||||||
directory.setText(folder.path);
|
directory.setText(folder.path);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
|
|
BIN
src/main/res/drawable-hdpi/ic_label_outline_black_24dp.png
Normal file
BIN
src/main/res/drawable-hdpi/ic_label_outline_black_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 403 B |
BIN
src/main/res/drawable-mdpi/ic_label_outline_black_24dp.png
Normal file
BIN
src/main/res/drawable-mdpi/ic_label_outline_black_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 292 B |
BIN
src/main/res/drawable-xhdpi/ic_label_outline_black_24dp.png
Normal file
BIN
src/main/res/drawable-xhdpi/ic_label_outline_black_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 483 B |
BIN
src/main/res/drawable-xxhdpi/ic_label_outline_black_24dp.png
Normal file
BIN
src/main/res/drawable-xxhdpi/ic_label_outline_black_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 649 B |
BIN
src/main/res/drawable-xxxhdpi/ic_label_outline_black_24dp.png
Normal file
BIN
src/main/res/drawable-xxxhdpi/ic_label_outline_black_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 812 B |
|
@ -6,13 +6,26 @@
|
||||||
tools:context=".fragments.FolderFragment">
|
tools:context=".fragments.FolderFragment">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:divider="?android:listDivider"
|
android:divider="?android:listDivider"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingBottom="8dp"
|
android:paddingBottom="8dp"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:showDividers="middle">
|
android:showDividers="middle"
|
||||||
|
android:focusableInTouchMode="true">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/label"
|
||||||
|
style="@style/Widget.Syncthing.TextView.Label.Details.Field"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:drawableLeft="@drawable/ic_label_outline_black_24dp"
|
||||||
|
android:drawableStart="@drawable/ic_label_outline_black_24dp"
|
||||||
|
android:hint="@string/folder_label"
|
||||||
|
android:imeOptions="actionDone"
|
||||||
|
android:inputType="textCapWords|textNoSuggestions" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/id"
|
android:id="@+id/id"
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
android:paddingTop="8dp">
|
android:paddingTop="8dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/id"
|
android:id="@+id/label"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
|
|
|
@ -98,6 +98,9 @@
|
||||||
<!-- Setting title -->
|
<!-- Setting title -->
|
||||||
<string name="folder_id">Folder ID</string>
|
<string name="folder_id">Folder ID</string>
|
||||||
|
|
||||||
|
<!-- Setting title -->
|
||||||
|
<string name="folder_label">Folder Label</string>
|
||||||
|
|
||||||
<!-- Setting title -->
|
<!-- Setting title -->
|
||||||
<string name="directory">Directory</string>
|
<string name="directory">Directory</string>
|
||||||
|
|
||||||
|
@ -418,6 +421,9 @@ Please report any problems you encounter via Github.</string>
|
||||||
<!-- Toast shown if syncthing failed to create a config -->
|
<!-- Toast shown if syncthing failed to create a config -->
|
||||||
<string name="config_create_failed">Failed to create a Syncthing config. Please check the logs.</string>
|
<string name="config_create_failed">Failed to create a Syncthing config. Please check the logs.</string>
|
||||||
|
|
||||||
|
<!-- Label of the default folder created of first start (camera folder). -->
|
||||||
|
<string name="default_folder_label">Camera</string>
|
||||||
|
|
||||||
<!-- ID of the default folder created on first start (camera folder). Must only contain 'a-z0-9_-'. Parameter is the device name-->
|
<!-- ID of the default folder created on first start (camera folder). Must only contain 'a-z0-9_-'. Parameter is the device name-->
|
||||||
<string name="default_folder_id">%1$s-photos</string>
|
<string name="default_folder_id">%1$s-photos</string>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue