diff --git a/app/src/main/java/ch/dissem/apps/abit/MessageListActivity.java b/app/src/main/java/ch/dissem/apps/abit/MessageListActivity.java index 1da5bf0..70891ea 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageListActivity.java +++ b/app/src/main/java/ch/dissem/apps/abit/MessageListActivity.java @@ -12,15 +12,6 @@ import android.view.View; import android.widget.AdapterView; import android.widget.CompoundButton; -import ch.dissem.apps.abit.listener.ActionBarListener; -import ch.dissem.apps.abit.listener.ListSelectionListener; -import ch.dissem.apps.abit.notification.NetworkNotification; -import ch.dissem.apps.abit.service.Singleton; -import ch.dissem.bitmessage.BitmessageContext; -import ch.dissem.bitmessage.entity.BitmessageAddress; -import ch.dissem.bitmessage.entity.Plaintext; -import ch.dissem.bitmessage.entity.valueobject.Label; - import com.mikepenz.community_material_typeface_library.CommunityMaterial; import com.mikepenz.google_material_typeface_library.GoogleMaterial; import com.mikepenz.iconics.IconicsDrawable; @@ -42,11 +33,10 @@ import org.slf4j.LoggerFactory; import java.io.Serializable; import java.util.ArrayList; -import java.util.Timer; -import java.util.TimerTask; -import ch.dissem.apps.abit.listeners.ActionBarListener; -import ch.dissem.apps.abit.listeners.ListSelectionListener; +import ch.dissem.apps.abit.listener.ActionBarListener; +import ch.dissem.apps.abit.listener.ListSelectionListener; +import ch.dissem.apps.abit.notification.NetworkNotification; import ch.dissem.apps.abit.service.Singleton; import ch.dissem.apps.abit.synchronization.Authenticator; import ch.dissem.bitmessage.BitmessageContext; @@ -277,14 +267,7 @@ public class MessageListActivity extends AppCompatActivity public boolean onItemClick(AdapterView adapterView, View view, int i, long l, IDrawerItem item) { if (item.getTag() instanceof Label) { selectedLabel = (Label) item.getTag(); - if (!(getSupportFragmentManager().findFragmentById(R.id.item_list) instanceof MessageListFragment)) { - MessageListFragment listFragment = new MessageListFragment(getApplicationContext()); - changeList(listFragment); - listFragment.updateList(selectedLabel); - } else { - ((MessageListFragment) getSupportFragmentManager() - .findFragmentById(R.id.item_list)).updateList(selectedLabel); - } + showSelectedLabel(); return false; } else if (item instanceof Nameable) { Nameable ni = (Nameable) item; @@ -300,6 +283,10 @@ public class MessageListActivity extends AppCompatActivity case R.string.settings: startActivity(new Intent(MessageListActivity.this, SettingsActivity.class)); break; + case R.string.archive: + selectedLabel = null; + showSelectedLabel(); + break; case R.string.full_node: return true; } @@ -311,6 +298,17 @@ public class MessageListActivity extends AppCompatActivity .build(); } + private void showSelectedLabel() { + if (getSupportFragmentManager().findFragmentById(R.id.item_list) instanceof MessageListFragment) { + ((MessageListFragment) getSupportFragmentManager() + .findFragmentById(R.id.item_list)).updateList(selectedLabel); + } else { + MessageListFragment listFragment = new MessageListFragment(getApplicationContext()); + changeList(listFragment); + listFragment.updateList(selectedLabel); + } + } + /** * Callback method from {@link ListSelectionListener} * indicating that the item with the given ID was selected. @@ -354,6 +352,7 @@ public class MessageListActivity extends AppCompatActivity @Override public void updateTitle(CharSequence title) { + //noinspection ConstantConditions getSupportActionBar().setTitle(title); } 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 c31b091..5de7c7e 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.java +++ b/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.java @@ -1,25 +1,24 @@ package ch.dissem.apps.abit; -import android.app.Activity; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.graphics.Typeface; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; -import android.support.v4.app.ListFragment; -import android.view.*; +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.ArrayAdapter; import android.widget.ImageView; -import android.widget.ListView; import android.widget.TextView; + import ch.dissem.apps.abit.listener.ActionBarListener; import ch.dissem.apps.abit.listener.ListSelectionListener; - -import ch.dissem.apps.abit.listeners.ActionBarListener; -import ch.dissem.apps.abit.listeners.ListSelectionListener; import ch.dissem.apps.abit.service.Singleton; -import ch.dissem.bitmessage.BitmessageContext; -import ch.dissem.bitmessage.entity.BitmessageAddress; import ch.dissem.bitmessage.entity.Plaintext; import ch.dissem.bitmessage.entity.valueobject.Label; import ch.dissem.bitmessage.ports.MessageRepository; @@ -45,6 +44,7 @@ public class MessageListFragment extends AbstractItemListFragment { public MessageListFragment() { } + @SuppressLint("ValidFragment") public MessageListFragment(Context ctx) { bmc = Singleton.getBitmessageContext(ctx); } @@ -98,7 +98,11 @@ public class MessageListFragment extends AbstractItemListFragment<Plaintext> { } }); if (getActivity() instanceof ActionBarListener) { - ((ActionBarListener) getActivity()).updateTitle(label.toString()); + if (label != null) { + ((ActionBarListener) getActivity()).updateTitle(label.toString()); + } else { + ((ActionBarListener) getActivity()).updateTitle(getString(R.string.archive)); + } } if (emptyTrashMenuItem != null) { emptyTrashMenuItem.setVisible(label != null && label.getType() == Label.Type.TRASH); diff --git a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidInventory.java b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidInventory.java index 32b9ed8..5e5f1c5 100644 --- a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidInventory.java +++ b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidInventory.java @@ -187,7 +187,7 @@ public class AndroidInventory implements Inventory { "hash = X'" + object.getInventoryVector() + "'", null, null, null, null ); - return c.getColumnCount() > 0; + return c.getCount() > 0; } @Override