Merge pull request #1766 from Bnyro/master

Chapter time codes
This commit is contained in:
Bnyro 2022-11-05 18:03:37 +01:00 committed by GitHub
commit 26e876419d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 66 additions and 36 deletions

View File

@ -141,7 +141,7 @@ interface PipedApi {
suspend fun importPlaylist(
@Header("Authorization") token: String,
@Body playlistId: PlaylistId
): Message
): PlaylistId
@GET("user/playlists")
suspend fun playlists(@Header("Authorization") token: String): List<Playlists>

View File

@ -0,0 +1,16 @@
package com.github.libretube.extensions
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.widget.Toast
fun Context.toastFromMainThread(stringId: Int) {
Handler(Looper.getMainLooper()).post {
Toast.makeText(
this,
stringId,
Toast.LENGTH_SHORT
).show()
}
}

View File

@ -1,6 +1,7 @@
package com.github.libretube.ui.adapters
import android.graphics.Color
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
@ -27,15 +28,15 @@ class ChaptersAdapter(
holder.binding.apply {
ImageHelper.loadImage(chapter.image, chapterImage)
chapterTitle.text = chapter.title
timeStamp.text = chapter.start?.let { DateUtils.formatElapsedTime(it) }
if (selectedPosition == position) {
// get the color for highlighted controls
val color =
val color = if (selectedPosition == position) {
ThemeHelper.getThemeColor(root.context, android.R.attr.colorControlHighlight)
chapterLL.setBackgroundColor(color)
} else {
chapterLL.setBackgroundColor(Color.TRANSPARENT)
Color.TRANSPARENT
}
chapterLL.setBackgroundColor(color)
root.setOnClickListener {
updateSelectedPosition(position)
val chapterStart = chapter.start!! * 1000 // s -> ms

View File

@ -1,10 +1,7 @@
package com.github.libretube.ui.dialogs
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.ArrayAdapter
import android.widget.Toast
@ -18,6 +15,7 @@ import com.github.libretube.api.obj.PlaylistId
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.DialogAddtoplaylistBinding
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.toastFromMainThread
import com.github.libretube.models.PlaylistViewModel
import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.ThemeHelper
@ -104,30 +102,19 @@ class AddToPlaylistDialog : DialogFragment() {
} catch (e: IOException) {
println(e)
Log.e(TAG(), "IOException, you might not have internet connection")
toastFromMainThread(appContext, R.string.unknown_error)
appContext.toastFromMainThread(R.string.unknown_error)
return@launch
} catch (e: HttpException) {
Log.e(TAG(), "HttpException, unexpected response")
toastFromMainThread(appContext, R.string.server_error)
appContext.toastFromMainThread(R.string.server_error)
return@launch
}
toastFromMainThread(
appContext,
appContext.toastFromMainThread(
if (response.message == "ok") R.string.added_to_playlist else R.string.fail
)
}
}
private fun toastFromMainThread(context: Context, stringId: Int) {
Handler(Looper.getMainLooper()).post {
Toast.makeText(
context,
stringId,
Toast.LENGTH_SHORT
).show()
}
}
private fun Fragment?.runOnUiThread(action: () -> Unit) {
this ?: return
if (!isAdded) return // Fragment not attached to an Activity

View File

@ -991,10 +991,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer)
// enable the chapters dialog in the player
val titles = mutableListOf<String>()
chapters.forEach {
titles += it.title!!
}
val titles = chapters.map { "${it.title} (${it.start?.let { DateUtils.formatElapsedTime(it) }})" }
playerBinding.chapterLL.setOnClickListener {
if (viewModel.isFullscreen.value!!) {
MaterialAlertDialogBuilder(requireContext())

View File

@ -2,15 +2,14 @@ package com.github.libretube.ui.sheets
import android.os.Bundle
import android.text.InputType
import android.util.Log
import android.widget.Toast
import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.obj.PlaylistId
import com.github.libretube.constants.ShareObjectType
import com.github.libretube.databinding.DialogTextPreferenceBinding
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.toID
import com.github.libretube.extensions.toastFromMainThread
import com.github.libretube.obj.ShareData
import com.github.libretube.ui.dialogs.ShareDialog
import com.github.libretube.util.BackgroundHelper
@ -114,6 +113,7 @@ class PlaylistOptionsBottomSheet(
}
private fun importPlaylist(token: String, playlistId: String) {
val appContext = context?.applicationContext
CoroutineScope(Dispatchers.IO).launch {
val response = try {
RetrofitInstance.authApi.importPlaylist(
@ -126,7 +126,7 @@ class PlaylistOptionsBottomSheet(
} catch (e: HttpException) {
return@launch
}
Log.e(TAG(), response.toString())
appContext?.toastFromMainThread(if (response.playlistId != null) R.string.playlistCloned else R.string.server_error)
}
}

View File

@ -15,12 +15,40 @@
android:orientation="vertical"
android:paddingHorizontal="5dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="55dp">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/chapter_image"
android:layout_width="match_parent"
android:layout_height="55dp"
android:src="@mipmap/ic_launcher"
app:shapeAppearanceOverlay="@style/roundedImageViewRounded" />
android:layout_height="match_parent"
app:shapeAppearanceOverlay="@style/roundedImageViewRounded"
tools:src="@tools:sample/backgrounds/scenic" />
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp"
app:cardElevation="0dp">
<TextView
android:id="@+id/timeStamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="2dp"
android:textColor="@color/duration_text_color"
android:textSize="10sp"
tools:ignore="SmallSp"
tools:text="05:36" />
</androidx.cardview.widget.CardView>
</FrameLayout>
<TextView
android:id="@+id/chapter_title"

View File

@ -355,6 +355,7 @@
<string name="livestreams">Livestreams</string>
<string name="alternative_videos_layout">Alternative videos layout</string>
<string name="defaultIconLight">Default light</string>
<string name="playlistCloned">Playlist cloned</string>
<!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string>