mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-03 07:36:31 +02:00
Added capabilities to account
This commit is contained in:
@@ -21,11 +21,13 @@ package eu.faircode.email;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v7.util.DiffUtil;
|
||||
import android.support.v7.util.ListUpdateCallback;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -42,6 +44,7 @@ import java.util.Locale;
|
||||
|
||||
public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHolder> {
|
||||
private Context context;
|
||||
private boolean debug;
|
||||
|
||||
private List<EntityAccount> all = new ArrayList<>();
|
||||
private List<EntityAccount> filtered = new ArrayList<>();
|
||||
@@ -53,6 +56,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
ImageView ivSync;
|
||||
TextView tvHost;
|
||||
TextView tvUser;
|
||||
TextView tvCapabilities;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
@@ -63,6 +67,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
ivSync = itemView.findViewById(R.id.ivSync);
|
||||
tvHost = itemView.findViewById(R.id.tvHost);
|
||||
tvUser = itemView.findViewById(R.id.tvUser);
|
||||
tvCapabilities = itemView.findViewById(R.id.tvCapabilities);
|
||||
}
|
||||
|
||||
private void wire() {
|
||||
@@ -89,6 +94,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
|
||||
AdapterAccount(Context context) {
|
||||
this.context = context;
|
||||
this.debug = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("debug", false);
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
@@ -198,6 +204,8 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
holder.ivSync.setVisibility(account.synchronize ? View.VISIBLE : View.INVISIBLE);
|
||||
holder.tvHost.setText(String.format("%s:%d", account.host, account.port));
|
||||
holder.tvUser.setText(account.user);
|
||||
holder.tvCapabilities.setText(TextUtils.join(", ", account.capabilities));
|
||||
holder.tvCapabilities.setVisibility(debug ? View.VISIBLE : View.GONE);
|
||||
|
||||
holder.wire();
|
||||
}
|
||||
|
||||
@@ -46,13 +46,12 @@ import java.util.concurrent.Executors;
|
||||
public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHolder> {
|
||||
private Context context;
|
||||
private ViewType viewType;
|
||||
private boolean debug = false;
|
||||
private boolean debug;
|
||||
private ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
private List<TupleMessageEx> all = new ArrayList<>();
|
||||
private List<TupleMessageEx> filtered = new ArrayList<>();
|
||||
|
||||
private ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
enum ViewType {FOLDER, THREAD}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.arch.persistence.room.TypeConverter;
|
||||
import android.arch.persistence.room.TypeConverters;
|
||||
import android.arch.persistence.room.migration.Migration;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
/*
|
||||
@@ -40,7 +41,7 @@ import android.util.Log;
|
||||
EntityAttachment.class,
|
||||
EntityOperation.class
|
||||
},
|
||||
version = 4,
|
||||
version = 5,
|
||||
exportSchema = true
|
||||
)
|
||||
|
||||
@@ -77,6 +78,7 @@ public abstract class DB extends RoomDatabase {
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
.addMigrations(MIGRATION_2_3)
|
||||
.addMigrations(MIGRATION_3_4)
|
||||
.addMigrations(MIGRATION_4_5)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -112,15 +114,23 @@ public abstract class DB extends RoomDatabase {
|
||||
}
|
||||
};
|
||||
|
||||
private static final Migration MIGRATION_4_5 = new Migration(4, 5) {
|
||||
@Override
|
||||
public void migrate(SupportSQLiteDatabase db) {
|
||||
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `account` ADD COLUMN `capabilities` TEXT NOT NULL DEFAULT ''");
|
||||
}
|
||||
};
|
||||
|
||||
public static class Converters {
|
||||
@TypeConverter
|
||||
public static byte[] fromString(String value) {
|
||||
return null;
|
||||
public static String[] fromStringArray(String value) {
|
||||
return value.split(",");
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static String fromBytes(byte[] value) {
|
||||
return null;
|
||||
public static String toStringArray(String[] value) {
|
||||
return TextUtils.join(",", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ public class EntityAccount {
|
||||
public Boolean primary;
|
||||
@NonNull
|
||||
public Boolean synchronize;
|
||||
@NonNull
|
||||
public String[] capabilities;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
@@ -334,9 +334,19 @@ public class ServiceSynchronize extends LifecycleService {
|
||||
public void opened(ConnectionEvent e) {
|
||||
Log.i(Helper.TAG, account.name + " opened");
|
||||
try {
|
||||
DB db = DB.getInstance(ServiceSynchronize.this);
|
||||
|
||||
List<String> capabilities = new ArrayList<>();
|
||||
if (fstore.hasCapability("IDLE"))
|
||||
capabilities.add("IDLE");
|
||||
if (fstore.hasCapability("MOVE"))
|
||||
capabilities.add("MOVE");
|
||||
account.capabilities = capabilities.toArray(new String[0]);
|
||||
db.account().updateAccount(account);
|
||||
Log.i(Helper.TAG, "capabilities=" + TextUtils.join(",", capabilities));
|
||||
|
||||
synchronizeFolders(account, fstore);
|
||||
|
||||
DB db = DB.getInstance(ServiceSynchronize.this);
|
||||
for (final EntityFolder folder : db.folder().getFolders(account.id, true)) {
|
||||
Log.i(Helper.TAG, account.name + " sync folder " + folder.name);
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
|
||||
Reference in New Issue
Block a user