mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-12-22 14:48:23 -05:00
Bring in the new navigation menu
API v8-compliant, sized correctly, all that good jazz.
This commit is contained in:
parent
51783afc0b
commit
21f940d767
@ -1,22 +1,20 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.acra.ReportingInteractionMode;
|
||||
import org.acra.annotation.ReportsCrashes;
|
||||
|
||||
/**
|
||||
* Create a MinimalBible application that we can extend from the main release
|
||||
* Currently it's not doing much, but would allow for shenanigans during testing in the future
|
||||
*/
|
||||
/*
|
||||
@ReportsCrashes(formKey = "",
|
||||
mailTo = "bspeice.nc@gmail.com",
|
||||
mode = ReportingInteractionMode.SILENT
|
||||
)
|
||||
*/
|
||||
public class MinimalBibleDebug extends MinimalBible implements Injector {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
ACRA.init(this);
|
||||
// ACRA.init(this);
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
android:theme="@style/MinimalBible">
|
||||
<activity
|
||||
android:name=".activity.downloader.DownloadActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name" />
|
||||
<activity
|
||||
android:name=".activity.settings.MinimalBibleSettings"
|
||||
|
@ -30,7 +30,7 @@ public class BaseActivity extends ActionBarActivity {
|
||||
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());
|
||||
view.setPadding(0, config.getPixelInsetTop(false), config.getPixelInsetRight(), config.getPixelInsetBottom());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -99,9 +99,11 @@ public abstract class AbstractNavDrawerFragment extends Fragment {
|
||||
GravityCompat.START);
|
||||
// set up the drawer's list view with items and click listener
|
||||
|
||||
/* TODO: Switch to Toolbar
|
||||
ActionBar actionBar = getActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
*/
|
||||
|
||||
// ActionBarDrawerToggle ties together the the proper interactions
|
||||
// between the navigation drawer and the action bar app icon.
|
||||
|
@ -1,15 +1,15 @@
|
||||
package org.bspeice.minimalbible.activity.viewer;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
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.crosswire.jsword.book.Book;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -26,7 +26,7 @@ public class BibleViewer extends BaseActivity implements Injector {
|
||||
Book mainBook;
|
||||
|
||||
@InjectView(R.id.navigation_drawer)
|
||||
ListView drawerContent;
|
||||
BibleMenu bibleMenu;
|
||||
|
||||
@InjectView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@ -57,23 +57,26 @@ public class BibleViewer extends BaseActivity implements Injector {
|
||||
|
||||
/**
|
||||
* Set up the application
|
||||
*
|
||||
* @param savedInstanceState Android's savedInstanceState
|
||||
*/
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
this.inject(this);
|
||||
|
||||
// Check that we have a book installed
|
||||
if (mainBook == null) {
|
||||
// No books installed, start the downloader.
|
||||
Intent i = new Intent(this, DownloadActivity.class);
|
||||
startActivityForResult(i, 0);
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_bible_viewer);
|
||||
ButterKnife.inject(this);
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
String[] drawerStrings = new String[]{"Content 1", "Content 2"};
|
||||
drawerContent.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
|
||||
drawerStrings));
|
||||
|
||||
setInsets(this, drawerContent);
|
||||
bibleMenu.setBible(mainBook);
|
||||
setInsets(this, bibleMenu);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package org.bspeice.minimalbible.activity
|
||||
|
||||
import android.view.View
|
||||
import android.os.Build
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager
|
||||
import android.app.Activity
|
||||
|
||||
/**
|
||||
* Created by bspeice on 12/22/14.
|
||||
*/
|
||||
|
||||
fun View.setInset(a: Activity) {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
|
||||
val config = SystemBarTintManager(a).getConfig()
|
||||
this.setPadding(0, config.getPixelInsetTop(false),
|
||||
config.getPixelInsetRight(), config.getPixelInsetBottom())
|
||||
}
|
||||
}
|
@ -15,12 +15,29 @@ import android.content.res.Resources
|
||||
import android.support.annotation.IdRes
|
||||
import android.widget.ExpandableListView
|
||||
import rx.subjects.PublishSubject
|
||||
import android.widget.LinearLayout
|
||||
import android.app.Activity
|
||||
import android.util.AttributeSet
|
||||
import kotlin.properties.Delegates
|
||||
import org.bspeice.minimalbible.activity.setInset
|
||||
import android.support.annotation.LayoutRes
|
||||
|
||||
/**
|
||||
* Created by bspeice on 10/24/14.
|
||||
*/
|
||||
class BibleMenu(val ctx: Context, val attrs: AttributeSet) : LinearLayout(ctx, attrs) {
|
||||
var menuContent: ExpandableListView by Delegates.notNull();
|
||||
|
||||
class BibleMenu(val b: Book) : BaseExpandableListAdapter() {
|
||||
{
|
||||
val inflater = ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
inflater.inflate(R.layout.view_bible_menu, this, true)
|
||||
|
||||
menuContent = findViewById(R.id.menu) as ExpandableListView
|
||||
}
|
||||
|
||||
fun setBible(b: Book) = menuContent.setAdapter(BibleAdapter(b))
|
||||
|
||||
fun placeInset(a: Activity) = setInset(a)
|
||||
}
|
||||
|
||||
class BibleAdapter(val b: Book) : BaseExpandableListAdapter() {
|
||||
|
||||
// Map BibleBooks to the number of chapters they have
|
||||
val menuMappings = b.getVersification().getBooks().map {
|
||||
@ -65,15 +82,16 @@ class BibleMenu(val b: Book) : BaseExpandableListAdapter() {
|
||||
override fun isChildSelectable(group: Int, child: Int): Boolean = true
|
||||
|
||||
private fun doBinding(convertView: View?, parent: ViewGroup,
|
||||
obj: Any, highlight: Boolean): View {
|
||||
obj: Any, highlight: Boolean,
|
||||
LayoutRes layout: Int): View {
|
||||
val finalView: View = convertView ?:
|
||||
(parent.getContext()
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater)
|
||||
.inflate(R.layout.list_navigation_drawer, parent, false)
|
||||
.inflate(layout, parent, false)
|
||||
|
||||
val holder: NavItemHolder =
|
||||
if (finalView.getTag() != null) finalView.getTag() as NavItemHolder
|
||||
else NavItemHolder(finalView, R.id.navlist_content)
|
||||
else NavItemHolder(finalView, R.id.content)
|
||||
|
||||
holder.bind(obj, highlight)
|
||||
finalView setTag holder
|
||||
@ -82,11 +100,14 @@ class BibleMenu(val b: Book) : BaseExpandableListAdapter() {
|
||||
|
||||
override fun getGroupView(position: Int, expanded: Boolean,
|
||||
convertView: View?, parent: ViewGroup): View =
|
||||
doBinding(convertView, parent, getGroup(position), position == groupHighlighted)
|
||||
doBinding(convertView, parent, getGroup(position),
|
||||
position == groupHighlighted, R.layout.list_bible_menu_group)
|
||||
|
||||
override fun getChildView(group: Int, child: Int, isLast: Boolean,
|
||||
convertView: View?, parent: ViewGroup): View =
|
||||
doBinding(convertView, parent, getChild(group, child), child == childHighlighted)
|
||||
doBinding(convertView, parent, getChild(group, child),
|
||||
group == groupHighlighted && child == childHighlighted,
|
||||
R.layout.list_bible_menu_child)
|
||||
|
||||
class NavItemHolder(val bindTo: View, IdRes resource: Int) {
|
||||
val content = bindTo.findViewById(resource) as TextView
|
||||
|
@ -25,17 +25,14 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Main Content" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Navigation drawer - layout_gravity:start activates the magic. -->
|
||||
<ListView
|
||||
<org.bspeice.minimalbible.activity.viewer.BibleMenu
|
||||
android:id="@+id/navigation_drawer"
|
||||
style="@style/MinimalBible.NavigationDrawer"
|
||||
android:layout_width="@dimen/navigation_drawer_width"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
android:fitsSystemWindows="true" />
|
||||
android:layout_gravity="start" />
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
|
16
app/src/main/res/layout/list_bible_menu_child.xml
Normal file
16
app/src/main/res/layout/list_bible_menu_child.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
|
||||
android:paddingRight="?android:attr/expandableListPreferredChildPaddingLeft"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</LinearLayout>
|
16
app/src/main/res/layout/list_bible_menu_group.xml
Normal file
16
app/src/main/res/layout/list_bible_menu_group.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
|
||||
android:paddingRight="?android:attr/expandableListPreferredChildPaddingLeft"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
</LinearLayout>
|
28
app/src/main/res/layout/view_bible_menu.xml
Normal file
28
app/src/main/res/layout/view_bible_menu.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Both paddingLeft and Right are given to support RtL
|
||||
layouts without worrying about min API and paddingStart shenanigans -->
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/colorPrimary"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:text="@string/app_name"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
|
||||
|
||||
<ExpandableListView
|
||||
android:id="@+id/menu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
|
||||
</LinearLayout>
|
@ -10,5 +10,4 @@
|
||||
<style name="ActionBar" parent="@style/Widget.AppCompat.ActionBar">
|
||||
<item name="android:background">@color/colorPrimary</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -6,6 +6,7 @@
|
||||
<!-- Per the design guidelines, navigation drawers should be between 240dp and 320dp:
|
||||
https://developer.android.com/design/patterns/navigation-drawer.html -->
|
||||
<dimen name="navigation_drawer_width">240dp</dimen>
|
||||
|
||||
<dimen name="navigation_drawer_highlight_height">32dp</dimen>
|
||||
|
||||
<dimen name="toolbar_height">56dp</dimen>
|
||||
</resources>
|
||||
|
@ -5,13 +5,9 @@
|
||||
<item name="android:textColorPrimary">@color/textColorPrimary</item>
|
||||
</style>
|
||||
|
||||
<!-- Actual application style. Allows selective over-riding while inheriting
|
||||
from the parent -->
|
||||
<style name="MinimalBible" parent="MinimalBibleBase" />
|
||||
|
||||
<!-- Almost re-use style from Widget.Holo.Button.Borderless -->
|
||||
<style name="MinimalBibleBase.Borderless">
|
||||
<item name="android:background">?android:attr/selectableItemBackground</item>
|
||||
<item name="android:background">?android:attr/selectableItemBackground</item>
|
||||
<item name="android:paddingLeft">4dip</item>
|
||||
<item name="android:paddingRight">4dip</item>
|
||||
<!-- Requires API 17
|
||||
@ -20,8 +16,14 @@
|
||||
-->
|
||||
</style>
|
||||
|
||||
<style name="MinimalBible.NavigationDrawer">
|
||||
<style name="MinimalBibleBase.NavigationDrawer">
|
||||
<item name="android:background">@color/navigationBackground</item>
|
||||
<item name="android:paddingLeft">8dp</item>
|
||||
</style>
|
||||
|
||||
<!-- Actual application style. Allows selective over-riding while inheriting
|
||||
from the parent -->
|
||||
<style name="MinimalBible" parent="MinimalBibleBase" />
|
||||
|
||||
<style name="MinimalBible.NavigationDrawer" parent="MinimalBibleBase.NavigationDrawer" />
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user