pull/2723/head
			
			
		
		
							parent
							
								
									1a9a5770fe
								
							
						
					
					
						commit
						542a116afd
					
				| @ -0,0 +1,46 @@ | ||||
| package io.legado.app.help | ||||
| 
 | ||||
| import io.legado.app.R | ||||
| import io.legado.app.constant.AppConst | ||||
| import io.legado.app.exception.NoStackTraceException | ||||
| import io.legado.app.help.coroutine.Coroutine | ||||
| import io.legado.app.help.http.newCallStrResponse | ||||
| import io.legado.app.help.http.okHttpClient | ||||
| import io.legado.app.utils.jsonPath | ||||
| import io.legado.app.utils.readString | ||||
| import kotlinx.coroutines.CoroutineScope | ||||
| import splitties.init.appCtx | ||||
| 
 | ||||
| @Suppress("unused") | ||||
| object AppUpdateGitHub: AppUpdate.AppUpdateInterface { | ||||
| 
 | ||||
|     override fun check( | ||||
|         scope: CoroutineScope, | ||||
|     ): Coroutine<AppUpdate.UpdateInfo> { | ||||
|         return Coroutine.async(scope) { | ||||
|             val lastReleaseUrl = appCtx.getString(R.string.latest_release_api) | ||||
|             val body = okHttpClient.newCallStrResponse { | ||||
|                 url(lastReleaseUrl) | ||||
|             }.body | ||||
|             if (body.isNullOrBlank()) { | ||||
|                 throw NoStackTraceException("获取新版本出错") | ||||
|             } | ||||
|             val rootDoc = jsonPath.parse(body) | ||||
|             val tagName = rootDoc.readString("$.tag_name") | ||||
|                 ?: throw NoStackTraceException("获取新版本出错") | ||||
|             if (tagName > AppConst.appInfo.versionName) { | ||||
|                 val updateBody = rootDoc.readString("$.body") | ||||
|                     ?: throw NoStackTraceException("获取新版本出错") | ||||
|                 val downloadUrl = rootDoc.readString("$.assets[0].browser_download_url") | ||||
|                     ?: throw NoStackTraceException("获取新版本出错") | ||||
|                 val fileName = rootDoc.readString("$.assets[0].name") | ||||
|                     ?: throw NoStackTraceException("获取新版本出错") | ||||
|                 return@async AppUpdate.UpdateInfo(tagName, updateBody, downloadUrl, fileName) | ||||
|             } else { | ||||
|                 throw NoStackTraceException("已是最新版本") | ||||
|             } | ||||
|         }.timeout(10000) | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,114 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto"> | ||||
| 
 | ||||
|     <io.legado.app.lib.prefs.Preference | ||||
|         android:key="contributors" | ||||
|         android:summary="@string/contributors_summary" | ||||
|         android:title="@string/contributors" | ||||
|         app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|     <io.legado.app.lib.prefs.Preference | ||||
|         android:key="update_log" | ||||
|         android:title="@string/update_log" | ||||
|         app:allowDividerAbove="false" | ||||
|         app:allowDividerBelow="false" | ||||
|         app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|     <io.legado.app.lib.prefs.Preference | ||||
|         android:key="check_update" | ||||
|         android:title="@string/check_update" | ||||
|         app:allowDividerAbove="false" | ||||
|         app:allowDividerBelow="false" | ||||
|         app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|     <io.legado.app.lib.prefs.PreferenceCategory | ||||
|         android:title="@string/contact" | ||||
|         app:allowDividerAbove="true" | ||||
|         app:allowDividerBelow="false" | ||||
|         app:iconSpaceReserved="false" | ||||
|         app:layout="@layout/view_preference_category"> | ||||
| 
 | ||||
|         <io.legado.app.lib.prefs.Preference | ||||
|             android:key="gzGzh" | ||||
|             android:summary="@string/official_account" | ||||
|             android:title="@string/follow_official_account" | ||||
|             app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|         <io.legado.app.lib.prefs.Preference | ||||
|             android:key="qqChannel" | ||||
|             android:title="@string/join_qq_channel" | ||||
|             android:summary="@string/qq_channel_summary" | ||||
|             app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|         <io.legado.app.lib.prefs.Preference | ||||
|             android:key="qq" | ||||
|             android:summary="@string/click_to_apply" | ||||
|             android:title="@string/join_qq_group" | ||||
|             app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|         <io.legado.app.lib.prefs.Preference | ||||
|             android:key="mail" | ||||
|             android:summary="@string/email" | ||||
|             android:title="@string/send_mail" | ||||
|             app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|         <io.legado.app.lib.prefs.Preference | ||||
|             android:key="git" | ||||
|             android:summary="@string/this_github_url" | ||||
|             android:title="@string/git_hub" | ||||
|             app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|         <io.legado.app.lib.prefs.Preference | ||||
|             android:key="discord" | ||||
|             android:summary="@string/discord_url" | ||||
|             android:title="Discord" | ||||
|             app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|         <io.legado.app.lib.prefs.Preference | ||||
|             android:key="tg" | ||||
|             android:summary="@string/tg_url" | ||||
|             android:title="TG" | ||||
|             app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|         <io.legado.app.lib.prefs.Preference | ||||
|             android:key="sourceRuleSummary" | ||||
|             android:summary="@string/source_rule_url" | ||||
|             android:title="@string/source_rule_s" | ||||
|             app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|         <io.legado.app.lib.prefs.Preference | ||||
|             android:key="home_page" | ||||
|             android:summary="@string/home_page_url" | ||||
|             android:title="@string/home_page" | ||||
|             app:allowDividerAbove="false" | ||||
|             app:allowDividerBelow="false" | ||||
|             app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|     </io.legado.app.lib.prefs.PreferenceCategory> | ||||
| 
 | ||||
|     <io.legado.app.lib.prefs.PreferenceCategory | ||||
|         android:title="@string/other" | ||||
|         app:allowDividerAbove="true" | ||||
|         app:allowDividerBelow="false" | ||||
|         app:iconSpaceReserved="false" | ||||
|         app:layout="@layout/view_preference_category"> | ||||
| 
 | ||||
|         <io.legado.app.lib.prefs.Preference | ||||
|             android:key="crashLog" | ||||
|             android:title="@string/crash_log" | ||||
|             app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|         <io.legado.app.lib.prefs.Preference | ||||
|             android:key="license" | ||||
|             android:title="@string/license" | ||||
|             app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|         <io.legado.app.lib.prefs.Preference | ||||
|             android:key="disclaimer" | ||||
|             android:title="@string/disclaimer" | ||||
|             app:iconSpaceReserved="false" /> | ||||
| 
 | ||||
|     </io.legado.app.lib.prefs.PreferenceCategory> | ||||
| 
 | ||||
| </androidx.preference.PreferenceScreen> | ||||
					Loading…
					
					
				
		Reference in new issue