leiyun пре 5 година
родитељ
комит
ba6ad7988f
18 измењених фајлова са 226 додато и 25 уклоњено
  1. +5
    -0
      .idea/jarRepositories.xml
  2. +6
    -4
      app/build.gradle
  3. +7
    -1
      app/src/main/AndroidManifest.xml
  4. +5
    -0
      app/src/main/java/com/yzx/webebook/App.kt
  5. +88
    -10
      app/src/main/java/com/yzx/webebook/activity/WebActivity.kt
  6. +8
    -0
      app/src/main/java/com/yzx/webebook/model/BaseBean.kt
  7. +11
    -0
      app/src/main/java/com/yzx/webebook/model/Version.kt
  8. +22
    -0
      app/src/main/java/com/yzx/webebook/presenter/base/JsonCallBack.kt
  9. +0
    -1
      app/src/main/java/com/yzx/webebook/widget/BaseDialog.kt
  10. +8
    -0
      app/src/main/res/drawable/dialog_border.xml
  11. +1
    -1
      app/src/main/res/layout/activity_main.xml
  12. +2
    -2
      app/src/main/res/layout/activity_web.xml
  13. +46
    -0
      app/src/main/res/layout/download_dialog.xml
  14. +4
    -2
      app/src/main/res/layout/version_dialog.xml
  15. BIN
      app/src/main/res/mipmap-xhdpi/ic_home_def.png
  16. +0
    -3
      app/src/main/res/values/styles.xml
  17. +3
    -1
      build.gradle
  18. +10
    -0
      proguard-rules.pro

+ 5
- 0
.idea/jarRepositories.xml Прегледај датотеку

@@ -26,5 +26,10 @@
<option name="name" value="maven" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
<remote-repository>
<option name="id" value="maven2" />
<option name="name" value="maven2" />
<option name="url" value="https://dl.bintray.com/umsdk/release" />
</remote-repository>
</component>
</project>

+ 6
- 4
app/build.gradle Прегледај датотеку

