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

Upgrade ConnectHelpAlertFragment to Jetpack Compose #3596

Merged
merged 11 commits into from
Sep 10, 2024
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ dependencies {
implementation(libs.androidx.cardview)
implementation(libs.androidx.startup)
implementation(libs.bundles.androidx.compose)
implementation(libs.androidx.tv.material)

// Dependency Injection
implementation(libs.bundles.koin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,126 @@

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Done
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.fragment.app.Fragment
import org.jellyfin.androidtv.databinding.FragmentAlertConnectHelpBinding
import androidx.fragment.compose.content
import androidx.tv.material3.Button
import androidx.tv.material3.ButtonDefaults
import androidx.tv.material3.Icon
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Surface
import androidx.tv.material3.SurfaceDefaults
import androidx.tv.material3.Text
import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.composable.overscan

class ConnectHelpAlertFragment : Fragment() {
private var _binding: FragmentAlertConnectHelpBinding? = null
private val binding get() = _binding!!

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = FragmentAlertConnectHelpBinding.inflate(inflater, container, false)
return binding.root
}
@Composable
private fun ConnectHelpAlert(

Check warning

Code scanning / detekt

One method should have one responsibility. Long methods tend to handle many things at once. Prefer smaller methods to make them easier to understand. Warning

The function ConnectHelpAlert is too long (69). The maximum length is 60.
onClose: () -> Unit,
) {
val focusRequester = remember { FocusRequester() }

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Surface(
colors = SurfaceDefaults.colors(
containerColor = colorResource(R.color.not_quite_black),
contentColor = colorResource(R.color.white),
)
) {
Row(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.overscan(),
horizontalArrangement = Arrangement.SpaceEvenly,
) {
Column(
modifier = Modifier
.width(400.dp)
.align(Alignment.CenterVertically),
) {
Text(
text = stringResource(R.string.login_help_title),
style = MaterialTheme.typography.displayMedium,
)
Text(
modifier = Modifier.padding(top = 16.dp),
text = stringResource(R.string.login_help_description),
style = MaterialTheme.typography.bodyLarge,
)
Button(
modifier = Modifier
.padding(top = 24.dp)
.align(Alignment.Start)
.focusRequester(focusRequester),
onClick = onClose,
colors = ButtonDefaults.colors(
containerColor = colorResource(R.color.button_default_normal_background),
contentColor = colorResource(R.color.button_default_normal_text),
focusedContainerColor = colorResource(R.color.button_default_highlight_background),
focusedContentColor = colorResource(R.color.button_default_highlight_text),
disabledContainerColor = colorResource(R.color.button_default_disabled_background),
disabledContentColor = colorResource(R.color.button_default_disabled_text),
),
) {
Icon(
imageVector = Icons.Default.Done,
contentDescription = null,
modifier = Modifier.size(ButtonDefaults.IconSize),
)
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
Text(
text = stringResource(id = R.string.btn_got_it),
style = MaterialTheme.typography.bodyLarge,
)
}
}

with(binding.confirm) {
requestFocus()
setOnClickListener { parentFragmentManager.popBackStack() }
Image(
painter = painterResource(R.drawable.qr_jellyfin_docs),
contentDescription = stringResource(R.string.app_name),
modifier = Modifier
.width(200.dp)
.align(Alignment.CenterVertically),
)
}
}

override fun onDestroyView() {
super.onDestroyView()
LaunchedEffect(focusRequester) {
focusRequester.requestFocus()
}
}

_binding = null
class ConnectHelpAlertFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
) = content {
ConnectHelpAlert(
onClose = { parentFragmentManager.popBackStack() },
)
}
}
Loading
Loading