optimize file selector

This commit is contained in:
1
2025-10-31 16:54:46 +08:00
parent 880c8c95bb
commit f6d09580fd
3 changed files with 12 additions and 4 deletions

View File

@@ -21,13 +21,11 @@ import com.donut.mixfile.util.reveiver.NetworkChangeReceiver
class MainActivity : MixActivity(MAIN_ID) {
companion object {
lateinit var mixFileSelector: MixFileSelector
lateinit var networkChangeReceiver: NetworkChangeReceiver
}
override fun onDestroy() {
super.onDestroy()
mixFileSelector.unregister()
unregisterReceiver(networkChangeReceiver)
}
@@ -36,7 +34,6 @@ class MainActivity : MixActivity(MAIN_ID) {
}
override fun onCreate(savedInstanceState: Bundle?) {
mixFileSelector = MixFileSelector(this)
super.onCreate(savedInstanceState)
val intentFilter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
networkChangeReceiver = NetworkChangeReceiver

View File

@@ -18,6 +18,7 @@ import androidx.compose.ui.Modifier
import com.donut.mixfile.MainActivity
import com.donut.mixfile.app
import com.donut.mixfile.appScope
import com.donut.mixfile.currentActivity
import com.donut.mixfile.server.core.utils.StreamContent
import com.donut.mixfile.server.core.utils.extensions.kb
import com.donut.mixfile.server.core.utils.extensions.mb
@@ -215,7 +216,7 @@ fun uploadFileUris(uriList: List<Uri>) {
@SuppressLint("Recycle")
fun selectAndUploadFile() {
MainActivity.mixFileSelector.openSelect { uriList ->
currentActivity?.fileSelector?.openSelect { uriList ->
uploadFileUris(uriList)
}
}

View File

@@ -2,8 +2,10 @@
package com.donut.mixfile.util.objects
import android.os.Bundle
import android.view.WindowManager
import androidx.activity.ComponentActivity
import com.donut.mixfile.util.file.MixFileSelector
open class MixActivity(private val id: String) : ComponentActivity() {
@@ -13,6 +15,7 @@ open class MixActivity(private val id: String) : ComponentActivity() {
var isActive = false
var lastPause = System.currentTimeMillis()
lateinit var fileSelector: MixFileSelector
companion object {
const val MAIN_ID = "main"
@@ -28,8 +31,14 @@ open class MixActivity(private val id: String) : ComponentActivity() {
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
fileSelector = MixFileSelector(this)
}
override fun onDestroy() {
super.onDestroy()
fileSelector.unregister()
referenceCache[id]?.remove(this)
}
@@ -60,3 +69,4 @@ open class MixActivity(private val id: String) : ComponentActivity() {
}