-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(settings/about): redesign credits & add libraries
- Loading branch information
1 parent
73a321f
commit d3bb609
Showing
21 changed files
with
614 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
app/src/main/java/com/aliernfrog/pftool/impl/CreditData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.aliernfrog.pftool.impl | ||
|
||
import android.util.Log | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import com.aliernfrog.pftool.TAG | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.json.JSONObject | ||
import java.net.URL | ||
|
||
class CreditData( | ||
val name: Any, | ||
val githubUsername: String? = null, | ||
val description: Any, | ||
val link: String? = githubUsername?.let { "https://github.com/$githubUsername" } | ||
) { | ||
private var fetchedAvatar = false | ||
var avatarURL by mutableStateOf<String?>(null) | ||
|
||
suspend fun fetchAvatar() { | ||
if (fetchedAvatar) return | ||
fetchedAvatar = true | ||
if (githubUsername == null) return | ||
withContext(Dispatchers.IO) { | ||
try { | ||
val res = URL("https://api.github.com/users/$githubUsername").readText() | ||
val json = JSONObject(res) | ||
avatarURL = json.getString("avatar_url") | ||
} catch (e: Exception) { | ||
Log.e(TAG, "CreditData/fetchAvatar: ", e) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.