Skip to content

Commit d8c83f4

Browse files
committed
Common: Add javadoc
Signed-off-by: Fung <fython@163.com>
1 parent 11cee9e commit d8c83f4

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

kotlinyan-common/src/main/kotlin/moe/feng/kotlinyan/common/ActivityExtensions.kt

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.graphics.Color
1010
import android.graphics.drawable.Drawable
1111
import android.os.Build
1212
import android.os.Process
13-
import android.view.KeyEvent
1413
import android.view.Menu
1514
import android.view.MenuItem
1615
import android.view.View
@@ -22,6 +21,10 @@ interface ActivityExtensions: ServiceExtensions {
2221

2322
/**
2423
* If function is supported, call it safely.
24+
*
25+
* @param minSDK The minimum supported SDK
26+
* @param block Methods
27+
* @return Only if not supported, return null
2528
*/
2629
fun ifSupportSDK(minSDK: Int, block: () -> Unit) : (() -> Unit)? {
2730
if (Build.VERSION.SDK_INT >= minSDK) {
@@ -45,13 +48,17 @@ interface ActivityExtensions: ServiceExtensions {
4548

4649
/**
4750
* Tint color for a menu item
51+
*
52+
* @param color Color value
4853
*/
4954
fun MenuItem.tintColor(color : Int) {
5055
this.icon?.setTint(color)
5156
}
5257

5358
/**
5459
* Tint color for all menu items
60+
*
61+
* @param color Color value
5562
*/
5663
fun Menu.tintItemsColor(color : Int) {
5764
for (i in 0..size() - 1) getItem(i).tintColor(color)
@@ -130,6 +137,11 @@ interface ActivityExtensions: ServiceExtensions {
130137
/**
131138
* If you use Activity.runWithPermissions to request permission,
132139
* please call this method in onRequestPermissionsResult method of your activity
140+
*
141+
* @param requestCode The result of request code
142+
* @param permissions Permissions string array
143+
* @param grantResults Permissions result array
144+
* @param deniedCallback Denied permission callback
133145
*/
134146
fun Activity.handleOnRequestPermissionsResult(requestCode: Int,
135147
permissions: Array<out String>,
@@ -146,6 +158,12 @@ interface ActivityExtensions: ServiceExtensions {
146158

147159
// Kotlin-style builders
148160

161+
/**
162+
* Build AlertDialog in Activity
163+
*
164+
* @param process The process of building AlertDialog
165+
* @see android.app.AlertDialog
166+
*/
149167
fun Activity.buildAlertDialog(process: AlertDialog.Builder.() -> Unit) : AlertDialog {
150168
val builder = AlertDialog.Builder(this)
151169
builder.process()
@@ -212,26 +230,80 @@ interface ActivityExtensions: ServiceExtensions {
212230
get() { throw NoSuchMethodException("View res id getter is not supported")}
213231
set(value) { this.setView(value) }
214232

233+
/**
234+
* Set ok button for AlertDialog
235+
*
236+
* @param onClick onClick callback
237+
*/
238+
fun AlertDialog.Builder.okButton(onClick: (DialogInterface, Int) -> Unit = {_, _ ->}) {
239+
setPositiveButton(android.R.string.ok, onClick)
240+
}
241+
242+
/**
243+
* Set cancel button for AlertDialog
244+
*
245+
* @param onClick onClick callback
246+
*/
247+
fun AlertDialog.Builder.cancelButton(onClick: (DialogInterface, Int) -> Unit = {_, _ ->}) {
248+
setNegativeButton(android.R.string.cancel, onClick)
249+
}
250+
251+
/**
252+
* Set positive button for AlertDialog
253+
*
254+
* @param textId Text resource id
255+
* @param onClick onClick callback
256+
*/
215257
fun AlertDialog.Builder.positiveButton(textId: Int, onClick: (DialogInterface, Int) -> Unit) {
216258
setPositiveButton(textId, onClick)
217259
}
218260

261+
/**
262+
* Set positive button for AlertDialog
263+
*
264+
* @param text Text string
265+
* @param onClick onClick callback
266+
*/
219267
fun AlertDialog.Builder.positiveButton(text: String, onClick: (DialogInterface, Int) -> Unit) {
220268
setPositiveButton(text, onClick)
221269
}
222270

271+
/**
272+
* Set negative button for AlertDialog
273+
*
274+
* @param textId Text resource id
275+
* @param onClick onClick callback
276+
*/
223277
fun AlertDialog.Builder.negativeButton(textId: Int, onClick: (DialogInterface, Int) -> Unit) {
224278
setNegativeButton(textId, onClick)
225279
}
226280

281+
/**
282+
* Set negative button for AlertDialog
283+
*
284+
* @param text Text string
285+
* @param onClick onClick callback
286+
*/
227287
fun AlertDialog.Builder.negativeButton(text: String, onClick: (DialogInterface, Int) -> Unit) {
228288
setNegativeButton(text, onClick)
229289
}
230290

291+
/**
292+
* Set neutral button for AlertDialog
293+
*
294+
* @param textId Text resource id
295+
* @param onClick onClick callback
296+
*/
231297
fun AlertDialog.Builder.neutralButton(textId: Int, onClick: (DialogInterface, Int) -> Unit) {
232298
setNeutralButton(textId, onClick)
233299
}
234300

301+
/**
302+
* Set neutral button for AlertDialog
303+
*
304+
* @param text Text string
305+
* @param onClick onClick callback
306+
*/
235307
fun AlertDialog.Builder.neutralButton(text: String, onClick: (DialogInterface, Int) -> Unit) {
236308
setNeutralButton(text, onClick)
237309
}

kotlinyan-common/src/main/kotlin/moe/feng/kotlinyan/common/FragmentExtensions.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import android.app.Fragment
55

66
interface FragmentExtensions: ActivityExtensions {
77

8+
/**
9+
* Build AlertDialog in Fragment
10+
*
11+
* @param process The process of building AlertDialog
12+
* @see android.app.AlertDialog
13+
*/
814
fun Fragment.buildAlertDialog(process: AlertDialog.Builder.() -> Unit) = activity.buildAlertDialog(process)
915

1016
}

0 commit comments

Comments
 (0)