Skip to content

Commit

Permalink
Merge pull request #71 from shockbytes/update-widget-more-often
Browse files Browse the repository at this point in the history
Update widget more often
  • Loading branch information
shockbytes authored Feb 2, 2020
2 parents 9bc599a + 1df4da8 commit 8a2f604
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package at.shockbytes.dante.ui.activity

import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import android.content.Context
import android.content.Intent
import android.net.Uri
Expand Down Expand Up @@ -37,6 +36,7 @@ import at.shockbytes.dante.flagging.FeatureFlag
import at.shockbytes.dante.navigation.Destination
import at.shockbytes.dante.ui.fragment.AnnouncementFragment
import at.shockbytes.dante.util.toggleVisibility
import at.shockbytes.dante.util.viewModelOf
import at.shockbytes.util.AppUtils
import com.leinardi.android.speeddial.SpeedDialActionItem
import io.reactivex.android.schedulers.AndroidSchedulers
Expand Down Expand Up @@ -67,7 +67,7 @@ class MainActivity : BaseActivity(), ViewPager.OnPageChangeListener {
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)

viewModel = ViewModelProviders.of(this, vmFactory)[MainViewModel::class.java]
viewModel = viewModelOf(vmFactory)
tabId = savedInstanceState?.getInt("tabId") ?: R.id.menu_navigation_current

handleIntentExtras()
Expand Down Expand Up @@ -116,8 +116,8 @@ class MainActivity : BaseActivity(), ViewPager.OnPageChangeListener {
setupFabMenu()
}

override fun onDestroy() {
super.onDestroy()
override fun onStop() {
super.onStop()
DanteAppWidgetManager.refresh(this)
}

Expand Down Expand Up @@ -388,10 +388,8 @@ class MainActivity : BaseActivity(), ViewPager.OnPageChangeListener {

danteSettings
.observeDarkModeEnabled()
.subscribe { isDarkModeEnabled ->
enableDarkMode(isDarkModeEnabled)
}
.addTo(compositeDisposable)
.subscribe(::enableDarkMode)
.addTo(compositeDisposable)
}

private fun enableDarkMode(isEnabled: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package at.shockbytes.dante.ui.fragment

import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.app.DatePickerDialog
import android.content.BroadcastReceiver
import androidx.lifecycle.ViewModelProvider
Expand All @@ -14,10 +13,10 @@ import android.os.Bundle
import androidx.palette.graphics.Palette
import android.view.HapticFeedbackConstants
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.DecelerateInterpolator
import android.widget.TextView
import androidx.core.app.SharedElementCallback
import androidx.lifecycle.Observer
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import at.shockbytes.dante.R
import at.shockbytes.dante.core.book.BookEntity
Expand Down Expand Up @@ -155,7 +154,7 @@ class BookDetailFragment : BaseFragment(),
val currentLines = txt_detail_description.maxLines

val lines = if (currentLines == defaultLines) 100 else defaultLines
val animationDuration = if (currentLines == defaultLines) 500L else 100L
val animationDuration = if (currentLines == defaultLines) 250L else 100L

ObjectAnimator.ofInt(
txt_detail_description,
Expand All @@ -173,7 +172,7 @@ class BookDetailFragment : BaseFragment(),
}

override fun bindViewModel() {
viewModel.getViewState().observe(this, androidx.lifecycle.Observer { viewState ->
viewModel.getViewState().observe(this, Observer { viewState ->
viewState?.let {
initializeBookInformation(viewState.book, viewState.showSummary)
initializeTimeInformation(viewState.book)
Expand Down Expand Up @@ -456,7 +455,7 @@ class BookDetailFragment : BaseFragment(),

btn_detail_pages.text = if (state == BookState.READING)
// Initially set currentPage to 0 for progress animation
getString(R.string.detail_pages, 0, pageCount)
getString(R.string.detail_pages, currentPage, pageCount)
else
pageCount.toString()
} else {
Expand All @@ -471,23 +470,12 @@ class BookDetailFragment : BaseFragment(),
private fun setupPageProgress(currentPage: Int, pageCount: Int) {

sb_detail_pages.apply {

value = 0 // Initially set to 0 for animation
value = currentPage
maxValue = pageCount
setCallback(this@BookDetailFragment)
setOnValueChangedListener { page ->
btn_detail_pages.text = getString(R.string.detail_pages, page, pageCount)
}

ValueAnimator.ofInt(0, currentPage).apply {
startDelay = 750L
addUpdateListener { animator ->
value = animator.animatedValue as Int
}
duration = 500
interpolator = AccelerateDecelerateInterpolator()
start()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/debug/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<resources>

<string name="app_name" translatable="false">Dante Debug</string>
<string name="app_version" translatable="false">3.8 (Debug Build)</string>
<string name="app_version" translatable="false">3.8.2 (Debug Build)</string>

</resources>

0 comments on commit 8a2f604

Please sign in to comment.