启动页水平加载进度条

This commit is contained in:
litingting 2026-01-08 14:03:23 +08:00
parent 0f0a3301d2
commit d828a5dc05
14 changed files with 115 additions and 23 deletions

View File

@ -69,6 +69,8 @@ dependencies {
// implementation("androidx.core:core-splashscreen:1.0.1")
implementation("androidx.browser:browser:1.8.0")
implementation("com.airbnb.android:lottie:6.7.1")
implementation(platform("com.google.firebase:firebase-bom:34.6.0"))
implementation("com.google.firebase:firebase-crashlytics")

View File

@ -31,6 +31,7 @@
<activity
android:name=".welcome.SplashActivity"
android:exported="true"
android:theme="@style/Theme.SplashActivity"
android:screenOrientation="portrait"
tools:ignore="SplashScreen">
<intent-filter>

View File

@ -19,7 +19,9 @@ import com.ux.video.file.filerecovery.utils.ScanState
import com.ux.video.file.filerecovery.utils.ScanType
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.launch
import kotlin.coroutines.cancellation.CancellationException
class ScanningActivity : BaseActivity<ActivityScanningBinding>() {
@ -94,7 +96,13 @@ class ScanningActivity : BaseActivity<ActivityScanningBinding>() {
repeatOnLifecycle(Lifecycle.State.STARTED) {
val root = Environment.getExternalStorageDirectory()
ScanManager.scanAllDocuments(this@ScanningActivity, root, fileType = scanType.mediaType)
.flowOn(Dispatchers.IO).collect {
.flowOn(Dispatchers.IO)
.onCompletion { cause ->
if (cause is CancellationException) {
Common.showLog( "扫描文件 Flow 被取消")
}
}
.collect {
when (it) {
is ScanState.Progress -> {
updateProgress(it)
@ -175,7 +183,7 @@ class ScanningActivity : BaseActivity<ActivityScanningBinding>() {
putExtra(Common.KEY_SCAN_TYPE, scanType.value)
})
}
ScanManager.showLog("HiddenScan", "完成: ${it.result.size}")
Common.showLog("完成: ${it.result.size}")
}
}
}

View File

@ -406,7 +406,7 @@ object Common {
}
fun showLog(msg: String) {
Log.d("============", msg)
Log.d("==File Recovery Tool==========", msg)
}

View File

@ -55,7 +55,7 @@ object ScanManager {
maxFiles: Int = 5000,
fileType: FileType
): Flow<ScanState> = flow {
val appContext = context.applicationContext
val result = mutableMapOf<String, MutableList<File>>()
var fileCount = 0
suspend fun scanDocuments(dir: File, depth: Int) {
@ -65,6 +65,7 @@ object ScanManager {
if (depth > maxDepth || fileCount >= maxFiles) return
dir.listFiles()?.forEach { file ->
context.ensureActive()
Common.showLog("扫描所有文件中....")
if (file.isDirectory) {
scanDocuments(file, depth + 1)
} else {
@ -90,7 +91,7 @@ object ScanManager {
path = file.absolutePath,
size = file.length(),
sizeString = Formatter.formatFileSize(
context,
appContext,
file.length()
),
lastModified = file.lastModified(),
@ -99,6 +100,7 @@ object ScanManager {
}
ResultData(dir, ArrayList(resultDataFilesList))
}
Common.showLog("扫描所有文件结束")
emit(ScanState.Complete(ArrayList(map)))
}
@ -361,7 +363,7 @@ object ScanManager {
}
success = destFile.exists() && destFile.length() > 0
Common.showLog("------------success------${success}")
Common.showLog("---------批量恢复---success------${success}")
success = true
recoveryCount++
withContext(Dispatchers.Main) {

View File

@ -1,28 +1,57 @@
package com.ux.video.file.filerecovery.welcome
import android.content.Intent
import android.os.CountDownTimer
import android.view.LayoutInflater
import com.ux.video.file.filerecovery.base.BaseActivity
import com.ux.video.file.filerecovery.databinding.ActivitySplashBinding
import com.ux.video.file.filerecovery.main.MainActivity
import com.ux.video.file.filerecovery.recovery.RecoveryActivity
class SplashActivity : BaseActivity<ActivitySplashBinding>() {
val time = 1500L
private var countDownTimer: CountDownTimer? = null
override fun inflateBinding(inflater: LayoutInflater): ActivitySplashBinding =
ActivitySplashBinding.inflate(inflater)
override fun initView() {
super.initView()
binding.textEnter.setOnClickListener {
binding.lottieView.playAnimation()
binding.lottieView.speed = 8f
countDownTimer = object : CountDownTimer(time, 100) {
override fun onFinish() {
enterMain()
}
override fun onTick(millisUntilFinished: Long) {
val progress =
100f - (millisUntilFinished.toFloat() / time.toFloat() * 100f)
binding.progressBar.progress = progress.toInt()
}
}.also { it.start() }
}
private fun enterMain() {
binding.progressBar.progress = 100
startActivity(Intent(this@SplashActivity, MainActivity::class.java))
binding.lottieView.cancelAnimation()
finish()
}
}
override fun initData() {
super.initData()
}
override fun onDestroy() {
super.onDestroy()
countDownTimer?.cancel()
countDownTimer == null
binding.lottieView.cancelAnimation()
}
}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="@color/welcome_progress_bar_bg" />
</shape>
</item>
<item android:id="@android:id/progress">
<scale
android:scaleWidth="100%"
android:gravity="left">>
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="@color/color_title_blue" />
</shape>
</scale>
</item>
</layer-list>

View File

@ -49,7 +49,7 @@
app:tabGravity="fill"
app:tabIndicator="@drawable/tab_indicator"
app:tabIndicatorGravity="bottom"
app:tabMode="fixed" />
app:tabMode="scrollable" />
<LinearLayout
android:layout_width="match_parent"

View File

@ -33,18 +33,40 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_name" />
<com.ux.video.file.filerecovery.utils.CustomTextView
android:id="@+id/text_enter"
<!-- <com.ux.video.file.filerecovery.utils.CustomTextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginBottom="20dp"-->
<!-- android:text="@string/loading"-->
<!-- android:textColor="@color/main_sub_title"-->
<!-- android:textSize="16sp"-->
<!-- app:fontType="bold"-->
<!-- app:layout_constraintBottom_toTopOf="@id/progress_bar"-->
<!-- app:layout_constraintLeft_toLeftOf="parent"-->
<!-- app:layout_constraintRight_toRightOf="parent" />-->
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottieView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toTopOf="@id/progress_bar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/welcome_anime" />
<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginHorizontal="60dp"
android:layout_height="10dp"
android:layout_marginHorizontal="70dp"
android:layout_marginBottom="80dp"
android:background="@drawable/bg_welcome_enter"
android:gravity="center"
android:text="@string/enter"
android:textColor="@color/white"
android:textSize="18sp"
app:fontType="alimama"
android:progress="1"
android:progressDrawable="@drawable/progressbar_drawable"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />

View File

@ -4,6 +4,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:paddingHorizontal="16dp"
android:orientation="vertical">
<com.ux.video.file.filerecovery.utils.CustomTextView
@ -11,7 +12,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/selector_recovery_file_tab_layout_title"
android:textSize="13sp"
android:textSize="16sp"
android:gravity="center"
app:fontType="bold" />

File diff suppressed because one or more lines are too long

View File

@ -30,4 +30,6 @@
<color name="welcome_enter_start_color">#70ABFF</color>
<color name="welcome_enter_end_color">#326EFF</color>
<color name="welcome_progress_bar_bg">#D5EBFF</color>
</resources>

View File

@ -8,6 +8,7 @@
<string name="enter">ENTER</string>
<string name="welcome_name">File\nRecovery</string>
<string name="welcome_sub_text">Important files shouldn\'t just disappear.</string>
<string name="loading">Loading...</string>
<string name="size_kb">%.2f KB</string>

View File

@ -6,4 +6,8 @@
</style>
<style name="Theme.FileRecovery" parent="Base.Theme.FileRecovery" />
<style name="Theme.SplashActivity" parent="Base.Theme.FileRecovery">
<item name="android:windowBackground">@drawable/welcome_bg</item>
</style>
</resources>