From 433c7571076cd8d2a3375abcec7cc9ef3097eecf Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Mon, 10 Jul 2017 06:21:29 +0200 Subject: [PATCH] UI improvements and fixes for older Android versions --- app/build.gradle | 3 +- app/src/main/AndroidManifest.xml | 14 +-- .../apps/abit/AbstractItemListFragment.java | 12 ++- .../dissem/apps/abit/AddressListFragment.java | 4 +- .../java/ch/dissem/apps/abit/ListHolder.java | 10 +- .../ch/dissem/apps/abit/MainActivity.java | 66 +++++++++--- .../dissem/apps/abit/MessageListFragment.java | 33 ++++-- .../ch/dissem/apps/abit/SettingsActivity.java | 18 ---- .../ch/dissem/apps/abit/SettingsFragment.java | 35 +++++-- .../ch/dissem/apps/abit/StatusFragment.java | 49 +++++++++ .../abit/adapter/SwipeableMessageAdapter.java | 6 +- .../repository/AndroidAddressRepository.java | 3 +- .../repository/AndroidMessageRepository.java | 62 ++++++----- .../apps/abit/repository/SqlHelper.java | 30 ++++++ .../main/res/drawable/bg_item_selectable.xml | 12 +++ .../res/drawable/bg_item_selected_state.xml | 24 ++--- app/src/main/res/drawable/bg_white.xml | 8 ++ .../layout-w720dp/activity_message_list.xml | 96 +++++++++--------- app/src/main/res/layout/contact_row.xml | 16 +-- .../main/res/layout/fragment_address_list.xml | 11 +- app/src/main/res/layout/fragment_status.xml | 11 ++ app/src/main/res/layout/subscription_row.xml | 3 +- app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/styles.xml | 1 + app/src/main/res/xml/preferences.xml | 12 +-- gradle/wrapper/gradle-wrapper.jar | Bin 54208 -> 54212 bytes gradle/wrapper/gradle-wrapper.properties | 4 +- 27 files changed, 352 insertions(+), 192 deletions(-) delete mode 100644 app/src/main/java/ch/dissem/apps/abit/SettingsActivity.java create mode 100644 app/src/main/java/ch/dissem/apps/abit/StatusFragment.java create mode 100644 app/src/main/res/drawable/bg_item_selectable.xml create mode 100644 app/src/main/res/drawable/bg_white.xml create mode 100644 app/src/main/res/layout/fragment_status.xml diff --git a/app/build.gradle b/app/build.gradle index e2150b3..f33f564 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,5 @@ -apply plugin: 'idea' apply plugin: 'com.android.application' +apply plugin: 'idea' ext { appName = "Abit" @@ -44,6 +44,7 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile "com.android.support:appcompat-v7:$supportVersion" + compile "com.android.support:preference-v7:$supportVersion" compile "com.android.support:support-v4:$supportVersion" compile "com.android.support:design:$supportVersion" compile "com.android.support:multidex:1.0.1" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46c295..fb086cc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -84,16 +84,6 @@ - - - - - - - + android:parentActivityName=".MainActivity"> + android:value=".MainActivity"/> diff --git a/app/src/main/java/ch/dissem/apps/abit/AbstractItemListFragment.java b/app/src/main/java/ch/dissem/apps/abit/AbstractItemListFragment.java index b61de46..aeaed74 100644 --- a/app/src/main/java/ch/dissem/apps/abit/AbstractItemListFragment.java +++ b/app/src/main/java/ch/dissem/apps/abit/AbstractItemListFragment.java @@ -27,7 +27,7 @@ import ch.dissem.apps.abit.listener.ListSelectionListener; /** * @author Christian Basler */ -public abstract class AbstractItemListFragment extends ListFragment implements ListHolder { +public abstract class AbstractItemListFragment extends ListFragment implements ListHolder { /** * The serialization (saved instance state) Bundle key representing the * activated item position. Only used on tablets. @@ -143,4 +143,14 @@ public abstract class AbstractItemListFragment extends ListFragment implement activatedPosition = position; } + + @Override + public L getCurrentLabel() { + return null; + } + + @Override + public boolean showPreviousList() { + return false; + } } diff --git a/app/src/main/java/ch/dissem/apps/abit/AddressListFragment.java b/app/src/main/java/ch/dissem/apps/abit/AddressListFragment.java index 9633cbe..ee220a8 100644 --- a/app/src/main/java/ch/dissem/apps/abit/AddressListFragment.java +++ b/app/src/main/java/ch/dissem/apps/abit/AddressListFragment.java @@ -47,7 +47,7 @@ import io.github.yavski.fabspeeddial.SimpleMenuListenerAdapter; /** * Fragment that shows a list of all contacts, the ones we subscribed to first. */ -public class AddressListFragment extends AbstractItemListFragment { +public class AddressListFragment extends AbstractItemListFragment { private ArrayAdapter adapter; @Override @@ -166,7 +166,7 @@ public class AddressListFragment extends AbstractItemListFragment { + void updateList(L label); void setActivateOnItemClick(boolean activateOnItemClick); + + L getCurrentLabel(); + + boolean showPreviousList(); } 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 d8c40bf..0b6ed77 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MainActivity.java +++ b/app/src/main/java/ch/dissem/apps/abit/MainActivity.java @@ -21,6 +21,7 @@ import android.graphics.Point; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; @@ -195,11 +196,15 @@ public class MainActivity extends AppCompatActivity } private void changeList(F listFragment) { - getSupportFragmentManager() - .beginTransaction() - .replace(R.id.item_list, listFragment) - .addToBackStack(null) - .commit(); + + FragmentTransaction transaction = getSupportFragmentManager() + .beginTransaction(); + transaction.replace(R.id.item_list, listFragment); + Fragment detailFragment = getSupportFragmentManager().findFragmentById(R.id.message_detail_container); + if (detailFragment != null) { + transaction.remove(detailFragment); + } + transaction.addToBackStack(null).commit(); if (twoPane) { // In two-pane mode, list items should be given the @@ -325,15 +330,31 @@ public class MainActivity extends AppCompatActivity }.execute(); } + @Override + public void onBackPressed() { + Fragment listFragment = getSupportFragmentManager().findFragmentById(R.id.item_list); + if (listFragment instanceof ListHolder) { + ListHolder listHolder = (ListHolder) listFragment; + if (listHolder.showPreviousList()) { + IDrawerItem drawerItem = drawer.getDrawerItem(listHolder.getCurrentLabel()); + if (drawerItem != null){ + drawer.setSelection(drawerItem); + } + return; + } + } + super.onBackPressed(); + } + private class DrawerItemClickListener implements Drawer.OnDrawerItemClickListener { @Override public boolean onItemClick(View view, int position, IDrawerItem item) { + Fragment itemList = getSupportFragmentManager().findFragmentById(R.id.item_list); if (item.getTag() instanceof Label) { selectedLabel = (Label) item.getTag(); - if (getSupportFragmentManager().findFragmentById(R.id.item_list) instanceof + if (itemList instanceof MessageListFragment) { - ((MessageListFragment) getSupportFragmentManager() - .findFragmentById(R.id.item_list)).updateList(selectedLabel); + ((MessageListFragment) itemList).updateList(selectedLabel); } else { MessageListFragment listFragment = new MessageListFragment(); changeList(listFragment); @@ -344,17 +365,18 @@ public class MainActivity extends AppCompatActivity Nameable ni = (Nameable) item; switch (ni.getName().getTextRes()) { case R.string.contacts_and_subscriptions: - if (!(getSupportFragmentManager().findFragmentById(R.id - .item_list) instanceof AddressListFragment)) { + if (!(itemList instanceof AddressListFragment)) { changeList(new AddressListFragment()); } else { - ((AddressListFragment) getSupportFragmentManager() - .findFragmentById(R.id.item_list)).updateList(); + ((AddressListFragment) itemList).updateList(); } return false; case R.string.settings: - startActivity(new Intent(MainActivity.this, SettingsActivity - .class)); + getSupportFragmentManager() + .beginTransaction() + .replace(R.id.item_list, new SettingsFragment()) + .addToBackStack(null) + .commit(); return false; case R.string.full_node: return true; @@ -501,7 +523,7 @@ public class MainActivity extends AppCompatActivity Fragment fragment; if (item instanceof Plaintext) { fragment = new MessageDetailFragment(); - } else if (item instanceof String) { + } else if (item instanceof BitmessageAddress) { fragment = new AddressDetailFragment(); } else { throw new IllegalArgumentException("Plaintext or BitmessageAddress expected, but was " + item.getClass().getSimpleName()); @@ -517,7 +539,7 @@ public class MainActivity extends AppCompatActivity if (item instanceof Plaintext) { detailIntent = new Intent(this, MessageDetailActivity.class); detailIntent.putExtra(EXTRA_SHOW_LABEL, selectedLabel); - } else if (item instanceof String) { + } else if (item instanceof BitmessageAddress) { detailIntent = new Intent(this, AddressDetailActivity.class); } else { throw new IllegalArgumentException("Plaintext or BitmessageAddress expected, but " + @@ -529,6 +551,18 @@ public class MainActivity extends AppCompatActivity } } + public boolean hasDetailPane() { + return twoPane; + } + + public void setDetailView(Fragment fragment) { + if (twoPane) { + getSupportFragmentManager().beginTransaction() + .replace(R.id.message_detail_container, fragment) + .commit(); + } + } + @Override public void updateTitle(CharSequence title) { if (getSupportActionBar() != null) { 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 e3a187a..219436e 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.java +++ b/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.java @@ -38,10 +38,8 @@ import com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeMana import com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager; import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils; -import java.util.Collections; -import java.util.LinkedList; import java.util.List; -import java.util.Objects; +import java.util.Stack; import ch.dissem.apps.abit.adapter.SwipeableMessageAdapter; import ch.dissem.apps.abit.listener.ActionBarListener; @@ -51,7 +49,6 @@ import ch.dissem.apps.abit.service.Singleton; 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; import io.github.yavski.fabspeeddial.FabSpeedDial; import io.github.yavski.fabspeeddial.SimpleMenuListenerAdapter; @@ -68,7 +65,7 @@ import static ch.dissem.apps.abit.MessageDetailFragment.isInTrash; * Activities containing this fragment MUST implement the {@link ListSelectionListener} * interface. */ -public class MessageListFragment extends Fragment implements ListHolder { +public class MessageListFragment extends Fragment implements ListHolder