Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/src/main/java/com/github/libretube/api/ExternalApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ interface ExternalApi {
@Query("actionType") actionType: List<String>? = null
): List<SegmentData>

@GET("$SB_API_URL/api/videoLabels/{videoId}")
suspend fun getVideoLabels(
@Path("videoId") videoId: String,
): List<SegmentData>

@POST("$SB_API_URL/api/branding")
suspend fun submitDeArrow(@Body body: DeArrowBody)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.github.libretube.api.obj.SearchResult
import com.github.libretube.api.obj.SegmentData
import com.github.libretube.api.obj.StreamItem
import com.github.libretube.api.obj.Streams
import com.github.libretube.extensions.sha256Sum
import com.github.libretube.helpers.PlayerHelper

interface MediaServiceRepository {
Expand All @@ -21,6 +22,13 @@ interface MediaServiceRepository {
actionType: List<String>? = null
): SegmentData

suspend fun getVideoLabels(videoId: String
): SegmentData? = RetrofitInstance.externalApi.getVideoLabels(
// use hashed video id for privacy
// https://wiki.sponsor.ajay.app/w/API_Docs/Draft#GET_/api/videoLabels/:sha256HashPrefix
videoId.sha256Sum().substring(0, 4),
).firstOrNull { it.videoID == videoId }

suspend fun getDeArrowContent(videoIds: String): Map<String, DeArrowContent>
suspend fun getCommentsNextPage(videoId: String, nextPage: String): CommentsPage
suspend fun getSearchResults(searchQuery: String, filter: String): SearchResult
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/github/libretube/api/obj/Segment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data class Segment(
val category: String? = null,
val description: String? = null,
val locked: Int? = null,
private val segment: List<Float> = listOf(),
private val segment: List<Float> = listOf(0f, 0f),
val userID: String? = null,
val videoDuration: Double? = null,
val votes: Int? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.ListAdapter
import com.github.libretube.api.MediaServiceRepository
import com.github.libretube.api.obj.StreamItem
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.AllCaughtUpRowBinding
Expand All @@ -21,6 +23,10 @@ import com.github.libretube.ui.extensions.setWatchProgressLength
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.VideoCardsViewHolder
import com.github.libretube.util.TextUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class VideoCardsAdapter(private val columnWidthDp: Float? = null) :
ListAdapter<StreamItem, VideoCardsViewHolder>(DiffUtilItemCallback()) {
Expand Down Expand Up @@ -107,6 +113,14 @@ class VideoCardsAdapter(private val columnWidthDp: Float? = null) :
sheet.show(fragmentManager, VideoCardsAdapter::class.java.name)
true
}

CoroutineScope(Dispatchers.IO).launch {
val sponsor = runCatching { MediaServiceRepository.instance.getVideoLabels(videoId) }.getOrNull()

withContext(Dispatchers.Main) {
sponsorBadge.isVisible = sponsor?.segments?.isNotEmpty() == true
}
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions app/src/main/res/layout/trending_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />

<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_margin="5dp"
app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp"
app:cardElevation="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:id="@+id/sponsor_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="6dp"
android:paddingVertical="2dp"
android:src="@drawable/ic_block"
android:visibility="gone"
android:layout_gravity="center"
app:tint="@color/duration_text_color"
tools:ignore="RtlSymmetry"
tools:visibility="visible" />

</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
Loading