Support for non selectable folders

pull/157/head
M66B 6 years ago
parent e8ced5da45
commit 9f6c1f3ea9

File diff suppressed because it is too large Load Diff

@ -507,7 +507,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
// Folders // Folders
JSONArray jfolders = new JSONArray(); JSONArray jfolders = new JSONArray();
for (EntityFolder folder : db.folder().getFolders(account.id)) { for (EntityFolder folder : db.folder().getFolders(account.id, true)) {
JSONObject jfolder = folder.toJSON(); JSONObject jfolder = folder.toJSON();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

@ -158,8 +158,10 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
} }
private void bindTo(final TupleFolderEx folder) { private void bindTo(final TupleFolderEx folder) {
view.setEnabled(folder.selectable);
view.setActivated(folder.tbc != null || folder.tbd != null); view.setActivated(folder.tbc != null || folder.tbd != null);
view.setAlpha(folder.hide || disabledIds.contains(folder.id) ? Helper.LOW_LIGHT : 1.0f); view.setAlpha(folder.hide || !folder.selectable || disabledIds.contains(folder.id)
? Helper.LOW_LIGHT : 1.0f);
if (textSize != 0) if (textSize != 0)
tvName.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); tvName.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
@ -293,7 +295,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
if (view.getId() == R.id.ivExpander) if (view.getId() == R.id.ivExpander)
onCollapse(folder); onCollapse(folder);
else { else if (folder.selectable) {
if (listener == null) { if (listener == null) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast( lbm.sendBroadcast(
@ -345,7 +347,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
return false; return false;
final TupleFolderEx folder = items.get(pos); final TupleFolderEx folder = items.get(pos);
if (folder.tbd != null) if (!folder.selectable || folder.tbd != null)
return false; return false;
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, view); PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, view);

@ -783,7 +783,7 @@ class Core {
// Get folder names // Get folder names
Map<String, EntityFolder> local = new HashMap<>(); Map<String, EntityFolder> local = new HashMap<>();
for (EntityFolder folder : db.folder().getFolders(account.id)) for (EntityFolder folder : db.folder().getFolders(account.id, true))
if (folder.tbc != null) { if (folder.tbc != null) {
Log.i(folder.name + " creating"); Log.i(folder.name + " creating");
Folder ifolder = istore.getFolder(folder.name); Folder ifolder = istore.getFolder(folder.name);
@ -852,7 +852,8 @@ class Core {
String childName = name[name.length - 1]; String childName = name[name.length - 1];
boolean subscribed = subscription.contains(fullName); boolean subscribed = subscription.contains(fullName);
String[] attr = ((IMAPFolder) ifolder).getAttributes(); String[] attr = ((IMAPFolder) ifolder).getAttributes();
String type = EntityFolder.getType(attr, fullName); String type = EntityFolder.getType(attr, fullName, false);
boolean selectable = !Arrays.asList(attr).contains("\\Noselect");
if (EntityFolder.INBOX.equals(type)) if (EntityFolder.INBOX.equals(type))
childName = null; childName = null;
@ -879,6 +880,7 @@ class Core {
folder.poll = ("imap.gmail.com".equals(account.host)); folder.poll = ("imap.gmail.com".equals(account.host));
folder.sync_days = EntityFolder.DEFAULT_SYNC; folder.sync_days = EntityFolder.DEFAULT_SYNC;
folder.keep_days = EntityFolder.DEFAULT_KEEP; folder.keep_days = EntityFolder.DEFAULT_KEEP;
folder.selectable = selectable;
folder.id = db.folder().insertFolder(folder); folder.id = db.folder().insertFolder(folder);
Log.i(folder.name + " added type=" + folder.type); Log.i(folder.name + " added type=" + folder.type);
} else { } else {

@ -54,7 +54,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 90, version = 91,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -890,6 +890,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `message` ADD COLUMN `notifying` INTEGER NOT NULL DEFAULT 0"); db.execSQL("ALTER TABLE `message` ADD COLUMN `notifying` INTEGER NOT NULL DEFAULT 0");
} }
}) })
.addMigrations(new Migration(90, 91) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `selectable` INTEGER NOT NULL DEFAULT 1");
}
})
.build(); .build();
} }

