Skip to content

Commit b48d912

Browse files
committed
feat: 更新到v1.8.1-fix
1 parent 6a3a3d0 commit b48d912

File tree

14 files changed

+93
-73
lines changed

14 files changed

+93
-73
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ android {
2929
applicationId "com.lanzou.cloud"
3030
minSdk 24
3131
targetSdk 35
32-
versionCode 19
33-
versionName "1.8.1"
32+
versionCode 20
33+
versionName "1.8.1-fix"
3434

3535
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3636
signingConfig signingConfigs.debug

app/src/main/java/com/lanzou/cloud/model/FileInfoModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ data class FileInfoModel(
1919
var folderId: String = "",
2020
@SerialName("name_all")
2121
val nameAll: String = "",
22-
var name: String = nameAll,
22+
var name: String = "",
2323
@Transient
2424
var path: String = "",
2525
@Transient

app/src/main/java/com/lanzou/cloud/model/FilePathModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ data class FilePathModel(
77
* 可以是路径,可以是文件夹 id
88
*/
99
val path: String = Environment.getExternalStorageDirectory().path,
10+
val name: String = "",
1011
var scrollPosition: Int = 0,
1112
)

app/src/main/java/com/lanzou/cloud/network/LanzouRepository.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ object LanzouRepository {
6464
map[item.attr("name")] = item.attr("value")
6565
}
6666

67-
6867
val result2 = Post<String>(Api.DISK_PHP) {
6968
addQuery("item", "profile")
7069
for ((key, value) in map.entries) {
@@ -169,9 +168,7 @@ object LanzouRepository {
169168
param("task", task)
170169
param("folder_id", folderId)
171170
param("pg", page)
172-
}.await()?.onEach {
173-
getFileRealName(it)
174-
} ?: emptyList()
171+
}.await() ?: emptyList()
175172
}
176173

177174
suspend fun getFileInfo(id: String) = coroutineScope {
@@ -208,6 +205,7 @@ object LanzouRepository {
208205
private fun getFileRealName(fileInfoModel: FileInfoModel) {
209206
val ext = fileInfoModel.extension
210207
val name = fileInfoModel.nameAll
208+
fileInfoModel.name = fileInfoModel.nameAll
211209

212210
val isApk = "apk" == ext
213211

app/src/main/java/com/lanzou/cloud/network/Repository.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ public static Repository getInstance() {
7777
"bds", "bdi", "conf", "it"
7878
};
7979

80-
private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36";
81-
private static final String ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
82-
80+
private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0";
81+
private static final String ACCEPT = "*/*";
8382
private static final String ACCEPT_LANGUAGE = "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6";
8483

8584
private static final Pattern filePattern = Pattern

app/src/main/java/com/lanzou/cloud/service/DownloadService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ private void startDownload(Download download) throws Exception {
464464
Objects.requireNonNull(downloadUrl, "获取下载地址失败");
465465
Log.i(TAG, "downloadUrl: " + downloadUrl);
466466

467-
repository.getResponse(downloadUrl);
467+
// repository.getResponse(downloadUrl);
468468

469469
// 获取到响应信息,注意:这里获取到的可能不是完整响应,因为需要断点续传
470470
Response response = repository.getRangeResponse(downloadUrl, download.getCurrent());

app/src/main/java/com/lanzou/cloud/ui/fragment/FileFragment.kt

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
44
import android.view.Menu
55
import android.view.MenuInflater
66
import android.view.MenuItem
7+
import androidx.appcompat.app.AppCompatActivity
78
import androidx.core.view.MenuProvider
89
import androidx.fragment.app.viewModels
910
import androidx.lifecycle.Lifecycle
@@ -270,6 +271,14 @@ abstract class FileFragment(
270271
}
271272
}
272273

274+
fun refreshPathSubTitle() {
275+
val pageType = when (filePageType) {
276+
FilePageType.LOCAL -> "本地"
277+
FilePageType.REMOTE -> "远程"
278+
}
279+
(activity as? AppCompatActivity)?.supportActionBar?.subtitle = pageType + " - " + getFullPath()
280+
}
281+
273282
override fun onResume() {
274283
super.onResume()
275284
viewModel.refreshLogin()
@@ -322,7 +331,8 @@ abstract class FileFragment(
322331
}
323332
paths[paths.lastIndex].scrollPosition = getFirstVisiblePosition()
324333
val path = model.path.ifEmpty { model.folderId }
325-
paths.add(FilePathModel(path))
334+
paths.add(FilePathModel(path = path, name = model.name))
335+
refreshPathSubTitle()
326336
binding.refresh.showLoading()
327337
}
328338

@@ -350,6 +360,7 @@ abstract class FileFragment(
350360
return true
351361
}
352362
paths.removeAt(paths.lastIndex)
363+
refreshPathSubTitle()
353364
refresh()
354365
return false
355366
}
@@ -473,6 +484,8 @@ abstract class FileFragment(
473484
return paths.lastOrNull()?.path
474485
}
475486

487+
open fun getFullPath() = paths.joinToString("/") { it.name }
488+
476489
override fun getCheckedFiles(ignoreDirectory: Boolean): List<FileInfoModel> {
477490
return models.filter { it.isChecked && (!ignoreDirectory || it.isFile) }
478491
}
@@ -557,7 +570,9 @@ abstract class FileFragment(
557570
.setMessage("确认要删除文件: ${file.name}")
558571
.setPositiveButton("确认") { dialog, _ ->
559572
scopeDialog {
560-
File(file.path).deleteRecursively()
573+
withIO {
574+
File(file.path).deleteRecursively()
575+
}
561576
removeFile(position, file)
562577
}.finally {
563578
toggleMulti(false)
@@ -569,9 +584,11 @@ abstract class FileFragment(
569584

570585
override fun deleteFiles(positions: List<Int>, files: List<FileInfoModel>) {
571586
scopeDialog {
572-
files.forEach {
573-
if (it.path.isNotEmpty()) {
574-
File(it.path).deleteRecursively()
587+
withIO {
588+
files.forEach {
589+
if (it.path.isNotEmpty()) {
590+
File(it.path).deleteRecursively()
591+
}
575592
}
576593
}
577594
binding.fileRv.removeModels(positions) {
@@ -668,13 +685,13 @@ abstract class FileFragment(
668685
if (current.path == targetFilePath) {
669686
return null
670687
}
671-
if (current.isDirectory) {
672-
if (FileUtils.moveDir(current.path, targetFilePath) { true }) {
673-
return current.copy(path = targetFilePath)
674-
}
675-
return null
688+
val result = if (current.isDirectory) {
689+
FileUtils.moveDir(current.path, targetFilePath) { true }
690+
} else {
691+
FileUtils.moveFile(current.path, targetFilePath) { true }
676692
}
677-
if (FileUtils.moveFile(current.path, targetFilePath) { true }) {
693+
694+
if (result) {
678695
return current.copy(path = targetFilePath)
679696
}
680697
return null
@@ -694,21 +711,18 @@ abstract class FileFragment(
694711
targetPath: String?
695712
): FileInfoModel? {
696713
targetPath ?: return null
697-
// FIXME: 不判断存不存在,暂时直接替换文件
698714
val targetFilePath = targetPath + File.separator + current.name
699715
if (current.path == targetFilePath) {
700716
return null
701717
}
702-
if (current.isDirectory) {
703-
if (FileUtils.copyDir(current.path, targetFilePath) { true }) {
704-
return current.copy(path = targetFilePath)
705-
}
706-
} else {
707-
if (FileUtils.copyFile(current.path, targetFilePath) { true }) {
708-
return current.copy(path = targetFilePath)
709-
}
718+
try {
719+
val file = File(current.path)
720+
val target = File(targetFilePath)
721+
file.copyRecursively(target, true)
722+
return current.copy(path = targetFilePath)
723+
} catch (_: Exception) {
724+
return null
710725
}
711-
return null
712726
}
713727

714728
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {

app/src/main/java/com/lanzou/cloud/ui/fragment/HomeFragment.kt

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class HomeFragment : EngineNavFragment<FragmentHomeBinding>(R.layout.fragment_ho
189189
override fun onPageSelected(position: Int) {
190190
homeViewModel.focusPosition(paths[position].fragment.layoutPosition)
191191
requireActivity().invalidateMenu()
192+
currentFileFragment.refreshPathSubTitle()
192193
}
193194
}
194195

@@ -251,8 +252,6 @@ class HomeFragment : EngineNavFragment<FragmentHomeBinding>(R.layout.fragment_ho
251252
file.deleteRecursively()
252253
}
253254
}
254-
255-
// 加载所需的页面数据
256255
}
257256

258257
override fun initData() {
@@ -282,6 +281,7 @@ class HomeFragment : EngineNavFragment<FragmentHomeBinding>(R.layout.fragment_ho
282281
lifecycleScope.launch {
283282
homeViewModel.focusedPositionFlow.collect {
284283
requireActivity().invalidateMenu()
284+
currentFileFragment.refreshPathSubTitle()
285285
}
286286
}
287287
}
@@ -555,28 +555,9 @@ class HomeFragment : EngineNavFragment<FragmentHomeBinding>(R.layout.fragment_ho
555555
.onItemClick = { itemPosition ->
556556
when (itemPosition) {
557557
"上传", "下载" -> showTransmissionDialog(fileInfoModel, position, filePageType)
558-
"分享" -> {
559-
currentFileFragment.shareFile(position, fileInfoModel)
560-
}
561-
562-
"复制" -> {
563-
if (filePageType != FilePageType.REMOTE) {
564-
val targetPath = targetFileFragment.getCurrentPath()
565-
scopeDialog {
566-
// 暂时不显示复制的进度
567-
withIO {
568-
currentFileFragment.copyFile(position, fileInfoModel, targetPath)
569-
}?.let {
570-
targetFileFragment.addFile(it)
571-
} ?: toast("发生错误或不能复制到这里")
572-
}
573-
} else {
574-
toast("远程路径不支持复制")
575-
}
576-
}
577-
558+
"分享" -> currentFileFragment.shareFile(position, fileInfoModel)
559+
"复制" -> copyFile(position, fileInfoModel)
578560
"移动" -> moveFile(position, fileInfoModel)
579-
580561
"删除" -> currentFileFragment.deleteFile(position, fileInfoModel)
581562
"重命名" -> currentFileFragment.renameFile(position, fileInfoModel)
582563
"详情" -> currentFileFragment.showDetail(position, fileInfoModel)
@@ -679,7 +660,7 @@ class HomeFragment : EngineNavFragment<FragmentHomeBinding>(R.layout.fragment_ho
679660
folderId.toLong(),
680661
folderName
681662
) { upload ->
682-
if (target != targetFileFragment) {
663+
if (view == null) {
683664
return@uploadFile
684665
}
685666
when (upload.status) {
@@ -696,7 +677,7 @@ class HomeFragment : EngineNavFragment<FragmentHomeBinding>(R.layout.fragment_ho
696677
}
697678
}
698679

699-
Upload.ERROR -> target.refresh()
680+
Upload.ERROR -> {}
700681
}
701682
}
702683
}
@@ -710,17 +691,15 @@ class HomeFragment : EngineNavFragment<FragmentHomeBinding>(R.layout.fragment_ho
710691
fileInfoModel.name,
711692
filePath
712693
) { download ->
713-
if (target != targetFileFragment || view == null) {
694+
if (view == null) {
714695
return@addDownloadWithPath
715696
}
716697
when (download.status) {
717698
Upload.PROGRESS, Upload.COMPLETE -> target.getFile(filePath)?.let {
718699
it.progress = download.progress
719700
}
720701

721-
Upload.ERROR -> target.getFile(filePath)?.let {
722-
target.refresh()
723-
}
702+
Upload.ERROR -> {}
724703
}
725704
}
726705
}
@@ -730,7 +709,7 @@ class HomeFragment : EngineNavFragment<FragmentHomeBinding>(R.layout.fragment_ho
730709
val target = targetFileFragment
731710
val paths = checkedFiles.map { it.path }
732711
uploadService.uploadFiles(paths, path.toLong(), folderName) { upload ->
733-
if (target != targetFileFragment || view == null) {
712+
if (view == null) {
734713
return@uploadFiles
735714
}
736715
when (upload.status) {
@@ -761,7 +740,7 @@ class HomeFragment : EngineNavFragment<FragmentHomeBinding>(R.layout.fragment_ho
761740
it.path = directory + File.separator + it.name
762741
}
763742
downloadService.addDownload(checkedFiles) { download ->
764-
if (target != targetFileFragment) {
743+
if (view == null) {
765744
return@addDownload
766745
}
767746
when (download.status) {
@@ -795,7 +774,9 @@ class HomeFragment : EngineNavFragment<FragmentHomeBinding>(R.layout.fragment_ho
795774
scopeDialog {
796775
val currentPath = targetFileFragment.getCurrentPath()
797776
checkedFiles.forEachIndexed { position, fileInfoModel ->
798-
currentFileFragment.moveFile(position, fileInfoModel, currentPath)?.let {
777+
withIO {
778+
currentFileFragment.moveFile(position, fileInfoModel, currentPath)
779+
}?.let {
799780
currentFileFragment.removeFile(-1, fileInfoModel)
800781
targetFileFragment.addFile(it)
801782
}
@@ -805,12 +786,26 @@ class HomeFragment : EngineNavFragment<FragmentHomeBinding>(R.layout.fragment_ho
805786
}
806787
}
807788

789+
private fun copyFile(position: Int, fileInfoModel: FileInfoModel) {
790+
val targetPath = targetFileFragment.getCurrentPath()
791+
scopeDialog {
792+
// 暂时不显示复制的进度
793+
withIO {
794+
currentFileFragment.copyFile(position, fileInfoModel, targetPath)
795+
}?.let {
796+
targetFileFragment.addFile(it)
797+
} ?: toast("发生错误或不能复制到这里")
798+
}
799+
}
800+
808801
private fun copyFiles(checkedFiles: List<FileInfoModel>) {
809802
// 只能本地对本地复制
810803
scopeDialog {
811804
val currentPath = targetFileFragment.getCurrentPath()
812805
checkedFiles.forEachIndexed { position, fileInfoModel ->
813-
currentFileFragment.copyFile(position, fileInfoModel, currentPath)?.let {
806+
withIO {
807+
currentFileFragment.copyFile(position, fileInfoModel, currentPath)
808+
}?.let {
814809
targetFileFragment.addFile(it)
815810
}
816811
}

app/src/main/java/com/lanzou/cloud/ui/fragment/LanzouFileFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class LanzouFileFragment(
4747
override fun initData() {
4848
super.initData()
4949
val folderId = arguments?.getString(PARAM_FOLDER_ID) ?: "-1"
50-
paths.add(FilePathModel(path = folderId))
50+
paths.add(FilePathModel(name = "根目录", path = folderId))
5151
}
5252

5353
override suspend fun getData(path: String?, page: Int): List<FileInfoModel> {

app/src/main/java/com/lanzou/cloud/ui/fragment/UploadAppSelectorFragment.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class UploadAppSelectorFragment(position: LayoutPosition = LayoutPosition.RIGHT)
5252
return true
5353
}
5454

55+
override fun getFullPath(): String {
56+
return "App"
57+
}
58+
5559
override fun deleteFiles(positions: List<Int>, files: List<FileInfoModel>) {
5660
toast("不支持多选删除App")
5761
}

0 commit comments

Comments
 (0)