Skip to content

Commit

Permalink
[build]: setup is made with Jetpack Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Jun 30, 2024
1 parent ea16c0c commit 0021140
Show file tree
Hide file tree
Showing 40 changed files with 1,412 additions and 378 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
implementation(project(":core:core-preferences"))
implementation(project(":core:core-terminals"))
implementation(project(":core:core-ui"))
implementation(project(":core:core-ui-compose"))

implementation(project(":feature:feature-crashes"))
implementation(project(":feature:feature-crashes-core"))
Expand Down
23 changes: 16 additions & 7 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,32 @@ gradlePlugin {
plugins {
register("androidApplication") {
id = "logfox.android.application"
implementationClass = "AndroidApplicationConventionPlugin"
implementationClass = "main.AndroidApplicationConventionPlugin"
}
register("androidLibrary") {
id = "logfox.android.library"
implementationClass = "AndroidLibraryConventionPlugin"
implementationClass = "main.AndroidLibraryConventionPlugin"
}
register("androidCore") {
id = "logfox.android.core"
implementationClass = "AndroidCoreConventionPlugin"
implementationClass = "main.AndroidCoreConventionPlugin"
}
register("androidFeature") {
id = "logfox.android.feature"
implementationClass = "main.feature.AndroidFeatureConventionPlugin"
}
register("androidFeatureCompose") {
id = "logfox.android.feature.compose"
implementationClass = "main.feature.AndroidComposeFeatureConventionPlugin"
}

register("androidHilt") {
id = "logfox.android.hilt"
implementationClass = "AndroidHiltConventionPlugin"
implementationClass = "additional.AndroidHiltConventionPlugin"
}
register("androidFeature") {
id = "logfox.android.feature"
implementationClass = "AndroidFeatureConventionPlugin"
register("androidCompose") {
id = "logfox.android.compose"
implementationClass = "additional.AndroidComposeConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package additional

import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.LibraryExtension
import extensions.bundle
import extensions.implementation
import extensions.pluginId
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies

class AndroidComposeConventionPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
with(pluginManager) {
apply(pluginId("compose-compiler"))
}

listOf(
LibraryExtension::class.java,
ApplicationExtension::class.java,
).forEach { extensionClass ->
extensions.findByType(extensionClass)?.enableCompose()
}

dependencies {
implementation(bundle("androidx-compose"))
}
}

private fun CommonExtension<*, *, *, *, *, *>.enableCompose() {
buildFeatures.compose = true
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package additional

import extensions.implementation
import extensions.ksp
import extensions.library
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package main

import com.android.build.api.dsl.ApplicationExtension
import extensions.configureKotlinAndroid
import extensions.pluginId
Expand All @@ -15,6 +17,7 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
apply(pluginId("ksp"))

apply("logfox.android.hilt")
apply("logfox.android.compose")
}

extensions.configure<ApplicationExtension> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package main

import extensions.bundle
import extensions.implementation
import extensions.library
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package main

import com.android.build.gradle.LibraryExtension
import extensions.configureKotlinAndroid
import extensions.pluginId
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main.feature

import extensions.implementation
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies

class AndroidComposeFeatureConventionPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
with(pluginManager) {
apply("logfox.android.feature")
apply("logfox.android.compose")
}

dependencies {
implementation(project(":core:core-ui-compose"))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package main.feature

import extensions.bundle
import extensions.implementation
import extensions.ksp
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.compose.compiler) apply false

alias(libs.plugins.ksp) apply false
alias(libs.plugins.hilt.android) apply false
Expand Down
2 changes: 2 additions & 0 deletions core/core-arch/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
plugins {
id("logfox.android.core")

id("logfox.android.hilt")
id("logfox.android.compose")
}

android.namespace = "com.f0x1d.logfox.arch"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ abstract class BaseFragment<T : ViewBinding>: Fragment() {
mutableBinding = null
}

protected fun snackbar(text: String) = requireView().snackbar(text).apply {
protected open fun snackbar(text: String) = requireView().snackbar(text).apply {
view.applyInsetter {
type(navigationBars = true) {
margin(vertical = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.f0x1d.logfox.arch.ui.fragment.compose

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.runtime.Composable
import com.f0x1d.logfox.arch.databinding.FragmentComposeBinding
import com.f0x1d.logfox.arch.ui.fragment.BaseFragment

abstract class BaseComposeFragment : BaseFragment<FragmentComposeBinding>() {

override fun inflateBinding(
inflater: LayoutInflater,
container: ViewGroup?,
) = FragmentComposeBinding.inflate(inflater, container, false)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.composeView.setContent {
Content()
}
}

@Composable
abstract fun Content()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.f0x1d.logfox.arch.ui.fragment.compose

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.runtime.Composable
import com.f0x1d.logfox.arch.databinding.FragmentComposeBinding
import com.f0x1d.logfox.arch.ui.fragment.BaseViewModelFragment
import com.f0x1d.logfox.arch.ui.snackbar
import com.f0x1d.logfox.arch.viewmodel.BaseViewModel
import com.google.android.material.snackbar.Snackbar
import dev.chrisbanes.insetter.applyInsetter

abstract class BaseComposeViewModelFragment<T : BaseViewModel> : BaseViewModelFragment<T, FragmentComposeBinding>() {

override fun inflateBinding(
inflater: LayoutInflater,
container: ViewGroup?,
) = FragmentComposeBinding.inflate(inflater, container, false)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.composeView.apply {
consumeWindowInsets = false

setContent {
this@BaseComposeViewModelFragment.Content()
}
}
}

override fun snackbar(text: String): Snackbar = requireView().snackbar(text).apply {
view.applyInsetter {
type(navigationBars = true) {
margin()
}
}
}

@Composable
abstract fun Content()
}
15 changes: 15 additions & 0 deletions core/core-arch/src/main/res/layout/fragment_compose.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion core/core-navigation/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<fragment
android:id="@+id/setupFragment"
android:name="com.f0x1d.logfox.feature.setup.ui.fragment.SetupFragment"
android:name="com.f0x1d.logfox.feature.setup.ui.fragment.setup.SetupFragment"
android:label="SetupFragment" />

<action
Expand Down
1 change: 1 addition & 0 deletions core/core-ui-compose/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
10 changes: 10 additions & 0 deletions core/core-ui-compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id("logfox.android.core")
id("logfox.android.compose")
}

android.namespace = "com.f0x1d.logfox.ui.compose"

dependencies {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.f0x1d.logfox.ui.compose.component.button

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.f0x1d.logfox.strings.Strings
import com.f0x1d.logfox.ui.compose.R
import com.f0x1d.logfox.ui.compose.theme.LogFoxTheme

@Composable
fun RichButton(
@StringRes text: Int,
@DrawableRes icon: Int,
onClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Button(
modifier = modifier,
onClick = onClick,
) {
Icon(
painter = painterResource(id = icon),
contentDescription = null,
)
Spacer(modifier = Modifier.width(8.dp))
Text(
text = stringResource(id = text),
style = MaterialTheme.typography.bodyLarge,
fontWeight = FontWeight.Bold,
)
}
}

@Preview
@Composable
private fun RichButtonPreview() {
LogFoxTheme {
RichButton(
text = Strings.root,
icon = R.drawable.ic_test_icon,
onClick = { },
)
}
}
Loading

0 comments on commit 0021140

Please sign in to comment.