Added confirming files

pull/212/head
M66B 2 years ago
parent 30af9cebcf
commit f8676e56c4

@ -20,6 +20,7 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Typeface;
@ -30,6 +31,8 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
@ -37,6 +40,7 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.core.app.ShareCompat;
import androidx.fragment.app.Fragment;
@ -387,6 +391,51 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
}
private void onView(EntityAttachment attachment) {
String extension = Helper.getExtension(attachment.name);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean confirm = prefs.getBoolean("confirm_files", true);
boolean confirm_type = prefs.getBoolean(extension + ".confirm_files", true);
if (extension != null && confirm && confirm_type) {
View view = LayoutInflater.from(context).inflate(R.layout.dialog_view_file, null);
TextView tvFile = view.findViewById(R.id.tvFile);
TextView tvType = view.findViewById(R.id.tvType);
CheckBox cbNotAgainType = view.findViewById(R.id.cbNotAgainType);
CheckBox cbNotAgain = view.findViewById(R.id.cbNotAgain);
tvFile.setText(context.getString(R.string.title_ask_view_file, attachment.name));
tvType.setText(attachment.getMimeType());
cbNotAgainType.setText(context.getString(R.string.title_no_ask_for_again, "." + extension));
cbNotAgainType.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
prefs.edit().putBoolean(extension + ".confirm_files", false).apply();
}
});
cbNotAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
prefs.edit().putBoolean("confirm_files", false).apply();
}
});
new AlertDialog.Builder(context)
.setView(view)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
onViewConfirmed(attachment);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
} else
onViewConfirmed(attachment);
}
private void onViewConfirmed(EntityAttachment attachment) {
try {
String title = (attachment.name == null ? attachment.cid : attachment.name);
Helper.share(context, attachment.getFile(context), attachment.getMimeType(), title);

@ -2270,9 +2270,10 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
final Context context = getContext();
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_reset_questions, null);
final CheckBox cbGeneral = dview.findViewById(R.id.cbGeneral);
final CheckBox cbFull = dview.findViewById(R.id.cbFull);
final CheckBox cbImages = dview.findViewById(R.id.cbImages);
final CheckBox cbLinks = dview.findViewById(R.id.cbLinks);
final CheckBox cbFiles = dview.findViewById(R.id.cbFiles);
final CheckBox cbImages = dview.findViewById(R.id.cbImages);
final CheckBox cbFull = dview.findViewById(R.id.cbFull);
new AlertDialog.Builder(context)
.setView(dview)
@ -2294,11 +2295,12 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
key.startsWith("translated_") && cbGeneral.isChecked()) ||
key.startsWith("oauth.") ||
(key.startsWith("announcement.") && cbGeneral.isChecked()) ||
(key.endsWith(".show_full") && cbFull.isChecked()) ||
(key.endsWith(".show_images") && cbImages.isChecked()) ||
(key.endsWith(".confirm_link") && cbLinks.isChecked()) ||
(key.endsWith(".link_view") && cbLinks.isChecked()) ||
(key.endsWith(".link_sanitize") && cbLinks.isChecked())) {
(key.endsWith(".link_sanitize") && cbLinks.isChecked()) ||
(key.endsWith(".confirm_files") && cbFiles.isChecked()) ||
(key.endsWith(".show_images") && cbImages.isChecked()) ||
(key.endsWith(".show_full") && cbFull.isChecked())) {
Log.i("Removing option=" + key);
editor.remove(key);
}

@ -60,6 +60,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
private SwitchCompat swConfirmLinks;
private SwitchCompat swSanitizeLinks;
private SwitchCompat swCheckLinksDbl;
private SwitchCompat swConfirmFiles;
private SwitchCompat swConfirmImages;
private SwitchCompat swAskImages;
private SwitchCompat swHtmlImages;
@ -100,7 +101,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
private final static int BIP39_WORDS = 6;
private final static String[] RESET_OPTIONS = new String[]{
"confirm_links", "sanitize_links", "check_links_dbl",
"confirm_links", "sanitize_links", "check_links_dbl", "confirm_files",
"confirm_images", "ask_images", "html_always_images", "confirm_html", "ask_html",
"disable_tracking",
"pin", "biometrics", "biometrics_timeout", "autolock", "autolock_nav",
@ -125,6 +126,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
swConfirmLinks = view.findViewById(R.id.swConfirmLinks);
swSanitizeLinks = view.findViewById(R.id.swSanitizeLinks);
swCheckLinksDbl = view.findViewById(R.id.swCheckLinksDbl);
swConfirmFiles = view.findViewById(R.id.swConfirmFiles);
swConfirmImages = view.findViewById(R.id.swConfirmImages);
swAskImages = view.findViewById(R.id.swAskImages);
swHtmlImages = view.findViewById(R.id.swHtmlImages);
@ -204,6 +206,19 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
}
});
swConfirmFiles.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("confirm_files", checked);
if (!checked)
for (String key : prefs.getAll().keySet())
if (key.endsWith(".confirm_files"))
editor.remove(key);
editor.apply();
}
});
swConfirmImages.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -561,6 +576,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
swSanitizeLinks.setEnabled(swConfirmLinks.isChecked());
swCheckLinksDbl.setChecked(prefs.getBoolean("check_links_dbl", BuildConfig.PLAY_STORE_RELEASE));
swCheckLinksDbl.setEnabled(swConfirmLinks.isChecked());
swConfirmFiles.setChecked(prefs.getBoolean("confirm_files", true));
swConfirmImages.setChecked(prefs.getBoolean("confirm_images", true));
swAskImages.setChecked(prefs.getBoolean("ask_images", true));
swAskImages.setEnabled(swConfirmImages.isChecked());

