1+ package moe.feng.kotlinyan.common
2+
3+ import android.app.Activity
4+ import android.app.Fragment
5+ import android.content.DialogInterface
6+ import android.graphics.drawable.Drawable
7+ import android.support.v7.app.AlertDialog
8+ import android.view.View
9+ import android.widget.AdapterView
10+
11+ interface AppCompatExtensions {
12+
13+ // Kotlin-style builders
14+
15+ fun Fragment.buildV7AlertDialog (process : AlertDialog .Builder .() -> Unit ) = activity.buildV7AlertDialog(process)
16+
17+ fun android.support.v4.app.Fragment
18+ .buildV7AlertDialog (process : AlertDialog .Builder .() -> Unit ) = activity.buildV7AlertDialog(process)
19+
20+ fun Activity.buildV7AlertDialog (process : AlertDialog .Builder .() -> Unit ) : AlertDialog {
21+ val builder = AlertDialog .Builder (this )
22+ builder.process()
23+ return builder.create()
24+ }
25+
26+ var AlertDialog .Builder .title : String
27+ get() { throw java.lang.NoSuchMethodException (" Title getter is not supported" ) }
28+ set(value) { this .setTitle(value) }
29+
30+ var AlertDialog .Builder .titleRes : Int
31+ get() { throw java.lang.NoSuchMethodException (" Title res id getter is not supported" ) }
32+ set(value) { this .setTitle(value) }
33+
34+ var AlertDialog .Builder .message : String
35+ get() { throw java.lang.NoSuchMethodException (" Message getter is not supported" ) }
36+ set(value) { this .setMessage(value) }
37+
38+ var AlertDialog .Builder .messageRes : Int
39+ get() { throw java.lang.NoSuchMethodException (" Message res id getter is not supported" ) }
40+ set(value) { this .setMessage(value) }
41+
42+ var AlertDialog .Builder .isCancelable : Boolean
43+ get() { throw java.lang.NoSuchMethodException (" isCancelable getter is not supported" ) }
44+ set(value) { this .setCancelable(value) }
45+
46+ var AlertDialog .Builder .customTitle : View
47+ get() { throw java.lang.NoSuchMethodException (" Custom title getter is not supported" ) }
48+ set(value) { this .setCustomTitle(value) }
49+
50+ var AlertDialog .Builder .icon : Drawable
51+ get() { throw java.lang.NoSuchMethodException (" Icon getter is not supported" ) }
52+ set(value) { this .setIcon(value) }
53+
54+ var AlertDialog .Builder .iconRes : Int
55+ get() { throw java.lang.NoSuchMethodException (" Icon res id getter is not supported" ) }
56+ set(value) { this .setIcon(value) }
57+
58+ var AlertDialog .Builder .iconAttribute : Int
59+ get() { throw java.lang.NoSuchMethodException (" Icon attribute getter is not supported" ) }
60+ set(value) { this .setIconAttribute(value) }
61+
62+ var AlertDialog .Builder .onCancel : (DialogInterface ) -> Unit
63+ get() { throw java.lang.NoSuchMethodException (" OnCancelListener getter is not supported" ) }
64+ set(value) { this .setOnCancelListener(value) }
65+
66+ var AlertDialog .Builder .onDismiss : (DialogInterface ) -> Unit
67+ get() { throw java.lang.NoSuchMethodException (" OnDismissListener getter is not supported" ) }
68+ set(value) { this .setOnDismissListener(value) }
69+
70+ var AlertDialog .Builder .onKey : DialogInterface .OnKeyListener
71+ get() { throw java.lang.NoSuchMethodException (" OnKeyListener getter is not supported" ) }
72+ set(value) { this .setOnKeyListener(value) }
73+
74+ var AlertDialog .Builder .onItemSelected : AdapterView .OnItemSelectedListener
75+ get() { throw java.lang.NoSuchMethodException (" OnItemSelectedListener getter is not supported" ) }
76+ set(value) { this .setOnItemSelectedListener(value) }
77+
78+ var AlertDialog .Builder .view : View
79+ get() { throw java.lang.NoSuchMethodException (" View getter is not supported" ) }
80+ set(value) { this .setView(value) }
81+
82+ var AlertDialog .Builder .viewRes : Int
83+ get() { throw java.lang.NoSuchMethodException (" View res id getter is not supported" ) }
84+ set(value) { this .setView(value) }
85+
86+ fun AlertDialog.Builder.positiveButton (textId : Int , onClick : (DialogInterface , Int ) -> Unit ) {
87+ setPositiveButton(textId, onClick)
88+ }
89+
90+ fun AlertDialog.Builder.positiveButton (text : String , onClick : (DialogInterface , Int ) -> Unit ) {
91+ setPositiveButton(text, onClick)
92+ }
93+
94+ fun AlertDialog.Builder.negativeButton (textId : Int , onClick : (DialogInterface , Int ) -> Unit ) {
95+ setNegativeButton(textId, onClick)
96+ }
97+
98+ fun AlertDialog.Builder.negativeButton (text : String , onClick : (DialogInterface , Int ) -> Unit ) {
99+ setNegativeButton(text, onClick)
100+ }
101+
102+ fun AlertDialog.Builder.neutralButton (textId : Int , onClick : (DialogInterface , Int ) -> Unit ) {
103+ setNeutralButton(textId, onClick)
104+ }
105+
106+ fun AlertDialog.Builder.neutralButton (text : String , onClick : (DialogInterface , Int ) -> Unit ) {
107+ setNeutralButton(text, onClick)
108+ }
109+
110+ }
0 commit comments