Commit dc75f75e authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Adds delete own account.

parent b0ac2591
......@@ -234,11 +234,11 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
fun showLogoutDialog() {
val builder = AlertDialog.Builder(this)
builder.setTitle(R.string.action_logout)
builder.setMessage(R.string.title_confirmation)
builder.setPositiveButton(R.string.action_logout) { _, _ -> presenter.logout()}
.setNegativeButton(R.string.action_stay) { dialog, _ -> dialog.cancel() }
builder.create().show()
builder.setTitle(R.string.title_are_you_sure)
.setPositiveButton(R.string.action_logout) { _, _ -> presenter.logout()}
.setNegativeButton(android.R.string.no) { dialog, _ -> dialog.cancel() }
.create()
.show()
}
fun setAvatar(avatarUrl: String) {
......
......@@ -9,15 +9,19 @@ import chat.rocket.android.helper.UserHelper
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.android.util.extension.compressImageAndGetByteArray
import chat.rocket.android.util.extension.gethash
import chat.rocket.android.util.extension.launchUI
import chat.rocket.android.util.extension.toHex
import chat.rocket.android.util.extensions.avatarUrl
import chat.rocket.android.util.retryIO
import chat.rocket.common.RocketChatException
import chat.rocket.common.util.ifNull
import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.rest.deleteOwnAccount
import chat.rocket.core.internal.rest.resetAvatar
import chat.rocket.core.internal.rest.setAvatar
import chat.rocket.core.internal.rest.updateProfile
import java.lang.Exception
import java.util.*
import javax.inject.Inject
......@@ -147,4 +151,21 @@ class ProfilePresenter @Inject constructor(
}
}
}
fun deleteAccount(password: String) {
launchUI(strategy) {
view.showLoading()
try {
retryIO { client.deleteOwnAccount(password.gethash().toHex()) }
} catch (exception: Exception) {
exception.message?.let {
view.showMessage(it)
}.ifNull {
view.showGenericErrorMessage()
}
} finally {
view.hideLoading()
}
}
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package chat.rocket.android.profile.ui
import DrawableHelper
import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.graphics.Bitmap
import android.os.Build
......@@ -11,6 +12,8 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.MenuInflater
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode
import androidx.core.net.toUri
......@@ -61,6 +64,7 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {
override fun onCreate(savedInstanceState: Bundle?) {
AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}
override fun onCreateView(
......@@ -98,6 +102,25 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {
}
}
override fun onPrepareOptionsMenu(menu: Menu) {
if (actionMode != null) {
menu.clear()
}
super.onPrepareOptionsMenu(menu)
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.profile, menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_delete_account -> showDeleteAccountDialog()
}
return true
}
override fun showProfile(avatarUrl: String, name: String, username: String, email: String?) {
ui {
image_avatar.setImageURI(avatarUrl)
......@@ -148,7 +171,7 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {
override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error))
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
mode.menuInflater.inflate(R.menu.profile, menu)
mode.menuInflater.inflate(R.menu.action_mode_profile, menu)
mode.title = getString(R.string.title_update_profile)
return true
}
......@@ -239,6 +262,7 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {
text_username.toString() != currentUsername ||
text_email.toString() != currentEmail)
}.subscribe { isValid ->
activity?.invalidateOptionsMenu()
if (isValid) {
startActionMode()
} else {
......@@ -264,4 +288,19 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {
text_email.isEnabled = value
}
}
fun showDeleteAccountDialog() {
val passwordEditText = EditText(context)
passwordEditText.hint = getString(R.string.msg_password)
val builder = AlertDialog.Builder(context)
builder.setTitle(R.string.title_are_you_sure)
.setView(passwordEditText)
.setPositiveButton(R.string.action_delete_account) { _, _ ->
presenter.deleteAccount(passwordEditText.text.toString())
}
.setNegativeButton(android.R.string.no) { dialog, _ -> dialog.cancel() }
.create()
.show()
}
}
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_update_profile"
android:icon="@drawable/ic_check_white_24dp"
android:title="@string/action_update" />
</menu>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_update_profile"
android:icon="@drawable/ic_check_white_24dp"
android:title="@string/action_update" />
android:id="@+id/action_delete_account"
android:title="@string/action_delete_account"
app:showAsAction="never" />
</menu>
\ No newline at end of file
......@@ -20,7 +20,7 @@
<string name="title_update_profile">Update Profil</string>
<string name="title_about">Über</string>
<string name="title_create_channel">Erstelle Raum</string>
<string name="title_confirmation">Are You Sure you want to logout?</string><!-- TODO Add translation -->
<string name="title_are_you_sure">Are you sure?</string><!-- TODO Add translation -->
<!-- Actions -->
<string name="action_connect">Verbinde</string>
......@@ -33,7 +33,6 @@
<string name="action_create_channel">Erstelle Raum</string>
<string name="action_create">Erstelle</string>
<string name="action_logout">Abmelden</string>
<string name="action_stay">Stay</string> <!-- TODO Add translation -->
<string name="action_files">Dateien</string>
<string name="action_confirm_password">Bestätige Passwort Änderung</string>
<string name="action_join_chat">Trete Chat bei</string>
......@@ -52,6 +51,7 @@
<string name="action_create_server">Create a new server</string> <!-- TODO Add translation -->
<string name="action_register">Register</string> <!-- TODO Add translation -->
<string name="action_confirm">Confirm</string> <!-- TODO Add translation -->
<string name="action_delete_account">Delete account</string> <!-- TODO Add translation -->
<!-- Settings List -->
<string-array name="settings_actions">
......
......@@ -19,7 +19,8 @@
<string name="title_update_profile">Actualización del perfil</string>
<string name="title_about">Acerca de</string>
<string name="title_create_channel">Crear canal</string>
<string name="title_confirmation">Are You Sure you want to logout?</string> <!-- TODO Add translation -->
<string name="title_are_you_sure">Are you sure?</string> <!-- TODO Add translation -->
<!-- Actions -->
<string name="action_connect">Conectar</string>
<string name="action_use_this_username">Usa este nombre de usuario</string>
......@@ -31,7 +32,6 @@
<string name="action_create_channel">Crear canal</string>
<string name="action_create">Create</string>
<string name="action_logout">Cerrar sesión</string>
<string name="action_stay">Stay</string> <!-- TODO Add translation -->
<string name="action_files">Archivos</string>
<string name="action_confirm_password">Confirmar cambio de contraseña</string>
<string name="action_join_chat">Unirse al chat</string>
......@@ -50,6 +50,7 @@
<string name="action_create_server">Create a new server</string> <!-- TODO Add translation -->
<string name="action_register">Register</string> <!-- TODO Add translation -->
<string name="action_confirm">Confirm</string> <!-- TODO Add translation -->
<string name="action_delete_account">Delete account</string> <!-- TODO Add translation -->
<!-- Settings List -->
<string-array name="settings_actions">
......
......@@ -20,9 +20,7 @@
<string name="title_update_profile">Mettre à jour le profil</string>
<string name="title_about">À propos</string>
<string name="title_create_channel">Créer salon</string>
<string name="title_confirmation">Are You Sure you want to logout?</string> <!-- TODO Add translation -->
<string name="title_are_you_sure">Are you sure?</string> <!-- TODO Add translation -->
<!-- Actions -->
<string name="action_connect">Se connecter</string>
......@@ -35,7 +33,6 @@
<string name="action_create_channel">Créer salon</string>
<string name="action_create">Créer</string>
<string name="action_logout">Se déconnecter</string>
<string name="action_stay">Stay</string> <!-- TODO Add translation -->
<string name="action_files">Fichiers</string>
<string name="action_confirm_password">Confirmer le mot de passe</string>
<string name="action_join_chat">Rejoignez le chat</string>
......@@ -54,6 +51,7 @@
<string name="action_create_server">Create a new server</string> <!-- TODO Add translation -->
<string name="action_register">Register</string> <!-- TODO Add translation -->
<string name="action_confirm">Confirm</string> <!-- TODO Add translation -->
<string name="action_delete_account">Delete account</string> <!-- TODO Add translation -->
<!-- Settings List -->
<string-array name="settings_actions">
......
......@@ -20,8 +20,7 @@
<string name="title_update_profile">प्रोफ़ाइल अपडेट करें</string>
<string name="title_about">परिचय</string>
<string name="title_create_channel">चैनल बनाएं</string>
<string name="title_confirmation">Are You Sure you want to logout?</string> <!-- TODO Add translation -->
<string name="title_are_you_sure">Are you sure?</string> <!-- TODO Add translation -->
<!-- Actions -->
<string name="action_connect">जुडिये</string>
......@@ -34,7 +33,6 @@
<string name="action_create_channel">चैनल बनाएं</string>
<string name="action_create">बनाएं</string>
<string name="action_logout">लोग आउट करें</string>
<string name="action_stay">Stay</string> <!-- TODO Add translation -->
<string name="action_files">फ़ाइलें</string>
<string name="action_confirm_password">पासवर्ड परिवर्तन की पुष्टि करें</string>
<string name="action_join_chat">चैट में शामिल हों</string>
......@@ -53,6 +51,7 @@
<string name="action_create_server">नया सर्वर बनाएं</string>
<string name="action_register">रजिस्टर</string>
<string name="action_confirm">पुष्टि करें</string>
<string name="action_delete_account">Delete account</string> <!-- TODO Add translation -->
<!-- Settings List -->
<string-array name="settings_actions">
......
......@@ -22,8 +22,7 @@
<string name="title_update_profile">プロフィールの更新</string>
<string name="title_about">About</string>
<string name="title_create_channel">新しいチャネルを作成します</string>
<string name="title_confirmation">Are You Sure you want to logout?</string> <!-- TODO Add translation -->
<string name="title_are_you_sure">Are you sure?</string> <!-- TODO Add translation -->
<!-- Actions -->
<string name="action_connect">接続</string>
......@@ -36,7 +35,6 @@
<string name="action_create_channel">チャンネル作成</string>
<string name="action_create">作ります</string>
<string name="action_logout">ログアウト</string>
<string name="action_stay">Stay</string> <!-- TODO Add translation -->
<string name="action_files">ファイル</string>
<string name="action_confirm_password">変更したパスワードの確認</string>
<string name="action_join_chat">チャットに参加</string>
......@@ -55,6 +53,7 @@
<string name="action_create_server">Create a new server</string> <!-- TODO Add translation -->
<string name="action_register">Register</string> <!-- TODO Add translation -->
<string name="action_confirm">Confirm</string> <!-- TODO Add translation -->
<string name="action_delete_account">Delete account</string> <!-- TODO Add translation -->
<!-- Settings List -->
<string-array name="settings_actions">
......
......@@ -20,8 +20,7 @@
<string name="title_update_profile">Editar perfil</string>
<string name="title_about">Sobre</string>
<string name="title_create_channel">Criar chat</string>
<string name="title_confirmation">Are You Sure you want to logout?</string> <!-- TODO Add translation -->
<string name="title_are_you_sure">Você tem certeza?</string>
<!-- Actions -->
<string name="action_connect">Conectar</string>
......@@ -34,7 +33,6 @@
<string name="action_create_channel">Criar chat</string>
<string name="action_create">Criar</string>
<string name="action_logout">Sair</string>
<string name="action_stay">Stay</string> <!-- TODO Add translation -->
<string name="action_files">Arquivos</string>
<string name="action_confirm_password">Confirme a nova senha</string>
<string name="action_join_chat">Entrar no Chat</string>
......@@ -48,11 +46,12 @@
<string name="action_select_photo_from_gallery">Escolher foto da galeria</string>
<string name="action_take_photo">Tirar foto</string>
<string name="action_reset_avatar">Resetar avatar</string>
<string name="action_connect_server">Connect with a server</string> <!-- TODO Add translation -->
<string name="action_join_community">Join in the community</string> <!-- TODO Add translation -->
<string name="action_create_server">Create a new server</string> <!-- TODO Add translation -->
<string name="action_register">Register</string> <!-- TODO Add translation -->
<string name="action_confirm">Confirm</string> <!-- TODO Add translation -->
<string name="action_connect_server">Conectar com um servidor</string>
<string name="action_join_community">Junte-se à comunidade</string>
<string name="action_create_server">Criar um novo servidor</string>
<string name="action_register">Registrar</string>
<string name="action_confirm">Confirmar</string>
<string name="action_delete_account">Deletar conta</string>
<!-- Settings List -->
<string-array name="settings_actions">
......
......@@ -20,8 +20,7 @@
<string name="title_update_profile">Обновить профиль</string>
<string name="title_about">О программе</string>
<string name="title_create_channel">Создать новый канал</string>
<string name="title_confirmation">Вы действительно хотите выйти?</string>
<string name="title_are_you_sure">Are you sure?</string> <!-- TODO Add translation -->
<!-- Actions -->
<string name="action_connect">Подключиться</string>
......@@ -34,7 +33,6 @@
<string name="action_create_channel">Создать канал</string>
<string name="action_create">Создать</string>
<string name="action_logout">Выйти</string>
<string name="action_stay">Остаться</string>
<string name="action_files">Файлы</string>
<string name="action_confirm_password">Подтверждение изменения пароля</string>
<string name="action_join_chat">Присоединиться к чату</string>
......@@ -53,6 +51,7 @@
<string name="action_create_server">Создать новый сервер</string>
<string name="action_register">Зарегистрировать</string>
<string name="action_confirm">Подтвердить</string>
<string name="action_delete_account">Delete account</string> <!-- TODO Add translation -->
<!-- Settings List -->
<string-array name="settings_actions">
......
......@@ -20,8 +20,7 @@
<string name="title_update_profile">Profilinizi Düzenleyin</string>
<string name="title_about">Hakkında</string>
<string name="title_create_channel">Yeni Kanal Oluştur</string>
<string name="title_confirmation">Are You Sure you want to logout?</string> <!-- TODO Add translation -->
<string name="title_are_you_sure">Are you sure?</string> <!-- TODO Add translation -->
<!-- Actions -->
<string name="action_connect">Bağlan</string>
......@@ -34,7 +33,6 @@
<string name="action_create_channel">Yeni Kanal Oluştur</string>
<string name="action_create">Oluştur</string>
<string name="action_logout">Çıkış Yap</string>
<string name="action_stay">Stay</string> <!-- TODO Add translation -->
<string name="action_files">Dosyalar</string>
<string name="action_confirm_password">Şifre Değişikliğini Onaylayın</string>
<string name="action_join_chat">Sohbete Bağlan</string>
......@@ -53,6 +51,7 @@
<string name="action_create_server">Create a new server</string> <!-- TODO Add translation -->
<string name="action_register">Register</string> <!-- TODO Add translation -->
<string name="action_confirm">Confirm</string> <!-- TODO Add translation -->
<string name="action_delete_account">Delete account</string> <!-- TODO Add translation -->
<!-- Settings List -->
<string-array name="settings_actions">
......
......@@ -20,8 +20,7 @@
<string name="title_update_profile">Оновити профіль</string>
<string name="title_about">"Про програму"</string>
<string name="title_create_channel">Створити новий канал</string>
<string name="title_confirmation">Are You Sure you want to logout?</string> <!-- TODO Add translation -->
<string name="title_are_you_sure">Are you sure?</string> <!-- TODO Add translation -->
<!-- Actions -->
<string name="action_connect">Підключитися</string>
......@@ -34,7 +33,6 @@
<string name="action_create_channel">Створити канал</string>
<string name="action_create">Створити</string>
<string name="action_logout">Вийти</string>
<string name="action_stay">Stay</string> <!-- TODO Add translation -->
<string name="action_files">Файли</string>
<string name="action_confirm_password">Підтвердження зміни пароля</string>
<string name="action_join_chat">Приєднатися до чату</string>
......@@ -53,6 +51,7 @@
<string name="action_create_server">Create a new server</string> <!-- TODO Add translation -->
<string name="action_register">Register</string> <!-- TODO Add translation -->
<string name="action_confirm">Confirm</string> <!-- TODO Add translation -->
<string name="action_delete_account">Delete account</string> <!-- TODO Add translation -->
<!-- Settings List -->
<string-array name="settings_actions">
......
......@@ -32,7 +32,7 @@ https://github.com/RocketChat/java-code-styles/blob/master/CODING_STYLE.md#strin
<string name="title_update_profile">Update profile</string>
<string name="title_about">About</string>
<string name="title_create_channel">Create Channel</string>
<string name="title_confirmation">Are You Sure you want to logout?</string>
<string name="title_are_you_sure">Are you sure?</string>
<!-- Actions -->
<string name="action_connect">Connect</string>
......@@ -45,7 +45,6 @@ https://github.com/RocketChat/java-code-styles/blob/master/CODING_STYLE.md#strin
<string name="action_create_channel">Create channel</string>
<string name="action_create">Create</string>
<string name="action_logout">Logout</string>
<string name="action_stay">Stay</string>
<string name="action_files">Files</string>
<string name="action_confirm_password">Confirm Password Change</string>
<string name="action_join_chat">Join Chat</string>
......@@ -64,6 +63,7 @@ https://github.com/RocketChat/java-code-styles/blob/master/CODING_STYLE.md#strin
<string name="action_create_server">Create a new server</string>
<string name="action_register">Register</string>
<string name="action_confirm">Confirm</string>
<string name="action_delete_account">Delete account</string>
<!-- Settings List -->
<string-array name="settings_actions">
......
package chat.rocket.android.util.extension
import java.math.BigInteger
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
@Throws(NoSuchAlgorithmException::class)
fun String.gethash(): ByteArray {
val digest = MessageDigest.getInstance("SHA-256")
digest.reset()
return digest.digest(this.toByteArray())
}
fun ByteArray.toHex(): String = String.format("%0" + this.size * 2 + "X", BigInteger(1, this))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment