Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to choose book order and save setting #1122

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class NavigationControl @Inject constructor(
return bibleBookList
}

/**
* Toggle sort of Bible books by name or canonically
* */
fun changeBibleBookSortOrder() {
bibleBookSortOrder = if (bibleBookSortOrder == BibleBookSortOrder.BIBLE_BOOK) {
BibleBookSortOrder.ALPHABETICAL
Expand All @@ -105,7 +108,7 @@ class NavigationControl @Inject constructor(
}
}

private var bibleBookSortOrder: BibleBookSortOrder
var bibleBookSortOrder: BibleBookSortOrder
get() {
val bibleBookSortOrderStr = getSharedPreference(BIBLE_BOOK_SORT_ORDER, BibleBookSortOrder.BIBLE_BOOK.toString())
return BibleBookSortOrder.valueOf(bibleBookSortOrderStr!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View.OnClickListener
import androidx.core.view.children

import net.bible.android.activity.R
import net.bible.android.control.navigation.BibleBookSortOrder
import net.bible.android.control.navigation.NavigationControl
import net.bible.android.control.page.window.ActiveWindowPageManagerProvider
import net.bible.android.view.activity.base.CustomTitlebarActivityBase
Expand Down Expand Up @@ -55,7 +58,7 @@ import javax.inject.Inject
*
* @author Martin Denham [mjdenham at gmail dot com]
*/
class GridChoosePassageBook : CustomTitlebarActivityBase(), OnButtonGridActionListener {
class GridChoosePassageBook : CustomTitlebarActivityBase(R.menu.choose_passage_book_menu), OnButtonGridActionListener {

private lateinit var buttonGrid: ButtonGrid

Expand Down Expand Up @@ -118,16 +121,6 @@ class GridChoosePassageBook : CustomTitlebarActivityBase(), OnButtonGridActionLi
bibleBookActionBarManager.setScriptureShown(isCurrentlyShowingScripture)
}

/**
* Handle scripture/Appendix toggle
*/
private val sortOrderClickListener = OnClickListener {
navigationControl.changeBibleBookSortOrder()

buttonGrid.clear()
buttonGrid.addButtons(bibleBookButtonInfo)
}

private var navigateToVerse: Boolean = false

/** Called when the activity is first created. */
Expand All @@ -149,7 +142,6 @@ class GridChoosePassageBook : CustomTitlebarActivityBase(), OnButtonGridActionLi
navigateToVerse = intent?.extras?.getBoolean("navigateToVerse", navigateToVerseDefault)?:navigateToVerseDefault

bibleBookActionBarManager.registerScriptureToggleClickListener(scriptureToggleClickListener)
bibleBookActionBarManager.sortButton.registerClickListener(sortOrderClickListener)

setActionBarManager(bibleBookActionBarManager)

Expand All @@ -161,12 +153,38 @@ class GridChoosePassageBook : CustomTitlebarActivityBase(), OnButtonGridActionLi
buttonGrid = ButtonGrid(this)
buttonGrid.setOnButtonGridActionListener(this)
buttonGrid.addButtons(bibleBookButtonInfo)
buttonGrid.isLeftToRightEnabled = CommonUtils.sharedPreferences.getBoolean(BOOK_GRID_FLOW_PREFS, false)

setContentView(buttonGrid)
}

override fun onPrepareOptionsMenu(menu: Menu): Boolean {
val sortOptionItem = menu.children.first { it.itemId == R.id.alphabetical_order_opt }
sortOptionItem.isChecked = navigationControl.bibleBookSortOrder == BibleBookSortOrder.ALPHABETICAL
val rowDistributionItem = menu.children.first { it.itemId == R.id.row_order_opt }
buttonGrid.isLeftToRightEnabled = CommonUtils.sharedPreferences.getBoolean(BOOK_GRID_FLOW_PREFS, false)
rowDistributionItem.isChecked = buttonGrid.isLeftToRightEnabled
return super.onPrepareOptionsMenu(menu)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.alphabetical_order_opt -> {
navigationControl.changeBibleBookSortOrder()
buttonGrid.clear()
buttonGrid.addButtons(bibleBookButtonInfo)
true
}
R.id.row_order_opt -> {
buttonGrid.toggleLeftToRight()
item.isChecked = buttonGrid.isLeftToRightEnabled
buttonGrid.clear()
buttonGrid.addButtons(bibleBookButtonInfo)
CommonUtils.sharedPreferences.edit()
.putBoolean(BOOK_GRID_FLOW_PREFS, item.isChecked)
.apply()
true
}
android.R.id.home -> {
onBackPressed()
true
Expand Down Expand Up @@ -295,6 +313,7 @@ class GridChoosePassageBook : CustomTitlebarActivityBase(), OnButtonGridActionLi
private val REVELATION_COLOR = Color.rgb(0xFE, 0x33, 0xFF)
private val OTHER_COLOR = ACTS_COLOR

private const val BOOK_GRID_FLOW_PREFS = "book_grid_ltr"
private const val TAG = "GridChoosePassageBook"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import javax.inject.Inject
* @author Martin Denham [mjdenham at gmail dot com]
*/
@ApplicationScope
class BibleBookActionBarManager @Inject constructor(private val scriptureToggleActionBarButton: ScriptureToggleActionBarButton, val sortButton: SortActionBarButton) : DefaultActionBarManager(), ActionBarManager {
class BibleBookActionBarManager @Inject constructor(private val scriptureToggleActionBarButton: ScriptureToggleActionBarButton) : DefaultActionBarManager(), ActionBarManager {
fun registerScriptureToggleClickListener(scriptureToggleClickListener: View.OnClickListener?) {
scriptureToggleActionBarButton.registerClickListener(scriptureToggleClickListener)
}
Expand All @@ -46,7 +46,6 @@ class BibleBookActionBarManager @Inject constructor(private val scriptureToggleA
override fun prepareOptionsMenu(activity: Activity, menu: Menu, actionBar: ActionBar) {
super.prepareOptionsMenu(activity, menu, actionBar)
scriptureToggleActionBarButton.addToMenu(menu)
sortButton.addToMenu(menu)
}

/* (non-Javadoc)
Expand All @@ -58,7 +57,6 @@ class BibleBookActionBarManager @Inject constructor(private val scriptureToggleA
// this can be called on end of speech in non-ui thread
CurrentActivityHolder.getInstance().runOnUiThread {
scriptureToggleActionBarButton.update()
sortButton.update()
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ButtonGrid constructor(context: Context, attrs: AttributeSet? = null, defS
private var rowColLayout: RowColLayout? = null
private var pressed: ButtonInfo? = null
private var isInitialised = false
var isLeftToRightEnabled = false

fun clear() {
removeAllViews()
Expand Down Expand Up @@ -144,14 +145,18 @@ class ButtonGrid constructor(context: Context, attrs: AttributeSet? = null, defS
previewHeight = (PREVIEW_HEIGHT_DIP * scale).toInt()
}

fun toggleLeftToRight() {
isLeftToRightEnabled = !isLeftToRightEnabled
}

/** Ensure longer runs by populating in longest direction ie columns if portrait and rows if landscape
*
* @param row
* @param col
* @return
*/
private fun getButtonInfoIndex(row: Int, col: Int): Int {
return if (rowColLayout!!.columnOrder) {
return if (rowColLayout!!.columnOrder && !isLeftToRightEnabled) {
col * rowColLayout!!.rows + row
} else {
row * rowColLayout!!.cols + col
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/menu/choose_passage_book_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/alphabetical_order_opt"
android:title="@string/sort_by_alphabetical"
android:checkable="true"/>

<item
android:id="@+id/row_order_opt"
android:title="Flow by row (LTR)"
jmarsican marked this conversation as resolved.
Show resolved Hide resolved
android:checkable="true"/>

</menu>