1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-26 21:01:32 +00:00

Add pull order to folder create and edit UI (fixes #677) (#1178)

This commit is contained in:
Catfriend1 2018-07-08 12:32:03 +02:00 committed by Audrius Butkevicius
parent 53aec6a313
commit 23f407ed74
6 changed files with 252 additions and 0 deletions

View file

@ -125,6 +125,14 @@
<action android:name="com.nutomic.syncthingandroid.action.STOP" />
</intent-filter>
</receiver>
<activity android:name=".activities.PullOrderDialogActivity"
android:label="@string/pull_order"
android:theme="@style/Theme.Syncthing.Dialog"
android:parentActivityName=".activities.FolderActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.nutomic.syncthingandroid.activities.FolderActivity" />
</activity>
<activity android:name=".activities.VersioningDialogActivity"
android:label="@string/file_versioning"
android:theme="@style/Theme.Syncthing.Dialog"

View file

@ -71,6 +71,7 @@ public class FolderActivity extends SyncthingActivity
private static final String IS_SHOW_DISCARD_DIALOG = "DISCARD_FOLDER_DIALOG_STATE";
private static final int FILE_VERSIONING_DIALOG_REQUEST = 3454;
private static final int PULL_ORDER_DIALOG_REQUEST = 3455;
private static final String IGNORE_FILE_NAME = ".stignore";
@ -83,6 +84,8 @@ public class FolderActivity extends SyncthingActivity
private SwitchCompat mFolderFileWatcher;
private SwitchCompat mFolderPaused;
private ViewGroup mDevicesContainer;
private TextView mPullOrderTypeView;
private TextView mPullOrderDescriptionView;
private TextView mVersioningDescriptionView;
private TextView mVersioningTypeView;
private TextView mEditIgnores;
@ -150,6 +153,8 @@ public class FolderActivity extends SyncthingActivity
mFolderMasterView = findViewById(R.id.master);
mFolderFileWatcher = findViewById(R.id.fileWatcher);
mFolderPaused = findViewById(R.id.folderPause);
mPullOrderTypeView = findViewById(R.id.pullOrderType);
mPullOrderDescriptionView = findViewById(R.id.pullOrderDescription);
mVersioningDescriptionView = findViewById(R.id.versioningDescription);
mVersioningTypeView = findViewById(R.id.versioningType);
mDevicesContainer = findViewById(R.id.devicesContainer);
@ -158,6 +163,7 @@ public class FolderActivity extends SyncthingActivity
mPathView.setOnClickListener(view ->
startActivityForResult(FolderPickerActivity.createIntent(this, mFolder.path, null), FolderPickerActivity.DIRECTORY_REQUEST_CODE));
findViewById(R.id.pullOrderContainer).setOnClickListener(v -> showPullOrderDialog());
findViewById(R.id.versioningContainer).setOnClickListener(v -> showVersioningDialog());
mEditIgnores.setOnClickListener(v -> editIgnores());
@ -213,6 +219,12 @@ public class FolderActivity extends SyncthingActivity
}
}
private void showPullOrderDialog() {
Intent intent = new Intent(this, PullOrderDialogActivity.class);
intent.putExtra(PullOrderDialogActivity.EXTRA_PULL_ORDER, mFolder.order);
startActivityForResult(intent, PULL_ORDER_DIALOG_REQUEST);
}
private void showVersioningDialog() {
Intent intent = new Intent(this, VersioningDialogActivity.class);
intent.putExtras(getVersioningBundle());
@ -336,6 +348,7 @@ public class FolderActivity extends SyncthingActivity
mLabelView.setText(mFolder.label);
mIdView.setText(mFolder.id);
mPathView.setText(mFolder.path);
updatePullOrderDescription();
updateVersioningDescription();
mFolderMasterView.setChecked(Objects.equal(mFolder.type, "readonly"));
mFolderFileWatcher.setChecked(mFolder.fsWatcherEnabled);
@ -430,6 +443,10 @@ public class FolderActivity extends SyncthingActivity
mEditIgnores.setEnabled(true);
} else if (resultCode == Activity.RESULT_OK && requestCode == FILE_VERSIONING_DIALOG_REQUEST) {
updateVersioning(data.getExtras());
} else if (resultCode == Activity.RESULT_OK && requestCode == PULL_ORDER_DIALOG_REQUEST) {
mFolder.order = data.getStringExtra(PullOrderDialogActivity.EXTRA_RESULT_PULL_ORDER);
updatePullOrderDescription();
mFolderNeedsToUpdate = true;
}
}
@ -546,6 +563,50 @@ public class FolderActivity extends SyncthingActivity
mFolderNeedsToUpdate = true;
}
private void updatePullOrderDescription() {
if (mFolder == null) {
return;
}
if (TextUtils.isEmpty(mFolder.order)) {
setPullOrderDescription(getString(R.string.pull_order_type_random),
getString(R.string.pull_order_type_random_description));
return;
}
switch (mFolder.order) {
case "random":
setPullOrderDescription(getString(R.string.pull_order_type_random),
getString(R.string.pull_order_type_random_description));
break;
case "alphabetic":
setPullOrderDescription(getString(R.string.pull_order_type_alphabetic),
getString(R.string.pull_order_type_alphabetic_description));
break;
case "smallestFirst":
setPullOrderDescription(getString(R.string.pull_order_type_smallestFirst),
getString(R.string.pull_order_type_smallestFirst_description));
break;
case "largestFirst":
setPullOrderDescription(getString(R.string.pull_order_type_largestFirst),
getString(R.string.pull_order_type_largestFirst_description));
break;
case "oldestFirst":
setPullOrderDescription(getString(R.string.pull_order_type_oldestFirst),
getString(R.string.pull_order_type_oldestFirst_description));
break;
case "newestFirst":
setPullOrderDescription(getString(R.string.pull_order_type_newestFirst),
getString(R.string.pull_order_type_newestFirst_description));
break;
}
}
private void setPullOrderDescription(String type, String description) {
mPullOrderTypeView.setText(type);
mPullOrderDescriptionView.setText(description);
}
private void updateVersioningDescription() {
if (mFolder == null){
return;

View file

@ -0,0 +1,80 @@
package com.nutomic.syncthingandroid.activities;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Spinner;
import com.nutomic.syncthingandroid.R;
import java.util.Arrays;
import java.util.List;
public class PullOrderDialogActivity extends AppCompatActivity {
public static final String EXTRA_PULL_ORDER = "com.nutomic.syncthinandroid.activities.PullOrderDialogActivity.PULL_ORDER";
public static final String EXTRA_RESULT_PULL_ORDER = "com.nutomic.syncthinandroid.activities.PullOrderDialogActivity.EXTRA_RESULT_PULL_ORDER";
private String selectedType;
private static final List<String> mTypes = Arrays.asList(
"random",
"alphabetic",
"smallestFirst",
"largestFirst",
"oldestFirst",
"newestFirst"
);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pullorder_dialog);
if (savedInstanceState == null) {
selectedType = getIntent().getStringExtra(EXTRA_PULL_ORDER);
}
initiateFinishBtn();
initiateSpinner();
}
private void initiateFinishBtn() {
Button finishBtn = findViewById(R.id.finish_btn);
finishBtn.setOnClickListener(v -> {
saveConfiguration();
finish();
});
}
private void saveConfiguration() {
Intent intent = new Intent();
intent.putExtra(EXTRA_RESULT_PULL_ORDER, selectedType);
setResult(Activity.RESULT_OK, intent);
}
private void initiateSpinner() {
Spinner pullOrderTypeSpinner = findViewById(R.id.pullOrderTypeSpinner);
pullOrderTypeSpinner.setSelection(mTypes.indexOf(selectedType));
pullOrderTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position != mTypes.indexOf(selectedType)) {
selectedType = mTypes.get(position);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// This is not allowed.
}
});
}
@Override
public void onBackPressed() {
saveConfiguration();
super.onBackPressed();
}
}

