Skip to content

Commit

Permalink
Adapt view binding changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kupeliorhun committed Jun 1, 2023
1 parent 29adf1c commit 8a35366
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import android.os.Parcelable
import android.util.Log
import android.view.KeyEvent
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.quickbirdstudios.example.R
import com.quickbirdstudios.example.databinding.MainActivityBinding
import com.quickbirdstudios.surveykit.AnswerFormat
import com.quickbirdstudios.surveykit.FinishReason
import com.quickbirdstudios.surveykit.Identifier
Expand All @@ -36,16 +36,13 @@ import kotlinx.android.parcel.Parcelize

class MainActivity : AppCompatActivity() {

private lateinit var survey: SurveyView
private lateinit var container: ViewGroup
private lateinit var binding: MainActivityBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)

survey = findViewById(R.id.survey_view)
container = findViewById(R.id.surveyContainer)
setupSurvey(survey)
binding = MainActivityBinding.inflate(layoutInflater)
setContentView(binding.root)
setupSurvey(binding.surveyView)
}

private fun setupSurvey(surveyView: SurveyView) {
Expand Down Expand Up @@ -194,7 +191,7 @@ class MainActivity : AppCompatActivity() {
if (reason == FinishReason.Completed) {
taskResult.results.forEach { stepResult ->
Log.e("ASDF", "answer ${stepResult.results.firstOrNull()}")
container.removeAllViews()
binding.surveyContainer.removeAllViews()
}
}
}
Expand All @@ -216,7 +213,7 @@ class MainActivity : AppCompatActivity() {

override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
return if (keyCode == KeyEvent.KEYCODE_BACK) {
survey.backPressed()
binding.surveyView.backPressed()
true
} else false
}
Expand Down
8 changes: 4 additions & 4 deletions example/src/main/res/layout/main_activity.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/surveyContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/surveyContainer">
android:orientation="vertical">

<com.quickbirdstudios.surveykit.survey.SurveyView
android:id="@+id/survey_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
android:layout_height="match_parent">

</com.quickbirdstudios.surveykit.survey.SurveyView>
</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import com.quickbirdstudios.surveykit.StepIdentifier
import com.quickbirdstudios.surveykit.SurveyTheme
import com.quickbirdstudios.surveykit.backend.navigator.TaskNavigator
import com.quickbirdstudios.surveykit.backend.presenter.animations.ViewAnimator
import com.quickbirdstudios.surveykit.backend.views.step.QuestionView
import com.quickbirdstudios.surveykit.backend.views.step.StepView
import com.quickbirdstudios.surveykit.result.StepResult
import com.quickbirdstudios.surveykit.steps.Step
import kotlinx.android.synthetic.main.view_question.view.*
import java.util.Date
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
Expand Down Expand Up @@ -101,8 +101,8 @@ internal class PresenterImpl(

val previousQuestionView = currentQuestionView

if (!hasPreviousStep()) {
questionView.questionHeader?.canBack = false
if (!hasPreviousStep() && questionView is QuestionView) {
questionView.header.canBack = false
}

currentQuestionView = questionView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.Button
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import com.quickbirdstudios.surveykit.R
import com.quickbirdstudios.surveykit.SurveyTheme
import com.quickbirdstudios.surveykit.databinding.LayoutHeaderBinding

// TODO should take [Configuration] in constructor and remove public color setters and getters
class Header @JvmOverloads constructor(
Expand All @@ -21,6 +21,13 @@ class Header @JvmOverloads constructor(
defStyleRes: Int = 0
) : Toolbar(context, attrs, defStyleRes),
StyleablePart {
private val root by lazy {
LayoutHeaderBinding.inflate(
LayoutInflater.from(context),
this,
false
)
}

//region Public API

Expand Down Expand Up @@ -62,9 +69,9 @@ class Header @JvmOverloads constructor(

//region Members

private val root: View = View.inflate(context, R.layout.layout_header, this)
private val headerLabel: TextView = root.findViewById(R.id.headerLabel)
private val buttonBack = root.findViewById<RelativeLayout>(R.id.headerBackButton).apply {
// private val root: View = View.inflate(context, R.layout.layout_header, this)
private val headerLabel: TextView = root.headerLabel
private val buttonBack = root.headerBackButton.apply {
setOnClickListener {
hideKeyboard()
onBack()
Expand All @@ -74,7 +81,7 @@ class Header @JvmOverloads constructor(
buttonBack.findViewById<ImageView>(R.id.headerBackButtonImage).apply {
background.setTint(themeColor)
}
private val cancelButton = root.findViewById<Button>(R.id.headerCancelButton).apply {
private val cancelButton = root.headerCancelButton.apply {
setTextColor(themeColor)
setOnClickListener {
hideKeyboard()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.quickbirdstudios.surveykit.backend.views.step

import android.content.Context
import android.view.View
import android.view.LayoutInflater
import androidx.annotation.CallSuper
import com.quickbirdstudios.surveykit.FinishReason
import com.quickbirdstudios.surveykit.R
Expand All @@ -13,6 +13,7 @@ import com.quickbirdstudios.surveykit.backend.views.main_parts.Dialogs
import com.quickbirdstudios.surveykit.backend.views.main_parts.Footer
import com.quickbirdstudios.surveykit.backend.views.main_parts.Header
import com.quickbirdstudios.surveykit.backend.views.question_parts.InfoTextPart
import com.quickbirdstudios.surveykit.databinding.ViewQuestionBinding
import com.quickbirdstudios.surveykit.result.QuestionResult
import java.util.Date

Expand All @@ -26,11 +27,17 @@ abstract class QuestionView(
private val skipButtonText: String
) : StepView(context, id, isOptional), ViewActions {

private var binding: ViewQuestionBinding

init {
binding = ViewQuestionBinding.inflate(LayoutInflater.from(context))
this.addView(binding.root)
}

//region Members

private val root: View = View.inflate(context, R.layout.view_question, this)
var header: Header = root.findViewById(R.id.questionHeader)
var content: Content = root.findViewById(R.id.questionContent)
var header: Header = binding.questionHeader
var content: Content = binding.questionContent
var footer: Footer = content.findViewById(R.id.questionFooter)
private var abortDialogConfiguration: AbortDialogConfiguration? = null

Expand Down

0 comments on commit 8a35366

Please sign in to comment.