| @ -58,6 +58,7 @@ dependencies { | |||||||
|     implementation 'com.github.bumptech.glide:glide:4.11.0' |     implementation 'com.github.bumptech.glide:glide:4.11.0' | ||||||
|     implementation 'com.afollestad.material-dialogs:core:3.3.0' |     implementation 'com.afollestad.material-dialogs:core:3.3.0' | ||||||
|     implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0' |     implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0' | ||||||
|  |     implementation 'androidx.legacy:legacy-support-v4:1.0.0' | ||||||
|  |  | ||||||
|     testImplementation 'junit:junit:4.12' |     testImplementation 'junit:junit:4.12' | ||||||
|     androidTestImplementation 'androidx.test.ext:junit:1.1.2' |     androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||||||
|  | |||||||
| @ -6,18 +6,22 @@ import androidx.fragment.app.Fragment | |||||||
| import android.view.LayoutInflater | import android.view.LayoutInflater | ||||||
| import android.view.View | import android.view.View | ||||||
| import android.view.ViewGroup | import android.view.ViewGroup | ||||||
| import android.widget.ArrayAdapter | import androidx.recyclerview.widget.LinearLayoutManager | ||||||
|  | import androidx.recyclerview.widget.RecyclerView | ||||||
| import com.bumptech.glide.Glide | import com.bumptech.glide.Glide | ||||||
| import kotlinx.android.synthetic.main.fragment_media.* | import kotlinx.android.synthetic.main.fragment_media.* | ||||||
| import org.mosad.teapod.MainActivity | import org.mosad.teapod.MainActivity | ||||||
| import org.mosad.teapod.R | import org.mosad.teapod.R | ||||||
| import org.mosad.teapod.util.DataTypes.MediaType | import org.mosad.teapod.util.DataTypes.MediaType | ||||||
|  | import org.mosad.teapod.util.EpisodesAdapter | ||||||
| import org.mosad.teapod.util.GUIMedia | import org.mosad.teapod.util.GUIMedia | ||||||
| import org.mosad.teapod.util.StreamMedia | import org.mosad.teapod.util.StreamMedia | ||||||
|  |  | ||||||
| class MediaFragment(private val guiMedia: GUIMedia, private val streamMedia: StreamMedia) : Fragment() { | class MediaFragment(private val guiMedia: GUIMedia, private val streamMedia: StreamMedia) : Fragment() { | ||||||
|  |  | ||||||
|     private lateinit var adapterEpisodes: ArrayAdapter<String> |     private lateinit var adapterRecEpisodes: EpisodesAdapter | ||||||
|  |     private lateinit var viewManager: RecyclerView.LayoutManager | ||||||
|  |  | ||||||
|  |  | ||||||
|     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||||||
|         return inflater.inflate(R.layout.fragment_media, container, false) |         return inflater.inflate(R.layout.fragment_media, container, false) | ||||||
| @ -37,11 +41,14 @@ class MediaFragment(private val guiMedia: GUIMedia, private val streamMedia: Str | |||||||
|                 "${guiMedia.title} - Ep. ${index + 1}" |                 "${guiMedia.title} - Ep. ${index + 1}" | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             adapterEpisodes = ArrayAdapter(requireContext(), android.R.layout.simple_list_item_1, episodes) |  | ||||||
|             list_episodes.adapter = adapterEpisodes |             adapterRecEpisodes = EpisodesAdapter(episodes) | ||||||
|  |             viewManager = LinearLayoutManager(context) | ||||||
|  |             recycler_episodes.layoutManager = viewManager | ||||||
|  |             recycler_episodes.adapter = adapterRecEpisodes | ||||||
|  |  | ||||||
|         } else if (streamMedia.type == MediaType.MOVIE) { |         } else if (streamMedia.type == MediaType.MOVIE) { | ||||||
|             list_episodes.visibility = View.GONE |             recycler_episodes.visibility = View.GONE | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |  | ||||||
| @ -55,8 +62,11 @@ class MediaFragment(private val guiMedia: GUIMedia, private val streamMedia: Str | |||||||
|             onClickButtonPlay() |             onClickButtonPlay() | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         list_episodes.setOnItemClickListener { _, _, position, _ -> |         // set onItemClick only in adapter is initialized | ||||||
|             playStream(streamMedia.streams[position]) |         if (this::adapterRecEpisodes.isInitialized) { | ||||||
|  |             adapterRecEpisodes.onItemClick = { item, position -> | ||||||
|  |                 playStream(streamMedia.streams[position]) | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -8,6 +8,7 @@ class DataTypes { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // TODO rework: add type, episodes list with episode title, if type == MOVIE the first episode will be the movie stream | ||||||
| data class GUIMedia(val title: String, val posterLink: String, val shortDesc : String, val link: String) { | data class GUIMedia(val title: String, val posterLink: String, val shortDesc : String, val link: String) { | ||||||
|     override fun toString(): String { |     override fun toString(): String { | ||||||
|         return title |         return title | ||||||
|  | |||||||
							
								
								
									
										35
									
								
								app/src/main/java/org/mosad/teapod/util/EpisodesAdapter.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								app/src/main/java/org/mosad/teapod/util/EpisodesAdapter.kt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | |||||||
|  | package org.mosad.teapod.util | ||||||
|  |  | ||||||
|  | import android.view.LayoutInflater | ||||||
|  | import android.view.View | ||||||
|  | import android.view.ViewGroup | ||||||
|  | import androidx.recyclerview.widget.RecyclerView | ||||||
|  | import kotlinx.android.synthetic.main.component_episode.view.* | ||||||
|  | import org.mosad.teapod.R | ||||||
|  |  | ||||||
|  | class EpisodesAdapter(private val data: List<String>) : RecyclerView.Adapter<EpisodesAdapter.MyViewHolder>() { | ||||||
|  |  | ||||||
|  |     var onItemClick: ((String, Int) -> Unit)? = null | ||||||
|  |  | ||||||
|  |     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { | ||||||
|  |         val view = LayoutInflater.from(parent.context).inflate(R.layout.component_episode, parent, false) | ||||||
|  |  | ||||||
|  |         return MyViewHolder(view) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     override fun onBindViewHolder(holder: MyViewHolder, position: Int) { | ||||||
|  |         holder.view .text_episode_title.text = data[position] | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     override fun getItemCount(): Int { | ||||||
|  |         return data.size | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     inner class MyViewHolder(val view: View) : RecyclerView.ViewHolder(view) { | ||||||
|  |         init { | ||||||
|  |             view.setOnClickListener { | ||||||
|  |                 onItemClick?.invoke(data[adapterPosition], adapterPosition) | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										40
									
								
								app/src/main/res/layout/component_episode.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								app/src/main/res/layout/component_episode.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,40 @@ | |||||||
|  | <?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" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="wrap_content" | ||||||
|  |     android:orientation="vertical" | ||||||
|  |     android:paddingStart="5dp" | ||||||
|  |     android:paddingTop="7dp" | ||||||
|  |     android:paddingEnd="5dp" | ||||||
|  |     android:paddingBottom="7dp"> | ||||||
|  |  | ||||||
|  |     <LinearLayout | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:orientation="horizontal"> | ||||||
|  |  | ||||||
|  |         <ImageView | ||||||
|  |             android:id="@+id/image_episode" | ||||||
|  |             android:layout_width="wrap_content" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:minWidth="48dp" | ||||||
|  |             app:srcCompat="@drawable/ic_baseline_account_box_24" /> | ||||||
|  |  | ||||||
|  |         <TextView | ||||||
|  |             android:id="@+id/text_episode_title" | ||||||
|  |             android:layout_width="match_parent" | ||||||
|  |             android:layout_height="match_parent" | ||||||
|  |             android:layout_marginStart="7dp" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:text="TextView" | ||||||
|  |             android:textSize="16sp" /> | ||||||
|  |     </LinearLayout> | ||||||
|  |  | ||||||
|  |     <TextView | ||||||
|  |         android:id="@+id/text_episode_desc" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:text="TextView" /> | ||||||
|  | </LinearLayout> | ||||||
| @ -7,73 +7,75 @@ | |||||||
|     android:background="#f5f5f5" |     android:background="#f5f5f5" | ||||||
|     tools:context=".ui.MediaFragment"> |     tools:context=".ui.MediaFragment"> | ||||||
|  |  | ||||||
|     <androidx.constraintlayout.widget.ConstraintLayout |     <androidx.core.widget.NestedScrollView | ||||||
|         android:layout_width="match_parent" |         android:layout_width="match_parent" | ||||||
|         android:layout_height="match_parent"> |         android:layout_height="match_parent" | ||||||
|  |         android:fillViewport="true"> | ||||||
|  |  | ||||||
|         <ImageView |         <LinearLayout | ||||||
|             android:id="@+id/image_poster" |  | ||||||
|             android:layout_width="wrap_content" |  | ||||||
|             android:layout_height="108dp" |  | ||||||
|             android:layout_marginTop="40dp" |  | ||||||
|             android:src="@drawable/ic_launcher_background" |  | ||||||
|             app:layout_constraintEnd_toEndOf="parent" |  | ||||||
|             app:layout_constraintStart_toStartOf="parent" |  | ||||||
|             app:layout_constraintTop_toTopOf="parent" /> |  | ||||||
|  |  | ||||||
|         <Button |  | ||||||
|             android:id="@+id/button_play" |  | ||||||
|             android:layout_width="0dp" |  | ||||||
|             android:layout_height="wrap_content" |  | ||||||
|             android:layout_marginStart="7dp" |  | ||||||
|             android:layout_marginTop="24dp" |  | ||||||
|             android:layout_marginEnd="7dp" |  | ||||||
|             android:background="#4A4141" |  | ||||||
|             android:drawableStart="@drawable/ic_baseline_play_arrow_24" |  | ||||||
|             android:drawablePadding="10dp" |  | ||||||
|             android:drawableTint="#FFFFFF" |  | ||||||
|             android:gravity="left|center_vertical" |  | ||||||
|             android:paddingStart="160dp" |  | ||||||
|             android:paddingEnd="160dp" |  | ||||||
|             android:text="@string/button_play" |  | ||||||
|             android:textAllCaps="false" |  | ||||||
|             android:textColor="@android:color/primary_text_dark" |  | ||||||
|             android:textSize="16sp" |  | ||||||
|             app:layout_constraintEnd_toEndOf="parent" |  | ||||||
|             app:layout_constraintStart_toStartOf="parent" |  | ||||||
|             app:layout_constraintTop_toBottomOf="@+id/image_poster" /> |  | ||||||
|  |  | ||||||
|         <TextView |  | ||||||
|             android:id="@+id/text_title" |  | ||||||
|             android:layout_width="wrap_content" |  | ||||||
|             android:layout_height="19dp" |  | ||||||
|             android:layout_marginStart="7dp" |  | ||||||
|             android:layout_marginTop="12dp" |  | ||||||
|             android:layout_marginEnd="7dp" |  | ||||||
|             android:text="TextView" |  | ||||||
|             android:textStyle="bold" |  | ||||||
|             app:layout_constraintEnd_toEndOf="parent" |  | ||||||
|             app:layout_constraintStart_toStartOf="parent" |  | ||||||
|             app:layout_constraintTop_toBottomOf="@+id/button_play" /> |  | ||||||
|  |  | ||||||
|         <TextView |  | ||||||
|             android:id="@+id/text_desc" |  | ||||||
|             android:layout_width="0dp" |  | ||||||
|             android:layout_height="wrap_content" |  | ||||||
|             android:layout_marginStart="17dp" |  | ||||||
|             android:layout_marginTop="10dp" |  | ||||||
|             android:layout_marginEnd="17dp" |  | ||||||
|             android:text="TextView" |  | ||||||
|             app:layout_constraintEnd_toEndOf="parent" |  | ||||||
|             app:layout_constraintStart_toStartOf="parent" |  | ||||||
|             app:layout_constraintTop_toBottomOf="@+id/text_title" /> |  | ||||||
|  |  | ||||||
|         <ListView |  | ||||||
|             android:id="@+id/list_episodes" |  | ||||||
|             android:layout_width="match_parent" |             android:layout_width="match_parent" | ||||||
|             android:layout_height="0dp" |             android:layout_height="wrap_content" | ||||||
|             android:layout_marginTop="17dp" |             android:orientation="vertical" > | ||||||
|             app:layout_constraintBottom_toBottomOf="parent" |  | ||||||
|             app:layout_constraintTop_toBottomOf="@+id/text_desc" /> |             <ImageView | ||||||
|     </androidx.constraintlayout.widget.ConstraintLayout> |                 android:id="@+id/image_poster" | ||||||
|  |                 android:layout_width="wrap_content" | ||||||
|  |                 android:layout_height="108dp" | ||||||
|  |                 android:layout_gravity="center" | ||||||
|  |                 android:layout_marginTop="40dp" | ||||||
|  |                 android:src="@drawable/ic_launcher_background" | ||||||
|  |                 /> | ||||||
|  |  | ||||||
|  |             <Button | ||||||
|  |                 android:id="@+id/button_play" | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:layout_gravity="center" | ||||||
|  |                 android:layout_marginStart="7dp" | ||||||
|  |                 android:layout_marginTop="24dp" | ||||||
|  |                 android:layout_marginEnd="7dp" | ||||||
|  |                 android:background="#4A4141" | ||||||
|  |                 android:drawableStart="@drawable/ic_baseline_play_arrow_24" | ||||||
|  |                 android:drawablePadding="10dp" | ||||||
|  |                 android:drawableTint="#FFFFFF" | ||||||
|  |                 android:gravity="start|center_vertical" | ||||||
|  |                 android:paddingStart="160dp" | ||||||
|  |                 android:paddingEnd="160dp" | ||||||
|  |                 android:text="@string/button_play" | ||||||
|  |                 android:textAllCaps="false" | ||||||
|  |                 android:textColor="@android:color/primary_text_dark" | ||||||
|  |                 android:textSize="16sp" /> | ||||||
|  |  | ||||||
|  |             <TextView | ||||||
|  |                 android:id="@+id/text_title" | ||||||
|  |                 android:layout_width="wrap_content" | ||||||
|  |                 android:layout_height="19dp" | ||||||
|  |                 android:layout_gravity="center" | ||||||
|  |                 android:layout_marginStart="7dp" | ||||||
|  |                 android:layout_marginTop="12dp" | ||||||
|  |                 android:layout_marginEnd="7dp" | ||||||
|  |                 android:text="TextView" | ||||||
|  |                 android:textStyle="bold" /> | ||||||
|  |  | ||||||
|  |             <TextView | ||||||
|  |                 android:id="@+id/text_desc" | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:layout_gravity="center" | ||||||
|  |                 android:layout_marginStart="7dp" | ||||||
|  |                 android:layout_marginTop="10dp" | ||||||
|  |                 android:layout_marginEnd="7dp" | ||||||
|  |                 android:text="TextView" /> | ||||||
|  |  | ||||||
|  |             <androidx.recyclerview.widget.RecyclerView | ||||||
|  |                 android:id="@+id/recycler_episodes" | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:layout_marginStart="7dp" | ||||||
|  |                 android:layout_marginTop="17dp" | ||||||
|  |                 android:layout_marginEnd="7dp" | ||||||
|  |                 tools:layout_editor_absoluteY="298dp" /> | ||||||
|  |         </LinearLayout> | ||||||
|  |     </androidx.core.widget.NestedScrollView> | ||||||
|  |  | ||||||
| </FrameLayout> | </FrameLayout> | ||||||
		Reference in New Issue
	
	Block a user