mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
Improved the design of SwitchRow
(TextView, and Switch).
* Fixed: The "No Bookmarks" text was not showing in the center of screen. * Removed the unused code from project.
This commit is contained in:
parent
b932dd0a04
commit
c1441f1461
@ -34,14 +34,11 @@ import androidx.compose.runtime.referentialEqualityPolicy
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.base.BaseFragment
|
||||
import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions
|
||||
import org.kiwix.kiwixmobile.core.databinding.FragmentPageBinding
|
||||
import org.kiwix.kiwixmobile.core.downloader.downloadManager.ZERO
|
||||
import org.kiwix.kiwixmobile.core.extensions.closeKeyboard
|
||||
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.OnItemClickListener
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.Page
|
||||
@ -54,7 +51,6 @@ import org.kiwix.kiwixmobile.core.ui.components.NavigationIcon
|
||||
import org.kiwix.kiwixmobile.core.ui.models.ActionMenuItem
|
||||
import org.kiwix.kiwixmobile.core.ui.models.IconItem
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.core.utils.SimpleRecyclerViewScrollListener
|
||||
import javax.inject.Inject
|
||||
|
||||
const val SEARCH_ICON_TESTING_TAG = "search"
|
||||
@ -106,7 +102,6 @@ abstract class PageFragment : OnItemClickListener, BaseFragment(), FragmentActiv
|
||||
clearSearchButtonClickListener = {}
|
||||
)
|
||||
)
|
||||
private var fragmentPageBinding: FragmentPageBinding? = null
|
||||
|
||||
private val actionModeCallback: ActionMode.Callback =
|
||||
object : ActionMode.Callback {
|
||||
@ -150,14 +145,14 @@ abstract class PageFragment : OnItemClickListener, BaseFragment(), FragmentActiv
|
||||
compositeDisposable.add(pageViewModel.effects.subscribe { it.invokeWith(activity) })
|
||||
pageViewModel.state.observe(viewLifecycleOwner, Observer(::render))
|
||||
|
||||
// hides keyboard when scrolled
|
||||
fragmentPageBinding?.recyclerView?.addOnScrollListener(
|
||||
SimpleRecyclerViewScrollListener { _, newState ->
|
||||
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
||||
fragmentPageBinding?.recyclerView?.closeKeyboard()
|
||||
}
|
||||
}
|
||||
)
|
||||
// // hides keyboard when scrolled
|
||||
// fragmentPageBinding?.recyclerView?.addOnScrollListener(
|
||||
// SimpleRecyclerViewScrollListener { _, newState ->
|
||||
// if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
||||
// fragmentPageBinding?.recyclerView?.closeKeyboard()
|
||||
// }
|
||||
// }
|
||||
// )
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
|
@ -20,9 +20,12 @@ package org.kiwix.kiwixmobile.core.page
|
||||
|
||||
import androidx.activity.compose.LocalActivity
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
@ -31,10 +34,12 @@ import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.SwitchDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.isCustomApp
|
||||
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.OnItemClickListener
|
||||
@ -43,8 +48,13 @@ import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.DateItem
|
||||
import org.kiwix.kiwixmobile.core.ui.components.KiwixAppBar
|
||||
import org.kiwix.kiwixmobile.core.ui.components.KiwixSearchView
|
||||
import org.kiwix.kiwixmobile.core.ui.models.ActionMenuItem
|
||||
import org.kiwix.kiwixmobile.core.ui.theme.AlabasterWhite
|
||||
import org.kiwix.kiwixmobile.core.ui.theme.Black
|
||||
import org.kiwix.kiwixmobile.core.ui.theme.KiwixTheme
|
||||
import org.kiwix.kiwixmobile.core.ui.theme.White
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.FOURTEEN_SP
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.PAGE_SWITCH_LEFT_RIGHT_MARGIN
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.PAGE_SWITCH_ROW_BOTTOM_MARGIN
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.SIXTEEN_DP
|
||||
|
||||
@Suppress("ComposableLambdaParameterNaming")
|
||||
@ -71,7 +81,11 @@ fun PageScreen(
|
||||
}
|
||||
) { padding ->
|
||||
val items = state.pageState.pageItems
|
||||
Box(modifier = Modifier.padding(padding)) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(padding)
|
||||
.fillMaxSize()
|
||||
) {
|
||||
if (items.isEmpty()) {
|
||||
Text(
|
||||
text = state.noItemsString,
|
||||
@ -114,20 +128,36 @@ private fun searchBarIfActive(
|
||||
fun PageSwitchRow(
|
||||
state: PageFragmentScreenState
|
||||
) {
|
||||
val switchTextColor = if (isSystemInDarkTheme()) {
|
||||
AlabasterWhite
|
||||
} else {
|
||||
White
|
||||
}
|
||||
val context = LocalActivity.current as CoreMainActivity
|
||||
// hide switches for custom apps, see more info here https://github.com/kiwix/kiwix-android/issues/3523
|
||||
if (!context.isCustomApp()) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(Black),
|
||||
.background(Black)
|
||||
.padding(bottom = PAGE_SWITCH_ROW_BOTTOM_MARGIN),
|
||||
horizontalArrangement = Arrangement.Absolute.Right,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(state.switchString)
|
||||
Text(
|
||||
state.switchString,
|
||||
color = switchTextColor,
|
||||
style = TextStyle(fontSize = FOURTEEN_SP)
|
||||
)
|
||||
Switch(
|
||||
checked = state.switchIsChecked,
|
||||
onCheckedChange = { state.onSwitchCheckedChanged(it) },
|
||||
enabled = state.switchIsEnabled
|
||||
enabled = state.switchIsEnabled,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = PAGE_SWITCH_LEFT_RIGHT_MARGIN),
|
||||
colors = SwitchDefaults.colors(
|
||||
uncheckedTrackColor = White
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -109,4 +109,6 @@ object ComposeDimens {
|
||||
|
||||
// Page dimens
|
||||
val PAGE_LIST_ITEM_FAVICON_SIZE = 40.dp
|
||||
val PAGE_SWITCH_LEFT_RIGHT_MARGIN = 10.dp
|
||||
val PAGE_SWITCH_ROW_BOTTOM_MARGIN = 8.dp
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/app_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar"
|
||||
app:popupTheme="@style/KiwixTheme"
|
||||
tools:showIn="@layout/fragment_search" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/page_switch"
|
||||
style="@style/switch_style" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/no_page"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.KiwixTheme.Headline5"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/app_bar" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:clipToPadding="false"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/app_bar"
|
||||
tools:listitem="@layout/item_bookmark_history" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user