taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

ErrorBottomSheet.kt (2373B)


      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.lib.android
     18 
     19 import android.content.Intent
     20 import android.os.Bundle
     21 import android.view.LayoutInflater
     22 import android.view.View
     23 import android.view.ViewGroup
     24 import com.google.android.material.bottomsheet.BottomSheetDialogFragment
     25 import net.taler.common.R
     26 import net.taler.common.databinding.BottomsheetErrorBinding
     27 
     28 class ErrorBottomSheet : BottomSheetDialogFragment() {
     29 
     30     companion object {
     31         fun newInstance(mainText: String, detailText: String) = ErrorBottomSheet().apply {
     32             arguments = Bundle().apply {
     33                 putString("TEXT_MAIN", mainText)
     34                 putString("TEXT_DETAIL", detailText)
     35             }
     36             setStyle(STYLE_NORMAL, R.style.ErrorBottomSheetTheme)
     37         }
     38     }
     39 
     40     override fun onCreateView(
     41         inflater: LayoutInflater,
     42         container: ViewGroup?,
     43         savedInstanceState: Bundle?
     44     ): View? {
     45         val ui = BottomsheetErrorBinding.inflate(inflater, container, false)
     46         val args = requireArguments()
     47         val mainText = args.getString("TEXT_MAIN")
     48         val detailText = args.getString("TEXT_DETAIL")
     49         ui.mainText.text = mainText
     50         ui.closeButton.setOnClickListener { dismiss() }
     51         ui.detailText.text = detailText
     52         ui.shareButton.setOnClickListener {
     53             val sendIntent: Intent = Intent().apply {
     54                 action = Intent.ACTION_SEND
     55                 putExtra(Intent.EXTRA_TEXT, "$mainText\n\n$detailText")
     56                 type = "text/plain"
     57             }
     58             val shareIntent = Intent.createChooser(sendIntent, null)
     59             startActivity(shareIntent)
     60         }
     61         return ui.root
     62     }
     63 
     64 }