mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Add permissions dialogs for scheduled messages.
This commit is contained in:
@@ -20,6 +20,7 @@ import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -2942,8 +2943,8 @@ public class ConversationParentFragment extends Fragment
|
||||
}
|
||||
|
||||
private void sendMessage(@Nullable String metricId, long scheduledDate) {
|
||||
if (scheduledDate != -1 && !SignalStore.uiHints().hasSeenScheduledMessagesInfoSheet()) {
|
||||
ScheduleMessageFtuxBottomSheetDialog.show(getChildFragmentManager());
|
||||
if (scheduledDate != -1) {
|
||||
ReenableScheduledMessagesDialogFragment.showIfNeeded(requireContext(), getChildFragmentManager());
|
||||
}
|
||||
if (inputPanel.isRecordingInLockedMode()) {
|
||||
inputPanel.releaseRecordingLock();
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.thoughtcrime.securesms.conversation
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.FixedRoundedCornerBottomSheetDialogFragment
|
||||
import org.thoughtcrime.securesms.conversation.ScheduleMessageFtuxBottomSheetDialog.Companion.show
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.util.BottomSheetUtil
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil
|
||||
|
||||
/**
|
||||
* Bottom sheet dialog to prompt user to enable schedule alarms permission for scheduling messages
|
||||
*/
|
||||
class ReenableScheduledMessagesDialogFragment : FixedRoundedCornerBottomSheetDialogFragment() {
|
||||
|
||||
override val peekHeightPercentage: Float = 1f
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.reenable_scheduled_messages_dialog_fragment, container, false)
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
val launcher: ActivityResultLauncher<Intent> = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
if (it.resultCode == Activity.RESULT_OK) {
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
|
||||
view.findViewById<View>(R.id.reenable_scheduled_messages_go_to_settings).setOnClickListener {
|
||||
launcher.launch(Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM, Uri.parse("package:" + requireContext().packageName)))
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun showIfNeeded(context: Context, fragmentManager: FragmentManager) {
|
||||
var hasPermission = true
|
||||
if (Build.VERSION.SDK_INT >= 31) {
|
||||
val alarmManager = ServiceUtil.getAlarmManager(context)
|
||||
hasPermission = alarmManager.canScheduleExactAlarms()
|
||||
}
|
||||
val fragment = if (!SignalStore.uiHints().hasSeenScheduledMessagesInfoSheet()) {
|
||||
ScheduleMessageFtuxBottomSheetDialog()
|
||||
} else if (!hasPermission) {
|
||||
ReenableScheduledMessagesDialogFragment()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
fragment?.show(fragmentManager, BottomSheetUtil.STANDARD_BOTTOM_SHEET_FRAGMENT_TAG)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
package org.thoughtcrime.securesms.conversation
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.FixedRoundedCornerBottomSheetDialogFragment
|
||||
@@ -11,6 +18,7 @@ import org.thoughtcrime.securesms.components.ViewBinderDelegate
|
||||
import org.thoughtcrime.securesms.databinding.ScheduleMessageFtuxBottomSheetBinding
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.util.BottomSheetUtil
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil
|
||||
|
||||
class ScheduleMessageFtuxBottomSheetDialog : FixedRoundedCornerBottomSheetDialogFragment() {
|
||||
override val peekHeightPercentage: Float = 0.66f
|
||||
@@ -23,6 +31,20 @@ class ScheduleMessageFtuxBottomSheetDialog : FixedRoundedCornerBottomSheetDialog
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
if (Build.VERSION.SDK_INT >= 31 && !ServiceUtil.getAlarmManager(context).canScheduleExactAlarms()) {
|
||||
binding.reenableSettings.visibility = View.VISIBLE
|
||||
binding.okay.visibility = View.GONE
|
||||
val launcher: ActivityResultLauncher<Intent> = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
if (it.resultCode == Activity.RESULT_OK) {
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
binding.enableScheduledMessagesGoToSettings.setOnClickListener {
|
||||
SignalStore.uiHints().markHasSeenScheduledMessagesInfoSheet()
|
||||
launcher.launch(Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM, Uri.parse("package:" + requireContext().packageName)))
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
binding.okay.setOnClickListener {
|
||||
SignalStore.uiHints().markHasSeenScheduledMessagesInfoSheet()
|
||||
dismiss()
|
||||
|
||||
Reference in New Issue
Block a user