Skip to content

Commit

Permalink
mesh gradient remote resources support
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Jan 3, 2025
1 parent 0f9c7a5 commit d089687
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,53 @@ internal class AndroidRemoteResourcesStore @Inject constructor(
}.onFailure(onFailure).getOrNull()
}

override suspend fun getResourceLinks(
name: String
): RemoteResources? = withContext(defaultDispatcher) {
runCatching {
val connection = URL(getResourcesLink(name)).openConnection() as HttpURLConnection

connection.apply {
doOutput = false
requestMethod = "GET"
setRequestProperty("Accept-Charset", Charsets.UTF_8.toString())
connectTimeout = 15000
connect()
}

val result = StringBuilder()

connection.inputStream.bufferedReader().use { reader ->
var line: String?
while ((reader.readLine().also { line = it }) != null) {
result.append(line)
}
}

var items = JSONArray(result.toString())

val resources = mutableSetOf<RemoteResource>()

for (i in 0..<items.length()) {
val item = items.getJSONObject(i)
val fileName = item.get("name") as String
val url = item.get("download_url") as String

resources.add(
RemoteResource(
uri = url,
name = fileName.decodeEscaped()
)
)
}

RemoteResources(
name = name,
list = resources.toList()
)
}.getOrNull()
}

private fun getResourcesLink(
dirName: String
): String = BaseUrl.replace("*", dirName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ data class RemoteResources(

companion object {
const val CUBE_LUT = "cubelut"
const val MESH_GRADIENTS = "mesh_gradient"

val CubeLutDefault = RemoteResources(
name = CUBE_LUT,
list = emptyList()
)

val MeshGradientsDefault = RemoteResources(
name = MESH_GRADIENTS,
list = emptyList()
)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ interface RemoteResourcesStore {
downloadOnlyNewData: Boolean = false
): RemoteResources?

suspend fun getResourceLinks(
name: String
): RemoteResources?

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class BaseComponent(

inline fun debounce(
time: Long = 150,
crossinline block: () -> Unit
crossinline block: suspend () -> Unit
) {
componentScope.launch {
delay(time)
Expand Down

0 comments on commit d089687

Please sign in to comment.