@@ -12,7 +12,7 @@ android {
minSdkVersion 26
targetSdkVersion 30
versionCode 2
versionName "2.0"
versionName "2.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
@@ -26,13 +26,13 @@ android {
}
buildTypes {
release {
minifyEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
zipAlignEnabled true
debuggable false
signingConfig signingConfigs.yzx
// 移除无用的resource文件
shrinkResources true
shrinkResources false
}

debug {
@@ -78,5 +78,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.6'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.github.AlexLiuSheng:CheckVersionLib:2.4.1_androidx'

// 友盟统计SDK
implementation 'com.umeng.umsdk:common:9.3.6' // 必选
implementation 'com.umeng.umsdk:asms:1.2.1' // 必选
}

+ 7
- 1
app/src/main/AndroidManifest.xml Прегледај датотеку

@@ -13,6 +13,7 @@
<uses-permission android:name="android.permission.READ_MEDIA_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />


<application
android:name=".App"
android:allowBackup="true"
@@ -21,7 +22,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".activity.NoteActivity"></activity>
<activity
android:name=".activity.NoteActivity"
android:configChanges="orientation|keyboard"
android:screenOrientation="portrait" />
<activity
android:name=".activity.WebActivity"
android:configChanges="orientation|keyboard"
@@ -30,6 +34,8 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


+ 5
- 0
app/src/main/java/com/yzx/webebook/App.kt Прегледај датотеку

@@ -3,6 +3,8 @@ package com.yzx.webebook
import android.app.Application
import com.blankj.utilcode.util.Utils
import com.lzy.okgo.OkGo
import com.umeng.analytics.MobclickAgent
import com.umeng.commonsdk.UMConfigure

class App: Application() {

@@ -10,5 +12,8 @@ class App: Application() {
super.onCreate()
OkGo.getInstance().init(this)
Utils.init(this)

UMConfigure.init(this, "60334d01425ec25f10fbd5b4", "ebook", UMConfigure.DEVICE_TYPE_PHONE, "")
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO)
}
}

+ 88
- 10
app/src/main/java/com/yzx/webebook/activity/WebActivity.kt Прегледај датотеку

@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.net.http.SslError
import android.os.Build
@@ -13,13 +14,25 @@ import android.view.View
import android.view.ViewGroup
import android.webkit.*
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.core.widget.ContentLoadingProgressBar
import com.allenliu.versionchecklib.v2.AllenVersionChecker
import com.allenliu.versionchecklib.v2.builder.UIData
import com.allenliu.versionchecklib.v2.callback.CustomDownloadingDialogListener
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.SPUtils
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.lzy.okgo.OkGo
import com.lzy.okgo.callback.StringCallback
import com.lzy.okgo.model.Response
import com.yzx.webebook.MainActivity
import com.yzx.webebook.R
import com.yzx.webebook.activity.base.BaseActivity
import com.yzx.webebook.model.BaseBean
import com.yzx.webebook.model.Version
import com.yzx.webebook.presenter.base.BasePresenter
import com.yzx.webebook.widget.BaseDialog
import kotlinx.android.synthetic.main.activity_web.*
@@ -28,6 +41,7 @@ import org.jetbrains.anko.find
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
import org.json.JSONObject
import java.util.*

/**
* 类名:WebActivity
@@ -63,28 +77,90 @@ class WebActivity : BaseActivity<BasePresenter<*>>() {
}

private fun checkVersion(): Unit {
val url =
"https://filea.oa.qbjjyyun.net/edufile/download?uniqueKey=22de6670beaa78a822ae4a95bdb2c6f5"
val test = "192.168.69.112:9009"
val online = "https://oa.qbjjyyun.net/api"
val BASE_URL = online
OkGo.post<String>("$BASE_URL/parent/common/getInkBottleMaxVersion")
.tag(this)
.execute(object : StringCallback() {

override fun onSuccess(response: Response<String>) {
val json = response.body()
Log.d("checkVersion", "onSuccess: ${json}")
val resultType = object : TypeToken<BaseBean<Version>>() {}.type
val gson = Gson()
val res = gson.fromJson<BaseBean<Version>>(json, resultType)
if (res.code == 0) {
val appVersion = AppUtils.getAppVersionName()
val appVersionCode = AppUtils.getAppVersionCode()
val versionCode = res?.data?.version_code ?: 0
val curr = Date().time
val lastTipTime = SPUtils.getInstance()
.getLong("last_tip_time${res.data.version_code}", 0)
if (versionCode > appVersionCode) { //有新版本
if (res.data.type == 1) { //强制升级
updateApp(res.data)
} else if (curr - lastTipTime > 24 * 60 * 60 * 1000) { //非强制一天以内提示一次
updateApp(res.data)
}

}
}
}

})


}

private fun updateApp(version: Version) {
AllenVersionChecker
.getInstance()
.downloadOnly(
UIData.create()
.setTitle("检测到新版本")
.setContent("1.优化了笔记的体验\n2.解决了若干已知bug\n")
.setDownloadUrl(url)

.setContent(version.explain)
.setDownloadUrl(version.app_src)
)
.setCustomVersionDialogListener { context, versionBundle ->
val dialog = BaseDialog(context, R.style.BaseDialog, R.layout.version_dialog)
val title = dialog.find<TextView>(R.id.tv_title)
title.text = "检测到新版本"
val content = dialog.find<TextView>(R.id.tv_msg)
content.text = "1.优化了笔记的体验\n2.解决了若干已知bug\n"
dialog.window?.setDimAmount(0.1f)
content.text = version.explain
dialog.window?.setDimAmount(0.5f)
val cancelBtn = dialog.find<View>(R.id.cancel_btn)
//cancelBtn.visibility = View.GONE
if (version.type == 1) {
cancelBtn.visibility = View.GONE
}

return@setCustomVersionDialogListener dialog
}
.setOnCancelListener {
SPUtils.getInstance().put("last_tip_time${version.version_code}", Date().time)
}
.setCustomDownloadingDialogListener(object : CustomDownloadingDialogListener {
@SuppressLint("SetTextI18n")
override fun updateUI(dialog: Dialog?, progress: Int, versionBundle: UIData?) {
val tvProgress: TextView = dialog!!.findViewById(R.id.tv_progress)
val progressBar: ContentLoadingProgressBar = dialog.findViewById(R.id.pb)
progressBar.progress = progress
tvProgress.text = "$progress%"
}

override fun getCustomDownloadingDialog(
context: Context?,
progress: Int,
versionBundle: UIData?
): Dialog {
return BaseDialog(
context!!,
R.style.BaseDialog,
R.layout.download_dialog
)
}

})
.executeMission(this)
}

@@ -101,7 +177,7 @@ class WebActivity : BaseActivity<BasePresenter<*>>() {
}
btnBack.setOnClickListener { onBackPressed() }
btnClose.setOnClickListener {
finish()
webView.loadUrl(url)
}
btnRefresh.setOnClickListener {
webView.reload()
@@ -171,9 +247,11 @@ class WebActivity : BaseActivity<BasePresenter<*>>() {
if (view.canGoBack()) {
//btnClose.visibility = View.VISIBLE
btnBack.visibility = View.VISIBLE
btnClose.visibility = View.VISIBLE
} else {
//btnClose.visibility = View.GONE
btnBack.visibility = View.GONE
btnClose.visibility = View.GONE
}
}
} else {
@@ -203,7 +281,6 @@ class WebActivity : BaseActivity<BasePresenter<*>>() {

override fun initData() {
webView.loadUrl(url)
// checkVersion()
}

override fun initPresenter(): BasePresenter<*>? {
@@ -213,6 +290,7 @@ class WebActivity : BaseActivity<BasePresenter<*>>() {
override fun onResume() {
super.onResume()
webView.onResume()
checkVersion()
}

override fun onPause() {


+ 8
- 0
app/src/main/java/com/yzx/webebook/model/BaseBean.kt Прегледај датотеку

@@ -0,0 +1,8 @@
package com.yzx.webebook.model

data class BaseBean<T>(
var code: Int,
var msg: String,
val data: T,
val list: MutableList<T>
)

+ 11
- 0
app/src/main/java/com/yzx/webebook/model/Version.kt Прегледај датотеку

@@ -0,0 +1,11 @@
package com.yzx.webebook.model

class Version {
var version: String = ""
var version_code: Int = 0
var id: Int = 0
var type: Int = 0
var explain: String = ""
var app_src: String = ""
var status: Int = 0
}

+ 22
- 0
app/src/main/java/com/yzx/webebook/presenter/base/JsonCallBack.kt Прегледај датотеку

@@ -0,0 +1,22 @@
package com.yzx.webebook.presenter.base

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.lzy.okgo.callback.AbsCallback
import com.lzy.okgo.convert.StringConvert
import com.yzx.webebook.model.BaseBean
import okhttp3.Response

abstract class JsonCallBack<T> : AbsCallback<BaseBean<T>>() {

private val convert = StringConvert()

override fun convertResponse(response: Response?): BaseBean<T> {
val json: String = convert.convertResponse(response)
val resultType = object : TypeToken<BaseBean<T>>() {}.type
val gson = Gson()
val fromJson = gson.fromJson<BaseBean<T>>(json, resultType)
return fromJson
}

}

+ 0
- 1
app/src/main/java/com/yzx/webebook/widget/BaseDialog.kt Прегледај датотеку

@@ -11,6 +11,5 @@ class BaseDialog(context: Context, themeResId: Int, res: Int) : Dialog(context,
this.res = res
setCanceledOnTouchOutside(false)
setCancelable(false)
window?.setDimAmount(0f)
}
}

+ 8
- 0
app/src/main/res/drawable/dialog_border.xml Прегледај датотеку

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />

<stroke
android:width="11dp"
android:color="#000000" />
</shape>

+ 1
- 1
app/src/main/res/layout/activity_main.xml Прегледај датотеку

@@ -62,7 +62,7 @@
android:layout_marginTop="@dimen/d_20"
android:hint="输入网址"
android:paddingHorizontal="15dp"
android:text="http://192.168.69.113:8098/"/>
android:text="http://192.168.69.112:8098/"/>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn3"


+ 2
- 2
app/src/main/res/layout/activity_web.xml Прегледај датотеку

@@ -29,8 +29,8 @@
android:layout_height="@dimen/title_height"
android:layout_toEndOf="@+id/btnBack"
android:scaleType="centerInside"
android:src="@mipmap/ic_close"
android:visibility="visible" />
android:src="@mipmap/ic_home_def"
android:visibility="gone" />

<ImageView
android:id="@+id/btnRefresh"


+ 46
- 0
app/src/main/res/layout/download_dialog.xml Прегледај датотеку

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp"
android:text="新版本更新"
android:textColor="#000" />

<androidx.core.widget.ContentLoadingProgressBar
android:id="@+id/pb"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="15dp"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/progressbar_horizontal" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/versionchecklib_downloading"
android:textColor="@color/versionchecklib_theme_color"
android:textSize="15sp" />

<TextView
android:id="@+id/tv_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/versionchecklib_progress"
android:textColor="@color/versionchecklib_theme_color"
android:textSize="15sp" />
</RelativeLayout>
</LinearLayout>

+ 4
- 2
app/src/main/res/layout/version_dialog.xml Прегледај датотеку

@@ -31,7 +31,7 @@
android:layout_marginTop="10dp"
android:text="@string/update_title"
android:textColor="@android:color/black"
android:textSize="13sp" />
android:textSize="18sp" />

<TextView
android:id="@+id/tv_msg"
@@ -40,7 +40,7 @@
android:layout_marginTop="10dp"
android:text="@string/updatecontent"
android:textColor="#666"
android:textSize="12sp" />
android:textSize="16sp" />

<LinearLayout
android:layout_width="match_parent"
@@ -61,6 +61,7 @@
android:layout_weight="1"
android:background="@drawable/shape_corner_plain"
android:text="取消"
android:textSize="16sp"
android:textColor="@android:color/black" />
</FrameLayout>

@@ -72,6 +73,7 @@
android:layout_weight="1"
android:background="@drawable/shape_corner"
android:text="立即升级"
android:textSize="16sp"
android:textColor="@android:color/white" />

</LinearLayout>


BIN
app/src/main/res/mipmap-xhdpi/ic_home_def.png Прегледај датотеку

Before After
Width: 36  |  Height: 36  |  Size: 607 B

+ 0
- 3
app/src/main/res/values/styles.xml Прегледај датотеку

@@ -11,11 +11,8 @@
<style name="BaseDialog" parent="android:Theme.Light">
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.1</item>
</style>
</resources>

+ 3
- 1
build.gradle Прегледај датотеку

@@ -6,7 +6,8 @@ buildscript {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://dl.bintray.com/umsdk/release' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
@@ -21,6 +22,7 @@ allprojects {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://dl.bintray.com/umsdk/release' }
}
}



+ 10
- 0
proguard-rules.pro Прегледај датотеку

@@ -91,3 +91,13 @@
-dontwarn io.bugtags.**
-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient

-keep class com.umeng.** {*;}

-keepclassmembers class * {
public <init> (org.json.JSONObject);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

Loading…
Откажи
Сачувај