1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 11:21:29 +00:00

Added "edit ignores" button (fixes #881)

This commit is contained in:
Felix Ableitner 2017-09-26 21:16:56 +09:00
parent 3f0be34f3e
commit 42a87031f1
8 changed files with 75 additions and 7 deletions

View file

@ -3,7 +3,9 @@ package com.nutomic.syncthingandroid.activities;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.SwitchCompat;
@ -30,6 +32,8 @@ import com.nutomic.syncthingandroid.model.Folder;
import com.nutomic.syncthingandroid.service.SyncthingService;
import com.nutomic.syncthingandroid.util.TextWatcherAdapter;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import java.util.Map;
@ -64,6 +68,8 @@ public class FolderActivity extends SyncthingActivity
private static final int FILE_VERSIONING_DIALOG_REQUEST = 3454;
private static final String IGNORE_FILE_NAME = ".stignore";
private Folder mFolder;
private EditText mLabelView;
@ -73,6 +79,7 @@ public class FolderActivity extends SyncthingActivity
private ViewGroup mDevicesContainer;
private TextView mVersioningDescriptionView;
private TextView mVersioningTypeView;
private TextView mEditIgnores;
private boolean mIsCreateMode;
private boolean mFolderNeedsToUpdate;
@ -130,11 +137,13 @@ public class FolderActivity extends SyncthingActivity
mVersioningDescriptionView = findViewById(R.id.versioningDescription);
mVersioningTypeView = findViewById(R.id.versioningType);
mDevicesContainer = findViewById(R.id.devicesContainer);
mEditIgnores = findViewById(R.id.edit_ignores);
mPathView.setOnClickListener(view ->
startActivityForResult(FolderPickerActivity.createIntent(this, mFolder.path), FolderPickerActivity.DIRECTORY_REQUEST_CODE));
findViewById(R.id.versioningContainer).setOnClickListener(v -> showVersioningDialog());
mEditIgnores.setOnClickListener(v -> editIgnores());
if (mIsCreateMode) {
if (savedInstanceState != null) {
@ -148,6 +157,7 @@ public class FolderActivity extends SyncthingActivity
}
// Open keyboard on label view in edit mode.
mLabelView.requestFocus();
mEditIgnores.setEnabled(false);
}
else {
prepareEditMode();
@ -166,6 +176,25 @@ public class FolderActivity extends SyncthingActivity
}
}
private void editIgnores() {
try {
File ignoreFile = new File(mFolder.path, IGNORE_FILE_NAME);
if (!ignoreFile.exists() && !ignoreFile.createNewFile()) {
Toast.makeText(this, R.string.create_ignore_file_error, Toast.LENGTH_SHORT).show();
return;
}
Intent intent = new Intent(Intent.ACTION_EDIT);
Uri uri = Uri.fromFile(ignoreFile);
intent.setDataAndType(uri, "text/plain");
startActivity(intent);
} catch (IOException e) {
Log.w(TAG, e);
} catch (ActivityNotFoundException e) {
Log.w(TAG, e);
Toast.makeText(this, R.string.edit_ignore_file_error, Toast.LENGTH_SHORT).show();
}
}
private void showVersioningDialog() {
Intent intent = new Intent(this, VersioningDialogActivity.class);
intent.putExtras(getVersioningBundle());
@ -369,6 +398,7 @@ public class FolderActivity extends SyncthingActivity
mFolder.path = data.getStringExtra(FolderPickerActivity.EXTRA_RESULT_DIRECTORY);
mPathView.setText(mFolder.path);
mFolderNeedsToUpdate = true;
mEditIgnores.setEnabled(true);
} else if (resultCode == Activity.RESULT_OK && requestCode == FILE_VERSIONING_DIALOG_REQUEST) {
updateVersioning(data.getExtras());
}

View file

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import com.annimon.stream.Stream;
import com.nutomic.syncthingandroid.service.RestApi;
import com.nutomic.syncthingandroid.service.SyncthingService;
import com.nutomic.syncthingandroid.service.SyncthingServiceBinder;
@ -46,7 +47,7 @@ public abstract class SyncthingActivity extends ToolbarBindingActivity implement
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
SyncthingServiceBinder binder = (SyncthingServiceBinder) iBinder;
mSyncthingService = binder.getService();
mServiceConnectedListeners.forEach(OnServiceConnectedListener::onServiceConnected);
Stream.of(mServiceConnectedListeners).forEach(OnServiceConnectedListener::onServiceConnected);
mServiceConnectedListeners.clear();
}

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_visibility_off_black_24dp_inactive" android:state_enabled="false" />
<item android:drawable="@drawable/ic_visibility_off_black_24dp_active" />
</selector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#8A000000"
android:pathData="M12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.7,-2.89 3.43,-4.75 -1.73,-4.39 -6,-7.5 -11,-7.5 -1.4,0 -2.74,0.25 -3.98,0.7l2.16,2.16C10.74,7.13 11.35,7 12,7zM2,4.27l2.28,2.28 0.46,0.46C3.08,8.3 1.78,10.02 1,12c1.73,4.39 6,7.5 11,7.5 1.55,0 3.03,-0.3 4.38,-0.84l0.42,0.42L19.73,22 21,20.73 3.27,3 2,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zM11.84,9.02l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01z"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#42000000"
android:pathData="M12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.7,-2.89 3.43,-4.75 -1.73,-4.39 -6,-7.5 -11,-7.5 -1.4,0 -2.74,0.25 -3.98,0.7l2.16,2.16C10.74,7.13 11.35,7 12,7zM2,4.27l2.28,2.28 0.46,0.46C3.08,8.3 1.78,10.02 1,12c1.73,4.39 6,7.5 11,7.5 1.55,0 3.03,-0.3 4.38,-0.84l0.42,0.42L19.73,22 21,20.73 3.27,3 2,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zM11.84,9.02l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01z"/>
</vector>

View file

@ -99,8 +99,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/abc_action_bar_content_inset_material"
android:layout_marginRight="@dimen/abc_action_bar_content_inset_material"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
tools:ignore="HardcodedText" />
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
</LinearLayout>
<android.support.v7.widget.SwitchCompat

View file

@ -106,8 +106,7 @@
android:layout_marginLeft="75dp"
android:layout_marginStart="75dp"
android:layout_marginTop="-20dp"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
tools:ignore="HardcodedText" />
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
<TextView
android:id="@+id/versioningDescription"
@ -115,8 +114,18 @@
android:layout_height="wrap_content"
android:layout_marginLeft="75dp"
android:layout_marginStart="75dp"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
tools:ignore="HardcodedText" />
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
<TextView
android:id="@+id/edit_ignores"
style="@style/Widget.Syncthing.TextView.Label.Details"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@null"
android:drawableLeft="@drawable/ic_visibility_off_black_24dp"
android:drawableStart="@drawable/ic_visibility_off_black_24dp"
android:text="@string/ignore_patterns"/>
</LinearLayout>
</LinearLayout>

View file

@ -167,6 +167,12 @@ Please report any problems you encounter via Github.</string>
<string name="dialog_discard_changes">Discard your changes?</string>
<string name="ignore_patterns">Ignore Patterns</string>
<string name="create_ignore_file_error">Failed to create ignore file. Is the directory writable?</string>
<string name="edit_ignore_file_error">No text editor found</string>
<!-- DeviceActivity -->