Added revision properties

pull/168/head
M66B 5 years ago
parent b4f528b673
commit 679eb92f74

File diff suppressed because it is too large Load Diff

@ -56,12 +56,13 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 112,
version = 113,
entities = {
EntityIdentity.class,
EntityAccount.class,
EntityFolder.class,
EntityMessage.class,
EntityRevision.class,
EntityAttachment.class,
EntityOperation.class,
EntityContact.class,
@ -83,6 +84,8 @@ public abstract class DB extends RoomDatabase {
public abstract DaoMessage message();
public abstract DaoRevision revision();
public abstract DaoAttachment attachment();
public abstract DaoOperation operation();
@ -1086,6 +1089,20 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `account` ADD COLUMN `move_to` INTEGER");
}
})
.addMigrations(new Migration(112, 113) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("CREATE TABLE IF NOT EXISTS `revision`" +
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT" +
", `message` INTEGER NOT NULL" +
", `sequence` INTEGER NOT NULL" +
", `reference` INTEGER NOT NULL" +
", FOREIGN KEY(`message`) REFERENCES `message`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
db.execSQL("CREATE INDEX IF NOT EXISTS `index_revision_message` ON `revision` (`message`)");
db.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_revision_message_sequence` ON `revision` (`message`, `sequence`)");
}
})
.build();
}

@ -0,0 +1,35 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail 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.
FairEmail 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 FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
@Dao
public interface DaoRevision {
@Query("SELECT * FROM revision" +
" WHERE message = :message" +
" AND sequence = :sequence")
EntityRevision getRevision(long message, int sequence);
@Insert
long insertRevision(EntityRevision revision);
}

@ -0,0 +1,63 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail 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.
FairEmail 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 FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Index;
import androidx.room.PrimaryKey;
import static androidx.room.ForeignKey.CASCADE;
@Entity(
tableName = EntityRevision.TABLE_NAME,
foreignKeys = {
@ForeignKey(childColumns = "message", entity = EntityMessage.class, parentColumns = "id", onDelete = CASCADE),
},
indices = {
@Index(value = {"message"}),
@Index(value = {"message", "sequence"}, unique = true)
}
)
public class EntityRevision {
static final String TABLE_NAME = "revision";
@PrimaryKey(autoGenerate = true)
public Long id;
@NonNull
public Long message;
@NonNull
public Integer sequence;
@NonNull
public Boolean reference;
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityRevision) {
EntityRevision other = (EntityRevision) obj;
return (this.message.equals(other.message) &&
this.sequence.equals(other.sequence) &&
this.reference.equals(other.reference));
} else
return false;
}
}

@ -784,7 +784,6 @@ public class FragmentCompose extends FragmentBase {
html = "<p>" + text.replaceAll("\\r?\\n", "<br>") + "</p>";
} else
html = HtmlHelper.sanitize(context, ref, true, false);
refFile.delete();
return body + html;
}
@ -794,6 +793,7 @@ public class FragmentCompose extends FragmentBase {
Bundle extras = new Bundle();
extras.putString("html", html);
extras.putBoolean("show", true);
extras.putBoolean("reference", false);
onAction(R.id.action_save, extras);
}
@ -2958,50 +2958,53 @@ public class FragmentCompose extends FragmentBase {
dirty = true;
if (draft.revisions == null)
draft.revisions = 1;
else
draft.revisions++;
draft.revisions = 0;
if (action != R.id.action_undo && action != R.id.action_redo)
draft.revision = draft.revisions;
boolean reference;
Bundle extras = args.getBundle("extras");
File refFile = EntityMessage.getRefFile(context, draft.id);
if (extras != null && extras.containsKey("reference"))
reference = extras.getBoolean("reference", refFile.exists());
else {
EntityRevision revision = db.revision().getRevision(draft.id, draft.revisions);
reference = (revision == null ? refFile.exists() : revision.reference);
}
Helper.writeText(draft.getFile(context), body);
Helper.writeText(draft.getFile(context, draft.revisions), body);
draft.revisions++;
db.message().setMessageRevision(draft.id, draft.revision);
db.message().setMessageRevisions(draft.id, draft.revisions);
Log.i("Inserting revision sequence=" + draft.revisions + " reference=" + reference);
EntityRevision revision = new EntityRevision();
revision.message = draft.id;
revision.sequence = draft.revisions;
revision.reference = reference;
db.revision().insertRevision(revision);
db.message().setMessageContent(draft.id,
true,
draft.plain_only,
HtmlHelper.getPreview(body),
null);
Helper.writeText(draft.getFile(context), body);
Helper.writeText(draft.getFile(context, draft.revisions), body);
}
if (action == R.id.action_undo || action == R.id.action_redo) {
if (draft.revision != null && draft.revisions != null) {
dirty = true;
if (action == R.id.action_undo) {
if (draft.revision > 1)
draft.revision--;
} else {
if (draft.revision < draft.revisions)
draft.revision++;
}
if (action == R.id.action_undo) {
if (draft.revision > 1)
draft.revision--;
} else {
if (draft.revision < draft.revisions)
draft.revision++;
}
body = Helper.readText(draft.getFile(context, draft.revision));
Helper.writeText(draft.getFile(context), body);
body = Helper.readText(draft.getFile(context, draft.revision));
Helper.writeText(draft.getFile(context), body);
} else
draft.revision = draft.revisions;
db.message().setMessageRevision(draft.id, draft.revision);
db.message().setMessageContent(draft.id,
true,
draft.plain_only, // unchanged
HtmlHelper.getPreview(body),
null);
db.message().setMessageContent(draft.id,
true,
draft.plain_only, // unchanged
HtmlHelper.getPreview(body),
null);
}
}
db.message().setMessageRevision(draft.id, draft.revision);
db.message().setMessageRevisions(draft.id, draft.revisions);
if (dirty) {
draft.received = new Date().getTime();
@ -3308,7 +3311,10 @@ public class FragmentCompose extends FragmentBase {
Spanned spannedRef = null;
File refFile = draft.getRefFile(context);
if (refFile.exists()) {
EntityRevision revision = db.revision().getRevision(draft.id, draft.revision == null ? 0 : draft.revision);
Log.i("Revision sequence=" + (revision == null ? null : revision.sequence) +
" reference=" + (revision == null ? null : revision.reference));
if (revision == null ? refFile.exists() : revision.reference) {
String quote = HtmlHelper.sanitize(context, Helper.readText(refFile), show_images, false);
Spanned spannedQuote = HtmlHelper.fromHtml(quote,
new Html.ImageGetter() {

Loading…
Cancel
Save