Skip to content

Commit

Permalink
Refractored ResultFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
MadRatSRP committed Feb 8, 2019
1 parent 3594dc0 commit cc68e27
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class BaseFragment : Fragment(), BaseVP.View {
socialScience: EditText?) : Bundle {

val bundle = Bundle()
bundle.putString("maths", maths.text.toString())
bundle.putString("russian", russian.text.toString())
bundle.putString("physics", physics?.text.toString())
bundle.putString("computerScience", computerScience?.text.toString())
bundle.putString("socialScience", socialScience?.text.toString())
bundle.putInt("maths", maths.text.toString().toInt())
bundle.putInt("russian", russian.text.toString().toInt())
physics?.text.toString().toIntOrNull()?.let { bundle.putInt("physics", it) }
computerScience?.text.toString().toIntOrNull()?.let { bundle.putInt("computerScience", it) }
socialScience?.text.toString().toIntOrNull()?.let { bundle.putInt("socialScience", it) }
return bundle
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.madrat.abiturhelper.ui.result

class ResultPresenter(private var rv: ResultVP.View) : ResultVP.Presenter {
import android.content.Context
import android.os.Bundle

lateinit var maths : String
class ResultPresenter (private var rv: ResultVP.View, private val arguments: Bundle) : ResultVP.Presenter {

/*val maths = arguments?.getString("maths")
maths_value.text = maths
val russian = arguments?.getString("russian")
val physics = arguments?.getString("physics")
val computerScience = arguments?.getString("computerScience")
val socialScience = arguments?.getString("socialScience")*/
override fun returnString(key: String?):String? {
return arguments.getInt(key).toString()
}

override fun addEgeScore(): String {
return rv.setEgeScore()
override fun returnSum():String? {
val maths = arguments.getInt("maths")
val russian = arguments.getInt("russian")
val physics = arguments.getInt("physics")
val computerScience = arguments.getInt("computerScience")
val socialScience = arguments.getInt("socialScience")
return (maths + russian + physics + computerScience + socialScience).toString()
}
}
12 changes: 7 additions & 5 deletions app/src/main/java/com/madrat/abiturhelper/ui/result/ResultVP.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.madrat.abiturhelper.ui.result

import android.os.Bundle
import android.widget.LinearLayout
import android.widget.TextView

interface ResultVP {
interface View {
fun setMVP()

fun setEgeScore(): String
fun setupMVP()
fun checkField(linearLayout: LinearLayout, textViewValue: TextView, key: String)
fun setupFields()
}

interface Presenter {
fun addEgeScore(): String
fun returnSum():String?
fun returnString(key: String?):String?
}
}
33 changes: 19 additions & 14 deletions app/src/main/java/com/madrat/abiturhelper/ui/result/ResultView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

import com.madrat.abiturhelper.R
Expand All @@ -19,9 +21,8 @@ class ResultView : Fragment(), ResultVP.View {

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setMVP()

resultValue.text = resultPresenter?.addEgeScore()
setupMVP()
setupFields()
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
Expand All @@ -30,21 +31,25 @@ class ResultView : Fragment(), ResultVP.View {
return inflater.inflate(R.layout.fragment_result, container, false)
}

override fun setMVP() {
resultPresenter = ResultPresenter(this)
override fun setupMVP() {
resultPresenter = ResultPresenter(this, arguments!!)
}

override fun setEgeScore(): String {

val maths = arguments?.getString("maths")
override fun checkField(linearLayout: LinearLayout, textViewValue: TextView, key: String) {
textViewValue.text = resultPresenter?.returnString(key)
if (textViewValue.text.toString().toInt() == 0) {
linearLayout.visibility = View.GONE
}
}

mathsValue.text = maths
override fun setupFields() {
mathsValue.text = resultPresenter?.returnString("maths")
russianValue.text = resultPresenter?.returnString("russian")

val russian = arguments?.getString("russian")
val physics = arguments?.getString("physics")
val computerScience = arguments?.getString("computerScience")
val socialScience = arguments?.getString("socialScience")
checkField(physics, physicsValue, "physics")
checkField(computerScience, computerScienceValue, "computerScience")
checkField(socialScience, socialScienceValue, "socialScience")

return maths + russian + physics + computerScience + socialScience
resultValue.text = resultPresenter?.returnSum()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.madrat.abiturhelper.ui.setup_score

import androidx.fragment.app.Fragment

interface SetupScoreVP {
interface View {
fun setMVP()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_result.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<LinearLayout
android:id="@+id/physics"
android:orientation="horizontal"
android:visibility="visible"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginTop="10dp"
Expand Down

0 comments on commit cc68e27

Please sign in to comment.