Skip to content

Commit 244eb41

Browse files
committed
feat: Added Cursor.kt and Utils.kt
Signed-off-by: plsankar <[email protected]>
1 parent 5da25bb commit 244eb41

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ toast(stringRes|string, LENGTH_SHORT)
5252

5353
openAppInPlayStore() // will open current app
5454
openAppInPlayStore(appPackageName) // will open the specified package
55+
56+
runSafe {
57+
// do things that may throw error but don't care about the error (error will be printed to the console)ō
58+
}
5559
```
5660
### Fragment KTX
5761

@@ -79,4 +83,11 @@ show() // visibility visible
7983
format("dd-MM-yyy")
8084
format("dd-MM-yyy", locale)
8185
format(simpleDateFormat)
86+
```
87+
88+
### Cursor KTX
89+
```kotlin
90+
val items = dbCursor.toList {
91+
it.getString(0)
92+
}
8293
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2021 CtrlBytes Technologies
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
package com.ctrlbytes.codekit.ktx
27+
28+
import android.database.Cursor
29+
30+
fun <T> Cursor.toList(block: (Cursor) -> T): MutableList<T> {
31+
return mutableListOf<T>().also { list ->
32+
if (moveToFirst()) {
33+
do {
34+
list.add(block(this))
35+
} while (moveToNext())
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2021 CtrlBytes Technologies
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
package com.ctrlbytes.codekit.ktx
27+
28+
fun runSafe(block: () -> Unit) {
29+
try {
30+
block()
31+
} catch (e: Error) {
32+
e.printStackTrace()
33+
}
34+
}

0 commit comments

Comments
 (0)