@@ -8,14 +8,12 @@ import android.view.ViewGroup
88import androidx.fragment.app.commitNow
99import androidx.lifecycle.lifecycleScope
1010import dk.nota.flutter_readium.R
11- import dk.nota.flutter_readium.StartLifecycleObserver
1211import dk.nota.flutter_readium.models.EpubReaderViewModel
1312import dk.nota.flutter_readium.throttleLatest
1413import kotlinx.coroutines.CoroutineScope
1514import kotlinx.coroutines.MainScope
1615import kotlinx.coroutines.flow.MutableStateFlow
1716import kotlinx.coroutines.launch
18- import kotlinx.serialization.encodeToString
1917import kotlinx.serialization.json.Json
2018import org.readium.r2.navigator.Decoration
2119import org.readium.r2.navigator.epub.EpubNavigatorFragment
@@ -24,8 +22,6 @@ import org.readium.r2.navigator.epub.EpubPreferencesEditor
2422import org.readium.r2.shared.ExperimentalReadiumApi
2523import org.readium.r2.shared.publication.Locator
2624import org.readium.r2.shared.util.AbsoluteUrl
27- import kotlin.coroutines.resume
28- import kotlin.coroutines.suspendCoroutine
2925import kotlin.time.Duration
3026
3127
@@ -152,20 +148,20 @@ class EpubReaderFragment : VisualReaderFragment(), EpubNavigatorFragment.Listene
152148 return
153149 }
154150
151+ if (editor == null ) {
152+ return
153+ }
154+
155155 try {
156- suspendCoroutine {
157- editor?.let {
158- it.apply {
159- fontFamily.set(preferences.fontFamily)
160- fontSize.set(preferences.fontSize)
161- fontWeight.set(preferences.fontWeight)
162- scroll.set(preferences.scroll)
163- backgroundColor.set(preferences.backgroundColor)
164- textColor.set(preferences.textColor)
165- }
166-
167- navigator.submitPreferences(it.preferences)
168- }
156+ editor?.apply {
157+ fontFamily.set(preferences.fontFamily)
158+ fontSize.set(preferences.fontSize)
159+ fontWeight.set(preferences.fontWeight)
160+ scroll.set(preferences.scroll)
161+ backgroundColor.set(preferences.backgroundColor)
162+ textColor.set(preferences.textColor)
163+
164+ navigator.submitPreferences(preferences)
169165 }
170166 } catch (ex: Exception ) {
171167 Log .e(TAG , " Error applying EpubPreferences: $ex " )
@@ -181,13 +177,10 @@ class EpubReaderFragment : VisualReaderFragment(), EpubNavigatorFragment.Listene
181177 return
182178 }
183179
184- suspendCoroutine {
185- if (navigator.goBackward(animated)) {
186- Log .d(TAG , " ::goLeft: Went back." )
187- } else {
188- Log .d(TAG , " ::goLeft: Couldn't go back." )
189- }
190- it.resume(Unit )
180+ if (navigator.goBackward(animated)) {
181+ Log .d(TAG , " ::goLeft: Went back." )
182+ } else {
183+ Log .d(TAG , " ::goLeft: Couldn't go back." )
191184 }
192185 }
193186
@@ -200,14 +193,10 @@ class EpubReaderFragment : VisualReaderFragment(), EpubNavigatorFragment.Listene
200193 return
201194 }
202195
203- suspendCoroutine {
204- if (navigator.goForward(animated)) {
205- Log .d(TAG , " ::goRight: Went forward." )
206- } else {
207- Log .d(TAG , " ::goRight: Couldn't go forward." )
208- }
209-
210- it.resume(Unit )
196+ if (navigator.goForward(animated)) {
197+ Log .d(TAG , " ::goRight: Went forward." )
198+ } else {
199+ Log .d(TAG , " ::goRight: Couldn't go forward." )
211200 }
212201 }
213202
0 commit comments