Skip to content

Commit

Permalink
Wait longer on uploading list for animation
Browse files Browse the repository at this point in the history
  • Loading branch information
0ranko0P committed Jul 20, 2020
1 parent f0ba189 commit c54a877
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/src/main/java/me/ranko/autodark/ui/BlockListViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.content.IntentFilter
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.os.SystemClock
import android.text.Editable
import android.text.TextWatcher
import android.view.MenuItem
Expand All @@ -21,7 +22,6 @@ import me.ranko.autodark.BuildConfig
import me.ranko.autodark.Constant
import me.ranko.autodark.Constant.*
import me.ranko.autodark.Receivers.ActivityUpdateReceiver
import me.ranko.autodark.Receivers.ActivityUpdateReceiver.Companion.STATUS_LIST_LOAD_FAILED
import me.ranko.autodark.Receivers.ActivityUpdateReceiver.Companion.STATUS_LIST_LOAD_START
import me.ranko.autodark.Receivers.ActivityUpdateReceiver.Companion.STATUS_LIST_LOAD_SUCCEED
import me.ranko.autodark.Utils.FileUtil
Expand Down Expand Up @@ -276,13 +276,14 @@ class BlockListViewModel(application: Application) : AndroidViewModel(applicatio
val watcher = uploadTimeOutWatcher.getAndSet(null)
if (watcher?.isActive == true) watcher.cancel("Response received: $response")

val cost = Duration.between(timer, Instant.now()).toMillis()
if (cost < 600L) SystemClock.sleep(1000L) // wait longer
Timber.i("onNewResponse: Response time cost: ${cost}ms")

uploadStatus.set(if (response == STATUS_LIST_LOAD_SUCCEED) JOB_STATUS_SUCCEED else JOB_STATUS_FAILED)

if (BuildConfig.DEBUG) {
if (BuildConfig.DEBUG)
mContext.sendBroadcast(Intent(ActivityUpdateReceiver.ACTION_SERVER_PRINT_LIST))
val cost = Duration.between(timer, Instant.now()).toMillis()
Timber.w("${if (response == STATUS_LIST_LOAD_SUCCEED) "Succeed" else "Failed"}: ${cost}ms")
}
}

fun isUploading(): Boolean = uploadStatus.get() == JOB_STATUS_PENDING
Expand Down

0 comments on commit c54a877

Please sign in to comment.