diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index e426361f0..b879f9648 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -80,6 +80,7 @@
@@ -142,6 +143,7 @@
diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/DeepLinkingActivity.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/DeepLinkingActivity.kt
index 439423db3..d561ed81a 100644
--- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/DeepLinkingActivity.kt
+++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/DeepLinkingActivity.kt
@@ -1,5 +1,6 @@
package io.github.feelfreelinux.wykopmobilny.ui.modules
+import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import io.github.feelfreelinux.wykopmobilny.utils.wykop_link_handler.WykopLinkHandler
@@ -9,6 +10,8 @@ class DeepLinkActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val url = intent.dataString!!
+ val activityToOpen = WykopLinkHandler.getLinkIntent(url, this)
+ activityToOpen?.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(WykopLinkHandler.getLinkIntent(url, this))
finish()
}
diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/YoutubeActivity.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/YoutubeActivity.kt
index 1aca1dae4..1263afdef 100644
--- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/YoutubeActivity.kt
+++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/embedview/YoutubeActivity.kt
@@ -3,6 +3,7 @@ package io.github.feelfreelinux.wykopmobilny.ui.modules.embedview
import android.content.Context
import android.content.Intent
import android.os.Bundle
+import android.provider.Settings
import android.widget.Toast
import com.google.android.youtube.player.YouTubeBaseActivity
import com.google.android.youtube.player.YouTubeInitializationResult
@@ -11,27 +12,76 @@ import io.github.feelfreelinux.wykopmobilny.GOOGLE_KEY
import io.github.feelfreelinux.wykopmobilny.R
import kotlinx.android.synthetic.main.activity_youtubeplayer.*
import java.util.regex.Pattern
-
-class YoutubeActivity : YouTubeBaseActivity(), YouTubePlayer.OnInitializedListener {
+import android.content.pm.ActivityInfo
+import android.os.Build
+import android.annotation.SuppressLint
+import android.R.attr.orientation
+import android.app.Activity
+import android.content.res.Configuration
+import com.google.android.youtube.player.YouTubeStandalonePlayer.createVideoIntent
+private val youTubeUrlRegEx = "^(https?)?(://)?(www.)?(m.)?((youtube.com)|(youtu.be))/"
+private val videoIdRegex = arrayOf("\\?vi?=([^&]*)", "watch\\?.*v=([^&]*)", "(?:embed|vi?)/([^/?]*)", "^([A-Za-z0-9_\\-]*)")
+
+class YoutubeActivity : YouTubeBaseActivity(), YouTubePlayer.OnInitializedListener, YouTubePlayer.OnFullscreenListener {
+ override fun onFullscreen(fullScreen: Boolean) {
+ if (fullScreen) {
+ requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
+ } else {
+ requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
+ }
+ }
companion object {
const val REQUEST_CODE_INITIALIZATION_ERROR = 172
const val EXTRA_URL = "URLEXTRA"
fun createIntent(context: Context, url: String) =
- Intent(context, YoutubeActivity::class.java).apply {
- putExtra(EXTRA_URL, url)
+ (createVideoIntent(context as Activity, GOOGLE_KEY, extractVideoIdFromUrl(url.replace("m.", "")), 0, true, false))
+
+
+ private fun extractVideoIdFromUrl(url: String): String? {
+ val youTubeLinkWithoutProtocolAndDomain = youTubeLinkWithoutProtocolAndDomain(url)
+
+ for (regex in videoIdRegex) {
+ val compiledPattern = Pattern.compile(regex)
+ val matcher = compiledPattern.matcher(youTubeLinkWithoutProtocolAndDomain)
+
+ if (matcher.find()) {
+ return matcher.group(1)
+ }
}
+
+ return null
+ }
+
+
+ fun youTubeLinkWithoutProtocolAndDomain(fullurl: String): String {
+ val url = fullurl.replace("m.", "")
+ val compiledPattern = Pattern.compile(youTubeUrlRegEx)
+ val matcher = compiledPattern.matcher(url)
+
+ return if (matcher.find()) {
+ url.replace(matcher.group(), "")
+ } else url
+ }
}
- private val youTubeUrlRegEx = "^(https?)?(://)?(www.)?(m.)?((youtube.com)|(youtu.be))/"
- private val videoIdRegex = arrayOf("\\?vi?=([^&]*)", "watch\\?.*v=([^&]*)", "(?:embed|vi?)/([^/?]*)", "^([A-Za-z0-9_\\-]*)")
+ val autoRotation by lazy {
+ Settings.System.getInt(getContentResolver(),
+ Settings.System.ACCELEROMETER_ROTATION, 0) == 1;
+ }
+
+
private val extraURL by lazy { intent.getStringExtra(EXTRA_URL) }
+ var player: YouTubePlayer? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_youtubeplayer)
- youtubePlayer.initialize(GOOGLE_KEY, this)
+/* //youtubePlayer.initialize(GOOGLE_KEY, this)
+
+ startActivity(createVideoIntent(this, GOOGLE_KEY, extractVideoIdFromUrl(extraURL.replace("m.", "")), 0, true, true))
+ finish()*/
}
override fun onInitializationFailure(provider: YouTubePlayer.Provider?, result: YouTubeInitializationResult?) {
@@ -46,40 +96,36 @@ class YoutubeActivity : YouTubeBaseActivity(), YouTubePlayer.OnInitializedListen
override fun onInitializationSuccess(provider: YouTubePlayer.Provider?, player: YouTubePlayer?, restored: Boolean) {
if (!restored) {
+ this.player = player
player?.prepare()
player?.loadVideo(extractVideoIdFromUrl(extraURL.replace("m.", "")))
}
}
fun YouTubePlayer.prepare() {
- fullscreenControlFlags = YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION or YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE or
- YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI
+ setOnFullscreenListener(this@YoutubeActivity)
+ if (autoRotation) {
+ addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION
+ or YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI
+ or YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE
+ or YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT)
+ } else {
+ addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION
+ or YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI
+ or YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT)
+ }
setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT)
}
- private fun extractVideoIdFromUrl(url: String): String? {
- val youTubeLinkWithoutProtocolAndDomain = youTubeLinkWithoutProtocolAndDomain(url)
-
- for (regex in videoIdRegex) {
- val compiledPattern = Pattern.compile(regex)
- val matcher = compiledPattern.matcher(youTubeLinkWithoutProtocolAndDomain)
+ override fun onConfigurationChanged(newConfig: Configuration) {
+ super.onConfigurationChanged(newConfig)
- if (matcher.find()) {
- return matcher.group(1)
- }
+ if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ this.player?.setFullscreen(true)
+ }
+ if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
+ this.player?.setFullscreen(false)
}
-
- return null
- }
-
- private fun youTubeLinkWithoutProtocolAndDomain(fullurl: String): String {
- val url = fullurl.replace("m.", "")
- val compiledPattern = Pattern.compile(youTubeUrlRegEx)
- val matcher = compiledPattern.matcher(url)
-
- return if (matcher.find()) {
- url.replace(matcher.group(), "")
- } else url
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
diff --git a/build.gradle b/build.gradle
index cb89f0d22..2a3b8dfe9 100755
--- a/build.gradle
+++ b/build.gradle
@@ -26,8 +26,8 @@ allprojects {
project.ext {
versionMajor = 0
versionMinor = 9
- versionPatch = 6
- versionBuild = 3
+ versionPatch = 7
+ versionBuild = 0
}
}