Skip to content

Commit 17a2444

Browse files
show on special vendors "disable power check" in auto upload menu
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent 3b24d09 commit 17a2444

File tree

6 files changed

+66
-4
lines changed

6 files changed

+66
-4
lines changed

src/main/java/com/nextcloud/client/preferences/AppPreferences.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,8 @@ public interface AppPreferences {
292292
boolean isUserIdMigrated();
293293

294294
void setMigratedUserId(boolean value);
295+
296+
boolean isPowerCheckDisabled();
297+
298+
void setPowerCheckDisabled(boolean value);
295299
}

src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public final class AppPreferencesImpl implements AppPreferences {
7171
private static final String PREF__LOCK = SettingsActivity.PREFERENCE_LOCK;
7272
private static final String PREF__SELECTED_ACCOUNT_NAME = "select_oc_account";
7373
private static final String PREF__MIGRATED_USER_ID = "migrated_user_id";
74+
private static final String PREF__POWER_CHECK_DISABLED = "power_check_disabled";
7475

7576
private final Context context;
7677
private final SharedPreferences preferences;
@@ -501,4 +502,14 @@ private static String getKeyFromFolder(String preferenceName, OCFile folder) {
501502

502503
return preferenceName + "_" + folderIdString;
503504
}
505+
506+
@Override
507+
public boolean isPowerCheckDisabled() {
508+
return preferences.getBoolean(PREF__POWER_CHECK_DISABLED, false);
509+
}
510+
511+
@Override
512+
public void setPowerCheckDisabled(boolean value) {
513+
preferences.edit().putBoolean(PREF__POWER_CHECK_DISABLED, value).apply();
514+
}
504515
}

src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
9898
SyncedFolderPreferencesDialogFragment.OnSyncedFolderPreferenceListener, Injectable {
9999

100100
private static final String[] PRIORITIZED_FOLDERS = new String[]{"Camera", "Screenshots"};
101-
private static final List<String> SPECIAL_MANUFACTURER = Arrays.asList("Samsung", "Huawei", "Xiaomi");
101+
private static final List<String> SPECIAL_MANUFACTURER = Arrays.asList("samsung", "huawei", "xiaomi");
102102
public static final String EXTRA_SHOW_SIDEBAR = "SHOW_SIDEBAR";
103103
private static final String SYNCED_FOLDER_PREFERENCES_DIALOG_TAG = "SYNCED_FOLDER_PREFERENCES_DIALOG";
104104
private static final String TAG = SyncedFoldersActivity.class.getSimpleName();
@@ -114,6 +114,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
114114
private String path;
115115
private int type;
116116
@Inject AppPreferences preferences;
117+
private boolean isSpecialManufacturer;
117118

118119
@Override
119120
protected void onCreate(Bundle savedInstanceState) {
@@ -171,15 +172,46 @@ protected void onCreate(Bundle savedInstanceState) {
171172
if (ThemeUtils.themingEnabled(this)) {
172173
setTheme(R.style.FallbackThemingTheme);
173174
}
175+
176+
isSpecialManufacturer = SPECIAL_MANUFACTURER.contains(Build.MANUFACTURER.toLowerCase(Locale.ROOT));
174177
}
175178

176179
@Override
177180
public boolean onCreateOptionsMenu(Menu menu) {
178181
MenuInflater inflater = getMenuInflater();
179182
inflater.inflate(R.menu.synced_folders_menu, menu);
183+
184+
if (isSpecialManufacturer) {
185+
MenuItem item = menu.findItem(R.id.action_disable_power_save_check);
186+
item.setVisible(true);
187+
188+
item.setChecked(preferences.isPowerCheckDisabled());
189+
190+
item.setOnMenuItemClickListener(powerCheck -> {
191+
if (!powerCheck.isChecked()) {
192+
showPowerCheckDialog();
193+
}
194+
195+
preferences.setPowerCheckDisabled(!powerCheck.isChecked());
196+
powerCheck.setChecked(!powerCheck.isChecked());
197+
198+
return true;
199+
});
200+
}
201+
180202
return true;
181203
}
182204

205+
private void showPowerCheckDialog() {
206+
AlertDialog.Builder builder = new AlertDialog.Builder(this);
207+
builder.setView(findViewById(R.id.root_layout))
208+
.setPositiveButton(R.string.common_ok, (dialog, which) -> dialog.dismiss())
209+
.setTitle(ThemeUtils.getColoredTitle(getResources().getString(R.string.power_check_dialog_title),
210+
ThemeUtils.primaryAccentColor(this)))
211+
.setMessage(getString(R.string.power_save_check_dialog_message));
212+
builder.show();
213+
}
214+
183215
/**
184216
* sets up the UI elements and loads all media/synced folders.
185217
*/
@@ -706,9 +738,6 @@ protected void onResume() {
706738
}
707739

708740
private void showBatteryOptimizationInfo() {
709-
710-
boolean isSpecialManufacturer = SPECIAL_MANUFACTURER.contains(Build.MANUFACTURER.toLowerCase(Locale.ROOT));
711-
712741
if (isSpecialManufacturer && checkIfBatteryOptimizationEnabled() || checkIfBatteryOptimizationEnabled()) {
713742
AlertDialog alertDialog = new AlertDialog.Builder(this, R.style.Theme_ownCloud_Dialog)
714743
.setTitle(getString(R.string.battery_optimization_title))

src/main/java/com/owncloud/android/utils/PowerUtils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import android.os.Build;
66
import android.os.PowerManager;
77

8+
import com.nextcloud.client.preferences.AppPreferences;
9+
import com.nextcloud.client.preferences.AppPreferencesImpl;
10+
811
public final class PowerUtils {
912

1013
private PowerUtils() {
@@ -17,6 +20,12 @@ private PowerUtils() {
1720
*/
1821
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
1922
public static boolean isPowerSaveMode(Context context) {
23+
AppPreferences preferences = AppPreferencesImpl.fromContext(context);
24+
25+
if (preferences.isPowerCheckDisabled()) {
26+
return false;
27+
}
28+
2029
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
2130
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
2231
return powerManager != null && powerManager.isPowerSaveMode();

src/main/res/menu/synced_folders_menu.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,11 @@
2525
<item
2626
android:id="@+id/action_create_custom_folder"
2727
android:title="@string/autoupload_custom_folder"/>
28+
29+
<item
30+
android:id="@+id/action_disable_power_save_check"
31+
android:title="@string/autoupload_disable_power_save_check"
32+
android:visible="false"
33+
android:checkable="true" />
2834
</group>
2935
</menu>

src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,4 +864,7 @@
864864
<string name="shared_avatar_desc">Avatar from shared user</string>
865865
<string name="shared_with_you_by">Shared with you by %1$s</string>
866866
<string name="reshare_not_allowed">Resharing is not allowed</string>
867+
<string name="autoupload_disable_power_save_check">Disable power save check</string>
868+
<string name="power_check_dialog_title">Disable power save check</string>
869+
<string name="power_save_check_dialog_message">Disabling power save check might result in uploading files when in low battery state!</string>
867870
</resources>

0 commit comments

Comments
 (0)