diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 811e4c2..8f897d8 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -49,6 +49,7 @@
+
1) {
+ actionAdapter.add(
+ Action(
+ ACTION_SELECT_SOURCE,
+ resources.getString(R.string.select_movie_source)
+ )
)
- )
+ }
row.actionsAdapter = actionAdapter
@@ -106,8 +112,12 @@ class MovieDetailsFragment: DetailsFragment() {
detailsPresenter.onActionClickedListener = OnActionClickedListener { action ->
when {
action.id == ACTION_PLAY_MOVIE -> startActivity(PlaybackActivity.createIntent(context, movie!!.id ))
- action.id == ACTION_SELECT_SOURCE -> Toast.makeText(context, "Select Source Selected",
- Toast.LENGTH_SHORT).show()
+ action.id == ACTION_SELECT_SOURCE -> {
+ val intent = Intent(context, SelectMovieSourceDialogActivity::class.java)
+ intent.putExtra(EXTRA_MOVIE_ID, movie!!.id)
+ startActivity(intent)
+ }
+
else -> Toast.makeText(context, action.toString(), Toast.LENGTH_SHORT).show()
}
}
diff --git a/app/src/main/java/com/ratanparai/moviedog/ui/PlaybackActivity.kt b/app/src/main/java/com/ratanparai/moviedog/ui/PlaybackActivity.kt
index 4de092a..509ae4a 100644
--- a/app/src/main/java/com/ratanparai/moviedog/ui/PlaybackActivity.kt
+++ b/app/src/main/java/com/ratanparai/moviedog/ui/PlaybackActivity.kt
@@ -8,6 +8,7 @@ import android.view.KeyEvent
import androidx.fragment.app.FragmentActivity
import com.ratanparai.moviedog.R
import com.ratanparai.moviedog.utilities.EXTRA_MOVIE_ID
+import com.ratanparai.moviedog.utilities.EXTRA_MOVIE_URL
class PlaybackActivity: FragmentActivity() {
@@ -42,5 +43,12 @@ class PlaybackActivity: FragmentActivity() {
intent.putExtra(EXTRA_MOVIE_ID, movieId)
return intent
}
+
+ fun createIntent(context: Context, movieId: Int, movieUrl: String): Intent {
+ val intent = Intent(context, PlaybackActivity::class.java)
+ intent.putExtra(EXTRA_MOVIE_ID, movieId)
+ intent.putExtra(EXTRA_MOVIE_URL, movieUrl)
+ return intent
+ }
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/ratanparai/moviedog/ui/PlaybackFragment.kt b/app/src/main/java/com/ratanparai/moviedog/ui/PlaybackFragment.kt
index d0f47f7..becca87 100644
--- a/app/src/main/java/com/ratanparai/moviedog/ui/PlaybackFragment.kt
+++ b/app/src/main/java/com/ratanparai/moviedog/ui/PlaybackFragment.kt
@@ -21,6 +21,7 @@ import com.ratanparai.moviedog.db.entity.Movie
import com.ratanparai.moviedog.player.VideoPlayerGlue
import com.ratanparai.moviedog.service.MovieService
import com.ratanparai.moviedog.utilities.EXTRA_MOVIE_ID
+import com.ratanparai.moviedog.utilities.EXTRA_MOVIE_URL
class PlaybackFragment: VideoSupportFragment() {
private val TAG = "PlaybackFragment"
@@ -34,12 +35,15 @@ class PlaybackFragment: VideoSupportFragment() {
private var movieIdToPlay: Int = -1
+ private var movieUrl: String? = null
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d(TAG, "Fragment loaded")
val movieId = activity?.intent?.getIntExtra(EXTRA_MOVIE_ID, -1)
+ movieUrl = activity?.intent?.getStringExtra(EXTRA_MOVIE_URL)
movieIdToPlay = movieId!!
@@ -109,9 +113,17 @@ class PlaybackFragment: VideoSupportFragment() {
private fun prepareMediaForPlaying(movie: Movie) {
val userAgent = Util.getUserAgent(context, "MovieDog")
- val mediaSource = ExtractorMediaSource
- .Factory(DefaultDataSourceFactory(context, userAgent))
- .createMediaSource(Uri.parse(movie.videoUrl))
+
+ val mediaSource = if (movieUrl == null) {
+ ExtractorMediaSource
+ .Factory(DefaultDataSourceFactory(context, userAgent))
+ .createMediaSource(Uri.parse(movie.videoUrl))
+ } else {
+ ExtractorMediaSource
+ .Factory(DefaultDataSourceFactory(context, userAgent))
+ .createMediaSource(Uri.parse(movieUrl))
+ }
+
exoPlayer.prepare(mediaSource)
}
diff --git a/app/src/main/java/com/ratanparai/moviedog/ui/SelectMovieSourceDialogActivity.kt b/app/src/main/java/com/ratanparai/moviedog/ui/SelectMovieSourceDialogActivity.kt
new file mode 100644
index 0000000..16dd2f2
--- /dev/null
+++ b/app/src/main/java/com/ratanparai/moviedog/ui/SelectMovieSourceDialogActivity.kt
@@ -0,0 +1,22 @@
+package com.ratanparai.moviedog.ui
+
+import android.app.Activity
+import android.graphics.Color
+import android.graphics.drawable.ColorDrawable
+import android.os.Bundle
+import androidx.leanback.app.GuidedStepFragment
+
+class SelectMovieSourceDialogActivity: Activity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ window.setBackgroundDrawable(ColorDrawable(Color.parseColor("#21272A")))
+
+ if (savedInstanceState == null) {
+ val fragment = SelectMovieSourceDialogFragment()
+ GuidedStepFragment.addAsRoot(this, fragment, android.R.id.content)
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/ratanparai/moviedog/ui/SelectMovieSourceDialogFragment.kt b/app/src/main/java/com/ratanparai/moviedog/ui/SelectMovieSourceDialogFragment.kt
new file mode 100644
index 0000000..5fe42ed
--- /dev/null
+++ b/app/src/main/java/com/ratanparai/moviedog/ui/SelectMovieSourceDialogFragment.kt
@@ -0,0 +1,88 @@
+package com.ratanparai.moviedog.ui
+
+import android.os.Bundle
+import android.widget.Toast
+import androidx.leanback.app.GuidedStepFragment
+import androidx.leanback.widget.GuidanceStylist
+import androidx.leanback.widget.GuidedAction
+import com.ratanparai.moviedog.R
+import com.ratanparai.moviedog.db.AppDatabase
+import com.ratanparai.moviedog.db.entity.MovieUrl
+import com.ratanparai.moviedog.utilities.EXTRA_MOVIE_ID
+
+class SelectMovieSourceDialogFragment: GuidedStepFragment() {
+
+ private var movieUrls: List? = null
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+
+ val movieId = activity?.intent?.getIntExtra(EXTRA_MOVIE_ID, -1)
+
+ if (movieId == -1) {
+ activity.finish()
+ }
+
+ movieUrls = AppDatabase.getInstance(context).movieUrlDao().getMovieUrlsByMovieId(movieId!!)
+
+ super.onCreate(savedInstanceState)
+ }
+
+ override fun onCreateGuidance(savedInstanceState: Bundle?): GuidanceStylist.Guidance {
+
+
+ val guidance = GuidanceStylist.Guidance(
+ getString(R.string.dialog_movie_select_title),
+ getString(R.string.dialog_movie_select_description),
+ "", null
+ )
+
+ return guidance
+ }
+
+
+
+ override fun onCreateActions(actions: MutableList, savedInstanceState: Bundle?) {
+
+ for (movieUrl in movieUrls!!) {
+ actions.add(
+ GuidedAction.Builder()
+ .id(movieUrl.id.toLong())
+ .description(movieUrl.movieUrl)
+ .title(movieUrl.serviceName).build()
+ )
+ }
+
+// var action = GuidedAction.Builder()
+// .id(ACTION_ID_POSITIVE)
+// .title("Positive").build()
+// actions.add(action)
+// action = GuidedAction.Builder()
+// .id(ACTION_ID_NEGATIVE)
+// .title("negative").build()
+// actions.add(action)
+ }
+
+ override fun onGuidedActionClicked(action: GuidedAction) {
+// if (ACTION_ID_POSITIVE == action.id) {
+// Toast.makeText(
+// activity, "Positive Clicked",
+// Toast.LENGTH_SHORT
+// ).show()
+// } else {
+// Toast.makeText(
+// activity, "Negative clicked",
+// Toast.LENGTH_SHORT
+// ).show()
+// }
+
+ for (movieUrl in movieUrls!!) {
+ if(movieUrl.id == action.id.toInt())
+ startActivity(PlaybackActivity.createIntent(context, movieUrl.movieId, movieUrl.movieUrl))
+ }
+ }
+
+ companion object {
+ private const val ACTION_ID_POSITIVE = 1L
+ private const val ACTION_ID_NEGATIVE = 2L
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/ratanparai/moviedog/utilities/Constant.kt b/app/src/main/java/com/ratanparai/moviedog/utilities/Constant.kt
index c7aaeaf..274b590 100644
--- a/app/src/main/java/com/ratanparai/moviedog/utilities/Constant.kt
+++ b/app/src/main/java/com/ratanparai/moviedog/utilities/Constant.kt
@@ -4,4 +4,5 @@ package com.ratanparai.moviedog.utilities
* Constants used throughout the app.
*/
const val DATABASE_NAME = "moviedog-db"
-const val EXTRA_MOVIE_ID = "com.ratanparai.moviedog.extra.MOVIE_ID"
\ No newline at end of file
+const val EXTRA_MOVIE_ID = "com.ratanparai.moviedog.extra.MOVIE_ID"
+const val EXTRA_MOVIE_URL = "com.ratanparai.moviedog.extra.MOVIE_URL"
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b64feba..ba0355d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -28,4 +28,8 @@
Not Implemented Yet!
Play
Select Source
+ Select movie source to play
+ You can choose any source to play movies. If one source failed,
+ please try another source
+