mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-24 03:42:15 +00:00
Update: Migrate PrefRepo to Compose
This commit is contained in:
parent
0d1ea78922
commit
bffcbea4ce
@ -5,9 +5,17 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.material.Scaffold
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.material3.*
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
|
import com.looker.droidify.R
|
||||||
import com.looker.droidify.content.Preferences
|
import com.looker.droidify.content.Preferences
|
||||||
|
import com.looker.droidify.database.entity.Repository
|
||||||
import com.looker.droidify.databinding.FragmentRepositoriesXBinding
|
import com.looker.droidify.databinding.FragmentRepositoriesXBinding
|
||||||
import com.looker.droidify.service.Connection
|
import com.looker.droidify.service.Connection
|
||||||
import com.looker.droidify.service.SyncService
|
import com.looker.droidify.service.SyncService
|
||||||
@ -45,8 +53,18 @@ class PrefsRepositoriesFragment : BaseNavFragment() {
|
|||||||
|
|
||||||
override fun setupLayout() {
|
override fun setupLayout() {
|
||||||
syncConnection.bind(requireContext())
|
syncConnection.bind(requireContext())
|
||||||
binding.addRepository.setOnClickListener { viewModel.addRepository() }
|
|
||||||
viewModel.repositories.observe(requireActivity()) {
|
viewModel.repositories.observe(requireActivity()) {
|
||||||
|
redrawPage(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
super.onDestroyView()
|
||||||
|
syncConnection.unbind(requireContext())
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
fun redrawPage(repos: List<Repository>) {
|
||||||
binding.reposRecycler.setContent {
|
binding.reposRecycler.setContent {
|
||||||
AppTheme(
|
AppTheme(
|
||||||
darkTheme = when (Preferences[Preferences.Key.Theme]) {
|
darkTheme = when (Preferences[Preferences.Key.Theme]) {
|
||||||
@ -55,9 +73,34 @@ class PrefsRepositoriesFragment : BaseNavFragment() {
|
|||||||
else -> isDarkTheme
|
else -> isDarkTheme
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Scaffold { _ ->
|
Scaffold {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(8.dp),
|
||||||
|
verticalArrangement = Arrangement.Absolute.spacedBy(4.dp)
|
||||||
|
) {
|
||||||
|
OutlinedButton(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
contentPadding = PaddingValues(12.dp),
|
||||||
|
colors = ButtonDefaults.outlinedButtonColors(
|
||||||
|
contentColor = MaterialTheme.colorScheme.primary,
|
||||||
|
containerColor = MaterialTheme.colorScheme.background
|
||||||
|
),
|
||||||
|
onClick = { viewModel.addRepository() }
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
text = stringResource(id = R.string.add_repository),
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
style = MaterialTheme.typography.titleSmall
|
||||||
|
)
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(id = R.drawable.ic_add),
|
||||||
|
contentDescription = stringResource(id = R.string.add_repository)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
RepositoriesRecycler(
|
RepositoriesRecycler(
|
||||||
repositoriesList = it.sortedBy { repo -> !repo.enabled },
|
repositoriesList = repos.sortedBy { repo -> !repo.enabled },
|
||||||
onClick = { repo ->
|
onClick = { repo ->
|
||||||
repo.enabled = !repo.enabled
|
repo.enabled = !repo.enabled
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
@ -73,9 +116,4 @@ class PrefsRepositoriesFragment : BaseNavFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
|
||||||
super.onDestroyView()
|
|
||||||
syncConnection.unbind(requireContext())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,30 +22,14 @@
|
|||||||
</data>
|
</data>
|
||||||
|
|
||||||
<com.google.android.material.circularreveal.CircularRevealFrameLayout
|
<com.google.android.material.circularreveal.CircularRevealFrameLayout
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
|
||||||
android:id="@+id/add_repository"
|
|
||||||
style="@style/Widget.Material3.Button.OutlinedButton.Icon"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="64dp"
|
|
||||||
android:layout_margin="@dimen/shape_margin_medium"
|
|
||||||
android:drawableEnd="@drawable/ic_add"
|
|
||||||
android:drawableTint="?colorPrimary"
|
|
||||||
android:text="@string/add_repository" />
|
|
||||||
|
|
||||||
<androidx.compose.ui.platform.ComposeView
|
<androidx.compose.ui.platform.ComposeView
|
||||||
android:id="@+id/reposRecycler"
|
android:id="@+id/reposRecycler"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="match_parent" />
|
||||||
android:layout_weight="1" />
|
|
||||||
</LinearLayout>
|
|
||||||
</com.google.android.material.circularreveal.CircularRevealFrameLayout>
|
</com.google.android.material.circularreveal.CircularRevealFrameLayout>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user