Added VPN active hint

pull/216/head
M66B 1 year ago
parent ea72a9d921
commit 9e45218f46

@ -0,0 +1,62 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2024 by Marcel Bokhorst (M66B)
*/
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.style.RelativeSizeSpan;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.PreferenceManager;
public class FragmentDialogVPN extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final Context context = getContext();
SpannableStringBuilder ssb = new SpannableStringBuilderEx();
ssb.append(context.getString(R.string.title_hint_vpn));
ssb.append("\n\n");
int start = ssb.length();
ssb.append(context.getString(R.string.title_hint_dismiss));
ssb.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL), start, ssb.length(), 0);
return new AlertDialog.Builder(context)
.setIcon(R.drawable.twotone_vpn_key_24)
.setTitle(R.string.title_hint_vpn_active)
.setMessage(ssb)
.setPositiveButton(android.R.string.ok, null)
.setNegativeButton(R.string.title_dismiss, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putBoolean("vpn_reminder", false).apply();
}
})
.create();
}
}

@ -254,6 +254,7 @@ public class FragmentMessages extends FragmentBase
private TextView tvNotifications; private TextView tvNotifications;
private TextView tvBatteryOptimizations; private TextView tvBatteryOptimizations;
private TextView tvDataSaver; private TextView tvDataSaver;
private TextView tvVpnActive;
private TextView tvSupport; private TextView tvSupport;
private ImageButton ibHintSupport; private ImageButton ibHintSupport;
private ImageButton ibHintSwipe; private ImageButton ibHintSwipe;
@ -282,6 +283,7 @@ public class FragmentMessages extends FragmentBase
private Group grpNotifications; private Group grpNotifications;
private Group grpBatteryOptimizations; private Group grpBatteryOptimizations;
private Group grpDataSaver; private Group grpDataSaver;
private Group grpVpnActive;
private Group grpSupport; private Group grpSupport;
private Group grpHintSupport; private Group grpHintSupport;
private Group grpHintSwipe; private Group grpHintSwipe;
@ -601,6 +603,7 @@ public class FragmentMessages extends FragmentBase
tvNotifications = view.findViewById(R.id.tvNotifications); tvNotifications = view.findViewById(R.id.tvNotifications);
tvBatteryOptimizations = view.findViewById(R.id.tvBatteryOptimizations); tvBatteryOptimizations = view.findViewById(R.id.tvBatteryOptimizations);
tvDataSaver = view.findViewById(R.id.tvDataSaver); tvDataSaver = view.findViewById(R.id.tvDataSaver);
tvVpnActive = view.findViewById(R.id.tvVpnActive);
tvSupport = view.findViewById(R.id.tvSupport); tvSupport = view.findViewById(R.id.tvSupport);
ibHintSupport = view.findViewById(R.id.ibHintSupport); ibHintSupport = view.findViewById(R.id.ibHintSupport);
ibHintSwipe = view.findViewById(R.id.ibHintSwipe); ibHintSwipe = view.findViewById(R.id.ibHintSwipe);
@ -630,6 +633,7 @@ public class FragmentMessages extends FragmentBase
grpNotifications = view.findViewById(R.id.grpNotifications); grpNotifications = view.findViewById(R.id.grpNotifications);
grpBatteryOptimizations = view.findViewById(R.id.grpBatteryOptimizations); grpBatteryOptimizations = view.findViewById(R.id.grpBatteryOptimizations);
grpDataSaver = view.findViewById(R.id.grpDataSaver); grpDataSaver = view.findViewById(R.id.grpDataSaver);
grpVpnActive = view.findViewById(R.id.grpVpnActive);
grpSupport = view.findViewById(R.id.grpSupport); grpSupport = view.findViewById(R.id.grpSupport);
grpHintSupport = view.findViewById(R.id.grpHintSupport); grpHintSupport = view.findViewById(R.id.grpHintSupport);
grpHintSwipe = view.findViewById(R.id.grpHintSwipe); grpHintSwipe = view.findViewById(R.id.grpHintSwipe);
@ -715,6 +719,13 @@ public class FragmentMessages extends FragmentBase
} }
}); });
tvVpnActive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new FragmentDialogVPN().show(getParentFragmentManager(), "vpn");
}
});
grpSupport.setVisibility(View.GONE); grpSupport.setVisibility(View.GONE);
tvSupport.setOnClickListener(new View.OnClickListener() { tvSupport.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -2003,6 +2014,7 @@ public class FragmentMessages extends FragmentBase
grpNotifications.setVisibility(View.GONE); grpNotifications.setVisibility(View.GONE);
grpBatteryOptimizations.setVisibility(View.GONE); grpBatteryOptimizations.setVisibility(View.GONE);
grpDataSaver.setVisibility(View.GONE); grpDataSaver.setVisibility(View.GONE);
grpVpnActive.setVisibility(View.GONE);
tvNoEmail.setVisibility(View.GONE); tvNoEmail.setVisibility(View.GONE);
tvNoEmailHint.setVisibility(View.GONE); tvNoEmailHint.setVisibility(View.GONE);
etSearch.setVisibility(View.GONE); etSearch.setVisibility(View.GONE);
@ -5646,6 +5658,9 @@ public class FragmentMessages extends FragmentBase
? View.VISIBLE : View.GONE); ? View.VISIBLE : View.GONE);
} }
if (grpVpnActive != null && "vpn_reminder".equals(key))
updateVPN();
if (grpSupport != null && if (grpSupport != null &&
("pro".equals(key) || "banner_hidden".equals(key))) { ("pro".equals(key) || "banner_hidden".equals(key))) {
boolean pro = ActivityBilling.isPro(getContext()); boolean pro = ActivityBilling.isPro(getContext());
@ -5673,14 +5688,16 @@ public class FragmentMessages extends FragmentBase
} }
private void check() { private void check() {
getMainHandler().post(new Runnable() { getMainHandler().post(new RunnableEx("messages:network") {
@Override @Override
public void run() { public void delegate() {
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return; return;
if (!rvMessage.isComputingLayout()) if (!rvMessage.isComputingLayout())
adapter.checkInternet(); adapter.checkInternet();
updateAirplaneMode(ConnectionHelper.airplaneMode(getContext())); updateAirplaneMode(ConnectionHelper.airplaneMode(getContext()));
updateVPN();
} }
}); });
} }
@ -5699,6 +5716,13 @@ public class FragmentMessages extends FragmentBase
grpAirplane.setVisibility(on ? View.VISIBLE : View.GONE); grpAirplane.setVisibility(on ? View.VISIBLE : View.GONE);
} }
private void updateVPN() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean vpn_reminder = prefs.getBoolean("vpn_reminder", true);
grpVpnActive.setVisibility(vpn_reminder && ConnectionHelper.vpnActive(getContext())
? View.VISIBLE : View.GONE);
}
private boolean checkRedmiNote() { private boolean checkRedmiNote() {
if (!Helper.isRedmiNote()) if (!Helper.isRedmiNote())
return false; return false;

@ -330,7 +330,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"raw_asked", "all_read_asked", "delete_asked", "raw_asked", "all_read_asked", "delete_asked",
"cc_bcc", "inline_image_hint", "compose_reference", "send_dialog", "cc_bcc", "inline_image_hint", "compose_reference", "send_dialog",
"setup_reminder", "was_ignoring", "setup_advanced", "setup_reminder", "was_ignoring", "setup_advanced",
"notifications_reminder", "datasaver_reminder", "notifications_reminder", "datasaver_reminder", "vpn_reminder",
"signature_images_hint", "signature_images_hint",
"gmail_checked", "gmail_checked",
"eml_auto_confirm", "eml_auto_confirm",

@ -118,6 +118,32 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDataSaver" /> app:layout_constraintTop_toBottomOf="@id/tvDataSaver" />
<TextView
android:id="@+id/tvVpnActive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="?android:attr/selectableItemBackground"
android:drawableStart="@drawable/twotone_vpn_key_24"
android:drawableEnd="@drawable/twotone_settings_24"
android:drawablePadding="6dp"
android:paddingHorizontal="12dp"
android:paddingVertical="6dp"
android:text="@string/title_hint_vpn_active"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:drawableTint="?android:attr/textColorSecondary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorDataSaver" />
<View
android:id="@+id/vSeparatorVpnActive"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvVpnActive" />
<TextView <TextView
android:id="@+id/tvSupport" android:id="@+id/tvSupport"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -128,7 +154,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorDataSaver" /> app:layout_constraintTop_toBottomOf="@+id/vSeparatorVpnActive" />
<View <View
android:id="@+id/vSeparatorSupport" android:id="@+id/vSeparatorSupport"
@ -599,6 +625,12 @@
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids="tvDataSaver,vSeparatorDataSaver" /> app:constraint_referenced_ids="tvDataSaver,vSeparatorDataSaver" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpVpnActive"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvVpnActive,vSeparatorVpnActive" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/grpSupport" android:id="@+id/grpSupport"
android:layout_width="0dp" android:layout_width="0dp"

@ -2308,10 +2308,12 @@
<string name="title_hint_folder_actions">Long press a folder for options, like adding a folder to the navigation menu for quick access</string> <string name="title_hint_folder_actions">Long press a folder for options, like adding a folder to the navigation menu for quick access</string>
<string name="title_hint_folder_sync">To limit battery and network usage not all folders and not all messages will be synchronized by default</string> <string name="title_hint_folder_sync">To limit battery and network usage not all folders and not all messages will be synchronized by default</string>
<string name="title_hint_airplane">Airplane mode is on</string> <string name="title_hint_airplane">Airplane mode is on</string>
<string name="title_hint_vpn_active">VPN active</string>
<string name="title_hint_notifications">No notification permissions</string> <string name="title_hint_notifications">No notification permissions</string>
<string name="title_hint_notifications_remark">Notification permissions are required for (account) alerts too. Notifications for new messages can be turned off in the settings.</string> <string name="title_hint_notifications_remark">Notification permissions are required for (account) alerts too. Notifications for new messages can be turned off in the settings.</string>
<string name="title_hint_battery_optimizations">Battery optimizations still enabled</string> <string name="title_hint_battery_optimizations">Battery optimizations still enabled</string>
<string name="title_hint_data_saver">If the data saver is enabled, the app will not be able to sync in the background and connection errors may occur.</string> <string name="title_hint_data_saver">If the data saver is enabled, the app will not be able to sync in the background and connection errors may occur.</string>
<string name="title_hint_vpn">E-mail servers often block connections through a VPN. Only the email provider can resolve this.</string>
<string name="title_hint_dismiss">You can dismiss this dialog box to remove the notice.</string> <string name="title_hint_dismiss">You can dismiss this dialog box to remove the notice.</string>
<string name="title_hint_support">If you have a question or a problem, please use the support menu to get help</string> <string name="title_hint_support">If you have a question or a problem, please use the support menu to get help</string>
<string name="title_hint_message_actions">Swipe left to trash; Swipe right to archive (if available); The swipe actions can be configured in the account settings</string> <string name="title_hint_message_actions">Swipe left to trash; Swipe right to archive (if available); The swipe actions can be configured in the account settings</string>

Loading…
Cancel
Save