From 718f31c92e2029d05260810435a2c70cef6e6ce5 Mon Sep 17 00:00:00 2001
From: lmw <125975490@qq.com>
Date: 星期四, 24 四月 2025 10:45:55 +0800
Subject: [PATCH] save

---
 app/src/main/java/com/sinata/xqmuse/ui/mine/SettingActivity.kt |   84 +++++++++++++++++++++++++++++++++--------
 1 files changed, 67 insertions(+), 17 deletions(-)

diff --git a/app/src/main/java/com/sinata/xqmuse/ui/mine/SettingActivity.kt b/app/src/main/java/com/sinata/xqmuse/ui/mine/SettingActivity.kt
index ee08c6c..2179fee 100644
--- a/app/src/main/java/com/sinata/xqmuse/ui/mine/SettingActivity.kt
+++ b/app/src/main/java/com/sinata/xqmuse/ui/mine/SettingActivity.kt
@@ -1,7 +1,10 @@
 package com.sinata.xqmuse.ui.mine
 
+import android.content.Context
 import cn.sinata.xldutils.gone
 import cn.sinata.xldutils.utils.SPUtils
+import cn.sinata.xldutils.utils.SpanBuilder
+import cn.sinata.xldutils.visible
 import com.sinata.xqmuse.MainActivity
 import com.sinata.xqmuse.R
 import com.sinata.xqmuse.dialog.LoginRuleDialog
@@ -14,10 +17,12 @@
 import com.sinata.xqmuse.ui.login.LoginActivity
 import com.sinata.xqmuse.utils.CacheCleanUtil
 import com.sinata.xqmuse.utils.Const
+import com.sinata.xqmuse.utils.download.DownloadUtil
 import com.sinata.xqmuse.utils.event.EmptyEvent
 import com.sinata.xqmuse.utils.extention.clickDelay
 import kotlinx.android.synthetic.main.activity_setting.*
 import org.greenrobot.eventbus.EventBus
+import org.jetbrains.anko.browse
 import org.jetbrains.anko.bundleOf
 import org.jetbrains.anko.startActivity
 import org.jetbrains.anko.toast
@@ -25,6 +30,7 @@
 class SettingActivity : TransparentStatusBarActivity() {
     override fun setContentView() = R.layout.activity_setting
     private var data : MineInfo? = null
+    private var isPush = true //个性推荐
 
     override fun initClick() {
         iv_back.setOnClickListener { finish() }
@@ -38,31 +44,26 @@
         }
 
         tv_clear.setOnClickListener {
-            val tipDialog = TipDialog()
-            tipDialog.arguments = bundleOf("msg" to "是否清除应用缓存?")
-            tipDialog.setCallback(object : TipDialog.OnClickCallback {
-                override fun onOk() {
-                    CacheCleanUtil.clearAllCache(this@SettingActivity)
-                    toast("清理成功")
-                }
-
-                override fun onCancel() {
-                }
-            })
-            tipDialog.show(supportFragmentManager, "tip")
+            CacheCleanUtil.clearAllCache(this@SettingActivity)
+            toast("清理成功")
         }
 
         tv_logout.setOnClickListener {
-            SPUtils.instance().put(Const.User.TOKEN,"").apply()
-            EventBus.getDefault().post(EmptyEvent(Const.EventCode.SWITCH_HOME))
+            SPUtils.instance().put(Const.User.TOKEN, "").apply()
+            EventBus.getDefault().post(EmptyEvent(Const.EventCode.CHANGE_USER))
             startActivity<MainActivity>()
+            startActivity<LoginActivity>()
         }
 
         tv_switch.setOnClickListener {
-            SPUtils.instance().put(Const.User.TOKEN,"").apply()
-            EventBus.getDefault().post(EmptyEvent(Const.EventCode.SWITCH_HOME))
             startActivity<MainActivity>()
             startActivity<LoginActivity>()
+        }
+
+        iv_push.setOnClickListener {
+            isPush = !isPush
+            iv_push.setImageResource(if (isPush) R.mipmap.sw_on else R.mipmap.sw_off)
+            SPUtils.instance().put(Const.IS_PUSH,isPush).apply()
         }
 
         tv_rule.setOnClickListener {
@@ -72,16 +73,65 @@
         tv_about.setOnClickListener {
             HttpManager.getH5(LoginRuleDialog.TYPE_ABOUT).request(this){ _, data->
                 data?.let {
-                    startActivity<H5Activity>("title" to "关于心泉","url" to it.content,"showClose" to false)
+                    startActivity<H5Activity>(
+                        "title" to "关于泉疗愈",
+                        "url" to it.content,
+                        "showClose" to false
+                    )
                 }
             }
         }
 
+        tv_update.clickDelay {
+            showDialog()
+            HttpManager.detailVersion().request(this){_,data->
+                if (data?.versionNo.isNullOrEmpty()||data!!.versionNo <= getAppVersion(this@SettingActivity)?:"")
+                    toast("已经是最新版本")
+                else
+                    TipDialog.show(supportFragmentManager,data.remark,object :TipDialog.OnClickCallback{
+                        override fun onOk() {
+//                            DownloadUtil(this@SettingActivity).downloadAPK(data.androidFile, "泉疗愈")
+//                            toast("后台开始下载,请等待")
+                            browse(data.androidFile)
+                        }
+
+                        override fun onCancel() {
+                        }
+                    },"立即更新","下次再说",false,"有新版本啦!")
+            }
+        }
     }
 
     override fun initView() {
         titleBar.gone()
         data = intent.getParcelableExtra("data")
+        tv_update.text = SpanBuilder("版本更新  当前版本:"+getAppVersion(this)).size(0,4,14).build()
+        isPush = SPUtils.instance().getBoolean(Const.IS_PUSH,true)
+        iv_push.setImageResource(if (isPush) R.mipmap.sw_on else R.mipmap.sw_off)
+        checkVirsion()
     }
 
+    private fun checkVirsion() {
+        HttpManager.detailVersion().request(this){_,data->
+            if (data?.versionNo.isNullOrEmpty()||data!!.versionNo <= getAppVersion(this@SettingActivity)?:"")
+            else
+                tv_new.visible()
+        }
+    }
+
+
+    /**
+     * 获取版本号
+     * @return 当前应用的版本号
+     */
+    private fun getAppVersion(context: Context): String? {
+        return try {
+            val manager = context.packageManager
+            val info = manager.getPackageInfo(context.packageName, 0)
+            info.versionName
+        } catch (e: Exception) {
+            e.printStackTrace()
+            "null"
+        }
+    }
 }

--
Gitblit v1.7.1