Skip to content

Commit

Permalink
fix postOnMainThread.jobCondition, Boolean to Unit.Boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyjs committed Jul 18, 2017
1 parent 6a07945 commit 1a2fb4d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions app/src/main/kotlin/com/tonyjs/hibiscus/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class MainActivity : AppCompatActivity(), LifecycleRegistryOwner {

messageViewModel.write(getString(R.string.desc_my_nickname, nickname()), Message.From.HUMAN)

postToMainThread(runCondition = isAlive(lifecycle), delayMillis = 1000L) {
postToMainThread(runCondition = { isAlive(lifecycle) }, delayMillis = 1000L) {
messageViewModel.write(getString(R.string.ok_wait_a_minute), Message.From.BOT)
}

Expand All @@ -201,7 +201,7 @@ class MainActivity : AppCompatActivity(), LifecycleRegistryOwner {
LOG.e(TAG, error)
messageViewModel.write(getString(R.string.error_on_sign_in), Message.From.BOT)

postToMainThread(runCondition = isAlive(lifecycle), delayMillis = 1000L) {
postToMainThread(runCondition = { isAlive(lifecycle) }, delayMillis = 1000L) {
navigationViewModel.moveTo(NavigationTo.SIGN_IN)
}
}).apply { addDisposable(this) }
Expand All @@ -212,7 +212,7 @@ class MainActivity : AppCompatActivity(), LifecycleRegistryOwner {

messageViewModel.write(getString(R.string.welcome_user, user.nickname), Message.From.BOT)

postToMainThread(runCondition = isAlive(lifecycle), delayMillis = 1000L) {
postToMainThread(runCondition = { isAlive(lifecycle) }, delayMillis = 1000L) {
navigationViewModel.moveTo(NavigationTo.GUIDE_TO_CREATE_POST)
}
}
Expand Down Expand Up @@ -244,7 +244,7 @@ class MainActivity : AppCompatActivity(), LifecycleRegistryOwner {
.subscribe({
val delay = 1000L - (System.currentTimeMillis() - startTime)

postToMainThread(runCondition = isAlive(lifecycle), delayMillis = delay) {
postToMainThread(runCondition = { isAlive(lifecycle) }, delayMillis = delay) {
guideToNext(it)
}
}, { error ->
Expand Down Expand Up @@ -284,7 +284,7 @@ class MainActivity : AppCompatActivity(), LifecycleRegistryOwner {

private fun addFragment(fragment: Fragment, tag: String, toBackStack: Boolean = false,
transition: Int = FragmentTransaction.TRANSIT_FRAGMENT_OPEN) {
postToMainThread(runCondition = isAlive(lifecycle)) {
postToMainThread(runCondition = { isAlive(lifecycle) }) {
supportFragmentManager.findFragmentByTag(tag)?.let { return@postToMainThread }

val ft = supportFragmentManager.beginTransaction()
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/kotlin/com/tonyjs/hibiscus/ui/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
import io.reactivex.android.schedulers.AndroidSchedulers
import java.util.concurrent.TimeUnit

inline fun postToMainThread(runCondition: Boolean = true, delayMillis: Long = 0L,
crossinline job: () -> Unit) {
fun postToMainThread(runCondition: () -> Boolean, delayMillis: Long = 0L,
job: () -> Unit) {
val withCondition = {
if (runCondition) {
if (runCondition.invoke()) {
job()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class CreatePostFragment : BaseFragment() {
}

private fun showPhotoList() {
postToMainThread(runCondition = isAlive(lifecycle)) {
postToMainThread(runCondition = { isAlive(lifecycle) }) {
childFragmentManager.findFragmentByTag(PhotoListFragment.TAG)?.let {
(it as PhotoListFragment).dialog.show()
return@postToMainThread
Expand All @@ -190,7 +190,7 @@ class CreatePostFragment : BaseFragment() {
}

private fun hidePhotoList() {
postToMainThread(runCondition = isAlive(lifecycle)) {
postToMainThread(runCondition = { isAlive(lifecycle) }) {
childFragmentManager.findFragmentByTag(PhotoListFragment.TAG)?.let {
(it as PhotoListFragment).dialog.hide()
}
Expand Down

0 comments on commit 1a2fb4d

Please # to comment.