refactor: migration layout to Hikage

This commit is contained in:
2025-06-11 12:39:05 +08:00
parent fafd54139b
commit 6ead14e65b
7 changed files with 250 additions and 404 deletions

View File

@@ -1,6 +1,7 @@
plugins {
autowire(libs.plugins.android.application)
autowire(libs.plugins.kotlin.android)
autowire(libs.plugins.kotlin.ksp)
}
android {
@@ -41,6 +42,11 @@ android {
}
dependencies {
ksp(com.highcapable.hikage.hikage.compiler)
implementation(com.highcapable.hikage.hikage.core)
implementation(com.highcapable.hikage.hikage.extension)
implementation(com.highcapable.hikage.hikage.widget.androidx)
implementation(com.highcapable.hikage.hikage.widget.material)
implementation(androidx.core.core.ktx)
implementation(androidx.appcompat.appcompat)
implementation(androidx.lifecycle.lifecycle.viewmodel.ktx)

View File

@@ -19,35 +19,99 @@
*
* This file is created by fankes on 2022/2/9.
*/
@file:Suppress("SameParameterValue", "UsePropertyAccessSyntax")
@file:Suppress("SetTextI18n", "SameParameterValue", "UsePropertyAccessSyntax")
package com.highcapable.yukihookapi.demo_app.ui
import android.os.Bundle
import android.widget.Toast
import android.view.Gravity
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.highcapable.yukihookapi.demo_app.databinding.ActivityMainBinding
import com.highcapable.betterandroid.ui.extension.view.toast
import com.highcapable.betterandroid.ui.extension.view.updateMargins
import com.highcapable.hikage.extension.setContentView
import com.highcapable.hikage.widget.android.widget.Button
import com.highcapable.hikage.widget.android.widget.ImageView
import com.highcapable.hikage.widget.android.widget.LinearLayout
import com.highcapable.hikage.widget.android.widget.TextView
import com.highcapable.hikage.widget.androidx.core.widget.NestedScrollView
import com.highcapable.yukihookapi.demo_app.R
import com.highcapable.yukihookapi.demo_app.test.Main
import android.R as Android_R
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ActivityMainBinding.inflate(layoutInflater).apply {
setContentView(root)
appDemoFirstText.text = getFirstText()
appDemoSecondText.text = secondText
appDemoThirdText.text = Main("Feel real").getString()
appDemoFourthText.text = getRegularText("Have fun day")
appDemoFifthText.text = getDataText()
appDemoSixthText.text = getArray(arrayOf("apple", "banana")).let { "${it[0]}, ${it[1]}" }
appDemoSeventhText.text = Main().getTestResultFirst()
appDemoEighthText.text = Main().getTestResultFirst("Find something interesting")
appDemoNinthText.text = Main().getTestResultLast()
appDemoTenthText.text = Main().getTestResultLast("This is the last sentence")
appDemoEleventhText.text = Main().getSuperString()
appDemoButton.setOnClickListener { toast() }
val hikage = setContentView {
NestedScrollView(
lparams = LayoutParams(matchParent = true),
init = {
isFillViewport = true
isVerticalScrollBarEnabled = false
}
) {
LinearLayout(
lparams = LayoutParams(widthMatchParent = true) {
updateMargins(vertical = 20.dp)
},
init = {
orientation = LinearLayout.VERTICAL
gravity = Gravity.CENTER
}
) {
ImageView(
lparams = LayoutParams(50.dp, 50.dp) {
bottomMargin = 15.dp
}
) {
setImageResource(R.mipmap.ic_face_unhappy)
}
TextView(
lparams = LayoutParams {
bottomMargin = 25.dp
}
) {
text = stringResource(R.string.test_string)
textSize = 17.5f
}
repeat(11) {
TextView(
id = "sample_text_$it",
lparams = LayoutParams {
bottomMargin = 15.dp
}
) {
text = stringResource(R.string.test_string)
textSize = 17.5f
}
}
ImageView(
lparams = LayoutParams(30.dp, 30.dp) {
bottomMargin = 15.dp
}
) {
setImageResource(Android_R.mipmap.sym_def_app_icon)
}
Button {
text = "Click Me!"
setOnClickListener { toast() }
}
}
}
}
hikage.get<TextView>("sample_text_0").text = getFirstText()
hikage.get<TextView>("sample_text_1").text = secondText
hikage.get<TextView>("sample_text_2").text = Main("Feel real").getString()
hikage.get<TextView>("sample_text_3").text = getRegularText("Have fun day")
hikage.get<TextView>("sample_text_4").text = getDataText()
hikage.get<TextView>("sample_text_5").text = getArray(arrayOf("apple", "banana")).let { "${it[0]}, ${it[1]}" }
hikage.get<TextView>("sample_text_6").text = Main().getTestResultFirst()
hikage.get<TextView>("sample_text_7").text = Main().getTestResultFirst("Find something interesting")
hikage.get<TextView>("sample_text_8").text = Main().getTestResultLast()
hikage.get<TextView>("sample_text_9").text = Main().getTestResultLast("This is the last sentence")
hikage.get<TextView>("sample_text_10").text = Main().getSuperString()
}
private val secondText = "This is a miracle"
@@ -60,5 +124,5 @@ class MainActivity : AppCompatActivity() {
private fun getDataText() = "No data found"
private fun toast() = Toast.makeText(this, "Nothing to show", Toast.LENGTH_SHORT).show()
private fun toast() = toast("Nothing to show")
}

View File

@@ -1,132 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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:fillViewport="true"
android:scrollbars="none"
tools:ignore="HardcodedText,ContentDescription">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="15dp"
android:src="@mipmap/ic_face_unhappy" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:text="@string/test_string"
android:textSize="17.5sp" />
<TextView
android:id="@+id/app_demo_first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="17.5sp" />
<TextView
android:id="@+id/app_demo_second_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="17.5sp" />
<TextView
android:id="@+id/app_demo_eleventh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="17.5sp" />
<TextView
android:id="@+id/app_demo_third_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="17.5sp" />
<TextView
android:id="@+id/app_demo_fourth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="17.5sp" />
<TextView
android:id="@+id/app_demo_seventh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="17.5sp" />
<TextView
android:id="@+id/app_demo_eighth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="17.5sp" />
<TextView
android:id="@+id/app_demo_ninth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="17.5sp" />
<TextView
android:id="@+id/app_demo_tenth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="17.5sp" />
<TextView
android:id="@+id/app_demo_sixth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="17.5sp" />
<TextView
android:id="@+id/app_demo_fifth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="sample"
android:textSize="17.5sp" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginBottom="15dp"
android:src="@android:mipmap/sym_def_app_icon" />
<Button
android:id="@+id/app_demo_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me!"
android:textAllCaps="false" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>