diff --git a/app/build.gradle b/app/build.gradle index b3e2fd0f..0cf1142e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -107,11 +107,6 @@ dependencies { testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_test_version" androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" - androidTestImplementation "androidx.test:core:$androidx_test_version" - androidTestImplementation "androidx.test:rules:$androidx_test_version" - androidTestImplementation "androidx.test:runner:$androidx_test_version" - androidTestImplementation "androidx.test.ext:junit:$androidx_junit_version" - androidTestImplementation "androidx.test.ext:truth:$androidx_test_version" androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_test_version" androidTestImplementation "org.mockito:mockito-android:$mockito_version" } diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/ModesAdapter.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/ModesAdapter.kt deleted file mode 100644 index f422b369..00000000 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/ModesAdapter.kt +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Look4Sat. Amateur radio satellite tracker and pass predictor. - * Copyright (C) 2019-2022 Arty Bishop (bishop.arty@gmail.com) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.rtbishop.look4sat.presentation.entriesScreen - -import android.view.LayoutInflater -import android.view.ViewGroup -import androidx.recyclerview.widget.AsyncListDiffer -import androidx.recyclerview.widget.DiffUtil -import androidx.recyclerview.widget.RecyclerView -import com.rtbishop.look4sat.databinding.ItemModeBinding - -class ModesAdapter(private val clickListener: ModesClickListener) : - RecyclerView.Adapter() { - - private val diffCallback = object : DiffUtil.ItemCallback() { - override fun areItemsTheSame(oldItem: String, newItem: String): Boolean { - return oldItem == newItem - } - - override fun areContentsTheSame(oldItem: String, newItem: String): Boolean { - return oldItem == newItem - } - } - private val differ = AsyncListDiffer(this, diffCallback) - private var selectedModes = listOf() - - fun submitModes(items: List, selected: List) { - differ.submitList(items) - selectedModes = selected - } - - override fun getItemCount(): Int = differ.currentList.size - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ModeHolder { - return ModeHolder.from(parent) - } - - override fun onBindViewHolder(holder: ModeHolder, position: Int) { - val currentItem = differ.currentList[position] - holder.bind(currentItem, selectedModes.contains(currentItem), clickListener) - } - - class ModeHolder(private val binding: ItemModeBinding) : RecyclerView.ViewHolder(binding.root) { - - fun bind(mode: String, isSelected: Boolean, listener: ModesClickListener) { - binding.modeCheckbox.text = mode - binding.modeCheckbox.isChecked = isSelected - binding.modeCheckbox.setOnClickListener { - listener.onModeClicked(mode, isSelected.not()) - } - } - - companion object { - fun from(parent: ViewGroup): ModeHolder { - val inflater = LayoutInflater.from(parent.context) - return ModeHolder(ItemModeBinding.inflate(inflater, parent, false)) - } - } - } - - interface ModesClickListener { - fun onModeClicked(mode: String, isSelected: Boolean) - } -} diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/ModesDialog.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/ModesDialog.kt deleted file mode 100644 index 69045c6e..00000000 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/ModesDialog.kt +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Look4Sat. Amateur radio satellite tracker and pass predictor. - * Copyright (C) 2019-2022 Arty Bishop (bishop.arty@gmail.com) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.rtbishop.look4sat.presentation.entriesScreen - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.appcompat.app.AppCompatDialogFragment -import androidx.recyclerview.widget.DividerItemDecoration -import androidx.recyclerview.widget.GridLayoutManager -import androidx.recyclerview.widget.SimpleItemAnimator -import com.rtbishop.look4sat.R -import com.rtbishop.look4sat.databinding.DialogModesBinding -import com.rtbishop.look4sat.domain.ISettingsManager -import dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject - -@AndroidEntryPoint -class ModesDialog : AppCompatDialogFragment(), ModesAdapter.ModesClickListener { - - @Inject - lateinit var preferences: ISettingsManager - private lateinit var binding: DialogModesBinding - private val allModes = listOf( - "AFSK", "AFSK S-Net", "AFSK SALSAT", "AHRPT", "AM", "APT", "BPSK", "BPSK PMT-A3", - "CERTO", "CW", "DQPSK", "DSTAR", "DUV", "FFSK", "FM", "FMN", "FSK", "FSK AX.100 Mode 5", - "FSK AX.100 Mode 6", "FSK AX.25 G3RUH", "GFSK", "GFSK Rktr", "GMSK", "HRPT", "LoRa", - "LRPT", "LSB", "MFSK", "MSK", "MSK AX.100 Mode 5", "MSK AX.100 Mode 6", "OFDM", "OQPSK", - "PSK", "PSK31", "PSK63", "QPSK", "QPSK31", "QPSK63", "SSTV", "USB", "WSJT" - ) - private val selectedModes = mutableListOf() - - override fun onCreateView(inflater: LayoutInflater, group: ViewGroup?, state: Bundle?): View { - binding = DialogModesBinding.inflate(inflater, group, false) - return binding.root - } - - override fun onViewCreated(view: View, state: Bundle?) { - super.onViewCreated(view, state) - dialog?.window?.setBackgroundDrawableResource(R.color.transparent) - dialog?.window?.setLayout( - (resources.displayMetrics.widthPixels * 0.94).toInt(), - (resources.displayMetrics.heightPixels * 0.76).toInt() - ) - val modesAdapter = ModesAdapter(this@ModesDialog) - val layoutManager = GridLayoutManager(context, 2) - val itemDecoration = DividerItemDecoration(context, layoutManager.orientation) - selectedModes.addAll(preferences.loadModesSelection()) - modesAdapter.submitModes(allModes, selectedModes) - binding.run { - modesRecycler.apply { - setHasFixedSize(true) - this.adapter = modesAdapter - this.layoutManager = layoutManager - addItemDecoration(itemDecoration) - (itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false - } - modesBtnNeg.setOnClickListener { dismiss() } - modesBtnPos.setOnClickListener { -// setNavResult("modes", selectedModes.toList()) - dismiss() - } - } - } - - override fun onModeClicked(mode: String, isSelected: Boolean) { - when { - isSelected -> selectedModes.add(mode) - selectedModes.contains(mode) -> selectedModes.remove(mode) - } - } -} diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/passesScreen/ModesDialog.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/passesScreen/ModesDialog.kt new file mode 100644 index 00000000..ef1b121b --- /dev/null +++ b/app/src/main/java/com/rtbishop/look4sat/presentation/passesScreen/ModesDialog.kt @@ -0,0 +1,88 @@ +package com.rtbishop.look4sat.presentation.passesScreen + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.LazyVerticalGrid +import androidx.compose.foundation.lazy.grid.items +import androidx.compose.material3.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Dialog +import com.rtbishop.look4sat.presentation.MainTheme + +private val allModes = listOf( + "AFSK", "AFSK S-Net", "AFSK SALSAT", "AHRPT", "AM", "APT", "BPSK", "BPSK PMT-A3", + "CERTO", "CW", "DQPSK", "DSTAR", "DUV", "FFSK", "FM", "FMN", "FSK", "FSK AX.100 Mode 5", + "FSK AX.100 Mode 6", "FSK AX.25 G3RUH", "GFSK", "GFSK Rktr", "GMSK", "HRPT", "LoRa", + "LRPT", "LSB", "MFSK", "MSK", "MSK AX.100 Mode 5", "MSK AX.100 Mode 6", "OFDM", "OQPSK", + "PSK", "PSK31", "PSK63", "QPSK", "QPSK31", "QPSK63", "SSTV", "USB", "WSJT" +) +private val selectedModes = mutableListOf("AFSK", "AFSK S-Net") + +@Preview(showBackground = true) +@Composable +private fun ModesDialogPreview() { + val modesList = remember { mutableStateOf(selectedModes) } + MainTheme { + ModesDialog(allModes, modesList.value, {}) { + if (modesList.value.contains(it)) modesList.value.remove(it) + else modesList.value.add(it) + } + } +} + +@Composable +fun ModesDialog( + list: List, + selected: List, + toggle: () -> Unit, + click: (String) -> Unit +) { + Dialog(onDismissRequest = { toggle() }) { + ElevatedCard(modifier = Modifier.fillMaxHeight(0.9f)) { + LazyVerticalGrid( + columns = GridCells.Fixed(1), + modifier = Modifier.background(MaterialTheme.colorScheme.background), + horizontalArrangement = Arrangement.spacedBy(1.dp), + verticalArrangement = Arrangement.spacedBy(1.dp) + ) { + items(list) { mode -> + Surface { + Row(verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .background(MaterialTheme.colorScheme.surface) + .fillMaxWidth() + .clickable { + click(mode) + toggle() + }) { + Text( + text = mode, + modifier = Modifier + .padding(start = 8.dp, end = 6.dp) + .weight(1f), + fontWeight = FontWeight.Normal, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + Checkbox( + checked = selected.contains(mode), + onCheckedChange = null, + modifier = Modifier.padding(6.dp) + ) + } + } + } + } + } + } +} diff --git a/app/src/main/res/layout/dialog_modes.xml b/app/src/main/res/layout/dialog_modes.xml deleted file mode 100644 index ef6884c3..00000000 --- a/app/src/main/res/layout/dialog_modes.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - -