Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply ktlint formatting #279

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BitmovinCastManagerModule(
uiManager?.addUIBlock {
BitmovinCastManager.initialize(
castOptions?.applicationId,
castOptions?.messageNamespace
castOptions?.messageNamespace,
)
promise.resolve(null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class DrmModule(private val context: ReactApplicationContext) : ReactContextBase
nativeId,
"onPrepareMessage",
preparedMessages,
preparedMessagesCondition
preparedMessagesCondition,
)
widevineConfig.prepareMessageCallback = PrepareMessageCallback {
prepareMessage(it)
Expand All @@ -151,7 +151,7 @@ class DrmModule(private val context: ReactApplicationContext) : ReactContextBase
nativeId,
"onPrepareLicense",
preparedLicenses,
preparedLicensesCondition
preparedLicensesCondition,
)
widevineConfig.prepareLicenseCallback = PrepareLicenseCallback {
prepareLicense(it)
Expand All @@ -170,11 +170,11 @@ class DrmModule(private val context: ReactApplicationContext) : ReactContextBase
nativeId: NativeId,
method: String,
registry: Registry<String>,
registryCondition: Condition
registryCondition: Condition,
): PrepareCallback = {
val args = Arguments.createArray()
args.pushString(Base64.encodeToString(it, Base64.NO_WRAP))
context.catalystInstance.callFunction("DRM-${nativeId}", method, args as NativeArray)
context.catalystInstance.callFunction("DRM-$nativeId", method, args as NativeArray)
lock.withLock {
registryCondition.await()
val result = registry[nativeId]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EventRelay<E : EventEmitter<T>, T : Event>(
/**
* Is called for every relayed event together with its associated name.
*/
private val eventOutput: (String, Event) -> Unit
private val eventOutput: (String, Event) -> Unit,
) {
private val eventListeners = forwardingEventClassesAndNameMapping.map {
Subscription(it.key) { event -> eventOutput(it.value, event) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.bitmovin.player.reactnative
import com.bitmovin.player.api.offline.options.OfflineOptionEntryState
import com.bitmovin.player.reactnative.converter.JsonConverter
import com.bitmovin.player.reactnative.extensions.toList
import com.bitmovin.player.reactnative.offline.OfflineDownloadRequest
import com.bitmovin.player.reactnative.offline.OfflineContentManagerBridge
import com.bitmovin.player.reactnative.offline.OfflineDownloadRequest
import com.facebook.react.bridge.*
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.UIManagerModule
Expand Down Expand Up @@ -69,7 +69,13 @@ class OfflineModule(private val context: ReactApplicationContext) : ReactContext
return@addUIBlock
}

offlineContentManagerBridges[nativeId] = OfflineContentManagerBridge(nativeId, context, identifier, sourceConfig, context.cacheDir.path)
offlineContentManagerBridges[nativeId] = OfflineContentManagerBridge(
nativeId,
context,
identifier,
sourceConfig,
context.cacheDir.path,
)
}
promise.resolve(null)
}
Expand Down Expand Up @@ -117,7 +123,8 @@ class OfflineModule(private val context: ReactApplicationContext) : ReactContext
return@safeOfflineContentManager
}
OfflineOptionEntryState.Downloading,
OfflineOptionEntryState.Failed -> {
OfflineOptionEntryState.Failed,
-> {
Comment on lines +126 to +127
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks odd 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I guess this is because of trailing commas rule: https://pinterest.github.io/ktlint/0.49.1/rules/configuration-ktlint/#trailing-comma-on-call-site

In the newest version of ktlint you either have the option to always have trailing commas or never. I decided to go with always, since it makes sense 99% of the time.

I'm not sure we can improve on that.

promise.reject(IllegalStateException("Download already in progress"))
return@safeOfflineContentManager
}
Expand All @@ -127,7 +134,7 @@ class OfflineModule(private val context: ReactApplicationContext) : ReactContext
}
else -> {}
}
val minimumBitRate = if(request.hasKey("minimumBitrate")) request.getInt("minimumBitrate") else null
val minimumBitRate = if (request.hasKey("minimumBitrate")) request.getInt("minimumBitrate") else null
if (minimumBitRate != null && minimumBitRate < 0) {
promise.reject(IllegalArgumentException("Invalid download request"))
return@safeOfflineContentManager
Expand All @@ -136,7 +143,9 @@ class OfflineModule(private val context: ReactApplicationContext) : ReactContext
val audioOptionIds = request.getArray("audioOptionIds")?.toList<String>()?.filterNotNull()
val textOptionIds = request.getArray("textOptionIds")?.toList<String>()?.filterNotNull()

getOfflineContentManagerBridge(nativeId)?.process(OfflineDownloadRequest(minimumBitRate, audioOptionIds, textOptionIds))
getOfflineContentManagerBridge(nativeId)?.process(
OfflineDownloadRequest(minimumBitRate, audioOptionIds, textOptionIds),
)
promise.resolve(null)
} catch (e: Exception) {
promise.reject(e)
Expand Down Expand Up @@ -260,20 +269,24 @@ class OfflineModule(private val context: ReactApplicationContext) : ReactContext
}
}

private fun safeOfflineContentManager(nativeId: NativeId, promise: Promise, runBlock: OfflineContentManagerBridge.() -> Unit) {
private fun safeOfflineContentManager(
nativeId: NativeId,
promise: Promise,
runBlock: OfflineContentManagerBridge.() -> Unit,
) {
getOfflineContentManagerBridge(nativeId)?.let(runBlock)
?: promise.reject(IllegalArgumentException("Could not find the offline module instance"))
?: promise.reject(IllegalArgumentException("Could not find the offline module instance"))
}

/**
* Helper function that returns the initialized `DrmModule` instance.
*/
private fun drmModule(): DrmModule? =
context.getNativeModule(DrmModule::class.java)
context.getNativeModule(DrmModule::class.java)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Would fit into one line I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I missed that.
bc9fa39


/**
* Helper function that returns the initialized `UIManager` instance.
*/
private fun uiManager(): UIManagerModule? =
context.getNativeModule(UIManagerModule::class.java)
context.getNativeModule(UIManagerModule::class.java)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Would fit into one line I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I missed that.
bc9fa39

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class PlayerModule(private val context: ReactApplicationContext) : ReactContextB
}
val playerConfig = JsonConverter.toPlayerConfig(playerConfigJson)
val analyticsConfig = JsonConverter.toAnalyticsConfig(analyticsConfigJson)
val defaultMetadata = JsonConverter.toAnalyticsDefaultMetadata(analyticsConfigJson?.getMap("defaultMetadata"))
val defaultMetadata = JsonConverter.toAnalyticsDefaultMetadata(
analyticsConfigJson?.getMap("defaultMetadata"),
)

players[nativeId] = if (analyticsConfig == null) {
Player.create(context, playerConfig)
Expand Down Expand Up @@ -481,7 +483,9 @@ class PlayerModule(private val context: ReactApplicationContext) : ReactContextB
@ReactMethod
fun setMaxSelectableBitrate(nativeId: NativeId, maxSelectableBitrate: Int) {
uiManager()?.addUIBlock {
players[nativeId]?.setMaxSelectableVideoBitrate(maxSelectableBitrate.takeUnless { it == -1 } ?: Integer.MAX_VALUE)
players[nativeId]?.setMaxSelectableVideoBitrate(
maxSelectableBitrate.takeUnless { it == -1 } ?: Integer.MAX_VALUE,
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ private val EVENT_CLASS_TO_REACT_NATIVE_NAME_MAPPING_UI = mapOf<KClass<out Event
* exposes player events as bubbling events.
*/
@SuppressLint("ViewConstructor")
class RNPlayerView(val context: ReactApplicationContext) : LinearLayout(context),
LifecycleEventListener, View.OnLayoutChangeListener, RNPictureInPictureDelegate {
class RNPlayerView(val context: ReactApplicationContext) :
LinearLayout(context),
LifecycleEventListener,
View.OnLayoutChangeListener,
RNPictureInPictureDelegate {

init {
// React Native has a bug that dynamically added views sometimes aren't laid out again properly.
Expand All @@ -109,6 +112,7 @@ class RNPlayerView(val context: ReactApplicationContext) : LinearLayout(context)
* to the `eventOutput` callback.
*/
private val playerEventRelay = EventRelay<Player, Event>(EVENT_CLASS_TO_REACT_NATIVE_NAME_MAPPING, ::emitEvent)

/**
* Relays the provided set of events, emitted by the player view, together with the associated name
* to the `eventOutput` callback.
Expand Down Expand Up @@ -273,7 +277,7 @@ class RNPlayerView(val context: ReactApplicationContext) : LinearLayout(context)
post {
measure(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY),
)
layout(left, top, right, bottom)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple
ATTACH_PLAYER("attachPlayer"),
ATTACH_FULLSCREEN_BRIDGE("attachFullscreenBridge"),
SET_CUSTOM_MESSAGE_HANDLER_BRIDGE_ID("setCustomMessageHandlerBridgeId"),
SET_FULLSCREEN("setFullscreen");
SET_FULLSCREEN("setFullscreen"),
}

/**
Expand Down Expand Up @@ -132,7 +132,7 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple
override fun getExportedCustomBubblingEventTypeConstants(): MutableMap<String, Any> =
bubblingEventsMapping.entries.associate {
it.key to mapOf(
"phasedRegistrationNames" to mapOf("bubbled" to it.value)
"phasedRegistrationNames" to mapOf("bubbled" to it.value),
)
}.toMutableMap()

Expand All @@ -154,7 +154,7 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple
*/
override fun receiveCommand(view: RNPlayerView, commandId: String?, args: ReadableArray?) {
val command = commandId?.toInt()?.toCommand() ?: throw IllegalArgumentException(
"The received command is not supported by the Bitmovin Player View"
"The received command is not supported by the Bitmovin Player View",
)
when (command) {
Commands.ATTACH_PLAYER -> attachPlayer(view, args?.getString(1), args?.getMap(2))
Expand All @@ -177,7 +177,7 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple
private fun attachFullscreenBridge(view: RNPlayerView, fullscreenBridgeId: NativeId) {
Handler(Looper.getMainLooper()).post {
view.playerView?.setFullscreenHandler(
context.getModule<FullscreenHandlerModule>()?.getInstance(fullscreenBridgeId)
context.getModule<FullscreenHandlerModule>()?.getInstance(fullscreenBridgeId),
)
}
}
Expand Down Expand Up @@ -205,7 +205,7 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple
view.playerView?.setCustomMessageHandler(
context.getModule<CustomMessageHandlerModule>()
?.getInstance(customMessageHandlerBridgeId)
?.customMessageHandler
?.customMessageHandler,
)
}

Expand Down Expand Up @@ -236,7 +236,7 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple
val playerView = PlayerView(currentActivity, player)
playerView.layoutParams = LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT
LayoutParams.MATCH_PARENT,
)
view.addPlayerView(playerView)
attachCustomMessageHandlerBridge(view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class RNPlayerViewPackage : ReactPackage {
* native component instances with `<NativePlayerView {...} />` on the js
* side.
*/
override fun createViewManagers(reactContext: ReactApplicationContext): MutableList<ViewManager<out View, out ReactShadowNode<*>>> {
override fun createViewManagers(
reactContext: ReactApplicationContext,
): MutableList<ViewManager<out View, out ReactShadowNode<*>>> {
return mutableListOf(RNPlayerViewManager(reactContext))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class SourceModule(private val context: ReactApplicationContext) : ReactContextB
drmNativeId: NativeId?,
config: ReadableMap?,
sourceRemoteControlConfig: ReadableMap?,
analyticsSourceMetadata: ReadableMap?
analyticsSourceMetadata: ReadableMap?,
) {
uiManager()?.addUIBlock {
val sourceMetadata = JsonConverter.toAnalyticsSourceMetadata(analyticsSourceMetadata) ?: SourceMetadata()
initializeSource(nativeId, drmNativeId, config) { sourceConfig ->
Source.create(sourceConfig, sourceMetadata)
Source.create(sourceConfig, sourceMetadata)
}
}
}
Expand All @@ -78,7 +78,7 @@ class SourceModule(private val context: ReactApplicationContext) : ReactContextB
nativeId: NativeId,
drmNativeId: NativeId?,
config: ReadableMap?,
sourceRemoteControlConfig: ReadableMap?
sourceRemoteControlConfig: ReadableMap?,
) {
uiManager()?.addUIBlock {
initializeSource(nativeId, drmNativeId, config) { sourceConfig ->
Expand All @@ -91,7 +91,7 @@ class SourceModule(private val context: ReactApplicationContext) : ReactContextB
nativeId: NativeId,
drmNativeId: NativeId?,
config: ReadableMap?,
action: (SourceConfig) -> Source
action: (SourceConfig) -> Source,
) {
val drmConfig = drmNativeId?.let { drmModule()?.getConfig(it) }
if (!sources.containsKey(nativeId)) {
Expand Down Expand Up @@ -217,12 +217,10 @@ class SourceModule(private val context: ReactApplicationContext) : ReactContextB
/**
* Helper function that returns the initialized `UIManager` instance.
*/
private fun uiManager(): UIManagerModule? =
context.getNativeModule(UIManagerModule::class.java)
private fun uiManager(): UIManagerModule? = context.getNativeModule(UIManagerModule::class.java)

/**
* Helper function that returns the initialized `DrmModule` instance.
*/
private fun drmModule(): DrmModule? =
context.getNativeModule(DrmModule::class.java)
private fun drmModule(): DrmModule? = context.getNativeModule(DrmModule::class.java)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.bitmovin.player.reactnative
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import java.util.*
import java.util.UUID

private const val MODULE_NAME = "UuidModule"

Expand Down
Loading