Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(comments): show if creator replied #4955

Merged
merged 2 commits into from
Oct 12, 2023
Merged
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
16 changes: 4 additions & 12 deletions app/src/main/java/com/github/libretube/api/PipedApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ interface PipedApi {
): SegmentData

@GET("dearrow")
suspend fun getDeArrowContent(
@Query("videoIds") videoIds: String
): JsonObject
suspend fun getDeArrowContent(@Query("videoIds") videoIds: String): JsonObject

@GET("nextpage/comments/{videoId}")
suspend fun getCommentsNextPage(
Expand Down Expand Up @@ -116,14 +114,10 @@ interface PipedApi {
suspend fun getFeed(@Query("authToken") token: String?): List<StreamItem>

@GET("feed/unauthenticated")
suspend fun getUnauthenticatedFeed(
@Query("channels") channels: String
): List<StreamItem>
suspend fun getUnauthenticatedFeed(@Query("channels") channels: String): List<StreamItem>

@POST("feed/unauthenticated")
suspend fun getUnauthenticatedFeed(
@Body channels: List<String>
): List<StreamItem>
suspend fun getUnauthenticatedFeed(@Body channels: List<String>): List<StreamItem>

@GET("subscribed")
suspend fun isSubscribed(
Expand All @@ -140,9 +134,7 @@ interface PipedApi {
): List<Subscription>

@POST("subscriptions/unauthenticated")
suspend fun unauthenticatedSubscriptions(
@Body channels: List<String>
): List<Subscription>
suspend fun unauthenticatedSubscriptions(@Body channels: List<String>): List<Subscription>

@POST("subscribe")
suspend fun subscribe(
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/github/libretube/api/obj/Comment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ data class Comment(
val pinned: Boolean,
val thumbnail: String,
val verified: Boolean,
val replyCount: Long
val replyCount: Long,
val creatorReplied: Boolean = false
) : Parcelable
2 changes: 1 addition & 1 deletion app/src/main/java/com/github/libretube/api/obj/Streams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.github.libretube.extensions.toLocalDateSafe
import com.github.libretube.extensions.toMillis
import com.github.libretube.helpers.ProxyHelper
import com.github.libretube.parcelable.DownloadData
import kotlinx.serialization.Serializable
import kotlin.io.path.Path
import kotlinx.serialization.Serializable

@Serializable
data class Streams(
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/github/libretube/db/Converters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.github.libretube.db
import androidx.room.TypeConverter
import com.github.libretube.api.JsonHelper
import com.github.libretube.extensions.toLocalDateSafe
import kotlinx.datetime.LocalDate
import kotlinx.serialization.encodeToString
import java.nio.file.Path
import kotlin.io.path.Path
import kotlinx.datetime.LocalDate
import kotlinx.serialization.encodeToString

object Converters {
@TypeConverter
Expand Down
51 changes: 26 additions & 25 deletions app/src/main/java/com/github/libretube/db/DatabaseHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,34 @@ object DatabaseHelper {
videoId,
streams.toStreamItem(videoId)
)
suspend fun addToWatchHistory(
videoId: String,
stream: StreamItem
) = withContext(Dispatchers.IO) {
val watchHistoryItem = WatchHistoryItem(
videoId,
stream.title,
Instant.fromEpochMilliseconds(stream.uploaded)
.toLocalDateTime(TimeZone.currentSystemDefault()).date,
stream.uploaderName,
stream.uploaderUrl?.toID(),
stream.uploaderAvatar,
stream.thumbnail,
stream.duration
)
Database.watchHistoryDao().insert(watchHistoryItem)
val maxHistorySize = PreferenceHelper.getString(PreferenceKeys.WATCH_HISTORY_SIZE, "100")
if (maxHistorySize == "unlimited") {
return@withContext
}
suspend fun addToWatchHistory(videoId: String, stream: StreamItem) =
withContext(Dispatchers.IO) {
val watchHistoryItem = WatchHistoryItem(
videoId,
stream.title,
Instant.fromEpochMilliseconds(stream.uploaded)
.toLocalDateTime(TimeZone.currentSystemDefault()).date,
stream.uploaderName,
stream.uploaderUrl?.toID(),
stream.uploaderAvatar,
stream.thumbnail,
stream.duration
)
Database.watchHistoryDao().insert(watchHistoryItem)
val maxHistorySize = PreferenceHelper.getString(
PreferenceKeys.WATCH_HISTORY_SIZE,
"100"
)
if (maxHistorySize == "unlimited") {
return@withContext
}

// delete the first watch history entry if the limit is reached
val watchHistory = Database.watchHistoryDao().getAll()
if (watchHistory.size > maxHistorySize.toInt()) {
Database.watchHistoryDao().delete(watchHistory.first())
// delete the first watch history entry if the limit is reached
val watchHistory = Database.watchHistoryDao().getAll()
if (watchHistory.size > maxHistorySize.toInt()) {
Database.watchHistoryDao().delete(watchHistory.first())
}
}
}

suspend fun addToSearchHistory(searchHistoryItem: SearchHistoryItem) {
Database.searchHistoryDao().insert(searchHistoryItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import kotlinx.datetime.toLocalDate

fun LocalDate.toMillis() = this.atStartOfDayIn(TimeZone.UTC).toEpochMilliseconds()

fun String.toLocalDateSafe() = this.substring(0, 10).toLocalDate()
fun String.toLocalDateSafe() = this.substring(0, 10).toLocalDate()
11 changes: 2 additions & 9 deletions app/src/main/java/com/github/libretube/helpers/DashHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ object DashHelper {
val audioLocale: String? = null
)

fun createManifest(
streams: Streams,
supportsHdr: Boolean,
rewriteUrls: Boolean
): String {
fun createManifest(streams: Streams, supportsHdr: Boolean, rewriteUrls: Boolean): String {
val builder = builderFactory.newDocumentBuilder()

val doc = builder.newDocument()
Expand Down Expand Up @@ -173,10 +169,7 @@ object DashHelper {
return representation
}

private fun createSegmentBaseElement(
document: Document,
stream: PipedStream
): Element {
private fun createSegmentBaseElement(document: Document, stream: PipedStream): Element {
val segmentBase = document.createElement("SegmentBase")
segmentBase.setAttribute("indexRange", "${stream.indexStart}-${stream.indexEnd}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import com.github.libretube.ui.views.SingleViewTouchableMotionLayout
object NavigationHelper {
private val handler = Handler(Looper.getMainLooper())

fun navigateChannel(
context: Context,
channelId: String?
) {
fun navigateChannel(context: Context, channelId: String?) {
if (channelId == null) return

val activity = ContextHelper.unwrapActivity(context)
Expand Down Expand Up @@ -85,11 +82,7 @@ object NavigationHelper {
}
}

fun navigatePlaylist(
context: Context,
playlistId: String?,
playlistType: PlaylistType
) {
fun navigatePlaylist(context: Context, playlistId: String?, playlistType: PlaylistType) {
if (playlistId == null) return

val activity = ContextHelper.unwrapActivity(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ object NotificationHelper {
/**
* Enqueue the work manager task
*/
fun enqueueWork(
context: Context,
existingPeriodicWorkPolicy: ExistingPeriodicWorkPolicy
) {
fun enqueueWork(context: Context, existingPeriodicWorkPolicy: ExistingPeriodicWorkPolicy) {
// get the notification preferences
PreferenceHelper.initialize(context)
val notificationsEnabled = PreferenceHelper.getBoolean(
Expand Down
36 changes: 17 additions & 19 deletions app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ import com.github.libretube.enums.SbSkipOptions
import com.github.libretube.extensions.updateParameters
import com.github.libretube.obj.VideoStats
import com.github.libretube.util.TextUtils
import kotlinx.coroutines.runBlocking
import java.util.Locale
import java.util.concurrent.Executors
import kotlin.math.absoluteValue
import kotlin.math.roundToInt
import kotlinx.coroutines.runBlocking

object PlayerHelper {
private const val ACTION_MEDIA_CONTROL = "media_control"
Expand All @@ -65,11 +65,7 @@ object PlayerHelper {
/**
* Create a base64 encoded DASH stream manifest
*/
fun createDashSource(
streams: Streams,
context: Context,
disableProxy: Boolean
): Uri {
fun createDashSource(streams: Streams, context: Context, disableProxy: Boolean): Uri {
val manifest = DashHelper.createManifest(
streams,
DisplayHelper.supportsHdr(context),
Expand Down Expand Up @@ -330,10 +326,12 @@ object PlayerHelper {
)

fun shouldPlayNextVideo(isPlaylist: Boolean = false): Boolean {
return autoPlayEnabled || (isPlaylist && PreferenceHelper.getBoolean(
PreferenceKeys.AUTOPLAY_PLAYLISTS,
false
))
return autoPlayEnabled || (
isPlaylist && PreferenceHelper.getBoolean(
PreferenceKeys.AUTOPLAY_PLAYLISTS,
false
)
)
}

private val handleAudioFocus
Expand Down Expand Up @@ -547,9 +545,9 @@ object PlayerHelper {
if (currentPosition in segmentStart until segmentEnd) {
if (sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC ||
(
sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC_ONCE &&
!segment.skipped
)
sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC_ONCE &&
!segment.skipped
)
) {
if (sponsorBlockNotifications) {
runCatching {
Expand All @@ -561,9 +559,9 @@ object PlayerHelper {
segment.skipped = true
} else if (sponsorBlockConfig[segment.category] == SbSkipOptions.MANUAL ||
(
sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC_ONCE &&
segment.skipped
)
sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC_ONCE &&
segment.skipped
)
) {
return segment
}
Expand Down Expand Up @@ -747,9 +745,9 @@ object PlayerHelper {
*/
fun haveAudioTrackRoleFlagSet(@C.RoleFlags roleFlags: Int): Boolean {
return isFlagSet(roleFlags, C.ROLE_FLAG_DESCRIBES_VIDEO) ||
isFlagSet(roleFlags, C.ROLE_FLAG_DUB) ||
isFlagSet(roleFlags, C.ROLE_FLAG_MAIN) ||
isFlagSet(roleFlags, C.ROLE_FLAG_ALTERNATE)
isFlagSet(roleFlags, C.ROLE_FLAG_DUB) ||
isFlagSet(roleFlags, C.ROLE_FLAG_MAIN) ||
isFlagSet(roleFlags, C.ROLE_FLAG_ALTERNATE)
}

@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ object ThemeHelper {
/**
* Update the accent color of the app and apply dynamic colors if needed
*/
private fun updateAccentColor(
activity: AppCompatActivity
) {
private fun updateAccentColor(activity: AppCompatActivity) {
var accentColor = PreferenceHelper.getString(PreferenceKeys.ACCENT_COLOR, "")

// automatically choose an accent color on the first app startup
Expand Down Expand Up @@ -117,10 +115,8 @@ object ThemeHelper {
/**
* Get a color by a color resource attr
*/
fun getThemeColor(
context: Context,
colorCode: Int
) = MaterialColors.getColor(context, colorCode, Color.TRANSPARENT)
fun getThemeColor(context: Context, colorCode: Int) =
MaterialColors.getColor(context, colorCode, Color.TRANSPARENT)

/**
* Get the styled app name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import com.github.libretube.enums.FileType
import com.github.libretube.extensions.toAndroidUri
import com.github.libretube.extensions.updateParameters
import com.github.libretube.helpers.PlayerHelper
import com.github.libretube.helpers.PlayerHelper.loadPlaybackParams
import com.github.libretube.obj.PlayerNotificationData
import com.github.libretube.util.NowPlayingNotification
import com.github.libretube.util.NowPlayingNotification.Companion.PLAYER_NOTIFICATION_ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import com.github.libretube.extensions.toID
import com.github.libretube.extensions.updateParameters
import com.github.libretube.helpers.PlayerHelper
import com.github.libretube.helpers.PlayerHelper.checkForSegments
import com.github.libretube.helpers.PlayerHelper.loadPlaybackParams
import com.github.libretube.helpers.ProxyHelper
import com.github.libretube.obj.PlayerNotificationData
import com.github.libretube.parcelable.PlayerData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import com.github.libretube.ui.interfaces.TimeFrameReceiver
import com.github.libretube.ui.listeners.SeekbarPreviewListener
import com.github.libretube.ui.models.PlayerViewModel
import com.github.libretube.util.OfflineTimeFrameReceiver
import kotlin.io.path.exists
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.io.path.exists

@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
class OfflinePlayerActivity : BaseActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.github.libretube.util.TextUtils
class CommentsAdapter(
private val fragment: Fragment?,
private val videoId: String,
private val channelAvatar: String?,
private val comments: MutableList<Comment>,
private val isRepliesAdapter: Boolean = false,
private val handleLink: ((url: String) -> Unit)?,
Expand Down Expand Up @@ -80,6 +81,11 @@ class CommentsAdapter(
ImageHelper.loadImage(comment.thumbnail, commentorImage)
likesTextView.text = comment.likeCount.formatShort()

if (comment.creatorReplied && !channelAvatar.isNullOrBlank()) {
ImageHelper.loadImage(channelAvatar, creatorReplyImageView)
creatorReplyImageView.isVisible = true
}

if (comment.verified) verifiedImageView.isVisible = true
if (comment.pinned) pinnedImageView.isVisible = true
if (comment.hearted) heartedImageView.isVisible = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ class VideosAdapter(
}

val context = (
holder.videoRowBinding ?: holder.trendingRowBinding
holder.videoRowBinding ?: holder.trendingRowBinding
?: holder.allCaughtUpBinding
)!!.root.context
)!!.root.context
val activity = (context as BaseActivity)
val fragmentManager = activity.supportFragmentManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,10 @@ class ColorPickerDialog : DialogFragment(), SeekBar.OnSeekBarChangeListener {

// Add listener to text input
binding.colorHexInput.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(
s: CharSequence?,
start: Int,
count: Int,
after: Int
) = Unit

override fun onTextChanged(
s: CharSequence?,
start: Int,
before: Int,
count: Int
) = Unit
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) =
Unit

override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) = Unit

var isValid = true
var oldHex = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class ShareDialog : DialogFragment() {
var url = when {
shareObjectType == ShareObjectType.VIDEO && host == YOUTUBE_SHORT_URL -> "$YOUTUBE_SHORT_URL/$id"
shareObjectType == ShareObjectType.VIDEO -> "$host/watch?v=$id"
shareObjectType == ShareObjectType.PLAYLIST -> "${host}/playlist?list=$id"
else -> "${host}/channel/$id"
shareObjectType == ShareObjectType.PLAYLIST -> "$host/playlist?list=$id"
else -> "$host/channel/$id"
}

if (shareObjectType == ShareObjectType.VIDEO && binding.timeCodeSwitch.isChecked) {
Expand Down
Loading
Loading