Skip to content

Commit

Permalink
Import letterbox ildatasource (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ authored May 23, 2023
1 parent 49c6102 commit d05134b
Show file tree
Hide file tree
Showing 122 changed files with 7,125 additions and 148 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Release

on:
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: 'gradle'
# the publishing section of your build.gradle
- name: Publish to GitHub Packages
uses: gradle/[email protected]
with:
arguments: publish
env:
USERNAME: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USER_NAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ lint/tmp/
.idea/deploymentTargetDropDown.xml
.idea/kotlinc.xml
.idea/misc.xml
.idea/androidTestResultsUserPreferences.xml
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# srgdataprovider-android
A library to retrieve SRG SSR unified metadata
[![SRG Data Provider logo](https://github.com/SRGSSR/srgdataprovider-apple/blob/master/docs/README-images/logo.png)](https://github.com/SRGSSR/srgdataprovider-android)

## About

The SRG Data Provider library provides a simple way to retrieve metadata for all SRG SSRG business units in a common format.

The library provides:

* Requests with Retrofit to get the usual metadata associated with SRG SSR productions.
* Gson serialization and deserialization.
* A flat object model to easily access the data relevant to front-end users.

## Warning

The library is still in progress!ub.com/SRGSSR/srgnetwork-apple).
18 changes: 0 additions & 18 deletions build.gradle

This file was deleted.

11 changes: 11 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

plugins {
id("com.android.application") version "8.0.1" apply false
id("com.android.library") version "8.0.1" apply false
id("org.jetbrains.kotlin.android") version "1.6.21" apply false
}

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
11 changes: 11 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2022. SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
}
12 changes: 12 additions & 0 deletions buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
object Config {
const val compileSdk = 33
const val targetSdk = 33
const val minSdk = 21

const val major = 0
const val minor = 0
const val patch = 1
const val versionName = "$major.$minor.$patch"

const val maven_group = "ch.srg.data.provider"
}
8 changes: 8 additions & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Versions {
const val coreKtx = "1.8.0"
const val lifecycle_version = "2.5.1"
const val dagger = "2.44.2"
const val retrofit_version = "2.9.0"
const val okHttp_version = "4.9.1"
const val gsonVersion = "2.10.1"
}
File renamed without changes.
69 changes: 69 additions & 0 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
`maven-publish`
}

