Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
Fix wrong import for catching timeout exception
  • Loading branch information
geckour committed Feb 27, 2019
1 parent 6aa114a commit 1f992ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.geckour.lopicmaker.ui.main.edit
import android.content.Context
import android.graphics.Point
import android.graphics.PointF
import android.graphics.drawable.BitmapDrawable
import android.view.MotionEvent
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModel
Expand All @@ -19,10 +18,10 @@ import com.geckour.lopicmaker.util.Algorithm
import com.geckour.lopicmaker.util.MyAlertDialogFragment
import com.geckour.lopicmaker.util.SingleLiveEvent
import com.geckour.lopicmaker.util.fromJson
import com.geckour.lopicmaker.util.solutionCount
import kotlinx.coroutines.launch
import timber.log.Timber
import java.sql.Timestamp
import java.util.concurrent.TimeoutException

class EditorViewModel : ViewModel() {

Expand Down Expand Up @@ -331,15 +330,8 @@ class EditorViewModel : ViewModel() {
internal fun refreshSatisfactionState() {
viewModelScope.launch {
val state = algorithm?.getSolutionCounter()?.let {
val count = try {
it.countSolutions()
} catch (e: TimeoutException) {
it.lowerBound()
} finally {
-1
}
nonNullAlgorithm.getSatisfactionState(count)
} ?: let {
nonNullAlgorithm.getSatisfactionState(it.solutionCount)
} ?: run {
Timber.d("solutionCounter is null")
Algorithm.SatisfactionState.Unsatisfiable
}
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/com/geckour/lopicmaker/util/ExtensionUtil.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package com.geckour.lopicmaker.util

import com.crashlytics.android.Crashlytics
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import org.sat4j.specs.TimeoutException

inline fun <reified T> Gson.fromJson(json: String): T = this.fromJson<T>(json, object : TypeToken<T>() {}.type)

fun String.getTagsList(): List<String> =
this.split(" ")
this.split(" ")

val UniqueSolutionCounter.solutionCount: Long
get() =
try {
countSolutions()
} catch (t: TimeoutException) {
Crashlytics.logException(t)
lowerBound()
} finally {
-1
}

0 comments on commit 1f992ae

Please sign in to comment.