Skip to content

Commit 1f15033

Browse files
committed
Added ability to add custom info models
1 parent bb2ca7e commit 1f15033

File tree

8 files changed

+95
-5
lines changed

8 files changed

+95
-5
lines changed

app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ dependencies {
3333
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
3434
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
3535

36+
//Gson
37+
implementation 'com.google.code.gson:gson:2.8.6'
3638
implementation(project(':library'))
39+
3740
implementation 'androidx.recyclerview:recyclerview:1.1.0'
3841
implementation 'com.squareup.picasso:picasso:2.71828'
3942
}

app/src/main/java/com/gapps/videonoapi/MainActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.gapps.library.api.VideoService
1111
import com.gapps.library.api.models.video.VideoPreviewModel
1212
import com.gapps.library.ui.bottom_menu.BottomVideoController
1313
import com.gapps.videonoapi.adapters.VideoAdapter
14+
import com.gapps.videonoapi.custom.abraira.UltimediaVideoInfoModel
1415
import com.gapps.videonoapi.utils.ScrollListener
1516
import com.gapps.videonoapi.utils.alphaSmooth
1617
import com.gapps.videonoapi.utils.convertDpToPx
@@ -36,7 +37,8 @@ class MainActivity : AppCompatActivity() {
3637
"https://ustream.tv/channel/6540154",
3738
"https://www.ted.com/talks/jill_bolte_taylor_my_stroke_of_insight",
3839
"https://coub.com/view/um0um0",
39-
"https://ustream.tv/recorded/101541339"
40+
"https://ustream.tv/recorded/101541339",
41+
"https://www.ultimedia.com/default/index/videogeneric/id/pzkk35/"
4042
)
4143

4244
override fun onCreate(savedInstanceState: Bundle?) {
@@ -63,6 +65,7 @@ class MainActivity : AppCompatActivity() {
6365
httpClient(okHttpClient)
6466
enableCache(true)
6567
enableLog(true)
68+
withCustomVideoInfoModels(UltimediaVideoInfoModel())
6669
}
6770
}
6871

