Archive is now handled somewhat differently, so we can distinguish between 'archive' and 'not initialized'.

This commit is contained in:
Christian Basler 2017-02-24 17:33:59 +01:00
parent 65c03bd638
commit 300da1730d
4 changed files with 37 additions and 19 deletions

View File

@ -54,14 +54,13 @@ import org.slf4j.LoggerFactory;
import java.io.Serializable; import java.io.Serializable;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import ch.dissem.apps.abit.dialog.AddIdentityDialogFragment; import ch.dissem.apps.abit.dialog.AddIdentityDialogFragment;
import ch.dissem.apps.abit.dialog.FullNodeDialogActivity; import ch.dissem.apps.abit.dialog.FullNodeDialogActivity;
import ch.dissem.apps.abit.listener.ActionBarListener; import ch.dissem.apps.abit.listener.ActionBarListener;
import ch.dissem.apps.abit.listener.ListSelectionListener; 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.BitmessageService;
import ch.dissem.apps.abit.service.Singleton; import ch.dissem.apps.abit.service.Singleton;
import ch.dissem.apps.abit.synchronization.SyncAdapter; import ch.dissem.apps.abit.synchronization.SyncAdapter;
@ -273,7 +272,7 @@ public class MainActivity extends AppCompatActivity
final ArrayList<IDrawerItem> drawerItems = new ArrayList<>(); final ArrayList<IDrawerItem> drawerItems = new ArrayList<>();
drawerItems.add(new PrimaryDrawerItem() drawerItems.add(new PrimaryDrawerItem()
.withName(R.string.archive) .withName(R.string.archive)
.withTag(null) .withTag(AndroidMessageRepository.LABEL_ARCHIVE)
.withIcon(CommunityMaterial.Icon.cmd_archive) .withIcon(CommunityMaterial.Icon.cmd_archive)
); );
drawerItems.add(new DividerDrawerItem()); drawerItems.add(new DividerDrawerItem());
@ -330,10 +329,6 @@ public class MainActivity extends AppCompatActivity
startActivity(new Intent(MainActivity.this, SettingsActivity startActivity(new Intent(MainActivity.this, SettingsActivity
.class)); .class));
break; break;
case R.string.archive:
selectedLabel = null;
showSelectedLabel();
break;
case R.string.full_node: case R.string.full_node:
return true; return true;
} }

View File

@ -100,8 +100,7 @@ public class MessageListFragment extends Fragment implements ListHolder {
MainActivity activity = (MainActivity) getActivity(); MainActivity activity = (MainActivity) getActivity();
messageRepo = Singleton.getMessageRepository(activity); messageRepo = Singleton.getMessageRepository(activity);
currentLabel = activity.getSelectedLabel(); doUpdateList(activity.getSelectedLabel());
doUpdateList(currentLabel);
} }
@Override @Override
@ -119,15 +118,24 @@ public class MessageListFragment extends Fragment implements ListHolder {
} }
private void doUpdateList(final Label label) { 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.<Plaintext>emptyList());
adapter.notifyDataSetChanged();
return;
}
currentLabel = label; currentLabel = label;
if (emptyTrashMenuItem != null) { if (emptyTrashMenuItem != null) {
emptyTrashMenuItem.setVisible(label != null && label.getType() == Label.Type.TRASH); emptyTrashMenuItem.setVisible(label.getType() == Label.Type.TRASH);
} }
if (getActivity() instanceof ActionBarListener) { if (getActivity() instanceof ActionBarListener) {
if (label != null) { ActionBarListener actionBarListener = (ActionBarListener) getActivity();
((ActionBarListener) getActivity()).updateTitle(label.toString()); if ("archive".equals(label.toString())) {
actionBarListener.updateTitle(getString(R.string.archive));
} else { } else {
((ActionBarListener) getActivity()).updateTitle(getString(R.string.archive)); actionBarListener.updateTitle(label.toString());
} }
} }
new AsyncTask<Void, Void, List<Plaintext>>() { new AsyncTask<Void, Void, List<Plaintext>>() {

View File

@ -45,6 +45,7 @@ import ch.dissem.apps.abit.util.Assets;
import ch.dissem.bitmessage.entity.Plaintext; import ch.dissem.bitmessage.entity.Plaintext;
import ch.dissem.bitmessage.entity.valueobject.Label; 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; import static ch.dissem.apps.abit.util.Strings.normalizeWhitespaces;
/** /**
@ -199,7 +200,7 @@ public class SwipeableMessageAdapter
@Override @Override
public int onGetSwipeReactionType(ViewHolder holder, int position, int x, int y) { 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_LEFT | REACTION_CAN_NOT_SWIPE_RIGHT_WITH_RUBBER_BAND_EFFECT;
} }
return REACTION_CAN_SWIPE_BOTH_H; return REACTION_CAN_SWIPE_BOTH_H;
@ -217,7 +218,7 @@ public class SwipeableMessageAdapter
bgRes = R.drawable.bg_swipe_item_left; bgRes = R.drawable.bg_swipe_item_left;
break; break;
case DRAWABLE_SWIPE_RIGHT_BACKGROUND: 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; bgRes = R.drawable.bg_swipe_item_neutral;
} else { } else {
bgRes = R.drawable.bg_swipe_item_right; bgRes = R.drawable.bg_swipe_item_right;

View File

@ -48,6 +48,8 @@ import static java.lang.String.valueOf;
public class AndroidMessageRepository extends AbstractMessageRepository { public class AndroidMessageRepository extends AbstractMessageRepository {
private static final Logger LOG = LoggerFactory.getLogger(AndroidMessageRepository.class); 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 TABLE_NAME = "Message";
private static final String COLUMN_ID = "id"; private static final String COLUMN_ID = "id";
private static final String COLUMN_IV = "iv"; private static final String COLUMN_IV = "iv";
@ -82,6 +84,15 @@ public class AndroidMessageRepository extends AbstractMessageRepository {
this.context = ctx; 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) { public List<Label> findLabels(String where) {
List<Label> result = new LinkedList<>(); List<Label> result = new LinkedList<>();
@ -153,15 +164,18 @@ public class AndroidMessageRepository extends AbstractMessageRepository {
public int countUnread(Label label) { public int countUnread(Label label) {
String[] args; String[] args;
String where; String where;
if (label != null) { if (label == null){
where = "id IN (SELECT message_id FROM Message_Label WHERE label_id=?) AND "; return 0;
}
if (label == LABEL_ARCHIVE) {
where = "";
args = new String[]{ args = new String[]{
label.getId().toString(),
Label.Type.UNREAD.name() Label.Type.UNREAD.name()
}; };
} else { } else {
where = ""; where = "id IN (SELECT message_id FROM Message_Label WHERE label_id=?) AND ";
args = new String[]{ args = new String[]{
label.getId().toString(),
Label.Type.UNREAD.name() Label.Type.UNREAD.name()
}; };
} }