View file

@ -110,6 +110,44 @@
android:drawableStart="@drawable/ic_folder_black_24dp"
android:text="@string/folder_pause" />
<LinearLayout
android:id="@+id/pullOrderContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
style="@style/Widget.Syncthing.TextView.Label.Details"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@null"
android:checked="false"
android:drawableLeft="@drawable/ic_content_copy_black_24dp"
android:drawableStart="@drawable/ic_content_copy_black_24dp"
android:text="@string/pull_order" />
<TextView
android:id="@+id/pullOrderType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="75dp"
android:layout_marginStart="75dp"
android:layout_marginTop="-20dp"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
<TextView
android:id="@+id/pullOrderDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="75dp"
android:layout_marginStart="75dp"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
</LinearLayout>
<LinearLayout
android:id="@+id/versioningContainer"
android:layout_width="match_parent"

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="?dialogPreferredPadding"
style="@style/Theme.Syncthing.Dialog">
<Spinner
android:id="@+id/pullOrderTypeSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/pull_order_types"
style="@style/Widget.AppCompat.Spinner.Underlined" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/finish_btn"
style="@style/Widget.AppCompat.Button.ButtonBar.AlertDialog"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="end"
android:text="@string/finish"
android:textColor="@color/primary_dark" />
</LinearLayout>
</ScrollView>
</LinearLayout>

View file

@ -325,6 +325,15 @@ Please report any problems you encounter via Github.</string>
<string name="pref_language_default">Default Language</string>
<string-array name="pull_order_types">
<item>Random</item>
<item>Alphabetic</item>
<item>Smallest First</item>
<item>Largest First</item>
<item>Oldest First</item>
<item>Newest First</item>
</string-array>
<string-array name="versioning_types">
<item>None</item>
<item>TrashCan</item>
@ -650,6 +659,25 @@ Please report any problems you encounter via Github.</string>
<string name="appconfig_receiver_background_enabled">Stopping Syncthing is not supported when running in background is enabled.</string>
<!-- Titles used in the pull order dialog and pull order button in the folder activity -->
<string name="pull_order">File Pull Order</string>
<!-- Displays the current pull order type in the Folder activity -->
<string name="pull_order_type_random">Random</string>
<string name="pull_order_type_alphabetic">Alphabetic</string>
<string name="pull_order_type_smallestFirst">Smallest First</string>
<string name="pull_order_type_largestFirst">Largest First</string>
<string name="pull_order_type_oldestFirst">Oldest First</string>
<string name="pull_order_type_newestFirst">Newest First</string>
<!-- Pull order dialog descriptions for pull order types -->
<string name="pull_order_type_random_description">Pull files in random order.</string>
<string name="pull_order_type_alphabetic_description">Pull files ordered by file name alphabetically.</string>
<string name="pull_order_type_smallestFirst_description">Pull files ordered by file size. Smallest first respectively.</string>
<string name="pull_order_type_largestFirst_description">Pull files ordered by file size. Largest first respectively.</string>
<string name="pull_order_type_oldestFirst_description">Pull files ordered by modification time. Oldest first respectively.</string>
<string name="pull_order_type_newestFirst_description">Pull files ordered by modification time. Newest first respectively.</string>
<!-- Titles used in the file versioning dialog and file versioning button in the folder activity -->
<string name="maximum_age">Maximum Age</string>
<string name="clean_out_after">Clean out after</string>