mirror of
https://github.com/HighCapable/YukiReflection.git
synced 2025-09-07 19:14:11 +08:00
refactor: merge samples all platform to compose
This commit is contained in:
@@ -2,4 +2,5 @@ plugins {
|
|||||||
autowire(libs.plugins.android.application) apply false
|
autowire(libs.plugins.android.application) apply false
|
||||||
autowire(libs.plugins.kotlin.jvm) apply false
|
autowire(libs.plugins.kotlin.jvm) apply false
|
||||||
autowire(libs.plugins.kotlin.android) apply false
|
autowire(libs.plugins.kotlin.android) apply false
|
||||||
|
autowire(libs.plugins.jetbrains.compose) apply false
|
||||||
}
|
}
|
@@ -16,7 +16,7 @@ plugins:
|
|||||||
alias: kotlin-android
|
alias: kotlin-android
|
||||||
version-ref: kotlin-jvm
|
version-ref: kotlin-jvm
|
||||||
org.jetbrains.compose:
|
org.jetbrains.compose:
|
||||||
alias: kotlin-compose
|
alias: jetbrains-compose
|
||||||
version: 1.5.1
|
version: 1.5.1
|
||||||
com.android.application:
|
com.android.application:
|
||||||
alias: android-application
|
alias: android-application
|
||||||
@@ -26,9 +26,21 @@ plugins:
|
|||||||
version: 0.25.3
|
version: 0.25.3
|
||||||
|
|
||||||
libraries:
|
libraries:
|
||||||
org.jetbrains.compose.material3:
|
androidx.compose:
|
||||||
material3-desktop:
|
compose-bom:
|
||||||
version: 1.5.1
|
version: 2023.09.02
|
||||||
|
androidx.compose.foundation:
|
||||||
|
foundation:
|
||||||
|
version: <no-spec>
|
||||||
|
androidx.compose.ui:
|
||||||
|
ui:
|
||||||
|
version: <no-spec>
|
||||||
|
androidx.compose.material3:
|
||||||
|
material3:
|
||||||
|
version: <no-spec>
|
||||||
|
androidx.activity:
|
||||||
|
activity-compose:
|
||||||
|
version: 1.7.2
|
||||||
androidx.core:
|
androidx.core:
|
||||||
core-ktx:
|
core-ktx:
|
||||||
version: 1.10.0
|
version: 1.10.0
|
||||||
@@ -38,9 +50,6 @@ libraries:
|
|||||||
com.google.android.material:
|
com.google.android.material:
|
||||||
material:
|
material:
|
||||||
version: 1.8.0
|
version: 1.8.0
|
||||||
androidx.constraintlayout:
|
|
||||||
constraintlayout:
|
|
||||||
version: 2.1.4
|
|
||||||
androidx.test.ext:
|
androidx.test.ext:
|
||||||
junit:
|
junit:
|
||||||
version: 1.1.5
|
version: 1.1.5
|
||||||
|
@@ -33,19 +33,26 @@ android {
|
|||||||
"-Xno-receiver-assertions"
|
"-Xno-receiver-assertions"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
composeOptions {
|
||||||
|
kotlinCompilerExtensionVersion = "1.5.3"
|
||||||
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
buildConfig = true
|
buildConfig = true
|
||||||
viewBinding = true
|
compose = true
|
||||||
}
|
}
|
||||||
lint { checkReleaseBuilds = false }
|
lint { checkReleaseBuilds = false }
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(projects.yukireflectionCore)
|
implementation(projects.yukireflectionCore)
|
||||||
|
implementation(platform(androidx.compose.compose.bom))
|
||||||
|
implementation(androidx.compose.foundation.foundation)
|
||||||
|
implementation(androidx.compose.ui.ui)
|
||||||
|
implementation(androidx.compose.material3.material3)
|
||||||
|
implementation(androidx.activity.activity.compose)
|
||||||
implementation(androidx.core.core.ktx)
|
implementation(androidx.core.core.ktx)
|
||||||
implementation(androidx.appcompat.appcompat)
|
implementation(androidx.appcompat.appcompat)
|
||||||
implementation(com.google.android.material.material)
|
implementation(com.google.android.material.material)
|
||||||
implementation(androidx.constraintlayout.constraintlayout)
|
|
||||||
testImplementation(junit.junit)
|
testImplementation(junit.junit)
|
||||||
androidTestImplementation(androidx.test.ext.junit)
|
androidTestImplementation(androidx.test.ext.junit)
|
||||||
androidTestImplementation(androidx.test.espresso.espresso.core)
|
androidTestImplementation(androidx.test.espresso.espresso.core)
|
||||||
|
@@ -25,15 +25,33 @@
|
|||||||
*
|
*
|
||||||
* This file is created by fankes on 2023/1/21.
|
* This file is created by fankes on 2023/1/21.
|
||||||
*/
|
*/
|
||||||
@file:Suppress("SetTextI18n", "UsePropertyAccessSyntax")
|
@file:Suppress("UsePropertyAccessSyntax")
|
||||||
|
|
||||||
package com.highcapable.yukireflection.demo_app.ui
|
package com.highcapable.yukireflection.demo_app.ui
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.activity.compose.setContent
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.alpha
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import com.highcapable.yukireflection.YukiReflection
|
import com.highcapable.yukireflection.YukiReflection
|
||||||
import com.highcapable.yukireflection.demo_app.BuildConfig
|
import com.highcapable.yukireflection.demo_app.BuildConfig
|
||||||
import com.highcapable.yukireflection.demo_app.databinding.ActivityMainBinding
|
import com.highcapable.yukireflection.demo_app.R
|
||||||
import com.highcapable.yukireflection.demo_app.test.Main
|
import com.highcapable.yukireflection.demo_app.test.Main
|
||||||
import com.highcapable.yukireflection.factory.buildOf
|
import com.highcapable.yukireflection.factory.buildOf
|
||||||
import com.highcapable.yukireflection.factory.classOf
|
import com.highcapable.yukireflection.factory.classOf
|
||||||
@@ -47,37 +65,85 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
YukiReflection.configs { isDebug = BuildConfig.DEBUG }
|
YukiReflection.configs { isDebug = BuildConfig.DEBUG }
|
||||||
ActivityMainBinding.inflate(layoutInflater).apply {
|
setContent {
|
||||||
setContentView(root)
|
MaterialTheme(colorScheme = MaterialTheme.colorScheme.copy(primary = Color(ContextCompat.getColor(this, R.color.yuki_theme_color)))) {
|
||||||
yukiReflectionVersionText.text = "${YukiReflection.TAG} Version: ${YukiReflection.VERSION}"
|
MainLayout()
|
||||||
testObjectDirectlyButton.setOnClickListener {
|
|
||||||
tipText.text = Main("I am directly call of new object").getContent()
|
|
||||||
}
|
|
||||||
testObjectReflectionButton.setOnClickListener {
|
|
||||||
tipText.text =
|
|
||||||
classOf<Main>().buildOf("I am reflection call of new object") { param(StringClass) }
|
|
||||||
?.current()
|
|
||||||
?.method {
|
|
||||||
name = "getContent"
|
|
||||||
emptyParam()
|
|
||||||
}?.string() ?: ""
|
|
||||||
}
|
|
||||||
testStaticDirectlyButton.setOnClickListener {
|
|
||||||
tipText.text = Main.getStaticContent()
|
|
||||||
}
|
|
||||||
testStaticReflectionButton.setOnClickListener {
|
|
||||||
tipText.text = classOf<Main>().method {
|
|
||||||
name = "getStaticContent"
|
|
||||||
modifiers { isStatic }
|
|
||||||
}.get().string()
|
|
||||||
}
|
|
||||||
testModifyStaticReflectionButton.setOnClickListener {
|
|
||||||
classOf<Main>().field {
|
|
||||||
name = "staticContent"
|
|
||||||
modifiers { isStatic }
|
|
||||||
}.get().set("I am static! Modified by reflection")
|
|
||||||
tipText.text = "Field is modified success"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun MainLayout() {
|
||||||
|
val currentVersion = "${YukiReflection.TAG} Version: ${YukiReflection.VERSION}"
|
||||||
|
val operationState = remember { mutableStateOf("Waiting for your operation") }
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "Using functions below to test",
|
||||||
|
fontSize = 18.sp,
|
||||||
|
modifier = Modifier.padding(bottom = 15.dp)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = operationState.value,
|
||||||
|
fontSize = 18.sp,
|
||||||
|
modifier = Modifier.padding(bottom = 35.dp)
|
||||||
|
)
|
||||||
|
Button(
|
||||||
|
onClick = { operationState.value = Main("I am directly call of new object").getContent() },
|
||||||
|
modifier = Modifier.padding(bottom = 15.dp)
|
||||||
|
) {
|
||||||
|
Text(text = "Create an Object and Call Directly")
|
||||||
|
}
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
operationState.value =
|
||||||
|
classOf<Main>().buildOf("I am reflection call of new object") { param(StringClass) }
|
||||||
|
?.current()
|
||||||
|
?.method {
|
||||||
|
name = "getContent"
|
||||||
|
emptyParam()
|
||||||
|
}?.string() ?: ""
|
||||||
|
},
|
||||||
|
modifier = Modifier.padding(bottom = 15.dp)
|
||||||
|
) {
|
||||||
|
Text(text = "Create an Object and Call Reflection")
|
||||||
|
}
|
||||||
|
Button(
|
||||||
|
onClick = { operationState.value = Main.getStaticContent() },
|
||||||
|
modifier = Modifier.padding(bottom = 15.dp)
|
||||||
|
) {
|
||||||
|
Text(text = "Get Static and Call Directly")
|
||||||
|
}
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
operationState.value = classOf<Main>().method {
|
||||||
|
name = "getStaticContent"
|
||||||
|
modifiers { isStatic }
|
||||||
|
}.get().string()
|
||||||
|
},
|
||||||
|
modifier = Modifier.padding(bottom = 15.dp)
|
||||||
|
) {
|
||||||
|
Text(text = "Get Static and Call Reflection")
|
||||||
|
}
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
classOf<Main>().field {
|
||||||
|
name = "staticContent"
|
||||||
|
modifiers { isStatic }
|
||||||
|
}.get().set("I am static! Modified by reflection")
|
||||||
|
operationState.value = "Field is modified success"
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text(text = "Modified Static Field Using Reflection")
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
text = currentVersion,
|
||||||
|
fontSize = 15.sp,
|
||||||
|
modifier = Modifier.padding(top = 35.dp).alpha(0.55f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,70 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout 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"
|
|
||||||
android:gravity="center"
|
|
||||||
android:orientation="vertical"
|
|
||||||
tools:context=".ui.MainActivity"
|
|
||||||
tools:ignore="HardcodedText">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="15dp"
|
|
||||||
android:text="Using functions below to test"
|
|
||||||
android:textSize="18sp" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tip_text"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="35dp"
|
|
||||||
android:text="Waiting for your operation"
|
|
||||||
android:textSize="18sp" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/test_object_directly_button"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="15dp"
|
|
||||||
android:text="Create an Object and Call Directly" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/test_object_reflection_button"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="15dp"
|
|
||||||
android:text="Create an Object and Call Reflection" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/test_static_directly_button"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="15dp"
|
|
||||||
android:text="Get Static and Call Directly" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/test_static_reflection_button"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="15dp"
|
|
||||||
android:text="Get Static and Call Reflection" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/test_modify_static_reflection_button"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Modified Static Field Using Reflection" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/yuki_reflection_version_text"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="35dp"
|
|
||||||
android:alpha="0.55"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:gravity="center|start"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:textSize="15sp" />
|
|
||||||
</LinearLayout>
|
|
@@ -1,6 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
autowire(libs.plugins.kotlin.jvm)
|
autowire(libs.plugins.kotlin.jvm)
|
||||||
autowire(libs.plugins.kotlin.compose)
|
autowire(libs.plugins.jetbrains.compose)
|
||||||
}
|
}
|
||||||
|
|
||||||
group = property.project.samples.demo.jvm.groupName
|
group = property.project.samples.demo.jvm.groupName
|
||||||
@@ -19,5 +19,5 @@ compose.desktop {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(projects.yukireflectionCore)
|
implementation(projects.yukireflectionCore)
|
||||||
implementation(compose.desktop.currentOs)
|
implementation(compose.desktop.currentOs)
|
||||||
implementation(org.jetbrains.compose.material3.material3.desktop)
|
implementation(compose.material3)
|
||||||
}
|
}
|
Reference in New Issue
Block a user