Skip to content

Commit

Permalink
chore: house keeping refactoring and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
wax911 committed Mar 19, 2024
1 parent d91a631 commit 533735d
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 55 deletions.
15 changes: 4 additions & 11 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# AniTrend Pull Request

Thank you for contributing! Please take a moment to review our [**contributing
guidelines**](https://github.com/AniTrend/android-emojify/blob/develop/CONTRIBUTING.md)
to make the process easy and effective for everyone involved.
Thank you for contributing! Please take a moment to review our [**contributing guidelines**](https://github.com/AniTrend/android-emojify/blob/develop/CONTRIBUTING.md) to make the process easy and effective for everyone involved.

**Please open an issue** before embarking on any significant pull request, especially those that
add a new library or change existing tests, otherwise you risk spending a lot of time working
on something that might not end up being merged into the project.
**Please open an issue** before embarking on any significant pull request, especially those that add a new library or change existing tests, otherwise you risk spending a lot of time working on something that might not end up being merged into the project.

Before opening a pull request, please ensure you've done the following:
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- You have followed our [**contributing
guidelines**](https://github.com/AniTrend/android-emojify/blob/develop/CONTRIBUTING.md)
- You have followed our [**contributing guidelines**](https://github.com/AniTrend/android-emojify/blob/develop/CONTRIBUTING.md)
- Double checked that your branch is based on `develop` and targets `develop` (where applicable)
- Pull request has tests (if applicable)
- Documentation is updated (if necessary)
Expand All @@ -32,6 +27,4 @@ Before opening a pull request, please ensure you've done the following:

<!--- Be kind to code reviewers, and please try to keep pull requests as small and focused as possible :) -->

**IMPORTANT**: By submitting a patch, you agree to allow the project
owners to license your work under the terms of
the [Apache License 2.0](https://github.com/AniTrend/android-emojify/blob/develop/LICENSE.md).
**IMPORTANT**: By submitting a patch, you agree to allow the project owners to license your work under the terms of the [Apache License 2.0](https://github.com/AniTrend/android-emojify/blob/develop/LICENSE.md).
2 changes: 1 addition & 1 deletion app/src/main/java/io/wax911/emojifysample/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.wax911.emojifysample
import android.app.Application
import androidx.startup.AppInitializer
import io.wax911.emojify.EmojiManager
import io.wax911.emojify.serializer.KotlinxDeserializer
import io.wax911.emojify.serializer.kotlinx.KotlinxDeserializer

/**
* Created by max on 2017/09/22.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.wax911.emojifysample

import io.wax911.emojify.contract.serializer.IEmojiDeserializer
import io.wax911.emojify.initializer.AbstractEmojiInitializer
import io.wax911.emojify.serializer.KotlinxDeserializer
import io.wax911.emojify.serializer.kotlinx.KotlinxDeserializer

class EmojiInitializer : AbstractEmojiInitializer() {
override val serializer: IEmojiDeserializer = KotlinxDeserializer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Libraries {
object Emojify {
val emojify = Modules.Library.Emojify.path()
val contract = Modules.Library.Contract.path()
val serializerKotlinx = Modules.Library.SerializerKotlinx.path()
val serializerKotlinx = Modules.Library.SerializerKotlinX.path()
val serializerGson = Modules.Library.SerializerGson.path()
val serializerMoshi = Modules.Library.SerializerMoshi.path()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal object Modules {
enum class Library(override val id: String) : Module {
Emojify("emojify"),
Contract("contract"),
SerializerKotlinx("serializer:kotlinx"),
SerializerKotlinX("serializer:kotlinx"),
SerializerGson("serializer:gson"),
SerializerMoshi("serializer:moshi"),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ open class CorePlugin : Plugin<Project> {
/**
* Inspecting available extensions
*/
@Suppress("UnstableApiUsage")
internal fun Project.availableExtensions() {
private fun Project.availableExtensions() {
val extensionSchema = project.extensions.extensionsSchema
extensionSchema.forEach {
println("Available extension for module ${project.path}: ${it.name} -> ${it.publicType}")
Expand All @@ -24,8 +23,7 @@ open class CorePlugin : Plugin<Project> {
/**
* Inspecting available components
*/
@Suppress("UnstableApiUsage")
internal fun Project.availableComponents() {
private fun Project.availableComponents() {
val collectionSchema = project.components.asMap
collectionSchema.forEach {
println("Available component for module ${project.path}: ${it.key} -> ${it.value}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package io.wax911.emoji.buildSrc.plugin.components

import com.android.build.gradle.internal.dsl.DefaultConfig
import io.wax911.emoji.buildSrc.plugin.extensions.*
import io.wax911.emoji.buildSrc.plugin.extensions.baseAppExtension
import io.wax911.emoji.buildSrc.plugin.extensions.baseExtension
import io.wax911.emoji.buildSrc.plugin.extensions.isLibraryModule
import io.wax911.emoji.buildSrc.plugin.extensions.isSampleModule
import io.wax911.emoji.buildSrc.plugin.extensions.libs
import io.wax911.emoji.buildSrc.plugin.extensions.props
import io.wax911.emoji.buildSrc.plugin.extensions.spotlessExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
Expand All @@ -13,7 +19,7 @@ internal fun Project.configureSpotless() {
spotlessExtension().run {
kotlin {
target("**/kotlin/**/*.kt")
targetExclude("$buildDir/**/*.kt", "**/test/**/*.kt", "bin/**/*.kt")
targetExclude("${layout.buildDirectory}/**/*.kt", "**/test/**/*.kt", "bin/**/*.kt")
ktlint(libs.versions.ktlint.get())
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
}
Expand All @@ -28,7 +34,6 @@ private fun Project.configureLint() = baseAppExtension().run {
}
}

@Suppress("UnstableApiUsage")
private fun DefaultConfig.applyAdditionalConfiguration(project: Project) {
if (project.isSampleModule()) {
applicationId = "io.wax911.emoji.sample"
Expand Down Expand Up @@ -106,9 +111,7 @@ internal fun Project.configureAndroid(): Unit = baseExtension().run {
if (isSampleModule()) {
compileArgs.add("-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi")
compileArgs.add("-opt-in=kotlinx.coroutines.FlowPreview")
} else
compileArgs.add("-opt-in=kotlinx.serialization.ExperimentalSerializationApi")
// Filter out modules that won't be using coroutines
}
freeCompilerArgs = compileArgs
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private fun Project.createMavenPublicationUsing(sourcesJar: Jar) {
version = props[PropertyTypes.VERSION]

artifact(sourcesJar)
artifact("${project.buildDir}/outputs/aar/${project.name}-release.aar")
artifact("${project.layout.buildDirectory}/outputs/aar/${project.name}-release.aar")
from(component)

pom {
Expand Down Expand Up @@ -148,7 +148,6 @@ private fun Project.createDokkaTaskProvider() = tasks.named<DokkaTask>("dokkaHtm
}


@Suppress("UnstableApiUsage")
internal fun Project.configureOptions() {
if (isLibraryModule()) {
println("Applying additional tasks options for dokka and javadoc on ${project.path}")
Expand All @@ -161,7 +160,7 @@ internal fun Project.configureOptions() {
}

val classesJar by tasks.register("classesJar", Jar::class.java) {
from("${project.buildDir}/intermediates/classes/release")
from("${project.layout.buildDirectory}/intermediates/classes/release")
}

artifacts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ fun Project.isSampleModule() =
name == Modules.App.Sample.id

fun Project.isLibraryModule() =
name == Modules.Library.Emojify.id
name == "emojify" ||
name == "contract" ||
name == "kotlinx" ||
name == "gson" ||
name == "moshi"

internal val Project.libs: LibrariesForLibs
get() =
extensions.getByType<LibrariesForLibs>()
get() = extensions.getByType<LibrariesForLibs>()

internal val Project.props: PropertiesReader
get() = PropertiesReader(this)
Expand Down
12 changes: 1 addition & 11 deletions contract/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("io.wax911.emojify")
}

android {
namespace = "io.wax911.emojify.contract"
compileSdk = 34

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 AniTrend
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.wax911.emojify.contract.model

import java.nio.charset.Charset
Expand All @@ -6,7 +22,7 @@ import java.nio.charset.Charset
* Abstract class holding some logic.
* To implement for parser-specific data representation with their annotation
*/
abstract class AbstractEmoji: IEmoji {
abstract class AbstractEmoji : IEmoji {
override val unicode: String by lazy(LazyThreadSafetyMode.NONE) {
String(emoji.toByteArray(), Charset.forName("UTF-8"))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 AniTrend
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.wax911.emojify.contract.model

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 AniTrend
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.wax911.emojify.contract.serializer

import io.wax911.emojify.contract.model.AbstractEmoji
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.wax911.emojify.core

import io.wax911.emojify.EmojiManager
import io.wax911.emojify.serializer.KotlinxDeserializer
import io.wax911.emojify.serializer.kotlinx.KotlinxDeserializer

abstract class EmojiLoader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.wax911.emojify.serializer
package io.wax911.emojify.serializer.gson

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
Expand All @@ -25,7 +25,7 @@ import java.io.InputStream
/**
* Default implementation for gson
*/
class GsonDeserializer: IEmojiDeserializer {
class GsonDeserializer : IEmojiDeserializer {
private val gson = Gson()

override fun decodeFromStream(inputStream: InputStream): List<AbstractEmoji> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package io.wax911.emojify.serializer
/*
* Copyright 2024 AniTrend
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.wax911.emojify.serializer.gson

import com.google.gson.annotations.SerializedName
import io.wax911.emojify.contract.model.AbstractEmoji
Expand All @@ -14,4 +30,4 @@ data class GsonEmoji(
@SerializedName(value = "supports_fitzpatrick") override val supportsFitzpatrick: Boolean,
@SerializedName(value = "supports_gender") override val supportsGender: Boolean,
@SerializedName(value = "tags") override val tags: List<String>?,
): AbstractEmoji()
) : AbstractEmoji()
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.wax911.emojify.serializer
package io.wax911.emojify.serializer.kotlinx

import io.wax911.emojify.contract.model.AbstractEmoji
import io.wax911.emojify.contract.serializer.IEmojiDeserializer
Expand All @@ -30,6 +30,7 @@ import java.io.InputStream
class KotlinxDeserializer : IEmojiDeserializer {
private val json = Json { isLenient = true }

@OptIn(kotlinx.serialization.ExperimentalSerializationApi::class)
@Throws(SerializationException::class)
override fun decodeFromStream(inputStream: InputStream): List<AbstractEmoji> {
val deserializer = ListSerializer(KotlinxEmoji.serializer())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package io.wax911.emojify.serializer
/*
* Copyright 2024 AniTrend
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.wax911.emojify.serializer.kotlinx

import io.wax911.emojify.contract.model.AbstractEmoji
import kotlinx.serialization.SerialName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

package io.wax911.emojify.serializer
package io.wax911.emojify.serializer.moshi

import com.squareup.moshi.JsonClass
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
Expand All @@ -29,7 +28,7 @@ import java.io.InputStream
/**
* Default implementation for moshi
*/
class MoshiDeserializer: IEmojiDeserializer {
class MoshiDeserializer : IEmojiDeserializer {
private val moshi = Moshi.Builder().addLast(KotlinJsonAdapterFactory()).build()

override fun decodeFromStream(inputStream: InputStream): List<AbstractEmoji> {
Expand Down
Loading

0 comments on commit 533735d

Please sign in to comment.