1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-30 19:56:10 +00:00

Added help button high battery usage

This commit is contained in:
M66B 2019-07-08 19:58:02 +02:00
parent f62e1bce82
commit 4d756593f5
3 changed files with 36 additions and 6 deletions

View file

@ -74,6 +74,7 @@ public class FragmentSetup extends FragmentBase {
private TextView tvDozeDone;
private Button btnDoze;
private Button btnBattery;
private Button btnData;
@ -119,6 +120,7 @@ public class FragmentSetup extends FragmentBase {
tvDozeDone = view.findViewById(R.id.tvDozeDone);
btnDoze = view.findViewById(R.id.btnDoze);
btnBattery = view.findViewById(R.id.btnBattery);
btnData = view.findViewById(R.id.btnData);
@ -126,6 +128,7 @@ public class FragmentSetup extends FragmentBase {
grpWelcome = view.findViewById(R.id.grpWelcome);
PackageManager pm = getContext().getPackageManager();
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
// Wire controls
@ -138,6 +141,7 @@ public class FragmentSetup extends FragmentBase {
}
});
btnHelp.setVisibility(Helper.getIntentSetupHelp().resolveActivity(pm) == null ? View.GONE : View.VISIBLE);
btnHelp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -145,9 +149,6 @@ public class FragmentSetup extends FragmentBase {
}
});
PackageManager pm = getContext().getPackageManager();
btnHelp.setVisibility(Helper.getIntentSetupHelp().resolveActivity(pm) == null ? View.GONE : View.VISIBLE);
btnQuick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -187,6 +188,15 @@ public class FragmentSetup extends FragmentBase {
}
});
final Intent faq = new Intent(Intent.ACTION_VIEW, Uri.parse(Helper.FAQ_URI + "#user-content-faq39"));
btnBattery.setVisibility(faq.resolveActivity(pm) == null ? View.GONE : View.VISIBLE);
btnBattery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(faq);
}
});
btnData.setOnClickListener(new View.OnClickListener() {
@Override
@TargetApi(Build.VERSION_CODES.N)
@ -330,22 +340,29 @@ public class FragmentSetup extends FragmentBase {
public void onResume() {
super.onResume();
// Doze
boolean ignoring = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
if (intent.resolveActivity(getContext().getPackageManager()) != null) {
PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
ignoring = pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID);
ignoring = (pm != null && pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID));
}
}
btnDoze.setEnabled(!ignoring);
// https://issuetracker.google.com/issues/37070074
ignoring = (ignoring || Build.VERSION.SDK_INT != Build.VERSION_CODES.M);
tvDozeDone.setText(ignoring ? R.string.title_setup_done : R.string.title_setup_to_do);
tvDozeDone.setTextColor(ignoring ? textColorPrimary : colorWarning);
tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(ignoring ? check : null, null, null, null);
// Power saving
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
boolean saving = (cm.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED);
boolean saving = (cm != null &&
cm.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED);
btnData.setVisibility(saving || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
}
}

View file

@ -411,6 +411,18 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tvDozeDone" />
<Button
android:id="@+id/btnBattery"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:text="@string/title_setup_doze_battery"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnDoze" />
<!-- data saver -->
<Button
@ -422,7 +434,7 @@
android:minWidth="0dp"
android:minHeight="0dp"
android:text="@string/title_setup_data"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnDoze" />
<!-- inbox -->

View file

@ -129,6 +129,7 @@
<string name="title_setup_doze">Setup battery optimizations</string>
<string name="title_setup_doze_remark">To continuously receive email (optional)</string>
<string name="title_setup_doze_instructions">In the next dialog, select \"All apps\" at the top, select this app and select and confirm \"Don\'t optimize\"</string>
<string name="title_setup_doze_battery">High battery usage?</string>
<string name="title_setup_data">Disable data saving</string>
<string name="title_setup_inbox">Go to messages</string>
<string name="title_setup_to_do">To do</string>