Commit 690c8b44 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

added some models

need to serialize as JSON string for support types
parent bff19611
......@@ -80,33 +80,33 @@ data class FeedRaw(
)
data class ArticlesListPaginationRaw(
val page:Int,
val pagesize:Int,
val total:Int,
val pages:Int,
val items:List<NewsArticleRaw>
val page : Int,
val pagesize : Int,
val total : Int,
val pages : Int,
val items : List<NewsArticleRaw>
)
data class NewsArticleRaw(
val id:Int,
val published: Date,
val title:String,
val announce:String,
val preview: String?
val id : Int,
val published : Date,
val title : String,
val announce : String,
val preview : String?
)
data class ArticleRaw(
val id:Int,
val published: Date,
val title:String,
val body:String,
val feed_alias:String,
val photo:List<NewsPhotoRaw>?
val id : Int,
val published : Date,
val title : String,
val body : String,
val feed_alias : String,
val photo : List<NewsPhotoRaw>?
)
data class NewsPhotoRaw(
val title:String,
val url:String
val title : String,
val url : String
)
data class ImageAlbumRaw(
......
package com.biganto.visual.roompark.data.repository.db.requrey
import android.os.Parcel
import android.os.Parcelable
/**
* Created by Vladislav Bogdashkin on 15.06.2018.
*/
......@@ -23,3 +26,56 @@ class RevisionString(private val value:String, private val revision:String?){
*/
fun revisionUri()="$value${revision.orEmpty()}"
}
class TitledPhoto(val title:String, val url:String){
companion object{
private const val delimiter = 'ø'
}
constructor(str:String) : this(
title = str.substringBefore(delimiter),
url = str.substringAfter(delimiter)
)
}
//@Serializable
data class ResolutionRaw(
val res_name:String,
val url:String,
val width:Int,
val height:Int
) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString(),
parcel.readString(),
parcel.readInt(),
parcel.readInt()
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(res_name)
parcel.writeString(url)
parcel.writeInt(width)
parcel.writeInt(height)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<ResolutionRaw> {
override fun createFromParcel(parcel: Parcel): ResolutionRaw {
return ResolutionRaw(parcel)
}
override fun newArray(size: Int): Array<ResolutionRaw?> {
return arrayOfNulls(size)
}
}
}
\ No newline at end of file
package com.biganto.visual.roompark.data.repository.db.requrey.model
import com.biganto.visual.roompark.data.repository.db.requrey.TitledPhoto
import com.biganto.visual.roompark.data.repository.db.requrey.utils.TitledPhotoConverter
import io.requery.*
import java.util.*
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
@Entity
interface Article : Persistable {
@get:Key
val id:Int
val published : Date
val title : String
@get:Nullable
val announce : String?
@get:Nullable
val preview : String?
@get:Nullable
val body : String?
@get:ForeignKey(references = Feed::class, referencedColumn = "alias")
@get:ManyToOne
val feed_alias : Feed
@get:Convert(TitledPhotoConverter::class)
val photo : List<TitledPhoto>?
}
\ No newline at end of file
package com.biganto.visual.roompark.data.repository.db.requrey.model
import io.requery.Entity
import io.requery.Key
import io.requery.Persistable
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
@Entity
interface Feed : Persistable {
@get:Key
val id: Int
val title:String
@get:Key
val alias: String
}
\ No newline at end of file
package com.biganto.visual.roompark.data.repository.db.requrey.model
import io.requery.Entity
import io.requery.ForeignKey
import io.requery.Key
import io.requery.Persistable
import java.util.*
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
@Entity
interface ImageAlbum : Persistable {
@get:Key
val id:Int
val title:String
val sort:Int
val date: Date
@get:ForeignKey(references = ImageAlbum::class, referencedColumn = "id")
val parent_id:Int
}
\ No newline at end of file
package com.biganto.visual.roompark.data.repository.db.requrey.model
import io.requery.Entity
import io.requery.Generated
import io.requery.Key
import io.requery.Persistable
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
@Entity
interface Settings : Persistable {
@get:Key
@get:Generated
val id: Int
val deviceToken: String
val feedsSubscription: Boolean
val authToken: String
val targetResolution: Int
//??/?////????/? ???WERR EW WF W
}
\ No newline at end of file
package com.biganto.visual.roompark.data.repository.db.requrey.model
import io.requery.*
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
@Entity
interface Subscription : Persistable {
@get:Key
@get:Generated
val id: Int
@get:ManyToOne
val user: User
val deviceToken: String
val topic: String
val number: String
val state: Boolean
}
\ No newline at end of file
package com.biganto.visual.roompark.data.repository.db.requrey.model
import io.requery.Entity
import io.requery.Key
import io.requery.Persistable
import io.requery.Table
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
@Entity
@Table(name = "UserContainer")
interface User : Persistable {
@get:Key
val uuid: Int
val name: String
val email: String
val authToken: String
val targetResolution: Int
}
\ No newline at end of file
package com.biganto.visual.roompark.data.repository.db.requrey.utils;
import java.util.ArrayList;
import io.requery.Converter;
/**
* Created by Vladislav Bogdashkin on 04.07.2018.
*/
public class IntListConverter implements Converter<ArrayList<Integer>, String> {
private final String stringDelimiter = ",";
@SuppressWarnings("unchecked")
@Override
public Class<ArrayList<Integer>> getMappedType() {
return (Class)ArrayList.class;
}
@Override
public Class<String> getPersistedType() {
return String.class;
}
@Override
public Integer getPersistedSize() {
return null;
}
@Override
public String convertToPersisted(ArrayList<Integer> value) {
if (value == null) {
return "";
}
StringBuilder sb = new StringBuilder();
int index = 0;
for (Integer str: value) {
if (index > 0) {
sb.append(stringDelimiter);
}
sb.append(str);
index++;
}
return sb.toString();
}
@Override
public ArrayList<Integer> convertToMapped(Class<? extends ArrayList<Integer>> type,
String value) {
ArrayList<Integer> list = new ArrayList<>();
if (!value.isEmpty())
for (String _val : value.split(stringDelimiter)) {
list.add(Integer.parseInt(_val));
}
return list;
}
}
package com.biganto.visual.roompark.data.repository.db.requrey.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import io.requery.Converter;
import timber.log.Timber;
/**
* Created by Vladislav Bogdashkin on 04.07.2018.
*/
public class IsoDateConverter implements Converter<Date, String> {
private SimpleDateFormat apiFormat =new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+hh:mm", Locale.ROOT);
//SimpleDateFormat dbFormat =new SimpleDateFormat("YYYYMMDDThhmmss", Locale.ROOT);
@SuppressWarnings("unchecked")
@Override
public Class<Date> getMappedType() {
return Date.class;
}
@Override
public Class<String> getPersistedType() {
return String.class;
}
@Override
public Integer getPersistedSize() {
return null;
}
@Override
public String convertToPersisted(Date value) {
return value == null ? null : apiFormat.format(value);
}
@Override
public Date convertToMapped(Class<? extends Date> type,
String value) {
try {
return value == null ? null : apiFormat.parse(value);
}
catch (Exception e){
Timber.e("Wrong stored data format! {%s}",value);
return new Date();
}
}
}
\ No newline at end of file
package com.biganto.visual.roompark.data.repository.db.requrey.utils;
import java.util.ArrayList;
import java.util.Arrays;
import io.requery.Converter;
/**
* Created by Vladislav Bogdashkin on 04.07.2018.
*/
public class StringListConverter implements Converter<ArrayList<String>, String> {
private static final String stringDelimiter ="¹/|¹";
@SuppressWarnings("unchecked")
@Override
public Class<ArrayList<String>> getMappedType() {
return (Class)ArrayList.class;
}
@Override
public Class<String> getPersistedType() {
return String.class;
}
@Override
public Integer getPersistedSize() {
return null;
}
@Override
public String convertToPersisted(ArrayList<String> value) {
if (value == null) {
return "";
}
StringBuilder sb = new StringBuilder();
int index = 0;
for (String str: value) {
if (index > 0) {
sb.append(stringDelimiter);
}
sb.append(str);
index++;
}
return sb.toString();
}
@Override
public ArrayList<String> convertToMapped(Class<? extends ArrayList<String>> type,
String value) {
ArrayList<String> list = new ArrayList<>();
if (value != null) {
list.addAll(Arrays.asList(value.split(stringDelimiter)));
}
return list;
}
}
package com.biganto.visual.roompark.data.repository.db.requrey.utils;
import com.biganto.visual.roompark.data.repository.db.requrey.TitledPhoto;
import java.text.SimpleDateFormat;
import java.util.Locale;
import io.requery.Converter;
import timber.log.Timber;
/**
* Created by Vladislav Bogdashkin on 04.07.2018.
*/
public class TitledPhotoConverter implements Converter<TitledPhoto, String> {
private SimpleDateFormat apiFormat =new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+hh:mm", Locale.ROOT);
//SimpleDateFormat dbFormat =new SimpleDateFormat("YYYYMMDDThhmmss", Locale.ROOT);
@SuppressWarnings("unchecked")
@Override
public Class<TitledPhoto> getMappedType() {
return TitledPhoto.class;
}
@Override
public Class<String> getPersistedType() {
return String.class;
}
@Override
public Integer getPersistedSize() {
return null;
}
@Override
public String convertToPersisted(TitledPhoto value) {
return value == null ? null : apiFormat.format(value);
}
@Override
public TitledPhoto convertToMapped(Class<? extends TitledPhoto> type,
String value) {
try {
return value == null ? null : new TitledPhoto(value);
}
catch (Exception e){
Timber.e("Wrong stored data format! {%s}",value);
return new TitledPhoto("","");
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment