Skip to content

Commit 0445df8

Browse files
committed
Add utils class
1 parent 8f68bfc commit 0445df8

File tree

8 files changed

+690
-6
lines changed

8 files changed

+690
-6
lines changed

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
*.iml
22
.gradle
33
/local.properties
4-
/.idea/caches
5-
/.idea/libraries
6-
/.idea/modules.xml
7-
/.idea/workspace.xml
8-
/.idea/navEditor.xml
9-
/.idea/assetWizardSettings.xml
4+
/.idea/*
105
.DS_Store
116
/build
127
/captures
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.rootstrap.base.utils
2+
3+
import java.util.concurrent.Executor
4+
5+
/**
6+
* @author Amaury Ricardo Miranda 2019
7+
*
8+
* Background thread
9+
* ioThread.execute {
10+
* //action
11+
* }
12+
*
13+
* Main thread
14+
* mainThread.execute {
15+
* //action
16+
* }
17+
* */
18+
19+
var ioThread: Executor = IoThreadExecutor()
20+
var mainThread: Executor = MainThreadExecutor()
21+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.rootstrap.base.utils
2+
3+
/**
4+
* @author Amaury Ricardo Miranda 2019
5+
* */
6+
7+
import com.google.gson.Gson
8+
import org.joda.time.DateTime
9+
import org.joda.time.DateTimeZone
10+
11+
fun Long.getDate(): DateTime = DateTime(this, DateTimeZone.UTC)
12+
fun DateTime.getLong(): Long = this.millis
13+
fun Any.toGson(): String = Gson().toJson(this)
14+
inline fun <reified T> String.fromGson() : T = Gson().fromJson(this,T :: class.java)
15+
16+
/**
17+
* Add more convert functions
18+
* */
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.rootstrap.base.utils
2+
3+
/**
4+
* @author Amaury Ricardo Miranda 2019
5+
* */
6+
7+
import java.util.concurrent.Executor
8+
import java.util.concurrent.Executors
9+
10+
/**
11+
* Executor that runs a task on a new background thread.
12+
*/
13+
class IoThreadExecutor : Executor {
14+
15+
private val mDiskIO: Executor
16+
17+
init {
18+
mDiskIO = Executors.newSingleThreadExecutor()
19+
}
20+
21+
override fun execute(command: Runnable) {
22+
mDiskIO.execute(command)
23+
}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.rootstrap.base.utils
2+
3+
/**
4+
* @author Amaury Ricardo Miranda 2019
5+
* */
6+
7+
import android.os.Handler
8+
import android.os.Looper
9+
import java.util.concurrent.Executor
10+
11+
class MainThreadExecutor : Executor {
12+
13+
private val mainThreadHandler : Handler = Handler(Looper.getMainLooper())
14+
15+
override fun execute(command: Runnable) {
16+
mainThreadHandler.post(command)
17+
}
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.rootstrap.base.utils
2+
3+
/**
4+
* @author Amaury Ricardo Miranda 2019
5+
* */
6+
7+
interface SimpleCallBack<T> {
8+
fun callBack(param: T)
9+
}

0 commit comments

Comments
 (0)