-Added rudimentary playlist fragment.

-Added schema for stream storage.
This commit is contained in:
John Zhen M 2017-08-25 15:10:54 -07:00 committed by John Zhen Mo
parent 391d3e7fc7
commit e70dcdc642
11 changed files with 1673 additions and 104 deletions

View file

@ -0,0 +1,17 @@
package org.schabi.newpipe.database;
import android.arch.persistence.room.TypeConverter;
import java.util.Date;
public class Converters {
@TypeConverter
public static Date fromTimestamp(Long value) {
return value == null ? null : new Date(value);
}
@TypeConverter
public static Long dateToTimestamp(Date date) {
return date == null ? null : date.getTime();
}
}

View file

@ -0,0 +1,70 @@
package org.schabi.newpipe.database.playlist;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.Ignore;
import android.arch.persistence.room.PrimaryKey;
import static org.schabi.newpipe.database.playlist.PlaylistEntity.PLAYLIST_TABLE;
@Entity(tableName = PLAYLIST_TABLE)
public class PlaylistEntity {
final static String PLAYLIST_TABLE = "playlists";
final static String PLAYLIST_URL = "url";
final static String PLAYLIST_TITLE = "title";
final static String PLAYLIST_THUMBNAIL_URL = "thumbnail_url";
@PrimaryKey(autoGenerate = true)
private long uid = 0;
@ColumnInfo(name = PLAYLIST_TITLE)
private String title;
/* This is used as a reference to the source, should this playlist be dynamic */
@ColumnInfo(name = PLAYLIST_URL)
private String url;
@ColumnInfo(name = PLAYLIST_THUMBNAIL_URL)
private String thumbnailUrl;
public long getUid() {
return uid;
}
/* Keep this package-private since UID should always be auto generated by Room impl */
void setUid(long uid) {
this.uid = uid;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getThumbnailUrl() {
return thumbnailUrl;
}
public void setThumbnailUrl(String thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl;
}
@Ignore
public void setData(final String title,
final String thumbnailUrl) {
this.setTitle(title);
this.setThumbnailUrl(thumbnailUrl);
}
}

View file

@ -0,0 +1,24 @@
package org.schabi.newpipe.database.stream;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Query;
import org.schabi.newpipe.database.BasicDAO;
import java.util.List;
import io.reactivex.Flowable;
import static org.schabi.newpipe.database.stream.StreamEntity.STREAM_SERVICE_ID;
import static org.schabi.newpipe.database.stream.StreamEntity.STREAM_TABLE;
@Dao
public interface StreamDAO extends BasicDAO<StreamEntity> {
@Override
@Query("SELECT * FROM " + STREAM_TABLE)
Flowable<List<StreamEntity>> findAll();
@Override
@Query("SELECT * FROM " + STREAM_TABLE + " WHERE " + STREAM_SERVICE_ID + " = :serviceId")
Flowable<List<StreamEntity>> listByService(int serviceId);
}

View file

@ -0,0 +1,207 @@
package org.schabi.newpipe.database.stream;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.Ignore;
import android.arch.persistence.room.Index;
import android.arch.persistence.room.PrimaryKey;
import org.schabi.newpipe.extractor.AbstractStreamInfo;
import org.schabi.newpipe.extractor.stream_info.StreamInfoItem;
import java.util.Date;
import static org.schabi.newpipe.database.stream.StreamEntity.STREAM_SERVICE_ID;
import static org.schabi.newpipe.database.stream.StreamEntity.STREAM_TABLE;
import static org.schabi.newpipe.database.stream.StreamEntity.STREAM_URL;
@Entity(tableName = STREAM_TABLE,
indices = {@Index(value = {STREAM_SERVICE_ID, STREAM_URL}, unique = true)})
public class StreamEntity {
public final static String STREAM_UID = "uid";
final static String STREAM_TABLE = "streams";
final static String STREAM_ID = "id";
final static String STREAM_TYPE = "type";
final static String STREAM_SERVICE_ID = "service_id";
final static String STREAM_URL = "url";
final static String STREAM_TITLE = "title";
final static String STREAM_THUMBNAIL_URL = "thumbnail_url";
final static String STREAM_VIEW_COUNT = "view_count";
final static String STREAM_UPLOADER = "uploader";
final static String STREAM_UPLOAD_DATE = "upload_date";
final static String STREAM_DURATION = "duration";
@PrimaryKey(autoGenerate = true)
private long uid = 0;
@ColumnInfo(name = STREAM_SERVICE_ID)
private int serviceId = -1;
@ColumnInfo(name = STREAM_ID)
private String id;
@ColumnInfo(name = STREAM_TYPE)
private String type;
@ColumnInfo(name = STREAM_URL)
private String url;
@ColumnInfo(name = STREAM_TITLE)
private String title;
@ColumnInfo(name = STREAM_THUMBNAIL_URL)
private String thumbnailUrl;
@ColumnInfo(name = STREAM_VIEW_COUNT)
private Long viewCount;
@ColumnInfo(name = STREAM_UPLOADER)
private String uploader;
@ColumnInfo(name = STREAM_UPLOAD_DATE)
private long uploadDate;
@ColumnInfo(name = STREAM_DURATION)
private int duration;
@Ignore
public StreamInfoItem toStreamInfoItem() {
StreamInfoItem item = new StreamInfoItem();
item.stream_type = AbstractStreamInfo.StreamType.valueOf( this.getType() );
item.service_id = this.getServiceId();
item.id = this.getId();
item.webpage_url = this.getUrl();
item.title = this.getTitle();
item.thumbnail_url = this.getThumbnailUrl();
item.view_count = this.getViewCount();
item.uploader = this.getUploader();
// TODO: temporary until upload date parsing is fleshed out
item.upload_date = "Unknown";
item.duration = this.getDuration();
return item;
}
@Ignore
public StreamEntity(final StreamInfoItem item) {
setData(item);
}
@Ignore
public void setData(final StreamInfoItem item) {
// Do not store ordinals into db since they may change in the future
this.type = item.stream_type.name();
this.serviceId = item.service_id;
this.id = item.id;
this.url = item.webpage_url;
this.title = item.title;
this.thumbnailUrl = item.thumbnail_url;
this.viewCount = item.view_count;
this.uploader = item.uploader;
// TODO: temporary until upload date parsing is fleshed out
this.uploadDate = new Date().getTime();
this.duration = item.duration;
}
@Ignore
public boolean is(final StreamInfoItem item) {
return this.type.equals( item.stream_type.name() ) &&
this.serviceId == item.service_id &&
this.id.equals( item.id ) &&
this.url.equals( item.webpage_url );
}
public long getUid() {
return uid;
}
void setUid(long uid) {
this.uid = uid;
}
public int getServiceId() {
return serviceId;
}
public void setServiceId(int serviceId) {
this.serviceId = serviceId;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getThumbnailUrl() {
return thumbnailUrl;
}
public void setThumbnailUrl(String thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl;
}
public Long getViewCount() {
return viewCount;
}
public void setViewCount(Long viewCount) {
this.viewCount = viewCount;
}
public String getUploader() {
return uploader;
}
public void setUploader(String uploader) {
this.uploader = uploader;
}
public long getUploadDate() {
return uploadDate;
}
public void setUploadDate(long uploadDate) {
this.uploadDate = uploadDate;
}
public int getDuration() {
return duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
}