mirror of
https://github.com/cmclark00/TetriStats.git
synced 2025-05-18 07:05:20 +01:00
Convert scaling factor analysis to fragment and add to navigation
This commit is contained in:
parent
cbeadcafda
commit
b4d0a3dd80
4 changed files with 272 additions and 0 deletions
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
161
app/src/main/res/layout/fragment_scaling_factor.xml
Normal file
161
app/src/main/res/layout/fragment_scaling_factor.xml
Normal file
|
@ -0,0 +1,161 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Scaling Factor Analysis"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textViewSampleCount"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Samples: 0"
|
||||||
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Game"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||||
|
android:layout_marginBottom="8dp">
|
||||||
|
|
||||||
|
<AutoCompleteTextView
|
||||||
|
android:id="@+id/spinnerGame"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="none"/>
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Skill Level"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||||
|
android:layout_marginBottom="8dp">
|
||||||
|
|
||||||
|
<AutoCompleteTextView
|
||||||
|
android:id="@+id/spinnerSkillLevel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="none"/>
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Score"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||||
|
android:layout_marginBottom="8dp">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/editTextScore"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="number"/>
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Level"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||||
|
android:layout_marginBottom="8dp">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/editTextLevel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="number"/>
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Notes (optional)"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||||
|
android:layout_marginBottom="16dp">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/editTextNotes"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="textMultiLine"
|
||||||
|
android:minLines="2"/>
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_marginBottom="16dp">
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/buttonAddSample"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Add Sample"
|
||||||
|
android:layout_marginEnd="8dp"/>
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/buttonClear"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Clear All"
|
||||||
|
android:layout_marginStart="8dp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/buttonAnalyze"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Analyze"
|
||||||
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Analysis Report"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginBottom="8dp"/>
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@android:color/darker_gray"
|
||||||
|
android:padding="8dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textViewReport"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:fontFamily="monospace"/>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
|
@ -16,4 +16,9 @@
|
||||||
android:icon="@drawable/ic_stats_24"
|
android:icon="@drawable/ic_stats_24"
|
||||||
android:title="Stats" />
|
android:title="Stats" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/navigation_analysis"
|
||||||
|
android:icon="@drawable/ic_analytics_24"
|
||||||
|
android:title="Analysis" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
|
@ -22,4 +22,11 @@
|
||||||
android:name="com.accidentalproductions.tetristats.ui.stats.StatsFragment"
|
android:name="com.accidentalproductions.tetristats.ui.stats.StatsFragment"
|
||||||
android:label="Statistics"
|
android:label="Statistics"
|
||||||
tools:layout="@layout/fragment_stats" />
|
tools:layout="@layout/fragment_stats" />
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/navigation_analysis"
|
||||||
|
android:name="com.accidentalproductions.tetristats.ui.analysis.ScalingFactorFragment"
|
||||||
|
android:label="Scaling Analysis"
|
||||||
|
tools:layout="@layout/fragment_scaling_factor" />
|
||||||
|
|
||||||
</navigation>
|
</navigation>
|
Loading…
Add table
Add a link
Reference in a new issue