Enforce style convention

This commit is contained in:
Niels Andriesse 2020-02-21 11:35:53 +07:00
parent f46354392c
commit 704c15cd24
2 changed files with 20 additions and 28 deletions

View File

@ -1662,13 +1662,12 @@
<string name="session_restore_banner_dismiss_button_title">Dismiss</string> <string name="session_restore_banner_dismiss_button_title">Dismiss</string>
<string name="session_restore_banner_restore_button_title">Restore</string> <string name="session_restore_banner_restore_button_title">Restore</string>
<!-- Loki -->
<!-- Session --> <!-- Session -->
<string name="activity_register_public_key_copied_message">Copied to clipboard</string> <string name="activity_register_public_key_copied_message">Copied to clipboard</string>
<!-- Session --> <string name="activity_home_leave_group_dialog_message">Are you sure you want to leave this group?</string>
<string name="activity_home_delete_conversation_dialog_message">Are you sure you want to delete this conversation?</string>
<!-- Home Activity --> <string name="activity_home_conversation_deleted_message">Conversation deleted</string>
<string name="activity_home_conversation_deleted">Conversation deleted</string>
<string name="activity_home_leave_group_title">Are you sure you want to leave the group?</string>
<string name="activity_home_delete_conversation_title">Are you sure you want to delete the conversation?</string>
</resources> </resources>

View File

@ -11,7 +11,6 @@ import android.graphics.Paint
import android.os.AsyncTask import android.os.AsyncTask
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.support.design.widget.Snackbar
import android.support.v4.app.LoaderManager import android.support.v4.app.LoaderManager
import android.support.v4.content.Loader import android.support.v4.content.Loader
import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.LinearLayoutManager
@ -232,8 +231,9 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
val threadID = (viewHolder as HomeAdapter.ViewHolder).view.thread!!.threadId viewHolder as HomeAdapter.ViewHolder
val recipient = (viewHolder as HomeAdapter.ViewHolder).view.thread!!.recipient val threadID = viewHolder.view.thread!!.threadId
val recipient = viewHolder.view.thread!!.recipient
val threadDatabase = DatabaseFactory.getThreadDatabase(activity) val threadDatabase = DatabaseFactory.getThreadDatabase(activity)
val deleteThread = object : Runnable { val deleteThread = object : Runnable {
@ -246,44 +246,37 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
apiDatabase.removeLastDeletionServerID(publicChat.channel, publicChat.server) apiDatabase.removeLastDeletionServerID(publicChat.channel, publicChat.server)
ApplicationContext.getInstance(activity).lokiPublicChatAPI!!.leave(publicChat.channel, publicChat.server) ApplicationContext.getInstance(activity).lokiPublicChatAPI!!.leave(publicChat.channel, publicChat.server)
} }
threadDatabase.deleteConversation(threadID) threadDatabase.deleteConversation(threadID)
MessageNotifier.updateNotification(activity) MessageNotifier.updateNotification(activity)
} }
} }
} }
val dialogMessage = if (recipient.isGroupRecipient) R.string.activity_home_leave_group_dialog_message else R.string.activity_home_delete_conversation_dialog_message
val message = if (recipient.isGroupRecipient) R.string.activity_home_leave_group_title else R.string.activity_home_delete_conversation_title val dialog = AlertDialog.Builder(activity)
val alertDialogBuilder = AlertDialog.Builder(activity) dialog.setMessage(dialogMessage)
alertDialogBuilder.setMessage(message) dialog.setPositiveButton(R.string.yes) { _, _ ->
alertDialogBuilder.setPositiveButton(R.string.yes) { _, _ ->
val isGroup = recipient.isGroupRecipient val isGroup = recipient.isGroupRecipient
// Send a leave group message if this is an active closed group
// If we are deleting a group and it's active
// We need to send a leave message
if (isGroup && DatabaseFactory.getGroupDatabase(activity).isActive(recipient.address.toGroupString())) { if (isGroup && DatabaseFactory.getGroupDatabase(activity).isActive(recipient.address.toGroupString())) {
if (!GroupUtil.leaveGroup(activity, recipient)) { if (!GroupUtil.leaveGroup(activity, recipient)) {
Toast.makeText(activity, R.string.ConversationActivity_error_leaving_group, Toast.LENGTH_LONG).show() Toast.makeText(activity, "Couldn't leave group", Toast.LENGTH_LONG).show()
clearView(activity.recyclerView, viewHolder) clearView(activity.recyclerView, viewHolder)
return@setPositiveButton return@setPositiveButton
} }
} }
// Archive the conversation and then delete it after 10 seconds (the case where the
// Archive and forcefully delete the conversation in 10 seconds // app was closed before the conversation could be deleted is handled in onCreate)
threadDatabase.archiveConversation(threadID) threadDatabase.archiveConversation(threadID)
val handler = Handler() val handler = Handler()
handler.postDelayed(deleteThread, 10000) handler.postDelayed(deleteThread, 10000)
// Notify the user // Notify the user
val snackbarText = if (isGroup) R.string.MessageRecord_left_group else R.string.activity_home_conversation_deleted val toastMessage = if (isGroup) R.string.MessageRecord_left_group else R.string.activity_home_conversation_deleted_message
val snackbar = Snackbar.make(activity.contentView, snackbarText, Snackbar.LENGTH_LONG) Toast.makeText(activity, toastMessage, Toast.LENGTH_LONG).show()
snackbar.show()
} }
alertDialogBuilder.setNegativeButton(R.string.no) { _, _ -> dialog.setNegativeButton(R.string.no) { _, _ ->
clearView(activity.recyclerView, viewHolder) clearView(activity.recyclerView, viewHolder)
} }
alertDialogBuilder.show() dialog.create().show()
} }
override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dx: Float, dy: Float, actionState: Int, isCurrentlyActive: Boolean) { override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dx: Float, dy: Float, actionState: Int, isCurrentlyActive: Boolean) {