Added folder legend

This commit is contained in:
M66B 2018-11-22 08:57:34 +01:00
parent 6c6dcca0ac
commit 692534bef5
4 changed files with 181 additions and 75 deletions

View File

@ -126,6 +126,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
static final String ACTION_STORE_ATTACHMENT = BuildConfig.APPLICATION_ID + ".STORE_ATTACHMENT";
static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT";
static final String ACTION_SHOW_PRO = BuildConfig.APPLICATION_ID + ".SHOW_PRO";
static final String ACTION_SHOW_LEGEND = BuildConfig.APPLICATION_ID + ".SHOW_LEGEND";
static final String UPDATE_LATEST_API = "https://api.github.com/repos/M66B/open-source-email/releases/latest";
static final long UPDATE_INTERVAL = 12 * 3600 * 1000L; // milliseconds
@ -350,6 +351,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
iff.addAction(ACTION_STORE_ATTACHMENT);
iff.addAction(ACTION_DECRYPT);
iff.addAction(ACTION_SHOW_PRO);
iff.addAction(ACTION_SHOW_LEGEND);
lbm.registerReceiver(receiver, iff);
if (!pgpService.isBound())
@ -1060,6 +1062,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
onDecrypt(intent);
else if (ACTION_SHOW_PRO.equals(intent.getAction()))
onShowPro(intent);
else if (ACTION_SHOW_LEGEND.equals(intent.getAction()))
onMenuLegend();
}
};

View File

@ -71,6 +71,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private final static int action_delete_local = 2;
private final static int action_empty_trash = 3;
private final static int action_edit_properties = 4;
private final static int action_legend = 5;
ViewHolder(View itemView) {
super(itemView);
@ -181,99 +182,126 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
if (folder.account != null)
popupMenu.getMenu().add(Menu.NONE, action_edit_properties, 4, R.string.title_edit_properties);
popupMenu.getMenu().add(Menu.NONE, action_legend, 5, R.string.menu_legend);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
switch (target.getItemId()) {
case action_synchronize_now:
Log.i(Helper.TAG, folder.name + " requesting sync");
lbm.sendBroadcast(
new Intent(ServiceSynchronize.ACTION_SYNCHRONIZE_FOLDER)
.setType("account/" + (folder.account == null ? "outbox" : Long.toString(folder.account)))
.putExtra("folder", folder.id));
onActionSynchronizeNow();
break;
case action_delete_local:
Bundle args = new Bundle();
args.putLong("id", folder.id);
args.putBoolean("outbox", folder.account == null);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
long id = args.getLong("id");
boolean outbox = args.getBoolean("outbox");
Log.i(Helper.TAG, "Delete local messages outbox=" + outbox);
if (outbox)
DB.getInstance(context).message().deleteSeenMessages(id);
else
DB.getInstance(context).message().deleteLocalMessages(id);
return null;
}
@Override
public void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, ex);
}
}.load(context, owner, args);
OnActionDeleteLocal();
break;
case action_empty_trash:
new DialogBuilderLifecycle(context, owner)
.setMessage(R.string.title_empty_trash_ask)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle args = new Bundle();
args.putLong("id", folder.id);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
for (Long mid : db.message().getMessageByFolder(id)) {
EntityMessage message = db.message().getMessage(mid);
db.message().setMessageUiHide(message.id, true);
EntityOperation.queue(db, message, EntityOperation.DELETE);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
EntityOperation.process(context);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, ex);
}
}.load(context, owner, args);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
onActionEmptyTrash();
break;
case action_edit_properties:
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_EDIT_FOLDER)
.putExtra("id", folder.id));
onActionEditProperties();
break;
case action_legend:
onActionLegend();
break;
}
return true;
}
private void onActionSynchronizeNow() {
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));
}
private void OnActionDeleteLocal() {
Bundle args = new Bundle();
args.putLong("id", folder.id);
args.putBoolean("outbox", folder.account == null);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
long id = args.getLong("id");
boolean outbox = args.getBoolean("outbox");
Log.i(Helper.TAG, "Delete local messages outbox=" + outbox);
if (outbox)
DB.getInstance(context).message().deleteSeenMessages(id);
else
DB.getInstance(context).message().deleteLocalMessages(id);
return null;
}
@Override
public void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, ex);
}
}.load(context, owner, args);
}
private void onActionEmptyTrash() {
new DialogBuilderLifecycle(context, owner)
.setMessage(R.string.title_empty_trash_ask)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle args = new Bundle();
args.putLong("id", folder.id);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
for (Long mid : db.message().getMessageByFolder(id)) {
EntityMessage message = db.message().getMessage(mid);
db.message().setMessageUiHide(message.id, true);
EntityOperation.queue(db, message, EntityOperation.DELETE);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
EntityOperation.process(context);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, ex);
}
}.load(context, owner, args);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
private void onActionEditProperties() {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_EDIT_FOLDER)
.putExtra("id", folder.id));
}
private void onActionLegend() {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_LEGEND));
}
});
popupMenu.show();

