Skip to content

Commit

Permalink
Migrate Java files to Kotlin (#49)
Browse files Browse the repository at this point in the history
This PR migrates the remaining [Java
files](https://github.com/search?q=repo%3ASRGSSR%2Fsrgdataprovider-android++language%3AJava&type=code)
to Kotlin. Each file is migrated in a dedicated commit.

To ensure that this doesn't break usages from either Java or Kotlin
clients, I've created the following simple classes. They do not test the
behavior, only that the API of each class remained the same.
```kotlin
package ch.srg.dataProvider.integrationlayer

import ch.srg.dataProvider.integrationlayer.data.remote.Quality
import ch.srg.dataProvider.integrationlayer.data.remote.Resource
import ch.srg.dataProvider.integrationlayer.data.remote.StreamingMethod
import ch.srg.dataProvider.integrationlayer.request.IlHost
import ch.srg.dataProvider.integrationlayer.utils.IlUrn
import ch.srg.dataProvider.integrationlayer.utils.StreamComparator

class KotlinUsages {
    fun ilHost() {
        IlHost.PROD
        IlHost.TEST
        IlHost.STAGE
        IlHost.MMF
        IlHost.MMF_PUBLIC
        IlHost.PROD_SAM
        IlHost.TEST_SAM
        IlHost.STAGE_SAM

        val ilHost = IlHost("custom-host", "my.il.host.com")
        ilHost.value
        ilHost.name
        ilHost.hostUri
    }

    fun streamComparator() {
        StreamComparator.SCORE_NOT_SUPPORTED

        val resource1 = Resource(url = "https://www.rts.ch/", quality = Quality.HD, streamingMethod = StreamingMethod.HLS)
        val resource2 = Resource(url = "https://www.srgssr.ch/", quality = Quality.SD, streamingMethod = StreamingMethod.DASH)
        val streamComparator = StreamComparator(emptyList(), emptyList(), emptyList(), false)
        streamComparator.compare(resource1, resource2)
        streamComparator.score(resource1)
    }

    fun ilUrn() {
        IlUrn.ASSET_VIDEO
        IlUrn.ASSET_VIDEO_SET
        IlUrn.ASSET_AUDIO
        IlUrn.ASSET_SHOW
        IlUrn.ASSET_GROUP

        IlUrn.isUrn("")
        IlUrn.format("", "", "")
        IlUrn.isAudio("")
        IlUrn.isVideo("")
        IlUrn.getId("")
        IlUrn.getAssetType("")

        val ilUrn1 = IlUrn("")
        val ilUrn2 = IlUrn("", "", "")

        ilUrn1.bu
        ilUrn1.assetType
        ilUrn1.id
        ilUrn1.isAudio
        ilUrn1.isVideo
        ilUrn1.isShow
        ilUrn1.equalsToString("")
    }
}
```

```java
package ch.srg.dataProvider.integrationlayer;

import java.util.Collections;

import ch.srg.dataProvider.integrationlayer.data.remote.Resource;
import ch.srg.dataProvider.integrationlayer.request.IlHost;
import ch.srg.dataProvider.integrationlayer.utils.IlUrn;
import ch.srg.dataProvider.integrationlayer.utils.StreamComparator;

public class JavaUsages {
    void ilHost() {
        var prod = IlHost.PROD;
        var test = IlHost.TEST;
        var stage = IlHost.STAGE;
        var mmf = IlHost.MMF;
        var mmfPublic = IlHost.MMF_PUBLIC;
        var prodSam = IlHost.PROD_SAM;
        var testSam = IlHost.TEST_SAM;
        var stageSam = IlHost.STAGE_SAM;

        var ilHost = new IlHost("custom-host", "my.il.host.com");
        ilHost.getValue();
        ilHost.getName();
        ilHost.getHostUri();
    }

    void streamComparator() {
        var scoreNotSupported = StreamComparator.SCORE_NOT_SUPPORTED;

        var resource1 = new Resource(); // This doesn't compile, but the goal is just to see if calls on `StreamComparator` are fine
        var resource2 = new Resource(); // This doesn't compile, but the goal is just to see if calls on `StreamComparator` are fine
        var streamComparator = new StreamComparator(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), false);
        streamComparator.compare(resource1, resource2);
        streamComparator.score(resource1);
    }

    void ilUrn() {
        var assetVideo = IlUrn.ASSET_VIDEO;
        var assetVideoSet = IlUrn.ASSET_VIDEO_SET;
        var assetAudio = IlUrn.ASSET_AUDIO;
        var assetShow = IlUrn.ASSET_SHOW;
        var assetGroup = IlUrn.ASSET_GROUP;

        IlUrn.isUrn("");
        IlUrn.format("", "", "");
        IlUrn.isAudio("");
        IlUrn.isVideo("");
        IlUrn.getId("");
        IlUrn.getAssetType("");

        var ilUrn1 = new IlUrn("");
        var ilUrn2 = new IlUrn("", "", "");

        ilUrn1.getBu();
        ilUrn1.getAssetType();
        ilUrn1.getId();
        ilUrn1.isAudio();
        ilUrn1.isVideo();
        ilUrn1.isShow();
        ilUrn1.equalsToString("");
    }
}
```

These should work the same way on the `master` branch and in this PR.

---------

Co-authored-by: Joaquim Stähli <[email protected]>
  • Loading branch information
MGaetan89 and StaehliJ authored Sep 3, 2024
1 parent 522bb77 commit 86c404b
Show file tree
Hide file tree
Showing 12 changed files with 793 additions and 337 deletions.
1 change: 0 additions & 1 deletion dataprovider-retrofit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ android {
dependencies {
api(project(":data"))
api(libs.retrofit)
compileOnly(libs.androidx.annotation)
api(platform(libs.retrofit.bom))
implementation(libs.retrofit.converter.kotlinx.serialization)
implementation(libs.okhttp.logging.interceptor)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package ch.srg.dataProvider.integrationlayer.request

import android.net.Uri
import java.io.Serializable

/**
* Copyright (c) SRG SSR. All rights reserved.
* <p>
* License information is available from the LICENSE file.
*
* @property name designed name
* @property value hostname of the integration layer url
*/
data class IlHost(
val name: String,
val value: String,
) : Serializable {
val hostUri: Uri
get() = Uri.parse("https://$value")

override fun toString(): String {
return name
}

companion object {
private const val serialVersionUID = 1L

@JvmField
val PROD = IlHost("PROD", "il.srgssr.ch")

@JvmField
val TEST = IlHost("TEST", "il-test.srgssr.ch")

@JvmField
val STAGE = IlHost("STAGE", "il-stage.srgssr.ch")

@JvmField
val MMF = IlHost("MMF", "play-mmf.herokuapp.com/android_26CE9E49-9600")

@JvmField
val MMF_PUBLIC = IlHost("MMF", "play-mmf.herokuapp.com")

@JvmField
val PROD_SAM = IlHost("PROD_SAM", "il.srgssr.ch/sam")

@JvmField
val TEST_SAM = IlHost("TEST_SAM", "il-test.srgssr.ch/sam")

@JvmField
val STAGE_SAM = IlHost("STAGE_SAM", "il-stage.srgssr.ch/sam")
}
}

This file was deleted.

Loading

0 comments on commit 86c404b

Please sign in to comment.