Skip to content

Commit 11cee9e

Browse files
committed
Project: Add javadoc(s) & Add okButton/cancelButton
Signed-off-by: Fung <fython@163.com>
1 parent a693abe commit 11cee9e

File tree

4 files changed

+122
-8
lines changed

4 files changed

+122
-8
lines changed

kotlinyan-appcompat-support/src/main/kotlin/moe/feng/kotlinyan/common/AppCompatExtensions.kt

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,38 @@ import android.view.View
99
import android.widget.AdapterView
1010
import 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+
*/
1217
interface 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

kotlinyan-appcompat-support/src/main/kotlin/moe/feng/kotlinyan/common/SupportDesignExtensions.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@ import android.content.res.ColorStateList
44
import android.support.design.widget.Snackbar
55
import android.view.View
66

7+
/**
8+
* Support Design Library Extensions
9+
*
10+
* Help developers to use Android Support Design Library's widgets
11+
*
12+
* @see <a href="https://github.com/fython/Kotlinyan/wiki/SupportDesignExtensions">SupportDesignExtensions Wiki</a>
13+
*/
714
interface SupportDesignExtensions {
815

16+
/**
17+
* Make snackbar on parent view
18+
*
19+
* @param process the process of building snackbar
20+
*/
921
fun View.snackbar(process: SnackbarBuilder.() -> Unit) : Snackbar {
1022
val builder = SnackbarBuilder(this)
1123
builder.process()
1224
return builder.build()
1325
}
1426

15-
class SnackbarBuilder(view: View) {
27+
/**
28+
* Snackbar Builder
29+
*/
30+
class SnackbarBuilder internal constructor(view: View) {
1631

1732
private var snackbar : Snackbar = Snackbar.make(view, "", Snackbar.LENGTH_SHORT)
1833

kotlinyan-recyclerview-support/src/main/kotlin/moe/feng/kotlinyan/common/OnLoadMoreListener.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import android.support.v7.widget.LinearLayoutManager
55
import android.support.v7.widget.RecyclerView
66
import android.support.v7.widget.StaggeredGridLayoutManager
77

8+
/**
9+
* A type of RecyclerView OnScrollListener help you to listen load more event
10+
*/
811
class OnLoadMoreListener(private val callback: OnLoadMoreListener.Callback) : RecyclerView.OnScrollListener() {
912

1013
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
@@ -38,6 +41,9 @@ class OnLoadMoreListener(private val callback: OnLoadMoreListener.Callback) : Re
3841
}
3942

4043
interface Callback {
44+
/**
45+
* When RecyclerView should load more contents (Whether or not there is more), onLoadMore() will be called
46+
*/
4147
fun onLoadMore()
4248
}
4349

kotlinyan-recyclerview-support/src/main/kotlin/moe/feng/kotlinyan/common/RecyclerViewExtensions.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@ package moe.feng.kotlinyan.common
33
import android.support.v7.widget.GridLayoutManager
44
import android.support.v7.widget.RecyclerView
55

6+
/**
7+
* RecyclerView Extensions
8+
*
9+
* @see android.support.v7.widget.RecyclerView
10+
* @see <a href="https://github.com/fython/Kotlinyan/wiki/RecyclerViewExtensions">RecyclerViewExtensions Wiki</a>
11+
*/
612
interface RecyclerViewExtensions {
713

14+
/**
15+
* When RecyclerView should load more contents, action will be done.
16+
*
17+
* @param action What should be done when it need to load more
18+
*/
819
fun RecyclerView.onLoadMore(action: () -> Unit) {
920
this.addOnScrollListener(OnLoadMoreListener(object: OnLoadMoreListener.Callback {
1021
override fun onLoadMore() {
@@ -13,7 +24,12 @@ interface RecyclerViewExtensions {
1324
}))
1425
}
1526

16-
fun RecyclerView.applySpanSize(transform: (Int) -> Int) {
27+
/**
28+
* Set GirdLayoutManager.SpanSizeLookup
29+
*
30+
* @param transform Transform position index to item width
31+
*/
32+
fun RecyclerView.applySpanSize(transform: (position: Int) -> Int) {
1733
val layoutManager = this.layoutManager
1834
if (layoutManager is GridLayoutManager) {
1935
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {

0 commit comments

Comments
 (0)