Skip to content

Commit

Permalink
[update] 更新弹窗自适应大
Browse files Browse the repository at this point in the history
  • Loading branch information
chiclaim committed Aug 13, 2022
1 parent b01130e commit ef6ba6e
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 15 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
}
buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
Expand All @@ -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'

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion downloader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Expand Down
1 change: 1 addition & 0 deletions downloader/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keep class com.chiclaim.android.downloader.widget.** { *; }
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +17,7 @@ import com.chiclaim.android.downloader.util.e
import java.io.File

/**
*
* 内置的更新弹窗
* @author by [email protected]
*/
class UpgradeDialogActivity : AppCompatActivity(), DownloadListener {
Expand Down Expand Up @@ -73,6 +72,8 @@ class UpgradeDialogActivity : AppCompatActivity(), DownloadListener {
findViewById<TextView>(R.id.tv_updater_desc).text =
dialogInfo.description ?: getString(R.string.downloader_desc_default)

// findViewById<MaxHeightScrollView>(R.id.scrollView).setMaxHeight(150)

tvNegative = findViewById<TextView>(R.id.tv_updater_cancel).apply {
this.text = dialogInfo.negativeText ?: getString(R.string.downloader_cancel)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
19 changes: 11 additions & 8 deletions downloader/src/main/res/layout/activity_upgrade_dialog_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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="更新提醒" />


<ScrollView
<com.chiclaim.android.downloader.widget.MaxHeightScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:fadingEdgeLength="20dp"
android:requiresFadingEdge="vertical">

<TextView
android:id="@+id/tv_updater_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:maxHeight="400dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingBottom="40dp"
android:textColor="@color/black_3"
android:textColor="@color/black_6"
android:textSize="@dimen/dialog_content_size"
android:lineSpacingExtra="3dp"
tools:text="XXX有新版本,是否更新?\nXXX有新版本,是否更新?" />
</ScrollView>

</com.chiclaim.android.downloader.widget.MaxHeightScrollView>

<ProgressBar
android:id="@+id/pb_updater"
Expand Down
7 changes: 7 additions & 0 deletions downloader/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>
<declare-styleable name="MaxHeightScrollView">
<attr name="maxHeight" format="dimension" />
</declare-styleable>
</resources>
1 change: 1 addition & 0 deletions downloader/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black_3">#333333</color>
<color name="black_6">#666666</color>
<color name="updater_positive_color">#4169E1</color>
</resources>

0 comments on commit ef6ba6e

Please sign in to comment.