diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 446cdb23..ccbbe1a7 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -20,15 +20,6 @@
-
diff --git a/design/src/main/java/com/github/kr328/clash/design/util/I18n.kt b/design/src/main/java/com/github/kr328/clash/design/util/I18n.kt
index 702256a2..d3d7e624 100644
--- a/design/src/main/java/com/github/kr328/clash/design/util/I18n.kt
+++ b/design/src/main/java/com/github/kr328/clash/design/util/I18n.kt
@@ -65,4 +65,12 @@ fun Long.toBytesString(): String {
else ->
"$this Bytes"
}
+}
+
+fun Double.toProgress(): Int {
+ return this.toInt()
+}
+fun Long.toDateStr(): String {
+ val simpleDateFormat =SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+ return simpleDateFormat.format(Date(this*1000))
}
\ No newline at end of file
diff --git a/design/src/main/res/drawable/bg_b.xml b/design/src/main/res/drawable/bg_b.xml
new file mode 100644
index 00000000..d02498d0
--- /dev/null
+++ b/design/src/main/res/drawable/bg_b.xml
@@ -0,0 +1,12 @@
+
+
+ -
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/design/src/main/res/layout/adapter_profile.xml b/design/src/main/res/layout/adapter_profile.xml
index fc88e80c..17e8b278 100644
--- a/design/src/main/res/layout/adapter_profile.xml
+++ b/design/src/main/res/layout/adapter_profile.xml
@@ -13,16 +13,18 @@
-
+
+
+
+
+
+
+
+
+
+ android:background="@color/color_clash_dark" />
+ if (!response.isSuccessful || response.headers["subscription-userinfo"] == null) return
+
+ var upload: Long = 0
+ var download: Long = 0
+ var total: Long = 0
+ var expire: Long = 0
+
+ val userinfo = response.headers["subscription-userinfo"]
+ if (response.isSuccessful && userinfo != null) {
+
+ val flags = userinfo.split(";")
+ for (flag in flags) {
+ val info = flag.split("=")
+ when {
+ info[0].contains("upload") -> upload =
+ info[1].toLong()
+
+ info[0].contains("download") -> download =
+ info[1].toLong()
+
+ info[0].contains("total") -> total =
+ info[1].toLong()
+
+ info[0].contains("expire") -> {
+ if (info[1].isNotEmpty()) {
+ expire = info[1].toLong()
+ }
+ }
+ }
+ }
+ }
+
+ val new = Imported(
+ old.uuid,
+ old.name,
+ old.type,
+ old.source,
+ old.interval,
+ upload,
+ download,
+ total,
+ expire,
+ old?.createdAt ?: System.currentTimeMillis()
+ )
+
+ if (old != null) {
+ ImportedDao().update(new)
+ } else {
+ ImportedDao().insert(new)
+ }
+
+ PendingDao().remove(new.uuid)
+ context.sendProfileChanged(new.uuid)
+ // println(response.body!!.string())
+ }
+
+ } catch (e: Exception) {
+ System.out.println(e)
+ }
}
override suspend fun commit(uuid: UUID, callback: IFetchObserver?) {
@@ -163,6 +258,10 @@ class ProfileManager(private val context: Context) : IProfileManager,
val type = pending?.type ?: imported?.type ?: return null
val source = pending?.source ?: imported?.source ?: return null
val interval = pending?.interval ?: imported?.interval ?: return null
+ val upload = pending?.upload ?: imported?.upload ?: return null
+ val download = pending?.download ?: imported?.download ?: return null
+ val total = pending?.total ?: imported?.total ?: return null
+ val expire = pending?.expire ?: imported?.expire ?: return null
return Profile(
uuid,
@@ -171,6 +270,10 @@ class ProfileManager(private val context: Context) : IProfileManager,
source,
active != null && imported?.uuid == active,
interval,
+ upload,
+ download,
+ total,
+ expire,
resolveUpdatedAt(uuid),
imported != null,
pending != null
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 f7d13f12..9c395650 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
@@ -19,6 +19,8 @@ import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
+import okhttp3.OkHttpClient
+import okhttp3.Request
import java.util.*
import java.util.concurrent.TimeUnit
@@ -65,28 +67,93 @@ object ProfileProcessor {
.copyRecursively(context.importedDir.resolve(snapshot.uuid.toString()))
val old = ImportedDao().queryByUUID(snapshot.uuid)
+ var upload: Long = 0
+ var download: Long = 0
+ var total: Long = 0
+ var expire: Long = 0
+ if (snapshot?.type == Profile.Type.Url) {
+ val client = OkHttpClient()
+ val request = Request.Builder()
+ .url(snapshot.source)
+ .header("User-Agent", "ClashforWindows/0.19.23")
+ .build()
- val new = Imported(
- snapshot.uuid,
- snapshot.name,
- snapshot.type,
- snapshot.source,
- snapshot.interval,
- old?.createdAt ?: System.currentTimeMillis()
- )
+ client.newCall(request).execute().use { response ->
+ val userinfo = response.headers["subscription-userinfo"]
+ if (response.isSuccessful && userinfo != null) {
+ val flags = userinfo.split(";")
+ for (flag in flags) {
+ val info = flag.split("=")
+ when {
+ info[0].contains("upload") -> upload =
+ info[1].toLong()
- if (old != null) {
- ImportedDao().update(new)
- } else {
- ImportedDao().insert(new)
+ info[0].contains("download") -> download =
+ info[1].toLong()
+
+ info[0].contains("total") -> total =
+ info[1].toLong()
+
+ info[0].contains("expire") -> {
+ if (info[1].isNotEmpty()) {
+ expire = info[1].toLong()
+ }
+ }
+ }
+ }
+
+ }
+ val new = Imported(
+ snapshot.uuid,
+ snapshot.name,
+ snapshot.type,
+ snapshot.source,
+ snapshot.interval,
+ upload,
+ download,
+ total,
+ expire,
+ old?.createdAt ?: System.currentTimeMillis()
+ )
+ if (old != null) {
+ ImportedDao().update(new)
+ } else {
+ ImportedDao().insert(new)
+ }
+
+ PendingDao().remove(snapshot.uuid)
+
+ context.pendingDir.resolve(snapshot.uuid.toString())
+ .deleteRecursively()
+
+ context.sendProfileChanged(snapshot.uuid)
+ }
+ } else if (snapshot?.type == Profile.Type.File) {
+ val new = Imported(
+ snapshot.uuid,
+ snapshot.name,
+ snapshot.type,
+ snapshot.source,
+ snapshot.interval,
+ upload,
+ download,
+ total,
+ expire,
+ old?.createdAt ?: System.currentTimeMillis()
+ )
+ if (old != null) {
+ ImportedDao().update(new)
+ } else {
+ ImportedDao().insert(new)
+ }
+
+ PendingDao().remove(snapshot.uuid)
+
+ context.pendingDir.resolve(snapshot.uuid.toString())
+ .deleteRecursively()
+
+ context.sendProfileChanged(snapshot.uuid)
}
-
- PendingDao().remove(snapshot.uuid)
-
- context.pendingDir.resolve(snapshot.uuid.toString())
- .deleteRecursively()
-
- context.sendProfileChanged(snapshot.uuid)
}
}
}
@@ -181,10 +248,13 @@ object ProfileProcessor {
when {
name.isBlank() ->
throw IllegalArgumentException("Empty name")
+
source.isEmpty() && type != Profile.Type.File ->
throw IllegalArgumentException("Invalid url")
+
source.isNotEmpty() && scheme != "https" && scheme != "http" && scheme != "content" ->
throw IllegalArgumentException("Unsupported url $source")
+
interval != 0L && TimeUnit.MILLISECONDS.toMinutes(interval) < 15 ->
throw IllegalArgumentException("Invalid interval")
}
diff --git a/service/src/main/java/com/github/kr328/clash/service/data/Imported.kt b/service/src/main/java/com/github/kr328/clash/service/data/Imported.kt
index 4d5dc0bf..571c556f 100644
--- a/service/src/main/java/com/github/kr328/clash/service/data/Imported.kt
+++ b/service/src/main/java/com/github/kr328/clash/service/data/Imported.kt
@@ -14,5 +14,9 @@ data class Imported(
@ColumnInfo(name = "type") val type: Profile.Type,
@ColumnInfo(name = "source") val source: String,
@ColumnInfo(name = "interval") val interval: Long,
+ @ColumnInfo(name = "upload") val upload: Long,
+ @ColumnInfo(name = "download") val download: Long,
+ @ColumnInfo(name = "total") val total: Long,
+ @ColumnInfo(name = "expire") val expire: Long,
@ColumnInfo(name = "createdAt") val createdAt: Long,
)
\ No newline at end of file
diff --git a/service/src/main/java/com/github/kr328/clash/service/data/Pending.kt b/service/src/main/java/com/github/kr328/clash/service/data/Pending.kt
index d9ba780b..2df5d656 100644
--- a/service/src/main/java/com/github/kr328/clash/service/data/Pending.kt
+++ b/service/src/main/java/com/github/kr328/clash/service/data/Pending.kt
@@ -14,5 +14,9 @@ data class Pending(
@ColumnInfo(name = "type") val type: Profile.Type,
@ColumnInfo(name = "source") val source: String,
@ColumnInfo(name = "interval") val interval: Long,
+ @ColumnInfo(name = "upload") val upload: Long,
+ @ColumnInfo(name = "download") val download: Long,
+ @ColumnInfo(name = "total") val total: Long,
+ @ColumnInfo(name = "expire") val expire: Long,
@ColumnInfo(name = "createdAt") val createdAt: Long = System.currentTimeMillis(),
)
\ No newline at end of file
diff --git a/service/src/main/java/com/github/kr328/clash/service/data/migrations/LegacyMigration.kt b/service/src/main/java/com/github/kr328/clash/service/data/migrations/LegacyMigration.kt
index 6959fd56..5155bcb8 100644
--- a/service/src/main/java/com/github/kr328/clash/service/data/migrations/LegacyMigration.kt
+++ b/service/src/main/java/com/github/kr328/clash/service/data/migrations/LegacyMigration.kt
@@ -92,7 +92,8 @@ private suspend fun migrationFromLegacy234(
type = newType,
source = if (newType != Profile.Type.File) cursor.getString(uri) else "",
interval = if (version == 2) intervalValue * 1000 else intervalValue,
- )
+ 0,0,0,0
+ )
val base = context.pendingDir.resolve(pending.uuid.toString())
@@ -165,6 +166,7 @@ private suspend fun migrationFromLegacy1(context: Context, legacy: SQLiteDatabas
type = newType,
source = source,
interval = 0,
+ 0,0,0,0
)
val base = context.pendingDir.resolve(pending.uuid.toString())
diff --git a/service/src/main/java/com/github/kr328/clash/service/document/Picker.kt b/service/src/main/java/com/github/kr328/clash/service/document/Picker.kt
index dae06a8b..aa08829c 100644
--- a/service/src/main/java/com/github/kr328/clash/service/document/Picker.kt
+++ b/service/src/main/java/com/github/kr328/clash/service/document/Picker.kt
@@ -133,7 +133,8 @@ class Picker(private val context: Context) {
imported.name,
imported.type,
imported.source,
- imported.interval
+ imported.interval,
+ 0,0,0,0
)
)
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 d8363a3a..4c2b4980 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
@@ -18,6 +18,11 @@ data class Profile(
val source: String,
val active: Boolean,
val interval: Long,
+ val upload: Long,
+ var download: Long,
+ val total: Long,
+ val expire: Long,
+
val updatedAt: Long,
val imported: Boolean,