@@ -9,15 +9,38 @@ import android.view.View
99import android.widget.AdapterView
1010import android.widget.Button
1111
12+ /* *
13+ * AppCompat Library Extensions
14+ *
15+ * @see <a href="https://github.com/fython/Kotlinyan/wiki/AppCompatExtensions">AppCompatExtensions Wiki</a>
16+ */
1217interface AppCompatExtensions {
1318
1419 // Kotlin-style builders
1520
21+ /* *
22+ * Build AppCompat v7 AlertDialog in Fragment
23+ *
24+ * @param process The process of building AppCompat v7 AlertDialog
25+ * @see android.support.v7.app.AlertDialog
26+ */
1627 fun Fragment.buildV7AlertDialog (process : AlertDialog .Builder .() -> Unit ) = activity.buildV7AlertDialog(process)
1728
29+ /* *
30+ * Build AppCompat v7 AlertDialog in Fragment
31+ *
32+ * @param process The process of building AppCompat v7 AlertDialog
33+ * @see android.support.v7.app.AlertDialog
34+ */
1835 fun android.support.v4.app.Fragment
1936 .buildV7AlertDialog (process : AlertDialog .Builder .() -> Unit ) = activity.buildV7AlertDialog(process)
2037
38+ /* *
39+ * Build AppCompat v7 AlertDialog in Activity
40+ *
41+ * @param process The process of building AppCompat v7 AlertDialog
42+ * @see android.support.v7.app.AlertDialog
43+ */
2144 fun Activity.buildV7AlertDialog (process : AlertDialog .Builder .() -> Unit ) : AlertDialog {
2245 val builder = AlertDialog .Builder (this )
2346 builder.process()
@@ -84,27 +107,81 @@ interface AppCompatExtensions {
84107 get() { throw java.lang.NoSuchMethodException (" View res id getter is not supported" ) }
85108 set(value) { this .setView(value) }
86109
87- fun AlertDialog.Builder.positiveButton (textId : Int , onClick : (DialogInterface , Int ) -> Unit ) {
110+ /* *
111+ * Set ok button for AlertDialog
112+ *
113+ * @param onClick onClick callback
114+ */
115+ fun AlertDialog.Builder.okButton (onClick : (DialogInterface , Int ) -> Unit = {_, _ -> }) {
116+ setPositiveButton(android.R .string.ok, onClick)
117+ }
118+
119+ /* *
120+ * Set cancel button for AlertDialog
121+ *
122+ * @param onClick onClick callback
123+ */
124+ fun AlertDialog.Builder.cancelButton (onClick : (DialogInterface , Int ) -> Unit = {_, _ -> }) {
125+ setNegativeButton(android.R .string.cancel, onClick)
126+ }
127+
128+ /* *
129+ * Set positive button for AlertDialog
130+ *
131+ * @param textId Text resource id
132+ * @param onClick onClick callback
133+ */
134+ fun AlertDialog.Builder.positiveButton (textId : Int , onClick : (DialogInterface , Int ) -> Unit = {_, _ -> }) {
88135 setPositiveButton(textId, onClick)
89136 }
90137
91- fun AlertDialog.Builder.positiveButton (text : String , onClick : (DialogInterface , Int ) -> Unit ) {
138+ /* *
139+ * Set positive button for AlertDialog
140+ *
141+ * @param text Text string
142+ * @param onClick onClick callback
143+ */
144+ fun AlertDialog.Builder.positiveButton (text : String , onClick : (DialogInterface , Int ) -> Unit = {_, _ -> }) {
92145 setPositiveButton(text, onClick)
93146 }
94147
95- fun AlertDialog.Builder.negativeButton (textId : Int , onClick : (DialogInterface , Int ) -> Unit ) {
148+ /* *
149+ * Set negative button for AlertDialog
150+ *
151+ * @param textId Text resource id
152+ * @param onClick onClick callback
153+ */
154+ fun AlertDialog.Builder.negativeButton (textId : Int , onClick : (DialogInterface , Int ) -> Unit = {_, _ -> }) {
96155 setNegativeButton(textId, onClick)
97156 }
98157
99- fun AlertDialog.Builder.negativeButton (text : String , onClick : (DialogInterface , Int ) -> Unit ) {
158+ /* *
159+ * Set negative button for AlertDialog
160+ *
161+ * @param text Text string
162+ * @param onClick onClick callback
163+ */
164+ fun AlertDialog.Builder.negativeButton (text : String , onClick : (DialogInterface , Int ) -> Unit = {_, _ -> }) {
100165 setNegativeButton(text, onClick)
101166 }
102167
103- fun AlertDialog.Builder.neutralButton (textId : Int , onClick : (DialogInterface , Int ) -> Unit ) {
168+ /* *
169+ * Set neutral button for AlertDialog
170+ *
171+ * @param textId Text resource id
172+ * @param onClick onClick callback
173+ */
174+ fun AlertDialog.Builder.neutralButton (textId : Int , onClick : (DialogInterface , Int ) -> Unit = {_, _ -> }) {
104175 setNeutralButton(textId, onClick)
105176 }
106177
107- fun AlertDialog.Builder.neutralButton (text : String , onClick : (DialogInterface , Int ) -> Unit ) {
178+ /* *
179+ * Set neutral button for AlertDialog
180+ *
181+ * @param text Text string
182+ * @param onClick onClick callback
183+ */
184+ fun AlertDialog.Builder.neutralButton (text : String , onClick : (DialogInterface , Int ) -> Unit = {_, _ -> }) {
108185 setNeutralButton(text, onClick)
109186 }
110187
0 commit comments