-
Notifications
You must be signed in to change notification settings - Fork 0
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
9 changed files
with
130 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
...phcbest/designpatterns/behaviorPattern/chainOfResponsibility/ChainOfResponsibilityDemo.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,14 @@ | ||
package com.phcbest.designpatterns.behaviorPattern.chainOfResponsibility | ||
|
||
import android.content.Context | ||
|
||
object ChainOfResponsibilityDemo { | ||
fun doChainOfResponsibility(context: Context) { | ||
val dialogUnit1 = DialogUnit1() | ||
val dialogUnit2 = DialogUnit2() | ||
val dialogUnit3 = DialogUnit3() | ||
dialogUnit1.setNextUnit(dialogUnit2) | ||
dialogUnit2.setNextUnit(dialogUnit3) | ||
dialogUnit1.handlerRequest(context) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...main/java/com/phcbest/designpatterns/behaviorPattern/chainOfResponsibility/DialogUnit1.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,24 @@ | ||
package com.phcbest.designpatterns.behaviorPattern.chainOfResponsibility | ||
|
||
import android.app.AlertDialog | ||
import android.content.Context | ||
|
||
class DialogUnit1 : IChainOfResponsibilityHandler { | ||
|
||
private var mNextHandler: IChainOfResponsibilityHandler? = null | ||
|
||
override fun setNextUnit(handler: IChainOfResponsibilityHandler) { | ||
mNextHandler = handler | ||
} | ||
|
||
override fun handlerRequest(context: Context) { | ||
AlertDialog.Builder(context).setTitle("处理器1").setMessage("处理器1") | ||
.setNegativeButton("处理") { dialog, which -> | ||
mNextHandler?.handlerRequest(context) | ||
}.setNeutralButton("取消处理") { dialog, which -> | ||
return@setNeutralButton | ||
}.show() | ||
} | ||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...main/java/com/phcbest/designpatterns/behaviorPattern/chainOfResponsibility/DialogUnit2.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,24 @@ | ||
package com.phcbest.designpatterns.behaviorPattern.chainOfResponsibility | ||
|
||
import android.app.AlertDialog | ||
import android.content.Context | ||
|
||
class DialogUnit2 : IChainOfResponsibilityHandler { | ||
|
||
private var mNextHandler: IChainOfResponsibilityHandler? = null | ||
|
||
override fun setNextUnit(handler: IChainOfResponsibilityHandler) { | ||
mNextHandler = handler | ||
} | ||
|
||
override fun handlerRequest(context: Context) { | ||
AlertDialog.Builder(context).setTitle("处理器2").setMessage("处理器2") | ||
.setNegativeButton("处理") { dialog, which -> | ||
mNextHandler?.handlerRequest(context) | ||
}.setNeutralButton("取消处理") { dialog, which -> | ||
return@setNeutralButton | ||
}.show() | ||
} | ||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...main/java/com/phcbest/designpatterns/behaviorPattern/chainOfResponsibility/DialogUnit3.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,24 @@ | ||
package com.phcbest.designpatterns.behaviorPattern.chainOfResponsibility | ||
|
||
import android.app.AlertDialog | ||
import android.content.Context | ||
|
||
class DialogUnit3 : IChainOfResponsibilityHandler { | ||
|
||
private var mNextHandler: IChainOfResponsibilityHandler? = null | ||
|
||
override fun setNextUnit(handler: IChainOfResponsibilityHandler) { | ||
mNextHandler = handler | ||
} | ||
|
||
override fun handlerRequest(context: Context) { | ||
AlertDialog.Builder(context).setTitle("处理器3").setMessage("处理器3") | ||
.setNegativeButton("处理") { dialog, which -> | ||
mNextHandler?.handlerRequest(context) | ||
}.setNeutralButton("取消处理") { dialog, which -> | ||
return@setNeutralButton | ||
}.show() | ||
} | ||
|
||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...est/designpatterns/behaviorPattern/chainOfResponsibility/IChainOfResponsibilityHandler.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,8 @@ | ||
package com.phcbest.designpatterns.behaviorPattern.chainOfResponsibility | ||
|
||
import android.content.Context | ||
|
||
interface IChainOfResponsibilityHandler { | ||
fun setNextUnit(handler: IChainOfResponsibilityHandler) | ||
fun handlerRequest(context: Context) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ui.dashboard.DashboardFragment"> | ||
|
||
<TextView | ||
android:id="@+id/text_dashboard" | ||
<GridLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:layout_marginEnd="8dp" | ||
android:textAlignment="center" | ||
android:textSize="20sp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
android:layout_height="match_parent" | ||
android:columnCount="4"> | ||
|
||
|
||
<com.google.android.material.button.MaterialButton | ||
android:id="@+id/btn_chain_of_responsibility" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_columnWeight="1" | ||
android:text="责任链模式" /> | ||
</GridLayout> | ||
|
||
</FrameLayout> |