fix external profile

This commit is contained in:
Kr328 committed 2020-04-14 19:47:16 +08:00
1 parent eaf16318de
commit 545c43fe2c
7 files changed
+26 -12

No files matched your search

-3
View File
@@ -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")
@@ -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
}
}
}
-1
View File
@@ -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"
@@ -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
}
}
}
@@ -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
@@ -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
@@ -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