Skip to content

Commit

Permalink
jetpack界面UI
Browse files Browse the repository at this point in the history
  • Loading branch information
iOrchid committed Mar 20, 2024
1 parent 5016b43 commit f82255f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ android {

//使用动态模块的形式,用于隔离代码module的依赖
dynamicFeatures += setOf(":jetpack:jetpack", ":kotlin", ":compose")
//jetpack模块有dataBinding,所以这里要声明
buildFeatures { dataBinding = true }

}

dependencies {
//因为app使用的theme是material的,因为使用了dynamicFeature依赖的module,所以如果多个dynamic的模块有共同的依赖库,则app中需要添加
implementation(libs.material)
implementation(libs.constraintlayout)
//接入jetpack的动态module,需要通用依赖
implementation(libs.lifecycle.livedata.ktx)
implementation(libs.navigation.ui.ktx)
implementation(libs.work.runtime.ktx)
implementation(libs.blankj.utils)

//compose 相关 ,因为有dynamic的组件,compose的,所以宿主模块也要有必要的依赖,否则会报错。
//这里android闭包内不需要compose的compiler和buildFeature,如果是普通module的依赖,则需要主module也开启。
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
</style>

<style name="Theme.Jetpack" parent="AppTheme" />

</resources>
6 changes: 6 additions & 0 deletions jetpack/jetpack/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.androidDynamicFeature)
alias(libs.plugins.org.jetbrains.kotlin.android)
alias(libs.plugins.ksp)
}

android {
Expand Down Expand Up @@ -28,11 +29,16 @@ android {
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures { dataBinding = true }
}

dependencies {

implementation(project(":app"))
implementation(project(":jetpack:databinding"))
implementation(project(":jetpack:work"))

implementation(libs.material)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
package org.zhiwei.jetpack.components

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import org.zhiwei.jetpack.databinding.DataBindingActivity
import org.zhiwei.jetpack.work.WorkActivity

/**
* jetpack相关演示代码的功能模块的主入口页面
*/
class JetpackActivity : Activity() {

private val btnDataBinding: Button by lazy { findViewById(R.id.btn_databinding_jetpack) }
private val btnWorkManager: Button by lazy { findViewById(R.id.btn_work_jetpack) }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//此界面在AndroidManifest中使用了theme,状态栏和导航栏的透明
setContentView(R.layout.activity_jetpack)
btnDataBinding.setOnClickListener {
startActivity(
Intent(
this,
DataBindingActivity::class.java
)
)
}
btnWorkManager.setOnClickListener { startActivity(Intent(this, WorkActivity::class.java)) }
}
}
23 changes: 20 additions & 3 deletions jetpack/jetpack/src/main/res/layout/activity_jetpack.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
android:padding="8dp">

<TextView
<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/hongkong"
android:gravity="center"
android:text="@string/title_jetpack"
android:textSize="22sp" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_databinding_jetpack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dataBinding" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_work_jetpack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_jetpack" />
android:text="WorkManager" />

</LinearLayout>

0 comments on commit f82255f

Please sign in to comment.