瀏覽代碼

Refs #28 Add delete button

isundil 7 年之前
父節點
當前提交
ee0f2cec4b

+ 20 - 8
app/src/main/java/info/knacki/pass/ui/EncryptionInformationActivity.java

@@ -18,6 +18,7 @@ import info.knacki.pass.io.IFileInterface;
 import info.knacki.pass.io.OnResponseListener;
 import info.knacki.pass.settings.SettingsManager;
 import info.knacki.pass.ui.alertPrompt.AlertPromptGenerator;
+import info.knacki.pass.ui.alertPrompt.views.TextView;
 import info.knacki.pass.ui.passwordPicker.PasswordPickerFactory;
 
 public class EncryptionInformationActivity extends AppCompatActivity {
@@ -36,14 +37,6 @@ public class EncryptionInformationActivity extends AppCompatActivity {
         fEncrypted = new File(filePath);
         setContentView(R.layout.activity_encryption_infos);
 
-        FillView();
-    }
-
-    private void FillView() {
-        setTitle(FileUtils.TrimExtension(fEncrypted.getName()));
-        IFileInterface f = FileInterfaceFactory.GetFileInterface(this, null, fEncrypted);
-        ((AppCompatTextView) findViewById(R.id.filepath)).setText(fEncrypted.getName());
-        ((AppCompatTextView) findViewById(R.id.enc_method)).setText(f.GetMethodName());
         findViewById(R.id.change_encmethod).setOnClickListener((v) -> {
             RadioGroup radioGroup = new RadioGroup(EncryptionInformationActivity.this);
             final SettingsManager.EncryptionType prevEncType = FileInterfaceFactory.GetEncryptionType(fEncrypted);
@@ -86,5 +79,24 @@ public class EncryptionInformationActivity extends AppCompatActivity {
                     .setTitle(R.string.change_encmethod)
                     .show();
         });
+        findViewById(R.id.remove).setOnClickListener((view) -> {
+            AlertPromptGenerator.StaticMake(this)
+                    .setTitle(R.string.are_you_sure)
+                    .setView(new TextView(this).SetText(String.format(getString(R.string.about_to_rm_file), fEncrypted.getName())))
+                    .setPositiveButton(R.string.ok, (dialogInterface, v) -> {
+                        fEncrypted.delete();
+                        EncryptionInformationActivity.this.finish();
+                    })
+                    .setNegativeButton(R.string.cancel, null)
+                    .show();
+        });
+        FillView();
+    }
+
+    private void FillView() {
+        setTitle(FileUtils.TrimExtension(fEncrypted.getName()));
+        IFileInterface f = FileInterfaceFactory.GetFileInterface(this, null, fEncrypted);
+        ((AppCompatTextView) findViewById(R.id.filepath)).setText(fEncrypted.getName());
+        ((AppCompatTextView) findViewById(R.id.enc_method)).setText(f.GetMethodName());
     }
 }

+ 7 - 1
app/src/main/res/layout/activity_encryption_infos.xml

@@ -2,7 +2,7 @@
 <GridLayout
     xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:rowCount="3"
+    android:rowCount="4"
     android:columnCount="2">
     <android.support.v7.widget.AppCompatTextView android:text="@string/path"
         android:paddingLeft="@dimen/fab_margin" android:paddingRight="@dimen/fab_margin"
@@ -17,4 +17,10 @@
         android:layout_row="1" android:layout_column="1" />
     <android.support.v7.widget.AppCompatButton android:id="@+id/change_encmethod" android:text="@string/change"
         android:layout_row="2" android:layout_column="1" />
+
+    <android.support.v7.widget.AppCompatTextView android:text="@string/remove"
+        android:paddingLeft="@dimen/fab_margin" android:paddingRight="@dimen/fab_margin"
+        android:layout_row="3" android:layout_column="0" />
+    <android.support.v7.widget.AppCompatButton android:id="@+id/remove" android:text="@string/remove"
+        android:layout_row="3" android:layout_column="1" />
 </GridLayout>

+ 1 - 0
app/src/main/res/values-fr/lang.xml

@@ -62,6 +62,7 @@
     <string name="ok">OK</string>
     <string name="are_you_sure">Êtes-vous sur.e ?</string>
     <string name="about_to_rm_directory">Vous allez supprimer tout les mots de passes dans le dossier</string>
+    <string name="about_to_rm_file">Vous allez supprimer "%s"</string>
     <string name="conflictingFiles">Résolution des conflits</string>
     <string name="useMine">Utiliser ma version</string>
     <string name="useTheir">Utiliser leur version</string>

+ 1 - 0
app/src/main/res/values/lang.xml

@@ -62,6 +62,7 @@
     <string name="ok">OK</string>
     <string name="are_you_sure">Are you sure ?</string>
     <string name="about_to_rm_directory">You are about to remove all password from this folder</string>
+    <string name="about_to_rm_file">You are about to remove "%s"</string>
     <string name="conflictingFiles">Solve conflicts</string>
     <string name="useMine">Use mine</string>
     <string name="useTheir">Use their</string>