diff --git a/app/src/main/java/ani/dantotsu/connections/github/Contributors.kt b/app/src/main/java/ani/dantotsu/connections/github/Contributors.kt new file mode 100644 index 00000000..f796e38a --- /dev/null +++ b/app/src/main/java/ani/dantotsu/connections/github/Contributors.kt @@ -0,0 +1,84 @@ +package ani.dantotsu.connections.github + +import ani.dantotsu.Mapper +import ani.dantotsu.R +import ani.dantotsu.client +import ani.dantotsu.getAppString +import ani.dantotsu.settings.Developer +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.runBlocking +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.decodeFromJsonElement + +class Contributors { + + fun getContributors(): Array { + var developers = arrayOf() + runBlocking(Dispatchers.IO) { + val repo = getAppString(R.string.repo) + val res = client.get("https://api.github.com/repos/$repo/contributors") + .parsed().map { + Mapper.json.decodeFromJsonElement(it) + } + res.find { it.login == "rebelonion"}?.let { first -> + developers = developers.plus( + Developer( + first.login, + first.avatarUrl, + "Owner and Maintainer", + first.htmlUrl + ) + ).plus(arrayOf( + Developer( + "Wai What", + "https://avatars.githubusercontent.com/u/149729762?v=4", + "Icon Designer", + "https://github.com/WaiWhat" + ), + Developer( + "MarshMeadow", + "https://avatars.githubusercontent.com/u/88599122?v=4", + "Beta Icon Designer", + "https://github.com/MarshMeadow?tab=repositories" + ), + Developer( + "Zaxx69", + "https://avatars.githubusercontent.com/u/138523882?v=4", + "Telegram Admin", + "https://github.com/Zaxx69" + ), + Developer( + "Arif Alam", + "https://avatars.githubusercontent.com/u/70383209?v=4", + "Head Discord Moderator", + "https://youtube.com/watch?v=dQw4w9WgXcQ" + ) + )) + } + res.filter {it.login != "rebelonion"}.forEach { + developers = developers.plus( + Developer( + it.login, + it.avatarUrl, + "Contributor", + it.htmlUrl + ) + ) + } + } + return developers + } + + + @Serializable + data class GithubResponse( + @SerialName("login") + val login: String, + @SerialName("avatar_url") + val avatarUrl: String, + @SerialName("html_url") + val htmlUrl: String + ) +} \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/connections/github/Forks.kt b/app/src/main/java/ani/dantotsu/connections/github/Forks.kt new file mode 100644 index 00000000..a074eea0 --- /dev/null +++ b/app/src/main/java/ani/dantotsu/connections/github/Forks.kt @@ -0,0 +1,55 @@ +package ani.dantotsu.connections.github + +import ani.dantotsu.Mapper +import ani.dantotsu.R +import ani.dantotsu.client +import ani.dantotsu.getAppString +import ani.dantotsu.settings.Developer +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.runBlocking +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.decodeFromJsonElement + +class Forks { + + fun getForks(): Array { + var forks = arrayOf() + runBlocking(Dispatchers.IO) { + val res = client.get("https://api.github.com/repos/rebelonion/Dantotsu/forks") + .parsed().map { + Mapper.json.decodeFromJsonElement(it) + } + res.forEach { + forks = forks.plus( + Developer( + it.name, + it.owner.avatarUrl, + it.owner.login, + it.htmlUrl + ) + ) + } + } + return forks + } + + + @Serializable + data class GithubResponse( + @SerialName("name") + val name: String, + val owner: Owner, + @SerialName("html_url") + val htmlUrl: String, + ) { + @Serializable + data class Owner( + @SerialName("login") + val login: String, + @SerialName("avatar_url") + val avatarUrl: String + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/settings/DevelopersDialogFragment.kt b/app/src/main/java/ani/dantotsu/settings/DevelopersDialogFragment.kt index 3f066e48..41d465b4 100644 --- a/app/src/main/java/ani/dantotsu/settings/DevelopersDialogFragment.kt +++ b/app/src/main/java/ani/dantotsu/settings/DevelopersDialogFragment.kt @@ -6,69 +6,13 @@ import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.LinearLayoutManager import ani.dantotsu.BottomSheetDialogFragment +import ani.dantotsu.connections.github.Contributors import ani.dantotsu.databinding.BottomSheetDevelopersBinding class DevelopersDialogFragment : BottomSheetDialogFragment() { private var _binding: BottomSheetDevelopersBinding? = null private val binding get() = _binding!! - private val developers = arrayOf( - Developer( - "rebelonion", - "https://avatars.githubusercontent.com/u/87634197?v=4", - "Owner and Maintainer", - "https://github.com/rebelonion" - ), - Developer( - "Aayush262", - "https://avatars.githubusercontent.com/u/99584765?v=4", - "Contributor", - "https://github.com/aayush2622" - ), - Developer( - "Ibo", - "https://avatars.githubusercontent.com/u/41344259?v=4", - "Contributor", - "https://github.com/sneazy-ibo" - ), - Developer( - "AbandonedCart", - "https://avatars.githubusercontent.com/u/1173913?v=4", - "Contributor", - "https://github.com/AbandonedCart" - ), - Developer( - "Sadwhy", - "https://avatars.githubusercontent.com/u/99601717?v=4", - "Contributor", - "https://github.com/Sadwhy" - ), - Developer( - "Wai What", - "https://avatars.githubusercontent.com/u/149729762?v=4", - "Icon Designer", - "https://github.com/WaiWhat" - ), - Developer( - "MarshMeadow", - "https://avatars.githubusercontent.com/u/88599122?v=4", - "Beta Icon Designer", - "https://github.com/MarshMeadow?tab=repositories" - ), - Developer( - "Zaxx69", - "https://avatars.githubusercontent.com/u/138523882?v=4", - "Telegram Admin", - "https://github.com/Zaxx69" - ), - Developer( - "Arif Alam", - "https://avatars.githubusercontent.com/u/70383209?v=4", - "Head Discord Moderator", - "https://youtube.com/watch?v=dQw4w9WgXcQ" - ), - ) - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -80,7 +24,7 @@ class DevelopersDialogFragment : BottomSheetDialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - binding.devsRecyclerView.adapter = DevelopersAdapter(developers) + binding.devsRecyclerView.adapter = DevelopersAdapter(Contributors().getContributors()) binding.devsRecyclerView.layoutManager = LinearLayoutManager(requireContext()) } diff --git a/app/src/main/java/ani/dantotsu/settings/ForksDialogFragment.kt b/app/src/main/java/ani/dantotsu/settings/ForksDialogFragment.kt index b1a4db01..74d00972 100644 --- a/app/src/main/java/ani/dantotsu/settings/ForksDialogFragment.kt +++ b/app/src/main/java/ani/dantotsu/settings/ForksDialogFragment.kt @@ -7,21 +7,13 @@ import android.view.ViewGroup import androidx.recyclerview.widget.LinearLayoutManager import ani.dantotsu.BottomSheetDialogFragment import ani.dantotsu.R +import ani.dantotsu.connections.github.Forks import ani.dantotsu.databinding.BottomSheetDevelopersBinding class ForksDialogFragment : BottomSheetDialogFragment() { private var _binding: BottomSheetDevelopersBinding? = null private val binding get() = _binding!! - private val developers = arrayOf( - Developer( - "Dantotsu", - "https://avatars.githubusercontent.com/u/87634197?v=4", - "rebelonion", - "https://github.com/rebelonion/Dantotsu" - ), - ) - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -34,7 +26,7 @@ class ForksDialogFragment : BottomSheetDialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.devsTitle.setText(R.string.forks) - binding.devsRecyclerView.adapter = DevelopersAdapter(developers) + binding.devsRecyclerView.adapter = DevelopersAdapter(Forks().getForks()) binding.devsRecyclerView.layoutManager = LinearLayoutManager(requireContext()) }