Skip to content

Commit

Permalink
Disable after-call if not handling calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
CDrummond committed Sep 1, 2024
1 parent 2eab65e commit e58cdbc
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
Expand All @@ -39,6 +38,7 @@
import androidx.preference.SwitchPreferenceCompat;

import java.util.List;
import java.util.Objects;

import io.github.muddz.styleabletoast.StyleableToast;

Expand Down Expand Up @@ -395,6 +395,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
updateListSummary(NOTIFCATIONS_PREF_KEY);
updateListSummary(ORIENTATION_PREF_KEY);
updateListSummary(ON_CALL_PREF_KEY);
setAfterCallState();
updateListSummary(PLAYER_APP_PREF_KEY);
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
}
Expand All @@ -407,6 +408,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin

if (ON_CALL_PREF_KEY.equals(key)) {
updateListSummary(key);
setAfterCallState();
if (!PhoneStateHandler.DO_NOTHING.equals(sharedPreferences.getString(key, PhoneStateHandler.DO_NOTHING))) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
activity.checkOnCallAndNotifPermission();
Expand Down Expand Up @@ -460,6 +462,7 @@ public void resetOnCall() {
pref.setValue(PhoneStateHandler.DO_NOTHING);
}
updateListSummary(ON_CALL_PREF_KEY);
setAfterCallState();
}
}

Expand Down Expand Up @@ -500,6 +503,14 @@ public void setNotifications(String val) {
resetOnCall();
}
}

private void setAfterCallState() {
SwitchPreferenceCompat afterCall = getPreferenceManager().findPreference(AFTER_CALL_PREF_KEY);
if (afterCall!=null) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext());
afterCall.setEnabled(!PhoneStateHandler.DO_NOTHING.equals(sharedPreferences.getString(ON_CALL_PREF_KEY, PhoneStateHandler.DO_NOTHING)));
}
}
}

public void checkNotificationPermission() {
Expand Down
3 changes: 2 additions & 1 deletion lms-material/src/main/res/color/switch_thumb_color.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorText" android:state_checked="true"/>
<item android:color="@color/colorText" android:state_checked="true" android:state_enabled="true"/>
<item android:color="@color/colorTextDim" android:state_enabled="false"/>
<item android:color="@color/colorTextDim"/>
</selector>
3 changes: 2 additions & 1 deletion lms-material/src/main/res/color/switch_thumb_color_light.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorText" android:state_checked="true"/>
<item android:color="@color/colorText" android:state_checked="true" android:state_enabled="true"/>
<item android:color="@color/colorTextDimLight" android:state_enabled="false"/>
<item android:color="@color/colorTextDimLight"/>
</selector>
2 changes: 1 addition & 1 deletion lms-material/src/main/res/color/switch_track_color.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorAccent" android:state_checked="true"/>
<item android:color="@color/colorAccent" android:state_checked="true" android:state_enabled="true"/>
</selector>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorAccent" android:state_checked="true"/>
<item android:color="@color/colorAccent" android:state_checked="true" android:state_enabled="true"/>
<item android:color="@color/colorTextDim" android:state_enabled="false"/>
<item android:color="@color/colorTextDim"/>
</selector>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorAccent" android:state_checked="true"/>
<item android:color="@color/colorAccent" android:state_checked="true" android:state_enabled="true"/>
<item android:color="@color/colorTextDimLight" android:state_enabled="false"/>
<item android:color="@color/colorTextDimLight"/>
</selector>

0 comments on commit e58cdbc

Please sign in to comment.