Skip to content

Commit b1c1742

Browse files
authored
Merge pull request #17 from Notalib/fix/unhandled-jsonDecode-error-caused-a-crash
fix/unhandled jsonDecode error caused a crash
2 parents 081a79b + ee7377c commit b1c1742

17 files changed

+1163
-1138
lines changed

flutter_readium/android/src/main/kotlin/dk/nota/flutter_readium/CoroutineHelpers.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import kotlinx.coroutines.flow.flow
77
import kotlin.time.Duration
88

99
fun <T> Flow<T>.throttleLatest(period: Duration): Flow<T> =
10-
flow {
11-
conflate().collect {
12-
emit(it)
13-
delay(period)
10+
flow {
11+
conflate().collect {
12+
emit(it)
13+
delay(period)
14+
}
1415
}
15-
}
1616

flutter_readium/android/src/main/kotlin/dk/nota/flutter_readium/FlutterReadiumPlugin.kt

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,79 +16,82 @@ import java.io.IOException
1616
private const val TAG = "FlutterReadiumPlugin"
1717

1818
class FlutterReadiumPlugin : FlutterPlugin, ActivityAware, MethodCallHandler {
19-
/// The MethodChannel that will the communication between Flutter and native Android
20-
///
21-
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
22-
/// when the Flutter Engine is detached from the Activity
23-
private lateinit var publicationChannel: MethodChannel
19+
/// The MethodChannel that will the communication between Flutter and native Android
20+
///
21+
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
22+
/// when the Flutter Engine is detached from the Activity
23+
private lateinit var publicationChannel: MethodChannel
2424

25-
private lateinit var publicationMethodCallHandler: PublicationMethodCallHandler
25+
private lateinit var publicationMethodCallHandler: PublicationMethodCallHandler
2626

27-
override fun onAttachedToEngine(flutterPluginBinding: FlutterPluginBinding) {
28-
Log.d(TAG, "onAttachedToEngine")
29-
val messenger = flutterPluginBinding.binaryMessenger
27+
override fun onAttachedToEngine(flutterPluginBinding: FlutterPluginBinding) {
28+
Log.d(TAG, "onAttachedToEngine")
29+
val messenger = flutterPluginBinding.binaryMessenger
3030

31-
// Register reader view factory
32-
flutterPluginBinding.platformViewRegistry.registerViewFactory(
33-
viewTypeChannelName,
34-
ReadiumReaderViewFactory(messenger)
35-
)
31+
// Register reader view factory
32+
flutterPluginBinding.platformViewRegistry.registerViewFactory(
33+
viewTypeChannelName,
34+
ReadiumReaderViewFactory(messenger)
35+
)
3636

37-
// TODO: Remove this, just for debugging.
38-
val files = listAssetFiles(flutterPluginBinding.applicationContext, "flutter_assets/packages/flutter_readium/assets/helpers")
39-
for (file in files) {
40-
Log.i("ListAssetFiles", "Asset: $file")
41-
}
37+
// TODO: Remove this, just for debugging.
38+
val files = listAssetFiles(
39+
flutterPluginBinding.applicationContext,
40+
"flutter_assets/packages/flutter_readium/assets/helpers"
41+
)
42+
for (file in files) {
43+
Log.i("ListAssetFiles", "Asset: $file")
44+
}
4245

43-
// Setup publication channel
44-
publicationMethodCallHandler =
45-
PublicationMethodCallHandler(flutterPluginBinding.applicationContext)
46-
publicationChannel = MethodChannel(messenger, publicationChannelName)
47-
publicationChannel.setMethodCallHandler(publicationMethodCallHandler)
48-
}
46+
// Setup publication channel
47+
publicationMethodCallHandler =
48+
PublicationMethodCallHandler(flutterPluginBinding.applicationContext)
49+
publicationChannel = MethodChannel(messenger, publicationChannelName)
50+
publicationChannel.setMethodCallHandler(publicationMethodCallHandler)
51+
}
4952

50-
override fun onMethodCall(call: MethodCall, result: Result) {
51-
Log.d(TAG, "onMethodCall")
52-
result.notImplemented()
53-
}
53+
override fun onMethodCall(call: MethodCall, result: Result) {
54+
Log.d(TAG, "onMethodCall")
55+
result.notImplemented()
56+
}
5457

55-
override fun onDetachedFromEngine(binding: FlutterPluginBinding) {
56-
Log.d(TAG, "onDetachedFromEngine")
57-
publicationChannel.setMethodCallHandler(null)
58-
}
58+
override fun onDetachedFromEngine(binding: FlutterPluginBinding) {
59+
Log.d(TAG, "onDetachedFromEngine")
60+
publicationChannel.setMethodCallHandler(null)
61+
}
5962

60-
private fun listAssetFiles(c: Context, rootPath: String): List<String> {
61-
Log.i("ListAssetFiles", "Listing assets in $rootPath")
62-
val files: MutableList<String> = ArrayList()
63-
try {
64-
val paths = c.assets.list(rootPath)
65-
if (paths!!.isNotEmpty()) {
66-
// This is a folder
67-
for (filePath in paths) {
68-
val path = "$rootPath/$filePath"
69-
if (File(path).isDirectory()) files.addAll(listAssetFiles(c, path))
70-
else files.add(path)
63+
private fun listAssetFiles(c: Context, rootPath: String): List<String> {
64+
Log.i("ListAssetFiles", "Listing assets in $rootPath")
65+
val files: MutableList<String> = ArrayList()
66+
try {
67+
val paths = c.assets.list(rootPath)
68+
if (paths!!.isNotEmpty()) {
69+
// This is a folder
70+
for (filePath in paths) {
71+
val path = "$rootPath/$filePath"
72+
if (File(path).isDirectory()) files.addAll(listAssetFiles(c, path))
73+
else files.add(path)
74+
}
75+
}
76+
} catch (e: IOException) {
77+
e.printStackTrace()
7178
}
72-
}
73-
} catch (e: IOException) {
74-
e.printStackTrace()
79+
return files
7580
}
76-
return files
77-
}
7881

79-
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
80-
Log.d(TAG, "onAttachedToActivity")
81-
}
82+
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
83+
Log.d(TAG, "onAttachedToActivity")
84+
}
8285

83-
override fun onDetachedFromActivityForConfigChanges() {
84-
Log.d(TAG, "onDetachedFromActivityForConfigChanges")
85-
}
86+
override fun onDetachedFromActivityForConfigChanges() {
87+
Log.d(TAG, "onDetachedFromActivityForConfigChanges")
88+
}
8689

87-
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
88-
Log.d(TAG, "onReattachedToActivityForConfigChanges")
89-
}
90+
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
91+
Log.d(TAG, "onReattachedToActivityForConfigChanges")
92+
}
9093

