AddExchangeDialogFragment.kt (1961B)
1 /* 2 * This file is part of GNU Taler 3 * (C) 2020 Taler Systems S.A. 4 * 5 * GNU Taler is free software; you can redistribute it and/or modify it under the 6 * terms of the GNU General Public License as published by the Free Software 7 * Foundation; either version 3, or (at your option) any later version. 8 * 9 * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License along with 14 * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 package net.taler.wallet.exchanges 18 19 import android.app.Dialog 20 import android.os.Bundle 21 import android.widget.TextView 22 import androidx.appcompat.app.AlertDialog 23 import androidx.fragment.app.DialogFragment 24 import androidx.fragment.app.activityViewModels 25 import com.google.android.material.dialog.MaterialAlertDialogBuilder 26 import net.taler.wallet.MainViewModel 27 import net.taler.wallet.R 28 29 30 class AddExchangeDialogFragment : DialogFragment() { 31 32 private val model: MainViewModel by activityViewModels() 33 private val exchangeManager by lazy { model.exchangeManager } 34 35 override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { 36 return MaterialAlertDialogBuilder(requireContext(), R.style.MaterialAlertDialog_Material3) 37 .setIcon(R.drawable.ic_account_balance) 38 .setTitle(R.string.exchange_list_add) 39 .setView(R.layout.dialog_exchange_add) 40 .setPositiveButton(R.string.ok) { dialog, _ -> 41 val urlView: TextView = (dialog as AlertDialog).findViewById(R.id.urlView)!! 42 exchangeManager.add(urlView.text.toString()) 43 } 44 .setNegativeButton(R.string.cancel) { _, _ -> 45 dismiss() 46 } 47 .create() 48 } 49 50 }