From 35839feeb935762f6cef0453db4e6b7c5de9c7da Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Thu, 11 Jul 2019 13:09:39 +0200 Subject: [PATCH] Override changes: Show confirmation dialog (fixes #397) (#436) * FoldersAdapter: Move code into onClickOverride * Override changes: Show confirmation dialog (fixes #397) * Update strings.xml --- .../views/FoldersAdapter.java | 23 +++++++++++++------ app/src/main/res/values/strings.xml | 3 +++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java b/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java index f44696ee..1ab46ab3 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java @@ -1,5 +1,6 @@ package com.nutomic.syncthingandroid.views; +import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.databinding.DataBindingUtil; @@ -53,13 +54,7 @@ public class FoldersAdapter extends ArrayAdapter { Folder folder = getItem(position); binding.label.setText(TextUtils.isEmpty(folder.label) ? folder.id : folder.label); binding.directory.setText(folder.path); - binding.override.setOnClickListener(v -> { - // Send "Override changes" through our service to the REST API. - Intent intent = new Intent(mContext, SyncthingService.class) - .putExtra(SyncthingService.EXTRA_FOLDER_ID, folder.id); - intent.setAction(SyncthingService.ACTION_OVERRIDE_CHANGES); - mContext.startService(intent); - }); + binding.override.setOnClickListener(view -> { onClickOverride(view, folder); } ); binding.openFolder.setOnClickListener(view -> { FileUtils.openFolder(mContext, folder.path); } ); // Update folder icon. @@ -194,5 +189,19 @@ public class FoldersAdapter extends ArrayAdapter { } } + private void onClickOverride(View view, Folder folder) { + AlertDialog.Builder confirmDialog = new AlertDialog.Builder(mContext) + .setTitle(R.string.override_changes) + .setMessage(R.string.override_changes_question) + .setPositiveButton(android.R.string.ok, (dialogInterface, i) -> { + // Send "Override changes" through our service to the REST API. + Intent intent = new Intent(mContext, SyncthingService.class) + .putExtra(SyncthingService.EXTRA_FOLDER_ID, folder.id); + intent.setAction(SyncthingService.ACTION_OVERRIDE_CHANGES); + mContext.startService(intent); + }) + .setNegativeButton(android.R.string.no, (dialogInterface, i) -> {}); + confirmDialog.show(); + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2ce0fbf5..6835922d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -127,6 +127,9 @@ Please report any problems you encounter via Github. Override changes + + This will undo all changes made on the other devices sharing this folder. Proceed? + Open file manager Open file with No app found to open the file.