Skip to content

Commit

Permalink
Fix warnings in Java/Kotlin code (#46)
Browse files Browse the repository at this point in the history
This PR:
- Fixes the warnings in Java/Kotlin code throughout the project.
- Replace some Android/Java APIs in Kotlin files with equivalent Kotlin
APIs.
  • Loading branch information
MGaetan89 authored Aug 30, 2024
1 parent c399f76 commit bf8419c
Show file tree
Hide file tree
Showing 33 changed files with 109 additions and 104 deletions.
4 changes: 1 addition & 3 deletions data/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
<manifest />
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package ch.srg.dataProvider.integrationlayer.data

import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*
import java.util.Date
import java.util.Locale

/**
* DateParser to convert Integration Layer String date to date (ISO_8601)
*
* DateParser isn't Thread Safe, each thread must use it own instance.
* DateParser isn't Thread Safe, each thread must use its own instance.
* Because SimpleDateFormat isn't Thread Safe @link(https://developer.android.com/reference/java/text/SimpleDateFormat)
*
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import kotlinx.serialization.Serializable
data class AspectRatio(val numerator: Int, val denominator: Int) {

override fun toString(): String {
return "$numerator$Separator$denominator"
return "$numerator$SEPARATOR$denominator"
}

companion object {
val Infinity = AspectRatio(1, 0)
val Zero = AspectRatio(0, 1)

private const val Separator = ":"
private const val SEPARATOR = ":"

/**
* Parse Aspect ratio writing with this numerator:denominator format.
* Example : 1:1, 16:9, 9:16
* Examples: 1:1, 16:9, 9:16
*/
fun parse(str: String): AspectRatio {
val numeratorDenominatorString = str.split(Separator)
val numeratorDenominatorString = str.split(SEPARATOR)
require(numeratorDenominatorString.size == 2) { "Expected rational as numerator:denominator but is $str" }
val numerator = numeratorDenominatorString[0].toInt()
val denominator = numeratorDenominatorString[1].toInt()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@file:UseSerializers(DateSerializer::class)

package ch.srg.dataProvider.integrationlayer.data.remote

import ch.srg.dataProvider.integrationlayer.data.serializer.DateSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ data class Chapter(
val postTrailerStart: Date? = null,
/**
* The reference date corresponding to the beginning of the stream, if any. You can use this date to map a time
* position relative to the stream (e.g. a segment mark in or mark out) to a date.
* position relative to the stream (e.g., a segment mark in or mark out) to a date.
*/
@SerialName("dvrReferenceDate")
val resourceReferenceDate: Date? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:UseSerializers(DateSerializer::class)

package ch.srg.dataProvider.integrationlayer.data.remote

import ch.srg.dataProvider.integrationlayer.data.ImageUrl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:UseSerializers(DateSerializer::class)

package ch.srg.dataProvider.integrationlayer.data.remote

import ch.srg.dataProvider.integrationlayer.data.ImageUrl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch.srg.dataProvider.integrationlayer.data.remote

import android.text.TextUtils
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand Down Expand Up @@ -35,7 +34,7 @@ data class MediaComposition(
)

/**
* The chapter which should be initially played.
* The chapter that should be initially played.
*/
fun getMainChapter(): Chapter {
return checkNotNull(findChapter(chapterUrn)) { "The main chapter is missing from mediaComposition" }
Expand Down Expand Up @@ -80,7 +79,7 @@ data class MediaComposition(
return false
}
for (chapter in chapterList) {
if (TextUtils.equals(chapter.urn, urn)) {
if (chapter.urn == urn) {
return true
}
if (chapter.findSegment(urn) != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.srg.dataProvider.integrationlayer.data.remote

import kotlinx.serialization.Serializable

/**
* Copyright (c) SRG SSR. All rights reserved.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.srg.dataProvider.integrationlayer.data.remote

import kotlinx.serialization.Serializable

/**
* Copyright (c) SRG SSR. All rights reserved.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch.srg.dataProvider.integrationlayer.data.remote

import android.net.Uri
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand Down Expand Up @@ -49,19 +48,19 @@ data class Resource @JvmOverloads constructor(
}

fun isLocalFile(): Boolean {
return Uri.parse(url).scheme == LOCAL_FILE_SCHEME_URL
return url.startsWith(LOCAL_FILE_SCHEME_URL)
}

fun hasDrm(): Boolean {
return drmList != null && drmList.isNotEmpty()
return !drmList.isNullOrEmpty()
}

fun hasSubtitles(): Boolean {
return subtitleVariants != null && subtitleVariants.isNotEmpty()
return !subtitleVariants.isNullOrEmpty()
}

fun hasAudioTracks(): Boolean {
return audioVariants != null && audioVariants.isNotEmpty()
return !audioVariants.isNullOrEmpty()
}

@Serializable
Expand All @@ -72,6 +71,6 @@ data class Resource @JvmOverloads constructor(
}

companion object {
const val LOCAL_FILE_SCHEME_URL = "file"
const val LOCAL_FILE_SCHEME_URL = "file:"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch.srg.dataProvider.integrationlayer.data.remote

import android.text.TextUtils
import java.util.Date

/**
Expand Down Expand Up @@ -28,12 +27,12 @@ interface SRGMediaMetadata : SRGIdentifierMetadata, SRGImageMetadata, SRGMetadat
fun getDownloadUri(quality: Quality = Quality.HD): String? {
return when (quality) {
Quality.SD -> podcastSdUrl
Quality.HD, Quality.HQ -> if (TextUtils.isEmpty(podcastHdUrl)) podcastSdUrl else podcastHdUrl
Quality.HD, Quality.HQ -> if (podcastHdUrl.isNullOrBlank()) podcastSdUrl else podcastHdUrl
}
}

/**
* isBlocked if it has a blockReason or blocked by TimeAvailability at given time
* isBlocked if it has a blockReason or blocked by TimeAvailability at a given time
*/
fun isBlocked(at: Date = Date()): Boolean {
return blockReason != null || getTimeAvailability(at) != TimeAvailability.AVAILABLE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package ch.srg.dataProvider.integrationlayer.data.remote

import android.text.TextUtils
import java.util.Locale

/**
* Copyright (c) SRG SSR. All rights reserved.
*
Expand All @@ -16,23 +13,23 @@ class SearchParams {
AND, OR;

override fun toString(): String {
return name.lowercase(Locale.getDefault())
return name.lowercase()
}
}

enum class SortBy {
DEFAULT, DATE;

override fun toString(): String {
return name.lowercase(Locale.getDefault())
return name.lowercase()
}
}

enum class SortDir {
DESC, ASC;

override fun toString(): String {
return name.lowercase(Locale.getDefault())
return name.lowercase()
}
}

Expand Down Expand Up @@ -102,7 +99,7 @@ class SearchParams {

private fun put(result: HashMap<String, String>, key: String, values: List<String?>?) {
if (values != null) {
result[key] = TextUtils.join(",", values)
result[key] = values.joinToString(",")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ch.srg.dataProvider.integrationlayer.data

import ch.srg.dataProvider.integrationlayer.data.remote.AspectRatio
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.junit.Assert.assertEquals
import org.junit.Test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ch.srg.dataProvider.integrationlayer.data

import ch.srg.dataProvider.integrationlayer.data.remote.BlockReason
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.junit.Assert.assertEquals
import org.junit.Test

Expand Down
4 changes: 1 addition & 3 deletions dataprovider-paging/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
<manifest />
Loading

0 comments on commit bf8419c

Please sign in to comment.