Skip to content

Add utils class. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you also remove the files from git?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only has the initial commit files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the files that I commented in the previous PR that should be deleted doesn't appear as deleted in this PR. So you still have to delete those from git I think

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

.DS_Store
/build
/captures
Expand Down
10 changes: 0 additions & 10 deletions .idea/codeStyles/Project.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/encodings.xml

This file was deleted.

18 changes: 0 additions & 18 deletions .idea/gradle.xml

This file was deleted.

14 changes: 0 additions & 14 deletions .idea/misc.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

21 changes: 21 additions & 0 deletions app/src/main/java/com/rootstrap/android/utils/AppExecutors.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.rootstrap.android.utils

import java.util.concurrent.Executor

/**
* @author Amaury Ricardo Miranda 2019
*
* Background thread
* ioThread.execute {
* //action
* }
*
* Main thread
* mainThread.execute {
* //action
* }
* */

var ioThread: Executor = IoThreadExecutor()
var mainThread: Executor = MainThreadExecutor()

18 changes: 18 additions & 0 deletions app/src/main/java/com/rootstrap/android/utils/Converter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.rootstrap.android.utils

/**
* @author Amaury Ricardo Miranda 2019
* */

import com.google.gson.Gson
import org.joda.time.DateTime
import org.joda.time.DateTimeZone

fun Long.getDate(): DateTime = DateTime(this, DateTimeZone.UTC)
fun DateTime.getLong(): Long = this.millis
fun Any.toGson(): String = Gson().toJson(this)
inline fun <reified T> String.fromGson() : T = Gson().fromJson(this, T :: class.java)

/**
* Add more convert functions
* */
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.rootstrap.android.utils

/**
* @author Amaury Ricardo Miranda 2019
* */

import java.util.concurrent.Executor
import java.util.concurrent.Executors

/**
* Executor that runs a task on a new background thread.
*/
class IoThreadExecutor : Executor {

private val mDiskIO: Executor

init {
mDiskIO = Executors.newSingleThreadExecutor()
}

override fun execute(command: Runnable) {
mDiskIO.execute(command)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.rootstrap.android.utils

/**
* @author Amaury Ricardo Miranda 2019
* */

import android.os.Handler
import android.os.Looper
import java.util.concurrent.Executor

class MainThreadExecutor : Executor {

private val mainThreadHandler : Handler = Handler(Looper.getMainLooper())

override fun execute(command: Runnable) {
mainThreadHandler.post(command)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.rootstrap.android.utils

/**
* @author Amaury Ricardo Miranda 2019
* */

interface SimpleCallBack<T> {
fun callBack(param: T)
}
Loading