aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/ui/EditAccountActivity.java77
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java11
-rw-r--r--src/main/res/layout/activity_edit_account.xml15
-rw-r--r--src/main/res/values/strings.xml3
4 files changed, 77 insertions, 29 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
index 8e58def2d..e82bc0c5c 100644
--- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
@@ -62,17 +62,20 @@ import de.pixart.messenger.xmpp.pep.Avatar;
public class EditAccountActivity extends XmppActivity implements OnAccountUpdate,
OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched {
- private AutoCompleteTextView mAccountJid;
+ private static final int REQUEST_DATA_SAVER = 0x37af244;
+ private AutoCompleteTextView mAccountJid;
private EditText mPassword;
private EditText mPasswordConfirm;
private CheckBox mRegisterNew;
private Button mCancelButton;
private Button mSaveButton;
- private Button mDisableBatterOptimizations;
+ private Button mDisableOsOptimizationsButton;
+ private TextView mDisableOsOptimizationsHeadline;
+ private TextView getmDisableOsOptimizationsBody;
private TableLayout mMoreTable;
private LinearLayout mStats;
- private RelativeLayout mBatteryOptimizations;
+ private RelativeLayout mOsOptimizations;
private TextView mServerInfoSm;
private TextView mServerInfoRosterVersion;
private TextView mServerInfoCarbons;
@@ -378,7 +381,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == REQUEST_BATTERY_OP) {
+ if (requestCode == REQUEST_BATTERY_OP || requestCode == REQUEST_DATA_SAVER) {
updateAccountInformation(mAccount == null);
}
}
@@ -477,21 +480,10 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mAvatar.setOnClickListener(this.mAvatarClickListener);
this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new);
this.mStats = (LinearLayout) findViewById(R.id.stats);
- this.mBatteryOptimizations = (RelativeLayout) findViewById(R.id.battery_optimization);
- this.mDisableBatterOptimizations = (Button) findViewById(R.id.batt_op_disable);
- this.mDisableBatterOptimizations.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
- Uri uri = Uri.parse("package:"+getPackageName());
- intent.setData(uri);
- try {
- startActivityForResult(intent, REQUEST_BATTERY_OP);
- } catch (ActivityNotFoundException e) {
- Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show();
- }
- }
- });
+ this.mOsOptimizations = (RelativeLayout) findViewById(R.id.os_optimization);
+ this.mDisableOsOptimizationsButton = (Button) findViewById(R.id.os_optimization_disable);
+ this.mDisableOsOptimizationsHeadline = (TextView) findViewById(R.id.os_optimization_headline);
+ this.getmDisableOsOptimizationsBody = (TextView) findViewById(R.id.os_optimization_body);
this.mSessionEst = (TextView) findViewById(R.id.session_est);
this.mServerInfoRosterVersion = (TextView) findViewById(R.id.server_info_roster_version);
this.mServerInfoCarbons = (TextView) findViewById(R.id.server_info_carbons);
@@ -811,8 +803,9 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) {
Features features = this.mAccount.getXmppConnection().getFeatures();
this.mStats.setVisibility(View.VISIBLE);
- boolean showOptimizingWarning = !xmppConnectionService.getPushManagementService().available(mAccount) && isOptimizingBattery();
- this.mBatteryOptimizations.setVisibility(showOptimizingWarning ? View.VISIBLE : View.GONE);
+ boolean showBatteryWarning = !xmppConnectionService.getPushManagementService().available(mAccount) && isOptimizingBattery();
+ boolean showDataSaverWarning = isAffectedByDataSaver();
+ showOsOptimizationWarning(showBatteryWarning,showDataSaverWarning);
this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection()
.getLastSessionEstablished()));
if (features.rosterVersioning()) {
@@ -971,7 +964,47 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
}
}
- public void showRegenerateAxolotlKeyDialog() {
+ private void showOsOptimizationWarning(boolean showBatteryWarning, boolean showDataSaverWarning) {
+ this.mOsOptimizations.setVisibility(showBatteryWarning || showDataSaverWarning ? View.VISIBLE : View.GONE);
+ if (showDataSaverWarning) {
+ this.mDisableOsOptimizationsHeadline.setText(R.string.data_saver_enabled);
+ this.getmDisableOsOptimizationsBody.setText(R.string.data_saver_enabled_explained);
+ this.mDisableOsOptimizationsButton.setText(R.string.allow);
+ this.mDisableOsOptimizationsButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent(Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS);
+ Uri uri = Uri.parse("package:" + getPackageName());
+ intent.setData(uri);
+ try {
+ startActivityForResult(intent, REQUEST_DATA_SAVER);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_data_saver, Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+ } else if (showBatteryWarning) {
+ this.mDisableOsOptimizationsButton.setText(R.string.disable);
+ this.mDisableOsOptimizationsHeadline.setText(R.string.battery_optimizations_enabled);
+ this.getmDisableOsOptimizationsBody.setText(R.string.battery_optimizations_enabled_explained);
+ this.mDisableOsOptimizationsButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
+ Uri uri = Uri.parse("package:" + getPackageName());
+ intent.setData(uri);
+ try {
+ startActivityForResult(intent, REQUEST_BATTERY_OP);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+ }
+ }
+
+
+ public void showRegenerateAxolotlKeyDialog() {
Builder builder = new Builder(this);
builder.setTitle("Regenerate Key");
builder.setIconAttribute(android.R.attr.alertDialogIcon);
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index a279e4b6d..2abfbc1e4 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -27,6 +27,7 @@ import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
+import android.net.ConnectivityManager;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
@@ -442,6 +443,16 @@ public abstract class XmppActivity extends Activity {
}
}
+ protected boolean isAffectedByDataSaver() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+ return cm.isActiveNetworkMetered()
+ && cm.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED;
+ } else {
+ return false;
+ }
+ }
+
protected boolean usingEnterKey() {
return getPreferences().getBoolean("display_enter_key", false);
}
diff --git a/src/main/res/layout/activity_edit_account.xml b/src/main/res/layout/activity_edit_account.xml
index cfa07f65a..808834d22 100644
--- a/src/main/res/layout/activity_edit_account.xml
+++ b/src/main/res/layout/activity_edit_account.xml
@@ -178,7 +178,7 @@
</RelativeLayout>
<RelativeLayout
- android:id="@+id/battery_optimization"
+ android:id="@+id/os_optimization"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin"
@@ -190,7 +190,7 @@
android:padding="@dimen/infocard_padding"
android:visibility="gone">
<TextView
- android:id="@+id/batt_op_headline"
+ android:id="@+id/os_optimization_headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/battery_optimizations_enabled"
@@ -198,25 +198,26 @@
android:textSize="?attr/TextSizeHeadline"
android:textStyle="bold"/>
<TextView
- android:id="@+id/batt_op_body"
+ android:id="@+id/os_optimization_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_below="@+id/batt_op_headline"
+ android:layout_below="@+id/os_optimization_headline"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="@string/battery_optimizations_enabled_explained"
android:textColor="@color/black87"
android:textSize="?attr/TextSizeBody"/>
<Button
- android:id="@+id/batt_op_disable"
+ android:id="@+id/os_optimization_disable"
style="?android:attr/borderlessButtonStyle"
android:layout_marginRight="-8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
- android:layout_alignParentRight="true" android:layout_below="@+id/batt_op_body"
- android:text="@string/disable" android:textColor="@color/accent"/>
+ android:layout_alignParentRight="true" android:layout_below="@+id/os_optimization_body"
+ android:text="@string/disable"
+ android:textColor="@color/accent"/>
</RelativeLayout>
<LinearLayout
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 97eca53a4..046291896 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -718,4 +718,7 @@
<string name="select_text">Select text</string>
<string name="show_error_message">Show error message</string>
<string name="error_message">Error Message</string>
+ <string name="data_saver_enabled">Data saver enabled</string>
+ <string name="data_saver_enabled_explained">Your operating system is restricting Pix-Art Messenger from accessing the Internet when in background. To receive notifications of new messages you should allow Pix-Art Messenger unrestricted access when Data saver is on.\\nPix-Art Messenger will still make an effort to save data when possible.</string>
+ <string name="device_does_not_support_data_saver">Your device does not supporting disabling Data saver for Pix-Art Messenger.</string>
</resources>