Skip to content

Commit 8968a4c

Browse files
Split source functionality between "modules",
Automatically apply changes for some ui elements Signed-off-by: MrBoom <[email protected]>
1 parent bbf56a8 commit 8968a4c

File tree

32 files changed

+565
-499
lines changed

32 files changed

+565
-499
lines changed

buildSrc/src/main/kotlin/com/mrboomdev/awery/gradle/settings/GenerateSettingsImpl.kt

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ internal object GenerateSettingsImpl {
3737
append(outputFile.nameWithoutExtension)
3838
append(" {\n")
3939

40+
val usedKeys = mutableListOf<String>()
41+
4042
for(file in inputFiles) {
4143
val text = file.readText()
4244

@@ -46,8 +48,27 @@ internal object GenerateSettingsImpl {
4648
ignoreUnknownKeys = true
4749
}.parseToJsonElement(text) as JsonObject
4850

49-
appendSetting(file.nameWithoutExtension, settings, this)
51+
appendSetting(usedKeys, file.nameWithoutExtension, settings, this)
52+
}
53+
54+
append("\n\tval all = mapOf(\n")
55+
usedKeys.iterator().apply {
56+
while(hasNext()) {
57+
val key = next()
58+
59+
append("\t\t\"")
60+
append(key)
61+
append("\" to ")
62+
append(key.uppercase())
63+
64+
if(hasNext()) {
65+
append(",")
66+
}
67+
68+
append("\n")
69+
}
5070
}
71+
append("\t)\n")
5172

5273
append("}")
5374
})
@@ -147,9 +168,16 @@ internal object GenerateSettingsImpl {
147168
}
148169
}
149170

150-
private fun appendSetting(originalFile: String, setting: JsonObject, output: StringBuilder) {
171+
private fun appendSetting(
172+
usedKeys: MutableList<String>,
173+
originalFile: String,
174+
setting: JsonObject,
175+
output: StringBuilder
176+
) {
151177
if(!setting["key"].isNull && !setting["type"].isNull) {
152178
with(output) {
179+
usedKeys += setting["key"]!!.textContent!!
180+
153181
append("\tval ")
154182
append(setting["key"]!!.textContent!!.uppercase())
155183
append(" = ")
@@ -181,7 +209,7 @@ internal object GenerateSettingsImpl {
181209

182210
setting["items"]?.items?.forEach { item ->
183211
require(item is JsonObject) { "An item is required to be an object!" }
184-
appendSetting(originalFile, item, output)
212+
appendSetting(usedKeys, originalFile, item, output)
185213
}
186214
}
187215
}

ext/src/main/kotlin/com/mrboomdev/awery/ext/constants/AweryFeature.kt

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.mrboomdev.awery.ext.constants
2+
3+
object AweryFilters {
4+
const val EPISODE = "AWERY.EPISODE"
5+
const val MEDIA = "AWERY.MEDIA"
6+
const val FEED = "AWERY.FEED"
7+
const val PAGE = "AWERY.PAGE"
8+
const val QUERY = "AWERY.QUERY"
9+
const val TAG = "AWERY.TAG"
10+
}
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.mrboomdev.awery.ext.data
22

3-
import com.mrboomdev.awery.ext.constants.AweryFeature
4-
53
class CatalogComment(
64
val avatar: String? = null,
75
val name: String,
@@ -10,6 +8,5 @@ class CatalogComment(
108
val likes: Int? = null,
119
val dislikes: Int? = null,
1210
val votes: Int? = null,
13-
val features: Array<AweryFeature>? = null,
1411
val repliesCount: Int? = null
1512
)

ext/src/main/kotlin/com/mrboomdev/awery/ext/source/Context.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package com.mrboomdev.awery.ext.source
22

33
import com.mrboomdev.awery.ext.constants.AgeRating
4-
import com.mrboomdev.awery.ext.constants.AweryFeature
54
import com.mrboomdev.awery.ext.util.Image
65

76
interface Context {
8-
val features: Array<AweryFeature>
97
val id: String
108
val isEnabled: Boolean
119
val name: String?
Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,15 @@
11
package com.mrboomdev.awery.ext.source
22

3-
import com.mrboomdev.awery.ext.data.CatalogComment
4-
import com.mrboomdev.awery.ext.data.CatalogFeed
5-
import com.mrboomdev.awery.ext.data.CatalogFile
6-
import com.mrboomdev.awery.ext.data.CatalogMedia
7-
import com.mrboomdev.awery.ext.data.CatalogSearchResults
8-
import com.mrboomdev.awery.ext.data.Setting
9-
import javax.xml.catalog.Catalog
3+
import com.mrboomdev.awery.ext.source.module.Module
104

115
/**
126
* Source is the provider of feeds, media, subtitles and more...
13-
* You MUST create an constructor with the context as an argument,
14-
* otherwise your extension won't be loaded!
157
* An context will be created by the manager,
168
* so that you won't need to repeat same values multiple times.
179
*/
1810
abstract class Source: AbstractSource() {
1911
override val context: Context.SourceContext
2012
get() = super.context as Context.SourceContext
2113

22-
open suspend fun getFeeds(): CatalogSearchResults<CatalogFeed> {
23-
throw NotImplementedError("getFeeds() isn't implemented!")
24-
}
25-
26-
open suspend fun getFilters(catalog: Catalog<*>): List<Setting> {
27-
throw NotImplementedError("getFilters() isn't implemented!")
28-
}
29-
30-
open suspend fun <E, T: Catalog<E>> search(catalog: T, filters: List<Setting>): CatalogSearchResults<E> {
31-
throw NotImplementedError("search() isn't implemented!")
32-
}
33-
34-
open suspend fun <E, T: Catalog<E>> submit(catalog: T, filters: List<Setting>): CatalogSearchResults<E> {
35-
throw NotImplementedError("submit() isn't implemented!")
36-
}
37-
38-
sealed class Catalog<T> {
39-
data object Comment: Catalog<CatalogComment>()
40-
data object Tracking: Catalog<Map<String, Any>>()
41-
data object Media: Catalog<CatalogMedia>()
42-
data object Subtitles: Catalog<CatalogFile>()
43-
}
44-
45-
companion object {
46-
const val FILTER_EPISODE = "__EPISODE__"
47-
const val FILTER_MEDIA = "__MEDIA__"
48-
const val FILTER_FEED = "__FEED__"
49-
const val FILTER_PAGE = "__PAGE__"
50-
const val FILTER_QUERY = "__QUERY__"
51-
const val FILTER_TAG = "__TAG__"
52-
53-
const val TRACKING_MEDIA = "__MEDIA__"
54-
}
14+
abstract fun createModules(): List<Module>
5515
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.mrboomdev.awery.ext.source.module
2+
3+
import com.mrboomdev.awery.ext.data.CatalogFeed
4+
import com.mrboomdev.awery.ext.data.CatalogMedia
5+
import com.mrboomdev.awery.ext.data.CatalogSearchResults
6+
import com.mrboomdev.awery.ext.data.Setting
7+
8+
interface CatalogModule: Module {
9+
suspend fun createFeeds(): CatalogSearchResults<CatalogFeed>
10+
suspend fun search(filters: List<Setting>): CatalogSearchResults<CatalogMedia>
11+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.mrboomdev.awery.ext.source.module
2+
3+
interface CommentsModule: Module {
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.mrboomdev.awery.ext.source.module
2+
3+
sealed interface Module
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.mrboomdev.awery.ext.source.module
2+
3+
interface NotificationsModule: Module {
4+
}

0 commit comments

Comments
 (0)