android {
namespace = "ch.srg.dataProvider.integrationlayer.data"
compileSdk = Config.compileSdk

defaultConfig {
minSdk = Config.minSdk
targetSdk = Config.targetSdk
group = Config.maven_group
version = Config.versionName
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
implementation("androidx.core:core-ktx:${Versions.coreKtx}")
implementation("com.google.code.gson:gson:${Versions.gsonVersion}")

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}

publishing {
publications {
register<MavenPublication>("gpr") {
afterEvaluate {
from(components["release"])
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/SRGSSR/srgdataprovider-android")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
maven {
url = uri("https://maven.ecetest.rts.ch/content/repositories/srg-letterbox-releases/")
credentials {
username = project.findProperty("sonatypeUsername") as String? ?: System.getenv("SONATYPE_USERNAME")
password = project.findProperty("sonatypePassword") as String? ?: System.getenv("SONATYPE_PASSWORD")
}
}
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package ch.srg.dataProvider.integrationlayer.data

import ch.srg.dataProvider.integrationlayer.gson.BlockReasonJSonDeserializer
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.JsonObject
import org.junit.Assert
import org.junit.Test

/**
* Copyright (c) SRG SSR. All rights reserved.
* <p>
* License information is available from the LICENSE file.
*/
class BlockReasonGsonTest {

private data class Dummy(val title: String, val blockReason: BlockReason?)

private val gson: Gson = GsonBuilder()
.registerTypeAdapter(BlockReason::class.java, BlockReasonJSonDeserializer())
.create()

@Test
fun testNoBlockReason() {
val expected = Dummy("NoBlockReason", null)
val jsonObj = JsonObject().apply {
addProperty("title", "NoBlockReason")
}
val result: Dummy = gson.fromJson(jsonObj, Dummy::class.java)
Assert.assertEquals(expected, result)
}

@Test
fun testKnownBlockReason() {
val expected = Dummy("KnownBlockReason", BlockReason.GEOBLOCK)
val jsonObj = JsonObject().apply {
addProperty("title", "KnownBlockReason")
addProperty("blockReason", "GEOBLOCK")
}
val result: Dummy = gson.fromJson(jsonObj, Dummy::class.java)
Assert.assertEquals(expected, result)
}

@Test
fun testUnknownBlockReason() {
val expected = Dummy("NoBlockReason", BlockReason.UNKNOWN)
val jsonObj = JsonObject().apply {
addProperty("title", "NoBlockReason")
addProperty("blockReason", "NEWBLOCKREASON")
}
val result: Dummy = gson.fromJson(jsonObj, Dummy::class.java)
Assert.assertEquals(expected, result)
}

@Test
fun testKnownSerialization() {
val expected = JsonObject().apply {
addProperty("title", "SerializeGeoBlock")
addProperty("blockReason", "GEOBLOCK")
}
val result = gson.toJsonTree(Dummy("SerializeGeoBlock", BlockReason.GEOBLOCK))
Assert.assertEquals(expected, result)
}

@Test
fun testNoBlockReasonSerialization() {
val expected = JsonObject().apply {
addProperty("title", "SerializeNoBlockReason")
}
val result = gson.toJsonTree(Dummy("SerializeNoBlockReason", null))
Assert.assertEquals(expected, result)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ch.srg.dataProvider.integrationlayer.data;

import org.junit.Assert;
import org.junit.Test;

import java.text.ParseException;
import java.util.Date;


/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class DateParserTest {
@Test
public void test8601() throws ParseException {
ISO8601DateParser parser = new ISO8601DateParser();
Assert.assertEquals(new Date(1496126175000L), parser.parseDate("2017-05-30T08:36:15.079+02:00"));
Assert.assertEquals(new Date(1496126175000L), parser.parseDate("2017-05-30T08:36:15+02:00"));
Assert.assertEquals(new Date(1496126175000L), parser.parseDate("2017-05-30T06:36:15Z"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package ch.srg.dataProvider.integrationlayer.data;

import android.util.Rational;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import ch.srg.dataProvider.integrationlayer.data.gson.DateJsonSerializer;
import ch.srg.dataProvider.integrationlayer.data.gson.RationalSerializer;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class GsonSerializerTest {

Gson gson;

@Before
public void initGson() {
gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new DateJsonSerializer())
.registerTypeAdapter(Rational.class, new RationalSerializer())
.create();
}

@Test
public void testDate() throws ParseException {
String ilJsonDate = "\"2021-12-07T20:14:59+01:00\"";
Calendar cal = new GregorianCalendar(2021, 11, 7, 20, 14, 59);
Date date = cal.getTime();

String jsonResult = gson.toJson(date);
Assert.assertEquals(ilJsonDate, jsonResult);

Date result = gson.fromJson(ilJsonDate, Date.class);
Assert.assertEquals(date, result);
}

@Test
public void testRational() throws ParseException {
Rational rational = new Rational(16, 9);
String ilJson = "\"16:9\"";

String jsonResult = gson.toJson(rational);
Assert.assertEquals(ilJson, jsonResult);

Rational result = gson.fromJson(ilJson, Rational.class);
Assert.assertEquals(rational, result);
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ch.srg.dataProvider.integrationlayer.data

import java.util.*

/**
* Copyright (c) SRG SSR. All rights reserved.
* <p>
* License information is available from the LICENSE file.
*/
data class BroadCastInformation @JvmOverloads constructor(
val hintText: String? = null,
val url: String? = null,
val startDate: Date? = null,
val endDate: Date? = null
)
Loading

0 comments on commit d05134b

Please sign in to comment.