Skip to content

Commit

Permalink
version: 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
yueeng committed Nov 13, 2017
1 parent 14621cd commit b92f2ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ apply plugin: "jp.leafytree.android-scala"

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
buildToolsVersion "26.0.3"

defaultConfig {
applicationId "io.github.yueeng.hacg"
minSdkVersion 14
targetSdkVersion 26
versionCode 21
versionName "1.2.0"
versionCode 22
versionName "1.2.1"
multiDexEnabled true
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/scala/io/github/yueeng/hacg/Common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.util
import java.util.Date
import java.util.concurrent._

import android.app
import android.content.DialogInterface.OnDismissListener
import android.content._
import android.graphics.{Canvas, Paint, RectF}
Expand Down Expand Up @@ -377,15 +378,26 @@ object Common {
object ContextHelper {
val handler = new Handler(Looper.getMainLooper)
val mainThread: Thread = Looper.getMainLooper.getThread

def ui(call: () => Unit): Unit = if (mainThread == Thread.currentThread()) call()
else handler.post(() => call())
}

class AsyncScalaContext[T <: AnyRef](weak: WeakReference[T]) {
def ui(func: T => Unit): Boolean = weak.get match {
case None => false
case Some(ref) =>
if (ContextHelper.mainThread == Thread.currentThread()) func(ref)
else ContextHelper.handler.post(() => func(ref))
true
if (ref match {
case f: Fragment if !f.isAdded => false
case f: app.Fragment if !f.isAdded => false
case _ => true
}) try {
ContextHelper.ui(() => func(ref))
true
} catch {
case _: Throwable => false
}
else false
}
}

Expand Down

0 comments on commit b92f2ce

Please sign in to comment.