@ -33,15 +33,25 @@
app:layout_constraintTop_toBottomOf="@id/tvAddImage" />
<CheckBox
android:id="@+id/cbFull"
android:id="@+id/cbLinks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_setup_reset_full"
android:text="@string/title_setup_reset_links"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbGeneral" />
<CheckBox
android:id="@+id/cbFiles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_setup_reset_files"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbLinks" />
<CheckBox
android:id="@+id/cbImages"
android:layout_width="wrap_content"
@ -50,14 +60,14 @@
android:text="@string/title_setup_reset_images"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbFull" />
app:layout_constraintTop_toBottomOf="@id/cbFiles" />
<CheckBox
android:id="@+id/cbLinks"
android:id="@+id/cbFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_setup_reset_links"
android:text="@string/title_setup_reset_full"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbImages" />

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<eu.faircode.email.ScrollViewEx xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="24dp"
android:scrollbarStyle="outsideOverlay">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_ask_view_file"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvType"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="@string/title_ask_show_html_remark"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvFile" />
<CheckBox
android:id="@+id/cbNotAgainType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_no_ask_for_again"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvType" />
<CheckBox
android:id="@+id/cbNotAgain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_no_ask_again"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbNotAgainType" />
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>

@ -138,6 +138,18 @@
app:layout_constraintTop_toBottomOf="@id/tvSanitizeLinksHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swConfirmFiles"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_confirm_files"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swCheckLinksDbl"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swConfirmImages"
android:layout_width="0dp"
@ -147,7 +159,7 @@
android:text="@string/title_advanced_confirm_images"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/swCheckLinksDbl"
app:layout_constraintTop_toBottomOf="@+id/swConfirmFiles"
app:switchPadding="12dp" />
<TextView

@ -365,9 +365,10 @@
<string name="title_setup_reset_questions">Reset questions</string>
<string name="title_setup_reset_general">General questions</string>
<string name="title_setup_reset_full">Show original messages</string>
<string name="title_setup_reset_images">Show images</string>
<string name="title_setup_reset_links">Confirm links</string>
<string name="title_setup_reset_files">View files</string>
<string name="title_setup_reset_images">Show images</string>
<string name="title_setup_reset_full">Show original messages</string>
<string name="title_check_gmail_oauth">Your Gmail accounts will continue to work after May 30, 2022</string>
<string name="title_check_gmail_password">Some of your Gmail accounts may stop working after May 30, 2022</string>
@ -728,6 +729,7 @@
<string name="title_advanced_caption_smime" translatable="false">S/MIME</string>
<string name="title_advanced_confirm_links">Confirm opening links</string>
<string name="title_advanced_confirm_files">Confirm viewing files</string>
<string name="title_advanced_sanitize_links">Remove tracking parameters by default</string>
<string name="title_advanced_sanitize_links_hint">Only when confirming links</string>
<string name="title_advanced_check_links_dbl">Check domain block lists for suspicious links</string>
@ -1499,6 +1501,7 @@
<string name="title_ask_show_image_hint">Images recognized as tracking images will not be shown</string>
<string name="title_ask_show_amp">Show AMP variant of the message?</string>
<string name="title_ask_show_amp_hint">AMP messages are designed to be dynamic and to interact with the internet and can therefore by definition used to track you</string>
<string name="title_ask_view_file">View file %1$s ?</string>
<string name="title_ask_delete_local">Delete local messages? Messages will remain on the remote server.</string>
<string name="title_ask_help">Help improve FairEmail</string>
<string name="title_ask_reporting">Send error reports?</string>

Loading…
Cancel
Save