This commit is contained in:
Bnyro 2022-06-13 16:15:02 +02:00
parent e813579e56
commit f74ef1e38c
7 changed files with 150 additions and 15 deletions

View File

@ -0,0 +1,48 @@
package com.github.libretube.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.obj.ChapterSegment
import com.google.android.exoplayer2.ExoPlayer
import com.squareup.picasso.Picasso
class ChaptersAdapter(
private val chapters: List<ChapterSegment>,
private val exoPlayer: ExoPlayer
) : RecyclerView.Adapter<ChaptersViewHolder>() {
val TAG = "ChaptersAdapter"
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChaptersViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val cell = layoutInflater.inflate(R.layout.chapter_column, parent, false)
return ChaptersViewHolder(cell)
}
override fun onBindViewHolder(holder: ChaptersViewHolder, position: Int) {
val chapter = chapters[position]
val chapterImage = holder.v.findViewById<ImageView>(R.id.chapter_image)
Picasso.get().load(chapter.image).fit().centerCrop().into(chapterImage)
val chapterTitle = holder.v.findViewById<TextView>(R.id.chapter_title)
chapterTitle.text = chapter.title
holder.v.setOnClickListener {
val chapterStart = chapter.start!!.toLong() * 1000 // multiply by thousand for ms -> s
exoPlayer.seekTo(chapterStart)
}
}
override fun getItemCount(): Int {
return chapters.size
}
}
class ChaptersViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
init {
}
}

View File

@ -43,6 +43,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.IS_DOWNLOAD_RUNNING
import com.github.libretube.MainActivity
import com.github.libretube.R
import com.github.libretube.adapters.ChaptersAdapter
import com.github.libretube.adapters.CommentsAdapter
import com.github.libretube.adapters.TrendingAdapter
import com.github.libretube.dialogs.AddtoPlaylistDialog
@ -597,8 +598,28 @@ class PlayerFragment : Fragment() {
}
private fun initializeChapters(chapters: List<ChapterSegment>) {
chapters.forEach { chapter ->
Log.e(TAG, chapter.title!!)
val chaptersToggle = view?.findViewById<LinearLayout>(R.id.chapters_toggle)
val chaptersRecView = view?.findViewById<RecyclerView>(R.id.chapters_recView)
val chaptersToggleText = view?.findViewById<TextView>(R.id.chapters_toggle_text)
val chaptersToggleArrow = view?.findViewById<ImageView>(R.id.chapters_toggle_arrow)
if (chapters.isNotEmpty()) {
chaptersToggle?.visibility = View.VISIBLE
chaptersToggle?.setOnClickListener {
if (chaptersRecView?.isVisible!!) {
chaptersRecView?.visibility = View.GONE
chaptersToggleText?.text = getString(R.string.show_chapters)
} else {
chaptersRecView?.visibility = View.VISIBLE
chaptersToggleText?.text = getString(R.string.hide_chapters)
}
chaptersToggleArrow!!.animate().setDuration(100).rotationBy(180F).start()
}
chaptersRecView?.layoutManager =
LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false)
chaptersRecView?.adapter = ChaptersAdapter(chapters, exoPlayer)
}
}

View File

@ -198,7 +198,6 @@ class SearchFragment : Fragment() {
lifecycleScope.launchWhenCreated {
isFetchingSearch = true
hideKeyboard()
Log.e("here", "here")
val response = try {
RetrofitInstance.api.getSearchResults(query, apiSearchFilter)
} catch (e: IOException) {

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_marginHorizontal="10dp"
android:layout_width="80dp"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/chapter_image"
android:layout_width="80dp"
android:layout_height="45dp"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/chapter_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:maxLines="3"
android:ellipsize="end"
android:text="Title"
android:textSize="13sp" />
</LinearLayout>

View File

@ -26,15 +26,16 @@
android:orientation="vertical">
<RelativeLayout
android:id="@+id/player_title_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/player_title_layout"
android:orientation="horizontal">
<TextView
android:id="@+id/player_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="30dp"
@ -54,14 +55,54 @@
</RelativeLayout>
<TextView
android:id="@+id/player_views_info"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<TextView
android:id="@+id/player_views_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10M views 2 days ago " />
<LinearLayout
android:id="@+id/chapters_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="@+id/chapters_toggle_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/show_chapters" />
<ImageView
android:id="@+id/chapters_toggle_arrow"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="bottom"
android:src="@drawable/ic_arrow_down" />
</LinearLayout>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/chapters_recView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/comments_toggle"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:text="10M views 2 days ago " />
android:nestedScrollingEnabled="false"
android:visibility="gone" />
<TextView
android:id="@+id/player_description"
@ -146,10 +187,10 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoSizeTextType="uniform"
android:gravity="center"
android:text="@string/download"
android:maxLines="1"
android:autoSizeTextType="uniform" />
android:text="@string/download" />
</LinearLayout>
<LinearLayout
@ -203,8 +244,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="15dp"
android:background="?android:attr/selectableItemBackground"
android:paddingLeft="8dp"
@ -294,10 +335,10 @@
android:id="@+id/comments_recView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_below="@id/comments_toggle"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:nestedScrollingEnabled="false"
android:visibility="gone" />

View File

@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:paddingVertical="6dp"
android:paddingVertical="8dp"
android:background="?android:attr/selectableItemBackground">
<ImageView

View File

@ -173,4 +173,6 @@
<string name="about_summary">Get to know team LibreTube and how it all happens.</string>
<string name="related_streams">Related streams</string>
<string name="related_streams_summary">Show related streams to videos.</string>
<string name="show_chapters">Show chapters</string>
<string name="hide_chapters">Hide chapters</string>
</resources>