diff --git a/app/src/main/java/com/github/libretube/adapters/ChaptersAdapter.kt b/app/src/main/java/com/github/libretube/adapters/ChaptersAdapter.kt new file mode 100644 index 000000000..66a0d7247 --- /dev/null +++ b/app/src/main/java/com/github/libretube/adapters/ChaptersAdapter.kt @@ -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, + private val exoPlayer: ExoPlayer +) : RecyclerView.Adapter() { + 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(R.id.chapter_image) + Picasso.get().load(chapter.image).fit().centerCrop().into(chapterImage) + + val chapterTitle = holder.v.findViewById(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 { + } +} diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index cfec34244..224d31801 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -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) { - chapters.forEach { chapter -> - Log.e(TAG, chapter.title!!) + val chaptersToggle = view?.findViewById(R.id.chapters_toggle) + val chaptersRecView = view?.findViewById(R.id.chapters_recView) + val chaptersToggleText = view?.findViewById(R.id.chapters_toggle_text) + val chaptersToggleArrow = view?.findViewById(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) } } diff --git a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt index 63ddd43e4..a61714dd8 100644 --- a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt @@ -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) { diff --git a/app/src/main/res/layout/chapter_column.xml b/app/src/main/res/layout/chapter_column.xml new file mode 100644 index 000000000..4f5171ea4 --- /dev/null +++ b/app/src/main/res/layout/chapter_column.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index 2622e435a..212256b9e 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -26,15 +26,16 @@ android:orientation="vertical"> - + + + + + + + + + + + + + + + android:nestedScrollingEnabled="false" + android:visibility="gone" /> + android:text="@string/download" /> diff --git a/app/src/main/res/layout/searchsuggestion_row.xml b/app/src/main/res/layout/searchsuggestion_row.xml index 09200c426..c7d535866 100644 --- a/app/src/main/res/layout/searchsuggestion_row.xml +++ b/app/src/main/res/layout/searchsuggestion_row.xml @@ -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"> Get to know team LibreTube and how it all happens. Related streams Show related streams to videos. + Show chapters + Hide chapters