Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: teprinciple/UpdateAppUtils
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: teprinciple/UpdateAppUtils
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: androidX
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 19 commits
  • 19 files changed
  • 1 contributor

Commits on Jul 2, 2019

  1. android x

    teprinciple committed Jul 2, 2019
    Copy the full SHA
    c31029c View commit details

Commits on Jul 10, 2019

  1. Copy the full SHA
    f168ac7 View commit details

Commits on Jul 15, 2019

  1. 9.0Http适配

    teprinciple committed Jul 15, 2019
    Copy the full SHA
    7290d41 View commit details

Commits on Aug 7, 2019

  1. Copy the full SHA
    217d2a3 View commit details

Commits on Aug 28, 2019

  1. fix bugs

    teprinciple committed Aug 28, 2019
    Copy the full SHA
    4759b24 View commit details
  2. 2.0.4:

    修复阿里云,码云平台上的apk FileDownloader下载失败
    增加UpdateConfig alwaysShowDownLoadDialog字段,让非强更也能显示下载进度弹窗
    teprinciple committed Aug 28, 2019
    Copy the full SHA
    2880890 View commit details
  3. V2.0.4

    teprinciple committed Aug 28, 2019
    Copy the full SHA
    d7b8f7c View commit details

Commits on Sep 16, 2019

  1. 2.1.0

    teprinciple committed Sep 16, 2019
    Copy the full SHA
    2f0af6c View commit details
  2. 更新文档

    teprinciple committed Sep 16, 2019
    Copy the full SHA
    cf4f822 View commit details

Commits on Mar 25, 2020

  1. androidX V2.2.0

    teprinciple committed Mar 25, 2020
    Copy the full SHA
    0f3669c View commit details
  2. V2.2.0 更新文档

    teprinciple committed Mar 25, 2020
    Copy the full SHA
    e295f84 View commit details

Commits on Mar 27, 2020

  1. V2.2.1

    teprinciple committed Mar 27, 2020
    Copy the full SHA
    f563802 View commit details
  2. V2.2.1

    teprinciple committed Mar 27, 2020
    Copy the full SHA
    fb198d2 View commit details

Commits on Apr 2, 2020

  1. V2.2.3

    teprinciple committed Apr 2, 2020
    Copy the full SHA
    a113ce6 View commit details
  2. V2.3.0

    teprinciple committed Apr 2, 2020
    Copy the full SHA
    91e8894 View commit details
  3. V2.3.0

    teprinciple committed Apr 2, 2020
    Copy the full SHA
    4d011eb View commit details
  4. V2.3.0

    teprinciple committed Apr 2, 2020
    Copy the full SHA
    1549583 View commit details
  5. V2.3.0

    teprinciple committed Apr 2, 2020
    Copy the full SHA
    6582ae2 View commit details
  6. V2.3.0

    teprinciple committed Apr 2, 2020
    Copy the full SHA
    742ce14 View commit details
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

