Skip to content

Commit c55d72c

Browse files
committed
prepare 1.0.0
1 parent fb6f95f commit c55d72c

File tree

9 files changed

+142
-11
lines changed

9 files changed

+142
-11
lines changed

app/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,7 @@ dependencies {
194194
///lottie
195195
implementation "com.airbnb.android:lottie:${lottie_version}"
196196

197+
198+
///bugly
199+
implementation "com.tencent.bugly:crashreport:${bugly_version}"
197200
}

app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
88
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
99
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
10+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
1011

1112
<application
1213
android:name="GSYGithubApplication"

app/src/main/java/com/shuyu/github/kotlin/GSYGithubApplication.kt

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.shuyu.github.kotlin.common.utils.CommonUtils
1616
import com.shuyu.github.kotlin.di.AppInjector
1717
import com.shuyu.gsygiideloader.GSYGlideImageLoader
1818
import com.shuyu.gsyimageloader.GSYImageLoaderManager
19+
import com.tencent.bugly.crashreport.CrashReport
1920
import dagger.android.DispatchingAndroidInjector
2021
import dagger.android.HasActivityInjector
2122
import io.realm.Realm
@@ -62,6 +63,11 @@ class GSYGithubApplication : Application(), HasActivityInjector {
6263
RealmFactory.instance
6364

6465

66+
if (!BuildConfig.DEBUG) {
67+
///bugly
68+
CrashReport.initCrashReport(applicationContext, "209f33d74f", false)
69+
}
70+
6571
DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
6672
override fun placeholder(ctx: Context?): Drawable {
6773
return getDrawable(R.drawable.logo)

app/src/main/java/com/shuyu/github/kotlin/common/utils/ExpandUtils.kt

+36
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.support.v4.content.ContextCompat
88
import android.util.TypedValue
99
import android.util.TypedValue.COMPLEX_UNIT_DIP
1010
import android.util.TypedValue.COMPLEX_UNIT_SP
11+
import java.util.regex.Pattern
1112

1213
/**
1314
* Created by guoshuyu
@@ -54,11 +55,46 @@ fun Context.copy(string: String) {
5455
clipboardManager.primaryClip = clip
5556
}
5657

58+
fun Context.getVersionName(): String {
59+
val manager = packageManager.getPackageInfo(packageName, 0)
60+
return manager.versionName
61+
}
62+
5763

5864
fun ArrayList<String>.toSplitString(): String {
5965
var result = ""
6066
this.forEach {
6167
result = "$result/$it"
6268
}
6369
return result
70+
}
71+
72+
fun String.compareVersion(v2: String?): String? {
73+
if (v2 == null || v2.isEmpty()) return null
74+
val regEx = "[^0-9]"
75+
val p = Pattern.compile(regEx)
76+
var s1: String = p.matcher(this).replaceAll("").trim()
77+
var s2: String = p.matcher(v2).replaceAll("").trim()
78+
79+
val cha: Int = s1.length - s2.length
80+
val buffer = StringBuffer()
81+
var i = 0
82+
while (i < Math.abs(cha)) {
83+
buffer.append("0")
84+
++i
85+
}
86+
87+
if (cha > 0) {
88+
buffer.insert(0, s2)
89+
s2 = buffer.toString()
90+
} else if (cha < 0) {
91+
buffer.insert(0, s1)
92+
s1 = buffer.toString()
93+
}
94+
95+
val s1Int = s1.toInt()
96+
val s2Int = s2.toInt()
97+
98+
return if (s1Int > s2Int) this
99+
else v2
64100
}

app/src/main/java/com/shuyu/github/kotlin/module/main/MainActivity.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.shuyu.github.kotlin.module.dynamic.DynamicFragment
1414
import com.shuyu.github.kotlin.module.search.SearchActivity
1515
import com.shuyu.github.kotlin.repository.IssueRepository
1616
import com.shuyu.github.kotlin.repository.LoginRepository
17+
import com.shuyu.github.kotlin.repository.ReposRepository
1718
import com.shuyu.github.kotlin.ui.adapter.FragmentPagerViewAdapter
1819
import com.shuyu.github.kotlin.ui.view.GSYNavigationTabBar
1920
import dagger.android.DispatchingAndroidInjector
@@ -51,6 +52,10 @@ class MainActivity : AppCompatActivity(), HasSupportFragmentInjector, Toolbar.On
5152
lateinit var loginRepository: LoginRepository
5253

5354

55+
@Inject
56+
lateinit var repositoryRepository: ReposRepository
57+
58+
5459
@Inject
5560
lateinit var issueRepository: IssueRepository
5661

@@ -65,7 +70,7 @@ class MainActivity : AppCompatActivity(), HasSupportFragmentInjector, Toolbar.On
6570

6671
initToolbar()
6772

68-
MainDrawerController(this, home_tool_bar, loginRepository, issueRepository, globalModel)
73+
MainDrawerController(this, home_tool_bar, loginRepository, issueRepository, repositoryRepository, globalModel)
6974

7075
}
7176

app/src/main/java/com/shuyu/github/kotlin/module/main/MainDrawerController.kt

+49-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.shuyu.github.kotlin.module.main
22

3+
import android.app.Activity
4+
import android.content.Context
35
import android.support.v7.widget.Toolbar
46
import androidx.core.net.toUri
57
import com.mikepenz.materialdrawer.AccountHeaderBuilder
@@ -10,23 +12,28 @@ import com.mikepenz.materialdrawer.model.ProfileDrawerItem
1012
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem
1113
import com.orhanobut.dialogplus.DialogPlus
1214
import com.shuyu.github.kotlin.R
15+
import com.shuyu.github.kotlin.common.net.ResultCallBack
1316
import com.shuyu.github.kotlin.common.utils.IssueDialogClickListener
17+
import com.shuyu.github.kotlin.common.utils.getVersionName
1418
import com.shuyu.github.kotlin.common.utils.showIssueEditDialog
1519
import com.shuyu.github.kotlin.model.AppGlobalModel
1620
import com.shuyu.github.kotlin.model.bean.Issue
21+
import com.shuyu.github.kotlin.model.bean.Release
1722
import com.shuyu.github.kotlin.repository.IssueRepository
1823
import com.shuyu.github.kotlin.repository.LoginRepository
19-
import org.jetbrains.anko.alert
24+
import com.shuyu.github.kotlin.repository.ReposRepository
25+
import org.jetbrains.anko.*
2026

2127
/**
2228
* Created by guoshuyu
2329
* Date: 2018-11-09
2430
*/
2531

2632

27-
class MainDrawerController(private val activity: MainActivity, toolbar: Toolbar,
33+
class MainDrawerController(private val activity: Activity, toolbar: Toolbar,
2834
loginRepository: LoginRepository,
2935
private val issueRepository: IssueRepository,
36+
private val reposRepository: ReposRepository,
3037
globalModel: AppGlobalModel) {
3138

3239
var drawer: Drawer? = null
@@ -44,6 +51,14 @@ class MainDrawerController(private val activity: MainActivity, toolbar: Toolbar,
4451
true
4552
}
4653
)
54+
.addDrawerItems(
55+
PrimaryDrawerItem().withName(R.string.update)
56+
.withTextColorRes(R.color.colorPrimary).withOnDrawerItemClickListener { view, position, drawerItem ->
57+
checkUpdate(true)
58+
unSelect(drawerItem)
59+
true
60+
}
61+
)
4762
.addDrawerItems(
4863
PrimaryDrawerItem().withName(R.string.about)
4964
.withTextColorRes(R.color.colorPrimary).withOnDrawerItemClickListener { view, position, drawerItem ->
@@ -68,6 +83,9 @@ class MainDrawerController(private val activity: MainActivity, toolbar: Toolbar,
6883
.withHeaderBackground(R.color.colorPrimary)
6984
.withSelectionListEnabled(false)
7085
.build()).build()
86+
87+
88+
checkUpdate(false)
7189
}
7290

7391

@@ -85,11 +103,9 @@ class MainDrawerController(private val activity: MainActivity, toolbar: Toolbar,
85103
}
86104

87105
private fun showAboutDialog() {
88-
val manager = activity.packageManager.getPackageInfo(activity.packageName, 0)
89-
90106
activity.alert {
91107
this.title = activity.getString(R.string.app_name)
92-
this.message = activity.getString(R.string.version) + " : " + manager.versionName
108+
this.message = activity.getVersionName()
93109
this.show()
94110
}
95111
}
@@ -98,4 +114,32 @@ class MainDrawerController(private val activity: MainActivity, toolbar: Toolbar,
98114
drawerItem.withSetSelected(false)
99115
drawer?.adapter?.notifyAdapterDataSetChanged()
100116
}
117+
118+
private fun checkUpdate(needTip: Boolean = false) {
119+
reposRepository.checkoutUpDate(activity, object : ResultCallBack<Release> {
120+
override fun onSuccess(result: Release?) {
121+
result?.name?.apply {
122+
showUpdateDialog(activity, this, result.body ?: "", "www.baidu.com")
123+
return
124+
}
125+
if (needTip) {
126+
activity.toast(R.string.newestVersion)
127+
}
128+
}
129+
})
130+
}
131+
132+
private fun showUpdateDialog(context: Context, version: String, message: String, url: String) {
133+
activity.alert {
134+
this.title = activity.getString(R.string.app_name)
135+
this.message = "$version: \n$message"
136+
this.cancelButton {
137+
it.dismiss()
138+
}
139+
this.okButton {
140+
context.browse(url)
141+
}
142+
this.show()
143+
}
144+
}
101145
}

app/src/main/java/com/shuyu/github/kotlin/repository/ReposRepository.kt

+38-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import android.content.Context
66
import com.shuyu.github.kotlin.R
77
import com.shuyu.github.kotlin.common.net.*
88
import com.shuyu.github.kotlin.common.utils.HtmlUtils
9-
import com.shuyu.github.kotlin.model.bean.Event
10-
import com.shuyu.github.kotlin.model.bean.Issue
11-
import com.shuyu.github.kotlin.model.bean.Repository
12-
import com.shuyu.github.kotlin.model.bean.SearchResult
9+
import com.shuyu.github.kotlin.common.utils.compareVersion
10+
import com.shuyu.github.kotlin.common.utils.getVersionName
11+
import com.shuyu.github.kotlin.model.bean.*
1312
import com.shuyu.github.kotlin.model.conversion.EventConversion
1413
import com.shuyu.github.kotlin.model.conversion.IssueConversion
1514
import com.shuyu.github.kotlin.model.conversion.ReposConversion
@@ -34,6 +33,41 @@ class ReposRepository @Inject constructor(private val retrofit: Retrofit, privat
3433
const val WATCH_KEY = "watched"
3534
}
3635

36+
fun checkoutUpDate(context: Context, resultCallBack: ResultCallBack<Release>?) {
37+
val service = retrofit.create(RepoService::class.java)
38+
.getReleases(true, "CarGuo", "GSYGithubAppKotlin", 1)
39+
.flatMap {
40+
FlatMapResponse2Result(it)
41+
}.map {
42+
if (it.size > 0) {
43+
val item = it[0]
44+
val versionName = item.name
45+
versionName?.apply {
46+
val currentName = context.getVersionName()
47+
val hadNew = currentName.compareVersion(versionName) != currentName
48+
if (hadNew) {
49+
return@map item
50+
}
51+
}
52+
Release()
53+
} else {
54+
Release()
55+
}
56+
}.flatMap {
57+
FlatMapResult2Response(it)
58+
}
59+
60+
RetrofitFactory.executeResult(service, object : ResultTipObserver<Release>(application) {
61+
override fun onSuccess(result: Release?) {
62+
resultCallBack?.onSuccess(result)
63+
}
64+
65+
override fun onFailure(e: Throwable, isNetWorkError: Boolean) {
66+
resultCallBack?.onFailure()
67+
}
68+
})
69+
}
70+
3771
/**
3872
* 趋势
3973
*/

app/src/main/java/com/shuyu/github/kotlin/service/RepoService.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ interface RepoService {
177177
@Header("forceNetWork") forceNetWork: Boolean,
178178
@Path("owner") owner: String,
179179
@Path("repo") repo: String,
180-
@Query("page") page: Int
180+
@Query("page") page: Int,
181+
@Query("per_page") per_page: Int = AppConfig.PAGE_SIZE
181182
): Observable<Response<ArrayList<Release>>>
182183

183184
@GET("repos/{owner}/{repo}/releases/tags/{tag}")

build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ buildscript {
3131
ext.prism4j_version='1.1.0'
3232
ext.dialogplus_version='1.11@aar'
3333
ext.lottie_version='2.7.0'
34+
ext.bugly_version='2.1.1'
3435

3536
repositories {
3637
google()

0 commit comments

Comments
 (0)