Skip to content

Commit bdac8d2

Browse files
committed
Loom added
1 parent 3ba82a1 commit bdac8d2

File tree

15 files changed

+140
-60
lines changed

15 files changed

+140
-60
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ A simple library for parsing and playing links from YouTube, YouTube Music, Vime
2323
* <img src="https://github.com/TalbotGooday/Android-Oembed-Video/blob/master/app/src/main/res/drawable-xxhdpi/ted_talks.png" width=18px/> Ted Talks
2424
* <img src="https://cdn.iconscout.com/icon/free/png-512/coub-1693601-1442642.png" width=18px/> Coub
2525
* <img src="https://cdn.embed.ly/providers/logos/streamable.png" width=18px/> Streamable
26+
* <img src="https://github.com/TalbotGooday/Android-Oembed-Video/blob/master/app/src/main/res/drawable-xxhdpi/loom.png" width=18px/> Loom
27+
2628
## Screenshots
2729

2830
<img src="/screenshots/device-2020-02-06-232720.png" width=32%/> <img src="/screenshots/device-2020-02-06-232746.png" width=32%/> <img src="/screenshots/device-2020-02-06-232924.png" width=32%/>

app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ apply plugin: 'kotlin-android'
55
apply plugin: 'kotlin-android-extensions'
66

