diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 33f4b5b..f7700c9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -21,7 +21,6 @@ val gKotlinVersion: String by rootExtra val gKotlinCoroutineVersion: String by rootExtra val gAppCenterVersion: String by rootExtra val gAndroidKtxVersion: String by rootExtra -val gLifecycleVersion: String by rootExtra val gRecyclerviewVersion: String by rootExtra val gAppCompatVersion: String by rootExtra val gMaterialDesignVersion: String by rootExtra @@ -96,8 +95,6 @@ dependencies { implementation(project(":common")) implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$gKotlinVersion") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$gKotlinCoroutineVersion") - implementation("androidx.lifecycle:lifecycle-extensions:$gLifecycleVersion") - implementation("androidx.lifecycle:lifecycle-common-java8:$gLifecycleVersion") implementation("androidx.recyclerview:recyclerview:$gRecyclerviewVersion") implementation("androidx.core:core-ktx:$gAndroidKtxVersion") implementation("androidx.appcompat:appcompat:$gAppCompatVersion") diff --git a/app/src/main/java/com/github/kr328/clash/fragment/ProfileEditFragment.kt b/app/src/main/java/com/github/kr328/clash/fragment/ProfileEditFragment.kt index b8409ec..e43b50e 100644 --- a/app/src/main/java/com/github/kr328/clash/fragment/ProfileEditFragment.kt +++ b/app/src/main/java/com/github/kr328/clash/fragment/ProfileEditFragment.kt @@ -25,7 +25,7 @@ class ProfileEditFragment( var uri: Uri, var interval: Long, private val type: Type, - private val source: Uri? + private val source: String? ) : Fragment() { var isModified = false @@ -176,8 +176,7 @@ class ProfileEditFragment( ) Type.EXTERNAL -> startActivityForResult( - Intent.parseUri(source?.toString(), 0) - ?: throw NullPointerException(), + source?.toIntent() ?: return false, REQUEST_CODE ) else -> return false @@ -196,4 +195,12 @@ class ProfileEditFragment( private fun Long.toStringIfNonZero(): String { return if ( this == 0L ) "" else this.toString() } + + private fun String.toIntent(): Intent? { + return try { + Intent.parseUri(this, 0) + } catch (e: Exception) { + null + } + } } \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 0e75a48..fb4b887 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,7 +19,6 @@ buildscript { this["gRoomVersion"] = "2.2.5" this["gAppCenterVersion"] = "2.5.1" this["gAndroidKtxVersion"] = "1.2.0" - this["gLifecycleVersion"] = "2.2.0" this["gRecyclerviewVersion"] = "1.1.0" this["gAppCompatVersion"] = "1.1.0" this["gMaterialDesignVersion"] = "1.1.0" diff --git a/service/src/main/java/com/github/kr328/clash/service/ProfileProcessor.kt b/service/src/main/java/com/github/kr328/clash/service/ProfileProcessor.kt index b60e042..9372380 100644 --- a/service/src/main/java/com/github/kr328/clash/service/ProfileProcessor.kt +++ b/service/src/main/java/com/github/kr328/clash/service/ProfileProcessor.kt @@ -1,6 +1,7 @@ package com.github.kr328.clash.service import android.content.Context +import android.content.Intent import android.net.Uri import android.webkit.URLUtil import com.github.kr328.clash.common.utils.Log @@ -15,6 +16,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.io.File import java.io.FileNotFoundException +import java.lang.Exception import java.util.* object ProfileProcessor { @@ -79,10 +81,19 @@ object ProfileProcessor { throw IllegalArgumentException("Invalid type") !URLUtil.isValidUrl(uri.toString()) -> throw IllegalArgumentException("Invalid uri") - source?.let { URLUtil.isValidUrl(it.toString()) } == false -> + source?.isValidIntent() == false -> throw IllegalArgumentException("Invalid source") interval < 0 -> throw IllegalArgumentException("Invalid interval") } } + + private fun String.isValidIntent(): Boolean { + return try { + Intent.parseUri(this, 0) + true + } catch (e: Exception) { + false + } + } } \ No newline at end of file diff --git a/service/src/main/java/com/github/kr328/clash/service/ProfileService.kt b/service/src/main/java/com/github/kr328/clash/service/ProfileService.kt index f311093..6092ef1 100644 --- a/service/src/main/java/com/github/kr328/clash/service/ProfileService.kt +++ b/service/src/main/java/com/github/kr328/clash/service/ProfileService.kt @@ -62,7 +62,7 @@ class ProfileService : BaseService() { name = "", type = Profile.Type.valueOf(type), uri = Uri.EMPTY, - source = source?.let { Uri.parse(it) }, + source = source, active = false, interval = 0, lastModified = 0 diff --git a/service/src/main/java/com/github/kr328/clash/service/model/Converters.kt b/service/src/main/java/com/github/kr328/clash/service/model/Converters.kt index 7496106..5e9c918 100644 --- a/service/src/main/java/com/github/kr328/clash/service/model/Converters.kt +++ b/service/src/main/java/com/github/kr328/clash/service/model/Converters.kt @@ -19,7 +19,7 @@ fun ProfileEntity.asProfile(context: Context): Profile { name = name, type = type, uri = Uri.parse(uri), - source = source?.let { Uri.parse(it) }, + source = source, active = active, interval = interval, lastModified = lastModified @@ -38,7 +38,7 @@ fun Profile.asEntity(): ProfileEntity { name = name, type = type, uri = uri.toString(), - source = source?.toString(), + source = source, active = active, interval = interval, id = id diff --git a/service/src/main/java/com/github/kr328/clash/service/model/Profile.kt b/service/src/main/java/com/github/kr328/clash/service/model/Profile.kt index 1bd8e3a..0f8ab80 100644 --- a/service/src/main/java/com/github/kr328/clash/service/model/Profile.kt +++ b/service/src/main/java/com/github/kr328/clash/service/model/Profile.kt @@ -15,7 +15,7 @@ data class Profile( val name: String, val type: Type, val uri: Uri, - val source: Uri?, + val source: String?, val active: Boolean, val interval: Long, val lastModified: Long