Skip to content

Commit

Permalink
Value not displaying bug fixed by adding text view showing the scores…
Browse files Browse the repository at this point in the history
… (Temporary fix)
  • Loading branch information
exotic123567 committed Sep 19, 2024
1 parent 3b61154 commit 8ef6a75
Show file tree
Hide file tree
Showing 17 changed files with 712 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<activity android:name=".HowToActivity" />
<activity android:name=".Questions_Activity" />
<activity android:name=".PersonalityResults" />
<activity android:name=".FullResultsActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
Expand All @@ -31,8 +32,9 @@ class AgreeablenessFragment : Fragment() {
private var param1: String? = null
private var param2: String? = null
private var personalityMap: MutableMap<String, Int>? = null
private lateinit var extrachart: BarChart
private lateinit var extrachart: com.github.mikephil.charting.charts.HorizontalBarChart
private lateinit var homebtn: com.google.android.material.button.MaterialButton
private lateinit var textView: TextView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -42,7 +44,7 @@ class AgreeablenessFragment : Fragment() {
if (serializableMap != null) {
personalityMap = serializableMap as MutableMap<String, Int>
Log.v("mapreceived", "Personality map of Extroversion received in fragment")
Log.v("mapextriv","Map of extroversion recieved is ${personalityMap}")
Log.v("mapagreeable","Map of agreeable recieved is ${personalityMap}")
}
}
}
Expand All @@ -61,6 +63,7 @@ class AgreeablenessFragment : Fragment() {

extrachart = view.findViewById(R.id.agreeablenesschart)
homebtn = view.findViewById(R.id.hoemebuttun)
textView = view.findViewById(R.id.agreescores)

// Assume personalityMap is passed or initialized in some way

Expand Down Expand Up @@ -100,6 +103,16 @@ class AgreeablenessFragment : Fragment() {
"Trust", "Morality", "Altruism", "Cooperation", "Modesty", "Sympathy"
)

val stringBuilder = StringBuilder()
stringBuilder.append("Your Agreeableness Traits:\n")
for ((trait, value) in personalityResultsExtroversion) {
stringBuilder.append("$trait: $value\n")
}

val personalityString = stringBuilder.toString()

textView.text = personalityString

val barDataSetExtroversion = BarDataSet(dataEntriesExtroversion, "Agreeableness Traits")
barDataSetExtroversion.setValueTextColor(color) // Set text color
barDataSetExtroversion.setColors(color) // Set bar color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
Expand All @@ -31,8 +32,9 @@ class ConscientiousnessFragment : Fragment() {
private var param1: String? = null
private var param2: String? = null
private var personalityMap: MutableMap<String, Int>? = null
private lateinit var extrachart: BarChart
private lateinit var extrachart: com.github.mikephil.charting.charts.HorizontalBarChart
private lateinit var homebtn: com.google.android.material.button.MaterialButton
private lateinit var textView: TextView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -41,8 +43,8 @@ class ConscientiousnessFragment : Fragment() {
// Check if it's not null before casting
if (serializableMap != null) {
personalityMap = serializableMap as MutableMap<String, Int>
Log.v("mapreceived", "Personality map of Extroversion received in fragment")
Log.v("mapextriv","Map of extroversion recieved is ${personalityMap}")
Log.v("mapreceived", "Personality map of Conscientiousness received in fragment")
Log.v("mapconscientiousness","Map of extroversion recieved is ${personalityMap}")
}
}
}
Expand All @@ -61,6 +63,7 @@ class ConscientiousnessFragment : Fragment() {

extrachart = view.findViewById(R.id.conscientiousnesschart)
homebtn = view.findViewById(R.id.hoemebuttun)
textView = view.findViewById(R.id.consciencescores)

// Assume personalityMap is passed or initialized in some way

Expand Down Expand Up @@ -107,6 +110,16 @@ class ConscientiousnessFragment : Fragment() {
"Orderliness", "Dutifulness", "Achievement-Striving", "Self-Discipline", "Cautiousness"
)

val stringBuilder = StringBuilder()
stringBuilder.append("Your Conscientiousness Traits:\n")
for ((trait, value) in personalityResultsExtroversion) {
stringBuilder.append("$trait: $value\n")
}

val personalityString = stringBuilder.toString()

textView.text = personalityString

val barDataSetExtroversion = BarDataSet(dataEntriesExtroversion, "Conscientiousness Traits")
barDataSetExtroversion.setValueTextColor(color) // Set text color
barDataSetExtroversion.setColors(color) // Set bar color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlin.math.pow

class EvaluatePersonality {
var numofquestions = 120
fun evaluate(questionsList: List<Question>,sex: String, age: Int): MutableMap<String, Int> {
suspend fun evaluate(questionsList: List<Question>,sex: String, age: Int): MutableMap<String, Int> {

//Create the answer's list
var qlist = mutableListOf<Int>()
Expand All @@ -18,6 +18,7 @@ class EvaluatePersonality {
for (i in 0 until numofquestions) {
qlist.add(questionsList[i].answerValue)
}
Log.v("qlistanswers","${qlist}")

//Create Score facet scales
var ss = mutableListOf<Int>()
Expand All @@ -32,6 +33,7 @@ class EvaluatePersonality {
k+=30
}
}
Log.v("ssvalue","${ss}")

//Number each facet set from 1-6
var nf = mutableListOf<Int>()
Expand All @@ -55,12 +57,12 @@ class EvaluatePersonality {
cf.add(0)
}
var j = 0
for (i in 0 until 6) {
nf[i] = ss[i+j]
ef[i] = ss[i + j + 1]
of[i] = ss[i + j + 2]
af[i] = ss[i + j + 3]
cf[i] = ss[i + j + 4]
for (i in 1 until 7) {
nf[i] = ss[i+j-1]
ef[i] = ss[i + j ]
of[i] = ss[i + j + 1]
af[i] = ss[i + j + 2]
cf[i] = ss[i + j + 3]
j = j + 4
}

Expand All @@ -70,7 +72,7 @@ class EvaluatePersonality {
var e = ss[1] + ss[6] + ss[11] + ss[16] + ss[21] + ss[26]
var o = ss[2] + ss[7] + ss[12] + ss[17] + ss[22] + ss[27]
var a = ss[3] + ss[8] + ss[13] + ss[18] + ss[23] + ss[28]
var c = ss[4] + ss[9] + ss[14] + ss[19] + ss[24] + ss[39]
var c = ss[4] + ss[9] + ss[14] + ss[19] + ss[24] + ss[29]

// Standardize scores
var norm = listOf(
Expand Down Expand Up @@ -183,7 +185,7 @@ class EvaluatePersonality {
scf.add(0.0)
}

for (i in 0 until 6) {
for (i in 1 until 7) {
snf[i] = 50 + (10 * (nf[i] - norm[i + 10].toDouble()) / norm[i + 16].toDouble())
sef[i] = 50 + (10 * (ef[i] - norm[i + 22].toDouble()) / norm[i + 28].toDouble())
sof[i] = 50 + (10 * (of[i] - norm[i + 34].toDouble()) / norm[i + 40].toDouble())
Expand Down Expand Up @@ -226,7 +228,7 @@ class EvaluatePersonality {
var flevText = MutableList(items) { "low" }

// Mapping for snf to snfp
for (i in 0 until 6) {
for (i in 1 until 7) {
flev[i] = snf[i]
flevText[i] = when {
snf[i] < 45 -> "low"
Expand All @@ -241,7 +243,7 @@ class EvaluatePersonality {
}
}
// Mapping for sef to sefp
for (i in 0 until 6) {
for (i in 1 until 7) {
flev[i + 6] = sef[i]
flevText[i + 6] = when {
sef[i] < 45 -> "low"
Expand All @@ -256,7 +258,7 @@ class EvaluatePersonality {
}
}
// Mapping for sof to sofp
for (i in 0 until 6) {
for (i in 1 until 7) {
flev[i + 12] = sof[i]
flevText[i + 12] = when {
sof[i] < 45 -> "low"
Expand All @@ -271,7 +273,7 @@ class EvaluatePersonality {
}
}
// Mapping for saf to safp
for (i in 0 until 6) {
for (i in 1 until 7) {
flev[i + 18] = saf[i]
flevText[i + 18] = when {
saf[i] < 45 -> "low"
Expand All @@ -286,7 +288,7 @@ class EvaluatePersonality {
}
}
// Mapping for scf to scfp
for (i in 0 until 6) {
for (i in 1 until 7) {
flev[i + 24] = scf[i]
flevText[i + 24] = when {
scf[i] < 45 -> "low"
Expand All @@ -310,8 +312,10 @@ class EvaluatePersonality {
// EXTRAVERSION
val extraversionLabels = listOf("EXTRAVERSION", "Friendliness", "Gregariousness", "Assertiveness", "Activity Level", "Excitement-Seeking", "Cheerfulness")
m[extraversionLabels[0]] = sep
Log.v("sefp","${sefp}")
for (i in 1 until extraversionLabels.size) {
m[extraversionLabels[i]] = sefp[i]
Log.v("CheckInsidLoop","${i}th element : ${extraversionLabels[i]}")
}

// AGREEABLENESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
Expand All @@ -23,17 +24,17 @@ private const val ARG_PARAM2 = "param2"

/**
* A simple [Fragment] subclass.
* Use the [ExtroversionFragment.newInstance] factory method to
* Use the [ConscientiousnessFragment.newInstance] factory method to
* create an instance of this fragment.
*/
class ExtroversionFragment : Fragment() {
// TODO: Rename and change types of parameters
private var param1: String? = null
private var param2: String? = null
private var personalityMap: MutableMap<String, Int>? = null
private lateinit var extrachart: BarChart
private lateinit var extrachart: com.github.mikephil.charting.charts.HorizontalBarChart
private lateinit var homebtn: com.google.android.material.button.MaterialButton

private lateinit var textView: TextView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -53,10 +54,7 @@ class ExtroversionFragment : Fragment() {
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
Log.v("Inside OnCreateView", "Inside OnCreateVIew and before returning layout inflater")
val view = inflater.inflate(R.layout.fragment_extroversion, container, false)
Log.v("ViewHierarchy", view.dumpViewHierarchy())
return view
return inflater.inflate(R.layout.fragment_extroversion, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand All @@ -65,6 +63,7 @@ class ExtroversionFragment : Fragment() {

extrachart = view.findViewById(R.id.extraversionchart)
homebtn = view.findViewById(R.id.hoemebuttun)
textView = view.findViewById(R.id.extraversionscores)

// Assume personalityMap is passed or initialized in some way

Expand All @@ -77,6 +76,12 @@ class ExtroversionFragment : Fragment() {
theme.resolveAttribute(colorAttr, typedValue, true)
val color = typedValue.data

homebtn.backgroundTintList = ColorStateList.valueOf(color)
homebtn.setOnClickListener {
val intent = Intent(requireContext(), MainActivity::class.java)
startActivity(intent)
}

personalityMap?.get("EXTRAVERSION")
?.let { personalityResultsExtroversion.put("EXTRAVERSION", it) }
personalityMap?.get("Friendliness")
Expand All @@ -92,11 +97,15 @@ class ExtroversionFragment : Fragment() {
personalityMap?.get("Cheerfulness")
?.let { personalityResultsExtroversion.put("Cheerfulness", it) }

Log.v("personalityextroversionmap","${personalityResultsExtroversion}")

for ((label, value) in personalityResultsExtroversion) {
dataEntriesExtroversion.add(BarEntry(dataEntriesExtroversion.size.toFloat(), value.toFloat()))
labelsExtroversion.add(label)
}

Log.v("dataentriesextriv","${dataEntriesExtroversion}")

dataEntriesExtroversion.reverse()
labelsExtroversion.reverse()

Expand All @@ -106,17 +115,25 @@ class ExtroversionFragment : Fragment() {
"Assertiveness", "Activity Level", "Excitement-Seeking", "Cheerfulness"
)

val barDataSetExtroversion = BarDataSet(dataEntriesExtroversion, "Extraversion Traits")

val stringBuilder = StringBuilder()
stringBuilder.append("Your Extraversion Traits:\n")
for ((trait, value) in personalityResultsExtroversion) {
stringBuilder.append("$trait: $value\n")
}

val personalityString = stringBuilder.toString()

textView.text = personalityString

val barDataSetExtroversion = BarDataSet(dataEntriesExtroversion, "Extroversion Traits")
barDataSetExtroversion.setValueTextColor(color) // Set text color
barDataSetExtroversion.setColors(color) // Set bar color

homebtn.backgroundTintList = ColorStateList.valueOf(color)
homebtn.setOnClickListener {
val intent = Intent(requireContext(), MainActivity::class.java)
startActivity(intent)
}
Log.v("baradatasetext","${barDataSetExtroversion}")

val barDataExtroversion = BarData(barDataSetExtroversion)
Log.v("baradataext","${barDataExtroversion}")
extrachart.data = barDataExtroversion
extrachart.invalidate()
extrachart.setDrawBorders(false)
Expand All @@ -136,7 +153,7 @@ class ExtroversionFragment : Fragment() {
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment ExtroversionFragment.
* @return A new instance of fragment ConscientiousnessFragment.
*/
// TODO: Rename and change types and number of parameters
@JvmStatic
Expand All @@ -148,30 +165,4 @@ class ExtroversionFragment : Fragment() {
}
}
}

fun View.dumpViewHierarchy(): String {
val stringBuilder = StringBuilder()
dumpView(this, stringBuilder, 0)
return stringBuilder.toString()
}

private fun dumpView(view: View, stringBuilder: StringBuilder, level: Int) {
for (i in 0 until level) {
stringBuilder.append(" ")
}
stringBuilder.append(view.javaClass.simpleName)
if (view is ViewGroup) {
stringBuilder.append(" {")
stringBuilder.append("\n")
for (i in 0 until view.childCount) {
dumpView(view.getChildAt(i), stringBuilder, level + 1)
}
for (i in 0 until level) {
stringBuilder.append(" ")
}
stringBuilder.append("}")
}
stringBuilder.append("\n")
}

}
Loading

0 comments on commit 8ef6a75

Please sign in to comment.