From 51783afc0b680e052fe06d39c109da86535428a8 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sun, 21 Dec 2014 23:23:12 -0500 Subject: [PATCH] Sometimes you have to destroy first to create Re-writing most of the UI for Material compliance. This is going to be a significant effort, but the final product is going to look *much* nicer for it. --- app/src/main/AndroidManifest.xml | 4 +- .../minimalbible/activity/BaseActivity.java | 51 ++++++-- .../activity/navigation/ListNavAdapter.java | 4 +- .../activity/viewer/BibleViewer.java | 114 +++--------------- .../activity/viewer/BibleViewerModules.java | 6 +- .../viewer/BookChapterNavFragment.java | 52 -------- .../activity/viewer/BookFragment.java | 102 ---------------- .../minimalbible/activity/viewer/BibleMenu.kt | 7 +- .../main/res/layout/activity_bible_viewer.xml | 43 ++++--- .../main/res/layout/list_download_items.xml | 28 ++--- .../main/res/layout/viewer_passage_view.xml | 3 +- app/src/main/res/values-v19/styles.xml | 10 +- app/src/main/res/values/colors.xml | 14 ++- app/src/main/res/values/styles.xml | 17 ++- 14 files changed, 127 insertions(+), 328 deletions(-) delete mode 100644 app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookChapterNavFragment.java delete mode 100644 app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookFragment.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8318440..1f5d14c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,7 +10,7 @@ android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" - android:theme="@style/AppTheme"> + android:theme="@style/MinimalBible"> @@ -21,7 +21,7 @@ android:name=".activity.viewer.BibleViewer" android:label="@string/app_name"> - + diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/BaseActivity.java b/app/src/main/java/org/bspeice/minimalbible/activity/BaseActivity.java index f3f59ed..7086cf4 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/BaseActivity.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/BaseActivity.java @@ -1,8 +1,10 @@ package org.bspeice.minimalbible.activity; +import android.app.Activity; import android.os.Build; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; +import android.view.View; import com.readystatesoftware.systembartint.SystemBarTintManager; @@ -14,17 +16,44 @@ import org.bspeice.minimalbible.R; */ public class BaseActivity extends ActionBarActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + protected static SystemBarTintManager.SystemBarConfig getConfig(Activity context) { + return new SystemBarTintManager(context).getConfig(); + } - // Only set the tint if the device is running KitKat or above - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - SystemBarTintManager tintManager = new SystemBarTintManager(this); - tintManager.setStatusBarTintEnabled(true); - tintManager.setStatusBarTintColor(getResources().getColor( - R.color.statusbar)); - } - } + /** + * Calculate the offset we need to display properly if the System bar is translucent + * + * @param context The {@link android.app.Activity} we are displaying in + * @param view The {@link android.view.View} we need to calculate the offset for. + */ + @SuppressWarnings("unused") + protected static void setInsets(Activity context, View view) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return; + SystemBarTintManager.SystemBarConfig config = getConfig(context); + view.setPadding(0, config.getPixelInsetTop(true), config.getPixelInsetRight(), config.getPixelInsetBottom()); + } + @SuppressWarnings("unused") + protected static void setInsetsSpinner(Activity context, View view) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return; + SystemBarTintManager.SystemBarConfig config = getConfig(context); + int marginTopBottom = config.getPixelInsetBottom() / 3; + view.setPadding(0, config.getPixelInsetTop(true) + marginTopBottom, + config.getPixelInsetRight(), + marginTopBottom); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Only set the tint if the device is running KitKat or above + // TODO: Can this be set as part of styles.xml? + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + SystemBarTintManager tintManager = new SystemBarTintManager(this); + tintManager.setStatusBarTintEnabled(true); + tintManager.setStatusBarTintColor(getResources().getColor( + R.color.colorPrimary)); + } + } } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/navigation/ListNavAdapter.java b/app/src/main/java/org/bspeice/minimalbible/activity/navigation/ListNavAdapter.java index 2829d1f..a16c54b 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/navigation/ListNavAdapter.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/navigation/ListNavAdapter.java @@ -89,9 +89,7 @@ public class ListNavAdapter extends BaseAdapter { public void bind() { content.setText(object.toString()); if (highlighted) { - content.setTextColor(v.getResources().getColor(R.color.navbar_highlight)); - } else { - content.setTextColor(v.getResources().getColor(R.color.navbar_unhighlighted)); + content.setTextColor(v.getResources().getColor(R.color.colorPrimary)); } } } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewer.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewer.java index 44dc3e9..d2a8986 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewer.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewer.java @@ -1,49 +1,37 @@ package org.bspeice.minimalbible.activity.viewer; -import android.content.Intent; import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.ActionBar; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; +import android.support.v7.widget.Toolbar; +import android.widget.ArrayAdapter; +import android.widget.ListView; import org.bspeice.minimalbible.Injector; import org.bspeice.minimalbible.MinimalBible; import org.bspeice.minimalbible.OGHolder; import org.bspeice.minimalbible.R; import org.bspeice.minimalbible.activity.BaseActivity; -import org.bspeice.minimalbible.activity.downloader.DownloadActivity; -import org.bspeice.minimalbible.activity.navigation.NavDrawerFragment; -import org.bspeice.minimalbible.activity.settings.MinimalBibleSettings; import org.crosswire.jsword.book.Book; import javax.inject.Inject; import javax.inject.Named; +import butterknife.ButterKnife; +import butterknife.InjectView; import dagger.ObjectGraph; -public class BibleViewer extends BaseActivity implements - NavDrawerFragment.NavigationDrawerCallbacks, - Injector { +public class BibleViewer extends BaseActivity implements Injector { @Inject @Named("MainBook") Book mainBook; + @InjectView(R.id.navigation_drawer) + ListView drawerContent; + + @InjectView(R.id.toolbar) + Toolbar toolbar; + private ObjectGraph bvObjectGraph; - /** - * Fragment managing the behaviors, interactions and presentation of the - * navigation drawer. - */ - private BookChapterNavFragment mNavigationDrawerFragment; - /** - * Used to store the last screen title. For use in - * {@link #restoreActionBar()}. - */ - private CharSequence mTitle; /** * Build a scoped object graph for anything used by the BibleViewer @@ -69,8 +57,6 @@ public class BibleViewer extends BaseActivity implements /** * Set up the application - * TODO: Get the main book, rather than the first installed book. - * * @param savedInstanceState Android's savedInstanceState */ @Override @@ -79,75 +65,15 @@ public class BibleViewer extends BaseActivity implements this.inject(this); - // If no books are installed, we need to download one first. - if (mainBook == null) { - // If there are no books installed... - Log.e(getLocalClassName(), "No books are currently installed, starting DownloadManager"); - Intent i = new Intent(BibleViewer.this, DownloadActivity.class); - startActivityForResult(i, 0); - finish(); - } else { - FragmentManager fragmentManager = getSupportFragmentManager(); - Fragment f = BookFragment.newInstance(mainBook.getName()); - fragmentManager.beginTransaction() - .replace(R.id.container, f) - .commit(); - setContentView(R.layout.activity_bible_viewer); + setContentView(R.layout.activity_bible_viewer); + ButterKnife.inject(this); - mNavigationDrawerFragment = (BookChapterNavFragment) getSupportFragmentManager() - .findFragmentById(R.id.navigation_drawer); - mTitle = getTitle(); + setSupportActionBar(toolbar); - // Set up the drawer. - mNavigationDrawerFragment.setUp(R.id.navigation_drawer, - (DrawerLayout) findViewById(R.id.drawer_layout)); - } + String[] drawerStrings = new String[]{"Content 1", "Content 2"}; + drawerContent.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, + drawerStrings)); + + setInsets(this, drawerContent); } - - @Override - public void onNavigationDrawerItemSelected(int position) { - // Handle a navigation movement - } - - public void setActionBarTitle(String title) { - ActionBar actionBar = getSupportActionBar(); - mTitle = title; - actionBar.setTitle(title); - } - - public void restoreActionBar() { - ActionBar actionBar = getSupportActionBar(); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setTitle(mTitle); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - if (mNavigationDrawerFragment != null && - !mNavigationDrawerFragment.isDrawerOpen()) { - // Only show items in the action bar relevant to this screen - // if the drawer is not showing. Otherwise, let the drawer - // decide what to show in the action bar. - getMenuInflater().inflate(R.menu.main, menu); - restoreActionBar(); - return true; - } - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - if (id == R.id.action_settings) { - Intent i = new Intent(this, MinimalBibleSettings.class); - startActivityForResult(i, 0); - } else if (id == R.id.action_downloads) { - startActivity(new Intent(this, DownloadActivity.class)); - } - return super.onOptionsItemSelected(item); - } } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java index 9627a9d..13ed5e7 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java @@ -16,7 +16,6 @@ import dagger.Provides; import de.devland.esperandro.Esperandro; import rx.functions.Action1; import rx.functions.Func1; -import rx.subjects.PublishSubject; /** * Modules used for the BibleViewer activity @@ -24,8 +23,6 @@ import rx.subjects.PublishSubject; @Module( injects = { BibleViewer.class, - BookFragment.class, - BookChapterNavFragment.class } ) @SuppressWarnings("unused") @@ -96,6 +93,8 @@ public class BibleViewerModules { return new BookManager(); } + /* + Commenting, as I will likely need these in the near future. @Provides @Named("MainAdapter") @Singleton @@ -108,4 +107,5 @@ public class BibleViewerModules { PublishSubject scrollEventProvider() { return PublishSubject.create(); } + */ } \ No newline at end of file diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookChapterNavFragment.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookChapterNavFragment.java deleted file mode 100644 index 76725bb..0000000 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookChapterNavFragment.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.bspeice.minimalbible.activity.viewer; - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ExpandableListView; - -import org.bspeice.minimalbible.Injector; -import org.bspeice.minimalbible.R; -import org.bspeice.minimalbible.activity.navigation.NavDrawerFragment; -import org.crosswire.jsword.book.Book; - -import javax.inject.Inject; -import javax.inject.Named; - -import rx.subjects.PublishSubject; - -/** - * ExpandableListView for managing books of the Bible. - * We extend from @link{BaseNavigationDrawerFragment} so we can inherit some of the lifecycle - * pieces, but the actual view inflation is done by us. - * I tried to refactor this into Kotlin, but I need to inject the vUtil and mainBook, - * and trying to getActivity() as BibleViewer yielded TypeCastException - * TODO: Extend BaseExpNavigationDrawerFragment? - */ -public class BookChapterNavFragment extends NavDrawerFragment { - - @Inject @Named("MainBook") - Book mainBook; - - @Inject - PublishSubject scrollListener; - - ExpandableListView mActualListView; - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - Injector i = (Injector) getActivity(); - i.inject(this); - - BibleMenu menu = new BibleMenu(mainBook); - mActualListView = (ExpandableListView) inflater.inflate( - R.layout.fragment_expandable_navigation_drawer, container, false); - mActualListView.setAdapter(menu); - mActualListView.setOnChildClickListener(menu.getMenuClickListener(scrollListener)); - - mActualListView.setItemChecked(mCurrentSelectedPosition, true); - return mActualListView; - } -} diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookFragment.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookFragment.java deleted file mode 100644 index 8bf53b5..0000000 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookFragment.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.bspeice.minimalbible.activity.viewer; - -import android.app.Activity; -import android.os.Bundle; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import org.bspeice.minimalbible.Injector; -import org.bspeice.minimalbible.R; -import org.bspeice.minimalbible.activity.BaseFragment; -import org.crosswire.jsword.book.Book; - -import javax.inject.Inject; -import javax.inject.Named; - -import butterknife.ButterKnife; -import butterknife.InjectView; -import rx.subjects.PublishSubject; - -/** - * A placeholder fragment containing a simple view. - */ -public class BookFragment extends BaseFragment { - - private static final String ARG_BOOK_NAME = "book_name"; - - Injector i; - @Inject - @Named("MainBook") - Book mBook; - @Inject - PublishSubject scrollEventProvider; - @Inject - @Named("MainAdapter") - BookAdapter adapter; - - @InjectView(R.id.book_content) - RecyclerView bookContent; - - /** - * Returns a new instance of this fragment for the given book. - */ - public static BookFragment newInstance(String bookName) { - BookFragment fragment = new BookFragment(); - Bundle args = new Bundle(); - args.putString(ARG_BOOK_NAME, bookName); - fragment.setArguments(args); - return fragment; - } - - @Override - public void onCreate(Bundle state) { - super.onCreate(state); - - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_viewer_main, container, - false); - this.i = (Injector) getActivity(); - i.inject(this); - ButterKnife.inject(this, rootView); - - // TODO: Load initial text from SharedPreferences, rather than getting the actual book. - displayBook(mBook); - - return rootView; - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - } - - /*---------------------------------------- - Here be all the methods you want to spend time with - ---------------------------------------- - */ - - /** - * Do the initial work of displaying a book. Requires setting up WebView, etc. - * TODO: Get initial content from cache? - * - * @param b The book we want to display - */ - private void displayBook(Book b) { - Log.d("BookFragment", b.getName()); - ((BibleViewer)getActivity()).setActionBarTitle(b.getInitials()); - - final RecyclerView.LayoutManager manager = new LinearLayoutManager(getActivity()); - bookContent.setLayoutManager(manager); - bookContent.setAdapter(adapter); - - adapter.bindScrollHandler(scrollEventProvider, manager); - } -} diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleMenu.kt b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleMenu.kt index 9bc6a95..7ce30a7 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleMenu.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleMenu.kt @@ -92,10 +92,9 @@ class BibleMenu(val b: Book) : BaseExpandableListAdapter() { val content = bindTo.findViewById(resource) as TextView val resources = bindTo.getResources(): Resources - fun getHighlightedColor(highlighted: Boolean) = when(highlighted) { - true -> resources getColor R.color.navbar_highlight - else -> resources getColor R.color.navbar_unhighlighted // false - } + fun getHighlightedColor(highlighted: Boolean) = + if (highlighted) resources getColor R.color.colorAccent + else resources getColor R.color.textColor fun bind(obj: Any, highlighted: Boolean) { content setText obj.toString() diff --git a/app/src/main/res/layout/activity_bible_viewer.xml b/app/src/main/res/layout/activity_bible_viewer.xml index 9f13347..9a15ffe 100644 --- a/app/src/main/res/layout/activity_bible_viewer.xml +++ b/app/src/main/res/layout/activity_bible_viewer.xml @@ -6,37 +6,36 @@ android:layout_height="match_parent" tools:context="org.bspeice.minimalbible.activities.viewer.BibleViewer"> - - - + + android:fitsSystemWindows="true" + android:orientation="vertical"> - - + - + + + + + + diff --git a/app/src/main/res/layout/list_download_items.xml b/app/src/main/res/layout/list_download_items.xml index 4e93430..a5f3eb6 100644 --- a/app/src/main/res/layout/list_download_items.xml +++ b/app/src/main/res/layout/list_download_items.xml @@ -7,39 +7,39 @@ android:padding="8dp"> + android:textAppearance="?android:attr/textAppearanceMedium" /> + android:layout_below="@+id/txt_download_item_name" + android:paddingTop="4dp" + android:textAppearance="?android:attr/textAppearanceSmall" /> + android:src="@drawable/ic_action_download" /> + app:barWidth="4dp" + app:rimWidth="0dp" /> \ No newline at end of file diff --git a/app/src/main/res/layout/viewer_passage_view.xml b/app/src/main/res/layout/viewer_passage_view.xml index 844bf77..7bb3156 100644 --- a/app/src/main/res/layout/viewer_passage_view.xml +++ b/app/src/main/res/layout/viewer_passage_view.xml @@ -3,5 +3,4 @@ android:id="@+id/passage" android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="vertical" - android:textColor="@color/content_text" /> + android:orientation="vertical" /> diff --git a/app/src/main/res/values-v19/styles.xml b/app/src/main/res/values-v19/styles.xml index cc0a9e8..3a432c3 100644 --- a/app/src/main/res/values-v19/styles.xml +++ b/app/src/main/res/values-v19/styles.xml @@ -1,12 +1,6 @@ - - \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 37bb5d8..66ce70c 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,8 +1,12 @@ - #dddddd - #ffffff - #cc0000 - #000000 - #000000 + #f44336 + #ffffff + #d50000 + #ffffff + + #000000 + + #cccccc + #000 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index d42c3f0..a2c60c4 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,16 +1,17 @@ - - - + +