mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
Refactor code related to navigation, close #104
New PackageChooserActivity Delete code of parsing apk metadata
This commit is contained in:
@@ -6,13 +6,19 @@ import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.result.contract.ActivityResultContract
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.navigation.NavType
|
||||
import com.bintianqi.owndroid.dpm.addDeviceAdmin
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
@@ -22,6 +28,7 @@ import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
var zhCN = true
|
||||
|
||||
@@ -93,3 +100,22 @@ fun getContext(): Context {
|
||||
}
|
||||
|
||||
const val APK_MIME = "application/vnd.android.package-archive"
|
||||
|
||||
inline fun <reified T> serializableNavTypePair() =
|
||||
typeOf<T>() to object : NavType<T>(false) {
|
||||
override fun get(bundle: Bundle, key: String): T? =
|
||||
bundle.getString(key)?.let { parseValue(it) }
|
||||
override fun put(bundle: Bundle, key: String, value: T) =
|
||||
bundle.putString(key, serializeAsValue(value))
|
||||
override fun parseValue(value: String): T =
|
||||
Json.decodeFromString(value)
|
||||
override fun serializeAsValue(value: T): String =
|
||||
Json.encodeToString(value)
|
||||
}
|
||||
|
||||
class ChoosePackageContract: ActivityResultContract<Nothing?, String?>() {
|
||||
override fun createIntent(context: Context, input: Nothing?): Intent =
|
||||
Intent(context, PackageChooserActivity::class.java)
|
||||
override fun parseResult(resultCode: Int, intent: Intent?): String? =
|
||||
intent?.getStringExtra("package")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user