细化+上游代理+1.1
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package net.bluemangoo.indpjsk.data
|
||||
|
||||
import android.content.Context
|
||||
import java.io.File
|
||||
|
||||
object CaptureFiles {
|
||||
|
||||
fun dir(context: Context): File = File(context.filesDir, "captures")
|
||||
|
||||
fun list(context: Context): List<File> {
|
||||
val root = dir(context)
|
||||
if (!root.exists()) return emptyList()
|
||||
return root.walkTopDown()
|
||||
.filter { it.isFile }
|
||||
.sortedByDescending { it.lastModified() }
|
||||
.toList()
|
||||
}
|
||||
|
||||
fun clear(context: Context) {
|
||||
val root = dir(context)
|
||||
root.deleteRecursively()
|
||||
root.mkdirs()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.bluemangoo.indpjsk.data
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.graphics.drawable.Drawable
|
||||
|
||||
data class AppEntry(
|
||||
val packageName: String,
|
||||
val label: String,
|
||||
val icon: Drawable,
|
||||
)
|
||||
|
||||
object InstalledApps {
|
||||
|
||||
fun list(context: Context): List<AppEntry> {
|
||||
val pm = context.packageManager
|
||||
return pm.getInstalledApplications(0)
|
||||
.asSequence()
|
||||
.filter { info ->
|
||||
(info.flags and ApplicationInfo.FLAG_SYSTEM) == 0 ||
|
||||
(info.flags and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0
|
||||
}
|
||||
.mapNotNull { info ->
|
||||
runCatching {
|
||||
AppEntry(
|
||||
packageName = info.packageName,
|
||||
label = pm.getApplicationLabel(info).toString(),
|
||||
icon = pm.getApplicationIcon(info),
|
||||
)
|
||||
}.getOrNull()
|
||||
}
|
||||
.distinctBy { it.packageName }
|
||||
.sortedBy { it.label.lowercase() }
|
||||
.toList()
|
||||
}
|
||||
|
||||
fun get(context: Context, packageName: String): AppEntry? = runCatching {
|
||||
val pm = context.packageManager
|
||||
val info = pm.getApplicationInfo(packageName, 0)
|
||||
AppEntry(
|
||||
packageName = packageName,
|
||||
label = pm.getApplicationLabel(info).toString(),
|
||||
icon = pm.getApplicationIcon(info),
|
||||
)
|
||||
}.getOrNull()
|
||||
}
|
||||
@@ -3,21 +3,47 @@ package net.bluemangoo.indpjsk.data
|
||||
import android.content.Context
|
||||
import androidx.core.content.edit
|
||||
|
||||
/** 一些零碎的全局设置,暂时只有上传码 */
|
||||
/** 全局配置持久化:上传码、上游代理、忽略的应用、选中的配置 */
|
||||
object SettingsStore {
|
||||
|
||||
private const val PREFS = "settings"
|
||||
private const val KEY_UPLOAD_CODE = "upload_code"
|
||||
private const val KEY_PROXY = "upstream_proxy"
|
||||
private const val KEY_BYPASS = "bypass_packages"
|
||||
private const val KEY_PROFILE = "selected_profile"
|
||||
|
||||
fun loadUploadCode(context: Context): String =
|
||||
private fun prefs(context: Context) =
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
.getString(KEY_UPLOAD_CODE, "")
|
||||
.orEmpty()
|
||||
|
||||
// ---- 上传码 ----
|
||||
fun loadUploadCode(context: Context): String =
|
||||
prefs(context).getString(KEY_UPLOAD_CODE, "").orEmpty()
|
||||
|
||||
fun saveUploadCode(context: Context, code: String) {
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
.edit {
|
||||
putString(KEY_UPLOAD_CODE, code)
|
||||
}
|
||||
prefs(context).edit { putString(KEY_UPLOAD_CODE, code) }
|
||||
}
|
||||
|
||||
// ---- 上游代理(空 = 直连) ----
|
||||
fun loadProxy(context: Context): String =
|
||||
prefs(context).getString(KEY_PROXY, "").orEmpty()
|
||||
|
||||
fun saveProxy(context: Context, proxy: String) {
|
||||
prefs(context).edit { putString(KEY_PROXY, proxy.trim()) }
|
||||
}
|
||||
|
||||
// ---- 不走 VPN 的应用(包名) ----
|
||||
fun loadBypassPackages(context: Context): Set<String> =
|
||||
prefs(context).getStringSet(KEY_BYPASS, emptySet())?.toSet() ?: emptySet()
|
||||
|
||||
fun saveBypassPackages(context: Context, packages: Set<String>) {
|
||||
prefs(context).edit { putStringSet(KEY_BYPASS, packages) }
|
||||
}
|
||||
|
||||
// ---- 当前选中的配置 ----
|
||||
fun loadSelectedProfileId(context: Context): String? =
|
||||
prefs(context).getString(KEY_PROFILE, null)
|
||||
|
||||
fun saveSelectedProfileId(context: Context, id: String) {
|
||||
prefs(context).edit { putString(KEY_PROFILE, id) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user