Snackbar when data saver is enabled

pull/160/head
M66B 5 years ago
parent c55cafa5d0
commit 9be0e5c788

@ -38,9 +38,11 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.media.Ringtone; import android.media.Ringtone;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.ConnectivityManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -66,6 +68,7 @@ import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
import org.json.JSONArray; import org.json.JSONArray;
@ -103,6 +106,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
private ActionBarDrawerToggle drawerToggle; private ActionBarDrawerToggle drawerToggle;
private ConstraintLayout drawerContainer; private ConstraintLayout drawerContainer;
private RecyclerView rvMenu; private RecyclerView rvMenu;
private Snackbar sbDataSaver;
private boolean hasAccount; private boolean hasAccount;
private String password; private String password;
@ -252,6 +256,20 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
adapter.set(menus); adapter.set(menus);
sbDataSaver = Snackbar.make(view, R.string.title_setup_data, Snackbar.LENGTH_INDEFINITE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
final Intent settings = new Intent(
Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS,
Uri.parse("package:" + BuildConfig.APPLICATION_ID));
if (settings.resolveActivity(getPackageManager()) != null)
sbDataSaver.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(settings);
}
});
}
getSupportFragmentManager().addOnBackStackChangedListener(this); getSupportFragmentManager().addOnBackStackChangedListener(this);
if (getSupportFragmentManager().getFragments().size() == 0) { if (getSupportFragmentManager().getFragments().size() == 0) {
@ -297,6 +315,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
IntentFilter iff = new IntentFilter(); IntentFilter iff = new IntentFilter();
iff.addAction(ACTION_QUICK_SETUP); iff.addAction(ACTION_QUICK_SETUP);
@ -305,6 +324,16 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
iff.addAction(ACTION_EDIT_ACCOUNT); iff.addAction(ACTION_EDIT_ACCOUNT);
iff.addAction(ACTION_EDIT_IDENTITY); iff.addAction(ACTION_EDIT_IDENTITY);
lbm.registerReceiver(receiver, iff); lbm.registerReceiver(receiver, iff);
// https://developer.android.com/training/basics/network-ops/data-saver.html
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
int status = cm.getRestrictBackgroundStatus();
if (status == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED)
sbDataSaver.show();
}
}
} }
@Override @Override
@ -312,6 +341,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
super.onPause(); super.onPause();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.unregisterReceiver(receiver); lbm.unregisterReceiver(receiver);
if (sbDataSaver.isShown())
sbDataSaver.dismiss();
} }
@Override @Override

@ -20,7 +20,6 @@ package eu.faircode.email;
*/ */
import android.Manifest; import android.Manifest;
import android.annotation.TargetApi;
import android.app.Dialog; import android.app.Dialog;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
@ -29,7 +28,6 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -76,8 +74,6 @@ public class FragmentSetup extends FragmentBase {
private Button btnDoze; private Button btnDoze;
private Button btnBattery; private Button btnBattery;
private Button btnData;
private Button btnInbox; private Button btnInbox;
private Group grpWelcome; private Group grpWelcome;
@ -122,8 +118,6 @@ public class FragmentSetup extends FragmentBase {
btnDoze = view.findViewById(R.id.btnDoze); btnDoze = view.findViewById(R.id.btnDoze);
btnBattery = view.findViewById(R.id.btnBattery); btnBattery = view.findViewById(R.id.btnBattery);
btnData = view.findViewById(R.id.btnData);
btnInbox = view.findViewById(R.id.btnInbox); btnInbox = view.findViewById(R.id.btnInbox);
grpWelcome = view.findViewById(R.id.grpWelcome); grpWelcome = view.findViewById(R.id.grpWelcome);
@ -200,19 +194,6 @@ public class FragmentSetup extends FragmentBase {
} }
}); });
btnData.setOnClickListener(new View.OnClickListener() {
@Override
@TargetApi(Build.VERSION_CODES.N)
public void onClick(View v) {
try {
startActivity(new Intent(Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS,
Uri.parse("package:" + BuildConfig.APPLICATION_ID)));
} catch (Throwable ex) {
Log.e(ex);
}
}
});
btnInbox.setOnClickListener(new View.OnClickListener() { btnInbox.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -237,8 +218,6 @@ public class FragmentSetup extends FragmentBase {
tvDozeDone.setCompoundDrawables(null, null, null, null); tvDozeDone.setCompoundDrawables(null, null, null, null);
btnDoze.setEnabled(false); btnDoze.setEnabled(false);
btnData.setVisibility(View.GONE);
btnInbox.setEnabled(false); btnInbox.setEnabled(false);
boolean welcome = prefs.getBoolean("welcome", true); boolean welcome = prefs.getBoolean("welcome", true);
@ -361,14 +340,6 @@ public class FragmentSetup extends FragmentBase {
tvDozeDone.setText(ignoring ? R.string.title_setup_done : R.string.title_setup_to_do); tvDozeDone.setText(ignoring ? R.string.title_setup_done : R.string.title_setup_to_do);
tvDozeDone.setTextColor(ignoring ? textColorPrimary : colorWarning); tvDozeDone.setTextColor(ignoring ? textColorPrimary : colorWarning);
tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(ignoring ? check : null, null, null, null); 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 != null &&
cm.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED);
btnData.setVisibility(saving || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
}
} }
@Override @Override

@ -450,20 +450,6 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnDoze" /> app:layout_constraintTop_toBottomOf="@id/btnDoze" />
<!-- data saver -->
<Button
android:id="@+id/btnData"
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_data"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnDoze" />
<!-- inbox --> <!-- inbox -->
<View <View

@ -140,7 +140,7 @@
<string name="title_setup_doze_remark">To continuously receive email (optional)</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_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_doze_battery">High battery usage?</string>
<string name="title_setup_data">Disable data saving</string> <string name="title_setup_data">Data saver is enabled</string>
<string name="title_setup_inbox">Go to messages</string> <string name="title_setup_inbox">Go to messages</string>
<string name="title_setup_to_do">To do</string> <string name="title_setup_to_do">To do</string>
<string name="title_setup_done">Done</string> <string name="title_setup_done">Done</string>

Loading…
Cancel
Save