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.
This commit is contained in:
Bradlee Speice
2014-12-21 23:23:12 -05:00
parent e1ab61dd5f
commit 51783afc0b
14 changed files with 127 additions and 328 deletions

View File

@ -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));
}
}
}

View File

@ -89,9 +89,7 @@ public class ListNavAdapter<T> 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));
}
}
}

View File

@ -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);
}
}

View File

@ -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<BookScrollEvent> scrollEventProvider() {
return PublishSubject.create();
}
*/
}

View File

@ -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<BookScrollEvent> 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;
}
}

View File

@ -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<BookScrollEvent> 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);
}
}