add language settings to player [Part 1]
This commit is contained in:
		| @ -250,7 +250,11 @@ object AoDParser { | ||||
|  | ||||
|             // if highlights is empty, add a random new title | ||||
|             if (highlightsList.isEmpty()) { | ||||
|                 highlightsList.add(newTitlesList[Random.nextInt(0, newTitlesList.size)]) | ||||
|                 if (newTitlesList.isNotEmpty()) { | ||||
|                     highlightsList.add(newTitlesList[Random.nextInt(0, newTitlesList.size)]) | ||||
|                 } else { | ||||
|                     highlightsList.add(ItemMedia(0,"", "")) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -30,6 +30,7 @@ import kotlinx.coroutines.withContext | ||||
| import org.mosad.teapod.R | ||||
| import org.mosad.teapod.preferences.Preferences | ||||
| import org.mosad.teapod.ui.components.EpisodesListPlayer | ||||
| import org.mosad.teapod.ui.components.LanguageSettingsPlayer | ||||
| import org.mosad.teapod.util.DataTypes | ||||
| import java.util.* | ||||
| import java.util.concurrent.TimeUnit | ||||
| @ -192,8 +193,9 @@ class PlayerActivity : AppCompatActivity() { | ||||
|         rwd_10.setOnButtonClickListener { rewind() } | ||||
|         ffwd_10.setOnButtonClickListener { fastForward() } | ||||
|         button_next_ep.setOnClickListener { playNextEpisode() } | ||||
|         button_next_ep_c.setOnClickListener { playNextEpisode() } | ||||
|         button_language.setOnClickListener { showLanguageSettings() } | ||||
|         button_episodes.setOnClickListener { showEpisodesList() } | ||||
|         button_next_ep_c.setOnClickListener { playNextEpisode() } | ||||
|     } | ||||
|  | ||||
|     private fun initTimeUpdates() { | ||||
| @ -395,6 +397,17 @@ class PlayerActivity : AppCompatActivity() { | ||||
|         } | ||||
|         player_layout.addView(episodesList) | ||||
|  | ||||
|         // hide player controls and pause playback | ||||
|         player.pause() | ||||
|         controller.hide() | ||||
|     } | ||||
|  | ||||
|     private fun showLanguageSettings() { | ||||
|         val languageSettings = LanguageSettingsPlayer(this, model = model).apply { | ||||
|             onViewRemovedAction = { player.play() } | ||||
|         } | ||||
|         player_layout.addView(languageSettings) | ||||
|  | ||||
|         // hide player controls and pause playback | ||||
|         player.pause() | ||||
|         controller.hideImmediately() | ||||
|  | ||||
| @ -65,6 +65,10 @@ class PlayerViewModel : ViewModel() { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fun changeLanguage(id: Int) { | ||||
|         println("new Language is ABC with id $id") | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * update currentEpisode, episodeId, nextEpisode to new episode | ||||
|      * updateWatchedState for the next (now current) episode | ||||
|  | ||||
| @ -0,0 +1,64 @@ | ||||
| package org.mosad.teapod.ui.components | ||||
|  | ||||
| import android.content.Context | ||||
| import android.graphics.Color | ||||
| import android.graphics.Typeface | ||||
| import android.util.AttributeSet | ||||
| import android.util.TypedValue | ||||
| import android.view.Gravity | ||||
| import android.view.LayoutInflater | ||||
| import android.view.ViewGroup | ||||
| import android.widget.LinearLayout | ||||
| import android.widget.TextView | ||||
| import org.mosad.teapod.R | ||||
| import org.mosad.teapod.databinding.PlayerLanguageSettingsBinding | ||||
| import org.mosad.teapod.player.PlayerViewModel | ||||
|  | ||||
| class LanguageSettingsPlayer @JvmOverloads constructor( | ||||
|     context: Context, | ||||
|     attrs: AttributeSet? = null, | ||||
|     defStyleAttr: Int = 0, | ||||
|     model: PlayerViewModel? = null | ||||
| ) : LinearLayout(context, attrs, defStyleAttr) { | ||||
|  | ||||
|     private val binding = PlayerLanguageSettingsBinding.inflate(LayoutInflater.from(context), this, true) | ||||
|     var onViewRemovedAction: (() -> Unit)? = null // TODO find a better solution for this | ||||
|  | ||||
|     init { | ||||
|         addLanguage("primary", true) { model?.changeLanguage(0) } | ||||
|         addLanguage("secondary", false ) { model?.changeLanguage(1) } | ||||
|  | ||||
|         binding.buttonCloseLanguageSettings.setOnClickListener { close() } | ||||
|         binding.buttonCancel.setOnClickListener { close() } | ||||
|     } | ||||
|  | ||||
|     private fun addLanguage(str: String, isSelected: Boolean, onClick: OnClickListener) { | ||||
|         val text = TextView(context).apply { | ||||
|             height = 96 | ||||
|             gravity = Gravity.CENTER_VERTICAL | ||||
|             text = str | ||||
|             setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f) | ||||
|  | ||||
|             if (isSelected) { | ||||
|                 setTextColor(context.resources.getColor(R.color.exo_white, context.theme)) | ||||
|                 setTypeface(null, Typeface.BOLD) | ||||
|                 setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_baseline_check_24, 0, 0, 0) | ||||
|                 compoundDrawablesRelative.getOrNull(0)?.setTint(Color.WHITE) | ||||
|                 compoundDrawablePadding = 12 | ||||
|             } else { | ||||
|                 setTextColor(context.resources.getColor(R.color.textPrimaryDark, context.theme)) | ||||
|                 setPadding(75, 0, 0, 0) | ||||
|             } | ||||
|  | ||||
|             setOnClickListener(onClick) | ||||
|         } | ||||
|  | ||||
|         binding.linearLanguages.addView(text) | ||||
|     } | ||||
|  | ||||
|     private fun close() { | ||||
|         (this.parent as ViewGroup).removeView(this) | ||||
|         onViewRemovedAction?.invoke() | ||||
|     } | ||||
|  | ||||
| } | ||||
| @ -1,11 +1,10 @@ | ||||
| <?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="wrap_content" | ||||
|     android:layout_height="match_parent" | ||||
|     android:orientation="vertical" | ||||
|     android:padding="7dp" > | ||||
|     android:padding="7dp"> | ||||
|  | ||||
|     <FrameLayout | ||||
|         android:layout_width="wrap_content" | ||||
|  | ||||
| @ -17,7 +17,8 @@ | ||||
|  | ||||
|         <ImageButton | ||||
|             android:id="@+id/exo_close_player" | ||||
|             style="@style/ExoStyledControls.Button.Center" | ||||
|             android:background="@android:color/transparent" | ||||
|             android:scaleType="fitXY" | ||||
|             android:layout_width="44dp" | ||||
|             android:layout_height="44dp" | ||||
|             android:contentDescription="@string/close_player" | ||||
| @ -119,15 +120,16 @@ | ||||
|         android:layout_marginBottom="7dp"> | ||||
|  | ||||
|         <com.google.android.material.button.MaterialButton | ||||
|             android:id="@+id/button_next_ep_c" | ||||
|             android:id="@+id/button_language" | ||||
|             style="@style/Widget.AppCompat.Button.Borderless" | ||||
|             android:layout_width="0dp" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:text="@string/episode" | ||||
|             android:layout_marginEnd="7dp" | ||||
|             android:text="@string/language" | ||||
|             android:textAllCaps="false" | ||||
|             app:icon="@drawable/ic_baseline_skip_next_24" | ||||
|             app:icon="@drawable/ic_baseline_subtitles_24" | ||||
|             app:layout_constraintBottom_toBottomOf="parent" | ||||
|             app:layout_constraintEnd_toEndOf="parent" | ||||
|             app:layout_constraintEnd_toStartOf="@+id/button_episodes" | ||||
|             app:layout_constraintTop_toTopOf="parent" /> | ||||
|  | ||||
|         <com.google.android.material.button.MaterialButton | ||||
| @ -142,6 +144,19 @@ | ||||
|             app:layout_constraintBottom_toBottomOf="parent" | ||||
|             app:layout_constraintEnd_toStartOf="@+id/button_next_ep_c" | ||||
|             app:layout_constraintTop_toTopOf="parent" /> | ||||
|  | ||||
|         <com.google.android.material.button.MaterialButton | ||||
|             android:id="@+id/button_next_ep_c" | ||||
|             style="@style/Widget.AppCompat.Button.Borderless" | ||||
|             android:layout_width="0dp" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:text="@string/episode" | ||||
|             android:textAllCaps="false" | ||||
|             app:icon="@drawable/ic_baseline_skip_next_24" | ||||
|             app:layout_constraintBottom_toBottomOf="parent" | ||||
|             app:layout_constraintEnd_toEndOf="parent" | ||||
|             app:layout_constraintTop_toTopOf="parent" /> | ||||
|  | ||||
|     </androidx.constraintlayout.widget.ConstraintLayout> | ||||
|  | ||||
| </FrameLayout> | ||||
| @ -4,7 +4,9 @@ | ||||
|     xmlns:tools="http://schemas.android.com/tools" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" | ||||
|     android:background="#73000000"> | ||||
|     android:background="#73000000" | ||||
|     android:clickable="true" | ||||
|     android:focusable="true"> | ||||
|  | ||||
|     <LinearLayout | ||||
|         android:id="@+id/linearLayout3" | ||||
| @ -20,7 +22,8 @@ | ||||
|  | ||||
|         <ImageButton | ||||
|             android:id="@+id/button_close_episodes_list" | ||||
|             style="@style/ExoStyledControls.Button.Center" | ||||
|             android:background="@android:color/transparent" | ||||
|             android:scaleType="fitXY" | ||||
|             android:layout_width="44dp" | ||||
|             android:layout_height="44dp" | ||||
|             android:contentDescription="@string/close_player" | ||||
|  | ||||
							
								
								
									
										99
									
								
								app/src/main/res/layout/player_language_settings.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								app/src/main/res/layout/player_language_settings.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,99 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" | ||||
|     android:background="#73000000" | ||||
|     android:clickable="true" | ||||
|     android:focusable="true"> | ||||
|  | ||||
|     <LinearLayout | ||||
|         android:id="@+id/linear_top" | ||||
|         android:layout_width="0dp" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_marginStart="12dp" | ||||
|         android:layout_marginTop="7dp" | ||||
|         android:layout_marginEnd="12dp" | ||||
|         android:gravity="center" | ||||
|         android:orientation="horizontal" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toTopOf="parent"> | ||||
|  | ||||
|         <ImageButton | ||||
|             android:id="@+id/button_close_language_settings" | ||||
|             android:background="@android:color/transparent" | ||||
|             android:scaleType="fitXY" | ||||
|             android:layout_width="44dp" | ||||
|             android:layout_height="44dp" | ||||
|             android:contentDescription="@string/close_player" | ||||
|             android:padding="10dp" | ||||
|             app:srcCompat="@drawable/ic_baseline_arrow_back_24" /> | ||||
|  | ||||
|         <TextView | ||||
|             android:id="@+id/exo_text_language" | ||||
|             android:layout_width="match_parent" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_marginEnd="44dp" | ||||
|             android:text="@string/language" | ||||
|             android:textAlignment="center" | ||||
|             android:textColor="@color/exo_white" | ||||
|             android:textSize="16sp" | ||||
|             android:textStyle="bold" /> | ||||
|  | ||||
|     </LinearLayout> | ||||
|  | ||||
|     <LinearLayout | ||||
|         android:id="@+id/linear_languages" | ||||
|         android:layout_width="0dp" | ||||
|         android:layout_height="0dp" | ||||
|         android:layout_marginStart="56dp" | ||||
|         android:layout_marginEnd="56dp" | ||||
|         android:orientation="vertical" | ||||
|         app:layout_constraintBottom_toTopOf="@+id/linear_bottom" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toBottomOf="@+id/linear_top" /> | ||||
|  | ||||
|     <LinearLayout | ||||
|         android:id="@+id/linear_bottom" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_marginStart="12dp" | ||||
|         android:layout_marginEnd="12dp" | ||||
|         android:layout_marginBottom="7dp" | ||||
|         android:gravity="end" | ||||
|         android:orientation="horizontal" | ||||
|         app:layout_constraintBottom_toBottomOf="parent" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintStart_toStartOf="parent"> | ||||
|  | ||||
|         <com.google.android.material.button.MaterialButton | ||||
|             android:id="@+id/button_cancel" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_marginEnd="7dp" | ||||
|             android:text="@string/cancel" | ||||
|             android:textAllCaps="false" | ||||
|             android:textColor="@color/exo_white" | ||||
|             android:textSize="16sp" | ||||
|             app:backgroundTint="@color/buttonBackgroundLight" | ||||
|             app:layout_constraintBottom_toBottomOf="parent" | ||||
|             app:layout_constraintEnd_toEndOf="parent" | ||||
|             app:layout_constraintTop_toTopOf="parent" /> | ||||
|  | ||||
|         <com.google.android.material.button.MaterialButton | ||||
|             android:id="@+id/button_select" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:text="@string/save" | ||||
|             android:textAllCaps="false" | ||||
|             android:textColor="@color/themePrimaryDark" | ||||
|             android:textSize="16sp" | ||||
|             app:backgroundTint="@color/buttonBackgroundDark" | ||||
|             app:layout_constraintBottom_toBottomOf="parent" | ||||
|             app:layout_constraintEnd_toEndOf="parent" | ||||
|             app:layout_constraintTop_toTopOf="parent" /> | ||||
|  | ||||
|     </LinearLayout> | ||||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||||
| @ -52,8 +52,9 @@ | ||||
|     <string name="play_pause">Abspielen/Pause</string> | ||||
|     <string name="forward_10">10 Sekunden vorwärts</string> | ||||
|     <string name="next_episode">Nächste Folge</string> | ||||
|     <string name="episode">Folge</string> | ||||
|     <string name="language">Sprache</string> | ||||
|     <string name="episodes">Folgen</string> | ||||
|     <string name="episode">Folge</string> | ||||
|  | ||||
|     <!-- dialogs --> | ||||
|     <string name="save">speichern</string> | ||||
|  | ||||
| @ -67,8 +67,9 @@ | ||||
|     <string name="next_episode">Next Episode</string> | ||||
|     <string name="time_min_sec" translatable="false">%1$02d:%2$02d</string> | ||||
|     <string name="time_hour_min_sec" translatable="false">%1$d:%2$02d:%3$02d</string> | ||||
|     <string name="episode">Episode</string> | ||||
|     <string name="language">Language</string> | ||||
|     <string name="episodes">Episodes</string> | ||||
|     <string name="episode">Episode</string> | ||||
|  | ||||
|     <!-- dialogs --> | ||||
|     <string name="save">save</string> | ||||
|  | ||||
		Reference in New Issue
	
	Block a user