From c55d72c2c4f347cc615c8513f2b0c582718dfea6 Mon Sep 17 00:00:00 2001 From: guoshuyu <359369982@qq.com> Date: Fri, 9 Nov 2018 15:25:12 +0800 Subject: [PATCH] prepare 1.0.0 --- app/build.gradle | 3 ++ app/src/main/AndroidManifest.xml | 1 + .../github/kotlin/GSYGithubApplication.kt | 6 +++ .../github/kotlin/common/utils/ExpandUtils.kt | 36 +++++++++++++ .../github/kotlin/module/main/MainActivity.kt | 7 ++- .../module/main/MainDrawerController.kt | 54 +++++++++++++++++-- .../kotlin/repository/ReposRepository.kt | 42 +++++++++++++-- .../github/kotlin/service/RepoService.kt | 3 +- build.gradle | 1 + 9 files changed, 142 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d01badf..eb028ba 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -194,4 +194,7 @@ dependencies { ///lottie implementation "com.airbnb.android:lottie:${lottie_version}" + + ///bugly + implementation "com.tencent.bugly:crashreport:${bugly_version}" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f786467..29e03f6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,7 @@ + .toSplitString(): String { var result = "" @@ -61,4 +67,34 @@ fun ArrayList.toSplitString(): String { result = "$result/$it" } return result +} + +fun String.compareVersion(v2: String?): String? { + if (v2 == null || v2.isEmpty()) return null + val regEx = "[^0-9]" + val p = Pattern.compile(regEx) + var s1: String = p.matcher(this).replaceAll("").trim() + var s2: String = p.matcher(v2).replaceAll("").trim() + + val cha: Int = s1.length - s2.length + val buffer = StringBuffer() + var i = 0 + while (i < Math.abs(cha)) { + buffer.append("0") + ++i + } + + if (cha > 0) { + buffer.insert(0, s2) + s2 = buffer.toString() + } else if (cha < 0) { + buffer.insert(0, s1) + s1 = buffer.toString() + } + + val s1Int = s1.toInt() + val s2Int = s2.toInt() + + return if (s1Int > s2Int) this + else v2 } \ No newline at end of file diff --git a/app/src/main/java/com/shuyu/github/kotlin/module/main/MainActivity.kt b/app/src/main/java/com/shuyu/github/kotlin/module/main/MainActivity.kt index c127440..e06ad32 100644 --- a/app/src/main/java/com/shuyu/github/kotlin/module/main/MainActivity.kt +++ b/app/src/main/java/com/shuyu/github/kotlin/module/main/MainActivity.kt @@ -14,6 +14,7 @@ import com.shuyu.github.kotlin.module.dynamic.DynamicFragment import com.shuyu.github.kotlin.module.search.SearchActivity import com.shuyu.github.kotlin.repository.IssueRepository import com.shuyu.github.kotlin.repository.LoginRepository +import com.shuyu.github.kotlin.repository.ReposRepository import com.shuyu.github.kotlin.ui.adapter.FragmentPagerViewAdapter import com.shuyu.github.kotlin.ui.view.GSYNavigationTabBar import dagger.android.DispatchingAndroidInjector @@ -51,6 +52,10 @@ class MainActivity : AppCompatActivity(), HasSupportFragmentInjector, Toolbar.On lateinit var loginRepository: LoginRepository + @Inject + lateinit var repositoryRepository: ReposRepository + + @Inject lateinit var issueRepository: IssueRepository @@ -65,7 +70,7 @@ class MainActivity : AppCompatActivity(), HasSupportFragmentInjector, Toolbar.On initToolbar() - MainDrawerController(this, home_tool_bar, loginRepository, issueRepository, globalModel) + MainDrawerController(this, home_tool_bar, loginRepository, issueRepository, repositoryRepository, globalModel) } diff --git a/app/src/main/java/com/shuyu/github/kotlin/module/main/MainDrawerController.kt b/app/src/main/java/com/shuyu/github/kotlin/module/main/MainDrawerController.kt index 2aef37f..499b2e2 100644 --- a/app/src/main/java/com/shuyu/github/kotlin/module/main/MainDrawerController.kt +++ b/app/src/main/java/com/shuyu/github/kotlin/module/main/MainDrawerController.kt @@ -1,5 +1,7 @@ package com.shuyu.github.kotlin.module.main +import android.app.Activity +import android.content.Context import android.support.v7.widget.Toolbar import androidx.core.net.toUri import com.mikepenz.materialdrawer.AccountHeaderBuilder @@ -10,13 +12,17 @@ import com.mikepenz.materialdrawer.model.ProfileDrawerItem import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem import com.orhanobut.dialogplus.DialogPlus import com.shuyu.github.kotlin.R +import com.shuyu.github.kotlin.common.net.ResultCallBack import com.shuyu.github.kotlin.common.utils.IssueDialogClickListener +import com.shuyu.github.kotlin.common.utils.getVersionName import com.shuyu.github.kotlin.common.utils.showIssueEditDialog import com.shuyu.github.kotlin.model.AppGlobalModel import com.shuyu.github.kotlin.model.bean.Issue +import com.shuyu.github.kotlin.model.bean.Release import com.shuyu.github.kotlin.repository.IssueRepository import com.shuyu.github.kotlin.repository.LoginRepository -import org.jetbrains.anko.alert +import com.shuyu.github.kotlin.repository.ReposRepository +import org.jetbrains.anko.* /** * Created by guoshuyu @@ -24,9 +30,10 @@ import org.jetbrains.anko.alert */ -class MainDrawerController(private val activity: MainActivity, toolbar: Toolbar, +class MainDrawerController(private val activity: Activity, toolbar: Toolbar, loginRepository: LoginRepository, private val issueRepository: IssueRepository, + private val reposRepository: ReposRepository, globalModel: AppGlobalModel) { var drawer: Drawer? = null @@ -44,6 +51,14 @@ class MainDrawerController(private val activity: MainActivity, toolbar: Toolbar, true } ) + .addDrawerItems( + PrimaryDrawerItem().withName(R.string.update) + .withTextColorRes(R.color.colorPrimary).withOnDrawerItemClickListener { view, position, drawerItem -> + checkUpdate(true) + unSelect(drawerItem) + true + } + ) .addDrawerItems( PrimaryDrawerItem().withName(R.string.about) .withTextColorRes(R.color.colorPrimary).withOnDrawerItemClickListener { view, position, drawerItem -> @@ -68,6 +83,9 @@ class MainDrawerController(private val activity: MainActivity, toolbar: Toolbar, .withHeaderBackground(R.color.colorPrimary) .withSelectionListEnabled(false) .build()).build() + + + checkUpdate(false) } @@ -85,11 +103,9 @@ class MainDrawerController(private val activity: MainActivity, toolbar: Toolbar, } private fun showAboutDialog() { - val manager = activity.packageManager.getPackageInfo(activity.packageName, 0) - activity.alert { this.title = activity.getString(R.string.app_name) - this.message = activity.getString(R.string.version) + " : " + manager.versionName + this.message = activity.getVersionName() this.show() } } @@ -98,4 +114,32 @@ class MainDrawerController(private val activity: MainActivity, toolbar: Toolbar, drawerItem.withSetSelected(false) drawer?.adapter?.notifyAdapterDataSetChanged() } + + private fun checkUpdate(needTip: Boolean = false) { + reposRepository.checkoutUpDate(activity, object : ResultCallBack { + override fun onSuccess(result: Release?) { + result?.name?.apply { + showUpdateDialog(activity, this, result.body ?: "", "www.baidu.com") + return + } + if (needTip) { + activity.toast(R.string.newestVersion) + } + } + }) + } + + private fun showUpdateDialog(context: Context, version: String, message: String, url: String) { + activity.alert { + this.title = activity.getString(R.string.app_name) + this.message = "$version: \n$message" + this.cancelButton { + it.dismiss() + } + this.okButton { + context.browse(url) + } + this.show() + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/shuyu/github/kotlin/repository/ReposRepository.kt b/app/src/main/java/com/shuyu/github/kotlin/repository/ReposRepository.kt index 717b6c2..f1127f3 100644 --- a/app/src/main/java/com/shuyu/github/kotlin/repository/ReposRepository.kt +++ b/app/src/main/java/com/shuyu/github/kotlin/repository/ReposRepository.kt @@ -6,10 +6,9 @@ import android.content.Context import com.shuyu.github.kotlin.R import com.shuyu.github.kotlin.common.net.* import com.shuyu.github.kotlin.common.utils.HtmlUtils -import com.shuyu.github.kotlin.model.bean.Event -import com.shuyu.github.kotlin.model.bean.Issue -import com.shuyu.github.kotlin.model.bean.Repository -import com.shuyu.github.kotlin.model.bean.SearchResult +import com.shuyu.github.kotlin.common.utils.compareVersion +import com.shuyu.github.kotlin.common.utils.getVersionName +import com.shuyu.github.kotlin.model.bean.* import com.shuyu.github.kotlin.model.conversion.EventConversion import com.shuyu.github.kotlin.model.conversion.IssueConversion import com.shuyu.github.kotlin.model.conversion.ReposConversion @@ -34,6 +33,41 @@ class ReposRepository @Inject constructor(private val retrofit: Retrofit, privat const val WATCH_KEY = "watched" } + fun checkoutUpDate(context: Context, resultCallBack: ResultCallBack?) { + val service = retrofit.create(RepoService::class.java) + .getReleases(true, "CarGuo", "GSYGithubAppKotlin", 1) + .flatMap { + FlatMapResponse2Result(it) + }.map { + if (it.size > 0) { + val item = it[0] + val versionName = item.name + versionName?.apply { + val currentName = context.getVersionName() + val hadNew = currentName.compareVersion(versionName) != currentName + if (hadNew) { + return@map item + } + } + Release() + } else { + Release() + } + }.flatMap { + FlatMapResult2Response(it) + } + + RetrofitFactory.executeResult(service, object : ResultTipObserver(application) { + override fun onSuccess(result: Release?) { + resultCallBack?.onSuccess(result) + } + + override fun onFailure(e: Throwable, isNetWorkError: Boolean) { + resultCallBack?.onFailure() + } + }) + } + /** * 趋势 */ diff --git a/app/src/main/java/com/shuyu/github/kotlin/service/RepoService.kt b/app/src/main/java/com/shuyu/github/kotlin/service/RepoService.kt index 7c47eb1..813fe93 100644 --- a/app/src/main/java/com/shuyu/github/kotlin/service/RepoService.kt +++ b/app/src/main/java/com/shuyu/github/kotlin/service/RepoService.kt @@ -177,7 +177,8 @@ interface RepoService { @Header("forceNetWork") forceNetWork: Boolean, @Path("owner") owner: String, @Path("repo") repo: String, - @Query("page") page: Int + @Query("page") page: Int, + @Query("per_page") per_page: Int = AppConfig.PAGE_SIZE ): Observable>> @GET("repos/{owner}/{repo}/releases/tags/{tag}") diff --git a/build.gradle b/build.gradle index 3e25ba2..e953c7f 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,7 @@ buildscript { ext.prism4j_version='1.1.0' ext.dialogplus_version='1.11@aar' ext.lottie_version='2.7.0' + ext.bugly_version='2.1.1' repositories { google()