Skip to content

Commit

Permalink
-Revamped local items to display more information such as service nam…
Browse files Browse the repository at this point in the history
…e, etc.

-Enabled reordering, renaming, removing of items on playlist fragment.
-Enabled removal of dangling streams entries when history is cleared.
-Changed playlist append menu item to icon on service player activity.
-Added adapter and builder for local items, removed dependency on infoitem and existing infolist for database entry items.
-Removed watch history entity and DAO.
-Extracted info item selected listener to remove adding boilerplate code when long click functionality is optional.
-Fixed query returning no record on left join when right table is empty.
  • Loading branch information
karyogamy committed Jan 28, 2018
1 parent 0d39ff9 commit 26aea7b
Show file tree
Hide file tree
Showing 38 changed files with 1,224 additions and 506 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/org/schabi/newpipe/database/LocalItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.schabi.newpipe.database;

public interface LocalItem {
enum LocalItemType {
PLAYLIST_ITEM,
PLAYLIST_STREAM_ITEM,
STATISTIC_STREAM_ITEM
}

LocalItemType getLocalItemType();
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import android.arch.persistence.room.ColumnInfo;

import org.schabi.newpipe.database.LocalItem;
import org.schabi.newpipe.info_list.stored.LocalPlaylistInfoItem;

import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_ID;
import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_NAME;
import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_THUMBNAIL_URL;

public class PlaylistMetadataEntry {
public class PlaylistMetadataEntry implements LocalItem {
final public static String PLAYLIST_STREAM_COUNT = "streamCount";

@ColumnInfo(name = PLAYLIST_ID)
Expand All @@ -33,4 +34,9 @@ public LocalPlaylistInfoItem toStoredPlaylistInfoItem() {
storedPlaylistInfoItem.setStreamCount(streamCount);
return storedPlaylistInfoItem;
}

@Override
public LocalItemType getLocalItemType() {
return LocalItemType.PLAYLIST_ITEM;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.schabi.newpipe.database.playlist;

import android.arch.persistence.room.ColumnInfo;

import org.schabi.newpipe.database.LocalItem;
import org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity;
import org.schabi.newpipe.database.stream.model.StreamEntity;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamType;

public class PlaylistStreamEntry implements LocalItem {
@ColumnInfo(name = StreamEntity.STREAM_ID)
final public long uid;
@ColumnInfo(name = StreamEntity.STREAM_SERVICE_ID)
final public int serviceId;
@ColumnInfo(name = StreamEntity.STREAM_URL)
final public String url;
@ColumnInfo(name = StreamEntity.STREAM_TITLE)
final public String title;
@ColumnInfo(name = StreamEntity.STREAM_TYPE)
final public StreamType streamType;
@ColumnInfo(name = StreamEntity.STREAM_DURATION)
final public long duration;
@ColumnInfo(name = StreamEntity.STREAM_UPLOADER)
final public String uploader;
@ColumnInfo(name = StreamEntity.STREAM_THUMBNAIL_URL)
final public String thumbnailUrl;
@ColumnInfo(name = PlaylistStreamEntity.JOIN_STREAM_ID)
final public long streamId;
@ColumnInfo(name = PlaylistStreamEntity.JOIN_INDEX)
final public int joinIndex;

public PlaylistStreamEntry(long uid, int serviceId, String url, String title,
StreamType streamType, long duration, String uploader,
String thumbnailUrl, long streamId, int joinIndex) {
this.uid = uid;
this.serviceId = serviceId;
this.url = url;
this.title = title;
this.streamType = streamType;
this.duration = duration;
this.uploader = uploader;
this.thumbnailUrl = thumbnailUrl;
this.streamId = streamId;
this.joinIndex = joinIndex;
}

public StreamInfoItem toStreamInfoItem() throws IllegalArgumentException {
StreamInfoItem item = new StreamInfoItem(serviceId, url, title, streamType);
item.setThumbnailUrl(thumbnailUrl);
item.setUploaderName(uploader);
item.setDuration(duration);
return item;
}

@Override
public LocalItemType getLocalItemType() {
return LocalItemType.PLAYLIST_STREAM_ITEM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.schabi.newpipe.database.BasicDAO;
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
import org.schabi.newpipe.database.playlist.PlaylistStreamEntry;
import org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity;
import org.schabi.newpipe.database.stream.model.StreamEntity;

Expand Down Expand Up @@ -37,17 +38,13 @@ public Flowable<List<PlaylistStreamEntity>> listByService(int serviceId) {
" WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
public abstract void deleteBatch(final long playlistId);

@Query("SELECT MAX(" + JOIN_INDEX + ")" +
@Query("SELECT COALESCE(MAX(" + JOIN_INDEX + "), -1)" +
" FROM " + PLAYLIST_STREAM_JOIN_TABLE +
" WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
public abstract Flowable<Integer> getMaximumIndexOf(final long playlistId);

@Transaction
@Query("SELECT " + STREAM_ID + ", " + STREAM_SERVICE_ID + ", " + STREAM_URL + ", " +
STREAM_TITLE + ", " + STREAM_TYPE + ", " + STREAM_UPLOADER + ", " +
STREAM_DURATION + ", " + STREAM_THUMBNAIL_URL +

" FROM " + STREAM_TABLE + " INNER JOIN " +
@Query("SELECT * FROM " + STREAM_TABLE + " INNER JOIN " +
// get ids of streams of the given playlist
"(SELECT " + JOIN_STREAM_ID + "," + JOIN_INDEX +
" FROM " + PLAYLIST_STREAM_JOIN_TABLE + " WHERE "
Expand All @@ -56,14 +53,16 @@ public Flowable<List<PlaylistStreamEntity>> listByService(int serviceId) {
// then merge with the stream metadata
" ON " + STREAM_ID + " = " + JOIN_STREAM_ID +
" ORDER BY " + JOIN_INDEX + " ASC")
public abstract Flowable<List<StreamEntity>> getOrderedStreamsOf(long playlistId);
public abstract Flowable<List<PlaylistStreamEntry>> getOrderedStreamsOf(long playlistId);

@Transaction
@Query("SELECT " + PLAYLIST_ID + ", " + PLAYLIST_NAME + ", " +
PLAYLIST_THUMBNAIL_URL + ", COUNT(*) AS " + PLAYLIST_STREAM_COUNT +
PLAYLIST_THUMBNAIL_URL + ", " +
"COALESCE(COUNT(" + JOIN_PLAYLIST_ID + "), 0) AS " + PLAYLIST_STREAM_COUNT +

" FROM " + PLAYLIST_TABLE + " LEFT JOIN " + PLAYLIST_STREAM_JOIN_TABLE +
" ON " + PLAYLIST_TABLE + "." + PLAYLIST_ID + " = " + PLAYLIST_STREAM_JOIN_TABLE + "." + JOIN_PLAYLIST_ID +
" FROM " + PLAYLIST_TABLE +
" LEFT JOIN " + PLAYLIST_STREAM_JOIN_TABLE +
" ON " + PLAYLIST_ID + " = " + JOIN_PLAYLIST_ID +
" GROUP BY " + JOIN_PLAYLIST_ID)
public abstract Flowable<List<PlaylistMetadataEntry>> getPlaylistMetadata();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import android.arch.persistence.room.ColumnInfo;

import org.schabi.newpipe.database.LocalItem;
import org.schabi.newpipe.database.history.model.StreamHistoryEntity;
import org.schabi.newpipe.database.stream.model.StreamEntity;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.info_list.stored.StreamStatisticsInfoItem;

import java.util.Date;

public class StreamStatisticsEntry {
public class StreamStatisticsEntry implements LocalItem {
final public static String STREAM_LATEST_DATE = "latestAccess";
final public static String STREAM_WATCH_COUNT = "watchCount";

Expand Down Expand Up @@ -53,14 +54,16 @@ public StreamStatisticsEntry(long uid, int serviceId, String url, String title,
this.watchCount = watchCount;
}

public StreamStatisticsInfoItem toStreamStatisticsInfoItem() {
StreamStatisticsInfoItem item =
new StreamStatisticsInfoItem(uid, serviceId, url, title, streamType);
public StreamInfoItem toStreamInfoItem() {
StreamInfoItem item = new StreamInfoItem(serviceId, url, title, streamType);
item.setDuration(duration);
item.setUploaderName(uploader);
item.setThumbnailUrl(thumbnailUrl);
item.setLatestAccessDate(latestAccessDate);
item.setWatchCount(watchCount);
return item;
}

@Override
public LocalItemType getLocalItemType() {
return LocalItemType.STATISTIC_STREAM_ITEM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.info_list.stored.StreamEntityInfoItem;
import org.schabi.newpipe.playlist.PlayQueueItem;
import org.schabi.newpipe.util.Constants;

Expand Down Expand Up @@ -88,16 +87,6 @@ public StreamEntity(final PlayQueueItem item) {
item.getThumbnailUrl(), item.getUploader(), item.getDuration());
}

@Ignore
public StreamEntityInfoItem toStreamEntityInfoItem() throws IllegalArgumentException {
StreamEntityInfoItem item = new StreamEntityInfoItem(getUid(), getServiceId(),
getUrl(), getTitle(), getStreamType());
item.setThumbnailUrl(getThumbnailUrl());
item.setUploaderName(getUploader());
item.setDuration(getDuration());
return item;
}

public long getUid() {
return uid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.schabi.newpipe.fragments.list.channel.ChannelFragment;
import org.schabi.newpipe.fragments.list.feed.FeedFragment;
import org.schabi.newpipe.fragments.list.kiosk.KioskFragment;
import org.schabi.newpipe.fragments.local.BookmarkFragment;
import org.schabi.newpipe.fragments.local.bookmark.BookmarkFragment;
import org.schabi.newpipe.fragments.subscription.SubscriptionFragment;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
Expand Down
Loading

0 comments on commit 26aea7b

Please sign in to comment.