mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Utilise dialog dsl in CallToggleListener
This commit is contained in:
parent
391735dc28
commit
623cfde8b1
@ -1,21 +1,33 @@
|
|||||||
package org.thoughtcrime.securesms.preferences
|
package org.thoughtcrime.securesms.preferences
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.AlertDialog
|
|
||||||
import android.content.DialogInterface
|
|
||||||
import androidx.appcompat.view.ContextThemeWrapper
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.session.libsession.utilities.TextSecurePreferences
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
import org.session.libsession.utilities.TextSecurePreferences.Companion.setBooleanPreference
|
import org.session.libsession.utilities.TextSecurePreferences.Companion.setBooleanPreference
|
||||||
import org.thoughtcrime.securesms.permissions.Permissions
|
import org.thoughtcrime.securesms.permissions.Permissions
|
||||||
|
import org.thoughtcrime.securesms.sessionDialog
|
||||||
|
|
||||||
internal class CallToggleListener(
|
internal class CallToggleListener(
|
||||||
private val context: Fragment,
|
private val context: Fragment,
|
||||||
private val setCallback: Function1<Boolean?, Void>
|
private val setCallback: Function1<Boolean?, Void>
|
||||||
) : Preference.OnPreferenceChangeListener {
|
) : Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
|
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
|
||||||
|
if (newValue == false) return true
|
||||||
|
|
||||||
|
// check if we've shown the info dialog and check for microphone permissions
|
||||||
|
context.sessionDialog {
|
||||||
|
title(R.string.dialog_voice_video_title)
|
||||||
|
text(R.string.dialog_voice_video_message)
|
||||||
|
button(R.string.dialog_link_preview_enable_button_title, R.string.AccessibilityId_enable) { requestMicrophonePermission() }
|
||||||
|
cancelButton()
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
private fun requestMicrophonePermission() {
|
private fun requestMicrophonePermission() {
|
||||||
Permissions.with(context)
|
Permissions.with(context)
|
||||||
.request(Manifest.permission.RECORD_AUDIO)
|
.request(Manifest.permission.RECORD_AUDIO)
|
||||||
@ -30,23 +42,4 @@ internal class CallToggleListener(
|
|||||||
.onAnyDenied { setCallback(false) }
|
.onAnyDenied { setCallback(false) }
|
||||||
.execute()
|
.execute()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
|
|
||||||
if (!(newValue as Boolean)) return true
|
|
||||||
|
|
||||||
// check if we've shown the info dialog and check for microphone permissions
|
|
||||||
val dialog = AlertDialog.Builder(
|
|
||||||
ContextThemeWrapper(
|
|
||||||
context.requireContext(), R.style.ThemeOverlay_Session_AlertDialog
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setTitle(R.string.dialog_voice_video_title)
|
|
||||||
.setMessage(R.string.dialog_voice_video_message)
|
|
||||||
.setPositiveButton(R.string.dialog_link_preview_enable_button_title) { d: DialogInterface?, w: Int -> requestMicrophonePermission() }
|
|
||||||
.setNegativeButton(R.string.cancel) { d: DialogInterface?, w: Int -> }
|
|
||||||
.show()
|
|
||||||
val positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE)
|
|
||||||
positiveButton.contentDescription = "Enable"
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user