mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-23 03:30:36 -04:00
feat(settings): Add microphone permission prompt
This commit is contained in:
parent
126884cf49
commit
53b4310804
@ -166,7 +166,9 @@ public class LauncherActivity extends BaseActivity {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private ActivityResultLauncher<String> mRequestNotificationPermissionLauncher;
|
private ActivityResultLauncher<String> mRequestNotificationPermissionLauncher;
|
||||||
|
private ActivityResultLauncher<String> mRequestMicrophonePermissionLauncher;
|
||||||
private WeakReference<Runnable> mRequestNotificationPermissionRunnable;
|
private WeakReference<Runnable> mRequestNotificationPermissionRunnable;
|
||||||
|
private WeakReference<Runnable> mRequestMicrophonePermissionRunnable;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean shouldIgnoreNotch() {
|
protected boolean shouldIgnoreNotch() {
|
||||||
@ -206,6 +208,16 @@ public class LauncherActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
mRequestMicrophonePermissionLauncher = registerForActivityResult(
|
||||||
|
new ActivityResultContracts.RequestPermission(),
|
||||||
|
isAllowed -> {
|
||||||
|
if(!isAllowed) handleNoNotificationPermission();
|
||||||
|
else {
|
||||||
|
Runnable runnable = Tools.getWeakReference(mRequestMicrophonePermissionRunnable);
|
||||||
|
if(runnable != null) runnable.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
getWindow().setBackgroundDrawable(null);
|
getWindow().setBackgroundDrawable(null);
|
||||||
bindViews();
|
bindViews();
|
||||||
checkNotificationPermission();
|
checkNotificationPermission();
|
||||||
@ -343,6 +355,11 @@ public class LauncherActivity extends BaseActivity {
|
|||||||
this,
|
this,
|
||||||
Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_DENIED;
|
Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_DENIED;
|
||||||
}
|
}
|
||||||
|
public boolean checkForMicrophonePermission() {
|
||||||
|
return ContextCompat.checkSelfPermission(
|
||||||
|
this,
|
||||||
|
Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
public void askForNotificationPermission(Runnable onSuccessRunnable) {
|
public void askForNotificationPermission(Runnable onSuccessRunnable) {
|
||||||
if(Build.VERSION.SDK_INT < 33) return;
|
if(Build.VERSION.SDK_INT < 33) return;
|
||||||
@ -352,6 +369,13 @@ public class LauncherActivity extends BaseActivity {
|
|||||||
mRequestNotificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS);
|
mRequestNotificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void askForMicrophonePermission(Runnable onSuccessRunnable) {
|
||||||
|
if(onSuccessRunnable != null) {
|
||||||
|
mRequestMicrophonePermissionRunnable = new WeakReference<>(onSuccessRunnable);
|
||||||
|
}
|
||||||
|
mRequestMicrophonePermissionLauncher.launch(Manifest.permission.RECORD_AUDIO);
|
||||||
|
}
|
||||||
|
|
||||||
/** Stuff all the view boilerplate here */
|
/** Stuff all the view boilerplate here */
|
||||||
private void bindViews(){
|
private void bindViews(){
|
||||||
mFragmentView = findViewById(R.id.container_fragment);
|
mFragmentView = findViewById(R.id.container_fragment);
|
||||||
|
@ -35,6 +35,7 @@ public class LauncherPreferenceFragment extends PreferenceFragmentCompat impleme
|
|||||||
|
|
||||||
private void setupNotificationRequestPreference() {
|
private void setupNotificationRequestPreference() {
|
||||||
Preference mRequestNotificationPermissionPreference = requirePreference("notification_permission_request");
|
Preference mRequestNotificationPermissionPreference = requirePreference("notification_permission_request");
|
||||||
|
Preference mMicrophonePermissionPreference = requirePreference("microphone_permission_request");
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if(activity instanceof LauncherActivity) {
|
if(activity instanceof LauncherActivity) {
|
||||||
LauncherActivity launcherActivity = (LauncherActivity)activity;
|
LauncherActivity launcherActivity = (LauncherActivity)activity;
|
||||||
@ -43,6 +44,11 @@ public class LauncherPreferenceFragment extends PreferenceFragmentCompat impleme
|
|||||||
launcherActivity.askForNotificationPermission(()->mRequestNotificationPermissionPreference.setVisible(false));
|
launcherActivity.askForNotificationPermission(()->mRequestNotificationPermissionPreference.setVisible(false));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
mMicrophonePermissionPreference.setVisible(!launcherActivity.checkForMicrophonePermission());
|
||||||
|
mMicrophonePermissionPreference.setOnPreferenceClickListener(preference -> {
|
||||||
|
launcherActivity.askForMicrophonePermission(()->mMicrophonePermissionPreference.setVisible(false));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}else{
|
}else{
|
||||||
mRequestNotificationPermissionPreference.setVisible(false);
|
mRequestNotificationPermissionPreference.setVisible(false);
|
||||||
}
|
}
|
||||||
|
@ -472,4 +472,6 @@
|
|||||||
<string name="preference_touchcontroller_vibrate_length_title">TouchController vibrate length</string>
|
<string name="preference_touchcontroller_vibrate_length_title">TouchController vibrate length</string>
|
||||||
<string name="preference_touchcontroller_vibrate_length_description">Set the length of the vibration when using TouchController.</string>
|
<string name="preference_touchcontroller_vibrate_length_description">Set the length of the vibration when using TouchController.</string>
|
||||||
<string name="error_vanilla_json_corrupt">Vanilla json seems to be corrupt. Please send a bug report on github or discord.</string>
|
<string name="error_vanilla_json_corrupt">Vanilla json seems to be corrupt. Please send a bug report on github or discord.</string>
|
||||||
|
<string name="preference_ask_for_microphone_title">Allow microphone</string>
|
||||||
|
<string name="preference_ask_for_microphone_description">Click to re-request the notification permission, required for voice chat mods like Simple Voice Chat.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -66,6 +66,11 @@
|
|||||||
android:summary="@string/preference_ask_for_notification_description"
|
android:summary="@string/preference_ask_for_notification_description"
|
||||||
android:key="notification_permission_request"
|
android:key="notification_permission_request"
|
||||||
/>
|
/>
|
||||||
|
<Preference
|
||||||
|
android:title="@string/preference_ask_for_microphone_title"
|
||||||
|
android:summary="@string/preference_ask_for_microphone_description"
|
||||||
|
android:key="microphone_permission_request"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user