Save reply info in draft, refactor (#449)

* Save reply info in draft, refactor

* Handle replying to deleted status
This commit is contained in:
Ivan Kupalov 2017-11-16 21:18:11 +03:00 committed by Konrad Pozniak
commit 2575b16dad
15 changed files with 575 additions and 390 deletions

View file

@ -1,25 +1,39 @@
/* 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 android.arch.persistence.db.SupportSQLiteDatabase;
import android.arch.persistence.room.Database;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.migration.Migration;
import android.support.annotation.NonNull;
/**
* DB version & declare DAO
*/
@Database(entities = {TootEntity.class}, version = 3, exportSchema = false)
@Database(entities = {TootEntity.class}, version = 4, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
public abstract TootDao tootDao();
public static final Migration MIGRATION_2_3 = new Migration(2, 3) {
@Override
public void migrate(SupportSQLiteDatabase database) {
//this migration is necessary because of a change in the room library
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE TootEntity2 (uid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, text TEXT, urls TEXT, contentWarning TEXT);");
database.execSQL("INSERT INTO TootEntity2 SELECT * FROM TootEntity;");
database.execSQL("DROP TABLE TootEntity;");
database.execSQL("ALTER TABLE TootEntity2 RENAME TO TootEntity;");
@ -27,4 +41,13 @@ public abstract class AppDatabase extends RoomDatabase {
}
};
public static final Migration MIGRATION_3_4 = new Migration(3, 4) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE TootEntity ADD COLUMN inReplyToId TEXT");
database.execSQL("ALTER TABLE TootEntity ADD COLUMN inReplyToText TEXT");
database.execSQL("ALTER TABLE TootEntity ADD COLUMN inReplyToUsername TEXT");
database.execSQL("ALTER TABLE TootEntity ADD COLUMN visibility INTEGER");
}
};
}

View file

@ -1,33 +1,43 @@
/* 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 android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Transaction;
import android.arch.persistence.room.Update;
import java.util.List;
/**
* Created by cto3543 on 28/06/2017.
* crud interface on this Toot DB
*
* DAO to fetch and update toots in the DB.
*/
@Dao
public interface TootDao {
// c
@Insert
long insert(TootEntity users);
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertOrReplace(TootEntity users);
// r
@Query("SELECT * FROM TootEntity")
@Query("SELECT * FROM TootEntity ORDER BY uid DESC")
List<TootEntity> loadAll();
// u
@Update
void updateToot(TootEntity toot);
// d
@Delete
int delete(TootEntity user);
@Query("DELETE FROM TootEntity WHERE uid = :uid")
int delete(int uid);
}

View file

@ -1,57 +1,119 @@
/* 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 android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.arch.persistence.room.TypeConverter;
import android.arch.persistence.room.TypeConverters;
import android.support.annotation.Nullable;
import com.keylesspalace.tusky.entity.Status;
/**
* toot model
* Toot model.
*/
@Entity
@TypeConverters(TootEntity.Converters.class)
public class TootEntity {
@PrimaryKey(autoGenerate = true)
private int uid;
private final int uid;
@ColumnInfo(name = "text")
private String text;
private final String text;
@ColumnInfo(name = "urls")
private String urls;
private final String urls;
@ColumnInfo(name = "contentWarning")
private String contentWarning;
private final String contentWarning;
// getter setter
public String getText() {
return text;
@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;
public TootEntity(int uid, String text, String urls, String contentWarning, String inReplyToId,
@Nullable String inReplyToText, @Nullable String inReplyToUsername,
Status.Visibility visibility) {
this.uid = uid;
this.text = text;
this.urls = urls;
this.contentWarning = contentWarning;
this.inReplyToId = inReplyToId;
this.inReplyToText = inReplyToText;
this.inReplyToUsername = inReplyToUsername;
this.visibility = visibility;
}
public void setText(String text) {
this.text = text;
public String getText() {
return text;
}
public String getContentWarning() {
return contentWarning;
}
public void setContentWarning(String contentWarning) {
this.contentWarning = contentWarning;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getUrls() {
return urls;
}
public void setUrls(String urls) {
this.urls = urls;
public String getInReplyToId() {
return inReplyToId;
}
@Nullable
public String getInReplyToText() {
return inReplyToText;
}
@Nullable
public String getInReplyToUsername() {
return inReplyToUsername;
}
public Status.Visibility getVisibility() {
return visibility;
}
public static final class Converters {
@TypeConverter
public Status.Visibility visibilityFromInt(int number) {
return Status.Visibility.byNum(number);
}
@TypeConverter
public int intToVisibility(Status.Visibility visibility) {
return visibility.getNum();
}
}
}