Skip to content

Commit

Permalink
feat: Display system bars when opening reader menu (#212)
Browse files Browse the repository at this point in the history
Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam authored Sep 13, 2024
1 parent 61561ca commit c9ebdf5
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 20 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion app/src/main/java/com/starry/myne/epub/EpubParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import java.util.zip.ZipInputStream
*/
class EpubParser(private val context: Context) {


/**
* Represents an EPUB document.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ class ReaderActivity : AppCompatActivity() {
}

// Reader content lazy column.
ReaderContent(viewModel = viewModel, lazyListState = lazyListState)
ReaderContent(
state = viewModel.state,
lazyListState = lazyListState,
onToggleReaderMenu = {
viewModel.toggleReaderMenu()
toggleSystemBars(viewModel.state.showReaderMenu)
})
})
}
}
Expand All @@ -154,6 +160,25 @@ class ReaderActivity : AppCompatActivity() {
// Keep screen on.
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}

private fun toggleSystemBars(show: Boolean) {
when (show) {
true -> showSystemBars()
false -> hideSystemBars()
}
}

private fun showSystemBars() {
val controller = WindowInsetsControllerCompat(window, window.decorView)
controller.show(WindowInsetsCompat.Type.systemBars())
controller.show(WindowInsetsCompat.Type.displayCutout())
}

private fun hideSystemBars() {
val controller = WindowInsetsControllerCompat(window, window.decorView)
controller.hide(WindowInsetsCompat.Type.systemBars())
controller.hide(WindowInsetsCompat.Type.displayCutout())
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,31 @@ import com.starry.myne.epub.models.EpubChapter
import com.starry.myne.helpers.toToast
import com.starry.myne.ui.common.MyneSelectionContainer
import com.starry.myne.ui.screens.reader.viewmodels.ReaderScreenState
import com.starry.myne.ui.screens.reader.viewmodels.ReaderViewModel
import com.starry.myne.ui.theme.pacificoFont


@Composable
fun ReaderContent(
viewModel: ReaderViewModel,
state: ReaderScreenState,
lazyListState: LazyListState,
onToggleReaderMenu: () -> Unit
) {
LazyColumn(
modifier = Modifier.fillMaxSize(),
state = lazyListState
) {
items(
count = viewModel.state.epubBook!!.chapters.size,
key = { index -> viewModel.state.epubBook!!.chapters[index].hashCode() }
count = state.epubBook!!.chapters.size,
key = { index -> state.epubBook.chapters[index].hashCode() }
) { index ->
val chapter = viewModel.state.epubBook!!.chapters[index]
val chapter = state.epubBook.chapters[index]
ChapterLazyItemItem(
chapter = chapter,
state = viewModel.state,
onClick = { viewModel.toggleReaderMenu() }
state = state,
onClick = onToggleReaderMenu
)
}
}


}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
Expand Down Expand Up @@ -131,6 +132,7 @@ fun ReaderScreen(
}

ModalNavigationDrawer(
modifier = Modifier.systemBarsPadding(),
drawerState = drawerState,
gesturesEnabled = drawerState.isOpen,
drawerContent = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ class ReaderViewModel @Inject constructor(
}

fun toggleReaderMenu() {
state = if (state.showReaderMenu) {
state.copy(showReaderMenu = false)
} else {
state.copy(showReaderMenu = true)
}
state = state.copy(showReaderMenu = !state.showReaderMenu)
}

fun hideReaderInfo() {
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Myne" parent="Theme.Material3.Dark.NoActionBar" />
<style name="Theme.Myne" parent="Theme.Material3.Dark.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
</resources>
13 changes: 13 additions & 0 deletions app/src/main/res/values-v27/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Myne" parent="Theme.Material3.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
</resources>
12 changes: 10 additions & 2 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="Theme.Myne" parent="Theme.Material3.Light.NoActionBar" />
<style name="Theme.Myne" parent="Theme.Material3.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
</resources>

0 comments on commit c9ebdf5

Please sign in to comment.