1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 19:31:30 +00:00

Added support for folder labels.

This commit is contained in:
Felix Ableitner 2016-04-10 00:15:48 +02:00
parent 6f77e4912b
commit 12997d6b36
12 changed files with 89 additions and 54 deletions

View file

@ -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<RestApi.Device> 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() {

View file

@ -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<String> 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);

View file

@ -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());

View file

@ -37,7 +37,7 @@ public class FoldersAdapter extends ArrayAdapter<RestApi.Folder>
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>
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) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 483 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 649 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 812 B

View file

@ -6,13 +6,26 @@
tools:context=".fragments.FolderFragment">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="?android:listDivider"
android:orientation="vertical"
android:paddingBottom="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
android:id="@+id/id"

View file

@ -9,7 +9,7 @@
android:paddingTop="8dp">
<TextView
android:id="@+id/id"
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"

View file

@ -98,6 +98,9 @@
<!-- Setting title -->
<string name="folder_id">Folder ID</string>
<!-- Setting title -->
<string name="folder_label">Folder Label</string>
<!-- Setting title -->
<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 -->
<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-->
<string name="default_folder_id">%1$s-photos</string>