Skip to content

Commit 6b387f4

Browse files
author
Jarvis
committed
自定义 View 的 MVP
1 parent 33f6d12 commit 6b387f4

File tree

6 files changed

+136
-0
lines changed

6 files changed

+136
-0
lines changed

app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
android:supportsRtl="true"
1111
android:theme="@style/AppTheme">
1212
<activity android:name=".test.TestActivity"></activity>
13+
<activity android:name=".main2.Main2Activity"></activity>
1314
<activity android:name=".MainActivity">
1415
<intent-filter>
1516
<action android:name="android.intent.action.MAIN" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.test.me.main2;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.app.AppCompatActivity;
6+
7+
import com.test.me.R;
8+
import com.test.me.main2.presenter.Main2Presenter;
9+
import com.test.me.main2.view.Main2View;
10+
11+
public class Main2Activity extends AppCompatActivity {
12+
13+
private Main2Presenter main2Presenter;
14+
15+
@Override
16+
protected void onCreate(@Nullable Bundle savedInstanceState) {
17+
super.onCreate(savedInstanceState);
18+
19+
setContentView(R.layout.activity_main2);
20+
21+
main2Presenter = new Main2Presenter(new Main2View(findViewById(R.id.ll_container)));
22+
23+
main2Presenter.start();
24+
}
25+
26+
@Override
27+
protected void onDestroy() {
28+
29+
main2Presenter.destroy();
30+
31+
super.onDestroy();
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.test.me.main2.model
2+
3+
class Main2Model {
4+
5+
fun loadData() {}
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.test.me.main2.presenter
2+
3+
import com.test.me.main2.model.Main2Model
4+
import com.test.me.main2.view.Main2View
5+
import kotlinx.coroutines.CoroutineScope
6+
import kotlinx.coroutines.MainScope
7+
import kotlinx.coroutines.cancel
8+
9+
class Main2Presenter(private val main2View: Main2View): CoroutineScope by MainScope() {
10+
11+
private val model = Main2Model()
12+
13+
fun start() {
14+
15+
main2View.initView(this)
16+
17+
main2View.hideView()
18+
19+
model.loadData()
20+
21+
main2View.showView()
22+
}
23+
24+
fun loadDataAndJumpToPage() {
25+
26+
}
27+
28+
fun destroy() {
29+
cancel()
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.test.me.main2.view
2+
3+
import android.content.Context
4+
import android.view.View
5+
import com.test.me.main2.presenter.Main2Presenter
6+
import kotlinx.android.synthetic.main.activity_main2.view.*
7+
8+
class Main2View(private val rootView: View) {
9+
10+
val context: Context = rootView.context
11+
12+
fun initView(main2Presenter: Main2Presenter) {
13+
14+
rootView.btn1.setOnClickListener {
15+
16+
main2Presenter.loadDataAndJumpToPage()
17+
}
18+
19+
rootView.btn2.setOnClickListener {
20+
21+
}
22+
23+
}
24+
25+
fun hideView() {
26+
27+
}
28+
29+
fun showView() {
30+
31+
}
32+
}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
xmlns:app="http://schemas.android.com/apk/res-auto"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
tools:context=".MainActivity">
9+
10+
<LinearLayout
11+
android:id="@+id/ll_container"
12+
android:layout_width="200dp"
13+
android:layout_height="400dp"
14+
android:orientation="vertical"
15+
app:layout_constraintBottom_toBottomOf="parent"
16+
app:layout_constraintLeft_toLeftOf="parent"
17+
app:layout_constraintRight_toRightOf="parent"
18+
app:layout_constraintTop_toTopOf="parent">
19+
20+
<Button
21+
android:id="@+id/btn1"
22+
android:layout_width="wrap_content"
23+
android:layout_height="wrap_content"/>
24+
25+
<Button
26+
android:id="@+id/btn2"
27+
android:layout_width="wrap_content"
28+
android:layout_height="wrap_content"/>
29+
30+
</LinearLayout>
31+
32+
</android.support.constraint.ConstraintLayout>

0 commit comments

Comments
 (0)