91-
override fun onDetachedFromActivity() {
92-
Log.d(TAG, "onDetachedFromActivity")
93-
}
94+
override fun onDetachedFromActivity() {
95+
Log.d(TAG, "onDetachedFromActivity")
96+
}
9497
}

flutter_readium/android/src/main/kotlin/dk/nota/flutter_readium/LifecycleDelegates.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class LifecycleDelegates(private val fragment: Fragment) : DefaultLifecycleObser
3232
}
3333
}
3434

35-
private val viewLifecycleValues: MutableList<ViewLifecycleAwareVar<*>> =
36-
mutableListOf()
35+
private val viewLifecycleValues: MutableList<ViewLifecycleAwareVar<*>> = mutableListOf()
3736

3837
override fun onCreate(owner: LifecycleOwner) {
3938
fragment.viewLifecycleOwnerLiveData.observe(fragment) { viewLifecycleOwner ->
@@ -64,5 +63,4 @@ class LifecycleDelegates(private val fragment: Fragment) : DefaultLifecycleObser
6463
/**
6564
* Make a single value automatically set to null every time the [Fragment]'s view is destroyed.
6665
*/
67-
fun <T : Any> Fragment.viewLifecycle() =
68-
LifecycleDelegates(this).viewLifecycleAware<T>()
66+
fun <T : Any> Fragment.viewLifecycle() = LifecycleDelegates(this).viewLifecycleAware<T>()

0 commit comments

Comments
 (0)