mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-31 20:25:38 +00:00
Don't kill my app
This commit is contained in:
parent
4f83eb572b
commit
00aec3a7e2
4 changed files with 117 additions and 9 deletions
|
@ -28,6 +28,8 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.graphics.Paint;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
|
@ -364,35 +366,55 @@ public class FragmentOptions extends FragmentBase {
|
|||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_setup, null);
|
||||
final Context context = getContext();
|
||||
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_setup, null);
|
||||
TextView tvDozeDevice = dview.findViewById(R.id.tvDozeDevice);
|
||||
TextView tvDozeAndroid = dview.findViewById(R.id.tvDozeAndroid);
|
||||
CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain);
|
||||
Group grp2 = dview.findViewById(R.id.grp2);
|
||||
Group grp3 = dview.findViewById(R.id.grp3);
|
||||
|
||||
tvDozeDevice.setPaintFlags(tvDozeDevice.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
tvDozeDevice.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Helper.view(context, Uri.parse(Helper.DONTKILL_URI), true);
|
||||
}
|
||||
});
|
||||
|
||||
cbNotAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefs.edit().putBoolean("setup_reminder", !isChecked).apply();
|
||||
}
|
||||
});
|
||||
|
||||
boolean hasPermissions = Helper.hasPermission(getContext(), Manifest.permission.READ_CONTACTS);
|
||||
Boolean isIgnoring = Helper.isIgnoringOptimizations(getContext());
|
||||
boolean hasPermissions = Helper.hasPermission(context, Manifest.permission.READ_CONTACTS);
|
||||
Boolean isIgnoring = Helper.isIgnoringOptimizations(context);
|
||||
boolean isKilling = Helper.isKilling() && !(isIgnoring == null || isIgnoring);
|
||||
boolean isRequired = Helper.isDozeRequired() && !(isIgnoring == null || isIgnoring);
|
||||
|
||||
tvDozeDevice.setVisibility(isKilling && !isRequired ? View.VISIBLE : View.GONE);
|
||||
tvDozeAndroid.setVisibility(isRequired ? View.VISIBLE : View.GONE);
|
||||
cbNotAgain.setVisibility(isRequired ? View.GONE : View.VISIBLE);
|
||||
|
||||
grp2.setVisibility(hasPermissions ? View.GONE : View.VISIBLE);
|
||||
grp3.setVisibility(isIgnoring == null || isIgnoring ? View.GONE : View.VISIBLE);
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||
.setView(dview)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
sendResult(Activity.RESULT_OK);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.create();
|
||||
});
|
||||
|
||||
if (!isRequired)
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -164,6 +164,7 @@ public class Helper {
|
|||
static final String TEST_URI = "https://play.google.com/apps/testing/" + BuildConfig.APPLICATION_ID;
|
||||
static final String GRAVATAR_PRIVACY_URI = "https://meta.stackexchange.com/questions/44717/is-gravatar-a-privacy-risk";
|
||||
static final String LICENSE_URI = "https://www.gnu.org/licenses/gpl-3.0.html";
|
||||
static final String DONTKILL_URI = "https://dontkillmyapp.com/";
|
||||
|
||||
static final Pattern EMAIL_ADDRESS
|
||||
= Pattern.compile(
|
||||
|
@ -875,14 +876,71 @@ public class Helper {
|
|||
return "Samsung".equalsIgnoreCase(Build.MANUFACTURER);
|
||||
}
|
||||
|
||||
static boolean isOnePlus() {
|
||||
return "OnePlus".equalsIgnoreCase(Build.MANUFACTURER);
|
||||
}
|
||||
|
||||
static boolean isHuawei() {
|
||||
return "HUAWEI".equalsIgnoreCase(Build.MANUFACTURER);
|
||||
}
|
||||
|
||||
static boolean isXiaomi() {
|
||||
return "Xiaomi".equalsIgnoreCase(Build.MANUFACTURER);
|
||||
}
|
||||
|
||||
static boolean isMeizu() {
|
||||
return "Meizu".equalsIgnoreCase(Build.MANUFACTURER);
|
||||
}
|
||||
|
||||
static boolean isAsus() {
|
||||
return "asus".equalsIgnoreCase(Build.MANUFACTURER);
|
||||
}
|
||||
|
||||
static boolean isWiko() {
|
||||
return "WIKO".equalsIgnoreCase(Build.MANUFACTURER);
|
||||
}
|
||||
|
||||
static boolean isLenovo() {
|
||||
return "LENOVO".equalsIgnoreCase(Build.MANUFACTURER);
|
||||
}
|
||||
|
||||
static boolean isOppo() {
|
||||
return "OPPO".equalsIgnoreCase(Build.MANUFACTURER);
|
||||
}
|
||||
|
||||
static boolean isRealme() {
|
||||
return "realme".equalsIgnoreCase(Build.MANUFACTURER);
|
||||
}
|
||||
|
||||
static boolean isBlackview() {
|
||||
return "Blackview".equalsIgnoreCase(Build.MANUFACTURER);
|
||||
}
|
||||
|
||||
static boolean isSurfaceDuo() {
|
||||
return ("Microsoft".equalsIgnoreCase(Build.MANUFACTURER) && "Surface Duo".equals(Build.MODEL));
|
||||
}
|
||||
|
||||
static boolean isKilling() {
|
||||
// https://dontkillmyapp.com/
|
||||
return (isSamsung() ||
|
||||
isOnePlus() ||
|
||||
isHuawei() ||
|
||||
isXiaomi() ||
|
||||
isMeizu() ||
|
||||
isAsus() ||
|
||||
isWiko() ||
|
||||
isLenovo() ||
|
||||
isOppo() ||
|
||||
// Vivo
|
||||
isRealme() ||
|
||||
isBlackview() ||
|
||||
BuildConfig.DEBUG);
|
||||
}
|
||||
|
||||
static boolean isDozeRequired() {
|
||||
return (Build.VERSION.SDK_INT > Build.VERSION_CODES.R);
|
||||
}
|
||||
|
||||
static void reportNoViewer(Context context, Uri uri) {
|
||||
reportNoViewer(context, new Intent().setData(uri));
|
||||
}
|
||||
|
|
|
@ -83,6 +83,32 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/title3" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvDozeDevice"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:drawableEnd="@drawable/twotone_open_in_new_12"
|
||||
android:drawablePadding="6dp"
|
||||
android:text="@string/title_setup_doze_device"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?attr/colorWarning"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDoze" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvDozeAndroid"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="@string/title_setup_doze_android"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?attr/colorWarning"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDozeDevice" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbNotAgain"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -91,7 +117,7 @@
|
|||
android:text="@string/title_no_ask_again"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDoze" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDozeAndroid" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grp2"
|
||||
|
|
|
@ -210,6 +210,8 @@
|
|||
<string name="title_setup_doze_instructions">In the next Android dialog change "Not optimized" to "All apps", select this app and select "Don\'t optimize"</string>
|
||||
<string name="title_setup_doze_battery">High battery usage?</string>
|
||||
<string name="title_setup_doze_stopped">Sync stopped?</string>
|
||||
<string name="title_setup_doze_device">This is probably required for this device</string>
|
||||
<string name="title_setup_doze_android">This is required for this Android version</string>
|
||||
<string name="title_setup_background">Background restrictions are enabled</string>
|
||||
<string name="title_setup_data">Data saver is enabled</string>
|
||||
<string name="title_setup_advanced_options">Show advanced options</string>
|
||||
|
|
Loading…
Reference in a new issue