app/src/main/java/com/gapps/videonoapi/adapters/VideoAdapter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class VideoAdapter(private val videoService: VideoService, private val listener:
155155
VideoPreviewModel.USTREAM -> R.drawable.ibm
156156
VideoPreviewModel.TED_TALKS -> R.drawable.ted_talks
157157
VideoPreviewModel.COUB -> R.drawable.ic_coub
158+
"Ultimedia" -> R.drawable.ultimedia
158159
else -> R.drawable.ic_video
159160
}
160161

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.gapps.videonoapi.custom.abraira
2+
3+
import com.gapps.library.api.FORMAT
4+
import com.gapps.library.api.FORMAT_JSON
5+
import com.gapps.library.api.URL
6+
import com.gapps.library.api.models.api.base.VideoInfoModel
7+
import com.gapps.videonoapi.custom.abraira.response.UltimediaResponse
8+
9+
class UltimediaVideoInfoModel: VideoInfoModel<UltimediaResponse>() {
10+
override val baseUrl: String
11+
get() = "https://www.ultimedia.com"
12+
//https://regex101.com/r/2AsrOc/1
13+
override val pattern: String
14+
get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?ultimedia\\.com\\/(?:deliver|default|api)\\/.*\\/([_a-zA-Z0-9]+)\\S*"
15+
override val idPattern: String
16+
get() = pattern
17+
override val type: Class<UltimediaResponse>
18+
get() = UltimediaResponse::class.java
19+
override val hostingName: String
20+
get() = "Ultimedia"
21+
22+
override fun getInfoUrl(incomingUrl: String?): String? {
23+
return "$baseUrl/api/search/oembed?$FORMAT=$FORMAT_JSON&$URL=$incomingUrl"
24+
}
25+
26+
override fun getPlayLink(videoId: String): String {
27+
return "https://www.ultimedia.com/deliver/generic/iframe/src/$videoId/"
28+
}
29+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.gapps.videonoapi.custom.abraira.response
2+
3+
4+
import com.gapps.library.api.models.video.VideoPreviewModel
5+
import com.gapps.library.api.models.video.base.BaseVideoResponse
6+
import com.google.gson.annotations.SerializedName
7+
8+
data class UltimediaResponse(
9+
@SerializedName("version")
10+
val version: String = "",
11+
@SerializedName("type")
12+
val type: String = "",
13+
@SerializedName("title")
14+
val title: String = "",
15+
@SerializedName("description")
16+
val description: String = "",
17+
@SerializedName("html")
18+
val html: String = "",
19+
@SerializedName("width")
20+
val width: String = "",
21+
@SerializedName("height")
22+
val height: String = "",
23+
@SerializedName("thumbnail_url")
24+
val thumbnailUrl: String = "",
25+
@SerializedName("thumbnail_width")
26+
val thumbnailWidth: String = "",
27+
@SerializedName("thumbnail_height")
28+
val thumbnailHeight: String = "",
29+
@SerializedName("provider_name")
30+
val providerName: String = "",
31+
@SerializedName("provider_url")
32+
val providerUrl: String = "",
33+
@SerializedName("author_name")
34+
val authorName: String = ""
35+
): BaseVideoResponse{
36+
override fun toPreview(url: String?, linkToPlay: String, hostingName: String, videoId: String): VideoPreviewModel {
37+
return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply {
38+
this.thumbnailUrl = this@UltimediaResponse.thumbnailUrl
39+
this.videoTitle = this@UltimediaResponse.authorName
40+
this.width = this@UltimediaResponse.width.toInt()
41+
this.height = this@UltimediaResponse.height.toInt()
42+
}
43+
}
44+
}
825 Bytes
Loading

library/src/main/java/com/gapps/library/api/VideoService.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ package com.gapps.library.api
33
import android.content.Context
44
import android.util.Log
55
import com.gapps.library.api.models.api.*
6+
import com.gapps.library.api.models.api.base.VideoInfoModel
67
import com.gapps.library.api.models.video.VideoPreviewModel
8+
import com.gapps.library.api.models.video.base.BaseVideoResponse
79
import okhttp3.OkHttpClient
810

911

1012
class VideoService(
1113
context: Context?,
1214
client: OkHttpClient,
1315
isCacheEnabled: Boolean,
14-
val isLogEnabled: Boolean
16+
val isLogEnabled: Boolean,
17+
val customModels: List<VideoInfoModel<out BaseVideoResponse>>
1518
) {
1619
private val videoInfoModelsList = mutableListOf(
1720
CoubVideoInfoModel(),
@@ -36,8 +39,11 @@ class VideoService(
3639
builder.context,
3740
builder.okHttpClient,
3841
builder.isCacheEnabled,
39-
builder.isLogEnabled
40-
)
42+
builder.isLogEnabled,
43+
builder.customModels
44+
) {
45+
this.videoInfoModelsList.addAll(customModels)
46+
}
4147

4248
private val videoHelper = Helper2(context, client, isCacheEnabled)
4349

@@ -83,6 +89,8 @@ class VideoService(
8389
var context: Context? = null
8490
private set
8591

92+
val customModels: MutableList<VideoInfoModel<out BaseVideoResponse>> = mutableListOf()
93+
8694
fun with(context: Context) = apply { this.context = context }
8795

8896
fun httpClient(client: OkHttpClient) = apply { okHttpClient = client }
@@ -91,6 +99,8 @@ class VideoService(
9199

92100
fun enableCache(isEnabled: Boolean) = apply { isCacheEnabled = isEnabled }
93101

102+
fun <T : VideoInfoModel<out BaseVideoResponse>> withCustomVideoInfoModels(vararg models: T) = apply { this.customModels.addAll(models) }
103+
94104
fun build() = VideoService(this)
95105
}
96106
}

library/src/main/java/com/gapps/library/api/models/api/RutubeVideoInfoModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RutubeVideoInfoModel : VideoInfoModel<RutubeResponse>() {
2222
val id = parseVideoId(incomingUrl) ?: return null
2323

2424
return if (id.length < 32) {
25-
"$baseUrl/oembed?$FORMAT=$FORMAT_JSON&$URL=$this"
25+
"$baseUrl/oembed?$FORMAT=$FORMAT_JSON&$URL=$id"
2626
} else {
2727
"$baseUrl/video/$id/"
2828
}

0 commit comments

Comments
 (0)