77
android {
8-
compileSdkVersion 29
9-
buildToolsVersion "29.0.3"
8+
compileSdkVersion 30
9+
buildToolsVersion "30.0.2"
1010
defaultConfig {
1111
applicationId "com.gapps.videonoapi"
1212
minSdkVersion 19
13-
targetSdkVersion 29
13+
targetSdkVersion 30
1414
versionCode 1
1515
versionName "1.0"
1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -28,7 +28,7 @@ dependencies {
2828
implementation fileTree(dir: 'libs', include: ['*.jar'])
2929
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3030
implementation 'androidx.appcompat:appcompat:1.2.0'
31-
implementation 'androidx.core:core-ktx:1.3.1'
31+
implementation 'androidx.core:core-ktx:1.3.2'
3232

3333
implementation 'com.squareup.okhttp3:okhttp:4.8.0'
3434
implementation 'com.squareup.okhttp3:logging-interceptor:4.7.2'

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class MainActivity : BaseActivity() {
4141
"https://www.ted.com/talks/jill_bolte_taylor_my_stroke_of_insight",
4242
"https://coub.com/view/um0um0",
4343
"https://www.ultimedia.com/default/index/videogeneric/id/pzkk35/",
44-
"https://notAVideoHost.tv/recorded/101541339"
44+
"https://loom.com/share/0281766fa2d04bb788eaf19e65135184",
45+
"https://notAVideoHost.tv/recorded/101541339",
4546
)
4647

4748
override fun onCreate(savedInstanceState: Bundle?) {
@@ -81,7 +82,7 @@ class MainActivity : BaseActivity() {
8182
}
8283
})
8384
adapter = videoAdapter.apply {
84-
swapData(videoUrls.filter { it.isVideoUrl() })
85+
swapData(getValidUrls())
8586
}
8687

8788
addOnScrollListener(ScrollListener(convertDpToPx(100f)) {
@@ -100,8 +101,10 @@ class MainActivity : BaseActivity() {
100101
}
101102

102103
swiperefresh.setOnRefreshListener {
103-
(videos_list.adapter as VideoAdapter).swapData(videoUrls)
104+
(videos_list.adapter as VideoAdapter).swapData(getValidUrls())
104105
swiperefresh.isRefreshing = false
105106
}
106107
}
108+
109+
private fun getValidUrls() = videoUrls.filter { it.isVideoUrl() }
107110
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class VideoAdapter(private val context: Context, private val videoService: Video
4141
}
4242

4343
override fun getBottomMargin(position: Int): Int {
44-
Log.d("MarginItemDecoration", "bottom: position: $position, itemCount: $itemCount")
45-
4644
return if (position == itemCount - 1) {
4745
context.convertDpToPx(75f).toInt()
4846
} else {
@@ -174,6 +172,7 @@ class VideoAdapter(private val context: Context, private val videoService: Video
174172
"Coub" -> R.drawable.ic_coub
175173
"Ultimedia" -> R.drawable.ultimedia
176174
"Streamable" -> R.drawable.streamable
175+
"Loom" -> R.drawable.loom
177176
else -> R.drawable.ic_video
178177
}
179178

3.75 KB
Loading

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.4.0'
4+
ext.kotlin_version = '1.4.10'
55

66
repositories {
77
google()

library/build.gradle

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44
android {
5-
compileSdkVersion 29
6-
buildToolsVersion "29.0.3"
5+
compileSdkVersion 30
6+
buildToolsVersion "30.0.2"
77

88
defaultConfig {
99
minSdkVersion 19
10-
targetSdkVersion 29
10+
targetSdkVersion 30
1111
versionCode 1
1212
versionName "1.0"
1313

@@ -31,20 +31,20 @@ dependencies {
3131
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3232

3333
//AndroidX
34-
implementation 'androidx.appcompat:appcompat:1.1.0'
35-
implementation 'com.google.android.material:material:1.1.0'
36-
implementation 'androidx.core:core-ktx:1.3.0'
34+
implementation 'androidx.appcompat:appcompat:1.2.0'
35+
implementation 'com.google.android.material:material:1.2.1'
36+
implementation 'androidx.core:core-ktx:1.3.2'
3737

3838
//Gson
3939
implementation 'com.google.code.gson:gson:2.8.6'
4040
//Coroutines
41-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7'
41+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
4242

43-
//Retrofit
44-
implementation 'com.squareup.okhttp3:okhttp:4.7.2'
43+
//OkHttp
44+
implementation 'com.squareup.okhttp3:okhttp:4.8.0'
4545

4646
//Test
47-
testImplementation 'junit:junit:4.13'
48-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
49-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
47+
testImplementation 'junit:junit:4.13.1'
48+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
49+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
5050
}

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ internal class VideoLoadHelper(
2222
private val context: Context?,
2323
private val client: OkHttpClient,
2424
private val isCacheEnabled: Boolean,
25-
val isLogEnabled: Boolean
25+
val isLogEnabled: Boolean,
2626
) : CoroutineScope {
27-
private val job = Job()
2827
override val coroutineContext: CoroutineContext
29-
get() = job + Dispatchers.Main
30-
31-
private val databaseContext = job + Dispatchers.IO
28+
get() = SupervisorJob() + Dispatchers.Main
3229

3330
private val gson = GsonBuilder()
3431
.setLenient()
@@ -39,7 +36,7 @@ internal class VideoLoadHelper(
3936
originalUrl: String?,
4037
videoInfoModel: VideoInfoModel<*>,
4138
onSuccess: (VideoPreviewModel) -> Unit,
42-
onError: (String, String) -> Unit
39+
onError: (String, String) -> Unit,
4340
) {
4441
val finalUrl = videoInfoModel.getInfoUrl(originalUrl)
4542
val videoId = videoInfoModel.parseVideoId(originalUrl)
@@ -56,9 +53,7 @@ internal class VideoLoadHelper(
5653
if (isCacheEnabled) {
5754
if (context != null) {
5855
try {
59-
val model = withContext(databaseContext) {
60-
getCachedVideoModel(context, playLink)
61-
}
56+
val model = getCachedVideoModel(context, playLink)
6257

6358
if (model != null) {
6459
onSuccess.invoke(model)
@@ -94,19 +89,19 @@ internal class VideoLoadHelper(
9489

9590
try {
9691
if (context != null && isCacheEnabled) {
97-
withContext(databaseContext) {
98-
insertModel(context, result)
99-
}
92+
insertModel(context, result)
10093
}
10194
} catch (e: Exception) {
102-
e.printStackTrace()
95+
onError.invoke(originalUrl
96+
?: "null url", "$ERROR_2\n---> ${e.localizedMessage}")
10397
}
10498
} catch (e: Exception) {
105-
onError.invoke(originalUrl ?: "null url", "$ERROR_2 \n---> ${e.localizedMessage}")
99+
onError.invoke(originalUrl ?: "null url", "$ERROR_2 !!! \n---> ${e.localizedMessage}")
106100
}
107101
}
108102
}
109103

104+
@Suppress("BlockingMethodInNonBlockingContext")
110105
private suspend fun makeCallGetBody(client: OkHttpClient, url: String) = withContext(Dispatchers.IO) {
111106
val response = client.newCall(Request.Builder().url(url).build()).execute()
112107
val stringBody = response.body?.string() ?: return@withContext null

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class VideoService(
2121
const val TAG = "VideoService"
2222

2323
val videoInfoModelsList = mutableListOf(
24+
LoomVideoInfoModel(),
2425
CoubVideoInfoModel(),
2526
DailymotionVideoInfoModel(),
2627
FacebookVideoInfoModel(),
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.gapps.library.api.models.api
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.library.api.models.video.loom.LoomResponse
8+
import com.gapps.library.api.models.video.ultimedia.UltimediaResponse
9+
10+
open class LoomVideoInfoModel: VideoInfoModel<LoomResponse>() {
11+
override val baseUrl: String
12+
get() = "https://www.loom.com"
13+
//https://regex101.com/r/0TwCJy/1
14+
override val pattern: String
15+
get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?(?:use)?loom\\.com\\/(?:share|default|api)\\/([_a-zA-Z0-9]+)\\S*"
16+
override val idPattern: String
17+
get() = pattern
18+
override val type: Class<LoomResponse>
19+
get() = LoomResponse::class.java
20+
override val hostingName: String
21+
get() = "Loom"
22+
23+
override fun getInfoUrl(incomingUrl: String?): String? {
24+
return "$baseUrl/v1/oembed?$FORMAT=$FORMAT_JSON&$URL=$incomingUrl"
25+
}
26+
27+
override fun getPlayLink(videoId: String): String {
28+
return "https://www.loom.com/embed/$videoId/"
29+
}
30+
}

0 commit comments

Comments
 (0)