parent
cb3840c699
commit
6c37cc770c
67 changed files with 872 additions and 904 deletions
|
|
@ -24,16 +24,17 @@ import androidx.sqlite.db.SupportSQLiteDatabase;
|
|||
import com.keylesspalace.tusky.TabDataKt;
|
||||
import com.keylesspalace.tusky.components.conversation.ConversationEntity;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* DB version & declare DAO
|
||||
*/
|
||||
|
||||
@Database(entities = { TootEntity.class, DraftEntity.class, AccountEntity.class, InstanceEntity.class, TimelineStatusEntity.class,
|
||||
@Database(entities = { DraftEntity.class, AccountEntity.class, InstanceEntity.class, TimelineStatusEntity.class,
|
||||
TimelineAccountEntity.class, ConversationEntity.class
|
||||
}, version = 25)
|
||||
}, version = 26)
|
||||
public abstract class AppDatabase extends RoomDatabase {
|
||||
|
||||
public abstract TootDao tootDao();
|
||||
public abstract AccountDao accountDao();
|
||||
public abstract InstanceDao instanceDao();
|
||||
public abstract ConversationsDao conversationDao();
|
||||
|
|
@ -365,4 +366,31 @@ public abstract class AppDatabase extends RoomDatabase {
|
|||
);
|
||||
}
|
||||
};
|
||||
|
||||
public static class Migration25_26 extends Migration {
|
||||
|
||||
private final File oldDraftDirectory;
|
||||
|
||||
public Migration25_26(File oldDraftDirectory) {
|
||||
super(25, 26);
|
||||
this.oldDraftDirectory = oldDraftDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("DROP TABLE `TootEntity`");
|
||||
|
||||
if (oldDraftDirectory != null && oldDraftDirectory.isDirectory()) {
|
||||
File[] oldDraftFiles = oldDraftDirectory.listFiles();
|
||||
if (oldDraftFiles != null) {
|
||||
for (File file : oldDraftFiles) {
|
||||
if (!file.isDirectory()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
/* Copyright 2017 Andrew Dawson
|
||||
*
|
||||
* This file is a part of Tusky.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky.db;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by cto3543 on 28/06/2017.
|
||||
*
|
||||
* DAO to fetch and update toots in the DB.
|
||||
*/
|
||||
|
||||
@Dao
|
||||
public interface TootDao {
|
||||
|
||||
@Query("SELECT * FROM TootEntity ORDER BY uid DESC")
|
||||
List<TootEntity> loadAll();
|
||||
|
||||
@Query("DELETE FROM TootEntity WHERE uid = :uid")
|
||||
int delete(int uid);
|
||||
|
||||
@Query("SELECT * FROM TootEntity WHERE uid = :uid")
|
||||
TootEntity find(int uid);
|
||||
|
||||
@Query("SELECT COUNT(*) FROM TootEntity")
|
||||
Observable<Integer> savedTootCount();
|
||||
}
|
||||
|
|
@ -1,151 +0,0 @@
|
|||
/* Copyright 2017 Andrew Dawson
|
||||
*
|
||||
* This file is a part of Tusky.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky.db;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.keylesspalace.tusky.entity.NewPoll;
|
||||
import com.keylesspalace.tusky.entity.Status;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
import androidx.room.TypeConverter;
|
||||
import androidx.room.TypeConverters;
|
||||
|
||||
/**
|
||||
* Toot model.
|
||||
*/
|
||||
|
||||
@Entity
|
||||
@TypeConverters(TootEntity.Converters.class)
|
||||
public class TootEntity {
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
private final int uid;
|
||||
|
||||
@ColumnInfo(name = "text")
|
||||
private final String text;
|
||||
|
||||
@ColumnInfo(name = "urls")
|
||||
private final String urls;
|
||||
|
||||
@ColumnInfo(name = "descriptions")
|
||||
private final String descriptions;
|
||||
|
||||
@ColumnInfo(name = "contentWarning")
|
||||
private final String contentWarning;
|
||||
|
||||
@ColumnInfo(name = "inReplyToId")
|
||||
private final String inReplyToId;
|
||||
|
||||
@Nullable
|
||||
@ColumnInfo(name = "inReplyToText")
|
||||
private final String inReplyToText;
|
||||
|
||||
@Nullable
|
||||
@ColumnInfo(name = "inReplyToUsername")
|
||||
private final String inReplyToUsername;
|
||||
|
||||
@ColumnInfo(name = "visibility")
|
||||
private final Status.Visibility visibility;
|
||||
|
||||
@Nullable
|
||||
@ColumnInfo(name = "poll")
|
||||
private final NewPoll poll;
|
||||
|
||||
public TootEntity(int uid, String text, String urls, String descriptions, String contentWarning, String inReplyToId,
|
||||
@Nullable String inReplyToText, @Nullable String inReplyToUsername,
|
||||
Status.Visibility visibility, @Nullable NewPoll poll) {
|
||||
this.uid = uid;
|
||||
this.text = text;
|
||||
this.urls = urls;
|
||||
this.descriptions = descriptions;
|
||||
this.contentWarning = contentWarning;
|
||||
this.inReplyToId = inReplyToId;
|
||||
this.inReplyToText = inReplyToText;
|
||||
this.inReplyToUsername = inReplyToUsername;
|
||||
this.visibility = visibility;
|
||||
this.poll = poll;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getContentWarning() {
|
||||
return contentWarning;
|
||||
}
|
||||
|
||||
public int getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public String getUrls() {
|
||||
return urls;
|
||||
}
|
||||
|
||||
public String getDescriptions() {
|
||||
return descriptions;
|
||||
}
|
||||
|
||||
public String getInReplyToId() {
|
||||
return inReplyToId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getInReplyToText() {
|
||||
return inReplyToText;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getInReplyToUsername() {
|
||||
return inReplyToUsername;
|
||||
}
|
||||
|
||||
public Status.Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public NewPoll getPoll() {
|
||||
return poll;
|
||||
}
|
||||
|
||||
public static final class Converters {
|
||||
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
@TypeConverter
|
||||
public Status.Visibility visibilityFromInt(int number) {
|
||||
return Status.Visibility.byNum(number);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public int intFromVisibility(Status.Visibility visibility) {
|
||||
return visibility == null ? Status.Visibility.UNKNOWN.getNum() : visibility.getNum();
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public String pollToString(NewPoll poll) {
|
||||
return gson.toJson(poll);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public NewPoll stringToPoll(String poll) {
|
||||
return gson.fromJson(poll, NewPoll.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue