fix profile edit
This commit is contained in:
3 files changed
+14
-19
No files matched your search
@@ -28,7 +28,7 @@ class ProfilesActivity : BaseActivity(), ProfileAdapter.Callback, ProfilesMenu.C
|
||||
|
||||
private var backgroundJob: Job? = null
|
||||
private val reloadMutex = Mutex()
|
||||
private val editorStack = Stack<Long>()
|
||||
private val editorStack = Stack<Profile>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -64,10 +64,11 @@ class ProfilesActivity : BaseActivity(), ProfileAdapter.Callback, ProfilesMenu.C
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == EDITOR_REQUEST_CODE) {
|
||||
launch {
|
||||
val id = editorStack.pop()
|
||||
val profile = editorStack.pop()
|
||||
|
||||
withProfile {
|
||||
startUpdate(id)
|
||||
updateMetadata(profile.id, profile)
|
||||
startUpdate(profile.id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,16 +121,13 @@ class ProfilesActivity : BaseActivity(), ProfileAdapter.Callback, ProfilesMenu.C
|
||||
startActivity(ProfileEditActivity::class.intent.putExtra("id", id))
|
||||
}
|
||||
|
||||
private fun openEditor(id: Long) = launch {
|
||||
private fun openEditor(profile: Profile) = launch {
|
||||
try {
|
||||
if (id < 0)
|
||||
throw FileNotFoundException()
|
||||
|
||||
val uri = withProfile {
|
||||
acquireTempUri(id)
|
||||
acquireTempUri(profile.id)
|
||||
} ?: throw FileNotFoundException()
|
||||
|
||||
editorStack.push(id)
|
||||
editorStack.push(profile.copy(uri = Uri.parse(uri)))
|
||||
|
||||
startActivityForResult(
|
||||
Intent(Intent.ACTION_VIEW)
|
||||
@@ -148,7 +146,7 @@ class ProfilesActivity : BaseActivity(), ProfileAdapter.Callback, ProfilesMenu.C
|
||||
}
|
||||
|
||||
override fun onOpenEditor(entity: Profile) {
|
||||
openEditor(entity.id)
|
||||
openEditor(entity)
|
||||
}
|
||||
|
||||
override fun onUpdate(entity: Profile) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.github.kr328.clash.service
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.webkit.URLUtil
|
||||
import com.github.kr328.clash.common.utils.Log
|
||||
import com.github.kr328.clash.core.Clash
|
||||
import com.github.kr328.clash.service.data.ProfileDao
|
||||
import com.github.kr328.clash.service.model.Profile
|
||||
@@ -30,6 +31,8 @@ object ProfileProcessor {
|
||||
context.resolveBaseDir(metadata.id)
|
||||
)
|
||||
|
||||
Log.d("${metadata.uri}")
|
||||
|
||||
val entity = if (metadata.type == Type.FILE)
|
||||
metadata.copy(
|
||||
uri = ProfileProvider.resolveUri(
|
||||
|
||||
@@ -145,17 +145,11 @@ class ProfileService : BaseService() {
|
||||
|
||||
val tempFile = service.resolveTempProfileFile(id)
|
||||
|
||||
file.copyTo(tempFile)
|
||||
tempFile.parentFile?.mkdirs()
|
||||
|
||||
val uri = ProfileProvider.resolveUri(service, tempFile)
|
||||
file.copyTo(tempFile, overwrite = true)
|
||||
|
||||
return runBlocking {
|
||||
lock.withLock {
|
||||
pending[id] = queryMetadataById(id)?.copy(uri = uri) ?: return@withLock
|
||||
}
|
||||
|
||||
uri.toString()
|
||||
}
|
||||
return ProfileProvider.resolveUri(service, tempFile).toString()
|
||||
}
|
||||
|
||||
override fun updateMetadata(id: Long, metadata: Profile?) {
|
||||
|
||||
Reference in new issue
Block a user