Skip to content

Commit

Permalink
Merge pull request #146 from bitmovin/fix-linting
Browse files Browse the repository at this point in the history
Fix various linting issues
  • Loading branch information
123mpozzi authored Jun 26, 2024
2 parents 5ae42d9 + f79aa1c commit 2432bf6
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 136 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ disabled_rules:
- todo
- trailing_comma
- inclusive_language
- non_optional_string_data_conversion

opt_in_rules:
# performance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@ class ChannelManager {
name: String,
handler: MethodCallHandler,
binaryMessenger: BinaryMessenger,
): MethodChannel {
return MethodChannel(binaryMessenger, name).apply {
): MethodChannel =
MethodChannel(binaryMessenger, name).apply {
this.setMethodCallHandler(handler)
}
}

fun registerEventChannel(
name: String,
handler: StreamHandler,
binaryMessenger: BinaryMessenger,
): EventChannel {
return EventChannel(binaryMessenger, name).apply {
): EventChannel =
EventChannel(binaryMessenger, name).apply {
this.setStreamHandler(handler)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class FlutterPlayer(
config: PlayerConfig?,
analyticsConfig: AnalyticsConfig?,
defaultMetadata: DefaultMetadata?,
) : StreamHandler, EventListener() {
) : EventListener(),
StreamHandler {
private var widevineCallbacksHandler: WidevineCallbacksHandler? = null
private val methodChannel =
ChannelManager.registerMethodChannel(
Expand Down Expand Up @@ -115,9 +116,7 @@ class FlutterPlayer(
private fun onMethodCall(
method: String,
arguments: JMethodArgs,
): Any {
return player.onMethodCall(method, arguments.asPlayerMethodArgs)
}
): Any = player.onMethodCall(method, arguments.asPlayerMethodArgs)

override fun onListen(
arguments: Any?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class FlutterPlayerView(
messenger: BinaryMessenger,
id: Int,
args: Any?,
) : MethodChannel.MethodCallHandler, EventChannel.StreamHandler, PlatformView, EventListener() {
) : EventListener(),
MethodChannel.MethodCallHandler,
EventChannel.StreamHandler,
PlatformView {
private val methodChannel: MethodChannel =
MethodChannel(
messenger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ class FlutterPlayerViewFactory(
context: Context,
viewId: Int,
args: Any?,
): PlatformView {
return FlutterPlayerView(context, messenger, viewId, args)
}
): PlatformView = FlutterPlayerView(context, messenger, viewId, args)
}
22 changes: 9 additions & 13 deletions android/src/main/kotlin/com/bitmovin/player/flutter/Helper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@ class Helper {
return (x - inMin) * outRange / inRange + outMin
}

fun getSystemBrightness(context: Context): Float {
return Settings.System.getInt(
context.contentResolver,
Settings.System.SCREEN_BRIGHTNESS,
0,
).toFloat()
}
fun getSystemBrightness(context: Context): Float =
Settings.System
.getInt(
context.contentResolver,
Settings.System.SCREEN_BRIGHTNESS,
0,
).toFloat()

@RequiresApi(Build.VERSION_CODES.M)
fun canWriteSystemSettings(context: Context): Boolean {
return Settings.System.canWrite(context)
}
fun canWriteSystemSettings(context: Context): Boolean = Settings.System.canWrite(context)

fun requestSystemWritePermission(context: Context) {
val intent =
Expand All @@ -48,8 +46,6 @@ class Helper {
ContextCompat.startActivity(context, intent, null)
}

fun getAudio(context: Context): AudioManager {
return context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
}
fun getAudio(context: Context): AudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package com.bitmovin.player.flutter

data class PlayerPayload(val id: String, val data: Any?)
data class PlayerPayload(
val id: String,
val data: Any?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import java.lang.ref.WeakReference

class PlayerPlugin : FlutterPlugin, ActivityAware {
class PlayerPlugin :
FlutterPlugin,
ActivityAware {
private var flutterPluginBindingReference = WeakReference<FlutterPlugin.FlutterPluginBinding>(null)
private var activity = WeakReference<Activity?>(null)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,42 @@ class WidevineCallbacksHandler(
methodName: String,
arguments: Map<String, Any>,
): ByteArray {
return CallbackToFutureAdapter.getFuture { completer ->
runOnMainThread {
methodChannel.invokeMethod(
methodName,
arguments,
object : MethodChannel.Result {
override fun success(result: Any?) {
if (result !is String) {
return CallbackToFutureAdapter
.getFuture { completer ->
runOnMainThread {
methodChannel.invokeMethod(
methodName,
arguments,
object : MethodChannel.Result {
override fun success(result: Any?) {
if (result !is String) {
completer.setException(
Exception("Invalid result type found for: $methodName"),
)
return
}

completer.set(Base64.decode(result, Base64.NO_WRAP))
}

override fun error(
errorCode: String,
errorMessage: String?,
errorDetails: Any?,
) {
completer.setException(
Exception("Invalid result type found for: $methodName"),
Exception("Error when calling $methodName. Error code: $errorCode, message: $errorMessage"),
)
return
}

completer.set(Base64.decode(result, Base64.NO_WRAP))
}

override fun error(
errorCode: String,
errorMessage: String?,
errorDetails: Any?,
) {
completer.setException(
Exception("Error when calling $methodName. Error code: $errorCode, message: $errorMessage"),
)
}

override fun notImplemented() {
completer.setException(
Exception("Method not implemented: $methodName"),
)
}
},
)
}
}.get()
override fun notImplemented() {
completer.setException(
Exception("Method not implemented: $methodName"),
)
}
},
)
}
}.get()
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package com.bitmovin.player.flutter.drm

data class WidevineConfigMetadata(val hasPrepareMessage: Boolean, val hasPrepareLicense: Boolean)
data class WidevineConfigMetadata(
val hasPrepareMessage: Boolean,
val hasPrepareLicense: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

/** set Result from returned object or set an error if an exception is thrown. */
internal class JsonMethodHandler(private val handler: (String, JMethodArgs) -> Any) :
MethodChannel.MethodCallHandler {
internal class JsonMethodHandler(
private val handler: (String, JMethodArgs) -> Any,
) : MethodChannel.MethodCallHandler {
override fun onMethodCall(
call: MethodCall,
result: MethodChannel.Result,
Expand Down
Loading

0 comments on commit 2432bf6

Please sign in to comment.