-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/loongwind/ardf/demo/DetailsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
app/src/main/java/com/loongwind/ardf/demo/TestViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters