diff --git a/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt b/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt
index 19e950ec8..c29d47fcb 100644
--- a/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt
+++ b/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt
@@ -1,20 +1,9 @@
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
-import android.widget.Toast
import io.legado.app.R
import io.legado.app.base.BaseActivity
-import io.legado.app.lib.theme.ATH
-import io.legado.app.utils.ACache
-import kotlinx.android.synthetic.main.activity_donate.*
-import org.jetbrains.anko.toast
-import java.net.URLEncoder
/**
* Created by GKF on 2018/1/13.
@@ -24,68 +13,12 @@ import java.net.URLEncoder
class DonateActivity : BaseActivity(R.layout.activity_donate) {
override fun onActivityCreated(savedInstanceState: Bundle?) {
- ATH.applyEdgeEffectColor(scroll_view)
- vw_zfb_tz.setOnClickListener { aliDonate(this) }
- cv_wx_gzh.setOnClickListener {
- val clipboard = this.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
- val clipData = ClipData.newPlainText(null, "开源阅读软件")
- clipboard?.let {
- clipboard.setPrimaryClip(clipData)
- toast(R.string.copy_complete)
- }
- }
- vw_zfb_hb.setOnClickListener { openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/zfbhbrwm.png") }
- vw_zfb_rwm.setOnClickListener { openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/zfbskrwm.jpg") }
- vw_wx_rwm.setOnClickListener { openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/wxskrwm.jpg") }
- vw_qq_rwm.setOnClickListener { openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/qqskrwm.jpg") }
- vw_zfb_hb_ssm.setOnClickListener { getZfbHb(this) }
+ val fTag = "donateFragment"
+ var donateFragment = supportFragmentManager.findFragmentByTag(fTag)
+ if (donateFragment == null) donateFragment = DonateFragment()
+ supportFragmentManager.beginTransaction()
+ .replace(R.id.fl_fragment, donateFragment, fTag)
+ .commit()
}
- private fun getZfbHb(context: Context) {
- val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
- val clipData = ClipData.newPlainText(null, "537954522")
- clipboard?.let {
- clipboard.setPrimaryClip(clipData)
- Toast.makeText(context, "高级功能已开启\n红包码已复制\n支付宝首页搜索“537954522” 立即领红包", Toast.LENGTH_LONG)
- .show()
- }
- try {
- val packageManager = context.applicationContext.packageManager
- val intent = packageManager.getLaunchIntentForPackage("com.eg.android.AlipayGphone")!!
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- context.startActivity(intent)
- } catch (e: Exception) {
- e.printStackTrace()
- } finally {
- ACache.get(this, cacheDir = false).put("proTime", System.currentTimeMillis())
- }
- }
-
- private fun openActionViewIntent(address: String) {
- try {
- val intent = Intent(Intent.ACTION_VIEW)
- intent.data = Uri.parse(address)
- startActivity(intent)
- } catch (e: Exception) {
- e.printStackTrace()
- Toast.makeText(this, R.string.can_not_open, Toast.LENGTH_SHORT).show()
- }
-
- }
-
- private fun aliDonate(context: Context) {
- try {
- val qrCode = URLEncoder.encode(
- "https://qr.alipay.com/tsx06677nwdk3javroq4ef0?_s=Dweb-other",
- "utf-8"
- )
- val aliPayQr =
- "alipayqr://platformapi/startapp?saId=10000007&qrcode=$qrCode&_t=${System.currentTimeMillis()}"
- val intent = Intent(Intent.ACTION_VIEW, Uri.parse(aliPayQr))
- context.startActivity(intent)
- } catch (e: Exception) {
- e.printStackTrace()
- }
-
- }
}
diff --git a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt
new file mode 100644
index 000000000..a202946b6
--- /dev/null
+++ b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt
@@ -0,0 +1,99 @@
+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
+import android.view.View
+import androidx.preference.Preference
+import androidx.preference.PreferenceFragmentCompat
+import io.legado.app.R
+import io.legado.app.utils.ACache
+import io.legado.app.utils.toast
+import org.jetbrains.anko.longToast
+import java.net.URLEncoder
+
+class DonateFragment : PreferenceFragmentCompat() {
+
+ private val zfbHbRwmUrl = "https://gitee.com/gekunfei/Donate/raw/master/zfbhbrwm.png"
+ private val zfbSkRwmUrl = "https://gitee.com/gekunfei/Donate/raw/master/zfbskrwm.jpg"
+ private val wxZsRwmUrl = "https://gitee.com/gekunfei/Donate/raw/master/wxskrwm.jpg"
+ private val qqSkRwmUrl = "https://gitee.com/gekunfei/Donate/raw/master/qqskrwm.jpg"
+
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ addPreferencesFromResource(R.xml.donate)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ listView.overScrollMode = View.OVER_SCROLL_NEVER
+ }
+
+ override fun onPreferenceTreeClick(preference: Preference?): Boolean {
+ when (preference?.key) {
+ "wxZsm" -> openIntent(Intent.ACTION_VIEW, wxZsRwmUrl)
+ "zfbHbRwm" -> openIntent(Intent.ACTION_VIEW, zfbHbRwmUrl)
+ "zfbSkRwm" -> openIntent(Intent.ACTION_VIEW, zfbSkRwmUrl)
+ "qqSkRwm" -> openIntent(Intent.ACTION_VIEW, qqSkRwmUrl)
+ "zfbSk" -> aliDonate(requireContext())
+ "zfbHbSsm" -> getZfbHb(requireContext())
+ "gzGzh" -> sendToClip("开源阅读软件")
+ }
+ return super.onPreferenceTreeClick(preference)
+ }
+
+ @Suppress("SameParameterValue")
+ private fun openIntent(intentName: String, address: String) {
+ try {
+ val intent = Intent(intentName)
+ intent.data = Uri.parse(address)
+ startActivity(intent)
+ } catch (e: Exception) {
+ toast(R.string.can_not_open)
+ }
+ }
+
+ 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)
+ }
+ }
+
+ private fun getZfbHb(context: Context) {
+ sendToClip("537954522")
+ context.longToast("高级功能已开启\n红包码已复制\n支付宝首页搜索“537954522” 立即领红包")
+ try {
+ val packageManager = context.applicationContext.packageManager
+ val intent = packageManager.getLaunchIntentForPackage("com.eg.android.AlipayGphone")!!
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ context.startActivity(intent)
+ } catch (e: Exception) {
+ e.printStackTrace()
+ } finally {
+ ACache.get(requireContext(), cacheDir = false)
+ .put("proTime", System.currentTimeMillis())
+ }
+ }
+
+ private fun aliDonate(context: Context) {
+ try {
+ val qrCode = URLEncoder.encode(
+ "https://qr.alipay.com/tsx06677nwdk3javroq4ef0?_s=Dweb-other",
+ "utf-8"
+ )
+ val aliPayQr =
+ "alipayqr://platformapi/startapp?saId=10000007&qrcode=$qrCode&_t=${System.currentTimeMillis()}"
+ val intent = Intent(Intent.ACTION_VIEW, Uri.parse(aliPayQr))
+ context.startActivity(intent)
+ } catch (e: Exception) {
+ e.printStackTrace()
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_donate.xml b/app/src/main/res/layout/activity_donate.xml
index 0956dd71b..d401b7e12 100644
--- a/app/src/main/res/layout/activity_donate.xml
+++ b/app/src/main/res/layout/activity_donate.xml
@@ -1,7 +1,8 @@
@@ -12,227 +13,27 @@
android:layout_height="wrap_content"
app:title="@string/donate"/>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
diff --git a/app/src/main/res/xml/donate.xml b/app/src/main/res/xml/donate.xml
index 65a47daa7..555792b67 100644
--- a/app/src/main/res/xml/donate.xml
+++ b/app/src/main/res/xml/donate.xml
@@ -1,4 +1,65 @@
-
+
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file