2018-01-15 21:30:52 +01:00
|
|
|
package org.schabi.newpipe.database;
|
2017-08-12 06:50:25 +02:00
|
|
|
|
2019-10-04 14:59:08 +02:00
|
|
|
import androidx.room.TypeConverter;
|
2017-08-12 06:50:25 +02:00
|
|
|
|
2018-01-15 21:30:52 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
|
|
|
|
2017-08-12 06:50:25 +02:00
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
public class Converters {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a long value to a date
|
|
|
|
* @param value the long value
|
|
|
|
* @return the date
|
|
|
|
*/
|
|
|
|
@TypeConverter
|
|
|
|
public static Date fromTimestamp(Long value) {
|
|
|
|
return value == null ? null : new Date(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a date to a long value
|
|
|
|
* @param date the date
|
|
|
|
* @return the long value
|
|
|
|
*/
|
|
|
|
@TypeConverter
|
|
|
|
public static Long dateToTimestamp(Date date) {
|
|
|
|
return date == null ? null : date.getTime();
|
|
|
|
}
|
2018-01-15 21:30:52 +01:00
|
|
|
|
|
|
|
@TypeConverter
|
|
|
|
public static StreamType streamTypeOf(String value) {
|
|
|
|
return StreamType.valueOf(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@TypeConverter
|
|
|
|
public static String stringOf(StreamType streamType) {
|
|
|
|
return streamType.name();
|
|
|
|
}
|
2017-08-12 06:50:25 +02:00
|
|
|
}
|