diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6217051f66..250a14882d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,6 +3,9 @@ xmlns:tools="http://schemas.android.com/tools" package="me.iacn.biliroaming"> + + + { private var runningStatusPref: Preference? = null - private var counter: Int = 0; + private var counter: Int = 0 private var prefs: SharedPreferences? = null private var toast: Toast? = null @@ -55,6 +61,7 @@ class MainActivity : Activity() { findPreference("version").onPreferenceClickListener = this findPreference("author").onPreferenceClickListener = this findPreference("test_cdn").onPreferenceClickListener = this + CheckVersionTask(this).execute(URL(resources.getString(R.string.version_url))) } override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean { @@ -115,35 +122,68 @@ class MainActivity : Activity() { if (counter == 7) { preferenceScreen.removeAll() addPreferencesFromResource(R.xml.prefs_setting) - prefs?.edit()?.putBoolean("hidden", true)?.commit() + prefs?.edit()?.putBoolean("hidden", true)?.apply() toast?.setText("已开启隐藏功能") - toast?.duration = LENGTH_SHORT; - toast?.show(); + toast?.duration = LENGTH_SHORT + toast?.show() preferenceScreen.removeAll() onCreate() onResume() } else if (counter >= 4) { toast?.let { - it.setText(text); - it.duration = LENGTH_SHORT; - it.show(); + it.setText(text) + it.duration = LENGTH_SHORT + it.show() } ?: run { toast = Toast.makeText(activity, text, LENGTH_SHORT) + toast?.setText(text) toast?.show() } } return true } + override fun onReturn(result: JSONObject?) { + try { + result?.getString("name")?.let { + if (BuildConfig.VERSION_NAME != it) { + findPreference("version").summary = "${BuildConfig.VERSION_NAME}(最新版${it})" + val aboutGroup = findPreference("about") as PreferenceCategory + val updatePreference = Preference(activity) + updatePreference.key = "update" + updatePreference.title = resources.getString(R.string.update_title) + var log = "" + try { + val body = result.getString("body") + log = body.substring(body.lastIndexOf("更新日志")) + }catch(e : Throwable){} + updatePreference.summary = if(log.isNotEmpty()) log else resources.getString(R.string.update_summary) + updatePreference.onPreferenceClickListener=this + updatePreference.order=1 + aboutGroup.addPreference(updatePreference) + + } + } + } catch (e: Throwable) { + } + } + private fun onAuthorClick(): Boolean { - val uri = Uri.parse("https://github.com/yujincheng08/BiliRoaming") + val uri = Uri.parse(resources.getString(R.string.github_url)) val intent = Intent(Intent.ACTION_VIEW, uri) startActivity(intent) return true } private fun onTestCDNClick(): Boolean { - val uri = Uri.parse("https://yujincheng08.github.io/BiliRoaming/cdn_test.html") + val uri = Uri.parse(resources.getString(R.string.cdn_url)) + val intent = Intent(Intent.ACTION_VIEW, uri) + startActivity(intent) + return true + } + + private fun onUpdateCheck(): Boolean { + val uri = Uri.parse(resources.getString(R.string.update_url)) val intent = Intent(Intent.ACTION_VIEW, uri) startActivity(intent) return true @@ -154,13 +194,13 @@ class MainActivity : Activity() { "version" -> onVersionClick() "author" -> onAuthorClick() "test_cdn" -> onTestCDNClick() + "update" -> onUpdateCheck() else -> false } } } companion object { - @android.support.annotation.Keep fun isModuleActive(): Boolean { Log.i("大不自多", "海纳江河") @@ -178,4 +218,5 @@ class MainActivity : Activity() { } } } + } \ No newline at end of file diff --git a/app/src/main/java/me/iacn/biliroaming/utils/VersionCheck.kt b/app/src/main/java/me/iacn/biliroaming/utils/VersionCheck.kt new file mode 100644 index 0000000000..905b5c11ad --- /dev/null +++ b/app/src/main/java/me/iacn/biliroaming/utils/VersionCheck.kt @@ -0,0 +1,24 @@ +package me.iacn.biliroaming.utils + +import android.os.AsyncTask +import org.json.JSONObject +import java.net.URL + +interface OnTaskReturn { + fun onReturn(result: T?) +} + +class CheckVersionTask(private val onResult: OnTaskReturn) : AsyncTask() { + override fun doInBackground(vararg url: URL?): JSONObject? { + return try { + JSONObject(url[0]?.readText()!!) + } catch (e: Throwable) { + null + } + } + + override fun onPostExecute(result: JSONObject?) { + onResult.onReturn(result) + } + +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 872bf0bd55..7c2551d1c8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -50,4 +50,10 @@ 设置 去你大爷的小程序 不再以小程序的方式分享到QQ或者微信(同时复制分享链接变为av号) + https://api.github.com/repos/yujincheng08/BiliRoaming/releases/latest + 更新 + 点击打开最新版下载地址 + https://github.com/yujincheng08/BiliRoaming/releases/latest + https://github.com/yujincheng08/BiliRoaming + https://yujincheng08.github.io/BiliRoaming/cdn_test.html \ No newline at end of file diff --git a/app/src/main/res/xml/prefs_setting.xml b/app/src/main/res/xml/prefs_setting.xml index 70077d4fc9..d6815c9b8f 100644 --- a/app/src/main/res/xml/prefs_setting.xml +++ b/app/src/main/res/xml/prefs_setting.xml @@ -112,7 +112,7 @@ android:title="@string/purify_drawer_title" /> - +