From ef6ba6e2f83d7bf807bdd7f1831f2056aeb856b4 Mon Sep 17 00:00:00 2001 From: chiclaim Date: Sat, 13 Aug 2022 12:09:00 +0800 Subject: [PATCH] =?UTF-8?q?[update]=20=E6=9B=B4=E6=96=B0=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E8=87=AA=E9=80=82=E5=BA=94=E5=A4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 6 +-- .../android/downloader/sample/MainActivity.kt | 9 +++- downloader/build.gradle | 3 +- downloader/proguard-rules.pro | 1 + .../downloader/UpgradeDialogActivity.kt | 5 +- .../downloader/widget/MaxHeightScrollView.kt | 48 +++++++++++++++++++ .../layout/activity_upgrade_dialog_layout.xml | 19 ++++---- downloader/src/main/res/values/attrs.xml | 7 +++ downloader/src/main/res/values/colors.xml | 1 + 9 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 downloader/src/main/java/com/chiclaim/android/downloader/widget/MaxHeightScrollView.kt create mode 100644 downloader/src/main/res/values/attrs.xml diff --git a/app/build.gradle b/app/build.gradle index 4a23b91..008ee2d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,7 +24,7 @@ android { } buildTypes { release { - minifyEnabled false + minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release } @@ -39,8 +39,8 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.2.0' implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - //implementation project(':downloader') - implementation 'io.github.chiclaim:downloader:1.0.0' + implementation project(':downloader') + //implementation 'io.github.chiclaim:downloader:1.0.0' debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1' } diff --git a/app/src/main/java/com/chiclaim/android/downloader/sample/MainActivity.kt b/app/src/main/java/com/chiclaim/android/downloader/sample/MainActivity.kt index c566e5d..4d6cc5b 100644 --- a/app/src/main/java/com/chiclaim/android/downloader/sample/MainActivity.kt +++ b/app/src/main/java/com/chiclaim/android/downloader/sample/MainActivity.kt @@ -171,7 +171,14 @@ class MainActivity : AppCompatActivity(), DownloadListener { it.url = fileUrl it.ignoreLocal = ignoreLocalFile it.title = if (isForceUpdate) "重要安全升级" else "发现新版本" - it.description = "1. 修复已知问题\n2. 修复已知问题" + it.description = """ + 1. 支持断点续传,节省流量 + 2. 支持文件缓存,避免重复下载 + 3. 通知栏下载进度、点击安装与重试 + 4. 统一处理安装权限的交互逻辑 + 5. 时间采样,避免创建大量通知对象 + 6. 更新弹窗自适应大小 + """.trimIndent() it.forceUpdate = isForceUpdate it.negativeText = if (isForceUpdate) "退出程序" else "取消" it.notifierSmallIcon = R.mipmap.ic_launcher diff --git a/downloader/build.gradle b/downloader/build.gradle index c66a45b..f36d01c 100644 --- a/downloader/build.gradle +++ b/downloader/build.gradle @@ -15,10 +15,11 @@ android { serviceActionSuffix: ".file.download.DownloadService"] buildConfigField("String", "AUTHORITIES_SUFFIX", "\"${manifestPlaceholders['authoritiesSuffix']}\"") buildConfigField("String", "SERVICE_ACTION_SUFFIX", "\"${manifestPlaceholders['serviceActionSuffix']}\"") + consumerProguardFiles "proguard-rules.pro" } buildTypes { release { - minifyEnabled false + minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } diff --git a/downloader/proguard-rules.pro b/downloader/proguard-rules.pro index c72311e..7b4cf54 100644 --- a/downloader/proguard-rules.pro +++ b/downloader/proguard-rules.pro @@ -15,3 +15,4 @@ #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} +-keep class com.chiclaim.android.downloader.widget.** { *; } \ No newline at end of file diff --git a/downloader/src/main/java/com/chiclaim/android/downloader/UpgradeDialogActivity.kt b/downloader/src/main/java/com/chiclaim/android/downloader/UpgradeDialogActivity.kt index eb9a6c3..279ea23 100644 --- a/downloader/src/main/java/com/chiclaim/android/downloader/UpgradeDialogActivity.kt +++ b/downloader/src/main/java/com/chiclaim/android/downloader/UpgradeDialogActivity.kt @@ -2,7 +2,6 @@ package com.chiclaim.android.downloader import android.app.ActivityManager import android.app.Application -import android.app.DownloadManager import android.content.Context import android.content.Intent import android.net.Uri @@ -18,7 +17,7 @@ import com.chiclaim.android.downloader.util.e import java.io.File /** - * + * 内置的更新弹窗 * @author by chiclaim@google.com */ class UpgradeDialogActivity : AppCompatActivity(), DownloadListener { @@ -73,6 +72,8 @@ class UpgradeDialogActivity : AppCompatActivity(), DownloadListener { findViewById(R.id.tv_updater_desc).text = dialogInfo.description ?: getString(R.string.downloader_desc_default) + // findViewById(R.id.scrollView).setMaxHeight(150) + tvNegative = findViewById(R.id.tv_updater_cancel).apply { this.text = dialogInfo.negativeText ?: getString(R.string.downloader_cancel) } diff --git a/downloader/src/main/java/com/chiclaim/android/downloader/widget/MaxHeightScrollView.kt b/downloader/src/main/java/com/chiclaim/android/downloader/widget/MaxHeightScrollView.kt new file mode 100644 index 0000000..2929b06 --- /dev/null +++ b/downloader/src/main/java/com/chiclaim/android/downloader/widget/MaxHeightScrollView.kt @@ -0,0 +1,48 @@ +package com.chiclaim.android.downloader.widget + +import android.content.Context +import android.util.AttributeSet +import android.widget.ScrollView +import com.chiclaim.android.downloader.R + +class MaxHeightScrollView : ScrollView { + + private var maxHeight: Int = -1 + + constructor(context: Context) : super(context) { + initAttrs(null) + } + + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { + initAttrs(attrs) + } + + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super( + context, + attrs, + defStyleAttr + ) { + initAttrs(attrs) + } + + private fun defaultMaxHeight() = context.resources.displayMetrics.heightPixels / 2 + + fun setMaxHeight(maxHeight: Int) { + this.maxHeight = maxHeight + } + + private fun initAttrs(attrs: AttributeSet?) { + if (attrs != null) { + val attr = context.obtainStyledAttributes(attrs, R.styleable.MaxHeightScrollView) + maxHeight = attr.getDimensionPixelSize(R.styleable.MaxHeightScrollView_maxHeight, -1) + attr.recycle() + maxHeight + } + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + if (maxHeight == -1) maxHeight = defaultMaxHeight() + val newHeightMeasureSpec = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST) + super.onMeasure(widthMeasureSpec, newHeightMeasureSpec) + } +} \ No newline at end of file diff --git a/downloader/src/main/res/layout/activity_upgrade_dialog_layout.xml b/downloader/src/main/res/layout/activity_upgrade_dialog_layout.xml index 20fecea..db35844 100644 --- a/downloader/src/main/res/layout/activity_upgrade_dialog_layout.xml +++ b/downloader/src/main/res/layout/activity_upgrade_dialog_layout.xml @@ -10,31 +10,34 @@ android:id="@+id/tv_updater_title" android:layout_width="match_parent" android:layout_height="60dp" - android:layout_marginLeft="18dp" - android:gravity="center|left" + android:layout_marginStart="18dp" + android:gravity="start|center" android:textColor="@color/black_3" android:textSize="@dimen/dialog_title_size" android:textStyle="normal" tools:text="更新提醒" /> - + android:layout_height="wrap_content" + android:fadingEdgeLength="20dp" + android:requiresFadingEdge="vertical"> - + + + + + + + + \ No newline at end of file diff --git a/downloader/src/main/res/values/colors.xml b/downloader/src/main/res/values/colors.xml index 05a6b25..631ddca 100644 --- a/downloader/src/main/res/values/colors.xml +++ b/downloader/src/main/res/values/colors.xml @@ -1,5 +1,6 @@ #333333 + #666666 #4169E1