Warning, /network/kdeconnect-android/src/org/kde/kdeconnect/UserInterface/About/AboutFragment.kt is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2021 Maxim Leshchenko <cnmaks90@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 package org.kde.kdeconnect.UserInterface.About
0008 
0009 import android.annotation.SuppressLint
0010 import android.content.Intent
0011 import android.net.Uri
0012 import android.os.Bundle
0013 import android.view.LayoutInflater
0014 import android.view.View
0015 import android.view.ViewGroup
0016 import android.widget.FrameLayout
0017 import androidx.core.content.ContextCompat
0018 import androidx.fragment.app.Fragment
0019 import org.kde.kdeconnect.UserInterface.List.ListAdapter
0020 import org.kde.kdeconnect.UserInterface.MainActivity
0021 import org.kde.kdeconnect_tp.R
0022 import org.kde.kdeconnect_tp.databinding.FragmentAboutBinding
0023 
0024 class AboutFragment : Fragment() {
0025     private var binding: FragmentAboutBinding? = null
0026     private lateinit var aboutData: AboutData
0027     private var tapCount = 0
0028     private var firstTapMillis: Long? = null
0029 
0030     companion object {
0031         @JvmStatic
0032         fun newInstance(aboutData: AboutData): Fragment {
0033             val fragment = AboutFragment()
0034 
0035             val args = Bundle(1)
0036             args.putParcelable("ABOUT_DATA", aboutData)
0037             fragment.arguments = args
0038 
0039             return fragment
0040         }
0041     }
0042 
0043     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
0044         if (activity != null) {
0045             (requireActivity() as MainActivity).supportActionBar?.setTitle(R.string.about)
0046         }
0047 
0048         aboutData = requireArguments().getParcelable("ABOUT_DATA")!!
0049         binding = FragmentAboutBinding.inflate(inflater, container, false)
0050 
0051         updateData()
0052         return binding!!.root
0053     }
0054 
0055     @SuppressLint("SetTextI18n")
0056     fun updateData() {
0057         // Update general info
0058 
0059         binding!!.appName.text = aboutData.name
0060         binding!!.appIcon.setImageDrawable(this.context?.let { ContextCompat.getDrawable(it, aboutData.icon) })
0061         binding!!.appVersion.text = this.context?.getString(R.string.version, aboutData.versionName)
0062 
0063         // Setup Easter Egg onClickListener
0064 
0065         binding!!.generalInfoCard.setOnClickListener {
0066             if (firstTapMillis == null) {
0067                 firstTapMillis = System.currentTimeMillis()
0068             }
0069 
0070             if (++tapCount == 3) {
0071                 tapCount = 0
0072 
0073                 if (firstTapMillis!! >= (System.currentTimeMillis() - 500)) {
0074                     startActivity(Intent(context, EasterEggActivity::class.java))
0075                 }
0076 
0077                 firstTapMillis = null
0078             }
0079         }
0080 
0081         // Update button onClickListeners
0082 
0083         setupInfoButton(aboutData.bugURL, binding!!.reportBugButton)
0084         setupInfoButton(aboutData.donateURL, binding!!.donateButton)
0085         setupInfoButton(aboutData.sourceCodeURL, binding!!.sourceCodeButton)
0086 
0087         binding!!.licensesButton.setOnClickListener {
0088             startActivity(Intent(context, LicensesActivity::class.java))
0089         }
0090 
0091         binding!!.aboutKdeButton.setOnClickListener {
0092             startActivity(Intent(context, AboutKDEActivity::class.java))
0093         }
0094 
0095         setupInfoButton(aboutData.websiteURL, binding!!.websiteButton)
0096 
0097         // Update authors
0098         binding!!.authorsList.adapter = ListAdapter(this.context, aboutData.authors.map { AboutPersonEntryItem(it) }, false)
0099         if (aboutData.authorsFooterText != null) {
0100             binding!!.authorsFooterText.text = context?.getString(aboutData.authorsFooterText!!)
0101         }
0102     }
0103 
0104     private fun setupInfoButton(url: String?, button: FrameLayout) {
0105         if (url == null) {
0106             button.visibility = View.GONE
0107         } else {
0108             button.setOnClickListener {
0109                 startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
0110             }
0111         }
0112     }
0113 
0114     override fun onDestroyView() {
0115         super.onDestroyView()
0116         binding = null
0117     }
0118 }