diff --git a/app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt b/app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt index 60404b266..ae477acd6 100644 --- a/app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt +++ b/app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt @@ -24,10 +24,8 @@ import android.content.DialogInterface import android.graphics.drawable.Drawable import android.view.KeyEvent import android.view.View -import android.view.ViewManager import androidx.annotation.DrawableRes import androidx.annotation.StringRes -import org.jetbrains.anko.UI import org.jetbrains.anko.internals.AnkoInternals.NO_GETTER import kotlin.DeprecationLevel.ERROR diff --git a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt index 5c35f51c0..739be8c72 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt @@ -1,5 +1,8 @@ package io.legado.app.ui.about +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle @@ -9,6 +12,7 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R +import io.legado.app.lib.dialogs.alert import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.toast @@ -16,11 +20,17 @@ class AboutFragment : PreferenceFragmentCompat() { private val licenseUrl = "https://github.com/gedoor/legado/blob/master/LICENSE" private val disclaimerUrl = "https://gedoor.github.io/MyBookshelf/disclaimer.html" + private val qqGroups = linkedMapOf( + Pair("(QQ群)701903217", "-iolizL4cbJSutKRpeImHlXlpLDZnzeF"), + Pair("(QQ群)805192012", "6GlFKjLeIk5RhQnR3PNVDaKB6j10royo"), + Pair("(QQ群)773736122", "5Bm5w6OgLupXnICbYvbgzpPUgf0UlsJF"), + Pair("(QQ群)981838750", "g_Sgmp2nQPKqcZQ5qPcKLHziwX_mpps9") + ) override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.about) findPreference("check_update")?.summary = - getString(R.string.version) + " " + App.INSTANCE.versionName + "${getString(R.string.version)} ${App.INSTANCE.versionName}" } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -38,6 +48,7 @@ class AboutFragment : PreferenceFragmentCompat() { "home_page" -> openIntent(Intent.ACTION_VIEW, R.string.home_page_url) "license" -> openIntent(Intent.ACTION_VIEW, licenseUrl) "disclaimer" -> openIntent(Intent.ACTION_VIEW, disclaimerUrl) + "qq" -> showQqGroups() } return super.onPreferenceTreeClick(preference) } @@ -62,4 +73,42 @@ class AboutFragment : PreferenceFragmentCompat() { TextDialog.show(childFragmentManager, log, TextDialog.MD) } + private fun showQqGroups() { + alert(title = R.string.join_qq_group) { + val names = arrayListOf() + qqGroups.forEach { + names.add(it.key) + } + items(names) { _, index -> + qqGroups[names[index]]?.let { + if (!joinQQGroup(it)) { + sendToClip(it) + } + } + } + }.show() + } + + private fun joinQQGroup(key: String): Boolean { + val intent = Intent() + intent.data = + Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D$key") + // 此Flag可根据具体产品需要自定义,如设置,则在加群界面按返回,返回手Q主界面,不设置,按返回会返回到呼起产品界面 //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + return try { + startActivity(intent) + false + } catch (e: java.lang.Exception) { + true + } + } + + private fun sendToClip(text: String) { + val clipboard = + requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager + val clipData = ClipData.newPlainText(null, text) + clipboard?.let { + clipboard.setPrimaryClip(clipData) + toast(R.string.copy_complete) + } + } } \ No newline at end of file