Skip to content

Commit

Permalink
add compose
Browse files Browse the repository at this point in the history
  • Loading branch information
REBOOTERS committed Oct 9, 2024
1 parent 4cba6b9 commit d1a2022
Show file tree
Hide file tree
Showing 31 changed files with 1,148 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id 'com.android.library' version '8.7.0' apply false
id 'org.jetbrains.kotlin.android' version '2.0.20' apply false
id 'com.google.devtools.ksp' version '2.0.10-1.0.24' apply false
id 'org.jetbrains.kotlin.plugin.compose' version '2.0.20' apply false
}
apply from: file('config.gradle')
//buildscript {
Expand Down
36 changes: 36 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[versions]
agp = "8.7.0"
kotlin = "2.0.0"
coreKtx = "1.10.1"
junit = "4.14-SNAPSHOT"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
lifecycleRuntimeKtx = "2.6.1"
activityCompose = "1.8.0"
composeBom = "2024.04.01"
coilCompose = "2.4.0"
composeRuntimeLiveData="1.7.0"
accompanistPager = "0.24.7-alpha"
lifecycleViewmodelCompose = "2.8.5"


[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
coil-compose = {group="io.coil-kt", name="coil-compose",version.ref = "coilCompose"}
accompanist-pager = {group = "com.google.accompanist",name="accompanist-pager",version.ref = "accompanistPager"}
accompanist-pager-indicator = {group = "com.google.accompanist",name="accompanist-pager-indicators",version.ref = "accompanistPager"}
androidx-compose-runtime = {group = "androidx.compose.runtime",name="runtime-livedata",version.ref = "composeRuntimeLiveData"}
androidx-lifecycle-viewmodel-compose = {group = "androidx.lifecycle",name="lifecycle-viewmodel-compose",version.ref = "lifecycleViewmodelCompose"}
3 changes: 2 additions & 1 deletion imitate/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-process:2.8.5'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.5'
implementation project(path: ':subs:cpp_native')


testImplementation 'junit:junit:4.13.2'
Expand Down Expand Up @@ -189,6 +188,8 @@ dependencies {
implementation project(path: ':subs:game')
implementation project(path: ':subs:gif-revert')
implementation project(path: ':subs:ai')
implementation project(path: ':subs:cpp_native')
implementation project(path: ':subs:compose')

implementation 'com.jaredrummler:simple-mvp:1.0.2'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.engineer.compose.ui.MainComposeActivity
import com.engineer.imitate.databinding.ActivityKotlinRootBinding
import com.engineer.imitate.model.FragmentItem
import com.engineer.imitate.room.SchoolDatabase
Expand Down Expand Up @@ -170,6 +171,7 @@ class KotlinRootActivity : AppCompatActivity() {
// <editor-fold defaultstate="collapsed" desc="init fragments">
private fun initList(): MutableList<FragmentItem> {
return mutableListOf(
FragmentItem("/anim/compose", "compose"),
FragmentItem("/anim/entrance", "entrance"),
FragmentItem("/anim/dependency_injection", "dependency_injection"),
FragmentItem("/anim/rx_play", "rx_play"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.engineer.compose.ui


import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.res.stringResource
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.engineer.compose.ui.ui.theme.MiniAppTheme
import com.engineer.imitate.R

/**
* A simple [Fragment] subclass.
*
*/
@Route(path = "/anim/compose")
class ComposeFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_compose, container, false)
val composeView = view.findViewById<ComposeView>(R.id.compose_view)
composeView.apply {
// Dispose of the Composition when the view's LifecycleOwner
// is destroyed
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
// SimpleScreen()
MiniAppTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colorScheme.background) {
MessageCard(Message("lucy", "hello world"))
}
}
}
}
return view
}
}

//@Composable
//private fun SimpleScreen() {
// Column(Modifier.fillMaxSize()) {
// Text(
// text = stringResource(R.string.content),
// style = MaterialTheme.typography.headlineMedium
// )
// Text(
// text = stringResource(R.string.content),
// style = MaterialTheme.typography.headlineSmall
// )
// Text(
// text = stringResource(R.string.content),
// style = MaterialTheme.typography.bodyMedium
// )
// Spacer(modifier = Modifier.weight(1f))
// Button(onClick = { /* Handle click */ }, Modifier.fillMaxWidth()) {
// Text(text = stringResource(R.string.content))
// }
// }
//}

12 changes: 12 additions & 0 deletions imitate/src/main/res/layout/fragment_compose.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</FrameLayout>
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ include ':app',
':subs:gif-revert',
':subs:game',
':subs:cpp_native',
':subs:ai'
':subs:ai',
':subs:compose'
1 change: 1 addition & 0 deletions subs/compose/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
55 changes: 55 additions & 0 deletions subs/compose/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.plugin.compose'
}
android {
namespace 'com.engineer.compose'
compileSdk 34

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
}

dependencies {

implementation libs.androidx.core.ktx
implementation libs.androidx.lifecycle.runtime.ktx
api libs.androidx.activity.compose
api platform(libs.androidx.compose.bom)
api libs.androidx.ui
api libs.androidx.ui.graphics
api libs.androidx.ui.tooling.preview
api libs.androidx.material3
api libs.coil.compose
api "io.coil-kt:coil-gif:2.6.0"

api libs.androidx.compose.runtime
api libs.androidx.lifecycle.viewmodel.compose

api libs.accompanist.pager
api libs.accompanist.pager.indicator


testImplementation libs.junit
androidTestImplementation libs.androidx.junit
androidTestImplementation libs.androidx.espresso.core
androidTestImplementation platform(libs.androidx.compose.bom)
androidTestImplementation libs.androidx.ui.test.junit4
debugApi libs.androidx.ui.tooling
debugImplementation libs.androidx.ui.test.manifest
}
Empty file added subs/compose/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions subs/compose/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.engineer.compose

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.engineer.compose.test", appContext.packageName)
}
}
24 changes: 24 additions & 0 deletions subs/compose/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application>
<activity
android:name=".ui.GalleryActivity"
android:exported="false"
android:label="@string/title_activity_gallery"
android:theme="@style/Theme.MiniApp" />
<activity
android:name=".ui.MainComposeActivity"
android:exported="true"
android:label="@string/title_activity_main_compose"
android:theme="@style/ComposeApp.Theme" />
<activity
android:name=".ui.ChatActivity"
android:exported="true"
android:theme="@style/ComposeApp.Theme"
android:windowSoftInputMode="adjustResize" />
</application>

</manifest>
Loading

0 comments on commit d1a2022

Please sign in to comment.