@ -28,8 +28,10 @@ import java.util.List;
@Dao @Dao
public interface DaoFolder { public interface DaoFolder {
@Query("SELECT * FROM folder WHERE account = :account") @Query("SELECT * FROM folder" +
List<EntityFolder> getFolders(long account); " WHERE account = :account" +
" AND (NOT :selectable OR selectable)")
List<EntityFolder> getFolders(long account, boolean selectable);
@Query("SELECT folder.*" + @Query("SELECT folder.*" +
", account.id AS accountId, account.`order` AS accountOrder, account.name AS accountName, account.color AS accountColor, account.state AS accountState" + ", account.id AS accountId, account.`order` AS accountOrder, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +

@ -106,6 +106,8 @@ public class EntityFolder extends EntityOrder implements Serializable {
public String sync_state; public String sync_state;
@NonNull @NonNull
public Boolean read_only = false; public Boolean read_only = false;
@NonNull
public Boolean selectable = true;
public String error; public String error;
public Long last_sync; public Long last_sync;
@ -244,10 +246,10 @@ public class EntityFolder extends EntityOrder implements Serializable {
return DRAFTS.equals(type) || OUTBOX.equals(type) || SENT.equals(type); return DRAFTS.equals(type) || OUTBOX.equals(type) || SENT.equals(type);
} }
static String getType(String[] attrs, String fullName) { static String getType(String[] attrs, String fullName, boolean selectable) {
// https://www.iana.org/assignments/imap-mailbox-name-attributes/imap-mailbox-name-attributes.xhtml // https://www.iana.org/assignments/imap-mailbox-name-attributes/imap-mailbox-name-attributes.xhtml
for (String attr : attrs) { for (String attr : attrs) {
if ("\\Noselect".equals(attr) || "\\NonExistent".equals(attr)) if ((selectable && "\\Noselect".equals(attr)) || "\\NonExistent".equals(attr))
return null; return null;
if (attr.startsWith("\\")) { if (attr.startsWith("\\")) {

@ -548,7 +548,7 @@ public class FragmentAccount extends FragmentBase {
String fullName = ifolder.getFullName(); String fullName = ifolder.getFullName();
String[] attrs = ((IMAPFolder) ifolder).getAttributes(); String[] attrs = ((IMAPFolder) ifolder).getAttributes();
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs)); Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs));
String type = EntityFolder.getType(attrs, fullName); String type = EntityFolder.getType(attrs, fullName, true);
if (type != null) { if (type != null) {
// Create entry // Create entry
@ -886,7 +886,7 @@ public class FragmentAccount extends FragmentBase {
String fullName = ifolder.getFullName(); String fullName = ifolder.getFullName();
String[] attrs = ((IMAPFolder) ifolder).getAttributes(); String[] attrs = ((IMAPFolder) ifolder).getAttributes();
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs)); Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs));
String type = EntityFolder.getType(attrs, fullName); String type = EntityFolder.getType(attrs, fullName, true);
if (EntityFolder.INBOX.equals(type)) { if (EntityFolder.INBOX.equals(type)) {
inbox = new EntityFolder(); inbox = new EntityFolder();
@ -1215,7 +1215,7 @@ public class FragmentAccount extends FragmentBase {
long account = args.getLong("account"); long account = args.getLong("account");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
List<EntityFolder> folders = db.folder().getFolders(account); List<EntityFolder> folders = db.folder().getFolders(account, true);
if (folders != null && folders.size() > 0) if (folders != null && folders.size() > 0)
Collections.sort(folders, folders.get(0).getComparator(null)); Collections.sort(folders, folders.get(0).getComparator(null));

@ -246,7 +246,7 @@ public class FragmentQuickSetup extends FragmentBase {
for (Folder ifolder : istore.getDefaultFolder().list("*")) { for (Folder ifolder : istore.getDefaultFolder().list("*")) {
String fullName = ifolder.getFullName(); String fullName = ifolder.getFullName();
String[] attrs = ((IMAPFolder) ifolder).getAttributes(); String[] attrs = ((IMAPFolder) ifolder).getAttributes();
String type = EntityFolder.getType(attrs, fullName); String type = EntityFolder.getType(attrs, fullName, true);
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs) + " type=" + type); Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs) + " type=" + type);

@ -372,7 +372,7 @@ public class FragmentRule extends FragmentBase {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
data.folder = db.folder().getFolder(fid); data.folder = db.folder().getFolder(fid);
data.folders = db.folder().getFolders(aid); data.folders = db.folder().getFolders(aid, true);
if (data.folders == null) if (data.folders == null)
data.folders = new ArrayList<>(); data.folders = new ArrayList<>();

@ -739,7 +739,7 @@ public class ServiceSynchronize extends LifecycleService {
// Open synchronizing folders // Open synchronizing folders
final ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory); final ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
List<EntityFolder> folders = db.folder().getFolders(account.id); List<EntityFolder> folders = db.folder().getFolders(account.id, true);
Collections.sort(folders, new Comparator<EntityFolder>() { Collections.sort(folders, new Comparator<EntityFolder>() {
@Override @Override
public int compare(EntityFolder f1, EntityFolder f2) { public int compare(EntityFolder f1, EntityFolder f2) {

Loading…
Cancel
Save