Browse Source

lpac-jni: Add lookup from progress to state

Peter Cai 1 year ago
parent
commit
f236b40cd4

+ 12 - 0
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/ProfileDownloadCallback.kt

@@ -1,6 +1,18 @@
 package net.typeblog.lpac_jni
 
 interface ProfileDownloadCallback {
+    companion object {
+        fun lookupStateFromProgress(progress: Int): DownloadState =
+            when (progress) {
+                0 -> DownloadState.Preparing
+                20 -> DownloadState.Connecting
+                40 -> DownloadState.Authenticating
+                60 -> DownloadState.Downloading
+                80 -> DownloadState.Finalizing
+                else -> throw IllegalArgumentException("Unknown state")
+            }
+    }
+
     enum class DownloadState(val progress: Int) {
         Preparing(0),
         Connecting(20), // Before {server,client} authentication