Skip to content

Commit

Permalink
prepare 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Nov 9, 2018
1 parent fb6f95f commit c55d72c
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 11 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,7 @@ dependencies {
///lottie
implementation "com.airbnb.android:lottie:${lottie_version}"


///bugly
implementation "com.tencent.bugly:crashreport:${bugly_version}"
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<application
android:name="GSYGithubApplication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.shuyu.github.kotlin.common.utils.CommonUtils
import com.shuyu.github.kotlin.di.AppInjector
import com.shuyu.gsygiideloader.GSYGlideImageLoader
import com.shuyu.gsyimageloader.GSYImageLoaderManager
import com.tencent.bugly.crashreport.CrashReport
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasActivityInjector
import io.realm.Realm
Expand Down Expand Up @@ -62,6 +63,11 @@ class GSYGithubApplication : Application(), HasActivityInjector {
RealmFactory.instance


if (!BuildConfig.DEBUG) {
///bugly
CrashReport.initCrashReport(applicationContext, "209f33d74f", false)
}

DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
override fun placeholder(ctx: Context?): Drawable {
return getDrawable(R.drawable.logo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.support.v4.content.ContextCompat
import android.util.TypedValue
import android.util.TypedValue.COMPLEX_UNIT_DIP
import android.util.TypedValue.COMPLEX_UNIT_SP
import java.util.regex.Pattern

/**
* Created by guoshuyu
Expand Down Expand Up @@ -54,11 +55,46 @@ fun Context.copy(string: String) {
clipboardManager.primaryClip = clip
}

fun Context.getVersionName(): String {
val manager = packageManager.getPackageInfo(packageName, 0)
return manager.versionName
}


fun ArrayList<String>.toSplitString(): String {
var result = ""
this.forEach {
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,6 +52,10 @@ class MainActivity : AppCompatActivity(), HasSupportFragmentInjector, Toolbar.On
lateinit var loginRepository: LoginRepository


@Inject
lateinit var repositoryRepository: ReposRepository


@Inject
lateinit var issueRepository: IssueRepository

Expand All @@ -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)

}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,23 +12,28 @@ 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
* Date: 2018-11-09
*/


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
Expand All @@ -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 ->
Expand All @@ -68,6 +83,9 @@ class MainDrawerController(private val activity: MainActivity, toolbar: Toolbar,
.withHeaderBackground(R.color.colorPrimary)
.withSelectionListEnabled(false)
.build()).build()


checkUpdate(false)
}


Expand All @@ -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()
}
}
Expand All @@ -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<Release> {
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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,6 +33,41 @@ class ReposRepository @Inject constructor(private val retrofit: Retrofit, privat
const val WATCH_KEY = "watched"
}

fun checkoutUpDate(context: Context, resultCallBack: ResultCallBack<Release>?) {
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<Release>(application) {
override fun onSuccess(result: Release?) {
resultCallBack?.onSuccess(result)
}

override fun onFailure(e: Throwable, isNetWorkError: Boolean) {
resultCallBack?.onFailure()
}
})
}

/**
* 趋势
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response<ArrayList<Release>>>

@GET("repos/{owner}/{repo}/releases/tags/{tag}")
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c55d72c

Please sign in to comment.