View File

@ -388,5 +388,77 @@
app:layout_constraintStart_toEndOf="@id/ivClosing"
app:layout_constraintTop_toTopOf="@id/ivClosing" />
<TextView
android:id="@+id/tvSyncKeep"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="24dp"
android:gravity="center_vertical"
android:text="123/456"
android:textAppearance="@android:style/TextAppearance.Small"
app:layout_constraintBottom_toBottomOf="@+id/tvSyncKeepLegend"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvClosing" />
<ImageView
android:id="@+id/ivSyncKeep"
android:layout_width="24dp"
android:layout_height="0dp"
android:layout_marginStart="6dp"
android:src="@drawable/baseline_mail_outline_24"
app:layout_constraintBottom_toBottomOf="@+id/tvSyncKeepLegend"
app:layout_constraintStart_toEndOf="@id/tvSyncKeep"
app:layout_constraintTop_toTopOf="@id/tvSyncKeep" />
<TextView
android:id="@+id/tvSyncKeepLegend"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:text="@string/title_legend_sync_keep"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ivSyncKeep"
app:layout_constraintTop_toTopOf="@id/ivSyncKeep" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrierSyncKeep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="tvSyncKeep,ivSyncKeep,tvSyncKeepLegend" />
<TextView
android:id="@+id/tvDownloadFetch"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="12dp"
android:gravity="center_vertical"
android:text="123/456"
android:textAppearance="@android:style/TextAppearance.Small"
app:layout_constraintBottom_toBottomOf="@+id/tvDownloadLegend"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/barrierSyncKeep" />
<ImageView
android:id="@+id/ivDownloadFetch"
android:layout_width="24dp"
android:layout_height="0dp"
android:layout_marginStart="6dp"
android:src="@drawable/baseline_sync_24"
app:layout_constraintBottom_toBottomOf="@+id/tvDownloadLegend"
app:layout_constraintStart_toEndOf="@id/tvDownloadFetch"
app:layout_constraintTop_toTopOf="@id/tvDownloadFetch" />
<TextView
android:id="@+id/tvDownloadLegend"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:text="@string/title_legend_download_fetch"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ivDownloadFetch"
app:layout_constraintTop_toTopOf="@id/ivDownloadFetch" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View File

@ -313,6 +313,8 @@
<string name="title_legend_synchronizing">Synchronizing</string>
<string name="title_legend_downloading">Downloading</string>
<string name="title_legend_closing">Closing</string>
<string name="title_legend_sync_keep">Number of days to synchronize / to keep messages</string>
<string name="title_legend_download_fetch">Number of message bodies downloaded / headers fetched</string>
<string name="title_hint_folder_actions">Long press for options</string>
<string name="title_hint_support">If you have a question or a problem, please use the support menu to get help</string>