Skip to content

Commit

Permalink
Add option to disable toast notifications
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Pascua <sgpascua@ngcp.ph>
  • Loading branch information
sgpascua committed Sep 19, 2023
1 parent 91a53f4 commit 8cc5fd8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/src/main/java/com/sammy/sbatterytweaks/BatteryWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class BatteryWorker {
private static boolean lvlSwitch;

private static int lvlThreshold;

private static boolean enableToast;
private static int duration;
private static com.topjohnwu.superuser.Shell Shell;

Expand Down Expand Up @@ -77,6 +79,7 @@ public static void batteryWorker(Context context, Boolean isCharging) {
lvlThreshold = sharedPref.getInt(SettingsActivity.PREF_BATT_LVL_THRESHOLD, 60);
disableSync = sharedPref.getBoolean(SettingsActivity.PREF_DISABLE_SYNC, false);
autoReset = sharedPref.getBoolean(SettingsActivity.PREF_RESET_STATS, false);
enableToast = sharedPref.getBoolean(SettingsActivity.PREF_TOAST_NOTIF, false);

SharedPreferences timePref = context.getSharedPreferences("timePref", Context.MODE_PRIVATE);
startHour = timePref.getInt(TimePicker.PREF_START_HOUR, 22);
Expand Down Expand Up @@ -161,21 +164,29 @@ private static void battWorker(Context context) {
} else if (((temperature <= (thresholdTemp - tempDelta)) || (isOngoing && !shouldCoolDown))) {
if (pauseMode && BatteryService.isBypassed()) {
setBypass(false, false);
Toast.makeText(context, "Charging is resumed!", Toast.LENGTH_SHORT).show();

if (enableToast)
Toast.makeText(context, "Charging is resumed!", Toast.LENGTH_SHORT).show();
} else if (fastChargeEnabled == 0) {
enableFastCharge(context,1);
Toast.makeText(context, "Fast charging mode is re-enabled", Toast.LENGTH_SHORT).show();

if (enableToast)
Toast.makeText(context, "Fast charging mode is re-enabled", Toast.LENGTH_SHORT).show();
}
} else if (temperature >= thresholdTemp) {
if (timerEnabled && !isOngoing)
startTimer();

if (pauseMode && !BatteryService.isBypassed()) {
setBypass(true, false);
Toast.makeText(context, "Charging is paused!", Toast.LENGTH_SHORT).show();

if (enableToast)
Toast.makeText(context, "Charging is paused!", Toast.LENGTH_SHORT).show();
} else if (fastChargeEnabled == 1 && !BatteryService.isBypassed()) {
enableFastCharge(context,0);
Toast.makeText(context, "Fast charging mode is disabled", Toast.LENGTH_SHORT).show();

if (enableToast)
Toast.makeText(context, "Fast charging mode is disabled", Toast.LENGTH_SHORT).show();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class SettingsActivity extends AppCompatActivity {
public static final String
PREF_BATT_LVL_THRESHOLD = "lvlThreshold";

public static final String
PREF_TOAST_NOTIF = "enabletoast";

@Override
protected void onCreate(Bundle savedInstanceState) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@
</PreferenceCategory>

<PreferenceCategory app:title="Miscellaneous">
<SwitchPreferenceCompat
android:dependency="enableservice"
android:summary="Enable toast notifications when fast charging is enabled/disabled or when charging is paused/resumed"
app:defaultValue="false"
app:key="enabletoast"
app:singleLineTitle="false"
app:title="Toast notifications" />

<SwitchPreferenceCompat
android:dependency="enableservice"
Expand Down

0 comments on commit 8cc5fd8

Please sign in to comment.