Skip to content

Commit

Permalink
Convert new and important files to Kotlin and optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
snaik20 committed Sep 3, 2024
1 parent 17f8fb5 commit 1498cc0
Show file tree
Hide file tree
Showing 12 changed files with 1,035 additions and 1,053 deletions.
13 changes: 0 additions & 13 deletions app/src/main/java/org/schabi/newpipe/database/LocalItem.java

This file was deleted.

18 changes: 18 additions & 0 deletions app/src/main/java/org/schabi/newpipe/database/LocalItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.schabi.newpipe.database

/**
* Represents a generic item that can be stored locally. This can be a playlist, a stream, etc.
*/
interface LocalItem {
/**
* The type of local item. Can be null if the type is unknown or not applicable.
*/
val localItemType: LocalItemType?

enum class LocalItemType {
PLAYLIST_LOCAL_ITEM,
PLAYLIST_REMOTE_ITEM,
PLAYLIST_STREAM_ITEM,
STATISTIC_STREAM_ITEM,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,16 @@ data class StreamHistoryEntry(
accessDate.isEqual(other.accessDate)
}

fun toStreamInfoItem(): StreamInfoItem {
val item = StreamInfoItem(
fun toStreamInfoItem(): StreamInfoItem =
StreamInfoItem(
streamEntity.serviceId,
streamEntity.url,
streamEntity.title,
streamEntity.streamType
)
item.duration = streamEntity.duration
item.uploaderName = streamEntity.uploader
item.uploaderUrl = streamEntity.uploaderUrl
item.thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl)

return item
}
streamEntity.streamType,
).apply {
duration = streamEntity.duration
uploaderName = streamEntity.uploader
uploaderUrl = streamEntity.uploaderUrl
thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.schabi.newpipe.database.playlist

import org.schabi.newpipe.database.LocalItem

/**
* Represents a playlist item stored locally.
*/
interface PlaylistLocalItem : LocalItem {
/**
* The name used for ordering this item within the playlist. Can be null.
*/
val orderingName: String?

/**
* The index used to display this item within the playlist.
*/
var displayIndex: Long

/**
* The unique identifier for this playlist item.
*/
val uid: Long

/**
* The URL of the thumbnail image for this playlist item. Can be null.
*/
val thumbnailUrl: String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ data class PlaylistStreamEntry(
@ColumnInfo(name = PlaylistStreamEntity.JOIN_INDEX)
val joinIndex: Int
) : LocalItem {

@Throws(IllegalArgumentException::class)
fun toStreamInfoItem(): StreamInfoItem {
val item = StreamInfoItem(streamEntity.serviceId, streamEntity.url, streamEntity.title, streamEntity.streamType)
item.duration = streamEntity.duration
item.uploaderName = streamEntity.uploader
item.uploaderUrl = streamEntity.uploaderUrl
item.thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl)

return item
}

override fun getLocalItemType(): LocalItem.LocalItemType {
return LocalItem.LocalItemType.PLAYLIST_STREAM_ITEM
}
fun toStreamInfoItem() =
StreamInfoItem(
streamEntity.serviceId,
streamEntity.url,
streamEntity.title,
streamEntity.streamType,
).apply {
duration = streamEntity.duration
uploaderName = streamEntity.uploader
uploaderUrl = streamEntity.uploaderUrl
thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl)
}

override val localItemType: LocalItem.LocalItemType
get() = LocalItem.LocalItemType.PLAYLIST_STREAM_ITEM
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ class StreamStatisticsEntry(
@ColumnInfo(name = STREAM_WATCH_COUNT)
val watchCount: Long
) : LocalItem {
fun toStreamInfoItem(): StreamInfoItem {
val item = StreamInfoItem(streamEntity.serviceId, streamEntity.url, streamEntity.title, streamEntity.streamType)
item.duration = streamEntity.duration
item.uploaderName = streamEntity.uploader
item.uploaderUrl = streamEntity.uploaderUrl
item.thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl)

return item
}

override fun getLocalItemType(): LocalItem.LocalItemType {
return LocalItem.LocalItemType.STATISTIC_STREAM_ITEM
}
fun toStreamInfoItem() =
StreamInfoItem(
streamEntity.serviceId,
streamEntity.url,
streamEntity.title,
streamEntity.streamType,
).apply {
duration = streamEntity.duration
uploaderName = streamEntity.uploader
uploaderUrl = streamEntity.uploaderUrl
thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl)
}

override val localItemType: LocalItem.LocalItemType
get() = LocalItem.LocalItemType.STATISTIC_STREAM_ITEM

companion object {
const val STREAM_LATEST_DATE = "latestAccess"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import static org.schabi.newpipe.util.ListHelper.getPopupResolutionIndex;
import static org.schabi.newpipe.util.ListHelper.getResolutionIndex;
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

import android.content.BroadcastReceiver;
Expand Down Expand Up @@ -417,7 +418,7 @@ public void handleIntent(@NonNull final Intent intent) {
}
if (playQueue.getIndex() != newQueue.getIndex()) {
simpleExoPlayer.seekTo(newQueue.getIndex(),
newQueue.getItem().getRecoveryPosition());
requireNonNull(newQueue.getItem()).getRecoveryPosition());
}
simpleExoPlayer.setPlayWhenReady(playWhenReady);

Expand Down
Loading

0 comments on commit 1498cc0

Please sign in to comment.