Chore/refactor in api folder (#3285)

* feat: add prop to allow controlling of debug log level

* fix: move props parsing to safeGetters

* chore: fix typing

* chore: fix types and lintter

* chore: move file VideoEventEmitter

* fix: make VideoEventEmitter player agnostic

And create a dedicated API data for that

* chore: move generic file in API folder

---------

Co-authored-by: olivier <olivier.bouillet@ifeelsmart.com>
This commit is contained in:
Olivier Bouillet
2023-10-13 17:27:55 +02:00
committed by GitHub
parent ad581ea2dc
commit ab0398d7dc
14 changed files with 186 additions and 191 deletions

View File

@@ -0,0 +1,54 @@
package com.brentvatne.common.API
import androidx.annotation.IntDef
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
internal object ResizeMode {
/**
* Either the width or height is decreased to obtain the desired aspect ratio.
*/
const val RESIZE_MODE_FIT = 0
/**
* The width is fixed and the height is increased or decreased to obtain the desired aspect ratio.
*/
const val RESIZE_MODE_FIXED_WIDTH = 1
/**
* The height is fixed and the width is increased or decreased to obtain the desired aspect ratio.
*/
const val RESIZE_MODE_FIXED_HEIGHT = 2
/**
* The height and the width is increased or decreased to fit the size of the view.
*/
const val RESIZE_MODE_FILL = 3
/**
* Keeps the aspect ratio but takes up the view's size.
*/
const val RESIZE_MODE_CENTER_CROP = 4
@JvmStatic
@Mode
fun toResizeMode(ordinal: Int): Int {
return when (ordinal) {
RESIZE_MODE_FIXED_WIDTH -> RESIZE_MODE_FIXED_WIDTH
RESIZE_MODE_FIXED_HEIGHT -> RESIZE_MODE_FIXED_HEIGHT
RESIZE_MODE_FILL -> RESIZE_MODE_FILL
RESIZE_MODE_CENTER_CROP -> RESIZE_MODE_CENTER_CROP
RESIZE_MODE_FIT -> RESIZE_MODE_FIT
else -> RESIZE_MODE_FIT
}
}
@Retention(RetentionPolicy.SOURCE)
@IntDef(
RESIZE_MODE_FIT,
RESIZE_MODE_FIXED_WIDTH,
RESIZE_MODE_FIXED_HEIGHT,
RESIZE_MODE_FILL,
RESIZE_MODE_CENTER_CROP
)
annotation class Mode
}

View File

@@ -0,0 +1,38 @@
package com.brentvatne.common.API
import com.brentvatne.ReactBridgeUtils
import com.facebook.react.bridge.ReadableMap
/**
* Helper file to parse SubtitleStyle prop and build a dedicated class
*/
class SubtitleStyle private constructor() {
var fontSize = -1
private set
var paddingLeft = 0
private set
var paddingRight = 0
private set
var paddingTop = 0
private set
var paddingBottom = 0
private set
companion object {
private const val PROP_FONT_SIZE_TRACK = "fontSize"
private const val PROP_PADDING_BOTTOM = "paddingBottom"
private const val PROP_PADDING_TOP = "paddingTop"
private const val PROP_PADDING_LEFT = "paddingLeft"
private const val PROP_PADDING_RIGHT = "paddingRight"
@JvmStatic
fun parse(src: ReadableMap?): SubtitleStyle {
val subtitleStyle = SubtitleStyle()
subtitleStyle.fontSize = ReactBridgeUtils.safeGetInt(src, PROP_FONT_SIZE_TRACK, -1)
subtitleStyle.paddingBottom = ReactBridgeUtils.safeGetInt(src, PROP_PADDING_BOTTOM, 0)
subtitleStyle.paddingTop = ReactBridgeUtils.safeGetInt(src, PROP_PADDING_TOP, 0)
subtitleStyle.paddingLeft = ReactBridgeUtils.safeGetInt(src, PROP_PADDING_LEFT, 0)
subtitleStyle.paddingRight = ReactBridgeUtils.safeGetInt(src, PROP_PADDING_RIGHT, 0)
return subtitleStyle
}
}
}

View File

@@ -1,8 +1,10 @@
package com.brentvatne.common.API
class TimedMetadata {
@kotlin.jvm.JvmField
var m_Identifier: String? = null
@kotlin.jvm.JvmField
var m_Value: String? = null
/*
* class to handle timedEvent retrieved from the stream
*/
class TimedMetadata(_identifier: String? = null, _value: String? = null) {
var identifier: String? = _identifier
var value: String? = _value
}

View File

@@ -0,0 +1,14 @@
package com.brentvatne.common.API
/*
* internal representation of audio & text tracks
*/
class Track {
var title: String? = null
var mimeType: String? = null
var language: String? = null
var isSelected = false
// in bps available only on audio tracks
var bitrate = 0
var index = 0
}

View File

@@ -0,0 +1,15 @@
package com.brentvatne.common.API
/*
* internal representation of audio & text tracks
*/
class VideoTrack {
var width = 0
var height = 0
var bitrate = 0
var codecs = ""
var id = -1
var trackId = ""
var isSelected = false
}

View File

@@ -1,13 +0,0 @@
package com.brentvatne.common;
import android.net.Uri;
public class Track
{
public String m_title;
public Uri m_uri;
public String m_mimeType;
public String m_language;
public boolean m_isSelected;
public int m_bitrate;
public int m_index;
}

View File

@@ -1,12 +0,0 @@
package com.brentvatne.common;
public class VideoTrack
{
public int m_width = 0;
public int m_height = 0;
public int m_bitrate = 0;
public String m_codecs = "";
public int m_id = -1;
public String m_trackId = "";
public boolean m_isSelected = false;
}

View File

@@ -4,8 +4,8 @@ import androidx.annotation.StringDef;
import android.view.View;
import com.brentvatne.common.API.TimedMetadata;
import com.brentvatne.common.Track;
import com.brentvatne.common.VideoTrack;
import com.brentvatne.common.API.Track;
import com.brentvatne.common.API.VideoTrack;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableArray;
@@ -55,7 +55,7 @@ public class VideoEventEmitter {
private static final String EVENT_VIDEO_TRACKS = "onVideoTracks";
private static final String EVENT_ON_RECEIVE_AD_EVENT = "onReceiveAdEvent";
public static final String[] Events = {
static public final String[] Events = {
EVENT_LOAD_START,
EVENT_LOAD,
EVENT_ERROR,
@@ -182,11 +182,11 @@ public class VideoEventEmitter {
Track format = audioTracks.get(i);
WritableMap audioTrack = Arguments.createMap();
audioTrack.putInt("index", i);
audioTrack.putString("title", format.m_title != null ? format.m_title : "");
audioTrack.putString("type", format.m_mimeType != null ? format.m_mimeType : "");
audioTrack.putString("language", format.m_language != null ? format.m_language : "");
audioTrack.putInt("bitrate", format.m_bitrate);
audioTrack.putBoolean("selected", format.m_isSelected);
audioTrack.putString("title", format.getTitle());
audioTrack.putString("type", format.getMimeType());
audioTrack.putString("language", format.getLanguage());
audioTrack.putInt("bitrate", format.getBitrate());
audioTrack.putBoolean("selected", format.isSelected());
waAudioTracks.pushMap(audioTrack);
}
}
@@ -199,12 +199,12 @@ public class VideoEventEmitter {
for (int i = 0; i < videoTracks.size(); ++i) {
VideoTrack vTrack = videoTracks.get(i);
WritableMap videoTrack = Arguments.createMap();
videoTrack.putInt("width", vTrack.m_width);
videoTrack.putInt("height",vTrack.m_height);
videoTrack.putInt("bitrate", vTrack.m_bitrate);
videoTrack.putString("codecs", vTrack.m_codecs);
videoTrack.putInt("trackId",vTrack.m_id);
videoTrack.putBoolean("selected", vTrack.m_isSelected);
videoTrack.putInt("width", vTrack.getWidth());
videoTrack.putInt("height",vTrack.getHeight());
videoTrack.putInt("bitrate", vTrack.getBitrate());
videoTrack.putString("codecs", vTrack.getCodecs());
videoTrack.putInt("trackId",vTrack.getId());
videoTrack.putBoolean("selected", vTrack.isSelected());
waVideoTracks.pushMap(videoTrack);
}
}
@@ -218,10 +218,10 @@ public class VideoEventEmitter {
Track format = textTracks.get(i);
WritableMap textTrack = Arguments.createMap();
textTrack.putInt("index", i);
textTrack.putString("title", format.m_title != null ? format.m_title : "");
textTrack.putString("type", format.m_mimeType != null ? format.m_mimeType : "");
textTrack.putString("language", format.m_language != null ? format.m_language : "");
textTrack.putBoolean("selected", format.m_isSelected);
textTrack.putString("title", format.getTitle());
textTrack.putString("type", format.getMimeType());
textTrack.putString("language", format.getLanguage());
textTrack.putBoolean("selected", format.isSelected());
waTextTracks.pushMap(textTrack);
}
}
@@ -388,8 +388,8 @@ public class VideoEventEmitter {
for (int i = 0; i < _metadataArrayList.size(); i++) {
WritableMap map = Arguments.createMap();
map.putString("identifier", _metadataArrayList.get(i).m_Identifier);
map.putString("value", _metadataArrayList.get(i).m_Value);
map.putString("identifier", _metadataArrayList.get(i).getIdentifier());
map.putString("value", _metadataArrayList.get(i).getValue());
metadataArray.pushMap(map);
}