Added option to manually sync folders

Fixes #16
pull/72/head
M66B 6 years ago
parent 079fd668cb
commit 5d018940d1

@ -48,7 +48,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private List<TupleFolderEx> all = new ArrayList<>();
private List<TupleFolderEx> filtered = new ArrayList<>();
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
View itemView;
ImageView ivEdit;
TextView tvName;
@ -75,12 +75,15 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private void wire(boolean properties) {
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
if (properties)
ivEdit.setOnClickListener(this);
}
private void unwire() {
itemView.setOnClickListener(null);
itemView.setOnLongClickListener(null);
ivEdit.setOnClickListener(null);
}
private void bindTo(TupleFolderEx folder) {
@ -104,8 +107,6 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
tvType.setText(resid > 0 ? context.getString(resid) : folder.type);
tvAfter.setText(Integer.toString(folder.after));
tvAfter.setVisibility(folder.synchronize ? View.VISIBLE : View.INVISIBLE);
ivSync.setVisibility(folder.synchronize ? View.VISIBLE : View.INVISIBLE);
if ("connected".equals(folder.state))
@ -142,6 +143,22 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
.putExtra("folder", folder.id));
}
}
@Override
public boolean onLongClick(View v) {
int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION)
return false;
TupleFolderEx folder = filtered.get(pos);
Log.i(Helper.TAG, folder.name + " requesting sync");
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(new Intent(ServiceSynchronize.ACTION_SYNCHRONIZE_FOLDER)
.setType("account/" + (folder.account == null ? "outbox" : Long.toString(folder.account)))
.putExtra("folder", folder.id));
return true;
}
}
AdapterFolder(Context context) {

@ -28,7 +28,9 @@ import androidx.room.Query;
@Dao
public interface DaoFolder {
@Query("SELECT * FROM folder WHERE account = :account")
@Query("SELECT * FROM folder" +
" WHERE account = :account" +
" ORDER BY CASE WHEN folder.type = '" + EntityFolder.USER + "' THEN 1 ELSE 0 END")
List<EntityFolder> getFolders(long account);
@Query("SELECT * FROM folder" +

@ -122,6 +122,7 @@ public class ServiceSynchronize extends LifecycleService {
private static final long STORE_NOOP_INTERVAL = 9 * 60 * 1000L; // ms
private static final int ATTACHMENT_BUFFER_SIZE = 8192; // bytes
static final String ACTION_SYNCHRONIZE_FOLDER = BuildConfig.APPLICATION_ID + ".SYNCHRONIZE_FOLDER";
static final String ACTION_PROCESS_OPERATIONS = BuildConfig.APPLICATION_ID + ".PROCESS_OPERATIONS";
public ServiceSynchronize() {
@ -652,15 +653,15 @@ public class ServiceSynchronize extends LifecycleService {
}
}
BroadcastReceiver processReceiver = new BroadcastReceiver() {
BroadcastReceiver processFolder = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final long fid = intent.getLongExtra("folder", -1);
//Log.v(Helper.TAG, "run operations folder=" + fid);
public void onReceive(Context context, final Intent intent) {
executor.submit(new Runnable() {
@Override
public void run() {
long fid = intent.getLongExtra("folder", -1);
Log.i(Helper.TAG, "Process folder=" + fid + " intent=" + intent);
// Get folder
EntityFolder folder = null;
IMAPFolder ifolder = null;
@ -675,21 +676,29 @@ public class ServiceSynchronize extends LifecycleService {
try {
if (folder == null)
throw new IllegalArgumentException("Unknown folder=" + fid);
folder = db.folder().getFolder(fid);
if (shouldClose)
Log.v(Helper.TAG, folder.name + " start operations offline=" + shouldClose);
Log.i(Helper.TAG, folder.name + " run offline=" + shouldClose);
else
Log.i(Helper.TAG, folder.name + " run online");
if (ifolder == null) {
// Prevent unnecessary folder connections
if (db.operation().getOperationCount(fid) == 0)
return;
if (ACTION_PROCESS_OPERATIONS.equals(intent.getAction()))
if (db.operation().getOperationCount(fid) == 0)
return;
ifolder = (IMAPFolder) istore.getFolder(folder.name);
ifolder.open(Folder.READ_WRITE);
}
processOperations(folder, isession, istore, ifolder);
if (ACTION_PROCESS_OPERATIONS.equals(intent.getAction()))
processOperations(folder, isession, istore, ifolder);
else if (ACTION_SYNCHRONIZE_FOLDER.equals(intent.getAction()))
synchronizeMessages(account, folder, ifolder, state);
} catch (Throwable ex) {
Log.e(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
reportError(account.name, folder.name, ex);
@ -702,7 +711,6 @@ public class ServiceSynchronize extends LifecycleService {
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
}
}
//Log.v(Helper.TAG, folder.name + " stop operations");
}
}
});
@ -710,10 +718,13 @@ public class ServiceSynchronize extends LifecycleService {
};
// Listen for folder operations
IntentFilter f = new IntentFilter(ACTION_PROCESS_OPERATIONS);
IntentFilter f = new IntentFilter();
f.addAction(ACTION_SYNCHRONIZE_FOLDER);
f.addAction(ACTION_PROCESS_OPERATIONS);
f.addDataType("account/" + account.id);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(ServiceSynchronize.this);
lbm.registerReceiver(processReceiver, f);
lbm.registerReceiver(processFolder, f);
try {
// Process pending folder operations
Log.i(Helper.TAG, "listen process folder");
@ -739,7 +750,7 @@ public class ServiceSynchronize extends LifecycleService {
}
Log.i(Helper.TAG, account.name + " done running=" + state.running);
} finally {
lbm.unregisterReceiver(processReceiver);
lbm.unregisterReceiver(processFolder);
}
} catch (Throwable ex) {
Log.e(Helper.TAG, account.name + " " + ex + "\n" + Log.getStackTraceString(ex));
@ -1471,7 +1482,9 @@ public class ServiceSynchronize extends LifecycleService {
}
// Start monitoring outbox
IntentFilter f = new IntentFilter(ACTION_PROCESS_OPERATIONS);
IntentFilter f = new IntentFilter();
f.addAction(ACTION_SYNCHRONIZE_FOLDER);
f.addAction(ACTION_PROCESS_OPERATIONS);
f.addDataType("account/outbox");
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(ServiceSynchronize.this);
lbm.registerReceiver(outboxReceiver, f);
@ -1564,13 +1577,13 @@ public class ServiceSynchronize extends LifecycleService {
@Override
public void run() {
try {
Log.v(Helper.TAG, outbox.name + " start operations");
Log.i(Helper.TAG, outbox.name + " start operations");
processOperations(outbox, isession, null, null);
} catch (Throwable ex) {
Log.e(Helper.TAG, outbox.name + " " + ex + "\n" + Log.getStackTraceString(ex));
reportError(null, outbox.name, ex);
} finally {
Log.v(Helper.TAG, outbox.name + " end operations");
Log.i(Helper.TAG, outbox.name + " end operations");
}
}
});

Loading…
Cancel
Save