improve autoplay next episode
* add animations to show/hide next episode button * add option to disable/enable autoplay
This commit is contained in:
		| @ -1,5 +1,7 @@ | ||||
| package org.mosad.teapod | ||||
|  | ||||
| import android.animation.Animator | ||||
| import android.animation.AnimatorListenerAdapter | ||||
| import android.annotation.SuppressLint | ||||
| import android.net.Uri | ||||
| import android.os.Build | ||||
| @ -28,6 +30,7 @@ import org.mosad.teapod.util.Episode | ||||
| import org.mosad.teapod.util.Media | ||||
| import java.util.concurrent.TimeUnit | ||||
|  | ||||
|  | ||||
| class PlayerActivity : AppCompatActivity() { | ||||
|  | ||||
|     private lateinit var player: SimpleExoPlayer | ||||
| @ -157,7 +160,7 @@ class PlayerActivity : AppCompatActivity() { | ||||
|                     else -> View.VISIBLE | ||||
|                 } | ||||
|  | ||||
|                 if (state == ExoPlayer.STATE_ENDED && nextEpisode != null) { | ||||
|                 if (state == ExoPlayer.STATE_ENDED && nextEpisode != null && Preferences.autoplay) { | ||||
|                     playNextEpisode() | ||||
|                 } | ||||
|  | ||||
| @ -219,8 +222,14 @@ class PlayerActivity : AppCompatActivity() { | ||||
|             if (remainingTime in 0..20000) { | ||||
|                 withContext(Dispatchers.Main) { | ||||
|                     // if the next ep button is not visible, make it visible | ||||
|                     if (!button_next_ep.isVisible && nextEpisode != null) { | ||||
|                         button_next_ep.visibility = View.VISIBLE // TODO animation | ||||
|                     if (!button_next_ep.isVisible && nextEpisode != null && Preferences.autoplay) { | ||||
|                         showButtonNextEp() | ||||
|                     } | ||||
|                 } | ||||
|             } else { | ||||
|                 withContext(Dispatchers.Main) { | ||||
|                     if (button_next_ep.isVisible) { | ||||
|                         hideButtonNextEp() | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
| @ -253,7 +262,7 @@ class PlayerActivity : AppCompatActivity() { | ||||
|  | ||||
|             // update the gui | ||||
|             exo_text_title.text = nextEp.title | ||||
|             button_next_ep.visibility = View.GONE // TODO animation | ||||
|             hideButtonNextEp() | ||||
|  | ||||
|             player.clearMediaItems() //remove previous item | ||||
|             val mediaSource = HlsMediaSource.Factory(dataSourceFactory) | ||||
| @ -316,6 +325,36 @@ class PlayerActivity : AppCompatActivity() { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * show the next episode button | ||||
|      * TODO improve the show animation | ||||
|      */ | ||||
|     private fun showButtonNextEp() { | ||||
|         button_next_ep.visibility = View.VISIBLE | ||||
|         button_next_ep.alpha = 0.0f | ||||
|  | ||||
|         button_next_ep.animate() | ||||
|             .alpha(1.0f) | ||||
|             .setListener(null) | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * hide the next episode button | ||||
|      * TODO improve the hide animation | ||||
|      */ | ||||
|     private fun hideButtonNextEp() { | ||||
|         button_next_ep.animate() | ||||
|             .alpha(0.0f) | ||||
|             .setListener(object : AnimatorListenerAdapter() { | ||||
|             override fun onAnimationEnd(animation: Animator?) { | ||||
|                 super.onAnimationEnd(animation) | ||||
|                 button_next_ep.visibility = View.GONE | ||||
|             } | ||||
|         }) | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|     inner class PlayerGestureListener : GestureDetector.SimpleOnGestureListener() { | ||||
|  | ||||
|         /** | ||||
|  | ||||
| @ -7,6 +7,8 @@ object Preferences { | ||||
|  | ||||
|     var preferSecondary = false | ||||
|         internal set | ||||
|     var autoplay = true | ||||
|         internal set | ||||
|  | ||||
|     fun savePreferSecondary(context: Context, preferSecondary: Boolean) { | ||||
|         val sharedPref = context.getSharedPreferences( | ||||
| @ -22,6 +24,20 @@ object Preferences { | ||||
|         this.preferSecondary = preferSecondary | ||||
|     } | ||||
|  | ||||
|     fun saveAutoplay(context: Context, autoplay: Boolean) { | ||||
|         val sharedPref = context.getSharedPreferences( | ||||
|             context.getString(R.string.preference_file_key), | ||||
|             Context.MODE_PRIVATE | ||||
|         ) | ||||
|  | ||||
|         with(sharedPref.edit()) { | ||||
|             putBoolean(context.getString(R.string.save_key_autoplay), autoplay) | ||||
|             apply() | ||||
|         } | ||||
|  | ||||
|         this.autoplay = autoplay | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * initially load the stored values | ||||
|      */ | ||||
| @ -34,6 +50,9 @@ object Preferences { | ||||
|         preferSecondary = sharedPref.getBoolean( | ||||
|             context.getString(R.string.save_key_prefer_secondary), false | ||||
|         ) | ||||
|         autoplay = sharedPref.getBoolean( | ||||
|             context.getString(R.string.save_key_autoplay), true | ||||
|         ) | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -28,6 +28,7 @@ class AccountFragment : Fragment() { | ||||
|         text_account_login.text = EncryptedPreferences.login | ||||
|         text_info_about_desc.text = getString(R.string.info_about_desc, BuildConfig.VERSION_NAME, getString(R.string.build_time)) | ||||
|         switch_secondary.isChecked = Preferences.preferSecondary | ||||
|         switch_autoplay.isChecked = Preferences.autoplay | ||||
|  | ||||
|         initActions() | ||||
|     } | ||||
| @ -57,6 +58,10 @@ class AccountFragment : Fragment() { | ||||
|         switch_secondary.setOnClickListener { | ||||
|             Preferences.savePreferSecondary(requireContext(), switch_secondary.isChecked) | ||||
|         } | ||||
|  | ||||
|         switch_autoplay.setOnClickListener { | ||||
|             Preferences.saveAutoplay(requireContext(), switch_autoplay.isChecked) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun showLoginDialog(firstTry: Boolean) { | ||||
|  | ||||
| @ -6,12 +6,15 @@ import android.view.View | ||||
| import android.view.ViewGroup | ||||
| import androidx.fragment.app.Fragment | ||||
| import kotlinx.android.synthetic.main.fragment_library.* | ||||
| import kotlinx.coroutines.* | ||||
| import kotlinx.coroutines.Dispatchers | ||||
| import kotlinx.coroutines.GlobalScope | ||||
| import kotlinx.coroutines.launch | ||||
| import kotlinx.coroutines.withContext | ||||
| import org.mosad.teapod.MainActivity | ||||
| import org.mosad.teapod.R | ||||
| import org.mosad.teapod.parser.AoDParser | ||||
| import org.mosad.teapod.util.decoration.MediaItemDecoration | ||||
| import org.mosad.teapod.util.adapter.MediaItemAdapter | ||||
| import org.mosad.teapod.util.decoration.MediaItemDecoration | ||||
|  | ||||
| class LibraryFragment : Fragment() { | ||||
|  | ||||
|  | ||||
| @ -1,5 +1,10 @@ | ||||
| <vector android:height="24dp" android:tint="#FFFFFF" | ||||
|     android:viewportHeight="24" android:viewportWidth="24" | ||||
|     android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||||
|     <path android:fillColor="@android:color/white" android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/> | ||||
| <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="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" /> | ||||
| </vector> | ||||
|  | ||||
							
								
								
									
										10
									
								
								app/src/main/res/drawable/ic_baseline_autorenew_24.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								app/src/main/res/drawable/ic_baseline_autorenew_24.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:width="24dp" | ||||
|     android:height="24dp" | ||||
|     android:viewportWidth="24" | ||||
|     android:viewportHeight="24" | ||||
|     android:tint="?attr/colorControlNormal"> | ||||
|     <path | ||||
|         android:fillColor="@android:color/white" | ||||
|         android:pathData="M12,6v3l4,-4 -4,-4v3c-4.42,0 -8,3.58 -8,8 0,1.57 0.46,3.03 1.24,4.26L6.7,14.8c-0.45,-0.83 -0.7,-1.79 -0.7,-2.8 0,-3.31 2.69,-6 6,-6zM18.76,7.74L17.3,9.2c0.44,0.84 0.7,1.79 0.7,2.8 0,3.31 -2.69,6 -6,6v-3l-4,4 4,4v-3c4.42,0 8,-3.58 8,-8 0,-1.57 -0.46,-3.03 -1.24,-4.26z" /> | ||||
| </vector> | ||||
| @ -50,7 +50,7 @@ | ||||
|                         android:contentDescription="@string/account" | ||||
|                         android:minWidth="48dp" | ||||
|                         android:minHeight="48dp" | ||||
|                         android:padding="5dp" | ||||
|                         android:padding="9dp" | ||||
|                         android:scaleType="fitXY" | ||||
|                         android:src="@drawable/ic_baseline_account_box_24" | ||||
|                         app:srcCompat="@drawable/ic_baseline_account_box_24" /> | ||||
| @ -112,10 +112,10 @@ | ||||
|                         android:id="@+id/imageView3" | ||||
|                         android:layout_width="wrap_content" | ||||
|                         android:layout_height="wrap_content" | ||||
|                         android:contentDescription="@string/account" | ||||
|                         android:contentDescription="@string/settings_secondary" | ||||
|                         android:minWidth="48dp" | ||||
|                         android:minHeight="48dp" | ||||
|                         android:padding="5dp" | ||||
|                         android:padding="9dp" | ||||
|                         android:scaleType="fitXY" | ||||
|                         android:src="@drawable/ic_baseline_subtitles_24" /> | ||||
|  | ||||
| @ -164,6 +164,67 @@ | ||||
|  | ||||
|  | ||||
|                 </LinearLayout> | ||||
|  | ||||
|                 <LinearLayout | ||||
|                     android:id="@+id/linear_settings_autoplay" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="match_parent" | ||||
|                     android:layout_margin="7dp" | ||||
|                     android:gravity="center" | ||||
|                     android:orientation="horizontal"> | ||||
|  | ||||
|                     <ImageView | ||||
|                         android:id="@+id/imageView4" | ||||
|                         android:layout_width="wrap_content" | ||||
|                         android:layout_height="wrap_content" | ||||
|                         android:contentDescription="@string/settings_autoplay" | ||||
|                         android:minWidth="48dp" | ||||
|                         android:minHeight="48dp" | ||||
|                         android:padding="9dp" | ||||
|                         android:src="@drawable/ic_baseline_autorenew_24" /> | ||||
|  | ||||
|                     <androidx.constraintlayout.widget.ConstraintLayout | ||||
|                         android:layout_width="match_parent" | ||||
|                         android:layout_height="wrap_content"> | ||||
|  | ||||
|                         <LinearLayout | ||||
|                             android:id="@+id/linearLayout2" | ||||
|                             android:layout_width="0dp" | ||||
|                             android:layout_height="wrap_content" | ||||
|                             android:orientation="vertical" | ||||
|                             app:layout_constraintBottom_toBottomOf="parent" | ||||
|                             app:layout_constraintEnd_toStartOf="@+id/switch_autoplay" | ||||
|                             app:layout_constraintStart_toStartOf="parent" | ||||
|                             app:layout_constraintTop_toTopOf="parent"> | ||||
|  | ||||
|                             <TextView | ||||
|                                 android:id="@+id/text_settings_auoplay" | ||||
|                                 android:layout_width="match_parent" | ||||
|                                 android:layout_height="wrap_content" | ||||
|                                 android:text="@string/settings_autoplay" | ||||
|                                 android:textColor="@android:color/primary_text_light" | ||||
|                                 android:textSize="16sp" /> | ||||
|  | ||||
|                             <TextView | ||||
|                                 android:id="@+id/text_settings_auoplay_desc" | ||||
|                                 android:layout_width="match_parent" | ||||
|                                 android:layout_height="wrap_content" | ||||
|                                 android:text="@string/settings_autoplay_desc" | ||||
|                                 android:textColor="@android:color/secondary_text_light" /> | ||||
|                         </LinearLayout> | ||||
|  | ||||
|                         <com.google.android.material.switchmaterial.SwitchMaterial | ||||
|                             android:id="@+id/switch_autoplay" | ||||
|                             android:layout_width="wrap_content" | ||||
|                             android:layout_height="wrap_content" | ||||
|                             android:checked="true" | ||||
|                             app:layout_constraintBottom_toBottomOf="parent" | ||||
|                             app:layout_constraintEnd_toEndOf="parent" | ||||
|                             app:layout_constraintTop_toTopOf="parent" /> | ||||
|  | ||||
|                     </androidx.constraintlayout.widget.ConstraintLayout> | ||||
|                 </LinearLayout> | ||||
|  | ||||
|             </LinearLayout> | ||||
|  | ||||
|             <LinearLayout | ||||
| @ -200,7 +261,7 @@ | ||||
|                         android:contentDescription="@string/info" | ||||
|                         android:minWidth="48dp" | ||||
|                         android:minHeight="48dp" | ||||
|                         android:padding="5dp" | ||||
|                         android:padding="9dp" | ||||
|                         android:scaleType="fitXY" | ||||
|                         app:srcCompat="@drawable/ic_baseline_info_24" /> | ||||
|  | ||||
|  | ||||
| @ -29,6 +29,8 @@ | ||||
|     <string name="settings">Einstellungen</string> | ||||
|     <string name="settings_secondary">Bevorzuge alternativen Stream</string> | ||||
|     <string name="settings_secondary_desc">Untertitle-Stream verwenden, sofern vorhanden</string> | ||||
|     <string name="settings_autoplay">Autoplay</string> | ||||
|     <string name="settings_autoplay_desc">Nächste Episode automatisch abspielen</string> | ||||
|  | ||||
|     <!-- player --> | ||||
|     <string name="close_player">Player schließen</string> | ||||
|  | ||||
| @ -38,6 +38,8 @@ | ||||
|     <string name="settings">Settings</string> | ||||
|     <string name="settings_secondary">Prefer secondary (sub) stream</string> | ||||
|     <string name="settings_secondary_desc">Use the subtitles stream if present</string> | ||||
|     <string name="settings_autoplay">Autoplay</string> | ||||
|     <string name="settings_autoplay_desc">Play next episode automatically</string> | ||||
|  | ||||
|     <!-- player --> | ||||
|     <string name="close_player">close player</string> | ||||
| @ -64,6 +66,7 @@ | ||||
|     <string name="save_key_user_login" translatable="false">org.mosad.teapod.user_login</string> | ||||
|     <string name="save_key_user_password" translatable="false">org.mosad.teapod.user_password</string> | ||||
|     <string name="save_key_prefer_secondary" translatable="false">org.mosad.teapod.prefer_secondary</string> | ||||
|     <string name="save_key_autoplay" translatable="false">org.mosad.teapod.autoplay</string> | ||||
|  | ||||
|     <!-- intents & states --> | ||||
|     <string name="intent_media_id" translatable="false">intent_media_id</string> | ||||
|  | ||||
		Reference in New Issue
	
	Block a user