Support for namespace prefix

This commit is contained in:
M66B
2018-12-22 17:39:16 +00:00
parent d5add6e41a
commit 78431857ce
9 changed files with 1328 additions and 8 deletions

View File

@@ -46,7 +46,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 24,
version = 25,
entities = {
EntityIdentity.class,
EntityAccount.class,
@@ -314,6 +314,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `folder` ADD COLUMN `tbc` INTEGER");
}
})
.addMigrations(new Migration(24, 25) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `prefix` TEXT");
}
})
.build();
}

View File

@@ -155,6 +155,9 @@ public interface DaoFolder {
@Query("UPDATE folder SET type = :type WHERE id = :id")
int setFolderType(long id, String type);
@Query("UPDATE folder SET display = :display WHERE id = :id")
int setFolderDisplay(long id, String display);
@Query("UPDATE folder SET level = :level WHERE id = :id")
int setFolderLevel(long id, int level);

View File

@@ -45,6 +45,7 @@ public class EntityAccount {
public Long id;
public String name;
public String signature; // obsolete
public String prefix; // namespace
@NonNull
public String host; // IMAP
@NonNull
@@ -97,6 +98,7 @@ public class EntityAccount {
public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject();
json.put("name", name);
json.put("prefix", prefix);
json.put("host", host);
json.put("starttls", starttls);
json.put("insecure", insecure);
@@ -121,6 +123,8 @@ public class EntityAccount {
EntityAccount account = new EntityAccount();
if (json.has("name"))
account.name = json.getString("name");
if (json.has("prefix"))
account.prefix = json.getString("prefix");
account.host = json.getString("host");
account.starttls = (json.has("starttls") && json.getBoolean("starttls"));
account.insecure = (json.has("insecure") && json.getBoolean("insecure"));
@@ -143,6 +147,7 @@ public class EntityAccount {
if (obj instanceof EntityAccount) {
EntityAccount other = (EntityAccount) obj;
return ((this.name == null ? other.name == null : this.name.equals(other.name)) &&
(this.prefix == null ? other.prefix == null : this.prefix.equals(other.prefix)) &&
this.host.equals(other.host) &&
this.starttls == other.starttls &&
this.insecure == other.insecure &&

View File

@@ -109,6 +109,7 @@ public class FragmentAccount extends FragmentEx {
private TextView tvName;
private EditText etName;
private EditText etPrefix;
private Button btnColor;
private View vwColor;
private ImageView ibColorDefault;
@@ -182,6 +183,7 @@ public class FragmentAccount extends FragmentEx {
etName = view.findViewById(R.id.etName);
tvName = view.findViewById(R.id.tvName);
etPrefix = view.findViewById(R.id.etPrefix);
btnColor = view.findViewById(R.id.btnColor);
vwColor = view.findViewById(R.id.vwColor);
ibColorDefault = view.findViewById(R.id.ibColorDefault);
@@ -599,6 +601,7 @@ public class FragmentAccount extends FragmentEx {
args.putInt("auth_type", authorized == null ? Helper.AUTH_TYPE_PASSWORD : provider.getAuthType());
args.putString("name", etName.getText().toString());
args.putString("prefix", etPrefix.getText().toString());
args.putInt("color", color);
args.putBoolean("notify", cbNotify.isChecked());
@@ -625,6 +628,7 @@ public class FragmentAccount extends FragmentEx {
int auth_type = args.getInt("auth_type");
String name = args.getString("name");
String prefix = args.getString("prefix");
Integer color = args.getInt("color");
boolean notify = args.getBoolean("notify");
@@ -651,6 +655,8 @@ public class FragmentAccount extends FragmentEx {
if (synchronize && drafts == null)
throw new Throwable(getContext().getString(R.string.title_no_drafts));
if (TextUtils.isEmpty(prefix))
prefix = null;
if (Color.TRANSPARENT == color)
color = null;
@@ -664,6 +670,7 @@ public class FragmentAccount extends FragmentEx {
!host.equals(account.host) || Integer.parseInt(port) != account.port ||
!user.equals(account.user) || !password.equals(account.password)));
boolean reload = (check || account == null ||
(account.prefix == null ? prefix != null : !account.prefix.equals(prefix)) ||
account.synchronize != synchronize ||
!account.poll_interval.equals(Integer.parseInt(interval)));
@@ -711,6 +718,7 @@ public class FragmentAccount extends FragmentEx {
account.auth_type = auth_type;
account.name = name;
account.prefix = prefix;
account.color = color;
account.notify = notify;
@@ -935,6 +943,7 @@ public class FragmentAccount extends FragmentEx {
tilPassword.getEditText().setText(account == null ? null : account.password);
etName.setText(account == null ? null : account.name);
etPrefix.setText(account == null ? null : account.prefix);
cbNotify.setChecked(account == null ? false : account.notify);
cbSynchronize.setChecked(account == null ? true : account.synchronize);

View File

@@ -1952,12 +1952,16 @@ public class ServiceSynchronize extends LifecycleService {
if (selectable) {
int level = EntityFolder.getLevel(separator, fullName);
String display = null;
if (account.prefix != null && fullName.startsWith(account.prefix + separator))
display = fullName.substring(account.prefix.length() + 1);
EntityFolder folder = db.folder().getFolderByName(account.id, fullName);
if (folder == null) {
folder = new EntityFolder();
folder.account = account.id;
folder.name = fullName;
folder.display = display;
folder.type = (type == null ? EntityFolder.USER : type);
folder.level = level;
folder.synchronize = false;
@@ -1968,7 +1972,17 @@ public class ServiceSynchronize extends LifecycleService {
Log.i(Helper.TAG, folder.name + " added");
} else {
Log.i(Helper.TAG, folder.name + " exists");
if (folder.display == null) {
if (display != null)
db.folder().setFolderDisplay(folder.id, display);
} else {
if (account.prefix == null && folder.name.endsWith(separator + folder.display))
db.folder().setFolderDisplay(folder.id, null);
}
db.folder().setFolderLevel(folder.id, level);
if ("Inbox_sub".equals(folder.type))
db.folder().setFolderType(folder.id, EntityFolder.USER);
else if (EntityFolder.USER.equals(folder.type) && EntityFolder.SYSTEM.equals(type))