From 300da1730d17f144a8d189f3c69eaa77866935be Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Fri, 24 Feb 2017 17:33:59 +0100 Subject: [PATCH] Archive is now handled somewhat differently, so we can distinguish between 'archive' and 'not initialized'. --- .../ch/dissem/apps/abit/MainActivity.java | 9 ++------ .../dissem/apps/abit/MessageListFragment.java | 20 ++++++++++++----- .../abit/adapter/SwipeableMessageAdapter.java | 5 +++-- .../repository/AndroidMessageRepository.java | 22 +++++++++++++++---- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/ch/dissem/apps/abit/MainActivity.java b/app/src/main/java/ch/dissem/apps/abit/MainActivity.java index 7b98637..c994207 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MainActivity.java +++ b/app/src/main/java/ch/dissem/apps/abit/MainActivity.java @@ -54,14 +54,13 @@ import org.slf4j.LoggerFactory; import java.io.Serializable; import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Objects; import ch.dissem.apps.abit.dialog.AddIdentityDialogFragment; import ch.dissem.apps.abit.dialog.FullNodeDialogActivity; import ch.dissem.apps.abit.listener.ActionBarListener; import ch.dissem.apps.abit.listener.ListSelectionListener; +import ch.dissem.apps.abit.repository.AndroidMessageRepository; import ch.dissem.apps.abit.service.BitmessageService; import ch.dissem.apps.abit.service.Singleton; import ch.dissem.apps.abit.synchronization.SyncAdapter; @@ -273,7 +272,7 @@ public class MainActivity extends AppCompatActivity final ArrayList drawerItems = new ArrayList<>(); drawerItems.add(new PrimaryDrawerItem() .withName(R.string.archive) - .withTag(null) + .withTag(AndroidMessageRepository.LABEL_ARCHIVE) .withIcon(CommunityMaterial.Icon.cmd_archive) ); drawerItems.add(new DividerDrawerItem()); @@ -330,10 +329,6 @@ public class MainActivity extends AppCompatActivity startActivity(new Intent(MainActivity.this, SettingsActivity .class)); break; - case R.string.archive: - selectedLabel = null; - showSelectedLabel(); - break; case R.string.full_node: return true; } diff --git a/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.java b/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.java index 55e91e7..f2bc0fb 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.java +++ b/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.java @@ -100,8 +100,7 @@ public class MessageListFragment extends Fragment implements ListHolder { MainActivity activity = (MainActivity) getActivity(); messageRepo = Singleton.getMessageRepository(activity); - currentLabel = activity.getSelectedLabel(); - doUpdateList(currentLabel); + doUpdateList(activity.getSelectedLabel()); } @Override @@ -119,15 +118,24 @@ public class MessageListFragment extends Fragment implements ListHolder { } private void doUpdateList(final Label label) { + if (label == null) { + if (getActivity() instanceof ActionBarListener) { + ((ActionBarListener) getActivity()).updateTitle(getString(R.string.app_name)); + } + adapter.setData(null, Collections.emptyList()); + adapter.notifyDataSetChanged(); + return; + } currentLabel = label; if (emptyTrashMenuItem != null) { - emptyTrashMenuItem.setVisible(label != null && label.getType() == Label.Type.TRASH); + emptyTrashMenuItem.setVisible(label.getType() == Label.Type.TRASH); } if (getActivity() instanceof ActionBarListener) { - if (label != null) { - ((ActionBarListener) getActivity()).updateTitle(label.toString()); + ActionBarListener actionBarListener = (ActionBarListener) getActivity(); + if ("archive".equals(label.toString())) { + actionBarListener.updateTitle(getString(R.string.archive)); } else { - ((ActionBarListener) getActivity()).updateTitle(getString(R.string.archive)); + actionBarListener.updateTitle(label.toString()); } } new AsyncTask<Void, Void, List<Plaintext>>() { diff --git a/app/src/main/java/ch/dissem/apps/abit/adapter/SwipeableMessageAdapter.java b/app/src/main/java/ch/dissem/apps/abit/adapter/SwipeableMessageAdapter.java index f50a3f6..7990c62 100644 --- a/app/src/main/java/ch/dissem/apps/abit/adapter/SwipeableMessageAdapter.java +++ b/app/src/main/java/ch/dissem/apps/abit/adapter/SwipeableMessageAdapter.java @@ -45,6 +45,7 @@ import ch.dissem.apps.abit.util.Assets; import ch.dissem.bitmessage.entity.Plaintext; import ch.dissem.bitmessage.entity.valueobject.Label; +import static ch.dissem.apps.abit.repository.AndroidMessageRepository.LABEL_ARCHIVE; import static ch.dissem.apps.abit.util.Strings.normalizeWhitespaces; /** @@ -199,7 +200,7 @@ public class SwipeableMessageAdapter @Override public int onGetSwipeReactionType(ViewHolder holder, int position, int x, int y) { - if (label == null || label.getType() == Label.Type.TRASH) { + if (label == LABEL_ARCHIVE || label.getType() == Label.Type.TRASH) { return REACTION_CAN_SWIPE_LEFT | REACTION_CAN_NOT_SWIPE_RIGHT_WITH_RUBBER_BAND_EFFECT; } return REACTION_CAN_SWIPE_BOTH_H; @@ -217,7 +218,7 @@ public class SwipeableMessageAdapter bgRes = R.drawable.bg_swipe_item_left; break; case DRAWABLE_SWIPE_RIGHT_BACKGROUND: - if (label == null || label.getType() == Label.Type.TRASH) { + if (label == LABEL_ARCHIVE || label.getType() == Label.Type.TRASH) { bgRes = R.drawable.bg_swipe_item_neutral; } else { bgRes = R.drawable.bg_swipe_item_right; diff --git a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java index a1500f4..40bc9c6 100644 --- a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java +++ b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java @@ -48,6 +48,8 @@ import static java.lang.String.valueOf; public class AndroidMessageRepository extends AbstractMessageRepository { private static final Logger LOG = LoggerFactory.getLogger(AndroidMessageRepository.class); + public static final Label LABEL_ARCHIVE = new Label("archive", null, 0); + private static final String TABLE_NAME = "Message"; private static final String COLUMN_ID = "id"; private static final String COLUMN_IV = "iv"; @@ -82,6 +84,15 @@ public class AndroidMessageRepository extends AbstractMessageRepository { this.context = ctx; } + @Override + public List<Plaintext> findMessages(Label label) { + if (label == LABEL_ARCHIVE) { + return super.findMessages((Label) null); + } else { + return super.findMessages(label); + } + } + public List<Label> findLabels(String where) { List<Label> result = new LinkedList<>(); @@ -153,15 +164,18 @@ public class AndroidMessageRepository extends AbstractMessageRepository { public int countUnread(Label label) { String[] args; String where; - if (label != null) { - where = "id IN (SELECT message_id FROM Message_Label WHERE label_id=?) AND "; + if (label == null){ + return 0; + } + if (label == LABEL_ARCHIVE) { + where = ""; args = new String[]{ - label.getId().toString(), Label.Type.UNREAD.name() }; } else { - where = ""; + where = "id IN (SELECT message_id FROM Message_Label WHERE label_id=?) AND "; args = new String[]{ + label.getId().toString(), Label.Type.UNREAD.name() }; }