File tree 8 files changed +690
-6
lines changed
app/src/main/java/com/rootstrap/android/utils
8 files changed +690
-6
lines changed Original file line number Diff line number Diff line change 1
1
* .iml
2
2
.gradle
3
3
/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 /*
10
5
.DS_Store
11
6
/build
12
7
/captures
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
+ * */
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments