Skip to content

Commit

Permalink
进入下级目录时,提前加载当前文件夹上下两个文件夹内的文件
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Aug 10, 2024
1 parent d948e1d commit e45e069
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 24 deletions.
24 changes: 12 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "github.zerorooot.nap511"
minSdk 26
targetSdk 34
versionCode 3
versionName "1.1.1"
versionCode 4
versionName "1.1.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -56,7 +56,7 @@ dependencies {
//setting screen
// implementation "com.github.JamalMulla:ComposePrefs3:1.0.3"
implementation "com.github.JamalMulla:ComposePrefs:1.0.6"
implementation "androidx.datastore:datastore-preferences:1.1.0"
implementation "androidx.datastore:datastore-preferences:1.1.1"

// implementation 'androidx.browser:browser:1.5.0'
// implementation 'com.android.support:customtabs:24.1.1'
Expand Down Expand Up @@ -89,27 +89,27 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.compose.material:material-icons-extended:$compose_version"
// implementation "com.google.accompanist:accompanist-swiperefresh:0.29.1-alpha"
// implementation 'androidx.window:window-core:'
implementation "androidx.navigation:navigation-compose:2.7.7"

def lifecycle_version = "2.7.0"
def lifecycle_version = "2.8.4"
// ViewModel
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
// ViewModel utilities for Compose
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version")
// LiveData
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")

implementation 'androidx.work:work-runtime-ktx:2.9.0'
implementation 'androidx.work:work-runtime-ktx:2.9.1'

implementation 'androidx.core:core-ktx:1.13.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0'
implementation 'androidx.activity:activity-compose:1.9.0'
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.4'
implementation 'androidx.activity:activity-compose:1.9.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-util:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
Expand All @@ -120,8 +120,8 @@ dependencies {
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3"
testImplementation "org.mockito:mockito-core:1.9.5"

androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
Expand Down
29 changes: 21 additions & 8 deletions app/src/main/java/github/zerorooot/nap511/screen/FileScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import kotlin.concurrent.thread
import kotlin.math.log

@SuppressLint(
"UnusedMaterial3ScaffoldPaddingParameter",
Expand Down Expand Up @@ -146,16 +147,28 @@ fun FileScreen(
} else {
// //记录上级目录当前的位置
fileViewModel.setListLocationAndClickCache(i)

val currentFileBean = fileBeanList[i]
val currentPath = path

//进入下一级
val fileBean = fileViewModel.fileBeanList[i]
val fileBean = fileBeanList[i]
if (fileBean.isFolder) {
//提前加载上下两个文件夹
if (DataStoreUtil.getData(ConfigUtil.earlyLoading, false)) {
val before = i - 1
val after = i + 1
if (before >= 0 && fileBeanList[before].isFolder) {
fileViewModel.updateFileCache(fileBeanList[before].categoryId)
}
if (after < fileBeanList.size && fileBeanList[after].isFolder) {
fileViewModel.updateFileCache(fileBeanList[after].categoryId)
}
// try {
// println("fileBean ${fileBean.name} before ${fileBeanList[before].name} after ${fileBeanList[after].name} ")
// } catch (_: Exception) {
// }
}
//加载文件
fileViewModel.getFiles(fileBean.categoryId)
}
//todo click to remember

if (fileBean.isVideo == 1) {
val intent = Intent(activity, VideoActivity::class.java)
intent.putExtra("cookie", App.cookie)
Expand All @@ -175,9 +188,9 @@ fun FileScreen(


//滚动到当前目录
if (currentFileBean.isFolder) {
if (fileBean.isFolder) {
fileViewModel.getListLocation(
currentPath + "/${currentFileBean.name}"
path + "/${fileBean.name}"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ fun SettingScreen() {
summary = "根据视频横竖自动旋转屏幕",
)
}
prefsItem {
SwitchPref(
key = ConfigUtil.earlyLoading,
title = "提前加载",
summary = "进入下级目录时,提前加载当前文件夹上下两个文件夹内的文件",
)
}
prefsItem {
EditTextPref(
key = ConfigUtil.defaultOfflineCid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ConfigUtil {
const val offlineMethod = "offlineMethod"
const val defaultOfflineTime = "defaultOfflineTime"
const val errorDownloadCid = "errorDownloadCid"
const val earlyLoading="EarlyLoading"

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,13 @@ class FileViewModel(private val cookie: String, private val application: Applica
imageBeanCache[currentCid] = imageBeanList
}

private fun updateFileCache(cid: String) {
fun updateFileCache(cid: String) {
viewModelScope.launch {
_isRefreshing.value = true
if (fileListCache.containsKey(cid)) {
_isRefreshing.value = false
return@launch
}
fileService.order(
hashMapOf(
"user_order" to orderBean.type,
Expand All @@ -195,6 +200,7 @@ class FileViewModel(private val cookie: String, private val application: Applica
setFileBeanProperty(files.fileBeanList)
// setFiles(files)
fileListCache[cid] = files
_isRefreshing.value = false
}
}

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
buildscript {
ext {
compose_version = '1.6.6'
compose_version = '1.6.8'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.1.1' apply false
id 'com.android.library' version '8.1.1' apply false
id 'com.android.application' version '8.1.4' apply false
id 'com.android.library' version '8.1.4' apply false
id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
}

0 comments on commit e45e069

Please sign in to comment.