diff --git a/ext/syncthing/src/github.com/syncthing/syncthing b/ext/syncthing/src/github.com/syncthing/syncthing index 94c6110f..0155b6f8 160000 --- a/ext/syncthing/src/github.com/syncthing/syncthing +++ b/ext/syncthing/src/github.com/syncthing/syncthing @@ -1 +1 @@ -Subproject commit 94c6110f2e10ab8dbb0a416556701317ecd437cc +Subproject commit 0155b6f84171724686694417cd8015bdffb31e22 diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/FolderFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/FolderFragment.java index 0d119c46..76570c85 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/FolderFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/FolderFragment.java @@ -68,57 +68,52 @@ public class FolderFragment extends Fragment private RestApi.Folder mFolder; + private EditText mLabelView; private EditText mIdView; - private TextView mPathView; - private SwitchCompat mFolderMasterView; - private ViewGroup mDevicesContainer; - private TextView mVersioningKeepView; private boolean mIsCreateMode; + private boolean mFolderNeedsToUpdate; private KeepVersionsDialogFragment mKeepVersionsDialogFragment = new KeepVersionsDialogFragment(); - private TextWatcher mIdTextWatcher = new TextWatcherAdapter() { + private TextWatcher mTextWatcher = new TextWatcherAdapter() { @Override public void afterTextChanged(Editable s) { - mFolder.id = s.toString(); - updateFolder(); + mFolder.label = mLabelView.getText().toString(); + mFolder.id = mIdView.getText().toString(); + mFolder.path = mPathView.getText().toString(); + mFolderNeedsToUpdate = true; } }; - private TextWatcher mPathTextWatcher = new TextWatcherAdapter() { - @Override - public void afterTextChanged(Editable s) { - mFolder.path = s.toString(); - } - }; - - private CompoundButton.OnCheckedChangeListener mMasterCheckedListener = new CompoundButton.OnCheckedChangeListener() { + private CompoundButton.OnCheckedChangeListener mCheckedListener = + new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton view, boolean isChecked) { - mFolder.readOnly = isChecked; - updateFolder(); - } - }; - - private CompoundButton.OnCheckedChangeListener mOnShareChangeListener = new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton view, boolean isChecked) { - RestApi.Device device = (RestApi.Device) view.getTag(); - if (isChecked) { - mFolder.deviceIds.add(device.deviceID); - } else { - mFolder.deviceIds.remove(device.deviceID); + switch (view.getId()) { + case R.id.master: + mFolder.readOnly = isChecked; + mFolderNeedsToUpdate = true; + break; + case R.id.share_device_id: + RestApi.Device device = (RestApi.Device) view.getTag(); + if (isChecked) { + mFolder.deviceIds.add(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 public void onValueChange(int intValue) { if (intValue == 0) { @@ -129,7 +124,7 @@ public class FolderFragment extends Fragment ((SimpleVersioning) mFolder.versioning).setParams(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 public void onCreate(Bundle 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. */ @@ -197,6 +196,7 @@ public class FolderFragment extends Fragment public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + mLabelView = (EditText) view.findViewById(R.id.label); mIdView = (EditText) view.findViewById(R.id.id); mPathView = (TextView) view.findViewById(R.id.directory); mFolderMasterView = (SwitchCompat) view.findViewById(R.id.master); @@ -204,9 +204,17 @@ public class FolderFragment extends Fragment mDevicesContainer = (ViewGroup) view.findViewById(R.id.devicesContainer); 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(); } } @@ -214,8 +222,9 @@ public class FolderFragment extends Fragment @Override public void onDestroyView() { super.onDestroyView(); - mIdView.removeTextChangedListener(mIdTextWatcher); - mPathView.removeTextChangedListener(mPathTextWatcher); + mLabelView.removeTextChangedListener(mTextWatcher); + mIdView.removeTextChangedListener(mTextWatcher); + mPathView.removeTextChangedListener(mTextWatcher); } @Override @@ -252,21 +261,23 @@ public class FolderFragment extends Fragment } private void updateViewsAndSetListeners() { - mIdView.removeTextChangedListener(mIdTextWatcher); - mPathView.removeTextChangedListener(mPathTextWatcher); + mLabelView.removeTextChangedListener(mTextWatcher); + mIdView.removeTextChangedListener(mTextWatcher); + mPathView.removeTextChangedListener(mTextWatcher); mFolderMasterView.setOnCheckedChangeListener(null); mKeepVersionsDialogFragment.setOnValueChangeListener(null); // Update views + mLabelView.setText(mFolder.label); mIdView.setText(mFolder.id); mPathView.setText(mFolder.path); mFolderMasterView.setChecked(mFolder.readOnly); List devicesList = mSyncthingService.getApi().getDevices(false); + mDevicesContainer.removeAllViews(); if (devicesList.isEmpty()) { addEmptyDeviceListView(); } else { - mDevicesContainer.removeAllViews(); for (RestApi.Device n : devicesList) { addDeviceViewAndSetListener(n, LayoutInflater.from(getActivity())); } @@ -283,9 +294,10 @@ public class FolderFragment extends Fragment mKeepVersionsDialogFragment.setValue(versions); // Keep state updated - mIdView.addTextChangedListener(mIdTextWatcher); - mPathView.addTextChangedListener(mPathTextWatcher); - mFolderMasterView.setOnCheckedChangeListener(mMasterCheckedListener); + mLabelView.addTextChangedListener(mTextWatcher); + mIdView.addTextChangedListener(mTextWatcher); + mPathView.addTextChangedListener(mTextWatcher); + mFolderMasterView.setOnCheckedChangeListener(mCheckedListener); mKeepVersionsDialogFragment.setOnValueChangeListener(mOnValueChangeListener); } @@ -343,7 +355,7 @@ 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); - updateFolder(); + mFolderNeedsToUpdate = true; } } @@ -384,7 +396,7 @@ public class FolderFragment extends Fragment deviceView.setChecked(mFolder.deviceIds.contains(device.deviceID)); deviceView.setText(RestApi.getDeviceDisplayName(device)); deviceView.setTag(device); - deviceView.setOnCheckedChangeListener(mOnShareChangeListener); + deviceView.setOnCheckedChangeListener(mCheckedListener); } private void updateFolder() { diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java index b5e08a8b..21768c9c 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java @@ -84,6 +84,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, public static class Folder implements Serializable { public String path; + public String label; public String id; public String invalid; public List deviceIds; @@ -473,6 +474,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, JSONObject json = folders.getJSONObject(i); Folder r = new Folder(); r.path = json.getString("path"); + r.label = json.getString("label"); r.id = json.getString("id"); // TODO: Field seems to be missing sometimes. // 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("label", folder.label); r.put("id", folder.id); r.put("ignorePerms", true); r.put("readOnly", folder.readOnly); diff --git a/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java b/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java index fab8be61..7ce3e7cd 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java @@ -232,6 +232,7 @@ public class ConfigXml { .replace(" ", "_") .toLowerCase(Locale.US) .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("path", Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath()); diff --git a/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java b/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java index 39805fc3..76a30cb5 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java @@ -37,7 +37,7 @@ public class FoldersAdapter extends ArrayAdapter if (convertView == null) 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 directory = (TextView) convertView.findViewById(R.id.directory); TextView items = (TextView) convertView.findViewById(R.id.items); @@ -46,7 +46,7 @@ public class FoldersAdapter extends ArrayAdapter RestApi.Folder folder = getItem(position); 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)); directory.setText(folder.path); if (model != null) { diff --git a/src/main/res/drawable-hdpi/ic_label_outline_black_24dp.png b/src/main/res/drawable-hdpi/ic_label_outline_black_24dp.png new file mode 100644 index 00000000..8b58b07f Binary files /dev/null and b/src/main/res/drawable-hdpi/ic_label_outline_black_24dp.png differ diff --git a/src/main/res/drawable-mdpi/ic_label_outline_black_24dp.png b/src/main/res/drawable-mdpi/ic_label_outline_black_24dp.png new file mode 100644 index 00000000..7ca623c5 Binary files /dev/null and b/src/main/res/drawable-mdpi/ic_label_outline_black_24dp.png differ diff --git a/src/main/res/drawable-xhdpi/ic_label_outline_black_24dp.png b/src/main/res/drawable-xhdpi/ic_label_outline_black_24dp.png new file mode 100644 index 00000000..7681beb0 Binary files /dev/null and b/src/main/res/drawable-xhdpi/ic_label_outline_black_24dp.png differ diff --git a/src/main/res/drawable-xxhdpi/ic_label_outline_black_24dp.png b/src/main/res/drawable-xxhdpi/ic_label_outline_black_24dp.png new file mode 100644 index 00000000..39a002d9 Binary files /dev/null and b/src/main/res/drawable-xxhdpi/ic_label_outline_black_24dp.png differ diff --git a/src/main/res/drawable-xxxhdpi/ic_label_outline_black_24dp.png b/src/main/res/drawable-xxxhdpi/ic_label_outline_black_24dp.png new file mode 100644 index 00000000..2446c9a1 Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/ic_label_outline_black_24dp.png differ diff --git a/src/main/res/layout/fragment_folder.xml b/src/main/res/layout/fragment_folder.xml index 2f1d8fe4..7cd176f9 100644 --- a/src/main/res/layout/fragment_folder.xml +++ b/src/main/res/layout/fragment_folder.xml @@ -6,13 +6,26 @@ tools:context=".fragments.FolderFragment"> + android:showDividers="middle" + android:focusableInTouchMode="true"> + + Folder ID + + Folder Label + Directory @@ -418,6 +421,9 @@ Please report any problems you encounter via Github. Failed to create a Syncthing config. Please check the logs. + + Camera + %1$s-photos