启动页水平加载进度条
This commit is contained in:
parent
0f0a3301d2
commit
d828a5dc05
@ -69,6 +69,8 @@ dependencies {
|
|||||||
// implementation("androidx.core:core-splashscreen:1.0.1")
|
// implementation("androidx.core:core-splashscreen:1.0.1")
|
||||||
implementation("androidx.browser:browser:1.8.0")
|
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(platform("com.google.firebase:firebase-bom:34.6.0"))
|
||||||
implementation("com.google.firebase:firebase-crashlytics")
|
implementation("com.google.firebase:firebase-crashlytics")
|
||||||
|
|||||||
@ -31,6 +31,7 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".welcome.SplashActivity"
|
android:name=".welcome.SplashActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
android:theme="@style/Theme.SplashActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
tools:ignore="SplashScreen">
|
tools:ignore="SplashScreen">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|||||||
@ -19,7 +19,9 @@ import com.ux.video.file.filerecovery.utils.ScanState
|
|||||||
import com.ux.video.file.filerecovery.utils.ScanType
|
import com.ux.video.file.filerecovery.utils.ScanType
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
|
import kotlinx.coroutines.flow.onCompletion
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlin.coroutines.cancellation.CancellationException
|
||||||
|
|
||||||
class ScanningActivity : BaseActivity<ActivityScanningBinding>() {
|
class ScanningActivity : BaseActivity<ActivityScanningBinding>() {
|
||||||
|
|
||||||
@ -94,7 +96,13 @@ class ScanningActivity : BaseActivity<ActivityScanningBinding>() {
|
|||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
val root = Environment.getExternalStorageDirectory()
|
val root = Environment.getExternalStorageDirectory()
|
||||||
ScanManager.scanAllDocuments(this@ScanningActivity, root, fileType = scanType.mediaType)
|
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) {
|
when (it) {
|
||||||
is ScanState.Progress -> {
|
is ScanState.Progress -> {
|
||||||
updateProgress(it)
|
updateProgress(it)
|
||||||
@ -175,7 +183,7 @@ class ScanningActivity : BaseActivity<ActivityScanningBinding>() {
|
|||||||
putExtra(Common.KEY_SCAN_TYPE, scanType.value)
|
putExtra(Common.KEY_SCAN_TYPE, scanType.value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ScanManager.showLog("HiddenScan", "完成: ${it.result.size}")
|
Common.showLog("完成: ${it.result.size}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -406,7 +406,7 @@ object Common {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun showLog(msg: String) {
|
fun showLog(msg: String) {
|
||||||
Log.d("============", msg)
|
Log.d("==File Recovery Tool==========", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -55,7 +55,7 @@ object ScanManager {
|
|||||||
maxFiles: Int = 5000,
|
maxFiles: Int = 5000,
|
||||||
fileType: FileType
|
fileType: FileType
|
||||||
): Flow<ScanState> = flow {
|
): Flow<ScanState> = flow {
|
||||||
|
val appContext = context.applicationContext
|
||||||
val result = mutableMapOf<String, MutableList<File>>()
|
val result = mutableMapOf<String, MutableList<File>>()
|
||||||
var fileCount = 0
|
var fileCount = 0
|
||||||
suspend fun scanDocuments(dir: File, depth: Int) {
|
suspend fun scanDocuments(dir: File, depth: Int) {
|
||||||
@ -65,6 +65,7 @@ object ScanManager {
|
|||||||
if (depth > maxDepth || fileCount >= maxFiles) return
|
if (depth > maxDepth || fileCount >= maxFiles) return
|
||||||
dir.listFiles()?.forEach { file ->
|
dir.listFiles()?.forEach { file ->
|
||||||
context.ensureActive()
|
context.ensureActive()
|
||||||
|
Common.showLog("扫描所有文件中....")
|
||||||
if (file.isDirectory) {
|
if (file.isDirectory) {
|
||||||
scanDocuments(file, depth + 1)
|
scanDocuments(file, depth + 1)
|
||||||
} else {
|
} else {
|
||||||
@ -90,7 +91,7 @@ object ScanManager {
|
|||||||
path = file.absolutePath,
|
path = file.absolutePath,
|
||||||
size = file.length(),
|
size = file.length(),
|
||||||
sizeString = Formatter.formatFileSize(
|
sizeString = Formatter.formatFileSize(
|
||||||
context,
|
appContext,
|
||||||
file.length()
|
file.length()
|
||||||
),
|
),
|
||||||
lastModified = file.lastModified(),
|
lastModified = file.lastModified(),
|
||||||
@ -99,6 +100,7 @@ object ScanManager {
|
|||||||
}
|
}
|
||||||
ResultData(dir, ArrayList(resultDataFilesList))
|
ResultData(dir, ArrayList(resultDataFilesList))
|
||||||
}
|
}
|
||||||
|
Common.showLog("扫描所有文件结束")
|
||||||
emit(ScanState.Complete(ArrayList(map)))
|
emit(ScanState.Complete(ArrayList(map)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,7 +363,7 @@ object ScanManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
success = destFile.exists() && destFile.length() > 0
|
success = destFile.exists() && destFile.length() > 0
|
||||||
Common.showLog("------------success------${success}")
|
Common.showLog("---------批量恢复---success------${success}")
|
||||||
success = true
|
success = true
|
||||||
recoveryCount++
|
recoveryCount++
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
|||||||
@ -1,28 +1,57 @@
|
|||||||
package com.ux.video.file.filerecovery.welcome
|
package com.ux.video.file.filerecovery.welcome
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.CountDownTimer
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import com.ux.video.file.filerecovery.base.BaseActivity
|
import com.ux.video.file.filerecovery.base.BaseActivity
|
||||||
import com.ux.video.file.filerecovery.databinding.ActivitySplashBinding
|
import com.ux.video.file.filerecovery.databinding.ActivitySplashBinding
|
||||||
import com.ux.video.file.filerecovery.main.MainActivity
|
import com.ux.video.file.filerecovery.main.MainActivity
|
||||||
import com.ux.video.file.filerecovery.recovery.RecoveryActivity
|
|
||||||
|
|
||||||
class SplashActivity : BaseActivity<ActivitySplashBinding>() {
|
class SplashActivity : BaseActivity<ActivitySplashBinding>() {
|
||||||
|
|
||||||
|
|
||||||
|
val time = 1500L
|
||||||
|
|
||||||
|
private var countDownTimer: CountDownTimer? = null
|
||||||
override fun inflateBinding(inflater: LayoutInflater): ActivitySplashBinding =
|
override fun inflateBinding(inflater: LayoutInflater): ActivitySplashBinding =
|
||||||
ActivitySplashBinding.inflate(inflater)
|
ActivitySplashBinding.inflate(inflater)
|
||||||
|
|
||||||
override fun initView() {
|
override fun initView() {
|
||||||
super.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))
|
startActivity(Intent(this@SplashActivity, MainActivity::class.java))
|
||||||
|
binding.lottieView.cancelAnimation()
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
override fun initData() {
|
override fun initData() {
|
||||||
super.initData()
|
super.initData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
countDownTimer?.cancel()
|
||||||
|
countDownTimer == null
|
||||||
|
binding.lottieView.cancelAnimation()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
19
app/src/main/res/drawable/progressbar_drawable.xml
Normal file
19
app/src/main/res/drawable/progressbar_drawable.xml
Normal 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>
|
||||||
@ -49,7 +49,7 @@
|
|||||||
app:tabGravity="fill"
|
app:tabGravity="fill"
|
||||||
app:tabIndicator="@drawable/tab_indicator"
|
app:tabIndicator="@drawable/tab_indicator"
|
||||||
app:tabIndicatorGravity="bottom"
|
app:tabIndicatorGravity="bottom"
|
||||||
app:tabMode="fixed" />
|
app:tabMode="scrollable" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@ -33,18 +33,40 @@
|
|||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/tv_name" />
|
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_width="match_parent"
|
||||||
android:layout_height="50dp"
|
android:layout_height="10dp"
|
||||||
android:layout_marginHorizontal="60dp"
|
android:layout_marginHorizontal="70dp"
|
||||||
android:layout_marginBottom="80dp"
|
android:layout_marginBottom="80dp"
|
||||||
android:background="@drawable/bg_welcome_enter"
|
android:progress="1"
|
||||||
android:gravity="center"
|
android:progressDrawable="@drawable/progressbar_drawable"
|
||||||
android:text="@string/enter"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="18sp"
|
|
||||||
app:fontType="alimama"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent" />
|
app:layout_constraintRight_toRightOf="parent" />
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:paddingHorizontal="16dp"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<com.ux.video.file.filerecovery.utils.CustomTextView
|
<com.ux.video.file.filerecovery.utils.CustomTextView
|
||||||
@ -11,7 +12,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="@color/selector_recovery_file_tab_layout_title"
|
android:textColor="@color/selector_recovery_file_tab_layout_title"
|
||||||
android:textSize="13sp"
|
android:textSize="16sp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
app:fontType="bold" />
|
app:fontType="bold" />
|
||||||
|
|
||||||
|
|||||||
1
app/src/main/res/raw/welcome_anime.json
Normal file
1
app/src/main/res/raw/welcome_anime.json
Normal file
File diff suppressed because one or more lines are too long
@ -30,4 +30,6 @@
|
|||||||
<color name="welcome_enter_start_color">#70ABFF</color>
|
<color name="welcome_enter_start_color">#70ABFF</color>
|
||||||
<color name="welcome_enter_end_color">#326EFF</color>
|
<color name="welcome_enter_end_color">#326EFF</color>
|
||||||
|
|
||||||
|
<color name="welcome_progress_bar_bg">#D5EBFF</color>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
@ -8,6 +8,7 @@
|
|||||||
<string name="enter">ENTER</string>
|
<string name="enter">ENTER</string>
|
||||||
<string name="welcome_name">File\nRecovery</string>
|
<string name="welcome_name">File\nRecovery</string>
|
||||||
<string name="welcome_sub_text">Important files shouldn\'t just disappear.</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>
|
<string name="size_kb">%.2f KB</string>
|
||||||
|
|||||||
@ -6,4 +6,8 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="Theme.FileRecovery" parent="Base.Theme.FileRecovery" />
|
<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>
|
</resources>
|
||||||
Loading…
Reference in New Issue
Block a user