@@ -16,79 +16,82 @@ import java.io.IOException
1616private const val TAG = " FlutterReadiumPlugin"
1717
1818class 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}
0 commit comments