|
| 1 | +/* |
| 2 | + * Infomaniak Mail - Android |
| 3 | + * Copyright (C) 2024 Infomaniak Network SA |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | +package com.infomaniak.mail.ui.main.thread.actions |
| 19 | + |
| 20 | +import android.content.Context |
| 21 | +import android.content.DialogInterface |
| 22 | +import android.content.DialogInterface.OnClickListener |
| 23 | +import android.os.Bundle |
| 24 | +import android.view.LayoutInflater |
| 25 | +import android.view.View |
| 26 | +import android.view.ViewGroup |
| 27 | +import androidx.appcompat.app.AlertDialog |
| 28 | +import androidx.core.widget.doOnTextChanged |
| 29 | +import androidx.fragment.app.activityViewModels |
| 30 | +import androidx.navigation.fragment.navArgs |
| 31 | +import com.google.android.material.dialog.MaterialAlertDialogBuilder |
| 32 | +import com.infomaniak.lib.core.utils.context |
| 33 | +import com.infomaniak.lib.core.utils.safeBinding |
| 34 | +import com.infomaniak.lib.core.utils.showKeyboard |
| 35 | +import com.infomaniak.mail.MatomoMail.trackBottomSheetThreadActionsEvent |
| 36 | +import com.infomaniak.mail.R |
| 37 | +import com.infomaniak.mail.data.models.message.Message |
| 38 | +import com.infomaniak.mail.databinding.BottomSheetUserToBlockBinding |
| 39 | +import com.infomaniak.mail.databinding.DialogConfirmationToBlockUserBinding |
| 40 | +import com.infomaniak.mail.databinding.DialogInsertLinkBinding |
| 41 | +import com.infomaniak.mail.ui.MainViewModel |
| 42 | +import com.infomaniak.mail.ui.alertDialogs.BaseAlertDialog |
| 43 | +import dagger.hilt.android.qualifiers.ActivityContext |
| 44 | +import dagger.hilt.android.scopes.ActivityScoped |
| 45 | +import javax.inject.Inject |
| 46 | + |
| 47 | +@ActivityScoped |
| 48 | +class ConfirmationToBlockUserDialog @Inject constructor( |
| 49 | + @ActivityContext private val activityContext: Context, |
| 50 | +) : BaseAlertDialog(activityContext) { |
| 51 | + |
| 52 | + private val binding: DialogConfirmationToBlockUserBinding by lazy { |
| 53 | + DialogConfirmationToBlockUserBinding.inflate(activity.layoutInflater) |
| 54 | + } |
| 55 | + |
| 56 | + private var onPositiveButtonClick: ((Message?) -> Unit)? = null |
| 57 | + private var messageOfUserToBlock: Message? = null |
| 58 | + |
| 59 | + override val alertDialog: AlertDialog = with(binding) { |
| 60 | + MaterialAlertDialogBuilder(context) |
| 61 | + .setView(root) |
| 62 | + .setPositiveButton(R.string.buttonConfirm) { dialog, which -> |
| 63 | + onPositiveButtonClick?.invoke(messageOfUserToBlock) |
| 64 | + } |
| 65 | + .setNegativeButton(com.infomaniak.lib.core.R.string.buttonCancel, null) |
| 66 | + .create() |
| 67 | + } |
| 68 | + |
| 69 | + override fun resetCallbacks() { |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + fun show(message: Message) = with(binding) { |
| 74 | + messageOfUserToBlock = message |
| 75 | + val recipient = message.from[0] |
| 76 | + blockExpeditorTitle.text = activityContext.getString(R.string.blockExpeditorTitle, recipient.name) |
| 77 | + blockExpeditorDescription.text = activityContext.getString(R.string.confirmationToBlockAnExpeditorText, recipient.email) |
| 78 | + alertDialog.show() |
| 79 | + } |
| 80 | + |
| 81 | + fun setCallback(onPositiveButtonClick: (Message?) -> Unit) { |
| 82 | + this.onPositiveButtonClick = onPositiveButtonClick |
| 83 | + } |
| 84 | +} |
0 commit comments