From b372230b5e5b0d22bbfe40949a49b2ad77227dac Mon Sep 17 00:00:00 2001 From: "maarten.vercruysse" Date: Sun, 25 Jun 2023 21:33:35 +0200 Subject: [PATCH 1/6] WIP --- app/build.gradle.kts | 47 ++++++++ app/get_instances.gradle.kts | 110 ++++++++++++++++++ app/src/main/AndroidManifest.xml | 17 +-- .../main/java/com/jerboa/DefaultInstances.kt | 61 ++++++++++ app/src/main/java/com/jerboa/Utils.kt | 17 --- app/src/release/AndroidManifest.xml | 17 +++ 6 files changed, 237 insertions(+), 32 deletions(-) create mode 100644 app/get_instances.gradle.kts create mode 100644 app/src/main/java/com/jerboa/DefaultInstances.kt create mode 100644 app/src/release/AndroidManifest.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 31584ac53..9ceab24cf 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,5 +1,8 @@ @file:Suppress("UnstableApiUsage") + +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet + plugins { id("com.android.application") id("org.jetbrains.kotlin.android") @@ -7,6 +10,8 @@ plugins { id("androidx.baselineprofile") } +apply(from = "get_instances.gradle.kts") + android { compileSdk = 33 @@ -23,6 +28,7 @@ android { useSupportLibrary = true } ksp { arg("room.schemaLocation", "$projectDir/schemas") } + manifestPlaceholders["deepLinks_manifestPlaceholder"] = genManifestHosts() } if (project.hasProperty("RELEASE_STORE_FILE")) { @@ -158,3 +164,44 @@ dependencies { implementation("androidx.profileinstaller:profileinstaller:1.3.1") baselineProfile(project(":benchmarks")) } + + +fun genManifestHosts(): String { + + val DEFAULT_LEMMY_INSTANCES = arrayOf( + "lemmy.world", // 13699 monthly users + "lemmy.ml", // 4164 monthly users + "beehaw.org", // 3708 monthly users + "feddit.de", // 2300 monthly users + "sh.itjust.works", // 2189 monthly users + "www.hexbear.net", // 1600 monthly users + ) + + return DEFAULT_LEMMY_INSTANCES.map { "" }.joinToString { "\n" } +} + +tasks.register("modifyManifest") { + doLast { + android.applicationVariants.all { variant -> + variant.outputs.forEach { output -> + val task = output.processManifestProvider.get() + task. + task.doLast { + val manifestFile = File (this.outputs.files., "AndroidManifest.xml") + var manifestContent = manifestFile.readText(Charsets.UTF_8) + + // Perform any modifications to the manifestContent string as needed + // For example, replace a placeholder with a custom value + manifestContent = manifestContent.replace("%CUSTOM_KEY%", "customValue") + + // Write the modified manifest back to the file + val writeSuccessful = manifestFile.writeText(manifestContent, Charsets.UTF_8, true) + if (!writeSuccessful) { + throw GradleException("Failed to write modified manifest file: ${manifestFile.absolutePath}") + } + } + } + true + } + } +} diff --git a/app/get_instances.gradle.kts b/app/get_instances.gradle.kts new file mode 100644 index 000000000..3522581b3 --- /dev/null +++ b/app/get_instances.gradle.kts @@ -0,0 +1,110 @@ +import java.io.OutputStreamWriter +import java.net.URL +import java.net.HttpURLConnection + +// We can't import libraries here for some reason, so we must use what is provided +// by gradle, which isn't much. The groovy JSON library is meant for use by groovy code, +// so we need some creativity to use it in Kotlin. +import org.apache.groovy.json.internal.LazyMap +import groovy.json.JsonOutput +import groovy.json.JsonSlurper + +val endpointUrl = "https://api.fediverse.observer/" +val instancesFilePath = "src/main/java/com/jerboa/DefaultInstances.kt" +val minimumMAU = 50 + +// Some extension methods to make the JsonSlurper output easier to process +fun LazyMap.getMap(key: String): LazyMap { + return this[key] as LazyMap +} + +fun LazyMap.getArray(key: String): ArrayList<*> { + return this[key] as ArrayList<*> +} + +@Suppress("UNCHECKED_CAST") +fun LazyMap.getAs(key: String): T { + return this[key] as T +} + +// Run this as `./gradlew app:fetchInstances -no-configuration-cache` +tasks.register("fetchInstances") { + description = "Fetches a list of popular Lemmy instances and writes it to the DefaultInstances.kt file" + + doFirst { + val url = URL(endpointUrl) + val query = """ +{ + nodes(softwarename: "lemmy") { + domain + active_users_monthly + } +}""" + + // Format JSON request body + val body = JsonOutput.toJson(mapOf("query" to query)) + + // Create POST request + val req = url.openConnection() as HttpURLConnection + req.requestMethod = "POST" + req.doOutput = true + req.setRequestProperty("Content-Type", "application/json") + + // Write body to request + OutputStreamWriter(req.outputStream, "UTF-8").use { + it.write(body) + } + + // Get response and JSON parse it + val json = JsonSlurper().parse(req.inputStream.reader()) as LazyMap + + // Get sorted list of nodes + val nodes = json + .getMap("data") + .getArray("nodes") + .map { + val name = (it as LazyMap)["domain"] as String + val users = it["active_users_monthly"] as Int? + + Pair(name, users ?: 0) + } + .filter { + it.second >= minimumMAU + } + .sortedBy { + it.second + } + .reversed() + + // Create output file and write header + val outFile = file(instancesFilePath) + outFile.writeText( + """package com.jerboa + +val DEFAULT_LEMMY_INSTANCES = arrayOf( +""" + ) + + // Write each node's name, one per line + for (n in nodes) { + outFile.appendText(" \"${n.first}\", // ${n.second!!.toInt()} monthly users\n") + } + + outFile.appendText(")\n") + } +} + + +fun genManifestHosts(): String { + + val DEFAULT_LEMMY_INSTANCES = arrayOf( + "lemmy.world", // 13699 monthly users + "lemmy.ml", // 4164 monthly users + "beehaw.org", // 3708 monthly users + "feddit.de", // 2300 monthly users + "sh.itjust.works", // 2189 monthly users + "www.hexbear.net", // 1600 monthly users + ) + + return DEFAULT_LEMMY_INSTANCES.map { "" }.joinToString { "\n" } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0b6927abb..13e849555 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -43,7 +43,7 @@ android:launchMode="standard" android:allowTaskReparenting="true" android:windowSoftInputMode="adjustResize" - > + tools:node="merge"> @@ -65,20 +65,7 @@ - - - - - - - - - - - - - - + ${deepLinks_manifestPlaceholder} diff --git a/app/src/main/java/com/jerboa/DefaultInstances.kt b/app/src/main/java/com/jerboa/DefaultInstances.kt new file mode 100644 index 000000000..edb36c3f2 --- /dev/null +++ b/app/src/main/java/com/jerboa/DefaultInstances.kt @@ -0,0 +1,61 @@ +@file:JvmName("DefaultInstances") +package com.jerboa + +val DEFAULT_LEMMY_INSTANCES = arrayOf( + "lemmy.world", // 13699 monthly users + "lemmy.ml", // 4164 monthly users + "beehaw.org", // 3708 monthly users + "feddit.de", // 2300 monthly users + "sh.itjust.works", // 2189 monthly users + "www.hexbear.net", // 1600 monthly users + "lemmy.ca", // 1078 monthly users + "lemmynsfw.com", // 1058 monthly users + "lemmy.one", // 987 monthly users + "lemm.ee", // 972 monthly users + "lemmy.fmhy.ml", // 930 monthly users + "lemmy.dbzer0.com", // 776 monthly users + "lemmy.blahaj.zone", // 758 monthly users + "lemmygrad.ml", // 624 monthly users + "programming.dev", // 608 monthly users + "discuss.tchncs.de", // 560 monthly users + "sopuli.xyz", // 556 monthly users + "lemmy.sdf.org", // 476 monthly users + "midwest.social", // 396 monthly users + "vlemmy.net", // 389 monthly users + "aussie.zone", // 371 monthly users + "startrek.website", // 317 monthly users + "feddit.uk", // 286 monthly users + "infosec.pub", // 277 monthly users + "dormi.zone", // 269 monthly users + "feddit.it", // 257 monthly users + "pawb.social", // 242 monthly users + "feddit.nl", // 197 monthly users + "burggit.moe", // 184 monthly users + "slrpnk.net", // 176 monthly users + "lemmy.nz", // 168 monthly users + "delraymisfitsboard.com", // 158 monthly users + "feddit.dk", // 158 monthly users + "mander.xyz", // 148 monthly users + "reddthat.com", // 148 monthly users + "feddit.cl", // 123 monthly users + "lemmy.zip", // 118 monthly users + "lemmy.pt", // 100 monthly users + "dataterm.digital", // 86 monthly users + "szmer.info", // 85 monthly users + "latte.isnot.coffee", // 85 monthly users + "monyet.cc", // 85 monthly users + "exploding-heads.com", // 83 monthly users + "lemmy.eco.br", // 79 monthly users + "lemmy.tedomum.net", // 78 monthly users + "waveform.social", // 78 monthly users + "enterprise.lemmy.ml", // 71 monthly users + "pathofexile-discuss.com", // 71 monthly users + "iusearchlinux.fyi", // 64 monthly users + "yiffit.net", // 61 monthly users + "ttrpg.network", // 61 monthly users + "lemmyrs.org", // 59 monthly users + "sub.wetshaving.social", // 57 monthly users + "monero.town", // 54 monthly users + "bakchodi.org", // 53 monthly users + "geddit.social", // 50 monthly users +) diff --git a/app/src/main/java/com/jerboa/Utils.kt b/app/src/main/java/com/jerboa/Utils.kt index 8be319ce6..9ebf32833 100644 --- a/app/src/main/java/com/jerboa/Utils.kt +++ b/app/src/main/java/com/jerboa/Utils.kt @@ -83,23 +83,6 @@ val gson = Gson() const val DEBOUNCE_DELAY = 1000L const val MAX_POST_TITLE_LENGTH = 200 -val DEFAULT_LEMMY_INSTANCES = listOf( - "beehaw.org", - "feddit.de", - "feddit.it", - "lemmy.ca", - "lemmy.ml", - "lemmy.one", - "lemmy.world", - "lemmygrad.ml", - "midwest.social", - "mujico.org", - "sh.itjust.works", - "slrpnk.net", - "sopuli.xyz", - "szmer.info", -) - // convert a data class to a map fun T.serializeToMap(): Map { return convert() diff --git a/app/src/release/AndroidManifest.xml b/app/src/release/AndroidManifest.xml new file mode 100644 index 000000000..670abec4b --- /dev/null +++ b/app/src/release/AndroidManifest.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + \ No newline at end of file From cd477e37bd7f276b307beed1d4e43ba4314f684f Mon Sep 17 00:00:00 2001 From: "maarten.vercruysse" Date: Mon, 26 Jun 2023 02:46:28 +0200 Subject: [PATCH 2/6] Generate lemmy instance list --- CONTRIBUTING.md | 24 +++ app/build.gradle.kts | 44 +----- app/get_instances.gradle.kts | 110 -------------- app/src/main/AndroidManifest.xml | 59 +++++++- .../main/java/com/jerboa/DefaultInstances.kt | 61 ++++---- app/src/main/java/com/jerboa/Utils.kt | 6 +- .../ui/components/inbox/InboxActivity.kt | 4 +- app/update_instances.gradle.kts | 138 ++++++++++++++++++ 8 files changed, 256 insertions(+), 190 deletions(-) delete mode 100644 app/get_instances.gradle.kts create mode 100644 app/update_instances.gradle.kts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dd59fbacc..7f03dc501 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,8 @@ * [Kotlin](#kotlin) * [Code quality](#code-quality) * [Adding translations](#adding-translations) + * [Updating the instance list](#updating-the-instance-list) + * [Generate compose compiler metrics](#generate-compose-compiler-metrics) @@ -73,3 +75,25 @@ prettier --write "*.md" "*.yml"` You can find the translations in the `app/src/main/res/values-{locale}/strings.xml` file. You can open it in android studio, right click and click open translations editor or you can directly edit the files. + +## Updating the instance list + +There is a custom gradle task that generates all the lemmy instances that this app directly supports. +It updates the lemmy instances list in DefaultInstances.kt and the AndroidManifest. +It uses the fediverse api and filters on the monthly users. +You can run it by doing + +```shell + ./gradlew app:updateInstances -no-configuration-cache +``` + +## Generate compose compiler metrics + +You can generate the compose compiler metrics by executing the following gradle task. + +```shell +./gradlew assembleRelease --rerun-tasks -P com.jerboa.enableComposeCompilerReports=true +``` + +Then you will find the metrics in `app/build/compose_metrics` directory. +See [this link for more information on these metrics](https://github.com/androidx/androidx/blob/androidx-main/compose/compiler/design/compiler-metrics.md) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9ceab24cf..2a282a7ce 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,8 +1,5 @@ @file:Suppress("UnstableApiUsage") - -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet - plugins { id("com.android.application") id("org.jetbrains.kotlin.android") @@ -10,7 +7,7 @@ plugins { id("androidx.baselineprofile") } -apply(from = "get_instances.gradle.kts") +apply(from = "update_instances.gradle.kts") android { compileSdk = 33 @@ -28,7 +25,6 @@ android { useSupportLibrary = true } ksp { arg("room.schemaLocation", "$projectDir/schemas") } - manifestPlaceholders["deepLinks_manifestPlaceholder"] = genManifestHosts() } if (project.hasProperty("RELEASE_STORE_FILE")) { @@ -166,42 +162,4 @@ dependencies { } -fun genManifestHosts(): String { - - val DEFAULT_LEMMY_INSTANCES = arrayOf( - "lemmy.world", // 13699 monthly users - "lemmy.ml", // 4164 monthly users - "beehaw.org", // 3708 monthly users - "feddit.de", // 2300 monthly users - "sh.itjust.works", // 2189 monthly users - "www.hexbear.net", // 1600 monthly users - ) - - return DEFAULT_LEMMY_INSTANCES.map { "" }.joinToString { "\n" } -} -tasks.register("modifyManifest") { - doLast { - android.applicationVariants.all { variant -> - variant.outputs.forEach { output -> - val task = output.processManifestProvider.get() - task. - task.doLast { - val manifestFile = File (this.outputs.files., "AndroidManifest.xml") - var manifestContent = manifestFile.readText(Charsets.UTF_8) - - // Perform any modifications to the manifestContent string as needed - // For example, replace a placeholder with a custom value - manifestContent = manifestContent.replace("%CUSTOM_KEY%", "customValue") - - // Write the modified manifest back to the file - val writeSuccessful = manifestFile.writeText(manifestContent, Charsets.UTF_8, true) - if (!writeSuccessful) { - throw GradleException("Failed to write modified manifest file: ${manifestFile.absolutePath}") - } - } - } - true - } - } -} diff --git a/app/get_instances.gradle.kts b/app/get_instances.gradle.kts deleted file mode 100644 index 3522581b3..000000000 --- a/app/get_instances.gradle.kts +++ /dev/null @@ -1,110 +0,0 @@ -import java.io.OutputStreamWriter -import java.net.URL -import java.net.HttpURLConnection - -// We can't import libraries here for some reason, so we must use what is provided -// by gradle, which isn't much. The groovy JSON library is meant for use by groovy code, -// so we need some creativity to use it in Kotlin. -import org.apache.groovy.json.internal.LazyMap -import groovy.json.JsonOutput -import groovy.json.JsonSlurper - -val endpointUrl = "https://api.fediverse.observer/" -val instancesFilePath = "src/main/java/com/jerboa/DefaultInstances.kt" -val minimumMAU = 50 - -// Some extension methods to make the JsonSlurper output easier to process -fun LazyMap.getMap(key: String): LazyMap { - return this[key] as LazyMap -} - -fun LazyMap.getArray(key: String): ArrayList<*> { - return this[key] as ArrayList<*> -} - -@Suppress("UNCHECKED_CAST") -fun LazyMap.getAs(key: String): T { - return this[key] as T -} - -// Run this as `./gradlew app:fetchInstances -no-configuration-cache` -tasks.register("fetchInstances") { - description = "Fetches a list of popular Lemmy instances and writes it to the DefaultInstances.kt file" - - doFirst { - val url = URL(endpointUrl) - val query = """ -{ - nodes(softwarename: "lemmy") { - domain - active_users_monthly - } -}""" - - // Format JSON request body - val body = JsonOutput.toJson(mapOf("query" to query)) - - // Create POST request - val req = url.openConnection() as HttpURLConnection - req.requestMethod = "POST" - req.doOutput = true - req.setRequestProperty("Content-Type", "application/json") - - // Write body to request - OutputStreamWriter(req.outputStream, "UTF-8").use { - it.write(body) - } - - // Get response and JSON parse it - val json = JsonSlurper().parse(req.inputStream.reader()) as LazyMap - - // Get sorted list of nodes - val nodes = json - .getMap("data") - .getArray("nodes") - .map { - val name = (it as LazyMap)["domain"] as String - val users = it["active_users_monthly"] as Int? - - Pair(name, users ?: 0) - } - .filter { - it.second >= minimumMAU - } - .sortedBy { - it.second - } - .reversed() - - // Create output file and write header - val outFile = file(instancesFilePath) - outFile.writeText( - """package com.jerboa - -val DEFAULT_LEMMY_INSTANCES = arrayOf( -""" - ) - - // Write each node's name, one per line - for (n in nodes) { - outFile.appendText(" \"${n.first}\", // ${n.second!!.toInt()} monthly users\n") - } - - outFile.appendText(")\n") - } -} - - -fun genManifestHosts(): String { - - val DEFAULT_LEMMY_INSTANCES = arrayOf( - "lemmy.world", // 13699 monthly users - "lemmy.ml", // 4164 monthly users - "beehaw.org", // 3708 monthly users - "feddit.de", // 2300 monthly users - "sh.itjust.works", // 2189 monthly users - "www.hexbear.net", // 1600 monthly users - ) - - return DEFAULT_LEMMY_INSTANCES.map { "" }.joinToString { "\n" } -} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 13e849555..3093ff2b5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -65,7 +65,64 @@ - ${deepLinks_manifestPlaceholder} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/jerboa/DefaultInstances.kt b/app/src/main/java/com/jerboa/DefaultInstances.kt index edb36c3f2..48a291275 100644 --- a/app/src/main/java/com/jerboa/DefaultInstances.kt +++ b/app/src/main/java/com/jerboa/DefaultInstances.kt @@ -1,57 +1,56 @@ -@file:JvmName("DefaultInstances") package com.jerboa val DEFAULT_LEMMY_INSTANCES = arrayOf( - "lemmy.world", // 13699 monthly users - "lemmy.ml", // 4164 monthly users - "beehaw.org", // 3708 monthly users + "lemmy.world", // 13856 monthly users + "lemmy.ml", // 4206 monthly users + "beehaw.org", // 3730 monthly users "feddit.de", // 2300 monthly users - "sh.itjust.works", // 2189 monthly users - "www.hexbear.net", // 1600 monthly users - "lemmy.ca", // 1078 monthly users - "lemmynsfw.com", // 1058 monthly users + "sh.itjust.works", // 2215 monthly users + "www.hexbear.net", // 1603 monthly users + "lemmynsfw.com", // 1122 monthly users + "lemmy.ca", // 1092 monthly users "lemmy.one", // 987 monthly users - "lemm.ee", // 972 monthly users - "lemmy.fmhy.ml", // 930 monthly users - "lemmy.dbzer0.com", // 776 monthly users - "lemmy.blahaj.zone", // 758 monthly users - "lemmygrad.ml", // 624 monthly users - "programming.dev", // 608 monthly users - "discuss.tchncs.de", // 560 monthly users - "sopuli.xyz", // 556 monthly users + "lemm.ee", // 984 monthly users + "lemmy.fmhy.ml", // 944 monthly users + "lemmy.dbzer0.com", // 782 monthly users + "lemmy.blahaj.zone", // 769 monthly users + "lemmygrad.ml", // 629 monthly users + "programming.dev", // 617 monthly users + "discuss.tchncs.de", // 564 monthly users + "sopuli.xyz", // 561 monthly users "lemmy.sdf.org", // 476 monthly users + "vlemmy.net", // 398 monthly users "midwest.social", // 396 monthly users - "vlemmy.net", // 389 monthly users - "aussie.zone", // 371 monthly users + "aussie.zone", // 373 monthly users "startrek.website", // 317 monthly users + "infosec.pub", // 286 monthly users "feddit.uk", // 286 monthly users - "infosec.pub", // 277 monthly users "dormi.zone", // 269 monthly users - "feddit.it", // 257 monthly users + "feddit.it", // 260 monthly users "pawb.social", // 242 monthly users "feddit.nl", // 197 monthly users - "burggit.moe", // 184 monthly users - "slrpnk.net", // 176 monthly users - "lemmy.nz", // 168 monthly users + "burggit.moe", // 185 monthly users + "slrpnk.net", // 178 monthly users + "lemmy.nz", // 166 monthly users + "feddit.dk", // 159 monthly users "delraymisfitsboard.com", // 158 monthly users - "feddit.dk", // 158 monthly users - "mander.xyz", // 148 monthly users - "reddthat.com", // 148 monthly users + "mander.xyz", // 152 monthly users + "reddthat.com", // 152 monthly users "feddit.cl", // 123 monthly users "lemmy.zip", // 118 monthly users "lemmy.pt", // 100 monthly users "dataterm.digital", // 86 monthly users "szmer.info", // 85 monthly users "latte.isnot.coffee", // 85 monthly users + "lemmy.eco.br", // 85 monthly users "monyet.cc", // 85 monthly users "exploding-heads.com", // 83 monthly users - "lemmy.eco.br", // 79 monthly users - "lemmy.tedomum.net", // 78 monthly users "waveform.social", // 78 monthly users - "enterprise.lemmy.ml", // 71 monthly users + "lemmy.tedomum.net", // 76 monthly users + "enterprise.lemmy.ml", // 72 monthly users "pathofexile-discuss.com", // 71 monthly users - "iusearchlinux.fyi", // 64 monthly users - "yiffit.net", // 61 monthly users + "iusearchlinux.fyi", // 65 monthly users + "yiffit.net", // 62 monthly users "ttrpg.network", // 61 monthly users "lemmyrs.org", // 59 monthly users "sub.wetshaving.social", // 57 monthly users diff --git a/app/src/main/java/com/jerboa/Utils.kt b/app/src/main/java/com/jerboa/Utils.kt index 9ebf32833..c9c78620d 100644 --- a/app/src/main/java/com/jerboa/Utils.kt +++ b/app/src/main/java/com/jerboa/Utils.kt @@ -1302,9 +1302,9 @@ fun getLangPreferenceDropdownEntries(ctx: Context): Map { val localeList = getLocaleListFromXml(ctx) val map = mutableMapOf() - for (a in 0 until localeList.size()) { - localeList[a].let { - it?.let { it1 -> map.put(it, it.getDisplayName(it)) } + for (i in 0 until localeList.size()) { + localeList[i]?.let { + map.put(it, it.getDisplayName(it)) } } return map diff --git a/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt b/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt index b8aecbc86..e941f3fd8 100644 --- a/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt @@ -293,9 +293,9 @@ fun InboxTabs( items( replies, key = { reply -> reply.comment_reply.id }, - ) { crv -> + ) { commentReplyView -> CommentReplyNode( - commentReplyView = crv, + commentReplyView = commentReplyView, onUpvoteClick = { cr -> account?.also { acct -> inboxViewModel.likeReply( diff --git a/app/update_instances.gradle.kts b/app/update_instances.gradle.kts new file mode 100644 index 000000000..b50b1155c --- /dev/null +++ b/app/update_instances.gradle.kts @@ -0,0 +1,138 @@ +import java.io.OutputStreamWriter +import java.net.URL +import java.net.HttpURLConnection + +// We can't import libraries here for some reason, so we must use what is provided +// by gradle, which isn't much. The groovy JSON library is meant for use by groovy code, +// so we need some creativity to use it in Kotlin. +import org.apache.groovy.json.internal.LazyMap +import groovy.json.JsonOutput +import groovy.json.JsonSlurper + +val endpointUrl = "https://api.fediverse.observer/" +val instancesFilePath = "src/main/java/com/jerboa/DefaultInstances.kt" +val manifestPath = "src/main/AndroidManifest.xml" +val START_TAG = "" +val END_TAG = "" +val IDENT = 15 +val minimumMAU = 50 + +// Some extension methods to make the JsonSlurper output easier to process +fun LazyMap.getMap(key: String): LazyMap { + return this[key] as LazyMap +} + +fun LazyMap.getArray(key: String): ArrayList<*> { + return this[key] as ArrayList<*> +} + +@Suppress("UNCHECKED_CAST") +fun LazyMap.getAs(key: String): T { + return this[key] as T +} + +// Run this as `./gradlew app:updateInstances -no-configuration-cache` +tasks.register("updateInstances") { + description = "Fetches a list of popular Lemmy instances and writes it to the DefaultInstances.kt file" + + doFirst { + // Get sorted list of nodes + val nodes = getData() + .getMap("data") + .getArray("nodes") + .map { + val name = (it as LazyMap)["domain"] as String + val users = it["active_users_monthly"] as Int? + + Pair(name, users ?: 0) + } + .filter { + it.second >= minimumMAU + } + .sortedBy { + it.second + } + .reversed() + + updateInstanceList(nodes) + updateManifest(nodes.map { it.first }) + } +} + + +fun getData(): LazyMap { + val url = URL(endpointUrl) + val query = """ +{ + nodes(softwarename: "lemmy") { + domain + active_users_monthly + } +}""" + + // Format JSON request body + val body = JsonOutput.toJson(mapOf("query" to query)) + + // Create POST request + val req = url.openConnection() as HttpURLConnection + req.requestMethod = "POST" + req.doOutput = true + req.setRequestProperty("Content-Type", "application/json") + + // Write body to request + OutputStreamWriter(req.outputStream, "UTF-8").use { + it.write(body) + } + + // Get response and JSON parse it + return JsonSlurper().parse(req.inputStream.reader()) as LazyMap +} + +fun updateInstanceList(nodes: List>) { + // Create output file and write header + val outFile = file(instancesFilePath) + outFile.writeText( + """package com.jerboa + +val DEFAULT_LEMMY_INSTANCES = arrayOf( +""" + ) + + // Write each node's name, one per line + for (n in nodes) { + outFile.appendText(" \"${n.first}\", // ${n.second} monthly users\n") + } + + outFile.appendText(")\n") +} + + +fun updateManifest(list: List) { + val manifest = file(manifestPath) + val lines = manifest.readLines() + manifest.writeText("") + + var skip = false + + for (line in lines) { + if (line.trim() == START_TAG) { + skip = true + manifest.appendText(" ".repeat(IDENT) + START_TAG) + manifest.appendText(genManifestHosts(list)) + manifest.appendText(" ".repeat(IDENT) + END_TAG + System.lineSeparator()) + } else if (line.trim() == END_TAG) { + skip = false + } else if (!skip) { + manifest.appendText(line + System.lineSeparator()) + } + } +} + +fun genManifestHosts(list: List): String { + return list.joinToString( + separator = System.lineSeparator(), + prefix = System.lineSeparator(), + postfix = System.lineSeparator(), + ) { " ".repeat(IDENT) + "" } +} + From add48c244547d9dd2b63c4a76a771499529eb679 Mon Sep 17 00:00:00 2001 From: "maarten.vercruysse" Date: Mon, 26 Jun 2023 02:50:43 +0200 Subject: [PATCH 3/6] Remove remainder --- app/src/main/AndroidManifest.xml | 2 +- app/src/release/AndroidManifest.xml | 17 ----------------- 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 app/src/release/AndroidManifest.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3093ff2b5..7e8d48c71 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -43,7 +43,7 @@ android:launchMode="standard" android:allowTaskReparenting="true" android:windowSoftInputMode="adjustResize" - tools:node="merge"> + > diff --git a/app/src/release/AndroidManifest.xml b/app/src/release/AndroidManifest.xml deleted file mode 100644 index 670abec4b..000000000 --- a/app/src/release/AndroidManifest.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file From d09c36ef02db3e661a06b3c84ad27ad99cd2ef13 Mon Sep 17 00:00:00 2001 From: "maarten.vercruysse" Date: Mon, 26 Jun 2023 02:57:40 +0200 Subject: [PATCH 4/6] Do cleaning --- app/build.gradle.kts | 3 - app/src/main/AndroidManifest.xml | 117 +++++++++++++++---------------- app/update_instances.gradle.kts | 10 ++- build.gradle.kts | 4 -- 4 files changed, 65 insertions(+), 69 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e716823b7..f3c715c9c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -160,6 +160,3 @@ dependencies { implementation("androidx.profileinstaller:profileinstaller:1.3.1") baselineProfile(project(":benchmarks")) } - - - diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7e8d48c71..5e225d451 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -59,70 +59,69 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/update_instances.gradle.kts b/app/update_instances.gradle.kts index b50b1155c..3fdf8ae9d 100644 --- a/app/update_instances.gradle.kts +++ b/app/update_instances.gradle.kts @@ -9,13 +9,17 @@ import org.apache.groovy.json.internal.LazyMap import groovy.json.JsonOutput import groovy.json.JsonSlurper +// All lemmy instances with at least this amount of monthly active users will be included. +val minimumMAU = 50 + + val endpointUrl = "https://api.fediverse.observer/" val instancesFilePath = "src/main/java/com/jerboa/DefaultInstances.kt" val manifestPath = "src/main/AndroidManifest.xml" -val START_TAG = "" +val START_TAG = "" val END_TAG = "" -val IDENT = 15 -val minimumMAU = 50 +val IDENT = 14 + // Some extension methods to make the JsonSlurper output easier to process fun LazyMap.getMap(key: String): LazyMap { diff --git a/build.gradle.kts b/build.gradle.kts index 32b673cfd..3a6d6ca35 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -45,7 +45,3 @@ subprojects { } } } - -tasks.register("clean", Delete::class) { - delete(rootProject.buildDir) -} From 13d957dbec9bb2f2a0eb28ada6afae151bd8b1f7 Mon Sep 17 00:00:00 2001 From: "maarten.vercruysse" Date: Mon, 26 Jun 2023 06:09:06 +0200 Subject: [PATCH 5/6] Fix typo & update lemmy list --- CONTRIBUTING.md | 2 +- app/src/main/AndroidManifest.xml | 6 +-- .../main/java/com/jerboa/DefaultInstances.kt | 44 +++++++++---------- app/update_instances.gradle.kts | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7f03dc501..4439a39af 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -84,7 +84,7 @@ It uses the fediverse api and filters on the monthly users. You can run it by doing ```shell - ./gradlew app:updateInstances -no-configuration-cache + ./gradlew app:updateInstances --no-configuration-cache ``` ## Generate compose compiler metrics diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5e225d451..b2f8c5945 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -73,8 +73,8 @@ - + @@ -98,15 +98,15 @@ - + + - diff --git a/app/src/main/java/com/jerboa/DefaultInstances.kt b/app/src/main/java/com/jerboa/DefaultInstances.kt index 48a291275..af5faf5b5 100644 --- a/app/src/main/java/com/jerboa/DefaultInstances.kt +++ b/app/src/main/java/com/jerboa/DefaultInstances.kt @@ -1,50 +1,50 @@ package com.jerboa val DEFAULT_LEMMY_INSTANCES = arrayOf( - "lemmy.world", // 13856 monthly users - "lemmy.ml", // 4206 monthly users - "beehaw.org", // 3730 monthly users + "lemmy.world", // 13911 monthly users + "lemmy.ml", // 4217 monthly users + "beehaw.org", // 3739 monthly users "feddit.de", // 2300 monthly users - "sh.itjust.works", // 2215 monthly users - "www.hexbear.net", // 1603 monthly users - "lemmynsfw.com", // 1122 monthly users - "lemmy.ca", // 1092 monthly users + "sh.itjust.works", // 2221 monthly users + "www.hexbear.net", // 1602 monthly users + "lemmynsfw.com", // 1126 monthly users + "lemmy.ca", // 1095 monthly users + "lemm.ee", // 994 monthly users "lemmy.one", // 987 monthly users - "lemm.ee", // 984 monthly users - "lemmy.fmhy.ml", // 944 monthly users - "lemmy.dbzer0.com", // 782 monthly users + "lemmy.fmhy.ml", // 945 monthly users + "lemmy.dbzer0.com", // 784 monthly users "lemmy.blahaj.zone", // 769 monthly users - "lemmygrad.ml", // 629 monthly users - "programming.dev", // 617 monthly users + "lemmygrad.ml", // 630 monthly users + "programming.dev", // 624 monthly users "discuss.tchncs.de", // 564 monthly users - "sopuli.xyz", // 561 monthly users + "sopuli.xyz", // 563 monthly users "lemmy.sdf.org", // 476 monthly users - "vlemmy.net", // 398 monthly users + "vlemmy.net", // 399 monthly users "midwest.social", // 396 monthly users "aussie.zone", // 373 monthly users "startrek.website", // 317 monthly users - "infosec.pub", // 286 monthly users + "infosec.pub", // 288 monthly users "feddit.uk", // 286 monthly users "dormi.zone", // 269 monthly users "feddit.it", // 260 monthly users - "pawb.social", // 242 monthly users + "pawb.social", // 243 monthly users "feddit.nl", // 197 monthly users - "burggit.moe", // 185 monthly users - "slrpnk.net", // 178 monthly users - "lemmy.nz", // 166 monthly users + "burggit.moe", // 187 monthly users + "slrpnk.net", // 179 monthly users + "lemmy.nz", // 167 monthly users "feddit.dk", // 159 monthly users "delraymisfitsboard.com", // 158 monthly users + "reddthat.com", // 154 monthly users "mander.xyz", // 152 monthly users - "reddthat.com", // 152 monthly users "feddit.cl", // 123 monthly users "lemmy.zip", // 118 monthly users "lemmy.pt", // 100 monthly users "dataterm.digital", // 86 monthly users + "lemmy.eco.br", // 86 monthly users "szmer.info", // 85 monthly users "latte.isnot.coffee", // 85 monthly users - "lemmy.eco.br", // 85 monthly users "monyet.cc", // 85 monthly users - "exploding-heads.com", // 83 monthly users + "exploding-heads.com", // 84 monthly users "waveform.social", // 78 monthly users "lemmy.tedomum.net", // 76 monthly users "enterprise.lemmy.ml", // 72 monthly users diff --git a/app/update_instances.gradle.kts b/app/update_instances.gradle.kts index 3fdf8ae9d..b8ee3a431 100644 --- a/app/update_instances.gradle.kts +++ b/app/update_instances.gradle.kts @@ -35,7 +35,7 @@ fun LazyMap.getAs(key: String): T { return this[key] as T } -// Run this as `./gradlew app:updateInstances -no-configuration-cache` +// Run this as `./gradlew app:updateInstances --no-configuration-cache` tasks.register("updateInstances") { description = "Fetches a list of popular Lemmy instances and writes it to the DefaultInstances.kt file" From d813c69af00e3db59d7264b33c21b0a3d43cf7cc Mon Sep 17 00:00:00 2001 From: "maarten.vercruysse" Date: Mon, 26 Jun 2023 06:53:10 +0200 Subject: [PATCH 6/6] Add nsfw filter list --- app/src/main/AndroidManifest.xml | 1 - app/src/main/java/com/jerboa/DefaultInstances.kt | 1 - app/update_instances.gradle.kts | 4 ++-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b2f8c5945..d30c7f06d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -71,7 +71,6 @@ - diff --git a/app/src/main/java/com/jerboa/DefaultInstances.kt b/app/src/main/java/com/jerboa/DefaultInstances.kt index af5faf5b5..f20ce474c 100644 --- a/app/src/main/java/com/jerboa/DefaultInstances.kt +++ b/app/src/main/java/com/jerboa/DefaultInstances.kt @@ -7,7 +7,6 @@ val DEFAULT_LEMMY_INSTANCES = arrayOf( "feddit.de", // 2300 monthly users "sh.itjust.works", // 2221 monthly users "www.hexbear.net", // 1602 monthly users - "lemmynsfw.com", // 1126 monthly users "lemmy.ca", // 1095 monthly users "lemm.ee", // 994 monthly users "lemmy.one", // 987 monthly users diff --git a/app/update_instances.gradle.kts b/app/update_instances.gradle.kts index b8ee3a431..61930aff6 100644 --- a/app/update_instances.gradle.kts +++ b/app/update_instances.gradle.kts @@ -19,7 +19,7 @@ val manifestPath = "src/main/AndroidManifest.xml" val START_TAG = "" val END_TAG = "" val IDENT = 14 - +val nsfwList = listOf("lemmynsfw.com") // Some extension methods to make the JsonSlurper output easier to process fun LazyMap.getMap(key: String): LazyMap { @@ -51,7 +51,7 @@ tasks.register("updateInstances") { Pair(name, users ?: 0) } .filter { - it.second >= minimumMAU + it.second >= minimumMAU && !nsfwList.contains(it.first) } .sortedBy { it.second