Skip to content

Commit

Permalink
add demo
Browse files Browse the repository at this point in the history
  • Loading branch information
loongwind committed Jul 27, 2022
1 parent 123d6e1 commit 05a5c4a
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
android:exported="false"
android:label="@string/title_activity_recycle_view_simple"
android:theme="@style/Theme.AndroidFramework.NoActionBar" />
<activity
android:name=".DetailsActivity"
android:exported="false"
android:label="@string/title_activity_recycle_view_simple"
android:theme="@style/Theme.AndroidFramework.NoActionBar" />
</application>

</manifest>
1 change: 1 addition & 0 deletions app/src/main/java/com/loongwind/ardf/demo/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ val appModule = module {
viewModel{ RecycleViewModel()}
viewModel{ MultiItemViewModel()}
viewModel{ MainViewModel()}
viewModel{ TestViewModel()}
}
15 changes: 15 additions & 0 deletions app/src/main/java/com/loongwind/ardf/demo/DetailsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.loongwind.ardf.demo

import com.loongwind.ardf.base.BaseBindingActivity
import com.loongwind.ardf.base.BaseBindingViewModelActivity
import com.loongwind.ardf.demo.databinding.DetailsPageBinding
import com.loongwind.ardf.demo.databinding.TestPageBinding

//泛型类型是布局通过 DataBinding 自动生成的 ViewDataBinding 类型
class DetailsActivity : BaseBindingViewModelActivity<DetailsPageBinding, TestViewModel>() {

// // 通过 binding 操作界面元素更新界面
// override fun initDataBinding(binding: TestPageBinding) {
// binding.text = "Hello ardf"
// }
}
40 changes: 40 additions & 0 deletions app/src/main/java/com/loongwind/ardf/demo/TestActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.loongwind.ardf.demo

import android.content.DialogInterface
import android.content.Intent
import androidx.appcompat.app.AlertDialog
import com.loongwind.ardf.base.BaseBindingActivity
import com.loongwind.ardf.base.BaseBindingViewModelActivity
import com.loongwind.ardf.demo.databinding.TestPageBinding

//泛型类型是布局通过 DataBinding 自动生成的 ViewDataBinding 类型
class TestActivity : BaseBindingViewModelActivity<TestPageBinding, TestViewModel>() {

// // 通过 binding 操作界面元素更新界面
// override fun initDataBinding(binding: TestPageBinding) {
// binding.text = "Hello ardf"
// }


// 接收事件
override fun onEvent(eventId: Int) {
super.onEvent(eventId)
// 判断事件 id 并进行对应处理
when(eventId){
TestViewModel.EVENT_TO_DETAILS -> startActivity(Intent(this, DetailsActivity::class.java))
TestViewModel.EVENT_SHOW_DIALOG -> {
AlertDialog.Builder(this)
.setTitle("Dialog")
.setMessage("this is dialog")
.setNegativeButton("cancel") { dialog, which ->
dialog.dismiss()
}
.setPositiveButton("OK") { dialog, which ->
dialog.dismiss()
}
.show()
}
}

}
}
39 changes: 39 additions & 0 deletions app/src/main/java/com/loongwind/ardf/demo/TestViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.loongwind.ardf.demo

import com.loongwind.ardf.base.BaseViewModel

class TestViewModel : BaseViewModel(){
val text = "Hello ardf ViewModel"

fun showToastString(){
//传入字符串
postHintText("Hello ardf toast")
}

fun showToastStringRes(){
//传入字符串资源
postHintText(R.string.hello)
}

fun goBack(){
//调用父类提供的 back 方法
back()
}

companion object {
// 定义跳转到详情页的事件 id
const val EVENT_TO_DETAILS = 0x00
// 定义弹出 Dialog 的事件 id
const val EVENT_SHOW_DIALOG = 0x01
}

fun toDetailsPage(){
// 发送跳转详情页事件
postEvent(EVENT_TO_DETAILS)
}

fun showDialog(){
// 发送弹出 Dialog 事件
postEvent(EVENT_SHOW_DIALOG)
}
}
20 changes: 20 additions & 0 deletions app/src/main/res/layout/details_page.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="10dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:textSize="30sp"
android:text="Details Page"/>

</LinearLayout>
</layout>
35 changes: 35 additions & 0 deletions app/src/main/res/layout/test_page.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<data>
<variable
name="vm"
type="com.loongwind.ardf.demo.TestViewModel" />
</data>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="10dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:textSize="30sp"
android:text="@{vm.text}"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="to Details"
android:onClick="@{()->vm.toDetailsPage()}"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="show dialog"
android:onClick="@{()->vm.showDialog()}"/>

</LinearLayout>
</layout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<string name="hello_first_fragment">Hello first fragment</string>
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
<string name="title_activity_recycle_view_simple">RecycleViewSimpleActivity</string>
<string name="hello">Hello ardf toast res</string>
</resources>

0 comments on commit 05a5c4a

Please sign in to comment.