mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-06 01:55:40 +00:00
Make kotlin code use dialog dsl
This commit is contained in:
parent
4ee68cbbb1
commit
1d8d678047
@ -417,7 +417,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|||||||
MediaItem mediaItem = getCurrentMediaItem();
|
MediaItem mediaItem = getCurrentMediaItem();
|
||||||
if (mediaItem == null) return;
|
if (mediaItem == null) return;
|
||||||
|
|
||||||
SaveAttachmentTask.showWarningDialog(this, () -> {
|
SaveAttachmentTask.showWarningDialog(this, 1, () -> {
|
||||||
Permissions.with(this)
|
Permissions.with(this)
|
||||||
.request(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
.request(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
.maxSdkVersion(Build.VERSION_CODES.P)
|
.maxSdkVersion(Build.VERSION_CODES.P)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.thoughtcrime.securesms
|
package org.thoughtcrime.securesms
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
@ -18,7 +19,6 @@ import androidx.core.view.setPadding
|
|||||||
import androidx.core.view.updateMargins
|
import androidx.core.view.updateMargins
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.thoughtcrime.securesms.util.toPx
|
import org.thoughtcrime.securesms.util.toPx
|
||||||
import java.lang.ref.Reference
|
|
||||||
|
|
||||||
|
|
||||||
@DslMarker
|
@DslMarker
|
||||||
@ -35,9 +35,15 @@ class SessionDialogBuilder(val context: Context) {
|
|||||||
|
|
||||||
private val topView = LinearLayout(context).apply { orientation = VERTICAL }
|
private val topView = LinearLayout(context).apply { orientation = VERTICAL }
|
||||||
.also(dialogBuilder::setCustomTitle)
|
.also(dialogBuilder::setCustomTitle)
|
||||||
|
private val contentView = LinearLayout(context).apply { orientation = VERTICAL }
|
||||||
|
private val buttonLayout = LinearLayout(context)
|
||||||
|
|
||||||
private val root = LinearLayout(context).apply { orientation = VERTICAL }
|
private val root = LinearLayout(context).apply { orientation = VERTICAL }
|
||||||
.also(dialogBuilder::setView)
|
.also(dialogBuilder::setView)
|
||||||
|
.apply {
|
||||||
|
addView(contentView)
|
||||||
|
addView(buttonLayout)
|
||||||
|
}
|
||||||
|
|
||||||
fun title(@StringRes id: Int) = title(context.getString(id))
|
fun title(@StringRes id: Int) = title(context.getString(id))
|
||||||
|
|
||||||
@ -65,52 +71,31 @@ class SessionDialogBuilder(val context: Context) {
|
|||||||
}.let(topView::addView)
|
}.let(topView::addView)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun view(view: View) {
|
fun view(view: View) = contentView.addView(view)
|
||||||
dialogBuilder.setView(view)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun view(@LayoutRes layout: Int) {
|
fun view(@LayoutRes layout: Int) = contentView.addView(LayoutInflater.from(context).inflate(layout, contentView))
|
||||||
dialogBuilder.setView(layout)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setIconAttribute(@AttrRes icon: Int) {
|
fun iconAttribute(@AttrRes icon: Int): AlertDialog.Builder = dialogBuilder.setIconAttribute(icon)
|
||||||
dialogBuilder.setIconAttribute(icon)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun singleChoiceItems(
|
fun singleChoiceItems(
|
||||||
options: Array<String>,
|
options: Array<String>,
|
||||||
currentSelected: Int,
|
currentSelected: Int,
|
||||||
onSelect: (Int) -> Unit
|
onSelect: (Int) -> Unit
|
||||||
) {
|
): AlertDialog.Builder = dialogBuilder.setSingleChoiceItems(
|
||||||
dialogBuilder.setSingleChoiceItems(
|
options,
|
||||||
options,
|
currentSelected
|
||||||
currentSelected
|
) { dialog, it -> onSelect(it); dialog.dismiss() }
|
||||||
) { dialog, it -> onSelect(it); dialog.dismiss() }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun buttons(build: (@DialogDsl ButtonsBuilder).() -> Unit) {
|
|
||||||
ButtonsBuilder(context, ::dismiss).build(build).let(root::addView)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun show(): AlertDialog = dialogBuilder.show()
|
|
||||||
}
|
|
||||||
|
|
||||||
@DialogDsl
|
|
||||||
class ButtonsBuilder(val context: Context, val dismiss: () -> Unit) {
|
|
||||||
val root = LinearLayout(context)
|
|
||||||
|
|
||||||
fun destructiveButton(
|
fun destructiveButton(
|
||||||
@StringRes text: Int,
|
@StringRes text: Int,
|
||||||
@StringRes contentDescription: Int,
|
@StringRes contentDescription: Int,
|
||||||
listener: () -> Unit = {}
|
listener: () -> Unit = {}
|
||||||
) {
|
) = button(
|
||||||
button(
|
text,
|
||||||
text,
|
contentDescription,
|
||||||
contentDescription,
|
R.style.Widget_Session_Button_Dialog_DestructiveText,
|
||||||
R.style.Widget_Session_Button_Dialog_DestructiveText,
|
listener
|
||||||
listener
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun cancelButton(listener: (() -> Unit) = {}) = button(android.R.string.cancel, R.string.AccessibilityId_cancel_button, listener = listener)
|
fun cancelButton(listener: (() -> Unit) = {}) = button(android.R.string.cancel, R.string.AccessibilityId_cancel_button, listener = listener)
|
||||||
|
|
||||||
@ -119,25 +104,18 @@ class ButtonsBuilder(val context: Context, val dismiss: () -> Unit) {
|
|||||||
@StringRes contentDescriptionRes: Int = 0,
|
@StringRes contentDescriptionRes: Int = 0,
|
||||||
@StyleRes style: Int = R.style.Widget_Session_Button_Dialog_UnimportantText,
|
@StyleRes style: Int = R.style.Widget_Session_Button_Dialog_UnimportantText,
|
||||||
listener: (() -> Unit) = {}
|
listener: (() -> Unit) = {}
|
||||||
) {
|
) = Button(context, null, 0, style).apply {
|
||||||
Button(context, null, 0, style)
|
setText(text)
|
||||||
.apply {
|
contentDescription = resources.getString(contentDescriptionRes)
|
||||||
setText(text)
|
layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1f)
|
||||||
contentDescription = resources.getString(contentDescriptionRes)
|
.apply { setMargins(toPx(20, resources)) }
|
||||||
layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1f)
|
setOnClickListener {
|
||||||
.apply { setMargins(toPx(20, resources)) }
|
listener.invoke()
|
||||||
setOnClickListener {
|
dismiss()
|
||||||
listener.invoke()
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.let(root::addView)
|
}.let(buttonLayout::addView)
|
||||||
}
|
|
||||||
|
|
||||||
internal fun build(build: ButtonsBuilder.() -> Unit): LinearLayout {
|
fun show(): AlertDialog = dialogBuilder.show()
|
||||||
build()
|
|
||||||
return root
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.sessionDialog(build: SessionDialogBuilder.() -> Unit): AlertDialog =
|
fun Context.sessionDialog(build: SessionDialogBuilder.() -> Unit): AlertDialog =
|
||||||
|
@ -965,16 +965,14 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(R.string.RecipientPreferenceActivity_block_this_contact_question)
|
title(R.string.RecipientPreferenceActivity_block_this_contact_question)
|
||||||
text(R.string.RecipientPreferenceActivity_you_will_no_longer_receive_messages_and_calls_from_this_contact)
|
text(R.string.RecipientPreferenceActivity_you_will_no_longer_receive_messages_and_calls_from_this_contact)
|
||||||
buttons {
|
destructiveButton(R.string.RecipientPreferenceActivity_block, R.string.AccessibilityId_block_confirm) {
|
||||||
destructiveButton(R.string.RecipientPreferenceActivity_block, R.string.AccessibilityId_block_confirm) {
|
viewModel.block()
|
||||||
viewModel.block()
|
if (deleteThread) {
|
||||||
if (deleteThread) {
|
viewModel.deleteThread()
|
||||||
viewModel.deleteThread()
|
finish()
|
||||||
finish()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cancelButton()
|
|
||||||
}
|
}
|
||||||
|
cancelButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1018,13 +1016,11 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(R.string.ConversationActivity_unblock_this_contact_question)
|
title(R.string.ConversationActivity_unblock_this_contact_question)
|
||||||
text(R.string.ConversationActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact)
|
text(R.string.ConversationActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact)
|
||||||
buttons {
|
destructiveButton(
|
||||||
destructiveButton(
|
R.string.ConversationActivity_unblock,
|
||||||
R.string.ConversationActivity_unblock,
|
R.string.AccessibilityId_block_confirm
|
||||||
R.string.AccessibilityId_block_confirm
|
) { viewModel.unblock() }
|
||||||
) { viewModel.unblock() }
|
cancelButton()
|
||||||
cancelButton()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1464,13 +1460,11 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(R.string.giphy_permission_title)
|
title(R.string.giphy_permission_title)
|
||||||
text(R.string.giphy_permission_message)
|
text(R.string.giphy_permission_message)
|
||||||
buttons {
|
button(R.string.continue_2) {
|
||||||
button(R.string.continue_2) {
|
textSecurePreferences.setHasSeenGIFMetaDataWarning()
|
||||||
textSecurePreferences.setHasSeenGIFMetaDataWarning()
|
selectGif()
|
||||||
selectGif()
|
|
||||||
}
|
|
||||||
cancelButton()
|
|
||||||
}
|
}
|
||||||
|
cancelButton()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
selectGif()
|
selectGif()
|
||||||
@ -1629,10 +1623,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(resources.getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messageCount, messageCount))
|
title(resources.getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messageCount, messageCount))
|
||||||
text(resources.getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messageCount, messageCount))
|
text(resources.getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messageCount, messageCount))
|
||||||
buttons {
|
button(R.string.delete) { messages.forEach(viewModel::deleteForEveryone); endActionMode() }
|
||||||
button(R.string.delete) { messages.forEach(viewModel::deleteForEveryone); endActionMode() }
|
cancelButton { endActionMode() }
|
||||||
cancelButton { endActionMode() }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (allSentByCurrentUser && allHasHash) {
|
} else if (allSentByCurrentUser && allHasHash) {
|
||||||
val bottomSheet = DeleteOptionsBottomSheet()
|
val bottomSheet = DeleteOptionsBottomSheet()
|
||||||
@ -1658,10 +1650,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(resources.getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messageCount, messageCount))
|
title(resources.getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messageCount, messageCount))
|
||||||
text(resources.getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messageCount, messageCount))
|
text(resources.getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messageCount, messageCount))
|
||||||
buttons {
|
button(R.string.delete) { messages.forEach(viewModel::deleteLocally); endActionMode() }
|
||||||
button(R.string.delete) { messages.forEach(viewModel::deleteLocally); endActionMode() }
|
cancelButton(::endActionMode)
|
||||||
cancelButton(::endActionMode)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1670,10 +1660,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(R.string.ConversationFragment_ban_selected_user)
|
title(R.string.ConversationFragment_ban_selected_user)
|
||||||
text("This will ban the selected user from this room. It won't ban them from other rooms.")
|
text("This will ban the selected user from this room. It won't ban them from other rooms.")
|
||||||
buttons {
|
button(R.string.ban) { viewModel.banUser(messages.first().individualRecipient); endActionMode() }
|
||||||
button(R.string.ban) { viewModel.banUser(messages.first().individualRecipient); endActionMode() }
|
cancelButton(::endActionMode)
|
||||||
cancelButton(::endActionMode)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1681,10 +1669,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(R.string.ConversationFragment_ban_selected_user)
|
title(R.string.ConversationFragment_ban_selected_user)
|
||||||
text("This will ban the selected user from this room and delete all messages sent by them. It won't ban them from other rooms or delete the messages they sent there.")
|
text("This will ban the selected user from this room and delete all messages sent by them. It won't ban them from other rooms or delete the messages they sent there.")
|
||||||
buttons {
|
button(R.string.ban) { viewModel.banAndDeleteAll(messages.first().individualRecipient); endActionMode() }
|
||||||
button(R.string.ban) { viewModel.banAndDeleteAll(messages.first().individualRecipient); endActionMode() }
|
cancelButton(::endActionMode)
|
||||||
cancelButton(::endActionMode)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,13 +150,11 @@ class ConversationAdapter(
|
|||||||
context.sessionDialog {
|
context.sessionDialog {
|
||||||
title(R.string.CallNotificationBuilder_first_call_title)
|
title(R.string.CallNotificationBuilder_first_call_title)
|
||||||
text(R.string.CallNotificationBuilder_first_call_message)
|
text(R.string.CallNotificationBuilder_first_call_message)
|
||||||
buttons {
|
button(R.string.activity_settings_title) {
|
||||||
button(R.string.activity_settings_title) {
|
Intent(context, PrivacySettingsActivity::class.java)
|
||||||
Intent(context, PrivacySettingsActivity::class.java)
|
.let(context::startActivity)
|
||||||
.let(context::startActivity)
|
|
||||||
}
|
|
||||||
cancelButton()
|
|
||||||
}
|
}
|
||||||
|
cancelButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -190,12 +190,10 @@ object ConversationMenuHelper {
|
|||||||
context.sessionDialog {
|
context.sessionDialog {
|
||||||
title(R.string.ConversationActivity_call_title)
|
title(R.string.ConversationActivity_call_title)
|
||||||
text(R.string.ConversationActivity_call_prompt)
|
text(R.string.ConversationActivity_call_prompt)
|
||||||
buttons {
|
button(R.string.activity_settings_title, R.string.AccessibilityId_settings) {
|
||||||
button(R.string.activity_settings_title, R.string.AccessibilityId_settings) {
|
Intent(context, PrivacySettingsActivity::class.java).let(context::startActivity)
|
||||||
Intent(context, PrivacySettingsActivity::class.java).let(context::startActivity)
|
|
||||||
}
|
|
||||||
cancelButton()
|
|
||||||
}
|
}
|
||||||
|
cancelButton()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -308,20 +306,18 @@ object ConversationMenuHelper {
|
|||||||
context.sessionDialog {
|
context.sessionDialog {
|
||||||
title(R.string.ConversationActivity_leave_group)
|
title(R.string.ConversationActivity_leave_group)
|
||||||
text(message)
|
text(message)
|
||||||
buttons {
|
button(R.string.yes) {
|
||||||
button(R.string.yes) {
|
try {
|
||||||
try {
|
val groupPublicKey = doubleDecodeGroupID(thread.address.toString()).toHexString()
|
||||||
val groupPublicKey = doubleDecodeGroupID(thread.address.toString()).toHexString()
|
val isClosedGroup = DatabaseComponent.get(context).lokiAPIDatabase().isClosedGroup(groupPublicKey)
|
||||||
val isClosedGroup = DatabaseComponent.get(context).lokiAPIDatabase().isClosedGroup(groupPublicKey)
|
|
||||||
|
|
||||||
if (isClosedGroup) MessageSender.leave(groupPublicKey, true)
|
if (isClosedGroup) MessageSender.leave(groupPublicKey, true)
|
||||||
else onLeaveFailed()
|
else onLeaveFailed()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
onLeaveFailed()
|
onLeaveFailed()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
button(R.string.no)
|
|
||||||
}
|
}
|
||||||
|
button(R.string.no)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,17 +492,15 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(R.string.RecipientPreferenceActivity_block_this_contact_question)
|
title(R.string.RecipientPreferenceActivity_block_this_contact_question)
|
||||||
text(R.string.RecipientPreferenceActivity_you_will_no_longer_receive_messages_and_calls_from_this_contact)
|
text(R.string.RecipientPreferenceActivity_you_will_no_longer_receive_messages_and_calls_from_this_contact)
|
||||||
buttons {
|
button(R.string.RecipientPreferenceActivity_block) {
|
||||||
button(R.string.RecipientPreferenceActivity_block) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
recipientDatabase.setBlocked(thread.recipient, true)
|
||||||
recipientDatabase.setBlocked(thread.recipient, true)
|
withContext(Dispatchers.Main) {
|
||||||
withContext(Dispatchers.Main) {
|
binding.recyclerView.adapter?.notifyDataSetChanged()
|
||||||
binding.recyclerView.adapter?.notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cancelButton()
|
|
||||||
}
|
}
|
||||||
|
cancelButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -510,17 +508,15 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(R.string.RecipientPreferenceActivity_unblock_this_contact_question)
|
title(R.string.RecipientPreferenceActivity_unblock_this_contact_question)
|
||||||
text(R.string.RecipientPreferenceActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact)
|
text(R.string.RecipientPreferenceActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact)
|
||||||
buttons {
|
button(R.string.RecipientPreferenceActivity_unblock) {
|
||||||
button(R.string.RecipientPreferenceActivity_unblock) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
recipientDatabase.setBlocked(thread.recipient, false)
|
||||||
recipientDatabase.setBlocked(thread.recipient, false)
|
withContext(Dispatchers.Main) {
|
||||||
withContext(Dispatchers.Main) {
|
binding.recyclerView.adapter?.notifyDataSetChanged()
|
||||||
binding.recyclerView.adapter?.notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cancelButton()
|
|
||||||
}
|
}
|
||||||
|
cancelButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -582,60 +578,58 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
|
|
||||||
sessionDialog {
|
sessionDialog {
|
||||||
text(message)
|
text(message)
|
||||||
buttons {
|
button(R.string.yes) {
|
||||||
button(R.string.yes) {
|
lifecycleScope.launch(Dispatchers.Main) {
|
||||||
lifecycleScope.launch(Dispatchers.Main) {
|
val context = this@HomeActivity as Context
|
||||||
val context = this@HomeActivity as Context
|
// Cancel any outstanding jobs
|
||||||
// Cancel any outstanding jobs
|
DatabaseComponent.get(context).sessionJobDatabase()
|
||||||
DatabaseComponent.get(context).sessionJobDatabase()
|
.cancelPendingMessageSendJobs(threadID)
|
||||||
.cancelPendingMessageSendJobs(threadID)
|
// Send a leave group message if this is an active closed group
|
||||||
// Send a leave group message if this is an active closed group
|
if (recipient.address.isClosedGroup && DatabaseComponent.get(context)
|
||||||
if (recipient.address.isClosedGroup && DatabaseComponent.get(context)
|
.groupDatabase().isActive(recipient.address.toGroupString())
|
||||||
.groupDatabase().isActive(recipient.address.toGroupString())
|
) {
|
||||||
) {
|
var isClosedGroup: Boolean
|
||||||
var isClosedGroup: Boolean
|
var groupPublicKey: String?
|
||||||
var groupPublicKey: String?
|
try {
|
||||||
try {
|
groupPublicKey =
|
||||||
groupPublicKey =
|
GroupUtil.doubleDecodeGroupID(recipient.address.toString())
|
||||||
GroupUtil.doubleDecodeGroupID(recipient.address.toString())
|
.toHexString()
|
||||||
.toHexString()
|
isClosedGroup = DatabaseComponent.get(context).lokiAPIDatabase()
|
||||||
isClosedGroup = DatabaseComponent.get(context).lokiAPIDatabase()
|
.isClosedGroup(groupPublicKey)
|
||||||
.isClosedGroup(groupPublicKey)
|
} catch (e: IOException) {
|
||||||
} catch (e: IOException) {
|
groupPublicKey = null
|
||||||
groupPublicKey = null
|
isClosedGroup = false
|
||||||
isClosedGroup = false
|
|
||||||
}
|
|
||||||
if (isClosedGroup) {
|
|
||||||
MessageSender.explicitLeave(groupPublicKey!!, false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Delete the conversation
|
if (isClosedGroup) {
|
||||||
val v2OpenGroup =
|
MessageSender.explicitLeave(groupPublicKey!!, false)
|
||||||
DatabaseComponent.get(this@HomeActivity).lokiThreadDatabase()
|
|
||||||
.getOpenGroupChat(threadID)
|
|
||||||
if (v2OpenGroup != null) {
|
|
||||||
OpenGroupManager.delete(
|
|
||||||
v2OpenGroup.server,
|
|
||||||
v2OpenGroup.room,
|
|
||||||
this@HomeActivity
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
|
||||||
threadDb.deleteConversation(threadID)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Update the badge count
|
|
||||||
ApplicationContext.getInstance(context).messageNotifier.updateNotification(
|
|
||||||
context
|
|
||||||
)
|
|
||||||
// Notify the user
|
|
||||||
val toastMessage =
|
|
||||||
if (recipient.isGroupRecipient) R.string.MessageRecord_left_group else R.string.activity_home_conversation_deleted_message
|
|
||||||
Toast.makeText(context, toastMessage, Toast.LENGTH_LONG).show()
|
|
||||||
}
|
}
|
||||||
|
// Delete the conversation
|
||||||
|
val v2OpenGroup =
|
||||||
|
DatabaseComponent.get(this@HomeActivity).lokiThreadDatabase()
|
||||||
|
.getOpenGroupChat(threadID)
|
||||||
|
if (v2OpenGroup != null) {
|
||||||
|
OpenGroupManager.delete(
|
||||||
|
v2OpenGroup.server,
|
||||||
|
v2OpenGroup.room,
|
||||||
|
this@HomeActivity
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
threadDb.deleteConversation(threadID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Update the badge count
|
||||||
|
ApplicationContext.getInstance(context).messageNotifier.updateNotification(
|
||||||
|
context
|
||||||
|
)
|
||||||
|
// Notify the user
|
||||||
|
val toastMessage =
|
||||||
|
if (recipient.isGroupRecipient) R.string.MessageRecord_left_group else R.string.activity_home_conversation_deleted_message
|
||||||
|
Toast.makeText(context, toastMessage, Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
button(R.string.no)
|
|
||||||
}
|
}
|
||||||
|
button(R.string.no)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,14 +645,12 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
private fun hideMessageRequests() {
|
private fun hideMessageRequests() {
|
||||||
sessionDialog {
|
sessionDialog {
|
||||||
text("Hide message requests?")
|
text("Hide message requests?")
|
||||||
buttons {
|
button(R.string.yes) {
|
||||||
button(R.string.yes) {
|
textSecurePreferences.setHasHiddenMessageRequests()
|
||||||
textSecurePreferences.setHasHiddenMessageRequests()
|
setupMessageRequestsBanner()
|
||||||
setupMessageRequestsBanner()
|
homeViewModel.tryUpdateChannel()
|
||||||
homeViewModel.tryUpdateChannel()
|
|
||||||
}
|
|
||||||
button(R.string.no)
|
|
||||||
}
|
}
|
||||||
|
button(R.string.no)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,10 +86,8 @@ class MessageRequestsActivity : PassphraseRequiredActionBarActivity(), Conversat
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(R.string.RecipientPreferenceActivity_block_this_contact_question)
|
title(R.string.RecipientPreferenceActivity_block_this_contact_question)
|
||||||
text(R.string.message_requests_block_message)
|
text(R.string.message_requests_block_message)
|
||||||
buttons {
|
button(R.string.recipient_preferences__block) { doBlock() }
|
||||||
button(R.string.recipient_preferences__block) { doBlock() }
|
button(R.string.no)
|
||||||
button(R.string.no)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,10 +103,8 @@ class MessageRequestsActivity : PassphraseRequiredActionBarActivity(), Conversat
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(R.string.decline)
|
title(R.string.decline)
|
||||||
text(resources.getString(R.string.message_requests_decline_message))
|
text(resources.getString(R.string.message_requests_decline_message))
|
||||||
buttons {
|
button(R.string.decline) { doDecline() }
|
||||||
button(R.string.decline) { doDecline() }
|
button(R.string.no)
|
||||||
button(R.string.no)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,10 +125,8 @@ class MessageRequestsActivity : PassphraseRequiredActionBarActivity(), Conversat
|
|||||||
|
|
||||||
sessionDialog {
|
sessionDialog {
|
||||||
text(resources.getString(R.string.message_requests_clear_all_message))
|
text(resources.getString(R.string.message_requests_clear_all_message))
|
||||||
buttons {
|
button(R.string.yes) { doDeleteAllAndBlock() }
|
||||||
button(R.string.yes) { doDeleteAllAndBlock() }
|
button(R.string.no)
|
||||||
button(R.string.no)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,9 +154,7 @@ class PNModeActivity : BaseActionBarActivity() {
|
|||||||
if (selectedOptionView == null) {
|
if (selectedOptionView == null) {
|
||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(R.string.activity_pn_mode_no_option_picked_dialog_title)
|
title(R.string.activity_pn_mode_no_option_picked_dialog_title)
|
||||||
buttons {
|
button(R.string.ok)
|
||||||
button(R.string.ok)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,8 @@ class BlockedContactsActivity: PassphraseRequiredActionBarActivity(), View.OnCli
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(title)
|
title(title)
|
||||||
text(message)
|
text(message)
|
||||||
buttons {
|
button(R.string.continue_2) { viewModel.unblock(contactsToUnblock) }
|
||||||
button(R.string.continue_2) { viewModel.unblock(contactsToUnblock) }
|
cancelButton()
|
||||||
cancelButton()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,13 +264,11 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
sessionDialog {
|
sessionDialog {
|
||||||
title(R.string.activity_settings_set_display_picture)
|
title(R.string.activity_settings_set_display_picture)
|
||||||
view(R.layout.dialog_change_avatar)
|
view(R.layout.dialog_change_avatar)
|
||||||
buttons {
|
button(R.string.activity_settings_upload) { startAvatarSelection() }
|
||||||
button(R.string.activity_settings_upload) { startAvatarSelection() }
|
if (TextSecurePreferences.getProfileAvatarId(context) != 0) {
|
||||||
if (TextSecurePreferences.getProfileAvatarId(context) != 0) {
|
button(R.string.activity_settings_remove) { removeAvatar() }
|
||||||
button(R.string.activity_settings_remove) { removeAvatar() }
|
|
||||||
}
|
|
||||||
cancelButton()
|
|
||||||
}
|
}
|
||||||
|
cancelButton()
|
||||||
}.apply {
|
}.apply {
|
||||||
findViewById<ProfilePictureView>(R.id.profile_picture_view)?.let(::setupProfilePictureView)
|
findViewById<ProfilePictureView>(R.id.profile_picture_view)?.let(::setupProfilePictureView)
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package org.thoughtcrime.securesms.util
|
|||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface.OnClickListener
|
|
||||||
import android.media.MediaScannerConnection
|
import android.media.MediaScannerConnection
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@ -12,7 +11,6 @@ import android.provider.MediaStore
|
|||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.webkit.MimeTypeMap
|
import android.webkit.MimeTypeMap
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.session.libsession.utilities.task.ProgressDialogAsyncTask
|
import org.session.libsession.utilities.task.ProgressDialogAsyncTask
|
||||||
import org.session.libsignal.utilities.ExternalStorageUtil
|
import org.session.libsignal.utilities.ExternalStorageUtil
|
||||||
@ -31,7 +29,12 @@ import java.util.concurrent.TimeUnit
|
|||||||
* Saves attachment files to an external storage using [MediaStore] API.
|
* Saves attachment files to an external storage using [MediaStore] API.
|
||||||
* Requires [android.Manifest.permission.WRITE_EXTERNAL_STORAGE] on API 28 and below.
|
* Requires [android.Manifest.permission.WRITE_EXTERNAL_STORAGE] on API 28 and below.
|
||||||
*/
|
*/
|
||||||
class SaveAttachmentTask : ProgressDialogAsyncTask<SaveAttachmentTask.Attachment, Void, Pair<Int, String?>> {
|
class SaveAttachmentTask @JvmOverloads constructor(context: Context, count: Int = 1) :
|
||||||
|
ProgressDialogAsyncTask<SaveAttachmentTask.Attachment, Void, Pair<Int, String?>>(
|
||||||
|
context,
|
||||||
|
context.resources.getQuantityString(R.plurals.ConversationFragment_saving_n_attachments, count, count),
|
||||||
|
context.resources.getQuantityString(R.plurals.ConversationFragment_saving_n_attachments_to_sd_card, count, count)
|
||||||
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@ -42,31 +45,25 @@ class SaveAttachmentTask : ProgressDialogAsyncTask<SaveAttachmentTask.Attachment
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun showWarningDialog(context: Context, count: Int = 1, onAcceptListener: () -> Unit) {
|
fun showWarningDialog(context: Context, count: Int = 1, onAcceptListener: () -> Unit = {}) {
|
||||||
context.sessionDialog {
|
context.sessionDialog {
|
||||||
title(R.string.ConversationFragment_save_to_sd_card)
|
title(R.string.ConversationFragment_save_to_sd_card)
|
||||||
setIconAttribute(R.attr.dialog_alert_icon)
|
iconAttribute(R.attr.dialog_alert_icon)
|
||||||
text(context.resources.getQuantityString(
|
text(context.resources.getQuantityString(
|
||||||
R.plurals.ConversationFragment_saving_n_media_to_storage_warning,
|
R.plurals.ConversationFragment_saving_n_media_to_storage_warning,
|
||||||
count,
|
count,
|
||||||
count))
|
count))
|
||||||
buttons {
|
button(R.string.yes) { onAcceptListener() }
|
||||||
button(R.string.yes) { onAcceptListener() }
|
button(R.string.no)
|
||||||
button(R.string.no)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val contextReference: WeakReference<Context>
|
private val contextReference: WeakReference<Context>
|
||||||
private val attachmentCount: Int
|
private val attachmentCount: Int = count
|
||||||
|
|
||||||
@JvmOverloads
|
init {
|
||||||
constructor(context: Context, count: Int = 1): super(context,
|
|
||||||
context.resources.getQuantityString(R.plurals.ConversationFragment_saving_n_attachments, count, count),
|
|
||||||
context.resources.getQuantityString(R.plurals.ConversationFragment_saving_n_attachments_to_sd_card, count, count)) {
|
|
||||||
this.contextReference = WeakReference(context)
|
this.contextReference = WeakReference(context)
|
||||||
this.attachmentCount = count
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doInBackground(vararg attachments: Attachment?): Pair<Int, String?> {
|
override fun doInBackground(vararg attachments: Attachment?): Pair<Int, String?> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user