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
706 changes: 706 additions & 0 deletions app/schemas/org.schabi.newpipe.database.AppDatabase/10.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion app/src/main/java/org/schabi/newpipe/NewPipeDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.schabi.newpipe.database.Migrations.MIGRATION_5_6
import org.schabi.newpipe.database.Migrations.MIGRATION_6_7
import org.schabi.newpipe.database.Migrations.MIGRATION_7_8
import org.schabi.newpipe.database.Migrations.MIGRATION_8_9
import org.schabi.newpipe.database.Migrations.MIGRATION_9_10

object NewPipeDatabase {

Expand All @@ -37,7 +38,8 @@ object NewPipeDatabase {
MIGRATION_5_6,
MIGRATION_6_7,
MIGRATION_7_8,
MIGRATION_8_9
MIGRATION_8_9,
MIGRATION_9_10
).build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import org.schabi.newpipe.database.subscription.SubscriptionEntity

@TypeConverters(Converters::class)
@Database(
version = Migrations.DB_VER_9,
version = Migrations.DB_VER_10,
entities = [
SubscriptionEntity::class,
SearchHistoryEntry::class,
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/org/schabi/newpipe/database/Migrations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object Migrations {
const val DB_VER_7 = 7
const val DB_VER_8 = 8
const val DB_VER_9 = 9
const val DB_VER_10 = 10

private val TAG = Migrations::class.java.getName()
private val isDebug = MainActivity.DEBUG
Expand Down Expand Up @@ -348,4 +349,20 @@ object Migrations {
db.endTransaction()
}
}

val MIGRATION_9_10 = Migration(DB_VER_9, DB_VER_10) { db ->
try {
db.beginTransaction()

// Create a new column content_availability
db.execSQL(
"ALTER TABLE `streams` ADD COLUMN `availability` " +
"TEXT NOT NULL DEFAULT 'UNKNOWN'"
)

db.setTransactionSuccessful()
} finally {
db.endTransaction()
}
}
}
24 changes: 17 additions & 7 deletions app/src/main/java/org/schabi/newpipe/database/feed/dao/FeedDAO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ abstract class FeedDAO {
abstract fun deleteAll(): Int

/**
* @param groupId the group id to get feed streams of; use
* [FeedGroupEntity.GROUP_ALL_ID] to not filter by group
* @param includePlayed if false, only return all of the live, never-played or non-finished
* feed streams (see `@see` items); if true no filter is applied
* @param uploadDateBefore get only streams uploaded before this date (useful to filter out
* future streams); use null to not filter by upload date
* @param groupId the group id to get feed streams of; use
* [FeedGroupEntity.GROUP_ALL_ID] to not filter by group
* @param includePlayed if false, only return all of the live, non-finished
* feed streams (see `@see` items); if true no filter is applied
* @param includePartiallyPlayed if false, only return all of the never-played
* feed streams (see `@see` items); if true no filter is applied
* @param uploadDateBefore get only streams uploaded before this date (useful to filter out
* future streams); use null to not filter by upload date
* @param includeMembersOnly if false, only return feed streams that are publicly accessible;
* if true no filter is applied
* @return the feed streams filtered according to the conditions provided in the parameters
* @see StreamStateEntity.isFinished()
* @see StreamStateEntity.PLAYBACK_FINISHED_END_MILLISECONDS
Expand Down Expand Up @@ -81,6 +85,11 @@ abstract class FeedDAO {
OR s.upload_date IS NULL
OR s.upload_date < :uploadDateBefore
)
AND (
:includeMembersOnly
OR (s.availability <> 'MEMBERSHIP'
AND s.availability <> 'PAID')
)

ORDER BY s.upload_date IS NULL DESC, s.upload_date DESC, s.uploader ASC
LIMIT 500
Expand All @@ -90,7 +99,8 @@ abstract class FeedDAO {
groupId: Long,
includePlayed: Boolean,
includePartiallyPlayed: Boolean,
uploadDateBefore: OffsetDateTime?
uploadDateBefore: OffsetDateTime?,
includeMembersOnly: Boolean
): Maybe<List<StreamWithState>>

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_SE
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_TABLE
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_URL
import org.schabi.newpipe.extractor.localization.DateWrapper
import org.schabi.newpipe.extractor.stream.ContentAvailability
import org.schabi.newpipe.extractor.stream.StreamInfo
import org.schabi.newpipe.extractor.stream.StreamInfoItem
import org.schabi.newpipe.extractor.stream.StreamType
Expand Down Expand Up @@ -52,6 +53,9 @@ data class StreamEntity(
@ColumnInfo(name = STREAM_THUMBNAIL_URL)
var thumbnailUrl: String? = null,

@ColumnInfo(name = STREAM_AVAILABILITY)
var contentAvailability: ContentAvailability = ContentAvailability.UNKNOWN,

@ColumnInfo(name = STREAM_VIEWS)
var viewCount: Long? = null,

Expand All @@ -69,7 +73,8 @@ data class StreamEntity(
serviceId = item.serviceId, url = item.url, title = item.name,
streamType = item.streamType, duration = item.duration, uploader = item.uploaderName,
uploaderUrl = item.uploaderUrl,
thumbnailUrl = ImageStrategy.imageListToDbUrl(item.thumbnails), viewCount = item.viewCount,
thumbnailUrl = ImageStrategy.imageListToDbUrl(item.thumbnails),
contentAvailability = item.contentAvailability, viewCount = item.viewCount,
textualUploadDate = item.textualUploadDate, uploadDate = item.uploadDate?.offsetDateTime(),
isUploadDateApproximation = item.uploadDate?.isApproximation
)
Expand All @@ -79,7 +84,8 @@ data class StreamEntity(
serviceId = info.serviceId, url = info.url, title = info.name,
streamType = info.streamType, duration = info.duration, uploader = info.uploaderName,
uploaderUrl = info.uploaderUrl,
thumbnailUrl = ImageStrategy.imageListToDbUrl(info.thumbnails), viewCount = info.viewCount,
thumbnailUrl = ImageStrategy.imageListToDbUrl(info.thumbnails),
contentAvailability = info.contentAvailability, viewCount = info.viewCount,
textualUploadDate = info.textualUploadDate, uploadDate = info.uploadDate?.offsetDateTime(),
isUploadDateApproximation = info.uploadDate?.isApproximation
)
Expand All @@ -102,6 +108,7 @@ data class StreamEntity(
item.uploaderName = uploader
item.uploaderUrl = uploaderUrl
item.thumbnails = ImageStrategy.dbUrlToImageList(thumbnailUrl)
item.contentAvailability = contentAvailability

if (viewCount != null) item.viewCount = viewCount as Long
item.textualUploadDate = textualUploadDate
Expand All @@ -123,6 +130,7 @@ data class StreamEntity(
const val STREAM_UPLOADER = "uploader"
const val STREAM_UPLOADER_URL = "uploader_url"
const val STREAM_THUMBNAIL_URL = "thumbnail_url"
const val STREAM_AVAILABILITY = "availability"

const val STREAM_VIEWS = "view_count"
const val STREAM_TEXTUAL_UPLOAD_DATE = "textual_upload_date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ class FeedDatabaseManager(context: Context) {
groupId: Long,
includePlayedStreams: Boolean,
includePartiallyPlayedStreams: Boolean,
includeFutureStreams: Boolean
includeFutureStreams: Boolean,
includeMembersOnlyStreams: Boolean
): Maybe<List<StreamWithState>> {
return feedTable.getStreams(
groupId,
includePlayedStreams,
includePartiallyPlayedStreams,
if (includeFutureStreams) null else OffsetDateTime.now()
if (includeFutureStreams) null else OffsetDateTime.now(),
includeMembersOnlyStreams
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,15 @@ class FeedFragment : BaseStateFragment<FeedState>() {
val dialogItems = arrayOf(
getString(R.string.feed_show_watched),
getString(R.string.feed_show_partially_watched),
getString(R.string.feed_show_upcoming)
getString(R.string.feed_show_upcoming),
getString(R.string.feed_show_members_only)
)

val checkedDialogItems = booleanArrayOf(
viewModel.getShowPlayedItemsFromPreferences(),
viewModel.getShowPartiallyPlayedItemsFromPreferences(),
viewModel.getShowFutureItemsFromPreferences()
viewModel.getShowFutureItemsFromPreferences(),
viewModel.getShowMembersOnlyItemsFromPreferences()
)

AlertDialog.Builder(requireContext())
Expand All @@ -264,6 +266,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
viewModel.setSaveShowPlayedItems(checkedDialogItems[0])
viewModel.setSaveShowPartiallyPlayedItems(checkedDialogItems[1])
viewModel.setSaveShowFutureItems(checkedDialogItems[2])
viewModel.setSaveShowMembersOnlyItems(checkedDialogItems[3])
}
.setNegativeButton(R.string.cancel, null)
.show()
Expand Down
44 changes: 33 additions & 11 deletions app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.lifecycle.viewmodel.viewModelFactory
import androidx.preference.PreferenceManager
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Flowable
import io.reactivex.rxjava3.functions.Function6
import io.reactivex.rxjava3.functions.Function7
import io.reactivex.rxjava3.processors.BehaviorProcessor
import io.reactivex.rxjava3.schedulers.Schedulers
import java.time.OffsetDateTime
Expand All @@ -33,7 +33,8 @@ class FeedViewModel(
groupId: Long = FeedGroupEntity.GROUP_ALL_ID,
initialShowPlayedItems: Boolean,
initialShowPartiallyPlayedItems: Boolean,
initialShowFutureItems: Boolean
initialShowFutureItems: Boolean,
initialShowMembersOnlyItems: Boolean
) : ViewModel() {
private val feedDatabaseManager = FeedDatabaseManager(application)

Expand All @@ -52,6 +53,11 @@ class FeedViewModel(
.startWithItem(initialShowFutureItems)
.distinctUntilChanged()

private val showMembersOnlyItems = BehaviorProcessor.create<Boolean>()
private val showMembersOnlyItemsFlowable = showMembersOnlyItems
.startWithItem(initialShowMembersOnlyItems)
.distinctUntilChanged()

private val mutableStateLiveData = MutableLiveData<FeedState>()
val stateLiveData: LiveData<FeedState> = mutableStateLiveData

Expand All @@ -61,27 +67,29 @@ class FeedViewModel(
showPlayedItemsFlowable,
showPartiallyPlayedItemsFlowable,
showFutureItemsFlowable,
showMembersOnlyItemsFlowable,
feedDatabaseManager.notLoadedCount(groupId),
feedDatabaseManager.oldestSubscriptionUpdate(groupId),

Function6 {
Function7 {
t1: FeedEventManager.Event,
t2: Boolean,
t3: Boolean,
t4: Boolean,
t5: Long,
t6: List<OffsetDateTime?>
t5: Boolean,
t6: Long,
t7: List<OffsetDateTime?>
->
return@Function6 CombineResultEventHolder(t1, t2, t3, t4, t5, t6.firstOrNull())
return@Function7 CombineResultEventHolder(t1, t2, t3, t4, t5, t6, t7.firstOrNull())
}
)
.throttleLatest(DEFAULT_THROTTLE_TIMEOUT, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.map { (event, showPlayedItems, showPartiallyPlayedItems, showFutureItems, notLoadedCount, oldestUpdate) ->
.map { (event, showPlayedItems, showPartiallyPlayedItems, showFutureItems, showMembersOnlyItems, notLoadedCount, oldestUpdate) ->
val streamItems = if (event is SuccessResultEvent || event is IdleEvent) {
feedDatabaseManager
.getStreams(groupId, showPlayedItems, showPartiallyPlayedItems, showFutureItems)
.getStreams(groupId, showPlayedItems, showPartiallyPlayedItems, showFutureItems, showMembersOnlyItems)
.blockingGet(arrayListOf())
} else {
arrayListOf()
Expand Down Expand Up @@ -115,8 +123,9 @@ class FeedViewModel(
val t2: Boolean,
val t3: Boolean,
val t4: Boolean,
val t5: Long,
val t6: OffsetDateTime?
val t5: Boolean,
val t6: Long,
val t7: OffsetDateTime?
)

private data class CombineResultDataHolder(
Expand Down Expand Up @@ -153,6 +162,15 @@ class FeedViewModel(

fun getShowFutureItemsFromPreferences() = getShowFutureItemsFromPreferences(application)

fun setSaveShowMembersOnlyItems(showMembersOnlyItems: Boolean) {
this.showMembersOnlyItems.onNext(showMembersOnlyItems)
PreferenceManager.getDefaultSharedPreferences(application).edit {
putBoolean(application.getString(R.string.feed_show_members_only_items_key), showMembersOnlyItems)
}
}

fun getShowMembersOnlyItemsFromPreferences() = getShowMembersOnlyItemsFromPreferences(application)

companion object {
private fun getShowPlayedItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.feed_show_watched_items_key), true)
Expand All @@ -163,6 +181,9 @@ class FeedViewModel(
private fun getShowFutureItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.feed_show_future_items_key), true)

private fun getShowMembersOnlyItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.feed_show_members_only_items_key), true)

fun getFactory(context: Context, groupId: Long) = viewModelFactory {
initializer {
FeedViewModel(
Expand All @@ -171,7 +192,8 @@ class FeedViewModel(
// Read initial value from preferences
getShowPlayedItemsFromPreferences(context.applicationContext),
getShowPartiallyPlayedItemsFromPreferences(context.applicationContext),
getShowFutureItemsFromPreferences(context.applicationContext)
getShowFutureItemsFromPreferences(context.applicationContext),
getShowMembersOnlyItemsFromPreferences(context.applicationContext)
)
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@
<string name="feed_show_watched_items_key">feed_show_played_items</string>
<string name="feed_show_partially_watched_items_key">feed_show_partially_watched_items</string>
<string name="feed_show_future_items_key">feed_show_future_items</string>
<string name="feed_show_members_only_items_key">feed_show_members_only_items</string>

<string name="show_thumbnail_key">show_thumbnail_key</string>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@
<string name="feed_show_watched">Fully watched</string>
<string name="feed_show_partially_watched">Partially watched</string>
<string name="feed_show_upcoming">Upcoming</string>
<string name="feed_show_members_only">Members only</string>
<string name="sort">Sort</string>
<string name="settings_category_exoplayer_title">ExoPlayer settings</string>
<string name="settings_category_exoplayer_summary">Manage some ExoPlayer settings. These changes require a player restart to take effect</string>
Expand Down
Loading