mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 02:36:24 -04:00
Removed the unnecessary compose dependencies from project.
* Removed the unnecessary overriding of rows since we are not showing these rows in custom apps. * Used `KiwixTheme` instead of hardcoded colors. * Used the `KiwixAppBar` instead of manually created `AppBar`. * Refined the `HelpScreen` for better readability and maintainability.
This commit is contained in:
parent
55b6ab129d
commit
64db5ad3e5
@ -22,9 +22,6 @@ import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.help.HelpFragment
|
||||
|
||||
class KiwixHelpFragment : HelpFragment() {
|
||||
override val navHostFragmentId: Int
|
||||
get() = org.kiwix.kiwixmobile.R.id.nav_host_fragment
|
||||
|
||||
override fun rawTitleDescriptionMap() =
|
||||
if (sharedPreferenceUtil.isPlayStoreBuildWithAndroid11OrAbove()) {
|
||||
listOf(
|
||||
|
@ -20,7 +20,6 @@ package plugin
|
||||
|
||||
import Config
|
||||
import Libs
|
||||
import Versions
|
||||
import com.android.build.api.dsl.CommonExtension
|
||||
import com.android.build.gradle.BaseExtension
|
||||
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
|
||||
|
@ -14,7 +14,6 @@ buildscript {
|
||||
plugins {
|
||||
`android-library`
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("org.jetbrains.kotlin.plugin.compose") version Versions.org_jetbrains_kotlin_plugin_compose
|
||||
}
|
||||
plugins.apply(KiwixConfigurationPlugin::class)
|
||||
apply(plugin = "io.objectbox")
|
||||
@ -28,12 +27,6 @@ android {
|
||||
isMinifyEnabled = false
|
||||
}
|
||||
}
|
||||
buildFeatures {
|
||||
compose = true
|
||||
}
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = Versions.kotlin_compiler_extension_version
|
||||
}
|
||||
}
|
||||
|
||||
fun shouldUseLocalVersion() = File(projectDir, "libs").exists()
|
||||
@ -71,17 +64,4 @@ dependencies {
|
||||
implementation(Libs.kotlinx_coroutines_android)
|
||||
implementation(Libs.kotlinx_coroutines_rx3)
|
||||
implementation(Libs.zxing)
|
||||
|
||||
implementation(Libs.androidx_compose_material3)
|
||||
implementation(Libs.androidx_activity_compose)
|
||||
|
||||
implementation(Libs.androidx_compose_ui)
|
||||
implementation(platform(Libs.androidx_compose_bom))
|
||||
implementation(Libs.androidx_compose_ui_tooling)
|
||||
implementation(Libs.androidx_compose_runtime_livedata)
|
||||
implementation(Libs.androidx_compose_runtime_rxjava2)
|
||||
|
||||
// For Compose UI Testing
|
||||
androidTestImplementation(Libs.androidx_compose_ui_test_junit4)
|
||||
debugImplementation(Libs.androidx_compose_ui_tooling)
|
||||
}
|
||||
|
@ -22,14 +22,11 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toolbar
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.navigation.Navigation
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.base.BaseActivity
|
||||
import org.kiwix.kiwixmobile.core.base.BaseFragment
|
||||
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||
import org.kiwix.kiwixmobile.core.ui.components.NavigationIcon
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -38,54 +35,30 @@ abstract class HelpFragment : BaseFragment() {
|
||||
@Inject
|
||||
lateinit var sharedPreferenceUtil: SharedPreferenceUtil
|
||||
|
||||
protected abstract val navHostFragmentId: Int
|
||||
|
||||
// Instead of keeping the XML binding, we now directly return a ComposeView.
|
||||
protected open fun createFragmentView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?
|
||||
): View {
|
||||
return ComposeView(requireContext()).apply {
|
||||
setContent {
|
||||
// Create the helpScreen data using your rawTitleDescriptionMap.
|
||||
val helpScreenData = transformToHelpScreenData(
|
||||
requireContext(),
|
||||
rawTitleDescriptionMap()
|
||||
)
|
||||
// Retrieve the NavController if your composable needs it.
|
||||
val navController = Navigation.findNavController(requireActivity(), navHostFragmentId)
|
||||
// Call your HelpScreen composable.
|
||||
HelpScreen(data = helpScreenData, navController = navController)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Each subclass is responsible for providing its own raw data.
|
||||
protected open fun rawTitleDescriptionMap(): List<Pair<Int, Any>> = emptyList()
|
||||
|
||||
// The following properties are now optional – if no longer use an XML toolbar or title,
|
||||
// we can remove or update these accordingly.
|
||||
override val fragmentToolbar: Toolbar? by lazy {
|
||||
// Already Applied ad TopAppBAr in scaffold in composable
|
||||
null
|
||||
}
|
||||
override val fragmentTitle: String? by lazy { getString(R.string.menu_help) }
|
||||
|
||||
override fun inject(baseActivity: BaseActivity) {
|
||||
(baseActivity as CoreMainActivity).cachedComponent.inject(this)
|
||||
}
|
||||
|
||||
// Remove or adjust onViewCreated if you no longer need to manipulate XML-based views.
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
// Any additional logic that is independent of the XML layout can be kept here.
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? = createFragmentView(inflater, container)
|
||||
): View? = ComposeView(requireContext()).apply {
|
||||
setContent {
|
||||
// Create the helpScreen data using your rawTitleDescriptionMap.
|
||||
val helpScreenData = transformToHelpScreenData(
|
||||
requireContext(),
|
||||
rawTitleDescriptionMap()
|
||||
)
|
||||
// Call your HelpScreen composable.
|
||||
HelpScreen(data = helpScreenData) {
|
||||
NavigationIcon(onClick = { activity?.onBackPressedDispatcher?.onBackPressed() })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Util function to modify the data accordingly
|
||||
|
@ -25,147 +25,66 @@ import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
import androidx.navigation.NavController
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.error.DiagnosticReportActivity
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start
|
||||
import org.kiwix.kiwixmobile.core.ui.components.KiwixAppBar
|
||||
import org.kiwix.kiwixmobile.core.ui.theme.KiwixTheme
|
||||
import org.kiwix.kiwixmobile.core.ui.theme.MineShaftGray350
|
||||
import org.kiwix.kiwixmobile.core.ui.theme.MineShaftGray600
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.SIXTEEN_DP
|
||||
|
||||
val SendDiagnosticReportFontSize = 18.sp
|
||||
|
||||
@Suppress("ComposableLambdaParameterNaming")
|
||||
@Composable
|
||||
fun HelpScreen(
|
||||
modifier: Modifier = Modifier,
|
||||
data: List<HelpScreenItemDataClass>,
|
||||
navController: NavController
|
||||
navigationIcon: @Composable () -> Unit
|
||||
) {
|
||||
val isDarkTheme = isSystemInDarkTheme()
|
||||
val backgroundColor =
|
||||
if (isDarkTheme) colorResource(id = R.color.mine_shaft_gray900) else Color.White
|
||||
val dividerColor =
|
||||
if (isDarkTheme) colorResource(id = R.color.mine_shaft_gray600)
|
||||
else colorResource(id = R.color.mine_shaft_gray350)
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
topBar = {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
HelpTopAppBar(navController)
|
||||
if (isSystemInDarkTheme()) {
|
||||
MineShaftGray600
|
||||
} else {
|
||||
MineShaftGray350
|
||||
}
|
||||
KiwixTheme {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
KiwixAppBar(R.string.menu_help, navigationIcon)
|
||||
}
|
||||
},
|
||||
containerColor = backgroundColor
|
||||
) { innerPadding ->
|
||||
HelpContent(data, dividerColor, innerPadding)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun HelpTopAppBar(navController: NavController) {
|
||||
// Retrieve the actionBarSize from the current theme
|
||||
val context = LocalContext.current
|
||||
val actionBarHeight = with(LocalDensity.current) {
|
||||
// Obtain the height defined in the theme (usually 56dp on phones)
|
||||
val styledAttributes =
|
||||
context.theme.obtainStyledAttributes(intArrayOf(android.R.attr.actionBarSize))
|
||||
styledAttributes.getDimension(0, 0f).toDp().also { styledAttributes.recycle() }
|
||||
}
|
||||
|
||||
TopAppBar(
|
||||
modifier = Modifier.height(actionBarHeight), // set the height here
|
||||
title = {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
modifier = Modifier.padding(
|
||||
start = dimensionResource(R.dimen.activity_horizontal_margin)
|
||||
),
|
||||
text = stringResource(id = R.string.menu_help),
|
||||
color = Color.White,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
) { innerPadding ->
|
||||
Column(modifier = Modifier.padding(innerPadding)) {
|
||||
SendReportRow()
|
||||
HorizontalDivider(color = dividerColor)
|
||||
HelpItemList(data, dividerColor)
|
||||
}
|
||||
},
|
||||
navigationIcon = {
|
||||
Row(modifier = Modifier.fillMaxHeight(), verticalAlignment = Alignment.CenterVertically) {
|
||||
IconButton(onClick = navController::popBackStack) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = "Back_Navigation",
|
||||
tint = Color.White
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = Color.Black
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun HelpContent(
|
||||
data: List<HelpScreenItemDataClass>,
|
||||
dividerColor: Color,
|
||||
innerPadding: androidx.compose.foundation.layout.PaddingValues
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(innerPadding)
|
||||
) {
|
||||
SendReportRow()
|
||||
HelpItemList(data, dividerColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SendReportRow() {
|
||||
val context = LocalContext.current
|
||||
val isDarkTheme = isSystemInDarkTheme()
|
||||
// val isDarkTheme = isSystemInDarkTheme()
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable {
|
||||
(context as? Activity)?.start<DiagnosticReportActivity>()
|
||||
},
|
||||
.clickable { (context as? Activity)?.start<DiagnosticReportActivity>() },
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Start
|
||||
) {
|
||||
@ -173,13 +92,13 @@ fun SendReportRow() {
|
||||
painter = painterResource(R.drawable.ic_feedback_orange_24dp),
|
||||
contentDescription = stringResource(R.string.send_report),
|
||||
modifier = Modifier
|
||||
.padding(dimensionResource(R.dimen.activity_horizontal_margin))
|
||||
.padding(SIXTEEN_DP)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.send_report),
|
||||
color = if (isDarkTheme) Color.LightGray else Color.DarkGray,
|
||||
fontSize = SendDiagnosticReportFontSize
|
||||
// color = if (isDarkTheme) Color.LightGray else Color.DarkGray,
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -191,15 +110,8 @@ fun HelpItemList(data: List<HelpScreenItemDataClass>, dividerColor: Color) {
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
itemsIndexed(data, key = { _, item -> item.title }) { _, item ->
|
||||
HorizontalDivider(
|
||||
color = dividerColor
|
||||
)
|
||||
HelpScreenItem(data = item)
|
||||
}
|
||||
item {
|
||||
HorizontalDivider(
|
||||
color = dividerColor
|
||||
)
|
||||
HorizontalDivider(color = dividerColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ import org.kiwix.kiwixmobile.core.R
|
||||
private val HelpItemTitleFontSize = 22.sp
|
||||
private val HelpItemDescriptionFontSize = 17.sp
|
||||
private val IconSize = 36.dp
|
||||
private const val HelpItemAnimationDuration = 300
|
||||
private const val HelpItemArrowRotationOpen = 180f
|
||||
private const val HelpItemArrowRotationClosed = 0f
|
||||
private const val HELP_ITEM_ANIMATION_DURATION = 300
|
||||
private const val HELP_ITEM_ARROW_ROTATION_OPEN = 180f
|
||||
private const val HELP_ITEM_ARROW_ROTATION_CLOSE = 0f
|
||||
|
||||
@Composable
|
||||
fun HelpScreenItem(
|
||||
@ -99,8 +99,8 @@ fun HelpItemHeader(
|
||||
onToggle: () -> Unit
|
||||
) {
|
||||
val arrowRotation by animateFloatAsState(
|
||||
targetValue = if (isOpen) HelpItemArrowRotationOpen else HelpItemArrowRotationClosed,
|
||||
animationSpec = tween(HelpItemAnimationDuration),
|
||||
targetValue = if (isOpen) HELP_ITEM_ARROW_ROTATION_OPEN else HELP_ITEM_ARROW_ROTATION_CLOSE,
|
||||
animationSpec = tween(HELP_ITEM_ANIMATION_DURATION),
|
||||
label = "arrowRotation"
|
||||
)
|
||||
val interactionSource = remember(::MutableInteractionSource)
|
||||
|
@ -18,5 +18,5 @@
|
||||
|
||||
package org.kiwix.kiwixmobile.core.help
|
||||
|
||||
// same as HelpItem data class in earlier in XML
|
||||
// Same as HelpItem data class in earlier in XML
|
||||
data class HelpScreenItemDataClass(val title: String, val description: String)
|
||||
|
@ -20,32 +20,4 @@ package org.kiwix.kiwixmobile.custom.help
|
||||
|
||||
import org.kiwix.kiwixmobile.core.help.HelpFragment
|
||||
|
||||
class CustomHelpFragment : HelpFragment() {
|
||||
override val navHostFragmentId: Int
|
||||
get() = org.kiwix.kiwixmobile.custom.R.id.custom_nav_controller
|
||||
|
||||
override fun rawTitleDescriptionMap() =
|
||||
if (sharedPreferenceUtil.isPlayStoreBuildWithAndroid11OrAbove()) {
|
||||
listOf(
|
||||
org.kiwix.kiwixmobile.core.R.string.help_2 to
|
||||
org.kiwix.kiwixmobile.core.R.array.description_help_2,
|
||||
org.kiwix.kiwixmobile.core.R.string.help_5 to
|
||||
org.kiwix.kiwixmobile.core.R.array.description_help_5,
|
||||
org.kiwix.kiwixmobile.core.R.string.how_to_update_content to
|
||||
org.kiwix.kiwixmobile.core.R.array.update_content_description,
|
||||
org.kiwix.kiwixmobile.core.R.string.why_copy_move_files_to_app_directory to
|
||||
getString(
|
||||
org.kiwix.kiwixmobile.core.R.string.copy_move_files_to_app_directory_description
|
||||
)
|
||||
)
|
||||
} else {
|
||||
listOf(
|
||||
org.kiwix.kiwixmobile.core.R.string.help_2 to
|
||||
org.kiwix.kiwixmobile.core.R.array.description_help_2,
|
||||
org.kiwix.kiwixmobile.core.R.string.help_5 to
|
||||
org.kiwix.kiwixmobile.core.R.array.description_help_5,
|
||||
org.kiwix.kiwixmobile.core.R.string.how_to_update_content to
|
||||
org.kiwix.kiwixmobile.core.R.array.update_content_description
|
||||
)
|
||||
}
|
||||
}
|
||||
class CustomHelpFragment : HelpFragment()
|
||||
|
Loading…
x
Reference in New Issue
Block a user