diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39b6783 --- /dev/null +++ b/.gitignore @@ -0,0 +1,65 @@ +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +.idea/caches + +# Keystore files +# Uncomment the following line if you do not want to check your keystore files in. +#*.jks + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..c22e776 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Video No Api \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="CompilerConfiguration"> + <bytecodeTargetLevel target="11" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..e34606c --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="RemoteRepositoriesConfiguration"> + <remote-repository> + <option name="id" value="central" /> + <option name="name" value="Maven Central repository" /> + <option name="url" value="https://repo1.maven.org/maven2" /> + </remote-repository> + <remote-repository> + <option name="id" value="jboss.community" /> + <option name="name" value="JBoss Community repository" /> + <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" /> + </remote-repository> + <remote-repository> + <option name="id" value="BintrayJCenter" /> + <option name="name" value="BintrayJCenter" /> + <option name="url" value="https://jcenter.bintray.com/" /> + </remote-repository> + <remote-repository> + <option name="id" value="Google" /> + <option name="name" value="Google" /> + <option name="url" value="https://dl.google.com/dl/android/maven2/" /> + </remote-repository> + <remote-repository> + <option name="id" value="MavenRepo" /> + <option name="name" value="MavenRepo" /> + <option name="url" value="https://repo.maven.apache.org/maven2/" /> + </remote-repository> + </component> +</project> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..35e1261 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="DesignSurface"> + <option name="filePathToZoomLevelMap"> + <map> + <entry key="app/src/main/res/layout/item_video.xml" value="0.3703125" /> + <entry key="embedded_video_lib/src/main/res/layout/layout_hc_video_view.xml" value="0.35572916666666665" /> + </map> + </option> + </component> + <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/build/classes" /> + </component> + <component name="ProjectType"> + <option name="id" value="Android" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..131c070 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/Video_No_Api.iml" filepath="$PROJECT_DIR$/.idea/modules/Video_No_Api.iml" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/app/Video_No_Api.app.iml" filepath="$PROJECT_DIR$/.idea/modules/app/Video_No_Api.app.iml" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/app/Video_No_Api.app.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/app/Video_No_Api.app.androidTest.iml" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/app/Video_No_Api.app.main.iml" filepath="$PROJECT_DIR$/.idea/modules/app/Video_No_Api.app.main.iml" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/app/Video_No_Api.app.unitTest.iml" filepath="$PROJECT_DIR$/.idea/modules/app/Video_No_Api.app.unitTest.iml" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/library/Video_No_Api.embedded_video_lib.iml" filepath="$PROJECT_DIR$/.idea/modules/library/Video_No_Api.embedded_video_lib.iml" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/embedded_video_lib/Video_No_Api.embedded_video_lib.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/embedded_video_lib/Video_No_Api.embedded_video_lib.androidTest.iml" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/embedded_video_lib/Video_No_Api.embedded_video_lib.main.iml" filepath="$PROJECT_DIR$/.idea/modules/embedded_video_lib/Video_No_Api.embedded_video_lib.main.iml" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/embedded_video_lib/Video_No_Api.embedded_video_lib.unitTest.iml" filepath="$PROJECT_DIR$/.idea/modules/embedded_video_lib/Video_No_Api.embedded_video_lib.unitTest.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..447adb5 --- /dev/null +++ b/README.md @@ -0,0 +1,161 @@ + +# Android Oembed Video +A simple library for parsing and playing links from YouTube, YouTube Music, Vimeo and Rutube and others in the WebView without the need to connect data API services. + +[![Release](https://jitpack.io/v/TalbotGooday/Android-Oembed-Video.svg)](https://jitpack.io/#TalbotGooday/Android-Oembed-Video) [![Platform](https://img.shields.io/badge/platforms-Android-green.svg)]() [![Languages](https://img.shields.io/badge/languages-Kotlin-F18E33.svg)]() + +## Supported Video Hostings + +* <img src="https://github.com/TalbotGooday/Android-Oembed-Video/blob/master/app/src/main/res/drawable-xxhdpi/youtube.png" width=18px/> YouTube + +* <img src="https://github.com/TalbotGooday/Android-Oembed-Video/blob/master/app/src/main/res/drawable-xxhdpi/youtube_music.png" width=18px/> YouTube Music + +* <img src="https://github.com/TalbotGooday/Android-Oembed-Video/blob/master/app/src/main/res/drawable-xxhdpi/vimeo.png" width=18px/> Vimeo + +* <img src="https://github.com/TalbotGooday/Android-Oembed-Video/blob/master/app/src/main/res/drawable-xxhdpi/rutube.png" width=18px/> Rutube + +* <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fb/Facebook_icon_2013.svg/1024px-Facebook_icon_2013.svg.png" width=18px/> Facebook (is no longer available due to API restrictions) +* <img src="https://github.com/TalbotGooday/Android-Oembed-Video/blob/master/app/src/main/res/drawable-xxhdpi/dailymotion.png" width=18px/> Dailymotion +* <img src="https://www.saashub.com/images/app/service_logos/25/1a1b2c9e8acc/large.png?1547934029" width=18px/> Wistia +* <img src="https://static.crozdesk.com/web_app_library/providers/logos/000/003/720/original/vzaar-1559230945-logo.png?1559230945" width=18px/> ~~Vzaar~~ (it's Dacast now) +* <img src="https://github.com/TalbotGooday/Android-Oembed-Video/blob/master/app/src/main/res/drawable-xxhdpi/hulu.png" width=18px/> Hulu +* <img src="https://blog.video.ibm.com/wp-content/uploads/2014/10/U_logo_blue-2.png" width=18px/> Ustream +* <img src="https://github.com/TalbotGooday/Android-Oembed-Video/blob/master/app/src/main/res/drawable-xxhdpi/ted_talks.png" width=18px/> Ted Talks +* <img src="https://cdn.iconscout.com/icon/free/png-512/coub-1693601-1442642.png" width=18px/> Coub +* <img src="https://cdn.embed.ly/providers/logos/streamable.png" width=18px/> Streamable +* <img src="https://github.com/TalbotGooday/Android-Oembed-Video/blob/master/app/src/main/res/drawable-xxhdpi/loom.png" width=18px/> Loom + +## Screenshots + +<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%/> + +Add it in your root build.gradle at the end of repositories: +```java +allprojects { + repositories { + ... + maven { url 'https://jitpack.io' } + } +} +``` +Add the dependency + +```java +dependencies { + implementation 'com.github.TalbotGooday:Android-Oembed-Video:Tag' +} + +``` + +## Work Flow +1. Create your OkHttpClient and add it to the VideoService.Builder +```kotlin +val okHttpClient = OkHttpClient.Builder() + .connectTimeout(15, TimeUnit.SECONDS) + .readTimeout(15, TimeUnit.SECONDS) + .build() + +val videoService = VideoService.build{ + with(this@MainActivity) + httpClient(okHttpClient) + enableCache(true) + enableLog(true) +} +``` +2. Get VideoPreviewModel +```kotlin +videoService.loadVideoPreview( + url, + onSuccess = { video -> + //handle a video model + }, + onError = { url, error -> + //handle an error + }) +``` +3. Enable/disable caching +```kotlin +val videoService = VideoService.build { + enableCache(true) +} +``` +4. Enable/disable logging +```kotlin +val videoService = VideoService.build { + enableLog(BuildConfig.DEBUG) +} +``` +## Play Video from VideoPreviewModel +The BottomVideoController allows to run any oembed video in WebView. +```kotlin +val host = model.videoHosting +val linkToPlay = model.linkToPlay +val title = model.videoTitle +val initUrl = model.url + +BottomVideoController.build(this) { + setListener(object : BottomVideoController.Listener() { + override fun openLinkIn(link: String) { + openLink(link) + } + override fun copyLink(link: String) { + copyLinkToClipboard(link) + } + }) + setHostText(host) + setPlayLink(linkToPlay) + setSize(model.width, model.height) + setTitle(title) + setVideoUrl(initUrl) + setProgressView(TextView(this@MainActivity).apply { text = "Loading" }) + show() +} +``` +## How to add some other video hosting +1. Add the `Gson` library to your project +2. Create the `Gson` data class from the embed response of the video service. Make this class a subclass of `VideoInfoModel`, implement the` toPreview` function, and override it: +```kotlin + override fun toPreview(url: String?, linkToPlay: String, hostingName: String, videoId: String): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@UltimediaResponse.thumbnailUrl + this.videoTitle = this@UltimediaResponse.authorName + this.width = this@UltimediaResponse.width.toInt() + this.height = this@UltimediaResponse.height.toInt() + } + } +``` +3. Create a subclass of `VideoInfoModel`, implement members and override them: +```kotlin +class UltimediaVideoInfoModel: VideoInfoModel<UltimediaResponse>() { + override val baseUrl: String + get() = "https://www.ultimedia.com" + //https://regex101.com/r/2AsrOc/1 + override val pattern: String + get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?ultimedia\\.com\\/(?:deliver|default|api)\\/.*\\/([_a-zA-Z0-9]+)\\S*" + override val idPattern: String + get() = pattern //or some another video id search pattern + override val type: Class<UltimediaResponse> + get() = UltimediaResponse::class.java + override val hostingName: String + get() = "Ultimedia" + + override fun getInfoUrl(incomingUrl: String?): String? { + return "$baseUrl/api/search/oembed?$FORMAT=$FORMAT_JSON&$URL=$incomingUrl" + } + + override fun getPlayLink(videoId: String): String { + return "https://www.ultimedia.com/deliver/generic/iframe/src/$videoId/" + } +} +``` +**Note:** By default, the index of the `Regex` group should be **1**. If your `idPattern` does not fulfill this condition, then override the `parseVideoId` method: +```kotlin +override fun parseVideoId(url: String?): String? { + url ?: return null + return idPattern.toRegex().find(url)?.groups?.get(**someIndex**)?.value +} +``` +## License + +This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details + diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..cd9a2a0 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,42 @@ +apply plugin: 'com.android.application' + +apply plugin: 'kotlin-android' + +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 31 + buildToolsVersion "30.0.3" + defaultConfig { + applicationId "com.gapps.videonoapi" + minSdkVersion 21 + targetSdkVersion 31 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables.useSupportLibrary = true + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.4.2' + implementation 'androidx.core:core-ktx:1.8.0' + + implementation 'com.squareup.okhttp3:okhttp:4.9.3' + implementation 'com.squareup.okhttp3:logging-interceptor:4.9.3' + + //Gson + implementation(project(':embedded_video_lib')) + + implementation 'androidx.recyclerview:recyclerview:1.2.1' + implementation("io.coil-kt:coil:2.1.0") + implementation("io.coil-kt:coil-gif:2.1.0") + implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/gapps/videonoapi/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/gapps/videonoapi/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..a2ed137 --- /dev/null +++ b/app/src/androidTest/java/com/gapps/videonoapi/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.gapps.videonoapi + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.gapps.videonoapi", appContext.packageName) + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..575fffd --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + package="com.gapps.videonoapi"> + + <uses-permission android:name="android.permission.INTERNET" /> + + <application + android:allowBackup="true" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:roundIcon="@mipmap/ic_launcher_round" + android:supportsRtl="true" + android:theme="@style/AppTheme" + android:name=".app.App" + android:usesCleartextTraffic="true" + tools:targetApi="m"> + <activity + android:name=".ui.main.MainActivity" + android:exported="true" + android:label="@string/app_name" + android:theme="@style/AppTheme.NoActionBar"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + <activity + android:name=".ui.text.TextActivity" + android:label="@string/app_name" + android:theme="@style/AppTheme.NoActionBar" /> + </application> + +</manifest> \ No newline at end of file diff --git a/app/src/main/java/com/gapps/videonoapi/app/App.kt b/app/src/main/java/com/gapps/videonoapi/app/App.kt new file mode 100644 index 0000000..9f457a4 --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/app/App.kt @@ -0,0 +1,29 @@ +package com.gapps.videonoapi.app + +import android.app.Application +import android.os.Build.VERSION.SDK_INT +import coil.Coil +import coil.ImageLoader +import coil.decode.GifDecoder +import coil.decode.ImageDecoderDecoder + +class App : Application() { + override fun onCreate() { + super.onCreate() + iniCoil() + } + + private fun iniCoil() { + val imageLoader = ImageLoader.Builder(this) + .components { + if (SDK_INT >= 28) { + add(ImageDecoderDecoder.Factory()) + } else { + add(GifDecoder.Factory()) + } + } + .build() + + Coil.setImageLoader(imageLoader) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gapps/videonoapi/ui/base/BaseActivity.kt b/app/src/main/java/com/gapps/videonoapi/ui/base/BaseActivity.kt new file mode 100644 index 0000000..485b652 --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/ui/base/BaseActivity.kt @@ -0,0 +1,84 @@ +package com.gapps.videonoapi.ui.base + +import android.content.* +import android.net.Uri +import android.widget.TextView +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.ui.bottom_menu.BottomVideoController +import com.gapps.videonoapi.R + +abstract class BaseActivity : AppCompatActivity() { + + protected fun showVideo(model: VideoPreviewModel) { + val host = model.videoHosting + val linkToPlay = model.linkToPlay + val title = model.videoTitle + val initUrl = model.url + + BottomVideoController.build(this) { + setListener(object : BottomVideoController.Listener() { + override fun openLinkIn(link: String) { + openLink(link) + } + + override fun copyLink(link: String) { + copyLinkToClipboard(link) + } + }) + setHostText(host) + setPlayLink(linkToPlay) + setSize(model.width, model.height) + setTitle(title) + setVideoUrl(initUrl) + setBackgroundColor(ContextCompat.getColor(this@BaseActivity, R.color.colorBackground)) + setTextColor(ContextCompat.getColor(this@BaseActivity, R.color.colorHostName)) + setTitleColor(ContextCompat.getColor(this@BaseActivity, R.color.colorVideoTitle)) + setLeftButtonText(R.string.vna_close) + setRightButtonText(R.string.vna_open_in) + setRightButtonTextColor( + ContextCompat.getColor( + this@BaseActivity, + R.color.colorVideoTitle + ) + ) + setLeftButtonTextColor( + ContextCompat.getColor( + this@BaseActivity, + R.color.colorVideoTitle + ) + ) + setCenterButtonIcon(R.drawable.ic_vna_content_copy) + setCenterButtonIconTint( + ContextCompat.getColor( + this@BaseActivity, + R.color.colorVideoTitle + ) + ) + setProgressView(TextView(this@BaseActivity).apply { + text = "Loading"; setTextColor(-1) + }) + show() + } + } + + private fun copyLinkToClipboard(link: String) { + val clip = ClipData.newPlainText("VideoUrl", link) + (getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager)?.setPrimaryClip(clip) + Toast.makeText(this, "Copied: $link", Toast.LENGTH_SHORT).show() + } + + private fun openLink(link: String) { + try { + val intent = Intent(Intent.ACTION_VIEW).apply { + data = Uri.parse(link) + } + + startActivity(intent) + } catch (e: ActivityNotFoundException) { + e.printStackTrace() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gapps/videonoapi/ui/main/MainActivity.kt b/app/src/main/java/com/gapps/videonoapi/ui/main/MainActivity.kt new file mode 100644 index 0000000..ff512ce --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/ui/main/MainActivity.kt @@ -0,0 +1,116 @@ +package com.gapps.videonoapi.ui.main + +import android.content.Intent +import android.os.Bundle +import androidx.recyclerview.widget.LinearLayoutManager +import com.gapps.library.api.VideoService +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.utils.isVideoUrl +import com.gapps.videonoapi.R +import com.gapps.videonoapi.ui.base.BaseActivity +import com.gapps.videonoapi.ui.main.adapters.VideoAdapter +import com.gapps.videonoapi.ui.text.TextActivity +import com.gapps.videonoapi.utils.extensions.alphaSmooth +import com.gapps.videonoapi.utils.extensions.convertDpToPx +import com.gapps.videonoapi.utils.recycler_view.MarginItemDecoration +import com.gapps.videonoapi.utils.scroll.ScrollListener +import com.gapps.videonoapi.video_utils.ultimedia.UltimediaVideoInfoModel +import com.gapps.videonoapi.video_utils.youtube.MyYoutubeVideoInfoModel +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import java.util.concurrent.TimeUnit + +class MainActivity : BaseActivity() { + + private lateinit var videoService: VideoService + + private val videoUrls = listOf( + "https://www.youtube.com/watch?v=M4BSGZ07NNA", + "https://music.youtube.com/watch?v=lFMOYjVCLUo", + "https://streamable.com/s0phr", + "https://vimeo.com/259411563", + "https://rutube.ru/video/d70e62b44b8893e98e3e90a6e2c9fcd4/?pl_type=source&pl_id=18265", + "https://www.facebook.com/watch?v=795751214848051", + "https://www.dailymotion.com/video/x5sxbmb", + "https://dave.wistia.com/medias/0k5h1g1chs/", + "https://vzaar.com/videos/401431", + "http://www.hulu.com/w/154323", + "https://ustream.tv/channel/6540154", + "https://ustream.tv/recorded/101541339", + "https://www.ted.com/talks/jill_bolte_taylor_my_stroke_of_insight", + "https://coub.com/view/um0um0", + "https://www.ultimedia.com/default/index/videogeneric/id/pzkk35/", + "https://loom.com/share/0281766fa2d04bb788eaf19e65135184", + "https://notAVideoHost.tv/recorded/101541339", + ) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + initService() + + initViews() + } + + private fun initService() { + val interceptor = HttpLoggingInterceptor() + interceptor.level = HttpLoggingInterceptor.Level.BODY + + val okHttpClient = OkHttpClient.Builder() + .connectTimeout(15, TimeUnit.SECONDS) + .readTimeout(15, TimeUnit.SECONDS) + .addInterceptor(interceptor) + .build() + + videoService = VideoService.build { + with(this@MainActivity) + httpClient(okHttpClient) + enableCache(false) + enableLog(true) + withCustomVideoInfoModels(UltimediaVideoInfoModel(), MyYoutubeVideoInfoModel()) + } + } + + private fun initViews() { + videos_list.apply { + layoutManager = LinearLayoutManager(this@MainActivity) + val videoAdapter = + VideoAdapter( + context = this@MainActivity, + videoService = videoService, + listener = object : VideoAdapter.Listener { + override fun onItemClick(item: VideoPreviewModel) { + showVideo(item) + } + } + ) + + adapter = videoAdapter.apply { + swapData(getValidUrls()) + } + + addOnScrollListener(ScrollListener(convertDpToPx(100f)) { + buttons_container.alphaSmooth(if (it) .1f else 1f) + }) + +// addItemDecoration(MarginItemDecoration(videoAdapter, top = false, bottom = true)) + } + + text_test.setOnClickListener { + startActivity(Intent(this, TextActivity::class.java)) + } + + collapse_all.setOnClickListener { + (videos_list.adapter as VideoAdapter).collapseAll() + } + + swiperefresh.setOnRefreshListener { + (videos_list.adapter as VideoAdapter).swapData(getValidUrls()) + swiperefresh.isRefreshing = false + } + } + + private fun getValidUrls() = videoUrls.filter { it.isVideoUrl() } +} diff --git a/app/src/main/java/com/gapps/videonoapi/ui/main/adapters/VideoAdapter.kt b/app/src/main/java/com/gapps/videonoapi/ui/main/adapters/VideoAdapter.kt new file mode 100644 index 0000000..8a222a2 --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/ui/main/adapters/VideoAdapter.kt @@ -0,0 +1,217 @@ +package com.gapps.videonoapi.ui.main.adapters + +import android.content.Context +import android.util.Log +import android.util.SparseArray +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.view.isVisible +import androidx.recyclerview.widget.RecyclerView +import coil.load +import com.gapps.library.api.VideoService +import com.gapps.library.api.models.api.* +import com.gapps.library.api.models.api.builder.EmbeddingRequest +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.videonoapi.R +import com.gapps.videonoapi.utils.extensions.collapse +import com.gapps.videonoapi.utils.extensions.convertDpToPx +import com.gapps.videonoapi.utils.extensions.expand +import com.gapps.videonoapi.utils.extensions.toggleArrow +import com.gapps.videonoapi.utils.recycler_view.MarginItemDecoration +import kotlinx.android.synthetic.main.item_video.view.* + + +class VideoAdapter( + private val context: Context, + private val videoService: VideoService, + private val listener: Listener +) : RecyclerView.Adapter<VideoAdapter.Holder>(), + MarginItemDecoration.Listener { + + private var data: MutableList<String> = mutableListOf() + private val dataExpanded: SparseArray<Boolean> = SparseArray() + private val loadedData: SparseArray<VideoPreviewModel?> = SparseArray() + private val inflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder { + return Holder(inflater.inflate(R.layout.item_video, parent, false)) + } + + override fun getItemCount() = data.size + + override fun onBindViewHolder(holder: Holder, position: Int) = + holder.bind(data[position], listener) + + override fun getTopMargin(position: Int): Int { + return 0 + } + + override fun getBottomMargin(position: Int): Int { + return if (position == itemCount - 1) { + context.convertDpToPx(75f).toInt() + } else { + 0 + } + } + + fun swapData(data: List<String>) { + this.data.clear() + this.data.addAll(data) + this.loadedData.clear() + notifyDataSetChanged() + } + + fun addData(data: List<String>) { + this.data.addAll(data) + this.notifyDataSetChanged() + } + + fun collapseAll() { + this.dataExpanded.clear() + this.notifyDataSetChanged() + } + + inner class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) { + private var loadedDataItem: VideoPreviewModel? = null + + fun bind(item: String, listener: Listener) = with(itemView) { + loadedDataItem = loadedData[adapterPosition] + + val isVideoDataVisible = dataExpanded[adapterPosition] ?: false + val isNeedToLoadData = loadedDataItem == null + + video_link.text = item + + progress.isVisible = isNeedToLoadData + icon_drop_down.isVisible = isNeedToLoadData.not() + video_preview_container.isVisible = isVideoDataVisible + text_preview.isVisible = loadedDataItem?.videoTitle != null + + icon_drop_down.toggleArrow(isVideoDataVisible, 0) + + if (loadedDataItem == null) { + videoService.loadVideoPreview( + request = createRequestBuilder(item), + onSuccess = { video -> + loadedData.put(bindingAdapterPosition, video) + loadedDataItem = video + + initVideoView(video) + }, + onError = { url, errorMessage -> + Log.e("MainActivity", "$errorMessage \n $url") + + val video = VideoPreviewModel.Builder() + .setUrl(url) + .setVideoTitle("Not found") + .setErrorMessage(errorMessage) + .setThumbnailUrl("https://c.tenor.com/IHdlTRsmcS4AAAAM/404.gif") + .build() + + loadedData.put(bindingAdapterPosition, video) + loadedDataItem = video + + initVideoView(video) + }) + } else { + initVideoView(loadedDataItem) + } + + video_data_container.setOnClickListener { + loadedDataItem ?: return@setOnClickListener + + val isExpanded = toggleLayoutExpand( + (dataExpanded[bindingAdapterPosition] ?: false).not(), + icon_drop_down, + video_preview_container + ) + + dataExpanded.put(bindingAdapterPosition, isExpanded) + } + } + + private fun initVideoView(video: VideoPreviewModel?) = with(itemView) { + video ?: return + + val isError = video.errorMessage.isNullOrBlank().not() + + progress.isVisible = false + icon_drop_down.isVisible = true + text_preview.isVisible = video.videoTitle.isNullOrBlank().not() + + image_preview.load(video.thumbnailUrl) { + placeholder(R.drawable.image_shop_1) + error(R.drawable.image_shop_1) + } + + text_preview.text = video.videoTitle + + image_play.isVisible = isError.not() + + setVideoHostingLogo(video_host_logo, video.videoHosting) + + if (isError) { + video_preview_container.setOnClickListener(null) + } else { + video_preview_container.setOnClickListener { + val model = loadedDataItem ?: return@setOnClickListener + + listener.onItemClick(model) + } + } + } + + private fun toggleLayoutExpand(show: Boolean, arrowView: View, layout: View): Boolean { + arrowView.toggleArrow(show) + + if (show) { + layout.expand() + } else { + layout.collapse() + } + + return show + } + + private fun setVideoHostingLogo(iconView: ImageView, type: String?) { + type ?: return + + val icon = when (type) { + YOUTUBE_HOST_NAME -> R.drawable.youtube + YOUTUBE_MUSIC_HOST_NAME -> R.drawable.youtube_music + VIMEO_HOST_NAME -> R.drawable.vimeo + RUTUBE_HOST_NAME -> R.drawable.rutube + FACEBOOK_HOST_NAME -> R.drawable.ic_fb + DAILYMOTION_HOST_NAME -> R.drawable.dailymotion + WISTIA_HOST_NAME -> R.drawable.ic_wistia + VZAAR_HOST_NAME -> R.drawable.ic_vzaar + HULU_HOST_NAME -> R.drawable.hulu + USTREAM_HOST_NAME -> R.drawable.ibm + TED_TALKS_HOST_NAME -> R.drawable.ted_talks + COUB_HOST_NAME -> R.drawable.ic_coub + ULTIMEDIA_HOST_NAME -> R.drawable.ultimedia + STREAMABLE_HOST_NAME -> R.drawable.streamable + LOOM_HOST_NAME -> R.drawable.loom + else -> R.drawable.ic_video + } + + iconView.setImageResource(icon) + } + } + + interface Listener { + fun onItemClick(item: VideoPreviewModel) + } +} + +fun createRequestBuilder(url: String) = EmbeddingRequest.build { + setUrl(url) + headers { + host(FACEBOOK_HOST_NAME) { + add("access_token", "") + addAll(mapOf()) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gapps/videonoapi/ui/text/TextActivity.kt b/app/src/main/java/com/gapps/videonoapi/ui/text/TextActivity.kt new file mode 100644 index 0000000..77424b8 --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/ui/text/TextActivity.kt @@ -0,0 +1,113 @@ +package com.gapps.videonoapi.ui.text + +import android.graphics.Color +import android.os.Bundle +import android.text.Spannable +import android.text.SpannableString +import android.text.method.LinkMovementMethod +import android.text.style.ClickableSpan +import android.view.View +import android.widget.Toast +import com.gapps.library.api.VideoService +import com.gapps.library.utils.patterns.PatternVideoLinksBuilder +import com.gapps.library.utils.findVideos +import com.gapps.videonoapi.R +import com.gapps.videonoapi.video_utils.ultimedia.UltimediaVideoInfoModel +import com.gapps.videonoapi.ui.base.BaseActivity +import kotlinx.android.synthetic.main.activity_text.* +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import java.util.concurrent.TimeUnit + + +class TextActivity : BaseActivity() { + + private lateinit var videoService: VideoService + + private val textString = + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, https://www.youtube.com/watch?v=M4BSGZ07NNA,\n" + + "https://music.youtube.com/watch?v=lFMOYjVCLUo," + + "https://vimeo.com/333257472," + + "https://streamable.com/s0phr," + + "https://rutube.ru/video/d70e62b44b8893e98e3e90a6e2c9fcd4/?pl_type=source&pl_id=18265,\n" + + "https://www.facebook.com/UFC/videos/410056389868335/,\n" + + "https://www.dailymotion.com/video/x5sxbmb,\n" + + "https://dave.wistia.com/medias/0k5h1g1chs/,\n" + + "https://vzaar.com/videos/401431sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_text) + + initService() + + initViews() + } + + private fun initService() { + val interceptor = HttpLoggingInterceptor() + interceptor.level = HttpLoggingInterceptor.Level.BODY + + val okHttpClient = OkHttpClient.Builder() + .connectTimeout(15, TimeUnit.SECONDS) + .readTimeout(15, TimeUnit.SECONDS) + .addInterceptor(interceptor) + .build() + + videoService = VideoService.build { + with(this@TextActivity) + httpClient(okHttpClient) + enableCache(true) + enableLog(true) + withCustomVideoInfoModels(UltimediaVideoInfoModel()) + } + } + + private fun initViews() { + initTextView(false) + + clearLinks.setOnCheckedChangeListener { _, isChecked -> + initTextView(isChecked) + } + } + + private fun initTextView(clearLinks: Boolean) { + val spannableString = SpannableString(textString) + + val onClick = { url: String -> + loadVideoInfo(url) + } + + textString.findVideos(clearLinks).forEach { + spannableString.setSpan( + VideoUrlSpan(it, onClick), + it.range.first, + it.range.last, + Spannable.SPAN_COMPOSING + ) + } + + text.text = spannableString + text.movementMethod = LinkMovementMethod.getInstance() + text.highlightColor = Color.TRANSPARENT + } + + private fun loadVideoInfo(url: String) { + videoService.loadVideoPreview(url, + { video -> + showVideo(video) + }, + { _, error -> + Toast.makeText(this, error, Toast.LENGTH_SHORT).show() + }) + } + + private class VideoUrlSpan( + private val item: PatternVideoLinksBuilder.VideoPatternItem, + private val click: (String) -> Unit + ) : ClickableSpan() { + override fun onClick(widget: View) { + click.invoke(item.url) + } + } +} diff --git a/app/src/main/java/com/gapps/videonoapi/utils/extensions/Animation.kt b/app/src/main/java/com/gapps/videonoapi/utils/extensions/Animation.kt new file mode 100644 index 0000000..26796eb --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/utils/extensions/Animation.kt @@ -0,0 +1,69 @@ +package com.gapps.videonoapi.utils.extensions + +import android.view.View +import android.view.ViewGroup +import android.view.animation.Animation +import android.view.animation.Transformation + + +fun View.toggleArrow(show: Boolean, delay: Long = 200): Boolean { + return if (show) { + this.animate().setDuration(delay).rotation(180f) + true + } else { + this.animate().setDuration(delay).rotation(0f) + false + } +} + +fun View.expand(): Animation { + this.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) + val targtetHeight = this.measuredHeight + + this.layoutParams.height = 0 + this.visibility = View.VISIBLE + val a = object : Animation() { + override fun applyTransformation(interpolatedTime: Float, t: Transformation) { + this@expand.layoutParams.height = if (interpolatedTime == 1f) + ViewGroup.LayoutParams.WRAP_CONTENT + else + (targtetHeight * interpolatedTime).toInt() + this@expand.requestLayout() + } + + override fun willChangeBounds(): Boolean { + return true + } + } + + a.duration = (targtetHeight / this.context.resources.displayMetrics.density).toInt().toLong() + this.startAnimation(a) + return a +} + +fun View.collapse() { + val initialHeight = this.measuredHeight + + val a = object : Animation() { + override fun applyTransformation(interpolatedTime: Float, t: Transformation) { + if (interpolatedTime == 1f) { + this@collapse.visibility = View.GONE + } else { + this@collapse.layoutParams.height = + initialHeight - (initialHeight * interpolatedTime).toInt() + this@collapse.requestLayout() + } + } + + override fun willChangeBounds(): Boolean { + return true + } + } + + var duration = (initialHeight / this.context.resources.displayMetrics.density).toInt() + if (duration > 300) + duration = 300 + + a.duration = duration.toLong() + this.startAnimation(a) +} diff --git a/app/src/main/java/com/gapps/videonoapi/utils/extensions/Context.kt b/app/src/main/java/com/gapps/videonoapi/utils/extensions/Context.kt new file mode 100644 index 0000000..991e6e6 --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/utils/extensions/Context.kt @@ -0,0 +1,12 @@ +package com.gapps.videonoapi.utils.extensions + +import android.content.Context +import android.util.TypedValue + +fun Context.convertDpToPx(dp: Float): Float { + return TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + dp, + this.resources.displayMetrics + ) +} diff --git a/app/src/main/java/com/gapps/videonoapi/utils/extensions/View.kt b/app/src/main/java/com/gapps/videonoapi/utils/extensions/View.kt new file mode 100644 index 0000000..ee107f2 --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/utils/extensions/View.kt @@ -0,0 +1,40 @@ +package com.gapps.videonoapi.utils.extensions + +import android.view.View +import android.view.animation.LinearInterpolator + +/** + * Set the visibility state of this view to [View.VISIBLE] or [View.GONE] + * + * @param visible + */ +fun View.visibleOrGone(visible: Boolean) { + visibility = if (visible) View.VISIBLE else View.GONE +} + +/** + * Set the visibility state of this view to [View.GONE] + */ +fun View.gone() { + if (visibility != View.GONE) { + visibility = View.GONE + } +} + +/** + * Set the visibility state of this view to [View.VISIBLE] + */ +fun View.visible() { + if (visibility != View.VISIBLE) { + visibility = View.VISIBLE + } +} + +fun View.alphaSmooth(value: Float) { + this.animate().apply { + interpolator = LinearInterpolator() + duration = 200 + alpha(value) + start() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gapps/videonoapi/utils/recycler_view/MarginItemDecoration.kt b/app/src/main/java/com/gapps/videonoapi/utils/recycler_view/MarginItemDecoration.kt new file mode 100644 index 0000000..ac09957 --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/utils/recycler_view/MarginItemDecoration.kt @@ -0,0 +1,35 @@ +package com.gapps.videonoapi.utils.recycler_view + +import android.graphics.Rect +import android.view.View +import androidx.recyclerview.widget.RecyclerView + +class MarginItemDecoration( + private val listener: Listener, + val top: Boolean = true, + val bottom: Boolean = false +) : RecyclerView.ItemDecoration() { + override fun getItemOffsets( + outRect: Rect, + view: View, + parent: RecyclerView, + state: RecyclerView.State + ) { + val position = parent.getChildAdapterPosition(view) + + with(outRect) { + if (this@MarginItemDecoration.top) { + top = listener.getTopMargin(position) + } + + if (this@MarginItemDecoration.bottom) { + bottom = listener.getBottomMargin(position) + } + } + } + + interface Listener { + fun getTopMargin(position: Int): Int + fun getBottomMargin(position: Int): Int + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gapps/videonoapi/utils/scroll/ScrollListener.kt b/app/src/main/java/com/gapps/videonoapi/utils/scroll/ScrollListener.kt new file mode 100644 index 0000000..d1cd838 --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/utils/scroll/ScrollListener.kt @@ -0,0 +1,37 @@ +package com.gapps.videonoapi.utils.scroll + +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView + +class ScrollListener(private val scrollValue: Float, private val action: (Boolean) -> Unit) : + RecyclerView.OnScrollListener() { + private var totalDy = 0f + + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + super.onScrolled(recyclerView, dx, dy) + val layoutManager = recyclerView.layoutManager as LinearLayoutManager + + val firstVisiblePos = layoutManager.findFirstVisibleItemPosition() + + if (firstVisiblePos == 0) { + action.invoke(false) + } else { + if (dy > 0) { + totalDy += dy.toFloat() + if (totalDy > scrollValue) { + totalDy = 0f + action.invoke(true) + + } + } else { + totalDy += dy.toFloat() + if (totalDy < -scrollValue) { + action.invoke(false) + + totalDy = 0f + } + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gapps/videonoapi/video_utils/ultimedia/UltimediaVideoInfoModel.kt b/app/src/main/java/com/gapps/videonoapi/video_utils/ultimedia/UltimediaVideoInfoModel.kt new file mode 100644 index 0000000..0614ef7 --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/video_utils/ultimedia/UltimediaVideoInfoModel.kt @@ -0,0 +1,30 @@ +package com.gapps.videonoapi.video_utils.ultimedia + +import com.gapps.library.api.FORMAT +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.videonoapi.video_utils.ultimedia.response.UltimediaResponse + +class UltimediaVideoInfoModel : VideoInfoModel<UltimediaResponse>() { + override val baseUrl: String + get() = "https://www.ultimedia.com" + + //https://regex101.com/r/2AsrOc/1 + override val pattern: String + get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?ultimedia\\.com\\/(?:deliver|default|api)\\/.*\\/([_a-zA-Z0-9]+)\\S*" + override val idPattern: String + get() = pattern + override val type: Class<UltimediaResponse> + get() = UltimediaResponse::class.java + override val hostingName: String + get() = "Ultimedia" + + override fun getInfoUrl(incomingUrl: String?): String? { + return "$baseUrl/api/search/oembed?$FORMAT=$FORMAT_JSON&$URL=$incomingUrl" + } + + override fun getPlayLink(videoId: String): String { + return "https://www.ultimedia.com/deliver/generic/iframe/src/$videoId/" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gapps/videonoapi/video_utils/ultimedia/response/UltimediaResponse.kt b/app/src/main/java/com/gapps/videonoapi/video_utils/ultimedia/response/UltimediaResponse.kt new file mode 100644 index 0000000..f9c001e --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/video_utils/ultimedia/response/UltimediaResponse.kt @@ -0,0 +1,49 @@ +package com.gapps.videonoapi.video_utils.ultimedia.response + + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class UltimediaResponse( + @SerializedName("version") + val version: String = "", + @SerializedName("type") + val type: String = "", + @SerializedName("title") + val title: String = "", + @SerializedName("description") + val description: String = "", + @SerializedName("html") + val html: String = "", + @SerializedName("width") + val width: String = "", + @SerializedName("height") + val height: String = "", + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("thumbnail_width") + val thumbnailWidth: String = "", + @SerializedName("thumbnail_height") + val thumbnailHeight: String = "", + @SerializedName("provider_name") + val providerName: String = "", + @SerializedName("provider_url") + val providerUrl: String = "", + @SerializedName("author_name") + val authorName: String = "" +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@UltimediaResponse.thumbnailUrl + this.videoTitle = this@UltimediaResponse.authorName + this.width = this@UltimediaResponse.width.toInt() + this.height = this@UltimediaResponse.height.toInt() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gapps/videonoapi/video_utils/youtube/MyYoutubeVideoInfoModel.kt b/app/src/main/java/com/gapps/videonoapi/video_utils/youtube/MyYoutubeVideoInfoModel.kt new file mode 100644 index 0000000..b3c1023 --- /dev/null +++ b/app/src/main/java/com/gapps/videonoapi/video_utils/youtube/MyYoutubeVideoInfoModel.kt @@ -0,0 +1,32 @@ +package com.gapps.videonoapi.video_utils.youtube + +import com.gapps.library.api.FORMAT +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.YoutubeVideoInfoModel +import com.gapps.library.api.models.video.youtube.YoutubeResponse + +class MyYoutubeVideoInfoModel : YoutubeVideoInfoModel() { + override val baseUrl: String + get() = "https://www.youtube.com" + + //https://regex101.com/r/nJzgG0/1 + override val pattern: String + get() = "(?:http[s]?:\\/\\/)(?:www.)?(?:m.)?youtu(?:be|.be)?(?:\\.com)?(?:(?:\\w*.?:\\/\\/)?\\w*.?\\w*-?.?\\w*\\/(?:embed|e|v|watch|.*\\/)?\\??(?:feature=\\w*\\.?\\w*)?&?(?:v=)?\\/?)([\\w\\d_-]{11})[^,;\\s]*" + override val idPattern: String + get() = pattern + override val type: Class<YoutubeResponse> + get() = YoutubeResponse::class.java + override val hostingName: String + get() = "YouTube" + + override fun getInfoUrl(incomingUrl: String?): String? { + val id = parseVideoId(incomingUrl) + + return "$baseUrl/oembed?$FORMAT=$FORMAT_JSON&$URL=https://www.youtube.com/watch?v=$id" + } + + override fun getPlayLink(videoId: String): String { + return "https://www.youtube.com/embed/${videoId}?autoplay=0&vq=small&hl=uk" + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:aapt="http://schemas.android.com/aapt" + android:width="108dp" + android:height="108dp" + android:viewportWidth="108" + android:viewportHeight="108"> + <path + android:fillType="evenOdd" + android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z" + android:strokeWidth="1" + android:strokeColor="#00000000"> + <aapt:attr name="android:fillColor"> + <gradient + android:endX="78.5885" + android:endY="90.9159" + android:startX="48.7653" + android:startY="61.0927" + android:type="linear"> + <item + android:color="#44000000" + android:offset="0.0" /> + <item + android:color="#00000000" + android:offset="1.0" /> + </gradient> + </aapt:attr> + </path> + <path + android:fillColor="#FFFFFF" + android:fillType="nonZero" + android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z" + android:strokeWidth="1" + android:strokeColor="#00000000" /> +</vector> diff --git a/app/src/main/res/drawable-v24/ic_play.xml b/app/src/main/res/drawable-v24/ic_play.xml new file mode 100644 index 0000000..098b71d --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_play.xml @@ -0,0 +1,10 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:tint="#FFFFFF" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="#FF000000" + android:pathData="M8,5v14l11,-7z" /> +</vector> diff --git a/app/src/main/res/drawable-xxhdpi/dailymotion.png b/app/src/main/res/drawable-xxhdpi/dailymotion.png new file mode 100644 index 0000000..650565f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/dailymotion.png differ diff --git a/app/src/main/res/drawable-xxhdpi/hulu.png b/app/src/main/res/drawable-xxhdpi/hulu.png new file mode 100644 index 0000000..2e2884d Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/hulu.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ibm.png b/app/src/main/res/drawable-xxhdpi/ibm.png new file mode 100644 index 0000000..dd7e8af Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ibm.png differ diff --git a/app/src/main/res/drawable-xxhdpi/loom.png b/app/src/main/res/drawable-xxhdpi/loom.png new file mode 100644 index 0000000..7964ad2 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/loom.png differ diff --git a/app/src/main/res/drawable-xxhdpi/rutube.png b/app/src/main/res/drawable-xxhdpi/rutube.png new file mode 100644 index 0000000..727dc4c Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/rutube.png differ diff --git a/app/src/main/res/drawable-xxhdpi/streamable.png b/app/src/main/res/drawable-xxhdpi/streamable.png new file mode 100644 index 0000000..620c4b6 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/streamable.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ted_talks.png b/app/src/main/res/drawable-xxhdpi/ted_talks.png new file mode 100644 index 0000000..a0f7da8 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ted_talks.png differ diff --git a/app/src/main/res/drawable-xxhdpi/vimeo.png b/app/src/main/res/drawable-xxhdpi/vimeo.png new file mode 100644 index 0000000..1b451af Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/vimeo.png differ diff --git a/app/src/main/res/drawable-xxhdpi/youtube.png b/app/src/main/res/drawable-xxhdpi/youtube.png new file mode 100644 index 0000000..e163b63 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/youtube.png differ diff --git a/app/src/main/res/drawable-xxhdpi/youtube_music.png b/app/src/main/res/drawable-xxhdpi/youtube_music.png new file mode 100644 index 0000000..2aaa177 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/youtube_music.png differ diff --git a/app/src/main/res/drawable/bg_action_button_image.xml b/app/src/main/res/drawable/bg_action_button_image.xml new file mode 100644 index 0000000..d737daa --- /dev/null +++ b/app/src/main/res/drawable/bg_action_button_image.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android"> + <solid android:color="#9a000000" /> + <corners android:radius="40dp" /> + <padding + android:bottom="0dp" + android:left="0dp" + android:right="0dp" + android:top="0dp" /> +</shape> \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_arrow_drop.xml b/app/src/main/res/drawable/ic_arrow_drop.xml new file mode 100644 index 0000000..a824bde --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_drop.xml @@ -0,0 +1,10 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:tint="?attr/colorControlNormal" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="@android:color/white" + android:pathData="M7,10l5,5 5,-5z" /> +</vector> diff --git a/app/src/main/res/drawable/ic_arrow_forward.xml b/app/src/main/res/drawable/ic_arrow_forward.xml new file mode 100644 index 0000000..517674f --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_forward.xml @@ -0,0 +1,10 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:tint="#FFFFFF" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="@android:color/white" + android:pathData="M5.88,4.12L13.76,12l-7.88,7.88L8,22l10,-10L8,2z" /> +</vector> diff --git a/app/src/main/res/drawable/ic_coub.xml b/app/src/main/res/drawable/ic_coub.xml new file mode 100644 index 0000000..fcb4bf0 --- /dev/null +++ b/app/src/main/res/drawable/ic_coub.xml @@ -0,0 +1,22 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="48dp" + android:height="48dp" + android:viewportWidth="48" + android:viewportHeight="48"> + <group> + <clip-path + android:fillType="evenOdd" + android:pathData="M24,48C36.813,48 47.2,37.613 47.2,24.8C47.2,11.987 36.813,1.6 24,1.6C11.187,1.6 0.8,11.987 0.8,24.8C0.8,37.613 11.187,48 24,48Z" /> + <path + android:fillColor="#fff" + android:pathData="M-0.0027,48.0006H48.0027V-0.0007H-0.0027V48.0006Z" /> + </group> + <group> + <clip-path + android:fillType="evenOdd" + android:pathData="M11.4013,44.4312C4.5591,40.203 0,32.634 0,24C0,10.7452 10.7452,0 24,0C37.2548,0 48,10.7452 48,24C48,37.2548 37.2548,48 24,48C23.3639,48 22.7336,47.9752 22.1099,47.9267L24.4708,41.4403C24.8614,40.367 26.1654,38.9293 27.3153,37.6602C27.9736,36.9357 28.541,36.3089 28.7577,35.9406C29.8029,34.1605 32.991,28.8133 33.0232,28.7592C33.6783,27.8197 34.7297,26.2132 35.3778,25.1648L38.918,19.4132C39.5656,18.3618 39.6146,17.0423 39.0272,16.4728C38.924,16.3733 38.803,16.2977 38.6682,16.2487C38.0191,16.0124 37.1567,16.3954 36.5216,17.2017L32.9627,22.1642C32.5511,22.6872 32.0908,23.116 31.6452,23.5312C31.2744,23.8765 30.8918,24.2343 30.5491,24.6332L30.1856,25.0583C30.1413,25.1092 30.0797,25.1405 30.0126,25.145C29.9456,25.1494 29.882,25.1411 29.8238,25.1199C29.6969,25.0737 29.4925,24.9288 29.548,24.4768C29.56,24.4212 30.183,21.803 28.5308,21.1055L28.4586,21.078C27.5656,20.753 26.8544,21.3114 26.065,22.2504C25.9463,22.3915 25.7034,22.4048 25.5809,22.3602C25.3389,22.26 25.232,22.0454 25.2881,21.7959C25.5698,20.5361 25.0504,19.358 24.0532,18.995L23.9764,18.9694C23.1085,18.6909 22.0613,19.0476 21.4333,19.8397C21.4101,19.8682 21.383,19.8911 21.3511,19.9071C21.2264,20.0261 21.0123,20.1917 20.7794,20.1069C20.53,20.0161 20.4707,19.7125 20.4482,19.4916L20.4201,19.2177C20.393,18.9464 20.3582,18.6334 20.3185,18.2972C20.1937,17.1984 20.0379,15.8304 20.0628,14.9217L20.4456,8.4639C20.4722,7.5207 20.0383,6.7169 19.3665,6.4724C19.1769,6.4034 18.9775,6.3818 18.7733,6.4076C17.8236,6.5298 17.0078,7.6065 16.9152,8.8595L16.2104,15.3886C16.1615,16.0495 16.1769,16.9728 16.1921,17.8654C16.2034,18.5279 16.2141,19.1535 16.1984,19.6589L16.137,21.7413C16.1151,22.4427 15.8912,22.9455 15.4704,23.2357C15.2384,23.399 14.4576,23.9602 13.6132,24.7475C13.5205,24.8341 13.4266,24.9165 13.3346,24.9979C12.7114,25.5502 12.1739,26.0273 12.1221,27.6111C12.0949,28.355 12.1293,29.1112 12.2365,30.2219C12.3485,31.3881 12.6931,32.1196 13.0587,32.8939C13.5795,33.9974 14.602,35.6375 13.9135,37.5291C13.908,37.5442 12.2479,42.1054 11.4013,44.4312Z" /> + <path + android:fillColor="#0043FF" + android:pathData="M-0.0027,48.0006H48.0027V-0.0007H-0.0027V48.0006Z" /> + </group> +</vector> diff --git a/app/src/main/res/drawable/ic_fb.xml b/app/src/main/res/drawable/ic_fb.xml new file mode 100644 index 0000000..b89befb --- /dev/null +++ b/app/src/main/res/drawable/ic_fb.xml @@ -0,0 +1,14 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="14.2222dp" + android:height="14.2222dp" + android:viewportWidth="14222" + android:viewportHeight="14222"> + <path + android:fillColor="#1977F3" + android:fillType="nonZero" + android:pathData="M14222,7111c0,-3927 -3184,-7111 -7111,-7111 -3927,0 -7111,3184 -7111,7111 0,3549 2600,6491 6000,7025l0,-4969 -1806,0 0,-2056 1806,0 0,-1567c0,-1782 1062,-2767 2686,-2767 778,0 1592,139 1592,139l0,1750 -897,0c-883,0 -1159,548 -1159,1111l0,1334 1972,0 -315,2056 -1657,0 0,4969c3400,-533 6000,-3475 6000,-7025z" /> + <path + android:fillColor="#FEFEFE" + android:fillType="nonZero" + android:pathData="M9879,9167l315,-2056 -1972,0 0,-1334c0,-562 275,-1111 1159,-1111l897,0 0,-1750c0,0 -814,-139 -1592,-139 -1624,0 -2686,984 -2686,2767l0,1567 -1806,0 0,2056 1806,0 0,4969c362,57 733,86 1111,86 378,0 749,-30 1111,-86l0,-4969 1657,0z" /> +</vector> diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ +<?xml version="1.0" encoding="utf-8"?> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="108dp" + android:height="108dp" + android:viewportWidth="108" + android:viewportHeight="108"> + <path + android:fillColor="#008577" + android:pathData="M0,0h108v108h-108z" /> + <path + android:fillColor="#00000000" + android:pathData="M9,0L9,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,0L19,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M29,0L29,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M39,0L39,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M49,0L49,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M59,0L59,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M69,0L69,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M79,0L79,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M89,0L89,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M99,0L99,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,9L108,9" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,19L108,19" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,29L108,29" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,39L108,39" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,49L108,49" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,59L108,59" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,69L108,69" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,79L108,79" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,89L108,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,99L108,99" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,29L89,29" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,39L89,39" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,49L89,49" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,59L89,59" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,69L89,69" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,79L89,79" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M29,19L29,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M39,19L39,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M49,19L49,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M59,19L59,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M69,19L69,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M79,19L79,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> +</vector> diff --git a/app/src/main/res/drawable/ic_refresh.xml b/app/src/main/res/drawable/ic_refresh.xml new file mode 100644 index 0000000..7b2e9b0 --- /dev/null +++ b/app/src/main/res/drawable/ic_refresh.xml @@ -0,0 +1,10 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:tint="#FFFFFF" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="@android:color/white" + android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z" /> +</vector> diff --git a/app/src/main/res/drawable/ic_video.xml b/app/src/main/res/drawable/ic_video.xml new file mode 100644 index 0000000..c11aead --- /dev/null +++ b/app/src/main/res/drawable/ic_video.xml @@ -0,0 +1,10 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:tint="?attr/colorControlNormal" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="@android:color/white" + android:pathData="M21,3L3,3c-1.11,0 -2,0.89 -2,2v12c0,1.1 0.89,2 2,2h5v2h8v-2h5c1.1,0 1.99,-0.9 1.99,-2L23,5c0,-1.11 -0.9,-2 -2,-2zM21,17L3,17L3,5h18v12zM16,11l-7,4L9,7z" /> +</vector> diff --git a/app/src/main/res/drawable/ic_vzaar.xml b/app/src/main/res/drawable/ic_vzaar.xml new file mode 100644 index 0000000..b16c235 --- /dev/null +++ b/app/src/main/res/drawable/ic_vzaar.xml @@ -0,0 +1,12 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="190.679dp" + android:height="190.672dp" + android:viewportWidth="190.679" + android:viewportHeight="190.672"> + <path + android:fillColor="#A3C73A" + android:pathData="M190.679,95.353c0,52.647 -42.686,95.319 -95.337,95.319c-15.787,0 -30.68,-3.835 -43.788,-10.619c-4.668,-2.419 -9.107,-5.215 -13.283,-8.337C15.043,154.345 0,126.6 0,95.353c0,-1.77 0.051,-3.534 0.147,-5.295C2.895,39.859 44.46,0 95.342,0C147.993,0 190.679,42.694 190.679,95.353zM95.349,20.61c-39.451,0 -71.758,30.584 -74.544,69.316c-0.126,1.797 -0.193,3.608 -0.193,5.436c0,41.266 33.454,74.705 74.737,74.705c41.262,0 74.719,-33.439 74.719,-74.705C170.067,54.09 136.61,20.61 95.349,20.61z" /> + <path + android:fillColor="#A3C73A" + android:pathData="M149.566,95.353c0,29.942 -24.271,54.207 -54.204,54.207c-29.947,0 -54.222,-24.265 -54.222,-54.207c0,-29.953 24.275,-54.233 54.222,-54.233C125.296,41.119 149.566,65.4 149.566,95.353zM70.761,62.336v71.758l66.341,-35.876L70.761,62.336z" /> +</vector> diff --git a/app/src/main/res/drawable/ic_wistia.xml b/app/src/main/res/drawable/ic_wistia.xml new file mode 100644 index 0000000..603915d --- /dev/null +++ b/app/src/main/res/drawable/ic_wistia.xml @@ -0,0 +1,18 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="491.37332dp" + android:height="382.4dp" + android:viewportWidth="491.37332" + android:viewportHeight="382.4"> + <path + android:fillAlpha="1" + android:fillColor="#148ee0" + android:fillType="nonZero" + android:pathData="m490.812,146.352c0,-0 -11.376,22.64 -68.163,58.429 -24.205,15.228 -74.468,31.427 -139.091,37.671 -34.893,3.388 -99.133,0.636 -126.696,0.636 -27.705,-0 -40.403,5.836 -65.249,33.82C0,380.177 0,380.177 0,380.177c0,-0 31.724,0.155 55.684,0.155 23.957,-0 173.793,8.7 240.273,-9.584C511.871,311.405 490.812,146.352 490.812,146.352" + android:strokeColor="#00000000" /> + <path + android:fillAlpha="1" + android:fillColor="#54bbff" + android:fillType="nonZero" + android:pathData="m485.017,80.74c10.387,-63.339 -25.393,-80.744 -25.393,-80.744 0,-0 1.511,51.564 -93.251,62.496C282.267,72.195 0,64.883 0,64.883c0,-0 0,-0 90.715,104.027 24.568,28.2 37.609,31.468 65.232,33.421 27.623,1.852 88.587,1.193 129.912,-1.953 45.172,-3.465 109.549,-18.195 153.081,-51.908 22.321,-17.268 41.737,-41.271 46.077,-67.729" + android:strokeColor="#00000000" /> +</vector> diff --git a/app/src/main/res/drawable/image_shop_1.jpg b/app/src/main/res/drawable/image_shop_1.jpg new file mode 100644 index 0000000..b77a1f6 Binary files /dev/null and b/app/src/main/res/drawable/image_shop_1.jpg differ diff --git a/app/src/main/res/drawable/ultimedia.png b/app/src/main/res/drawable/ultimedia.png new file mode 100644 index 0000000..a0953e4 Binary files /dev/null and b/app/src/main/res/drawable/ultimedia.png differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..a1faa7a --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:orientation="vertical" + tools:context=".ui.main.MainActivity"> + + <androidx.swiperefreshlayout.widget.SwipeRefreshLayout + android:id="@+id/swiperefresh" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/videos_list" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:listitem="@layout/item_video" /> + + </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> + + <FrameLayout + android:id="@+id/buttons_container" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom"> + + <LinearLayout + android:id="@+id/collapse_all" + android:layout_width="wrap_content" + android:layout_height="48dp" + android:layout_gravity="start" + android:layout_margin="8dp" + android:background="@drawable/bg_action_button_image" + android:gravity="center" + android:orientation="horizontal" + android:paddingStart="8dp" + android:paddingEnd="20dp"> + + <androidx.appcompat.widget.AppCompatImageView + style="@style/ItemIcon" + android:rotation="180" + android:tint="@android:color/white" + app:srcCompat="@drawable/ic_arrow_drop" /> + + <TextView + style="@style/ItemText" + android:text="@string/collapse_all" + android:textAllCaps="true" + android:textColor="@android:color/white" /> + + </LinearLayout> + + <LinearLayout + android:id="@+id/text_test" + android:layout_width="wrap_content" + android:layout_height="48dp" + android:layout_gravity="end" + android:layout_margin="8dp" + android:background="@drawable/bg_action_button_image" + android:gravity="center" + android:orientation="horizontal" + android:paddingStart="20dp" + android:paddingEnd="8dp"> + + <TextView + style="@style/ItemText" + android:text="@string/text_test" + android:textAllCaps="true" + android:textColor="@android:color/white" /> + + <androidx.appcompat.widget.AppCompatImageView + style="@style/ItemIcon" + app:srcCompat="@drawable/ic_arrow_forward" /> + + </LinearLayout> + </FrameLayout> +</FrameLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_text.xml b/app/src/main/res/layout/activity_text.xml new file mode 100644 index 0000000..1c39884 --- /dev/null +++ b/app/src/main/res/layout/activity_text.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:orientation="vertical" + tools:context=".ui.main.MainActivity"> + + <androidx.appcompat.widget.AppCompatTextView + android:id="@+id/text" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_margin="16dp" + android:layout_weight="1" /> + + <CheckBox + android:id="@+id/clearLinks" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_margin="16dp" + android:text="Clear links" /> +</LinearLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/item_video.xml b/app/src/main/res/layout/item_video.xml new file mode 100644 index 0000000..c94cafb --- /dev/null +++ b/app/src/main/res/layout/item_video.xml @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <LinearLayout + android:id="@+id/video_data_container" + android:layout_width="match_parent" + android:layout_height="48dp" + android:background="?selectableItemBackground" + android:gravity="center" + android:orientation="horizontal"> + + <androidx.appcompat.widget.AppCompatImageView + android:id="@+id/video_host_logo" + style="@style/ItemIcon" + app:srcCompat="@drawable/ic_video" /> + + <TextView + android:id="@+id/video_link" + style="@style/ItemText" + android:layout_weight="1" + tools:text="https://www.youtube.com/watch?v=M4BSGZ07NNA" /> + + <FrameLayout + android:layout_width="48dp" + android:layout_height="48dp"> + + <androidx.appcompat.widget.AppCompatImageView + android:id="@+id/icon_drop_down" + style="@style/ItemIcon" + android:layout_gravity="center" + app:srcCompat="@drawable/ic_arrow_drop" /> + + <ProgressBar + android:id="@+id/progress" + android:layout_width="34dp" + android:layout_height="34dp" + android:layout_gravity="center" /> + </FrameLayout> + + </LinearLayout> + + <FrameLayout + android:id="@+id/video_preview_container" + android:layout_width="match_parent" + android:layout_height="wrap_content" + tools:layout_height="175dp"> + + <androidx.appcompat.widget.AppCompatImageView + android:id="@+id/image_preview" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:adjustViewBounds="true" + android:background="#A6000000" /> + + <androidx.appcompat.widget.AppCompatImageView + android:id="@+id/image_play" + android:layout_width="50dp" + android:layout_height="50dp" + android:layout_gravity="center" + android:background="@drawable/bg_action_button_image" + android:padding="10dp" + app:srcCompat="@drawable/ic_play" /> + + <TextView + android:id="@+id/text_preview" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom" + android:background="#A6000000" + android:ellipsize="end" + android:gravity="start" + android:maxLines="2" + android:padding="8dp" + android:textColor="@android:color/white" + android:textSize="14sp" + android:textStyle="bold" + android:visibility="invisible" + tools:text="Title will be here." + tools:visibility="visible" /> + </FrameLayout> +</LinearLayout> \ No newline at end of file diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml new file mode 100644 index 0000000..5475d0d --- /dev/null +++ b/app/src/main/res/menu/menu_main.xml @@ -0,0 +1,10 @@ +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + tools:context="com.gapps.videonoapi.ui.main.MainActivity"> + <item + android:id="@+id/action_settings" + android:orderInCategory="100" + android:title="@string/action_settings" + app:showAsAction="never" /> +</menu> diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> + <background android:drawable="@drawable/ic_launcher_background" /> + <foreground android:drawable="@drawable/ic_launcher_foreground" /> +</adaptive-icon> \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> + <background android:drawable="@drawable/ic_launcher_background" /> + <foreground android:drawable="@drawable/ic_launcher_foreground" /> +</adaptive-icon> \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..898f3ed Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..dffca36 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..64ba76f Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..dae5e08 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..e5ed465 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..14ed0af Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..b0907ca Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..d8ae031 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..2c18de9 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..beed3cd Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..2726423 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="colorPrimary">#008577</color> + <color name="colorPrimaryDark">#00574B</color> + <color name="colorAccent">#D81B60</color> + <color name="colorBackground">#161627</color> + <color name="colorHostName">#AAAAE2</color> + <color name="colorVideoTitle">#ffffff</color> + +</resources> diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..59a0b0c --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,3 @@ +<resources> + <dimen name="fab_margin">16dp</dimen> +</resources> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..f436196 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,14 @@ +<resources> + <string name="app_name">Video No Api</string> + <string name="action_settings">Settings</string> + <!-- Strings used for fragments for navigation --> + <string name="hello_first_fragment">Hello first fragment</string> + <string name="hello_second_fragment">Hello second fragment</string> + <string name="next">Next</string> + <string name="previous">Previous</string> + <string name="first_fragment_label">First Fragment</string> + <string name="second_fragment_label">Second Fragment</string> + <string name="refresh">Refresh</string> + <string name="text_test">Text test</string> + <string name="collapse_all">Collapse all</string> +</resources> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..af06cef --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,47 @@ +<resources> + + <!-- Base application theme. --> + <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> + <!-- Customize your theme here. --> + <item name="colorPrimary">@color/colorPrimary</item> + <item name="colorPrimaryDark">@color/colorPrimaryDark</item> + <item name="colorAccent">@color/colorAccent</item> + </style> + + <style name="AppTheme.NoActionBar"> + <item name="windowActionBar">false</item> + <item name="windowNoTitle">true</item> + </style> + + <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> + + <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> + + <style name="Item"> + <item name="android:layout_width">match_parent</item> + <item name="android:layout_height">48dp</item> + <item name="android:gravity">center_vertical</item> + <item name="background">?selectableItemBackground</item> + <item name="android:orientation">horizontal</item> + <item name="android:paddingStart">10dp</item> + <item name="android:paddingEnd">10dp</item> + </style> + + <style name="ItemText"> + <item name="android:textSize">14sp</item> + <item name="android:textColor">#2F3C47</item> + <item name="android:layout_width">match_parent</item> + <item name="android:layout_height">wrap_content</item> + <item name="android:maxLines">1</item> + <item name="android:ellipsize">end</item> + <item name="android:gravity">center_vertical</item> + </style> + + <style name="ItemIcon"> + <item name="android:layout_width">24dp</item> + <item name="android:layout_height">24dp</item> + <item name="android:layout_marginStart">8dp</item> + <item name="android:layout_marginEnd">8dp</item> + </style> + +</resources> diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..dfbdc81 --- /dev/null +++ b/build.gradle @@ -0,0 +1,27 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + ext.kotlin_version = '1.5.20' + + repositories { + google() + mavenCentral() + } + dependencies { + classpath "com.android.tools.build:gradle:7.0.4" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + mavenCentral() + google() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/embedded_video_lib/build.gradle b/embedded_video_lib/build.gradle new file mode 100644 index 0000000..e63a75c --- /dev/null +++ b/embedded_video_lib/build.gradle @@ -0,0 +1,42 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' +android { + compileSdkVersion 31 + buildToolsVersion "30.0.3" + + defaultConfig { + minSdkVersion 19 + targetSdkVersion 31 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles 'consumer-rules.pro' + + vectorDrawables.useSupportLibrary = true + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + //AndroidX + api 'androidx.appcompat:appcompat:1.4.1' + api 'com.google.android.material:material:1.5.0' + api 'androidx.core:core-ktx:1.7.0' + + //Gson + api 'com.google.code.gson:gson:2.8.7' + //Coroutines + api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2' + + //OkHttp + api 'com.squareup.okhttp3:okhttp:4.9.3' +} diff --git a/embedded_video_lib/consumer-rules.pro b/embedded_video_lib/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/embedded_video_lib/proguard-rules.pro b/embedded_video_lib/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/embedded_video_lib/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/embedded_video_lib/src/androidTest/java/com/gapps/library/ExampleInstrumentedTest.kt b/embedded_video_lib/src/androidTest/java/com/gapps/library/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..382f319 --- /dev/null +++ b/embedded_video_lib/src/androidTest/java/com/gapps/library/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.gapps.library + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.gapps.library.test", appContext.packageName) + } +} diff --git a/embedded_video_lib/src/main/AndroidManifest.xml b/embedded_video_lib/src/main/AndroidManifest.xml new file mode 100644 index 0000000..dec512f --- /dev/null +++ b/embedded_video_lib/src/main/AndroidManifest.xml @@ -0,0 +1,9 @@ +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.gapps.library"> + + <uses-permission android:name="android.permission.INTERNET" /> + + <application android:allowBackup="true"> + + </application> +</manifest> diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/Const.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/Const.kt new file mode 100644 index 0000000..e797629 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/Const.kt @@ -0,0 +1,5 @@ +package com.gapps.library.api + +const val FORMAT = "format" +const val FORMAT_JSON = "json" +const val URL = "url" diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/VideoLoadHelper.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/VideoLoadHelper.kt new file mode 100644 index 0000000..a62fcd8 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/VideoLoadHelper.kt @@ -0,0 +1,142 @@ +package com.gapps.library.api + +import android.content.Context +import android.util.Log +import com.gapps.library.api.models.api.builder.EmbeddingRequest +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.gapps.library.cache.getCachedVideoModel +import com.gapps.library.cache.insertModel +import com.gapps.library.utils.errors.ERROR_1 +import com.gapps.library.utils.errors.ERROR_2 +import com.gapps.library.utils.errors.ERROR_3 +import com.google.gson.GsonBuilder +import com.google.gson.JsonElement +import com.google.gson.JsonParser.parseString +import kotlinx.coroutines.* +import okhttp3.OkHttpClient +import okhttp3.Request +import java.lang.reflect.Type +import kotlin.coroutines.CoroutineContext + +internal class VideoLoadHelper( + private val context: Context?, + private val client: OkHttpClient, + private val isCacheEnabled: Boolean, + private val isLogEnabled: Boolean +) : CoroutineScope { + + override val coroutineContext: CoroutineContext + get() = SupervisorJob() + Dispatchers.Main + + private val gson = GsonBuilder() + .setLenient() + .setPrettyPrinting() + .create() + + fun getVideoInfo( + requestModel: EmbeddingRequest, + onSuccess: (resultModel: VideoPreviewModel) -> Unit, + onError: (url: String, message: String) -> Unit, + ) { + val videoInfoModel = requestModel.videoInfoModel + val originalUrl = requestModel.originalUrl + val headers = requestModel.requestHeaders + + if (videoInfoModel == null) { + onError(originalUrl, ERROR_1) + + return + } + + val finalUrl = videoInfoModel.getInfoUrl(originalUrl) + val videoId = videoInfoModel.parseVideoId(originalUrl) + + if (finalUrl == null || videoId == null) { + onError(originalUrl, ERROR_3) + + return + } + + val playLink = videoInfoModel.getPlayLink(videoId) + + launch { + try { + if (isCacheEnabled) { + if (context != null) { + val model = getCachedVideoModel(context, playLink) + + if (model != null) { + onSuccess(model) + return@launch + } + } + } + + val jsonBody = withContext(Dispatchers.IO) { + makeCallGetBody(client, finalUrl, headers) + } + + if (isLogEnabled) { + Log.i( + VideoService.TAG, + "a response from $originalUrl:\n${gson.toJson(jsonBody)}" + ) + } + + if (jsonBody == null) { + onError(originalUrl, "$ERROR_2 \n---> Response is null") + + return@launch + } + + val result = fromJson(jsonBody, videoInfoModel.type) + .toPreview( + url = originalUrl, + linkToPlay = playLink, + hostingName = videoInfoModel.hostingName, + videoId = videoId + ) + + onSuccess(result) + + try { + if (context != null && isCacheEnabled) { + insertModel(context, result) + } + } catch (e: Exception) { + onError(originalUrl, "$ERROR_2\n---> ${e.localizedMessage}") + } + } catch (e: Exception) { + onError(originalUrl, ERROR_3) + } + } + } + + private fun makeCallGetBody( + client: OkHttpClient, + url: String, + headers: Map<String, String> + ): JsonElement? = + runBlocking { + val requestBuilder = Request.Builder().url(url) + + headers.entries.forEach { header -> + requestBuilder.addHeader(header.key, header.value) + } + + val response = client.newCall(requestBuilder.build()).execute() + val stringBody = response.body?.string() ?: return@runBlocking null + val jsonObject = parseString(stringBody) + + return@runBlocking if (jsonObject.isJsonArray) { + jsonObject.asJsonArray[0] + } else { + jsonObject + } + } + + private fun fromJson(json: JsonElement?, type: Type?): BaseVideoResponse { + return gson.fromJson(json, type) + } +} diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/VideoService.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/VideoService.kt new file mode 100644 index 0000000..37539ba --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/VideoService.kt @@ -0,0 +1,168 @@ +package com.gapps.library.api + +import android.content.Context +import android.util.Log +import com.gapps.library.api.models.api.* +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.api.builder.EmbeddingRequest +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.gapps.library.utils.errors.EmbeddingError +import kotlinx.coroutines.suspendCancellableCoroutine +import okhttp3.OkHttpClient +import kotlin.coroutines.resumeWithException + + +class VideoService private constructor( + context: Context?, + client: OkHttpClient, + isCacheEnabled: Boolean, + private val isLogEnabled: Boolean, + private val customModels: List<VideoInfoModel<out BaseVideoResponse>> +) { + companion object { + const val TAG = "VideoService" + + val videoInfoModelsList = mutableListOf( + LoomVideoInfoModel(), + CoubVideoInfoModel(), + DailymotionVideoInfoModel(), + FacebookVideoInfoModel(), + HuluVideoInfoModel(), + RutubeVideoInfoModel(), + TedTalksVideoInfoModel(), + UstreamVideoInfoModel(), + VimeoVideoInfoModel(), + VzaarVideoInfoModel(), + WistiaVideoInfoModel(), + YoutubeMusicVideoInfoModel(), + YoutubeVideoInfoModel(), + UltimediaVideoInfoModel(), + StreamableVideoInfoModel() + ) + + val videoPatterns + get() = videoInfoModelsList.map { it.pattern } + + inline fun build(block: Builder.() -> Unit) = Builder().apply(block).build() + } + + constructor(builder: Builder) : this( + context = builder.context, + client = builder.okHttpClient, + isCacheEnabled = builder.isCacheEnabled, + isLogEnabled = builder.isLogEnabled, + customModels = builder.customModels + ) { + customModels.forEach { custom -> + videoInfoModelsList.removeAll { it.hostingName == custom.hostingName } + } + + videoInfoModelsList.addAll(customModels) + } + + private val videoHelper = createVideoLoadHelper( + context = context, + client = client, + isCacheEnabled = isCacheEnabled + ) + + fun loadVideoPreview( + url: String, + onSuccess: (resultModel: VideoPreviewModel) -> Unit, + onError: ((url: String, message: String) -> Unit)? = null + ) { + val request = EmbeddingRequest.Builder() + .setUrl(url) + .build() + + loadVideoPreview(request, onSuccess, onError) + } + + fun loadVideoPreview( + request: EmbeddingRequest, + onSuccess: (resultModel: VideoPreviewModel) -> Unit, + onError: ((url: String, message: String) -> Unit)? = null + ) { + if (isLogEnabled) { + Log.i(TAG, "Loading url: ${request.originalUrl}") + } + + val callback: (resultModel: VideoPreviewModel) -> Unit = { model: VideoPreviewModel -> + onSuccess.invoke(model) + } + + val callbackError: (url: String, message: String) -> Unit = + { url: String, errorMessage: String -> + onError?.run { invoke(url, errorMessage) } + } + + if (request.videoInfoModel == null) { + request.videoInfoModel = + videoInfoModelsList.firstOrNull { it.checkHostAffiliation(request.originalUrl) } + } + + videoHelper.getVideoInfo( + requestModel = request, + onSuccess = callback, + onError = callbackError + ) + } + + suspend fun loadVideoAsync(url: String): VideoPreviewModel { + val request = EmbeddingRequest.Builder() + .setUrl(url) + .build() + + return loadVideoAsync(request) + } + + suspend fun loadVideoAsync(request: EmbeddingRequest) = + suspendCancellableCoroutine<VideoPreviewModel> { continuation -> + loadVideoPreview(request, { videoPreviewModel -> + continuation.resumeWith(Result.success(videoPreviewModel)) + }, { url: String, errorMessage: String -> + continuation.resumeWithException(EmbeddingError(url, errorMessage)) + }) + } + + private fun createVideoLoadHelper( + context: Context?, + client: OkHttpClient, + isCacheEnabled: Boolean + ) = VideoLoadHelper( + context = context, + client = client, + isCacheEnabled = isCacheEnabled, + isLogEnabled = isLogEnabled + ) + + class Builder { + var okHttpClient: OkHttpClient = OkHttpClient() + private set + + var isLogEnabled = false + private set + + var isCacheEnabled = false + private set + + var context: Context? = null + private set + + val customModels: MutableList<VideoInfoModel<out BaseVideoResponse>> = mutableListOf() + + fun with(context: Context) = apply { this.context = context } + + fun httpClient(client: OkHttpClient) = apply { okHttpClient = client } + + fun enableLog(isEnabled: Boolean) = apply { isLogEnabled = isEnabled } + + fun enableCache(isEnabled: Boolean) = apply { isCacheEnabled = isEnabled } + + fun <T : VideoInfoModel<out BaseVideoResponse>> withCustomVideoInfoModels(vararg models: T) = + apply { this.customModels.addAll(models) } + + fun build() = VideoService(this) + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/CoubVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/CoubVideoInfoModel.kt new file mode 100644 index 0000000..10b60d1 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/CoubVideoInfoModel.kt @@ -0,0 +1,34 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.coub.CoubResponse + +open class CoubVideoInfoModel : VideoInfoModel<CoubResponse>() { + override val baseUrl: String + get() = "http://coub.com" + + //https://regex101.com/r/ZoQVLa/1 + override val pattern: String + get() = COUB_PATTERN + + override val idPattern: String + get() = pattern + + override val type: Class<CoubResponse> + get() = CoubResponse::class.java + + override val hostingName: String + get() = COUB_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + incomingUrl ?: return null + + return "$baseUrl/api/oembed.$FORMAT_JSON?$URL=$incomingUrl" + } + + override fun getPlayLink(videoId: String): String { + return "https://coub.com/embed/${videoId}" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/DailymotionVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/DailymotionVideoInfoModel.kt new file mode 100644 index 0000000..1785c64 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/DailymotionVideoInfoModel.kt @@ -0,0 +1,31 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.dailymotion.DailymotionResponse + +open class DailymotionVideoInfoModel : VideoInfoModel<DailymotionResponse>() { + override val baseUrl: String + get() = "https://www.dailymotion.com" + + override val pattern: String + get() = DAILYMOTION_PATTERN + override val idPattern: String + get() = pattern + + override val type: Class<DailymotionResponse> = DailymotionResponse::class.java + + override val hostingName: String + get() = DAILYMOTION_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + incomingUrl ?: return null + + val id = parseVideoId(incomingUrl) + return "$baseUrl/services/oembed/?$URL=https://www.dailymotion.com/video/$id" + } + + override fun getPlayLink(videoId: String): String { + return "https://www.dailymotion.com/embed/video/${videoId}" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/FacebookVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/FacebookVideoInfoModel.kt new file mode 100644 index 0000000..5650da2 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/FacebookVideoInfoModel.kt @@ -0,0 +1,29 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.facebook.FacebookResponse + +open class FacebookVideoInfoModel : VideoInfoModel<FacebookResponse>() { + override val baseUrl: String + get() = "https://graph.facebook.com/v15.0/" + + //Pattern: https://regex101.com/r/98Nfkr/6 + override val pattern: String + get() = FACEBOOK_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<FacebookResponse> + get() = FacebookResponse::class.java + override val hostingName: String + get() = FACEBOOK_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + val id = parseVideoId(incomingUrl) + return "$baseUrl/oembed_page?$URL=https://www.facebook.com/facebook/videos/$id" + } + + override fun getPlayLink(videoId: String): String { + return "https://www.facebook.com/video/embed?video_id=${videoId}" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HostConstants.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HostConstants.kt new file mode 100644 index 0000000..668a320 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HostConstants.kt @@ -0,0 +1,19 @@ +@file:JvmName("HostConstants") +package com.gapps.library.api.models.api + +const val COUB_HOST_NAME ="Coub" +const val DAILYMOTION_HOST_NAME = "Dailymotion" +const val FACEBOOK_HOST_NAME ="Facebook" +const val HULU_HOST_NAME = "Hulu" +const val LOOM_HOST_NAME = "Loom" +const val RUTUBE_HOST_NAME = "Rutube" +const val STREAMABLE_HOST_NAME = "Streamable" +const val TED_TALKS_HOST_NAME = "Ted Talks" +const val TIKTOK_HOST_NAME = "TikTok" +const val ULTIMEDIA_HOST_NAME = "Ultimedia" +const val USTREAM_HOST_NAME = "Ustream" +const val VIMEO_HOST_NAME = "Vimeo" +const val VZAAR_HOST_NAME = "Vzaar" +const val WISTIA_HOST_NAME = "Wistia" +const val YOUTUBE_MUSIC_HOST_NAME = "Youtube Music" +const val YOUTUBE_HOST_NAME = "YouTube" \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HuluVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HuluVideoInfoModel.kt new file mode 100644 index 0000000..540f296 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HuluVideoInfoModel.kt @@ -0,0 +1,31 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.FORMAT +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.hulu.HuluResponse + +open class HuluVideoInfoModel : VideoInfoModel<HuluResponse>() { + override val baseUrl: String + get() = "https://www.hulu.com" + + //https://regex101.com/r/LORZgZ/2 + override val pattern: String + get() = HULU_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<HuluResponse> + get() = HuluResponse::class.java + override val hostingName: String + get() = HULU_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + val id = parseVideoId(incomingUrl) + return "$baseUrl/api/oembed.$FORMAT=$FORMAT_JSON&$URL=http://www.hulu.com/watch/$id" + } + + override fun getPlayLink(videoId: String): String { + return "www.hulu.com/embed.html?eid=$videoId" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/LoomVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/LoomVideoInfoModel.kt new file mode 100644 index 0000000..1606cec --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/LoomVideoInfoModel.kt @@ -0,0 +1,31 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.FORMAT +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.loom.LoomResponse +import com.gapps.library.api.models.video.ultimedia.UltimediaResponse + +open class LoomVideoInfoModel : VideoInfoModel<LoomResponse>() { + override val baseUrl: String + get() = "https://www.loom.com" + + //https://regex101.com/r/0TwCJy/1 + override val pattern: String + get() = LOOM_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<LoomResponse> + get() = LoomResponse::class.java + override val hostingName: String + get() = LOOM_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + return "$baseUrl/v1/oembed?$FORMAT=$FORMAT_JSON&$URL=$incomingUrl" + } + + override fun getPlayLink(videoId: String): String { + return "https://www.loom.com/embed/$videoId/" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RegexCollection.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RegexCollection.kt new file mode 100644 index 0000000..5b66ef4 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RegexCollection.kt @@ -0,0 +1,18 @@ +package com.gapps.library.api.models.api + +const val COUB_PATTERN = "(?:http[s]?:\\/\\/)?(?:www)?\\.?coub\\.com\\/(?:embed|view|api)\\/([_a-zA-Z0-9]+)[^,;\\s]*" +const val DAILYMOTION_PATTERN = "(?:http[s]?://)?(?:www\\.)?(?:(?:dailymotion\\.com(?:/embed)?/video)|dai\\.ly)/([a-zA-Z0-9]+)[^,;\\s]*" +const val FACEBOOK_PATTERN = "(?:http[s]?:\\/\\/)?(?:www.|web.|m.)?(?:facebook|fb)?.com\\/(?:(?:video.php|watch)?\\?v=|.+\\/videos(?:\\/.+)?\\/)(\\d+)(?:\\S+)?" +const val HULU_PATTERN = "(?:http[s]?:\\/\\/)?(?:www.)?hulu\\.(?:(?:com\\/\\S*(?:w(?:atch)?|eid)(?:\\/|=)?)|(?:tv\\/))?([a-zA-Z0-9]+)[^,;\\s]*" +const val LOOM_PATTERN = "(?:http[s]?:\\/\\/)?(?:www)?\\.?(?:use)?loom\\.com\\/(?:share|default|api)\\/([_a-zA-Z0-9]+)\\S*" +const val RUTUBE_PATTERN = "(?:http[s]?://)(?:w{3})?(?:player\\.)?rutube\\.ru/video/(?:embed/)?([A-Za-z0-9]+)[^,\\s]*" +const val STREAMABLE_PATTERN = "(?:http[s]?:\\/\\/)?(?:www)?\\.?streamable\\.com\\/([_a-zA-Z0-9]+)\\S*" +const val TED_TALKS_PATTERN = "(?:http[s]?:\\/\\/)?(?:www|embed)?\\.?ted\\.com\\/talks\\/([_a-zA-Z0-9]+)[^,;\\s]*" +const val TIKTOK_PATTERN = "(?:http[s]?:\\/\\/)(?:www.)?(?:m.)?youtu(?:be|.be)?(?:\\.com)?(?:(?:\\w*.?:\\/\\/)?\\w*.?\\w*-?.?\\w*\\/(?:embed|e|v|watch|.*\\/)?\\??(?:feature=\\w*\\.?\\w*)?&?(?:v=)?\\/?)([\\w\\d_-]{11})[^,;\\s]*" +const val ULTIMEDIA_PATTERN = "(?:http[s]?:\\/\\/)?(?:www)?\\.?ultimedia\\.com\\/(?:deliver|default|api)\\/.*\\/([_a-zA-Z0-9]+)\\S*" +const val USTREAM_PATTERN = "(?:http[s]?:\\/\\/)?(?:www\\.)?ustream.(?:com|tv)\\/(?:recorded|embed|channel)\\/?(?:([0-9]+)|(\\S+))[^,;\\s]*" +const val VIMEO_PATTERN = "(?:http[s]?://)(?:w{3})?(?:player\\.)?vimeo\\.com/(?:[a-z]*/)*([0-9]{6,11})[^,;\\s]*" +const val VZAAR_PATTERN = "(?:http[s]?://)?(?:.+)?vzaar.com/?(?:videos/)?([0-9]+)[^,;\\s]*" +const val WISTIA_PATTERN = "(?:http[s]?:\\/\\/)?(?:.+)?(?:wistia\\.(?:com|net)|wi\\.st)\\/(?:medias|embed|series)\\/(?:iframe\\/?)?(?:\\S+\\?\\S*wvideoid=)?([a-zA-Z0-9]+)[^,;\\s]*" +const val YOUTUBE_MUSIC_PATTERN = "(?:http[s]?:\\/\\/)(?:www.)?(?:m.)?music.youtu(?:be|.be)?(?:\\.com)?(?:(?:\\w*.?:\\/\\/)?\\w*.?\\w*-?.?\\w*\\/(?:embed|e|v|watch|.*\\/)?\\??(?:feature=\\w*\\.?\\w*)?&?(?:v=)?\\/?)([\\w\\d_-]{11})[^,;\\s]*" +const val YOUTUBE_PATTERN = "(?:http[s]?:\\/\\/)(?:www.)?(?:m.)?youtu(?:be|.be)?(?:\\.com)?(?:(?:\\w*.?:\\/\\/)?\\w*.?\\w*-?.?\\w*\\/(?:embed|e|v|watch|.*\\/)?\\??(?:feature=\\w*\\.?\\w*)?&?(?:v=)?\\/?)([\\w\\d_-]{11})[^,;\\s]*" \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RutubeVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RutubeVideoInfoModel.kt new file mode 100644 index 0000000..5a53bc5 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RutubeVideoInfoModel.kt @@ -0,0 +1,34 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.FORMAT +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.rutube.RutubeResponse + +open class RutubeVideoInfoModel : VideoInfoModel<RutubeResponse>() { + override val baseUrl: String + get() = "http://rutube.ru" + override val pattern: String + get() = RUTUBE_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<RutubeResponse> + get() = RutubeResponse::class.java + override val hostingName: String + get() = RUTUBE_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + val id = parseVideoId(incomingUrl) ?: return null + + return if (id.length < 32) { + "$baseUrl/api/oembed?$FORMAT=$FORMAT_JSON&$URL=$id" + } else { + "$baseUrl/api/video/$id/" + } + } + + override fun getPlayLink(videoId: String): String { + return "http://rutube.ru/play/embed/${videoId}" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/StreamableVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/StreamableVideoInfoModel.kt new file mode 100644 index 0000000..87adf8b --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/StreamableVideoInfoModel.kt @@ -0,0 +1,26 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.streamable.StreamableResponse + +class StreamableVideoInfoModel : VideoInfoModel<StreamableResponse>() { + override val baseUrl: String + get() = "https://api.streamable.com" + override val pattern: String + get() = STREAMABLE_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<StreamableResponse> + get() = StreamableResponse::class.java + override val hostingName: String + get() = STREAMABLE_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + return "$baseUrl/oembed.json?$URL=$incomingUrl" + } + + override fun getPlayLink(videoId: String): String { + return "https://streamable.com/o/$videoId" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TedTalksVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TedTalksVideoInfoModel.kt new file mode 100644 index 0000000..f670dfe --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TedTalksVideoInfoModel.kt @@ -0,0 +1,27 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.ted.TedTalksResponse + +open class TedTalksVideoInfoModel : VideoInfoModel<TedTalksResponse>() { + override val baseUrl: String + get() = "https://www.ted.com" + override val pattern: String + get() = TED_TALKS_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<TedTalksResponse> + get() = TedTalksResponse::class.java + override val hostingName: String + get() = TED_TALKS_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + return "$baseUrl/services/v1/oembed.$FORMAT_JSON?$URL=$incomingUrl" + } + + override fun getPlayLink(videoId: String): String { + return "https://embed.ted.com/talks/$videoId" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TikTokVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TikTokVideoInfoModel.kt new file mode 100644 index 0000000..ccc0a25 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TikTokVideoInfoModel.kt @@ -0,0 +1,33 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.FORMAT +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.tiktok.TikTokResponse +import com.gapps.library.api.models.video.youtube.YoutubeResponse + +open class TikTokVideoInfoModel : VideoInfoModel<TikTokResponse>() { + override val baseUrl: String + get() = "https://www.tiktok.com" + + //https://regex101.com/r/nJzgG0/1 + override val pattern: String + get() = TIKTOK_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<TikTokResponse> + get() = TikTokResponse::class.java + override val hostingName: String + get() = TIKTOK_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + val id = parseVideoId(incomingUrl) + + return "$baseUrl/oembed?$FORMAT=$FORMAT_JSON&$URL=https://www.youtube.com/watch?v=$id" + } + + override fun getPlayLink(videoId: String): String { + return "https://www.youtube.com/embed/${videoId}?autoplay=1&vq=small" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UltimediaVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UltimediaVideoInfoModel.kt new file mode 100644 index 0000000..2c52406 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UltimediaVideoInfoModel.kt @@ -0,0 +1,30 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.FORMAT +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.ultimedia.UltimediaResponse + +class UltimediaVideoInfoModel : VideoInfoModel<UltimediaResponse>() { + override val baseUrl: String + get() = "https://www.ultimedia.com" + + //https://regex101.com/r/2AsrOc/1 + override val pattern: String + get() = ULTIMEDIA_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<UltimediaResponse> + get() = UltimediaResponse::class.java + override val hostingName: String + get() = ULTIMEDIA_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + return "$baseUrl/api/search/oembed?$FORMAT=$FORMAT_JSON&$URL=$incomingUrl" + } + + override fun getPlayLink(videoId: String): String { + return "https://www.ultimedia.com/deliver/generic/iframe/src/$videoId/" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UstreamVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UstreamVideoInfoModel.kt new file mode 100644 index 0000000..79b41fa --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UstreamVideoInfoModel.kt @@ -0,0 +1,40 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.ustream.UstreamResponse +import com.gapps.library.utils.getGroupValue + +open class UstreamVideoInfoModel : VideoInfoModel<UstreamResponse>() { + override val baseUrl: String + get() = "https://video.ibm.com" + + //https://regex101.com/r/E0PMAV/2 + override val pattern: String + get() = USTREAM_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<UstreamResponse> + get() = UstreamResponse::class.java + override val hostingName: String + get() = USTREAM_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + incomingUrl ?: return null + + val id = parseVideoId(incomingUrl) + val channelId = pattern.getGroupValue(incomingUrl, 2) + + val url = if (id == null || incomingUrl.contains("channel")) { + "https://ustream.tv/channel/${channelId ?: id}" + } else { + "https://ustream.tv/recorded/$id" + } + + return "$baseUrl/oembed?$URL=$url" + } + + override fun getPlayLink(videoId: String): String { + return "http://www.ustream.tv/embed/$videoId" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VimeoVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VimeoVideoInfoModel.kt new file mode 100644 index 0000000..b22e1a8 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VimeoVideoInfoModel.kt @@ -0,0 +1,28 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.vimeo.VimeoResponse + +open class VimeoVideoInfoModel : VideoInfoModel<VimeoResponse>() { + override val baseUrl: String + get() = "http://vimeo.com" + override val pattern: String + get() = VIMEO_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<VimeoResponse> + get() = VimeoResponse::class.java + override val hostingName: String + get() = VIMEO_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + val id = parseVideoId(incomingUrl) ?: return null + + return "$baseUrl/api/v2/video/$id.$FORMAT_JSON" + } + + override fun getPlayLink(videoId: String): String { + return "https://player.vimeo.com/video/${videoId}" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VzaarVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VzaarVideoInfoModel.kt new file mode 100644 index 0000000..80e1781 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VzaarVideoInfoModel.kt @@ -0,0 +1,28 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.vzaar.VzaarResponse + +open class VzaarVideoInfoModel : VideoInfoModel<VzaarResponse>() { + override val baseUrl: String + get() = "https://app.vzaar.com" + override val pattern: String + get() = VZAAR_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<VzaarResponse> + get() = VzaarResponse::class.java + override val hostingName: String + get() = VZAAR_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + val id = parseVideoId(incomingUrl) ?: return null + + return "$baseUrl/videos/$id.$FORMAT_JSON" + } + + override fun getPlayLink(videoId: String): String { + return "https://view.vzaar.com/${videoId}/player" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/WistiaVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/WistiaVideoInfoModel.kt new file mode 100644 index 0000000..70eb912 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/WistiaVideoInfoModel.kt @@ -0,0 +1,28 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.wistia.WistiaResponse + +open class WistiaVideoInfoModel : VideoInfoModel<WistiaResponse>() { + override val baseUrl: String + get() = "https://fast.wistia.net" + override val pattern: String + get() = WISTIA_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<WistiaResponse> + get() = WistiaResponse::class.java + override val hostingName: String + get() = WISTIA_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + incomingUrl ?: return null + + return "$baseUrl/oembed?$URL=$incomingUrl" + } + + override fun getPlayLink(videoId: String): String { + return "http://fast.wistia.com/embed/iframe/${videoId}" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeMusicVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeMusicVideoInfoModel.kt new file mode 100644 index 0000000..a84f484 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeMusicVideoInfoModel.kt @@ -0,0 +1,30 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.FORMAT +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.youtube.YoutubeResponse + +open class YoutubeMusicVideoInfoModel : VideoInfoModel<YoutubeResponse>() { + override val baseUrl: String + get() = "https://www.youtube.com" + override val pattern: String + get() = YOUTUBE_MUSIC_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<YoutubeResponse> + get() = YoutubeResponse::class.java + override val hostingName: String + get() = YOUTUBE_MUSIC_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + val id = parseVideoId(incomingUrl) + + return "$baseUrl/oembed?$FORMAT=$FORMAT_JSON&$URL=https://www.youtube.com/watch?v=$id" + } + + override fun getPlayLink(videoId: String): String { + return "https://www.youtube.com/embed/${videoId}?autoplay=1&vq=small" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeVideoInfoModel.kt new file mode 100644 index 0000000..924e5e6 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeVideoInfoModel.kt @@ -0,0 +1,32 @@ +package com.gapps.library.api.models.api + +import com.gapps.library.api.FORMAT +import com.gapps.library.api.FORMAT_JSON +import com.gapps.library.api.URL +import com.gapps.library.api.models.api.base.VideoInfoModel +import com.gapps.library.api.models.video.youtube.YoutubeResponse + +open class YoutubeVideoInfoModel : VideoInfoModel<YoutubeResponse>() { + override val baseUrl: String + get() = "https://www.youtube.com" + + //https://regex101.com/r/nJzgG0/1 + override val pattern: String + get() = YOUTUBE_PATTERN + override val idPattern: String + get() = pattern + override val type: Class<YoutubeResponse> + get() = YoutubeResponse::class.java + override val hostingName: String + get() = YOUTUBE_HOST_NAME + + override fun getInfoUrl(incomingUrl: String?): String? { + val id = parseVideoId(incomingUrl) + + return "$baseUrl/oembed?$FORMAT=$FORMAT_JSON&$URL=https://www.youtube.com/watch?v=$id" + } + + override fun getPlayLink(videoId: String): String { + return "https://www.youtube.com/embed/${videoId}?autoplay=1&vq=small" + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/base/VideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/base/VideoInfoModel.kt new file mode 100644 index 0000000..24c9230 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/base/VideoInfoModel.kt @@ -0,0 +1,28 @@ +package com.gapps.library.api.models.api.base + +import com.gapps.library.utils.getGroupValue + +abstract class VideoInfoModel<T> { + abstract val baseUrl: String + abstract val pattern: String + abstract val idPattern: String + abstract val type: Class<T> + + abstract val hostingName: String + + open fun parseVideoId(url: String?): String? { + url ?: return null + + return idPattern.getGroupValue(url, 1) + } + + open fun checkHostAffiliation(url: String?): Boolean { + url ?: return false + + return url.matches(pattern.toRegex()) + } + + abstract fun getInfoUrl(incomingUrl: String?): String? + + abstract fun getPlayLink(videoId: String): String +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/builder/EmbeddingRequestBuilder.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/builder/EmbeddingRequestBuilder.kt new file mode 100644 index 0000000..fccb3a1 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/builder/EmbeddingRequestBuilder.kt @@ -0,0 +1,103 @@ +package com.gapps.library.api.models.api.builder + +import com.gapps.library.api.models.api.base.VideoInfoModel + +class EmbeddingRequest private constructor( + var originalUrl: String = "", + var videoInfoModel: VideoInfoModel<*>? = null, + private var headers: Headers = emptyMap() +) { + companion object { + inline fun build(block: Builder.() -> Unit) = + Builder().apply(block).build() + } + + val requestHeaders: Map<String, String> + get() { + val headersMap = mutableMapOf<String, String>() + + val hostName = videoInfoModel?.hostingName + + hostName?.let { headers[it] }?.run { + headersMap.putAll(this) + } + + headers[Builder.HostBuilder.DEFAULT]?.run { + headersMap.putAll(this) + } + + return headersMap + } + + @EmbeddingRequestBuilderDsl + class Builder { + private val request: EmbeddingRequest = EmbeddingRequest() + private val hostBuilder = HostBuilder() + + fun setUrl(url: String) = apply { request.originalUrl = url } + + fun setVideoInfoModel(videoInfoModel: VideoInfoModel<*>) = + apply { request.videoInfoModel = videoInfoModel } + + fun headers(headersBuilder: HostBuilder.() -> Unit) = apply { + this.hostBuilder.apply(headersBuilder) + } + + fun build(): EmbeddingRequest { + return request.apply { + headers = hostBuilder.headers + } + } + + @HostBuilderDsl + @EmbeddingRequestBuilderDsl + class HostBuilder { + companion object { + const val DEFAULT = "default" + } + + private val builders = mutableMapOf<String, HeadersBuilder>() + + val headers: Headers + get() = builders.map { it.key to it.value.headers }.toMap() + + fun host(hostName: String, builder: HeadersBuilder.() -> Unit) = apply { + val builderForHost = getHeadersBuilder(hostName) + + builderForHost.apply(builder) + } + + fun add(key: String, value: String) = apply { + getHeadersBuilder(DEFAULT).add(key, value) + } + + fun addAll(headers: Map<String, String>) = apply { + getHeadersBuilder(DEFAULT).addAll(headers) + } + + private fun getHeadersBuilder(hostName: String) = + builders[hostName] ?: HeadersBuilder() + } + + @HostBuilderDsl + class HeadersBuilder { + val headers = mutableMapOf<String, String>() + + fun add(key: String, value: String) = apply { + this.headers[key] = value + } + + fun addAll(headers: Map<String, String>) = apply { + this.headers.putAll(headers) + } + } + } +} + +typealias Headers = Map<String, Map<String, String>> + +@DslMarker +annotation class HostBuilderDsl + +@DslMarker +annotation class EmbeddingRequestBuilderDsl diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/VideoPreviewModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/VideoPreviewModel.kt new file mode 100644 index 0000000..5a39d15 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/VideoPreviewModel.kt @@ -0,0 +1,45 @@ +package com.gapps.library.api.models.video + +class VideoPreviewModel private constructor() { + var url: String? = null + var videoTitle: String? = null + var thumbnailUrl: String? = null + var videoHosting: String? = null + var videoId: String? = null + var linkToPlay: String? = null + var width = 0 + var height = 0 + var errorMessage: String? = null + + constructor(url: String?, linkToPlay: String, hostingName: String, videoId: String) : this() { + this.url = url + this.videoHosting = hostingName + this.videoId = videoId + this.linkToPlay = linkToPlay + } + + class Builder(private val model: VideoPreviewModel = VideoPreviewModel()) { + + fun setUrl(url: String) = apply { model.url = url } + fun setVideoTitle(videoTitle: String) = apply { model.videoTitle = videoTitle } + fun setThumbnailUrl(thumbnailUrl: String) = apply { model.thumbnailUrl = thumbnailUrl } + fun setVideoHosting(videoHosting: String) = apply { model.videoHosting = videoHosting } + fun setVideoId(videoId: String) = apply { model.videoId = videoId } + fun setLinkToPlay(linkToPlay: String) = apply { model.linkToPlay = linkToPlay } + fun setWidth(width: Int) = apply { model.width = width } + fun setHeight(height: Int) = apply { model.height = height } + fun setErrorMessage(errorMessage: String) = apply { model.errorMessage = errorMessage } + + fun build(): VideoPreviewModel { + return model + } + } + + companion object { + private const val ERROR_404 = "Not found" + + fun error() = VideoPreviewModel().apply { + this.videoTitle = ERROR_404 + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/base/BaseVideoResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/base/BaseVideoResponse.kt new file mode 100644 index 0000000..a75c806 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/base/BaseVideoResponse.kt @@ -0,0 +1,12 @@ +package com.gapps.library.api.models.video.base + +import com.gapps.library.api.models.video.VideoPreviewModel + +interface BaseVideoResponse { + fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/coub/CoubResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/coub/CoubResponse.kt new file mode 100644 index 0000000..7b0dca3 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/coub/CoubResponse.kt @@ -0,0 +1,51 @@ +package com.gapps.library.api.models.video.coub + + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class CoubResponse( + @SerializedName("type") + val type: String = "", + @SerializedName("version") + val version: String = "", + @SerializedName("width") + val width: String = "", + @SerializedName("height") + val height: String = "", + @SerializedName("title") + val title: String = "", + @SerializedName("url") + val url: String = "", + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("thumbnail_width") + val thumbnailWidth: String = "", + @SerializedName("thumbnail_height") + val thumbnailHeight: String = "", + @SerializedName("author_name") + val authorName: String = "", + @SerializedName("channel_url") + val channelUrl: String = "", + @SerializedName("provider_name") + val providerName: String = "", + @SerializedName("provider_url") + val providerUrl: String = "", + @SerializedName("html") + val html: String = "" +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@CoubResponse.thumbnailUrl + this.videoTitle = this@CoubResponse.title + this.width = this@CoubResponse.width.toInt() + this.height = this@CoubResponse.height.toInt() + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/dailymotion/DailymotionResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/dailymotion/DailymotionResponse.kt new file mode 100644 index 0000000..11a9347 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/dailymotion/DailymotionResponse.kt @@ -0,0 +1,51 @@ +package com.gapps.library.api.models.video.dailymotion + + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class DailymotionResponse( + @SerializedName("type") + val type: String = "", + @SerializedName("version") + val version: String = "", + @SerializedName("provider_name") + val providerName: String = "", + @SerializedName("provider_url") + val providerUrl: String = "", + @SerializedName("title") + val title: String = "", + @SerializedName("description") + val description: String = "", + @SerializedName("author_name") + val authorName: String = "", + @SerializedName("author_url") + val authorUrl: String = "", + @SerializedName("width") + val width: Int = 0, + @SerializedName("height") + val height: Int = 0, + @SerializedName("html") + val html: String = "", + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("thumbnail_width") + val thumbnailWidth: Int = 0, + @SerializedName("thumbnail_height") + val thumbnailHeight: Int = 0 +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@DailymotionResponse.thumbnailUrl + this.videoTitle = this@DailymotionResponse.title + this.width = this@DailymotionResponse.width + this.height = this@DailymotionResponse.height + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/facebook/FacebookResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/facebook/FacebookResponse.kt new file mode 100644 index 0000000..b125594 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/facebook/FacebookResponse.kt @@ -0,0 +1,45 @@ +package com.gapps.library.api.models.video.facebook + + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class FacebookResponse( + @SerializedName("author_name") + val authorName: String = "", + @SerializedName("author_url") + val authorUrl: String = "", + @SerializedName("provider_url") + val providerUrl: String = "", + @SerializedName("provider_name") + val providerName: String = "", + @SerializedName("success") + val success: Boolean = false, + @SerializedName("height") + val height: Int? = 0, + @SerializedName("html") + val html: String = "", + @SerializedName("type") + val type: String = "", + @SerializedName("version") + val version: String = "", + @SerializedName("url") + val url: String = "", + @SerializedName("width") + val width: Int? = 0 +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = "https://graph.facebook.com/${videoId}/thumbnails" + this.videoTitle = this@FacebookResponse.authorName + this.width = this@FacebookResponse.width ?: 0 + this.height = this@FacebookResponse.height ?: 0 + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/hulu/HuluResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/hulu/HuluResponse.kt new file mode 100644 index 0000000..ab7afc8 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/hulu/HuluResponse.kt @@ -0,0 +1,62 @@ +package com.gapps.library.api.models.video.hulu + + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class HuluResponse( + @SerializedName("provider_name") + val providerName: String = "", + @SerializedName("type") + val type: String = "", + @SerializedName("thumbnail_width") + val thumbnailWidth: Int = 0, + @SerializedName("provider_url") + val providerUrl: String = "", + @SerializedName("width") + val width: Int = 0, + @SerializedName("thumbnail_height") + val thumbnailHeight: Int = 0, + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("cache_age") + val cacheAge: Int = 0, + @SerializedName("height") + val height: Int = 0, + @SerializedName("version") + val version: String = "", + @SerializedName("large_thumbnail_url") + val largeThumbnailUrl: String = "", + @SerializedName("html") + val html: String = "", + @SerializedName("air_date") + val airDate: String = "", + @SerializedName("large_thumbnail_width") + val largeThumbnailWidth: Int = 0, + @SerializedName("duration") + val duration: Double = 0.0, + @SerializedName("title") + val title: String = "", + @SerializedName("large_thumbnail_height") + val largeThumbnailHeight: Int = 0, + @SerializedName("embed_url") + val embedUrl: String = "", + @SerializedName("author_name") + val authorName: String = "", +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@HuluResponse.largeThumbnailUrl + this.videoTitle = this@HuluResponse.title + this.linkToPlay = "https:$embedUrl" + this.width = this@HuluResponse.width + this.height = this@HuluResponse.height + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/loom/LoomResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/loom/LoomResponse.kt new file mode 100644 index 0000000..f9604db --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/loom/LoomResponse.kt @@ -0,0 +1,49 @@ +package com.gapps.library.api.models.video.loom + + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class LoomResponse( + @SerializedName("type") + val type: String = "", + @SerializedName("version") + val version: String = "", + @SerializedName("html") + val html: String = "", + @SerializedName("title") + val title: String = "", + @SerializedName("height") + val height: Int = 0, + @SerializedName("width") + val width: Int = 0, + @SerializedName("provider_name") + val providerName: String = "", + @SerializedName("provider_url") + val providerUrl: String = "", + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("thumbnail_height") + val thumbnailHeight: Int = 0, + @SerializedName("thumbnail_width") + val thumbnailWidth: Int = 0, + @SerializedName("duration") + val duration: Int = 0, + @SerializedName("description") + val description: String = "" +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@LoomResponse.thumbnailUrl + this.videoTitle = this@LoomResponse.title + this.width = this@LoomResponse.width + this.height = this@LoomResponse.height + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/AllTag.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/AllTag.kt new file mode 100644 index 0000000..67d01f2 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/AllTag.kt @@ -0,0 +1,17 @@ +package com.gapps.library.api.models.video.rutube + + +import com.google.gson.annotations.SerializedName + +data class AllTag( + @SerializedName("comment") + val comment: String = "", + @SerializedName("id") + val id: Int = 0, + @SerializedName("name") + val name: String = "", + @SerializedName("type") + val type: String = "", + @SerializedName("url") + val url: String = "" +) \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/Author.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/Author.kt new file mode 100644 index 0000000..0e77aa5 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/Author.kt @@ -0,0 +1,15 @@ +package com.gapps.library.api.models.video.rutube + + +import com.google.gson.annotations.SerializedName + +data class Author( + @SerializedName("avatar_url") + val avatarUrl: String = "", + @SerializedName("id") + val id: Int = 0, + @SerializedName("name") + val name: String = "", + @SerializedName("site_url") + val siteUrl: String = "" +) \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/Category.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/Category.kt new file mode 100644 index 0000000..31262be --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/Category.kt @@ -0,0 +1,13 @@ +package com.gapps.library.api.models.video.rutube + + +import com.google.gson.annotations.SerializedName + +data class Category( + @SerializedName("category_url") + val categoryUrl: String = "", + @SerializedName("id") + val id: Int = 0, + @SerializedName("name") + val name: String = "" +) \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/Country.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/Country.kt new file mode 100644 index 0000000..0575852 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/Country.kt @@ -0,0 +1,11 @@ +package com.gapps.library.api.models.video.rutube + + +import com.google.gson.annotations.SerializedName + +data class Country( + @SerializedName("allowed") + val allowed: List<String> = listOf(), + @SerializedName("restricted") + val restricted: List<Any> = listOf() +) \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/PgRating.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/PgRating.kt new file mode 100644 index 0000000..737e67b --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/PgRating.kt @@ -0,0 +1,11 @@ +package com.gapps.library.api.models.video.rutube + + +import com.google.gson.annotations.SerializedName + +data class PgRating( + @SerializedName("age") + val age: Int = 0, + @SerializedName("logo") + val logo: String = "" +) \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/Restrictions.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/Restrictions.kt new file mode 100644 index 0000000..168ecee --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/Restrictions.kt @@ -0,0 +1,9 @@ +package com.gapps.library.api.models.video.rutube + + +import com.google.gson.annotations.SerializedName + +data class Restrictions( + @SerializedName("country") + val country: Country = Country() +) \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/RutubeResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/RutubeResponse.kt new file mode 100644 index 0000000..381cb61 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/rutube/RutubeResponse.kt @@ -0,0 +1,138 @@ +package com.gapps.library.api.models.video.rutube + + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class RutubeResponse( + @SerializedName("title") + val title: String = "", + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("source_url") + val sourceUrl: String = "", + @SerializedName("all_tags") + val allTags: List<AllTag> = listOf(), + @SerializedName("author") + val author: Author = Author(), + @SerializedName("category") + val category: Category = Category(), + @SerializedName("club_params") + val clubParams: String = "", + @SerializedName("comment_editors") + val commentEditors: String = "", + @SerializedName("comments_count") + val commentsCount: Int = 0, + @SerializedName("created_ts") + val createdTs: String = "", + @SerializedName("description") + val description: String = "", + @SerializedName("duration") + val duration: Int = 0, + @SerializedName("embed_url") + val embedUrl: String = "", + @SerializedName("episode") + val episode: Any? = Any(), + @SerializedName("ext_id") + val extId: Any? = Any(), + @SerializedName("feed_name") + val feedName: String = "", + @SerializedName("feed_subscribers_count") + val feedSubscribersCount: Int = 0, + @SerializedName("feed_subscription_url") + val feedSubscriptionUrl: String = "", + @SerializedName("feed_url") + val feedUrl: String = "", + @SerializedName("for_linked") + val forLinked: Boolean = false, + @SerializedName("for_registered") + val forRegistered: Boolean = false, + @SerializedName("genres") + val genres: String = "", + @SerializedName("has_high_quality") + val hasHighQuality: Boolean = false, + @SerializedName("hashtags") + val hashtags: List<Any> = listOf(), + @SerializedName("hits") + val hits: Int = 0, + @SerializedName("html") + val html: String = "", + @SerializedName("id") + val id: String = "", + @SerializedName("is_adult") + val isAdult: Boolean = false, + @SerializedName("is_classic") + val isClassic: Boolean = false, + @SerializedName("is_club") + val isClub: Boolean = false, + @SerializedName("is_deleted") + val isDeleted: Boolean = false, + @SerializedName("is_external") + val isExternal: Boolean = false, + @SerializedName("is_hidden") + val isHidden: Boolean = false, + @SerializedName("is_livestream") + val isLivestream: Boolean = false, + @SerializedName("is_official") + val isOfficial: Boolean = false, + @SerializedName("is_serial") + val isSerial: Boolean = false, + @SerializedName("last_update_ts") + val lastUpdateTs: String = "", + @SerializedName("music") + val music: Any? = Any(), + @SerializedName("pepper") + val pepper: Any? = Any(), + @SerializedName("persons") + val persons: String = "", + @SerializedName("pg_rating") + val pgRating: PgRating = PgRating(), + @SerializedName("picture_url") + val pictureUrl: String = "", + @SerializedName("publication_ts") + val publicationTs: String = "", + @SerializedName("restrictions") + val restrictions: Restrictions = Restrictions(), + @SerializedName("rutube_poster") + val rutubePoster: Any? = Any(), + @SerializedName("season") + val season: Any? = Any(), + @SerializedName("short_description") + val shortDescription: String = "", + @SerializedName("show") + val show: Any? = Any(), + @SerializedName("track_id") + val trackId: Int = 0, + @SerializedName("tv_show_id") + val tvShowId: Any? = Any(), + @SerializedName("video_url") + val videoUrl: String = "" + +) : BaseVideoResponse { + private fun width() = try { + "(?:width=\"(\\d+)\")".toRegex().find(html)?.groups?.get(1)?.value?.toIntOrNull() ?: 0 + } catch (e: Exception) { + 0 + } + + private fun height() = try { + "(?:height=\"(\\d+)\")".toRegex().find(html)?.groups?.get(1)?.value?.toIntOrNull() ?: 0 + } catch (e: Exception) { + 0 + } + + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.videoTitle = this@RutubeResponse.title + this.thumbnailUrl = this@RutubeResponse.thumbnailUrl + this.width = this@RutubeResponse.width() + this.height = this@RutubeResponse.height() + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/streamable/StreamableResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/streamable/StreamableResponse.kt new file mode 100644 index 0000000..960b63b --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/streamable/StreamableResponse.kt @@ -0,0 +1,40 @@ +package com.gapps.library.api.models.video.streamable + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class StreamableResponse( + @SerializedName("version") + val version: String = "", + @SerializedName("type") + val type: String = "", + @SerializedName("title") + val title: String = "", + @SerializedName("html") + val html: String = "", + @SerializedName("width") + val width: String = "", + @SerializedName("height") + val height: String = "", + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("provider_name") + val providerName: String = "", + @SerializedName("provider_url") + val providerUrl: String = "" +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = "https:${this@StreamableResponse.thumbnailUrl.trim()}" + this.videoTitle = this@StreamableResponse.title + this.width = this@StreamableResponse.width.toInt() + this.height = this@StreamableResponse.height.toInt() + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/ted/TedTalksResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/ted/TedTalksResponse.kt new file mode 100644 index 0000000..e68b332 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/ted/TedTalksResponse.kt @@ -0,0 +1,55 @@ +package com.gapps.library.api.models.video.ted + + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class TedTalksResponse( + @SerializedName("type") + val type: String = "", + @SerializedName("version") + val version: String = "", + @SerializedName("width") + val width: Int = 0, + @SerializedName("height") + val height: Int = 0, + @SerializedName("title") + val title: String = "", + @SerializedName("description") + val description: String = "", + @SerializedName("url") + val url: String = "", + @SerializedName("author_name") + val authorName: String = "", + @SerializedName("provider_name") + val providerName: String = "", + @SerializedName("provider_url") + val providerUrl: String = "", + @SerializedName("cache_age") + val cacheAge: Int = 0, + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("thumbnail_width") + val thumbnailWidth: Int = 0, + @SerializedName("thumbnail_height") + val thumbnailHeight: Int = 0, + @SerializedName("author_url") + val authorUrl: String = "", + @SerializedName("html") + val html: String = "" +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@TedTalksResponse.thumbnailUrl + this.videoTitle = this@TedTalksResponse.title + this.width = this@TedTalksResponse.width + this.height = this@TedTalksResponse.height + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/tiktok/TikTokResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/tiktok/TikTokResponse.kt new file mode 100644 index 0000000..39bdb68 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/tiktok/TikTokResponse.kt @@ -0,0 +1,50 @@ +package com.gapps.library.api.models.video.tiktok + + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class TikTokResponse( + @SerializedName("version") + val version: String = "", + @SerializedName("type") + val type: String = "", + @SerializedName("title") + val title: String = "", + @SerializedName("author_url") + val authorUrl: String = "", + @SerializedName("author_name") + val authorName: String = "", + @SerializedName("width") + val width: String = "", + @SerializedName("height") + val height: String = "", + @SerializedName("html") + val html: String = "", + @SerializedName("thumbnail_width") + val thumbnailWidth: Int = 0, + @SerializedName("thumbnail_height") + val thumbnailHeight: Int = 0, + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("provider_url") + val providerUrl: String = "", + @SerializedName("provider_name") + val providerName: String = "" +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@TikTokResponse.thumbnailUrl + this.videoTitle = this@TikTokResponse.authorName + this.width = this@TikTokResponse.width.toInt() + this.height = this@TikTokResponse.height.toInt() + } + } + +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/ultimedia/UltimediaResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/ultimedia/UltimediaResponse.kt new file mode 100644 index 0000000..35258ab --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/ultimedia/UltimediaResponse.kt @@ -0,0 +1,49 @@ +package com.gapps.library.api.models.video.ultimedia + + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class UltimediaResponse( + @SerializedName("version") + val version: String = "", + @SerializedName("type") + val type: String = "", + @SerializedName("title") + val title: String = "", + @SerializedName("description") + val description: String = "", + @SerializedName("html") + val html: String = "", + @SerializedName("width") + val width: String = "", + @SerializedName("height") + val height: String = "", + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("thumbnail_width") + val thumbnailWidth: String = "", + @SerializedName("thumbnail_height") + val thumbnailHeight: String = "", + @SerializedName("provider_name") + val providerName: String = "", + @SerializedName("provider_url") + val providerUrl: String = "", + @SerializedName("author_name") + val authorName: String = "" +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@UltimediaResponse.thumbnailUrl + this.videoTitle = this@UltimediaResponse.authorName + this.width = this@UltimediaResponse.width.toInt() + this.height = this@UltimediaResponse.height.toInt() + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/ustream/UstreamResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/ustream/UstreamResponse.kt new file mode 100644 index 0000000..f06da36 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/ustream/UstreamResponse.kt @@ -0,0 +1,47 @@ +package com.gapps.library.api.models.video.ustream + + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class UstreamResponse( + @SerializedName("provider_url") + val providerUrl: String = "", + @SerializedName("html") + val html: String = "", + @SerializedName("title") + val title: String = "", + @SerializedName("author_name") + val authorName: String = "", + @SerializedName("height") + val height: Int = 0, + @SerializedName("thumbnail_width") + val thumbnailWidth: Int = 0, + @SerializedName("width") + val width: Int = 0, + @SerializedName("version") + val version: String = "", + @SerializedName("author_url") + val authorUrl: String = "", + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("type") + val type: String = "", + @SerializedName("thumbnail_height") + val thumbnailHeight: Int = 0 +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@UstreamResponse.thumbnailUrl + this.videoTitle = this@UstreamResponse.title + this.width = this@UstreamResponse.width + this.height = this@UstreamResponse.height + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/vimeo/VimeoResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/vimeo/VimeoResponse.kt new file mode 100644 index 0000000..7ec6dff --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/vimeo/VimeoResponse.kt @@ -0,0 +1,114 @@ +package com.gapps.library.api.models.video.vimeo + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.Expose +import com.google.gson.annotations.SerializedName + +class VimeoResponse : BaseVideoResponse { + @SerializedName("id") + @Expose + var id: Int? = null + + @SerializedName("title") + @Expose + var title: String? = null + + @SerializedName("description") + @Expose + var description: String? = null + + @SerializedName("url") + @Expose + var url: String? = null + + @SerializedName("upload_date") + @Expose + var uploadDate: String? = null + + @SerializedName("thumbnail_small") + @Expose + var thumbnailSmall: String? = null + + @SerializedName("thumbnail_medium") + @Expose + var thumbnailMedium: String? = null + + @SerializedName("thumbnail_large") + @Expose + var thumbnailLarge: String? = null + + @SerializedName("user_id") + @Expose + var userId: Int? = null + + @SerializedName("user_name") + @Expose + var userName: String? = null + + @SerializedName("user_url") + @Expose + var userUrl: String? = null + + @SerializedName("user_portrait_small") + @Expose + var userPortraitSmall: String? = null + + @SerializedName("user_portrait_medium") + @Expose + var userPortraitMedium: String? = null + + @SerializedName("user_portrait_large") + @Expose + var userPortraitLarge: String? = null + + @SerializedName("user_portrait_huge") + @Expose + var userPortraitHuge: String? = null + + @SerializedName("stats_number_of_likes") + @Expose + var statsNumberOfLikes: Int? = null + + @SerializedName("stats_number_of_plays") + @Expose + var statsNumberOfPlays: Int? = null + + @SerializedName("stats_number_of_comments") + @Expose + var statsNumberOfComments: Int? = null + + @SerializedName("duration") + @Expose + var duration: Int? = null + + @SerializedName("width") + @Expose + var width: Int? = null + + @SerializedName("height") + @Expose + var height: Int? = null + + @SerializedName("tags") + @Expose + var tags: String? = null + + @SerializedName("embed_privacy") + @Expose + var embedPrivacy: String? = null + + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@VimeoResponse.thumbnailLarge + this.videoTitle = this@VimeoResponse.title + this.width = this@VimeoResponse.width ?: 0 + this.height = this@VimeoResponse.height ?: 0 + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/vzaar/Rendition.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/vzaar/Rendition.kt new file mode 100644 index 0000000..31bf989 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/vzaar/Rendition.kt @@ -0,0 +1,13 @@ +package com.gapps.library.api.models.video.vzaar + + +import com.google.gson.annotations.SerializedName + +data class Rendition( + @SerializedName("type") + val type: String = "", + @SerializedName("status_id") + val statusId: Int = 0, + @SerializedName("status") + val status: String = "" +) \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/vzaar/VzaarResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/vzaar/VzaarResponse.kt new file mode 100644 index 0000000..b6928ff --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/vzaar/VzaarResponse.kt @@ -0,0 +1,75 @@ +package com.gapps.library.api.models.video.vzaar + + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class VzaarResponse( + @SerializedName("type") + val type: String = "", + @SerializedName("version") + val version: String = "", + @SerializedName("width") + val width: Int? = 0, + @SerializedName("height") + val height: Int? = 0, + @SerializedName("html") + val html: String = "", + @SerializedName("video_status_id") + val videoStatusId: Int = 0, + @SerializedName("video_status_description") + val videoStatusDescription: String = "", + @SerializedName("play_count") + val playCount: Int = 0, + @SerializedName("total_size") + val totalSize: Int = 0, + @SerializedName("title") + val title: String = "", + @SerializedName("description") + val description: String = "", + @SerializedName("author_name") + val authorName: String = "", + @SerializedName("author_url") + val authorUrl: String = "", + @SerializedName("author_account") + val authorAccount: Int = 0, + @SerializedName("provider_name") + val providerName: String = "", + @SerializedName("provider_url") + val providerUrl: String = "", + @SerializedName("video_url") + val videoUrl: String = "", + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("thumbnail_width") + val thumbnailWidth: String = "", + @SerializedName("thumbnail_height") + val thumbnailHeight: String = "", + @SerializedName("framegrab_url") + val framegrabUrl: String = "", + @SerializedName("framegrab_width") + val framegrabWidth: Int = 0, + @SerializedName("framegrab_height") + val framegrabHeight: Int = 0, + @SerializedName("duration") + val duration: Double = 0.0, + @SerializedName("renditions") + val renditions: List<Rendition> = listOf(), + @SerializedName("categories") + val categories: List<Any> = listOf() +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@VzaarResponse.framegrabUrl + this.videoTitle = this@VzaarResponse.title + this.width = this@VzaarResponse.width ?: 0 + this.height = this@VzaarResponse.height ?: 0 + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/wistia/WistiaResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/wistia/WistiaResponse.kt new file mode 100644 index 0000000..82d8982 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/wistia/WistiaResponse.kt @@ -0,0 +1,48 @@ +package com.gapps.library.api.models.video.wistia + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +data class WistiaResponse( + @SerializedName("version") + val version: String = "", + @SerializedName("type") + val type: String = "", + @SerializedName("html") + val html: String = "", + @SerializedName("width") + val width: Int = 0, + @SerializedName("height") + val height: Int = 0, + @SerializedName("provider_name") + val providerName: String = "", + @SerializedName("provider_url") + val providerUrl: String = "", + @SerializedName("title") + val title: String = "", + @SerializedName("thumbnail_url") + val thumbnailUrl: String = "", + @SerializedName("thumbnail_width") + val thumbnailWidth: Int = 0, + @SerializedName("thumbnail_height") + val thumbnailHeight: Int = 0, + @SerializedName("player_color") + val playerColor: String = "", + @SerializedName("duration") + val duration: Double = 0.0 +) : BaseVideoResponse { + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.thumbnailUrl = this@WistiaResponse.thumbnailUrl + this.videoTitle = this@WistiaResponse.title + this.width = this@WistiaResponse.width + this.height = this@WistiaResponse.height + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/youtube/YoutubeResponse.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/youtube/YoutubeResponse.kt new file mode 100644 index 0000000..14eb8a9 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/video/youtube/YoutubeResponse.kt @@ -0,0 +1,60 @@ +package com.gapps.library.api.models.video.youtube + +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.api.models.video.base.BaseVideoResponse +import com.google.gson.annotations.SerializedName + +class YoutubeResponse : BaseVideoResponse { + @SerializedName("author_name") + var authorName: String? = null + + @SerializedName("provider_url") + var providerUrl: String? = null + + @SerializedName("thumbnail_url") + var thumbnailUrl: String? = null + + @SerializedName("title") + var title: String? = null + + @SerializedName("type") + var type: String? = null + + @SerializedName("version") + var version: String? = null + + @SerializedName("thumbnail_height") + var thumbnailHeight: Int = 0 + + @SerializedName("author_url") + var authorUrl: String? = null + + @SerializedName("thumbnail_width") + var thumbnailWidth: Int = 0 + + @SerializedName("width") + var width: Int = 0 + + @SerializedName("html") + var html: String? = null + + @SerializedName("provider_name") + var providerName: String? = null + + @SerializedName("height") + var height: Int = 0 + + override fun toPreview( + url: String?, + linkToPlay: String, + hostingName: String, + videoId: String + ): VideoPreviewModel { + return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply { + this.videoTitle = this@YoutubeResponse.title + this.thumbnailUrl = this@YoutubeResponse.thumbnailUrl + this.width = this@YoutubeResponse.width + this.height = this@YoutubeResponse.height + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/cache/DatabaseWrapper.kt b/embedded_video_lib/src/main/java/com/gapps/library/cache/DatabaseWrapper.kt new file mode 100644 index 0000000..47a8014 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/cache/DatabaseWrapper.kt @@ -0,0 +1,35 @@ +package com.gapps.library.cache + +import android.content.Context +import android.database.sqlite.SQLiteDatabase +import android.database.sqlite.SQLiteOpenHelper +import android.util.Log + +class DatabaseWrapper(context: Context?) : + SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) { + companion object { + private const val TAG = "DatabaseWrapper" + private const val DATABASE_NAME = "vna.db" + private const val DATABASE_VERSION = 1 + } + + /** + * Called if the database named DATABASE_NAME doesn't exist in order to create it. + */ + override fun onCreate(sqLiteDatabase: SQLiteDatabase) { + Log.i(TAG, "Creating database [$DATABASE_NAME v.$DATABASE_VERSION]...\n$SQL_CREATE_TABLE") + sqLiteDatabase.execSQL(SQL_CREATE_TABLE) + } + + /** + * Called when the DATABASE_VERSION is increased. + */ + override fun onUpgrade(sqLiteDatabase: SQLiteDatabase, oldVersion: Int, newVersion: Int) { + Log.i( + TAG, + "Upgrading database [$DATABASE_NAME v.$oldVersion] to [$DATABASE_NAME v.$newVersion]..." + ) + sqLiteDatabase.execSQL(SQL_DROP_TABLE) + onCreate(sqLiteDatabase) + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/cache/VideoModelORM.kt b/embedded_video_lib/src/main/java/com/gapps/library/cache/VideoModelORM.kt new file mode 100644 index 0000000..7abaad2 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/cache/VideoModelORM.kt @@ -0,0 +1,136 @@ +package com.gapps.library.cache + +import android.content.ContentValues +import android.content.Context +import android.database.Cursor +import android.util.Log +import com.gapps.library.api.models.video.VideoPreviewModel +import com.gapps.library.utils.toMD5 +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.withContext + + +private const val TAG = "VideoServiceORM" +private const val TABLE_NAME = "video_model" +private const val COMMA_SEP = ", " + +private const val COLUMN_VIDEO_ID_TYPE = "TEXT PRIMARY KEY" +private const val COLUMN_VIDEO_ID = "video_id" + +private const val COLUMN_ID_TYPE = "TEXT" +private const val COLUMN_ID = "id" + +private const val COLUMN_URL_TYPE = "TEXT" +private const val COLUMN_URL = "url" + +private const val COLUMN_TITLE_TYPE = "TEXT" +private const val COLUMN_TITLE = "title" + +private const val COLUMN_THUMBNAIL_TYPE = "TEXT" +private const val COLUMN_THUMBNAIL = "thumbnail" + +private const val COLUMN_VIDEO_HOSTING_TYPE = "TEXT" +private const val COLUMN_VIDEO_HOSTING = "video_hosting" + +private const val COLUMN_PLAY_LINK_TYPE = "TEXT" +private const val COLUMN_PLAY_LINK = "play_link" + +private const val COLUMN_WIDTH_TYPE = "INTEGER" +private const val COLUMN_WIDTH = "width" + +private const val COLUMN_HEIGHT_TYPE = "INTEGER" +private const val COLUMN_HEIGHT = "height" + +private val job = Job() + +private val databaseContext = job + Dispatchers.IO + +const val SQL_CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + + COLUMN_VIDEO_ID + " " + COLUMN_VIDEO_ID_TYPE + COMMA_SEP + + COLUMN_URL + " " + COLUMN_URL_TYPE + COMMA_SEP + + COLUMN_ID + " " + COLUMN_ID_TYPE + COMMA_SEP + + COLUMN_TITLE + " " + COLUMN_TITLE_TYPE + COMMA_SEP + + COLUMN_THUMBNAIL + " " + COLUMN_THUMBNAIL_TYPE + COMMA_SEP + + COLUMN_VIDEO_HOSTING + " " + COLUMN_VIDEO_HOSTING_TYPE + COMMA_SEP + + COLUMN_PLAY_LINK + " " + COLUMN_PLAY_LINK_TYPE + COMMA_SEP + + COLUMN_WIDTH + " " + COLUMN_WIDTH_TYPE + COMMA_SEP + + COLUMN_HEIGHT + " " + COLUMN_HEIGHT_TYPE + + ")" + +const val SQL_DROP_TABLE = "DROP TABLE IF EXISTS $TABLE_NAME" + +suspend fun insertModel(context: Context?, model: VideoPreviewModel) = + withContext(databaseContext) { + val databaseWrapper = DatabaseWrapper(context) + val database = databaseWrapper.writableDatabase + val values = modelToContentValues(model) + val modelId = database.replace(TABLE_NAME, "null", values) + Log.i(TAG, "Inserted new VideoPreviewModel with ID: $modelId") + database.close() + } + +/** + * Packs a VideoPreviewModel object into a ContentValues map for use with SQL inserts. + */ +private fun modelToContentValues(videoModel: VideoPreviewModel): ContentValues { + val values = ContentValues() + + val hash = (videoModel.linkToPlay ?: "").toMD5() + values.put(COLUMN_ID, hash) + values.put(COLUMN_URL, videoModel.url) + values.put(COLUMN_TITLE, videoModel.videoTitle) + values.put(COLUMN_THUMBNAIL, videoModel.thumbnailUrl) + values.put(COLUMN_VIDEO_HOSTING, videoModel.videoHosting) + values.put(COLUMN_VIDEO_ID, videoModel.videoId) + values.put(COLUMN_PLAY_LINK, videoModel.linkToPlay) + values.put(COLUMN_WIDTH, videoModel.width) + values.put(COLUMN_HEIGHT, videoModel.height) + return values +} + +suspend fun getCachedVideoModel(context: Context?, linkToPlay: String) = + withContext(databaseContext) { + val databaseWrapper = DatabaseWrapper(context) + val database = databaseWrapper.readableDatabase + val columnId = linkToPlay.toMD5() + + val cursor = database.rawQuery( + "SELECT * FROM $TABLE_NAME WHERE $COLUMN_ID ='$columnId' LIMIT 1", + null + ) + + var model: VideoPreviewModel? = null + if (cursor.count > 0) { + cursor.moveToFirst() + while (!cursor.isAfterLast) { + model = cursorToVideoModel(cursor) + cursor.moveToNext() + } + Log.i(TAG, "VideoModel loaded successfully.") + } + + database.close() + + model + } + +/** + * Populates a VideoPreviewModel object with data from a Cursor + * + * @param cursor + * @return + */ +private fun cursorToVideoModel(cursor: Cursor): VideoPreviewModel { + val model = VideoPreviewModel.Builder().build() + + model.url = cursor.getString(cursor.getColumnIndex(COLUMN_URL)) + model.videoTitle = cursor.getString(cursor.getColumnIndex(COLUMN_TITLE)) + model.thumbnailUrl = cursor.getString(cursor.getColumnIndex(COLUMN_THUMBNAIL)) + model.videoHosting = cursor.getString(cursor.getColumnIndex(COLUMN_VIDEO_HOSTING)) + model.videoId = cursor.getString(cursor.getColumnIndex(COLUMN_VIDEO_ID)) + model.linkToPlay = cursor.getString(cursor.getColumnIndex(COLUMN_PLAY_LINK)) + model.width = cursor.getInt(cursor.getColumnIndex(COLUMN_WIDTH)) + model.height = cursor.getInt(cursor.getColumnIndex(COLUMN_HEIGHT)) + return model +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/ui/bottom_dialog/BottomSheetDialogFixed.kt b/embedded_video_lib/src/main/java/com/gapps/library/ui/bottom_dialog/BottomSheetDialogFixed.kt new file mode 100644 index 0000000..d3e9044 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/ui/bottom_dialog/BottomSheetDialogFixed.kt @@ -0,0 +1,47 @@ +package com.gapps.library.ui.bottom_dialog + +import android.content.Context +import android.content.DialogInterface +import android.os.Bundle +import android.view.View +import com.gapps.library.R +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetDialog + +class BottomSheetDialogFixed : BottomSheetDialog { + constructor(context: Context) : super(context) + constructor(context: Context, theme: Int) : super(context, theme) + constructor( + context: Context, + cancelable: Boolean, + cancelListener: DialogInterface.OnCancelListener? + ) : super(context, cancelable, cancelListener) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + window?.run { + findViewById<View>(R.id.container)?.fitsSystemWindows = false + findViewById<View>(R.id.coordinator)?.fitsSystemWindows = false + } + + findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)?.let { + val dialogWidth = context.resources.getDimensionPixelSize(R.dimen.vna_bv_dialog_width) + it.layoutParams = it.layoutParams.apply { + if (dialogWidth > 0) { + width = context.resources.getDimensionPixelSize(R.dimen.vna_bv_dialog_width) + } + } + } + } + + override fun show() { + super.show() + // androidx should use: com.google.android.material.R.id.design_bottom_sheet + val view = findViewById<View>(com.google.android.material.R.id.design_bottom_sheet) + view?.post { + val behavior = BottomSheetBehavior.from(view) + behavior.setState(BottomSheetBehavior.STATE_EXPANDED) + } + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/ui/bottom_menu/BottomVideoController.kt b/embedded_video_lib/src/main/java/com/gapps/library/ui/bottom_menu/BottomVideoController.kt new file mode 100644 index 0000000..d97e353 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/ui/bottom_menu/BottomVideoController.kt @@ -0,0 +1,356 @@ +package com.gapps.library.ui.bottom_menu + +import android.annotation.SuppressLint +import android.content.Context +import android.graphics.* +import android.os.Build +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.WindowManager +import android.webkit.WebChromeClient +import android.webkit.WebResourceRequest +import android.webkit.WebView +import android.webkit.WebViewClient +import android.widget.FrameLayout +import android.widget.LinearLayout +import android.widget.TextView +import androidx.annotation.ColorInt +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes +import androidx.appcompat.widget.AppCompatImageButton +import androidx.core.content.ContextCompat +import androidx.core.graphics.ColorUtils +import androidx.core.view.ViewCompat +import androidx.core.view.updatePadding +import com.gapps.library.R +import com.gapps.library.ui.bottom_dialog.BottomSheetDialogFixed +import com.gapps.library.utils.getHeightFromWidth +import com.gapps.library.utils.getWidth + +class BottomVideoController private constructor( + private val context: Context?, + private val listener: Listener?, + @ColorInt private val titleColor: Int, + @ColorInt private val textColor: Int, + @ColorInt private val backgroundColor: Int, + private val url: String?, + private val titleText: String?, + private val hostText: String?, + private val playLink: String?, + private val size: Pair<Float, Float>?, + private val progressView: View?, + private val isBottomControlPanelVisible: Boolean, + @DrawableRes private val centerButtonIcon: Int, + @StringRes private val leftButtonText: Int, + @StringRes private val rightButtonText: Int, + @ColorInt private val leftButtonTextColor: Int, + @ColorInt private val rightButtonTextColor: Int, + @ColorInt private val centerButtonIconTint: Int +) { + companion object { + var isVisible = false + + inline fun build(context: Context?, block: Builder.() -> Unit) = + Builder(context).apply(block).build() + } + + private constructor(builder: Builder) : this( + builder.context, + builder.listener, + builder.titleColor, + builder.textColor, + builder.backgroundColor, + builder.url, + builder.titleText, + builder.hostText, + builder.playLink, + builder.size, + builder.progressView, + builder.isBottomControlPanelVisible, + builder.centerButtonIcon, + builder.leftButtonText, + builder.rightButtonText, + builder.leftButtonTextColor, + builder.rightButtonTextColor, + builder.centerButtonIconTint + ) + + @SuppressLint("InflateParams", "SetJavaScriptEnabled") + fun show() { + if (isVisible) { + return + } + + context ?: return + + val url = url ?: return + + Log.i("Player link", playLink ?: "none") + + val bottomSheetDialog = BottomSheetDialogFixed(context) + val menuView = LayoutInflater.from(context).inflate(R.layout.layout_hc_video_view, null) + val menuContainer = menuView.findViewById<LinearLayout>(R.id.vna_menu_container) + val videoView = menuView.findViewById<WebView>(R.id.vna_video_view) + val videoContainer = menuView.findViewById<FrameLayout>(R.id.vna_video_container) + val progressBarContainer = + menuView.findViewById<ViewGroup>(R.id.vna_video_progress_container) + val title = menuView.findViewById<TextView>(R.id.vna_text_url_preview_title) + val videoServiceType = menuView.findViewById<TextView>(R.id.vna_player_type) + val leftButton = menuView.findViewById<TextView>(R.id.vna_left_button) + val rightButton = menuView.findViewById<TextView>(R.id.vna_right_button) + val centerButton = menuView.findViewById<AppCompatImageButton>(R.id.vna_center_button) + val controlPanelOutline = menuView.findViewById<View>(R.id.vna_control_panel_outline) + val controlPanel = menuView.findViewById<View>(R.id.vna_bottom_control_panel) + + controlPanel.visibility = if (isBottomControlPanelVisible) View.VISIBLE else View.GONE + + title.apply { + this.setTextColor(titleColor) + this.text = titleText + } + + videoServiceType.apply { + this.setTextColor(textColor) + this.text = hostText + } + + leftButton.apply { + this.setTextColor(leftButtonTextColor) + this.setText(leftButtonText) + + this.setOnClickListener { + bottomSheetDialog.dismiss() + } + } + + rightButton.apply { + this.setTextColor(rightButtonTextColor) + this.setText(rightButtonText) + + this.setOnClickListener { + listener?.openLinkIn(url) + + bottomSheetDialog.dismiss() + } + } + + centerButton.apply { + this.setImageResource(centerButtonIcon) + this.setColorFilter( + centerButtonIconTint, + PorterDuff.Mode.SRC_IN + ) + + this.setOnClickListener { + listener?.copyLink(url) + } + } + + menuContainer.apply { + this.setBackgroundColor(backgroundColor) + } + + val outlineColor = ColorUtils.setAlphaComponent(textColor, (255 * .1).toInt()) + controlPanelOutline.background.colorFilter = + PorterDuffColorFilter(outlineColor, PorterDuff.Mode.SRC_IN) + + val videoViewWidth = + context.getWidth(context.resources.getDimensionPixelSize(R.dimen.vna_bv_dialog_width)) + val videoViewHeight = getHeightFromWidth(size?.first, size?.second, videoViewWidth) + + if (progressView != null) { + progressBarContainer.removeAllViews() + progressBarContainer.addView(progressView) + } + + videoContainer.apply { + layoutParams.apply { + this.width = videoViewWidth + this.height = videoViewHeight + } + } + + videoView.apply { + setBackgroundColor(backgroundColor) + + layoutParams.apply { + this.width = videoViewWidth + this.height = videoViewHeight + } + + webViewClient = object : WebViewClient() { + override fun shouldOverrideUrlLoading( + view: WebView?, + request: WebResourceRequest? + ): Boolean { + return true + } + + override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { + super.onPageStarted(view, url, favicon) + progressBarContainer.visibility = View.VISIBLE + } + + override fun onPageFinished(view: WebView?, url: String?) { + super.onPageFinished(view, url) + progressBarContainer.visibility = View.GONE + } + } + + webChromeClient = object : WebChromeClient() { + override fun getDefaultVideoPoster(): Bitmap? { + return if (super.getDefaultVideoPoster() == null) { + try { + BitmapFactory.decodeResource( + context.resources, + R.drawable.ic_vna_play_icon + ) + } catch (e: Exception) { + null + } + } else { + super.getDefaultVideoPoster() + } + } + } + + settings.apply { + javaScriptEnabled = true + domStorageEnabled = true + } + } + + if (playLink != null) { + videoView.loadUrl(playLink) + } + + bottomSheetDialog.apply { + setContentView(menuView) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + window?.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) + } + setOnShowListener { + isVisible = true + } + setOnDismissListener { + isVisible = false + } + show() + } + + + ViewCompat.setOnApplyWindowInsetsListener(menuContainer) { view, insets -> + view?.apply { + setPadding(paddingLeft, paddingTop, paddingRight, insets.systemWindowInsetBottom) + } + + insets + } + } + + abstract class Listener { + open fun openLinkIn(link: String) {} + open fun copyLink(link: String) {} + } + + class Builder(val context: Context?) { + var listener: Listener? = null + private set + + @ColorInt + var titleColor = 0x1d1d26 + private set + + @ColorInt + var textColor = Color.parseColor("#80000000") + private set + + @ColorInt + var backgroundColor = Color.WHITE + private set + + var isBottomControlPanelVisible: Boolean = true + private set + + var url: String? = null + private set + + var titleText: String? = null + private set + + var hostText: String? = null + private set + + var playLink: String? = null + private set + + var size: Pair<Float, Float>? = null + private set + + var progressView: View? = null + private set + + @DrawableRes + var centerButtonIcon = R.drawable.ic_vna_content_copy + private set + + @ColorInt + var centerButtonIconTint = 0x1d1d26 + private set + + @ColorInt + var rightButtonTextColor = 0x1d1d26 + private set + + @ColorInt + var leftButtonTextColor = 0x1d1d26 + private set + + @StringRes + var rightButtonText = R.string.vna_open_in + private set + + @StringRes + var leftButtonText = R.string.vna_close + private set + + fun setVideoUrl(url: String?) = apply { this.url = url } + fun setTitle(title: String?) = apply { this.titleText = title } + fun setHostText(host: String?) = apply { this.hostText = host } + fun setPlayLink(url: String?) = apply { this.playLink = url } + fun setSize(width: Int, height: Int) = + apply { this.size = width.toFloat() to height.toFloat() } + + fun setProgressView(view: View) = apply { this.progressView = view } + + fun setListener(listener: Listener) = apply { this.listener = listener } + + //Theme + fun setTitleColor(@ColorInt color: Int) = apply { this.titleColor = color } + fun setTextColor(@ColorInt color: Int) = apply { this.textColor = color } + fun setLeftButtonTextColor(@ColorInt color: Int) = + apply { this.leftButtonTextColor = color } + + fun setRightButtonTextColor(@ColorInt color: Int) = + apply { this.rightButtonTextColor = color } + + fun setBackgroundColor(@ColorInt color: Int) = apply { this.backgroundColor = color } + fun setCenterButtonIconTint(@ColorInt color: Int) = + apply { this.centerButtonIconTint = color } + + fun setCenterButtonIcon(@DrawableRes resource: Int) = + apply { this.centerButtonIcon = resource } + + fun setLeftButtonText(@StringRes resource: Int) = apply { this.leftButtonText = resource } + fun setRightButtonText(@StringRes resource: Int) = apply { this.rightButtonText = resource } + fun setBottomControlPanelVisible(isVisible: Boolean) = + apply { this.isBottomControlPanelVisible = isVisible } + + fun build() = BottomVideoController(this) + + fun show() = BottomVideoController(this).show() + } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/utils/MD5.kt b/embedded_video_lib/src/main/java/com/gapps/library/utils/MD5.kt new file mode 100644 index 0000000..0c69b67 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/utils/MD5.kt @@ -0,0 +1,12 @@ +package com.gapps.library.utils + +import java.security.MessageDigest + +fun String.toMD5(): String { + val bytes = MessageDigest.getInstance("MD5").digest(this.toByteArray()) + return bytes.toHex() +} + +fun ByteArray.toHex(): String { + return joinToString("") { "%02x".format(it) } +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/utils/Regex.kt b/embedded_video_lib/src/main/java/com/gapps/library/utils/Regex.kt new file mode 100644 index 0000000..ed3d2c6 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/utils/Regex.kt @@ -0,0 +1,7 @@ +package com.gapps.library.utils + +fun String.getGroupValue(input: CharSequence?, groupIndex: Int): String? { + input ?: return null + + return this.toRegex().find(input)?.groups?.get(groupIndex)?.value +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/utils/VideoServiceExtensions.kt b/embedded_video_lib/src/main/java/com/gapps/library/utils/VideoServiceExtensions.kt new file mode 100644 index 0000000..2a2ff62 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/utils/VideoServiceExtensions.kt @@ -0,0 +1,37 @@ +package com.gapps.library.utils + +import com.gapps.library.api.VideoService.Companion.videoInfoModelsList +import com.gapps.library.utils.patterns.PatternVideoLinksBuilder +import java.util.regex.Pattern + +/** + * Check url is a video link + * + * @return true if url is a link and false otherwise + */ +fun String?.isVideoUrl(): Boolean { + this ?: return false + + return videoInfoModelsList.joinToString("|") { it.pattern } + .toRegex() + .matches(this) +} + +/** + * Looking for video links in a string + * + * @return list of [PatternVideoLinksBuilder.VideoPatternItem] + */ +fun String?.findVideos(clearLink: Boolean = false): List<PatternVideoLinksBuilder.VideoPatternItem> { + this ?: return emptyList() + + val patternBuilder = PatternVideoLinksBuilder() + + videoInfoModelsList.forEach { + patternBuilder + .clearLink(clearLink) + .addPattern(Pattern.compile(it.pattern), it.hostingName) + } + + return patternBuilder.build(this) +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/utils/VideoSize.kt b/embedded_video_lib/src/main/java/com/gapps/library/utils/VideoSize.kt new file mode 100644 index 0000000..59de698 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/utils/VideoSize.kt @@ -0,0 +1,27 @@ +package com.gapps.library.utils + +import android.content.Context +import android.graphics.Point +import android.view.WindowManager +import kotlin.math.roundToInt + +fun Context.getWidth(widthRes: Int): Int { + return if (widthRes <= 0) { + val wm = getSystemService(Context.WINDOW_SERVICE) as WindowManager + val display = wm.defaultDisplay + val size = Point() + display.getSize(size) + size.x + } else { + widthRes + } +} + +fun getHeightFromWidth(width: Float?, height: Float?, videoViewWidth: Int): Int { + return if (width == null || width <= 0 || height == null || height <= 0) { + videoViewWidth / 16 * 9 + } else { + val aspectRatio = width / height + (videoViewWidth / aspectRatio).roundToInt() + } +} diff --git a/embedded_video_lib/src/main/java/com/gapps/library/utils/errors/ErrorMessages.kt b/embedded_video_lib/src/main/java/com/gapps/library/utils/errors/ErrorMessages.kt new file mode 100644 index 0000000..414c208 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/utils/errors/ErrorMessages.kt @@ -0,0 +1,8 @@ +package com.gapps.library.utils.errors + +const val ERROR_1 = + "Err 1. Unknown video service. \nPlease, visit https://github.com/TalbotGooday/Android-Oembed-Video for more information about available services" +const val ERROR_2 = "Err 2. Can't parse response" +const val ERROR_3 = "Err 3. Can't get oEmbed url" + +class EmbeddingError(url: String, message: String) : Exception(message) \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/utils/patterns/PatternVideoLinksBuilder.kt b/embedded_video_lib/src/main/java/com/gapps/library/utils/patterns/PatternVideoLinksBuilder.kt new file mode 100644 index 0000000..e22a1be --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/utils/patterns/PatternVideoLinksBuilder.kt @@ -0,0 +1,68 @@ +package com.gapps.library.utils.patterns + +import java.util.regex.Pattern + +class PatternVideoLinksBuilder { + private var patterns: ArrayList<VideoLinkPatternItem> = ArrayList() + + private var typeForOther = "" + private var shouldClearLink = false + + fun addPattern(pattern: Pattern, hosting: String): PatternVideoLinksBuilder { + this.patterns.add(VideoLinkPatternItem(pattern, hosting)) + + return this + } + + + fun other(type: String): PatternVideoLinksBuilder { + this.typeForOther = type + + return this + } + + fun clearLink(shouldClear: Boolean): PatternVideoLinksBuilder { + this.shouldClearLink = shouldClear + + return this + } + + fun build(editable: CharSequence): List<VideoPatternItem> { + val rangesMap = mutableMapOf<IntRange, String>() + + val indexes = sortedSetOf(0) + + for (item in patterns) { + val matcher = item.pattern.matcher(editable) + while (matcher.find()) { + val start = matcher.start() + val end = matcher.end(if (shouldClearLink) 1 else 0) + + indexes.add(start) + indexes.add(end) + val intRange = start..end + rangesMap[intRange] = item.hosting + } + } + + if (indexes.last() != editable.length - 1 || editable.length == 1) { + indexes.add(editable.length) + } + + return indexes.zipWithNext().map { + val rightRange = it.first until it.second + + val intRange = IntRange(it.first, it.second) + + return@map VideoPatternItem( + rangesMap[intRange] ?: "", + editable.substring(rightRange).trim(), + intRange + ) + }.filter { it.hosting.isNotBlank() && it.url.isNotBlank() } + } + + inner class VideoLinkPatternItem(var pattern: Pattern, var hosting: String) + + inner class VideoPatternItem(var hosting: String, val url: String, val range: IntRange) +} \ No newline at end of file diff --git a/embedded_video_lib/src/main/res/drawable/ic_vna_content_copy.xml b/embedded_video_lib/src/main/res/drawable/ic_vna_content_copy.xml new file mode 100644 index 0000000..2b97644 --- /dev/null +++ b/embedded_video_lib/src/main/res/drawable/ic_vna_content_copy.xml @@ -0,0 +1,10 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:tint="#FFFFFF" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="#FF000000" + android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z" /> +</vector> diff --git a/embedded_video_lib/src/main/res/drawable/ic_vna_play_icon.png b/embedded_video_lib/src/main/res/drawable/ic_vna_play_icon.png new file mode 100644 index 0000000..1935840 Binary files /dev/null and b/embedded_video_lib/src/main/res/drawable/ic_vna_play_icon.png differ diff --git a/embedded_video_lib/src/main/res/layout/layout_hc_video_view.xml b/embedded_video_lib/src/main/res/layout/layout_hc_video_view.xml new file mode 100644 index 0000000..b8bf7a6 --- /dev/null +++ b/embedded_video_lib/src/main/res/layout/layout_hc_video_view.xml @@ -0,0 +1,119 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/vna_menu_container" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom" + android:orientation="vertical"> + + <FrameLayout + android:id="@+id/vna_video_container" + android:layout_width="match_parent" + android:layout_height="@dimen/vna_web_view_default_height"> + + <WebView + android:id="@+id/vna_video_view" + android:layout_width="match_parent" + android:layout_height="@dimen/vna_web_view_default_height" /> + + <FrameLayout + android:id="@+id/vna_video_progress_container" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center"> + + <ProgressBar + android:id="@+id/vna_video_progress" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" /> + </FrameLayout> + </FrameLayout> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/vna_large_text_space" + android:layout_marginTop="@dimen/vna_large_text_space" + android:layout_marginEnd="@dimen/vna_large_text_space" + android:layout_marginBottom="@dimen/vna_large_text_space" + android:orientation="vertical"> + + <androidx.appcompat.widget.AppCompatTextView + android:id="@+id/vna_text_url_preview_title" + style="@style/VNAText.Title" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="end" + android:textSize="@dimen/vna_title_text_size" + android:textStyle="bold" + tools:text="Title will be\n here." /> + + <androidx.appcompat.widget.AppCompatTextView + android:id="@+id/vna_player_type" + style="@style/VNAText.Hosting" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="3dp" + android:ellipsize="end" + android:textColor="@color/vna_black_p50" + tools:text="Youtube" + tools:visibility="visible" /> + </LinearLayout> + + <LinearLayout + android:id="@+id/vna_bottom_control_panel" + android:layout_width="match_parent" + android:layout_height="@dimen/vna_control_panel_height" + android:orientation="vertical"> + + <View + android:id="@+id/vna_control_panel_outline" + android:layout_width="match_parent" + android:layout_height="1dp" + android:background="@color/vna_dialog_divider" /> + + <FrameLayout + android:id="@+id/vna_control_container" + android:layout_width="match_parent" + android:layout_height="@dimen/vna_control_panel_height" + android:orientation="horizontal"> + + <androidx.appcompat.widget.AppCompatTextView + android:id="@+id/vna_left_button" + style="@style/Widget.AppCompat.Button.Borderless" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:background="?selectableItemBackgroundBorderless" + android:gravity="start|center_vertical" + android:paddingStart="18dp" + android:paddingEnd="0dp" + android:text="@string/vna_close" /> + + <androidx.appcompat.widget.AppCompatImageButton + android:id="@+id/vna_center_button" + android:layout_width="@dimen/vna_copy_icon_size" + android:layout_height="@dimen/vna_copy_icon_size" + android:layout_gravity="center" + android:layout_marginStart="@dimen/vna_copy_icon_margin" + android:layout_marginEnd="@dimen/vna_copy_icon_margin" + android:background="?selectableItemBackgroundBorderless" + android:tint="@color/vna_black_p50" + app:srcCompat="@drawable/ic_vna_content_copy" /> + + <androidx.appcompat.widget.AppCompatTextView + android:id="@+id/vna_right_button" + style="@style/Widget.AppCompat.Button.Borderless" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_gravity="end" + android:background="?selectableItemBackgroundBorderless" + android:gravity="end|center_vertical" + android:paddingStart="0dp" + android:paddingEnd="18dp" + android:text="@string/vna_open_in" /> + </FrameLayout> + </LinearLayout> +</LinearLayout> \ No newline at end of file diff --git a/embedded_video_lib/src/main/res/values-w600dp/dimens.xml b/embedded_video_lib/src/main/res/values-w600dp/dimens.xml new file mode 100644 index 0000000..951e339 --- /dev/null +++ b/embedded_video_lib/src/main/res/values-w600dp/dimens.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <dimen name="vna_bv_dialog_width">600dp</dimen> +</resources> diff --git a/embedded_video_lib/src/main/res/values/colors.xml b/embedded_video_lib/src/main/res/values/colors.xml new file mode 100644 index 0000000..b7074f4 --- /dev/null +++ b/embedded_video_lib/src/main/res/values/colors.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="vna_color_video_title_text">#ff1d1d26</color> + <color name="vna_black_p50">#80000000</color> + <color name="vna_dialog_divider">#ebebeb</color> + +</resources> \ No newline at end of file diff --git a/embedded_video_lib/src/main/res/values/dimens.xml b/embedded_video_lib/src/main/res/values/dimens.xml new file mode 100644 index 0000000..0fb7cc6 --- /dev/null +++ b/embedded_video_lib/src/main/res/values/dimens.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <dimen name="vna_large_text_space">10dp</dimen> + <dimen name="vna_bv_dialog_width">0dp</dimen> + <dimen name="vna_control_panel_height">48dp</dimen> + <dimen name="vna_copy_icon_size">35dp</dimen> + <dimen name="vna_copy_icon_margin">18dp</dimen> + <dimen name="vna_host_text_size">14sp</dimen> + <dimen name="vna_title_text_size">16sp</dimen> + <dimen name="vna_web_view_default_height">195dp</dimen> +</resources> \ No newline at end of file diff --git a/embedded_video_lib/src/main/res/values/strings.xml b/embedded_video_lib/src/main/res/values/strings.xml new file mode 100644 index 0000000..ea426ba --- /dev/null +++ b/embedded_video_lib/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ +<resources> + <string name="vna_open_in">open in…</string> + <string name="vna_close">close</string> +</resources> diff --git a/embedded_video_lib/src/main/res/values/styles.xml b/embedded_video_lib/src/main/res/values/styles.xml new file mode 100644 index 0000000..e45ecae --- /dev/null +++ b/embedded_video_lib/src/main/res/values/styles.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + + <style name="VNAText"> + <item name="android:textAlignment">viewStart</item> + <item name="android:textDirection">locale</item> + <item name="android:textSize">14sp</item> + <item name="android:ellipsize">end</item> + <item name="android:maxLines">1</item> + </style> + + <style name="VNAText.Title"> + <item name="android:textSize">@dimen/vna_title_text_size</item> + </style> + + <style name="VNAText.Hosting"> + <item name="android:textSize">@dimen/vna_host_text_size</item> + </style> +</resources> \ No newline at end of file diff --git a/embedded_video_lib/src/test/java/com/gapps/library/utils/ExtensionsKtTest.kt b/embedded_video_lib/src/test/java/com/gapps/library/utils/ExtensionsKtTest.kt new file mode 100644 index 0000000..9baec16 --- /dev/null +++ b/embedded_video_lib/src/test/java/com/gapps/library/utils/ExtensionsKtTest.kt @@ -0,0 +1,73 @@ +package com.gapps.library.utils + +import com.gapps.library.api.VideoService +import org.junit.Assert.* +import org.junit.Before +import org.junit.Test + +class ExtensionsKtTest { + @Before + fun init() { + VideoService.build { + httpClient(okHttpClient) + enableCache(true) + enableLog(true) + } + } + + private val videoUrls = listOf( + "https://www.youtube.com/watch?v=M4BSGZ07NNA", + "https://music.youtube.com/watch?v=lFMOYjVCLUo", + "https://vimeo.com/333257472", + "https://rutube.ru/video/d70e62b44b8893e98e3e90a6e2c9fcd4/?pl_type=source&pl_id=18265", + "https://www.facebook.com/UFC/videos/410056389868335/", + "https://www.dailymotion.com/video/x5sxbmb", + "https://dave.wistia.com/medias/0k5h1g1chs/", + "https://vzaar.com/videos/401431" + ) + + private val nonVideoUrls = listOf( + "asdfasdfasdfasdf", + "Some text", + "https://www.facebook.com/", + "https://vzaar.com/", + "https://www.youtube.com/", + "https://music.youtube.com/", + "https://vimeo.com/", + "https://rutube.ru/", + "https://www.facebook.com/", + "https://www.dailymotion.com/", + "https://dave.wistia.com/", + "https://vzaar.com/" + ) + + @Test + fun `Check url is a video link`() { + for (url in videoUrls) { + println(url) + assertTrue(url.isVideoUrl()) + } + + for (url in nonVideoUrls) { + println(url) + assertFalse(url.isVideoUrl()) + } + } + + @Test + fun `Check text contains links`() { + val text = + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, https://www.youtube.com/watch?v=M4BSGZ07NNA,\n" + + "https://music.youtube.com/watch?v=lFMOYjVCLUo," + + "https://vimeo.com/333257472," + + "https://rutube.ru/video/d70e62b44b8893e98e3e90a6e2c9fcd4/?pl_type=source&pl_id=18265,\n" + + "https://www.facebook.com/UFC/videos/410056389868335/,\n" + + "https://www.dailymotion.com/video/x5sxbmb,\n" + + "https://dave.wistia.com/medias/0k5h1g1chs/,\n" + + "https://vzaar.com/videos/401431sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." + + val videos = text.findVideos() + + assertEquals(videos.size, 8) + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..4e0b3ac --- /dev/null +++ b/gradle.properties @@ -0,0 +1,22 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official +-Dorg.gradle.logging.level=debug diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..f3d88b1 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..f7ff37c --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Mar 02 20:57:14 EET 2022 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..2fe81a7 --- /dev/null +++ b/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..62bd9b9 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/screenshots/device-2020-02-06-232720.png b/screenshots/device-2020-02-06-232720.png new file mode 100644 index 0000000..60d9547 Binary files /dev/null and b/screenshots/device-2020-02-06-232720.png differ diff --git a/screenshots/device-2020-02-06-232746.png b/screenshots/device-2020-02-06-232746.png new file mode 100644 index 0000000..fe3aea4 Binary files /dev/null and b/screenshots/device-2020-02-06-232746.png differ diff --git a/screenshots/device-2020-02-06-232924.png b/screenshots/device-2020-02-06-232924.png new file mode 100644 index 0000000..50d0b7c Binary files /dev/null and b/screenshots/device-2020-02-06-232924.png differ diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..4d1ee6a --- /dev/null +++ b/settings.gradle @@ -0,0 +1,3 @@ +rootProject.name='Video No Api' +include ':app' +include ':embedded_video_lib'