Support for namespace prefix

pull/147/head
M66B 6 years ago
parent d5add6e41a
commit 78431857ce

File diff suppressed because it is too large Load Diff

@ -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();
}

@ -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);

@ -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 &&

@ -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);

@ -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))

@ -251,11 +251,43 @@
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/title_optional"
android:inputType="text"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNameRemark" />
<TextView
android:id="@+id/tvPrefix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_account_prefix"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
<TextView
android:id="@+id/tvPrefixRemark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="@string/title_account_prefix_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPrefix" />
<EditText
android:id="@+id/etPrefix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/title_optional"
android:inputType="text"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPrefixRemark" />
<Button
android:id="@+id/btnColor"
style="@style/buttonStyleSmall"
@ -266,7 +298,7 @@
android:minHeight="0dp"
android:text="@string/title_account_color"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
app:layout_constraintTop_toBottomOf="@id/etPrefix" />
<View
android:id="@+id/vwColor"
@ -283,11 +315,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:src="@drawable/baseline_delete_24"
app:layout_constraintBottom_toBottomOf="@id/btnColor"
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toBottomOf="@id/etName" />
app:layout_constraintTop_toTopOf="@id/btnColor" />
<CheckBox
android:id="@+id/cbNotify"
@ -529,7 +560,7 @@
android:id="@+id/grpAdvanced"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvName,tvNameRemark,etName,btnColor,vwColor,ibColorDefault,cbNotify,cbSynchronize,cbPrimary,tvInterval,etInterval" />
app:constraint_referenced_ids="tvName,tvNameRemark,etName,tvPrefix,tvPrefixRemark,etPrefix,btnColor,vwColor,ibColorDefault,cbNotify,cbSynchronize,cbPrimary,tvInterval,etInterval" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpFolders"

@ -81,8 +81,8 @@
android:id="@+id/etDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapSentences"
android:hint="@string/title_optional"
android:inputType="textCapSentences"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDisplay" />
@ -388,11 +388,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:src="@drawable/baseline_delete_24"
app:layout_constraintBottom_toBottomOf="@id/btnColor"
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toBottomOf="@id/tilPassword" />
app:layout_constraintTop_toTopOf="@id/btnColor" />
<TextView
android:id="@+id/tvSignature"

@ -150,6 +150,8 @@
<string name="title_account_linked">Linked account</string>
<string name="title_account_name">Account name</string>
<string name="title_account_name_hint">Used to differentiate folders</string>
<string name="title_account_prefix">Namespace prefix</string>
<string name="title_account_prefix_hint">Used to simplify folder names</string>
<string name="title_account_signature">Signature text</string>
<string name="title_account_color">Color</string>
<string name="title_account_notify">Separate notifications</string>

Loading…
Cancel
Save