diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 2310be3f10..70a07b0dfc 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -281,9 +281,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB drawerArray.add(new DrawerItem(R.layout.item_drawer_separator)); - if (PreferenceManager.getDefaultSharedPreferences(ActivityView.this).getBoolean("debug", false)) - drawerArray.add(new DrawerItem(ActivityView.this, R.layout.item_drawer, R.drawable.baseline_list_24, R.string.menu_operations)); - + drawerArray.add(new DrawerItem(ActivityView.this, R.layout.item_drawer, R.drawable.baseline_list_24, R.string.menu_operations)); drawerArray.add(new DrawerItem(ActivityView.this, R.layout.item_drawer, R.drawable.baseline_help_24, R.string.menu_legend)); if (getIntentFAQ().resolveActivity(getPackageManager()) != null) diff --git a/app/src/main/java/eu/faircode/email/AdapterOperation.java b/app/src/main/java/eu/faircode/email/AdapterOperation.java index 13018dd379..c2c2f0090b 100644 --- a/app/src/main/java/eu/faircode/email/AdapterOperation.java +++ b/app/src/main/java/eu/faircode/email/AdapterOperation.java @@ -22,16 +22,17 @@ package eu.faircode.email; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.text.format.DateUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -import java.text.DateFormat; -import java.text.SimpleDateFormat; +import org.json.JSONArray; +import org.json.JSONException; + import java.util.ArrayList; -import java.util.Date; import java.util.List; import androidx.annotation.NonNull; @@ -45,16 +46,14 @@ public class AdapterOperation extends RecyclerView.Adapter all = new ArrayList<>(); - private List filtered = new ArrayList<>(); + private List all = new ArrayList<>(); + private List filtered = new ArrayList<>(); - private DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.LONG); - - public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { + public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { private View itemView; + private TextView tvFolder; private TextView tvMessage; - private TextView tvName; - private TextView tvArgs; + private TextView tvOperation; private TextView tvTime; private TextView tvError; @@ -62,16 +61,15 @@ public class AdapterOperation extends RecyclerView.Adapter 0) + sb.append(' ').append(operation.args); + } catch (JSONException ex) { + sb.append(' ').append(ex.toString()); + } + + tvFolder.setText(operation.accountName + "/" + operation.folderName); tvMessage.setText(operation.message == null ? null : Long.toString(operation.message)); - tvName.setText(operation.name); - tvArgs.setText(operation.args); - tvTime.setText(df.format(new Date(operation.created))); + tvOperation.setText(sb.toString()); + tvTime.setText(DateUtils.getRelativeTimeSpanString(context, operation.created)); tvError.setText(operation.error); tvError.setVisibility(operation.error == null ? View.GONE : View.VISIBLE); } @@ -94,7 +102,7 @@ public class AdapterOperation extends RecyclerView.Adapter() { - @Override - protected Void onLoad(Context context, Bundle args) { - DB.getInstance(context).operation().deleteOperation(args.getLong("id")); - return null; - } - - @Override - protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(context, owner, ex); - } - }.load(context, owner, args); - - return true; - } } AdapterOperation(Context context, LifecycleOwner owner) { @@ -174,7 +155,7 @@ public class AdapterOperation extends RecyclerView.Adapter operations) { + public void set(@NonNull List operations) { Log.i(Helper.TAG, "Set operations=" + operations.size()); all = operations; @@ -209,10 +190,10 @@ public class AdapterOperation extends RecyclerView.Adapter prev; - private List next; + private List prev; + private List next; - MessageDiffCallback(List prev, List next) { + MessageDiffCallback(List prev, List next) { this.prev = prev; this.next = next; } @@ -229,15 +210,15 @@ public class AdapterOperation extends RecyclerView.Adapter getOperationsByFolder(long folder, boolean outbox); - @Query("SELECT * FROM operation ORDER BY id") - LiveData> liveOperations(); + @Query("SELECT operation.*, account.name AS accountName, folder.name AS folderName" + + " FROM operation" + + " JOIN folder ON folder.id = operation.folder" + + " JOIN account ON account.id = folder.account" + + " ORDER BY operation.id") + LiveData> liveOperations(); @Query("SELECT * FROM operation WHERE folder = :folder ORDER BY id") LiveData> liveOperations(long folder); @@ -47,6 +51,9 @@ public interface DaoOperation { @Query("SELECT * FROM operation ORDER BY id") List getOperations(); + @Query("SELECT * FROM operation ORDER BY id LIMIT 1") + EntityOperation getOperationFirst(); + @Query("SELECT COUNT(id) FROM operation" + " WHERE folder = :folder" + " AND (:name IS NULL OR operation.name = :name)") diff --git a/app/src/main/java/eu/faircode/email/FragmentOperations.java b/app/src/main/java/eu/faircode/email/FragmentOperations.java index 0fcb18a951..bceac8870b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOperations.java +++ b/app/src/main/java/eu/faircode/email/FragmentOperations.java @@ -19,8 +19,15 @@ package eu.faircode.email; Copyright 2018 by Marcel Bokhorst (M66B) */ +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ProgressBar; @@ -46,6 +53,7 @@ public class FragmentOperations extends FragmentEx { @Nullable public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { setSubtitle(R.string.menu_operations); + setHasOptionsMenu(true); View view = inflater.inflate(R.layout.fragment_operations, container, false); @@ -75,9 +83,9 @@ public class FragmentOperations extends FragmentEx { super.onActivityCreated(savedInstanceState); // Observe folders - DB.getInstance(getContext()).operation().liveOperations().observe(getViewLifecycleOwner(), new Observer>() { + DB.getInstance(getContext()).operation().liveOperations().observe(getViewLifecycleOwner(), new Observer>() { @Override - public void onChanged(@Nullable List operations) { + public void onChanged(@Nullable List operations) { if (operations == null) operations = new ArrayList<>(); @@ -88,4 +96,58 @@ public class FragmentOperations extends FragmentEx { } }); } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.menu_operations, menu); + super.onCreateOptionsMenu(menu, inflater); + } + + @Override + public void onPrepareOptionsMenu(Menu menu) { + PackageManager pm = getContext().getPackageManager(); + menu.findItem(R.id.menu_help).setVisible(getFAQIntent().resolveActivity(pm) != null); + super.onPrepareOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_help: + onMenuHelp(); + return true; + case R.id.menu_delete: + onMenuDelete(); + return true; + + default: + return super.onOptionsItemSelected(item); + } + } + + private void onMenuHelp() { + startActivity(getFAQIntent()); + } + + private void onMenuDelete() { + new SimpleTask() { + @Override + protected Void onLoad(Context context, Bundle args) { + DB db = DB.getInstance(context); + EntityOperation operation = db.operation().getOperationFirst(); + if (operation != null) { + if (operation.message != null) + db.message().setMessageUiHide(operation.message, false); + db.operation().deleteOperation(operation.id); + } + return null; + } + }.load(this, new Bundle()); + } + + private Intent getFAQIntent() { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse("https://github.com/M66B/open-source-email/blob/master/FAQ.md#user-content-faq3")); + return intent; + } } diff --git a/app/src/main/java/eu/faircode/email/TupleOperationEx.java b/app/src/main/java/eu/faircode/email/TupleOperationEx.java new file mode 100644 index 0000000000..5ce84fb689 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/TupleOperationEx.java @@ -0,0 +1,36 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see . + + Copyright 2018 by Marcel Bokhorst (M66B) +*/ + +public class TupleOperationEx extends EntityOperation { + public String accountName; + public String folderName; + + @Override + public boolean equals(Object obj) { + if (obj instanceof TupleOperationEx) { + TupleOperationEx other = (TupleOperationEx) obj; + return (super.equals(obj) && + (this.accountName == null ? other.accountName == null : accountName.equals(other.accountName)) && + (this.folderName == null ? other.folderName == null : this.folderName.equals(other.folderName))); + } else + return false; + } +} diff --git a/app/src/main/res/layout/item_operation.xml b/app/src/main/res/layout/item_operation.xml index b0f0a9e095..ddd735ee2c 100644 --- a/app/src/main/res/layout/item_operation.xml +++ b/app/src/main/res/layout/item_operation.xml @@ -7,35 +7,39 @@ android:layout_marginBottom="3dp"> \ No newline at end of file diff --git a/app/src/main/res/menu/menu_operations.xml b/app/src/main/res/menu/menu_operations.xml new file mode 100644 index 0000000000..185ce66568 --- /dev/null +++ b/app/src/main/res/menu/menu_operations.xml @@ -0,0 +1,14 @@ + + + + + +