/* * This file is part of GNU Taler * (C) 2020 Taler Systems S.A. * * GNU Taler is free software; you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation; either version 3, or (at your option) any later version. * * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with * GNU Taler; see the file COPYING. If not, see */ package net.taler.wallet import android.app.Dialog import android.content.Context import android.content.Intent import android.os.Bundle import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button import androidx.appcompat.app.AlertDialog import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment import kotlinx.android.synthetic.main.fragment_settings.* interface ResetDialogEventListener { fun onResetConfirmed() fun onResetCancelled() } class ResetDialogFragment : DialogFragment() { private lateinit var listener: ResetDialogEventListener override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return activity?.let { // Use the Builder class for convenient dialog construction val builder = AlertDialog.Builder(it) builder.setMessage("Do you really want to reset the wallet and lose all coins and purchases? Consider making a backup first.") .setPositiveButton("Reset") { _, _ -> listener.onResetConfirmed() } .setNegativeButton("Cancel") { _, _ -> listener.onResetCancelled() } // Create the AlertDialog object and return it builder.create() } ?: throw IllegalStateException("Activity cannot be null") } override fun onAttach(context: Context) { super.onAttach(context) // Verify that the host activity implements the callback interface try { // Instantiate the NoticeDialogListener so we can send events to the host listener = context as ResetDialogEventListener } catch (e: ClassCastException) { // The activity doesn't implement the interface, throw exception throw ClassCastException((context.toString() + " must implement ResetDialogEventListener")) } } } /** * A simple [Fragment] subclass. * */ class Settings : Fragment() { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { when (requestCode) { CREATE_FILE -> { if (data == null) { return } Log.i(TAG, "got createFile result with URL ${data.data}") } PICK_FILE -> { if (data == null) { return } Log.i(TAG, "got pickFile result with URL ${data.data}") } else -> { } } } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment val view = inflater.inflate(R.layout.fragment_settings, container, false) view.findViewById