From b4d0a3dd80f59ecfe305fa2c166dae863b3577ec Mon Sep 17 00:00:00 2001 From: Corey Date: Mon, 24 Mar 2025 00:17:06 -0400 Subject: [PATCH] Convert scaling factor analysis to fragment and add to navigation --- .../ui/analysis/ScalingFactorFragment.kt | 99 +++++++++++ .../res/layout/fragment_scaling_factor.xml | 161 ++++++++++++++++++ app/src/main/res/menu/bottom_nav_menu.xml | 5 + .../main/res/navigation/mobile_navigation.xml | 7 + 4 files changed, 272 insertions(+) create mode 100644 app/src/main/java/com/accidentalproductions/tetristats/ui/analysis/ScalingFactorFragment.kt create mode 100644 app/src/main/res/layout/fragment_scaling_factor.xml diff --git a/app/src/main/java/com/accidentalproductions/tetristats/ui/analysis/ScalingFactorFragment.kt b/app/src/main/java/com/accidentalproductions/tetristats/ui/analysis/ScalingFactorFragment.kt new file mode 100644 index 0000000..85cc5e4 --- /dev/null +++ b/app/src/main/java/com/accidentalproductions/tetristats/ui/analysis/ScalingFactorFragment.kt @@ -0,0 +1,99 @@ +package com.accidentalproductions.tetristats.ui.analysis + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ArrayAdapter +import androidx.fragment.app.Fragment +import com.accidentalproductions.tetristats.databinding.FragmentScalingFactorBinding +import com.accidentalproductions.tetristats.util.GameScoreSample +import com.accidentalproductions.tetristats.util.ScalingFactorAnalyzer + +class ScalingFactorFragment : Fragment() { + private var _binding: FragmentScalingFactorBinding? = null + private val binding get() = _binding!! + private val analyzer = ScalingFactorAnalyzer() + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = FragmentScalingFactorBinding.inflate(inflater, container, false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + setupGameDropdown() + setupSkillLevelDropdown() + setupButtons() + } + + private fun setupGameDropdown() { + val games = listOf( + "NES Tetris", + "Game Boy Tetris", + "Tetris DX", + "Tetris DS", + "Tetris Effect", + "Rosy Retrospection DX", + "Apotris", + "Modretro Tetris", + "Tetris Mobile" + ) + val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_dropdown_item_1line, games) + binding.spinnerGame.setAdapter(adapter) + } + + private fun setupSkillLevelDropdown() { + val skillLevels = listOf("beginner", "intermediate", "advanced") + val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_dropdown_item_1line, skillLevels) + binding.spinnerSkillLevel.setAdapter(adapter) + } + + private fun setupButtons() { + binding.buttonAddSample.setOnClickListener { + val game = binding.spinnerGame.text.toString() + val score = binding.editTextScore.text.toString().toIntOrNull() + val level = binding.editTextLevel.text.toString().toIntOrNull() + val skillLevel = binding.spinnerSkillLevel.text.toString() + val notes = binding.editTextNotes.text.toString() + + if (score != null && level != null) { + val sample = GameScoreSample(game, score, level, skillLevel, notes) + analyzer.addSample(sample) + clearInputs() + updateSampleCount() + } + } + + binding.buttonAnalyze.setOnClickListener { + analyzer.printAnalysisReport() + binding.textViewReport.text = analyzer.generateScalingFactorCode() + } + + binding.buttonClear.setOnClickListener { + analyzer.clearSamples() + updateSampleCount() + binding.textViewReport.text = "" + } + } + + private fun updateSampleCount() { + binding.textViewSampleCount.text = "Samples: ${analyzer.sampleCount}" + } + + private fun clearInputs() { + binding.editTextScore.text?.clear() + binding.editTextLevel.text?.clear() + binding.editTextNotes.text?.clear() + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_scaling_factor.xml b/app/src/main/res/layout/fragment_scaling_factor.xml new file mode 100644 index 0000000..b8e7aab --- /dev/null +++ b/app/src/main/res/layout/fragment_scaling_factor.xml @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/bottom_nav_menu.xml b/app/src/main/res/menu/bottom_nav_menu.xml index 0498b82..fc052db 100644 --- a/app/src/main/res/menu/bottom_nav_menu.xml +++ b/app/src/main/res/menu/bottom_nav_menu.xml @@ -16,4 +16,9 @@ android:icon="@drawable/ic_stats_24" android:title="Stats" /> + + \ No newline at end of file diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index d87901b..84ef1a4 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -22,4 +22,11 @@ android:name="com.accidentalproductions.tetristats.ui.stats.StatsFragment" android:label="Statistics" tools:layout="@layout/fragment_stats" /> + + + \ No newline at end of file