Browse Source

Allow disabling account sync without internet connection

main
M66B 6 years ago
parent
commit
511acdc875
4 changed files with 37 additions and 38 deletions
  1. +3
    -6
      app/src/main/java/eu/faircode/email/DaoFolder.java
  2. +30
    -29
      app/src/main/java/eu/faircode/email/FragmentAccount.java
  3. +3
    -2
      app/src/main/res/layout/fragment_account.xml
  4. +1
    -1
      app/src/main/res/values/strings.xml

+ 3
- 6
app/src/main/java/eu/faircode/email/DaoFolder.java View File

@ -95,15 +95,12 @@ public interface DaoFolder {
@Query("UPDATE folder SET type = :type WHERE id = :id")
int setFolderType(long id, String type);
@Query("UPDATE folder SET type = '" + EntityFolder.USER + "' WHERE type = :type")
int setFolderUser(String type);
@Query("UPDATE folder SET synchronize = :synchronize, after = :after WHERE id = :id")
int setFolderProperties(long id, boolean synchronize, int after);
@Query("DELETE FROM folder WHERE account= :account AND name = :name")
void deleteFolder(Long account, String name);
@Query("DELETE FROM folder" +
" WHERE account= :account" +
" AND type <> '" + EntityFolder.INBOX + "'" +
" AND type <> '" + EntityFolder.USER + "'")
int deleteSystemFolders(Long account);
}

+ 30
- 29
app/src/main/java/eu/faircode/email/FragmentAccount.java View File

@ -48,7 +48,6 @@ import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Locale;
@ -151,6 +150,8 @@ public class FragmentAccount extends FragmentEx {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
cbPrimary.setEnabled(checked);
btnCheck.setVisibility(checked ? View.VISIBLE : View.GONE);
btnSave.setVisibility(checked ? View.GONE : View.VISIBLE);
}
});
@ -349,15 +350,15 @@ public class FragmentAccount extends FragmentEx {
EntityFolder trash = (EntityFolder) spTrash.getSelectedItem();
EntityFolder junk = (EntityFolder) spJunk.getSelectedItem();
if (drafts.type == null)
if (drafts != null && drafts.type == null)
drafts = null;
if (sent.type == null)
if (sent != null && sent.type == null)
sent = null;
if (all.type == null)
if (all != null && all.type == null)
all = null;
if (trash.type == null)
if (trash != null && trash.type == null)
trash = null;
if (junk.type == null)
if (junk != null && junk.type == null)
junk = null;
Bundle args = new Bundle();
@ -398,29 +399,29 @@ public class FragmentAccount extends FragmentEx {
throw new Throwable(getContext().getString(R.string.title_no_user));
if (TextUtils.isEmpty(password))
throw new Throwable(getContext().getString(R.string.title_no_password));
if (drafts == null)
if (synchronize && drafts == null)
throw new Throwable(getContext().getString(R.string.title_no_drafts));
// Check IMAP server
Session isession = Session.getInstance(MessageHelper.getSessionProperties(), null);
IMAPStore istore = null;
try {
istore = (IMAPStore) isession.getStore("imaps");
istore.connect(host, Integer.parseInt(port), user, password);
if (synchronize) {
Session isession = Session.getInstance(MessageHelper.getSessionProperties(), null);
IMAPStore istore = null;
try {
istore = (IMAPStore) isession.getStore("imaps");
istore.connect(host, Integer.parseInt(port), user, password);
if (!istore.hasCapability("IDLE"))
throw new MessagingException(getContext().getString(R.string.title_no_idle));
} finally {
if (istore != null)
istore.close();
if (!istore.hasCapability("IDLE"))
throw new MessagingException(getContext().getString(R.string.title_no_idle));
} finally {
if (istore != null)
istore.close();
}
}
if (TextUtils.isEmpty(name))
name = host + "/" + user;
try {
ServiceSynchronize.stop(getContext(), "account");
DB db = DB.getInstance(getContext());
try {
db.beginTransaction();
@ -437,10 +438,6 @@ public class FragmentAccount extends FragmentEx {
account.synchronize = synchronize;
account.primary = (account.synchronize && args.getBoolean("primary"));
// On disabling synchronization mark message seen until now
if (!account.synchronize && account.synchronize != synchronize)
account.seen_until = new Date().getTime();
if (account.primary)
db.account().resetPrimary();
@ -459,8 +456,10 @@ public class FragmentAccount extends FragmentEx {
folders.add(inbox);
drafts.type = EntityFolder.DRAFTS;
folders.add(drafts);
if (drafts != null) {
drafts.type = EntityFolder.DRAFTS;
folders.add(drafts);
}
if (sent != null) {
sent.type = EntityFolder.SENT;
@ -479,10 +478,8 @@ public class FragmentAccount extends FragmentEx {
folders.add(junk);
}
int count = db.folder().deleteSystemFolders(account.id);
Log.w(Helper.TAG, "Deleted system folders count=" + count);
for (EntityFolder folder : folders) {
db.folder().setFolderUser(folder.type);
EntityFolder existing = db.folder().getFolderByName(account.id, folder.name);
if (existing == null) {
folder.account = account.id;
@ -591,6 +588,8 @@ public class FragmentAccount extends FragmentEx {
DB.getInstance(getContext()).account().liveAccount(id).observe(getViewLifecycleOwner(), new Observer<EntityAccount>() {
@Override
public void onChanged(@Nullable EntityAccount account) {
Helper.setViewsEnabled(view, true);
etName.setText(account == null ? null : account.name);
etHost.setText(account == null ? null : account.host);
etPort.setText(account == null ? null : Long.toString(account.port));
@ -601,7 +600,9 @@ public class FragmentAccount extends FragmentEx {
cbPrimary.setEnabled(account == null ? true : account.synchronize);
ibDelete.setVisibility(account == null ? View.GONE : View.VISIBLE);
Helper.setViewsEnabled(view, true);
btnCheck.setVisibility(account.synchronize ? View.VISIBLE : View.GONE);
btnSave.setVisibility(account.synchronize ? View.GONE : View.VISIBLE);
btnCheck.setEnabled(true);
pbWait.setVisibility(View.GONE);
}


+ 3
- 2
app/src/main/res/layout/fragment_account.xml View File

@ -202,9 +202,10 @@
android:id="@+id/ibDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:src="@drawable/baseline_delete_24"
app:layout_constraintBottom_toBottomOf="@id/btnCheck"
app:layout_constraintEnd_toEndOf="parent" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
<TextView
android:id="@+id/tvDrafts"


+ 1
- 1
app/src/main/res/values/strings.xml View File

@ -79,7 +79,7 @@
<string name="title_password">Password</string>
<string name="title_synchronize_account">Synchronize (receive messages)</string>
<string name="title_synchronize_identity">Synchronize (send messages)</string>
<string name="title_primary_account">Primary (used to store drafts)</string>
<string name="title_primary_account">Primary (default account)</string>
<string name="title_primary_identity">Primary (default identity)</string>
<string name="title_check">Check</string>
<string name="title_no_name">Name missing</string>


Loading…
Cancel
Save