Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show confirmation dialog before deleting message. #1811

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
override val sendIntent by lazy { send.clicks() }
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
override val confirmDeleteIntent: Subject<List<Long>> = PublishSubject.create()

private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ComposeViewModel::class.java] }

Expand Down Expand Up @@ -349,6 +350,16 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
}
}

override fun showDeleteDialog(messages: List<Long>) {
val count = messages.size
android.app.AlertDialog.Builder(this)
.setTitle(R.string.dialog_delete_title)
.setMessage(resources.getQuantityString(R.plurals.dialog_delete_chat, count, count))
.setPositiveButton(R.string.button_delete) { _, _ -> confirmDeleteIntent.onNext(messages) }
.setNegativeButton(R.string.button_cancel, null)
.show()
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.compose, menu)
return super.onCreateOptionsMenu(menu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface ComposeView : QkView<ComposeState> {
val sendIntent: Observable<Unit>
val viewQksmsPlusIntent: Subject<Unit>
val backPressedIntent: Observable<Unit>
val confirmDeleteIntent: Observable<List<Long>>

fun clearSelection()
fun showDetails(details: String)
Expand All @@ -71,5 +72,6 @@ interface ComposeView : QkView<ComposeState> {
fun setDraft(draft: String)
fun scrollToMessage(id: Long)
fun showQksmsPlusSnackbar(@StringRes message: Int)
fun showDeleteDialog( messages: List<Long>)

}
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ class ComposeViewModel @Inject constructor(
.autoDisposable(view.scope())
.subscribe { view.showDetails(it) }

// Delete the messages
// Show the delete message dialog
view.optionsItemIntent
.filter { it == R.id.delete }
.filter { permissionManager.isDefaultSms().also { if (!it) view.requestDefaultSms() } }
.withLatestFrom(view.messagesSelectedIntent, conversation) { _, messages, conversation ->
deleteMessages.execute(DeleteMessages.Params(messages, conversation.id))
view.showDeleteDialog(messages)
}
.autoDisposable(view.scope())
.subscribe { view.clearSelection() }
.subscribe()

// Forward the message
view.optionsItemIntent
Expand Down Expand Up @@ -728,6 +728,14 @@ class ComposeViewModel @Inject constructor(
.autoDisposable(view.scope())
.subscribe()

// Delete the message
view.confirmDeleteIntent
.withLatestFrom(view.messagesSelectedIntent, conversation) { _, messages, conversation ->
deleteMessages.execute(DeleteMessages.Params(messages, conversation.id))
}
.autoDisposable(view.scope())
.subscribe { view.clearSelection() }

}

private fun getVCard(contactData: Uri): String? {
Expand Down
3 changes: 2 additions & 1 deletion presentation/src/main/res/layout/blocked_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
app:textSize="primary"
tools:text="@tools:sample/full_names" />
tools:text="@tools:sample/full_names"
android:textDirection="ltr" />

<com.moez.QKSMS.common.widget.QkTextView
android:id="@+id/date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingStart="24dp"
tools:text="(123) 456-7890" />
tools:text="(123) 456-7890"
android:textDirection="ltr" />

<ImageView
android:id="@+id/unblock"
Expand Down
3 changes: 2 additions & 1 deletion presentation/src/main/res/layout/chip_input_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
android:privateImeOptions="nm"
android:textColor="?android:attr/textColorPrimary"
android:textColorHint="?android:attr/textColorTertiary"
app:textSize="primary" />
app:textSize="primary"
android:textDirection="ltr" />
3 changes: 2 additions & 1 deletion presentation/src/main/res/layout/compose_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@
android:id="@+id/toolbarTitle"
style="@style/ToolbarText"
android:layout_height="wrap_content"
tools:text="Moez Bhatti" />
tools:text="Moez Bhatti"
android:textDirection="ltr" />

<com.moez.QKSMS.common.widget.QkTextView
android:id="@+id/toolbarSubtitle"
Expand Down
3 changes: 2 additions & 1 deletion presentation/src/main/res/layout/contact_chip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
app:textSize="secondary"
tools:text="Moez Bhatti" />
tools:text="Moez Bhatti"
android:textDirection="ltr" />

</LinearLayout>

Expand Down
3 changes: 2 additions & 1 deletion presentation/src/main/res/layout/contact_chip_detailed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
app:layout_constraintTop_toBottomOf="@id/name"
app:textSize="secondary"
tools:text="(123) 456-7890"
tools:textColor="@color/textTertiaryDark" />
tools:textColor="@color/textTertiaryDark"
android:textDirection="ltr" />

<ImageView
android:id="@+id/delete"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
android:gravity="center_vertical"
android:textColor="?android:attr/textColorTertiary"
app:textSize="secondary"
tools:text="(123) 456-7890" />
tools:text="(123) 456-7890"
android:textDirection="ltr" />

</LinearLayout>
3 changes: 2 additions & 1 deletion presentation/src/main/res/layout/contacts_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar"
tools:listitem="@layout/contact_list_item" />
tools:listitem="@layout/contact_list_item"
android:textDirection="ltr" />

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
android:clipChildren="false"
android:clipToPadding="false"
android:paddingTop="8dp"
android:paddingBottom="8dp" />
android:paddingBottom="8dp"
android:textDirection="ltr" />
3 changes: 2 additions & 1 deletion presentation/src/main/res/layout/conversation_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
app:layout_constraintStart_toEndOf="@id/avatars"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="@tools:sample/full_names" />
tools:text="@tools:sample/full_names"
android:textDirection="ltr" />

<com.moez.QKSMS.common.widget.QkTextView
android:id="@+id/snippet"
Expand Down
4 changes: 4 additions & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
<item quantity="one">Are you sure you would like to delete this conversation?</item>
<item quantity="other">Are you sure you would like to delete %d conversations?</item>
</plurals>
<plurals name="dialog_delete_chat">
<item quantity="one">Are you sure you would like to delete this message?</item>
<item quantity="other">Are you sure you would like to delete %d messages?</item>
</plurals>

<string-array name="message_options">
<item>Copy text</item>
Expand Down