Support for non selectable folders

pull/157/head
M66B 5 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
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();
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) {
view.setEnabled(folder.selectable);
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)
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)
onCollapse(folder);
else {
else if (folder.selectable) {
if (listener == null) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
@ -345,7 +347,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
return false;
final TupleFolderEx folder = items.get(pos);
if (folder.tbd != null)
if (!folder.selectable || folder.tbd != null)
return false;
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, view);

@ -783,7 +783,7 @@ class Core {
// Get folder names
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) {
Log.i(folder.name + " creating");
Folder ifolder = istore.getFolder(folder.name);
@ -852,7 +852,8 @@ class Core {
String childName = name[name.length - 1];
boolean subscribed = subscription.contains(fullName);
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))
childName = null;
@ -879,6 +880,7 @@ class Core {
folder.poll = ("imap.gmail.com".equals(account.host));
folder.sync_days = EntityFolder.DEFAULT_SYNC;
folder.keep_days = EntityFolder.DEFAULT_KEEP;
folder.selectable = selectable;
folder.id = db.folder().insertFolder(folder);
Log.i(folder.name + " added type=" + folder.type);
} else {

@ -54,7 +54,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 90,
version = 91,
entities = {
EntityIdentity.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");
}
})
.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();
}

@ -28,8 +28,10 @@ import java.util.List;
@Dao
public interface DaoFolder {
@Query("SELECT * FROM folder WHERE account = :account")
List<EntityFolder> getFolders(long account);
@Query("SELECT * FROM folder" +
" WHERE account = :account" +
" AND (NOT :selectable OR selectable)")
List<EntityFolder> getFolders(long account, boolean selectable);
@Query("SELECT folder.*" +
", 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;
@NonNull
public Boolean read_only = false;
@NonNull
public Boolean selectable = true;
public String error;
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);
}
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
for (String attr : attrs) {
if ("\\Noselect".equals(attr) || "\\NonExistent".equals(attr))
if ((selectable && "\\Noselect".equals(attr)) || "\\NonExistent".equals(attr))
return null;
if (attr.startsWith("\\")) {

@ -548,7 +548,7 @@ public class FragmentAccount extends FragmentBase {
String fullName = ifolder.getFullName();
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs));
String type = EntityFolder.getType(attrs, fullName);
String type = EntityFolder.getType(attrs, fullName, true);
if (type != null) {
// Create entry
@ -886,7 +886,7 @@ public class FragmentAccount extends FragmentBase {
String fullName = ifolder.getFullName();
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
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)) {
inbox = new EntityFolder();
@ -1215,7 +1215,7 @@ public class FragmentAccount extends FragmentBase {
long account = args.getLong("account");
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)
Collections.sort(folders, folders.get(0).getComparator(null));

@ -246,7 +246,7 @@ public class FragmentQuickSetup extends FragmentBase {
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
String fullName = ifolder.getFullName();
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);

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

@ -739,7 +739,7 @@ public class ServiceSynchronize extends LifecycleService {
// Open synchronizing folders
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>() {
@Override
public int compare(EntityFolder f1, EntityFolder f2) {

Loading…
Cancel
Save