Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions app/src/main/java/dev/jekis/canvacompass/XmlFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.setFragmentResultListener
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import dev.jekis.canvacompass.databinding.FragmentXmlBinding
import dev.jekis.canvacompass.presentation.CompassViewModel
import kotlinx.coroutines.launch
import org.koin.androidx.viewmodel.ext.android.activityViewModel

private const val LISTENER_KEY = "XmlFragmentListenerKey"
class XmlFragment : Fragment() {

private var _binding: FragmentXmlBinding? = null
Expand All @@ -23,17 +25,20 @@ class XmlFragment : Fragment() {
savedInstanceState: Bundle?
): View {
_binding = FragmentXmlBinding.inflate(inflater, container, false)
val fragmentListener = { requestKey: String, bundle: Bundle ->
val args = bundle.get(requestKey)
println(args)
}
setFragmentResultListener(requestKey = LISTENER_KEY, fragmentListener)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel


viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.uiState.collect { state ->
binding.compassView.setAzimuth(state.azimuth)
}
}
}
}

override fun onDestroyView() {
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/java/dev/jekis/canvacompass/ui/CompassScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.text.drawText
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.rememberTextMeasurer
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dev.jekis.canvacompass.presentation.CompassViewModel
Expand Down Expand Up @@ -73,7 +74,7 @@ fun CompassScreenContent(
Canvas(modifier = modifier.fillMaxSize()) {
val centerX = size.width / 2
val centerY = size.height / 2
val padding = 16f
val padding = 16.dp.toPx()
val radius = (size.minDimension / 2) - padding

val azimuthInRadians = Math.toRadians(-animatedAzimuth.toDouble())
Expand Down Expand Up @@ -221,12 +222,7 @@ fun CompassScreenContent(

/* Gray divider */
val grayDividerWidth = 30f
val dummyTextLayout = textMeasurer.measure(
text = "360", style = TextStyle(
color = Color.White, fontSize = 10.sp, fontWeight = FontWeight.Bold
)
)
val textHeight = dummyTextLayout.size.height.toFloat()
val textHeight = 10.sp.toPx()
val textRadius = thirtyDegreeSegmentRadius - roundScaleLineLength - textPadding
val textInnerBoundary = textRadius - (textHeight / 2f) - 4f
val grayDividerRadius = textInnerBoundary - (grayDividerWidth / 2f)
Expand Down
Loading
Loading