[ ![](https://img.shields.io/badge/platform-android-green.svg) ](http://developer.android.com/index.html)
[ ![Download](https://api.bintray.com/packages/teprinciple/maven/updateapputils/images/download.svg) ](https://bintray.com/teprinciple/maven/updateapputils/_latestVersion)

### 一行代码,快速实现app在线下载更新 A simple library for Android update app

#### UpdateAppUtils2.0 特点
@@ -28,18 +29,24 @@ repositories {
}
// Support
implementation 'com.teprinciple:updateapputils:2.2.1'
implementation 'com.teprinciple:updateapputils:2.3.0'
```

AndroidX项目
```
// AndroidX
implementation 'com.teprinciple:updateapputilsX:2.2.1'
implementation 'com.teprinciple:updateapputilsX:2.3.0'
```

### 使用
下面为kotlin使用示例,Java示例请参考[JavaDemo](https://github.com/teprinciple/UpdateAppUtils/blob/master/app/src/main/java/com/example/teprinciple/updateappdemo/JavaDemoActivity.java)
#### 1、快速使用

##### 注意:部分手机SDK内部初始化不了context,造成context空指针,建议在application或者使用SDK前先初始化
```
UpdateAppUtils.init(context)
```

```
UpdateAppUtils
.getInstance()
@@ -175,7 +182,7 @@ implementation 'com.teprinciple:updateapputilsX:2.2.1'
<img src="https://github.com/teprinciple/UpdateAppUtils/blob/master/img/demo.png" width="220">

### 更新日志
#### 2.2.1
* 优化代码
* 修复部分bug

#### 2.3.0
* 修复部分手机context空指针异常
##### [更多历史版本](https://github.com/teprinciple/UpdateAppUtils/blob/master/readme/version.md)
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -41,8 +41,8 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':updateapputils')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.1'
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ package com.example.teprinciple.updateappdemo

import android.os.Bundle
import android.os.Environment
import android.support.v7.app.AppCompatActivity
import androidx.appcompat.app.AppCompatActivity
import android.widget.Toast
import kotlinx.android.synthetic.main.check_md5_demo_activity.*
import listener.Md5CheckResultListener
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.teprinciple.updateappdemo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;

import org.jetbrains.annotations.NotNull;
@@ -30,6 +30,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_java_demo);


UpdateAppUtils.init(this);

findViewById(R.id.btn_java).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -43,7 +46,7 @@ public void onClick(View v) {
uiConfig.setUiType(UiType.PLENTIFUL);

UpdateAppUtils
.getInstance(JavaDemoActivity.this)
.getInstance()
.apkUrl(apkUrl)
.updateTitle(updateTitle)
.updateContent(updateContent)
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.os.Environment
import android.support.v7.app.AppCompatActivity
import androidx.appcompat.app.AppCompatActivity
import android.view.View
import android.widget.TextView
import android.widget.Toast
@@ -20,7 +20,6 @@ import update.UpdateAppUtils


class MainActivity : AppCompatActivity() {

private val apkUrl = "http://118.24.148.250:8080/yk/update_signed.apk"
// private val apkUrl = "https://github.com/AlexLiuSheng/CheckVersionLib/blob/master/library/src/main/java/com/allenliu/versionchecklib/utils/AppUtils.java"
private val updateTitle = "发现新版本V2.0.0"
Original file line number Diff line number Diff line change
@@ -15,14 +15,6 @@
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.FloatRange;
import android.support.annotation.IntDef;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.Layout;
import android.text.Layout.Alignment;
import android.text.SpannableStringBuilder;
@@ -55,6 +47,15 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;

import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.FloatRange;
import androidx.annotation.IntDef;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import static android.graphics.BlurMaskFilter.Blur;

/**
4 changes: 2 additions & 2 deletions app/src/main/res/layout/view_update_dialog_custom.xml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.constraint.ConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="280dp"
android:layout_height="wrap_content"
android:background="@drawable/bg_custom_update"
@@ -78,7 +78,7 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="V1.0.0"/>

</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

<ImageView
android:id="@+id/btn_update_cancel"
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
2 changes: 2 additions & 0 deletions readme/version.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
### 更新日志
#### 2.3.0
* 修复部分手机context空指针异常
#### 2.2.1
* 优化代码
* 修复部分bug
8 changes: 4 additions & 4 deletions updateapputils/build.gradle
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.liulishuo.filedownloader:library:1.7.7'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1'
@@ -42,8 +42,8 @@ repositories {
publish {
userOrg = 'teprinciple'
groupId = 'com.teprinciple'
artifactId = 'updateapputils'
publishVersion = '2.2.2'
artifactId = 'updateapputilsx'
publishVersion = '2.3.0'
desc = 'A Simple library for Android update app'
website = 'https://github.com/teprinciple/UpdateAppUtils'
}
2 changes: 1 addition & 1 deletion updateapputils/src/main/java/extension/ContextKtx.kt
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import android.content.Intent
import android.net.ConnectivityManager
import android.net.Uri
import android.os.Build
import android.support.v4.content.FileProvider
import androidx.core.content.FileProvider
import java.io.File

/**
10 changes: 5 additions & 5 deletions updateapputils/src/main/java/extension/CoreKtx.kt
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@ package extension
import android.app.ActivityManager
import android.content.Context
import android.os.Build
import android.support.v4.content.ContextCompat
import android.util.Log
import android.view.View
import androidx.core.content.ContextCompat
import update.UpdateAppUtils
import util.GlobalContextProvider
import kotlin.system.exitProcess
@@ -19,7 +19,7 @@ import kotlin.system.exitProcess
/**
* 全局context
*/
val globalContext by lazy { GlobalContextProvider.mContext }
fun globalContext() = GlobalContextProvider.mContext


/**
@@ -32,12 +32,12 @@ fun log(content: String?) = UpdateAppUtils.updateInfo.config.isDebug.yes {
/**
* 获取color
*/
fun color(color: Int) = if (globalContext == null) 0 else ContextCompat.getColor(globalContext!!, color)
fun color(color: Int) = if (globalContext() == null) 0 else ContextCompat.getColor(globalContext()!!, color)

/**
* 获取 String
*/
fun string(string: Int) = globalContext?.getString(string) ?: ""
fun string(string: Int) = globalContext()?.getString(string) ?: ""

/**
* view 显示隐藏
@@ -54,7 +54,7 @@ fun View.visibleOrGone(show: Boolean) {
* 退出app
*/
fun exitApp() {
val manager = globalContext!!.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val manager = globalContext()!!.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
manager.appTasks.forEach { it.finishAndRemoveTask() }
} else {
16 changes: 6 additions & 10 deletions updateapputils/src/main/java/ui/UpdateAppActivity.kt
Original file line number Diff line number Diff line change
@@ -8,10 +8,11 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity
import android.view.MotionEvent

import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.appcompat.app.AppCompatActivity
import android.view.View
import android.widget.ImageView
import android.widget.TextView
@@ -24,7 +25,6 @@ import update.DownloadAppUtils
import update.UpdateAppService
import update.UpdateAppUtils
import util.AlertDialogUtil
import util.GlobalContextProvider
import util.SPUtil

/**
@@ -57,10 +57,6 @@ internal class UpdateAppActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (GlobalContextProvider.mContext == null){
GlobalContextProvider.mContext = this.applicationContext
}

setContentView(
when (uiConfig.uiType) {
UiType.SIMPLE -> R.layout.view_update_dialog_simple
@@ -310,10 +306,10 @@ internal class UpdateAppActivity : AppCompatActivity() {

companion object {

fun launch() = globalContext.let {
fun launch() = globalContext()?.let {
val intent = Intent(it, UpdateAppActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
it?.startActivity(intent)
it.startActivity(intent)
}

private const val permission = Manifest.permission.WRITE_EXTERNAL_STORAGE
2 changes: 1 addition & 1 deletion updateapputils/src/main/java/update/DownloadAppUtils.kt
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ internal object DownloadAppUtils {
/**
* context
*/
private val context by lazy { globalContext!! }
private val context by lazy { globalContext()!! }

/**
* 是否在下载中
22 changes: 13 additions & 9 deletions updateapputils/src/main/java/update/UpdateAppUtils.kt
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ import util.SPUtil
object UpdateAppUtils {

// 更新信息对象
internal val updateInfo = UpdateInfo()
internal val updateInfo by lazy { UpdateInfo() }

// 下载监听
internal var downloadListener: UpdateDownloadListener? = null
@@ -124,7 +124,8 @@ object UpdateAppUtils {
* 检查更新
*/
fun update() {
val keyName = (globalContext?.packageName ?: "") + updateInfo.config.serverVersionName
val keyName = (globalContext()?.packageName ?: "") + updateInfo.config.serverVersionName

// 设置每次显示,设置本次显示及强制更新 每次都显示弹窗
(updateInfo.config.alwaysShow || updateInfo.config.thisTimeShow || updateInfo.config.force).yes {
UpdateAppActivity.launch()
@@ -153,14 +154,17 @@ object UpdateAppUtils {

/**
* 获取单例对象
* @param context 提供全局context。解决部分手机 通过UpdateFileProvider 获取不到
*/
@JvmStatic
fun getInstance(context: Context? = null): UpdateAppUtils{
context?.let {
GlobalContextProvider.mContext = context.applicationContext
log("外部初始化context")
}
return this
fun getInstance() = this

/**
* 初始化,非必须。解决部分手机 通过UpdateFileProvider 获取不到context情况使用
* * @param context 提供全局context。
*/
@JvmStatic
fun init(context: Context){
GlobalContextProvider.mContext = context.applicationContext
log("外部初始化context")
}
}
5 changes: 2 additions & 3 deletions updateapputils/src/main/java/update/UpdateFileProvider.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package update

import android.support.v4.content.FileProvider
import androidx.core.content.FileProvider
import extension.log
import extension.yes
import util.GlobalContextProvider
@@ -15,7 +14,7 @@ class UpdateFileProvider : FileProvider() {
val result = super.onCreate()
(GlobalContextProvider.mContext == null && context != null).yes {
GlobalContextProvider.mContext = context
log("Provider初始化context" + GlobalContextProvider.mContext)
log("内部Provider初始化context" + GlobalContextProvider.mContext)
}
return result
}
4 changes: 2 additions & 2 deletions updateapputils/src/main/java/util/SPUtil.kt
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ internal object SPUtil {
}

private fun getSp(): SharedPreferences? {
if (globalContext == null) return null
return globalContext!!.getSharedPreferences(globalContext!!.packageName, Activity.MODE_PRIVATE)
if (globalContext() == null) return null
return globalContext()!!.getSharedPreferences(globalContext()!!.packageName, Activity.MODE_PRIVATE)
}
}
Loading