Browse Source

feat: set account name on compose

main
Distopico Vegan 5 years ago
parent
commit
e4a97052f1
6 changed files with 1091 additions and 10 deletions
  1. +9
    -3
      app/schemas/org.dystopia.email.DB/23.json
  2. +1040
    -0
      app/schemas/org.dystopia.email.DB/24.json
  3. +8
    -1
      app/src/main/java/org/dystopia/email/DB.java
  4. +1
    -0
      app/src/main/java/org/dystopia/email/EntityMessage.java
  5. +14
    -6
      app/src/main/java/org/dystopia/email/FragmentCompose.java
  6. +19
    -0
      app/src/main/java/org/dystopia/email/FragmentEx.java

+ 9
- 3
app/schemas/org.dystopia.email.DB/23.json View File

@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 23,
"identityHash": "50f45495091ca49a0bcaa5fc9f827604",
"identityHash": "c29c5644635baac82ae92f61d0cd624d",
"entities": [
{
"tableName": "identity",
@ -405,7 +405,7 @@
},
{
"tableName": "message",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `account` INTEGER, `folder` INTEGER NOT NULL, `identity` INTEGER, `replying` INTEGER, `uid` INTEGER, `msgid` TEXT, `references` TEXT, `deliveredto` TEXT, `inreplyto` TEXT, `thread` TEXT, `avatar` TEXT, `from` TEXT, `to` TEXT, `cc` TEXT, `bcc` TEXT, `reply` TEXT, `headers` TEXT, `subject` TEXT, `size` INTEGER, `content` INTEGER NOT NULL, `sent` INTEGER, `received` INTEGER NOT NULL, `stored` INTEGER NOT NULL, `seen` INTEGER NOT NULL, `flagged` INTEGER NOT NULL, `ui_seen` INTEGER NOT NULL, `ui_flagged` INTEGER NOT NULL, `ui_hide` INTEGER NOT NULL, `ui_found` INTEGER NOT NULL, `ui_ignored` INTEGER NOT NULL, `error` TEXT, FOREIGN KEY(`account`) REFERENCES `account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`folder`) REFERENCES `folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`identity`) REFERENCES `identity`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`replying`) REFERENCES `message`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `account` INTEGER, `account_name` TEXT, `folder` INTEGER NOT NULL, `identity` INTEGER, `replying` INTEGER, `uid` INTEGER, `msgid` TEXT, `references` TEXT, `deliveredto` TEXT, `inreplyto` TEXT, `thread` TEXT, `avatar` TEXT, `from` TEXT, `to` TEXT, `cc` TEXT, `bcc` TEXT, `reply` TEXT, `headers` TEXT, `subject` TEXT, `size` INTEGER, `content` INTEGER NOT NULL, `sent` INTEGER, `received` INTEGER NOT NULL, `stored` INTEGER NOT NULL, `seen` INTEGER NOT NULL, `flagged` INTEGER NOT NULL, `ui_seen` INTEGER NOT NULL, `ui_flagged` INTEGER NOT NULL, `ui_hide` INTEGER NOT NULL, `ui_found` INTEGER NOT NULL, `ui_ignored` INTEGER NOT NULL, `error` TEXT, FOREIGN KEY(`account`) REFERENCES `account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`folder`) REFERENCES `folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`identity`) REFERENCES `identity`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`replying`) REFERENCES `message`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
@ -419,6 +419,12 @@
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "account_name",
"columnName": "account_name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "folder",
"columnName": "folder",
@ -1028,7 +1034,7 @@
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"50f45495091ca49a0bcaa5fc9f827604\")"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"c29c5644635baac82ae92f61d0cd624d\")"
]
}
}

+ 1040
- 0
app/schemas/org.dystopia.email.DB/24.json
File diff suppressed because it is too large
View File


+ 8
- 1
app/src/main/java/org/dystopia/email/DB.java View File

@ -45,7 +45,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 23,
version = 24,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -284,6 +284,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `identity` ADD COLUMN `insecure` INTEGER NOT NULL DEFAULT 0");
}
})
.addMigrations(new Migration(23, 24) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `account_name` TEXT");
}
})
.build();
}


+ 1
- 0
app/src/main/java/org/dystopia/email/EntityMessage.java View File

@ -73,6 +73,7 @@ public class EntityMessage implements Serializable {
@PrimaryKey(autoGenerate = true)
public Long id;
public Long account; // performance
public String account_name;
@NonNull
public Long folder;
public Long identity;


+ 14
- 6
app/src/main/java/org/dystopia/email/FragmentCompose.java View File

@ -136,8 +136,7 @@ public class FragmentCompose extends FragmentEx {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_compose);
setTitle(R.string.title_compose);
view = (ViewGroup) inflater.inflate(R.layout.fragment_compose, container, false);
// Get controls
@ -962,9 +961,10 @@ public class FragmentCompose extends FragmentEx {
Log.i(Helper.TAG, "Load draft action=" + action + " id=" + id + " reference=" + reference);
DB db = DB.getInstance(context);
EntityMessage draft;
EntityAccount account;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
@ -972,10 +972,14 @@ public class FragmentCompose extends FragmentEx {
if (draft == null || draft.ui_hide) {
if ("edit".equals(action))
throw new IllegalStateException("Message to edit not found");
} else
} else {
if (draft.account_name == null) {
account = db.account().getAccount(draft.account);
draft.account_name = account.name;
}
return draft;
}
EntityAccount account;
EntityMessage ref = db.message().getMessage(reference);
if (ref == null) {
long aid = args.getLong("account", -1);
@ -983,8 +987,9 @@ public class FragmentCompose extends FragmentEx {
account = db.account().getPrimaryAccount();
if (account == null)
throw new IllegalArgumentException(context.getString(R.string.title_no_account));
} else
} else {
account = db.account().getAccount(aid);
}
} else {
account = db.account().getAccount(ref.account);
@ -1038,6 +1043,7 @@ public class FragmentCompose extends FragmentEx {
draft = new EntityMessage();
draft.account = account.id;
draft.account_name = account.name;
draft.folder = drafts.id;
draft.msgid = EntityMessage.generateMessageId();
@ -1203,6 +1209,8 @@ public class FragmentCompose extends FragmentEx {
final String action = getArguments().getString("action");
Log.i(Helper.TAG, "Loaded draft id=" + draft.id + " action=" + action);
setSubtitle(draft.account_name);
etTo.setText(MessageHelper.getFormattedAddresses(draft.to, true));
etCc.setText(MessageHelper.getFormattedAddresses(draft.cc, true));
etBcc.setText(MessageHelper.getFormattedAddresses(draft.bcc, true));


+ 19
- 0
app/src/main/java/org/dystopia/email/FragmentEx.java View File

@ -33,9 +33,19 @@ import androidx.fragment.app.Fragment;
import androidx.lifecycle.Lifecycle;
public class FragmentEx extends Fragment {
private String title = "";
private String subtitle = " ";
private boolean finish = false;
protected void setTitle(int resid) {
setTitle(getString(resid));
}
protected void setTitle(String subtitle) {
this.title = subtitle;
updateTitle();
}
protected void setSubtitle(int resid) {
setSubtitle(getString(resid));
}
@ -118,6 +128,15 @@ public class FragmentEx extends Fragment {
super.onDestroy();
}
private void updateTitle() {
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity != null) {
ActionBar actionbar = activity.getSupportActionBar();
if (actionbar != null)
actionbar.setTitle(title);
}
}
private void updateSubtitle() {
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity != null) {


Loading…
Cancel
Save