Skip to content

Commit

Permalink
1)Resolved yes/no horizontal alignment to make it us full width
Browse files Browse the repository at this point in the history
2)Added View More/ View Less option for help text expandable view
  • Loading branch information
khyativyasargus committed Feb 21, 2023
1 parent 840e6d8 commit f140865
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.google.android.fhir.datacapture.views

import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.RadioButton
import androidx.constraintlayout.helper.widget.Flow
import androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -140,12 +140,15 @@ internal object QuestionnaireItemBooleanTypePickerViewHolderFactory :
choiceOrientation: ChoiceOrientationTypes
) {
layoutParams =
ViewGroup.LayoutParams(
LinearLayout.LayoutParams(
when (choiceOrientation) {
ChoiceOrientationTypes.HORIZONTAL -> ViewGroup.LayoutParams.WRAP_CONTENT
ChoiceOrientationTypes.VERTICAL -> ViewGroup.LayoutParams.MATCH_PARENT
ChoiceOrientationTypes.HORIZONTAL -> {
0
}
ChoiceOrientationTypes.VERTICAL -> LinearLayout.LayoutParams.MATCH_PARENT
},
ViewGroup.LayoutParams.WRAP_CONTENT
LinearLayout.LayoutParams.WRAP_CONTENT,
1.0f
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewTreeObserver
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
Expand Down Expand Up @@ -112,43 +113,47 @@ internal fun initHelpButton(
GONE
}
val helpCardView = view.findViewById<MaterialCardView>(R.id.helpCardView)
val originalText: CharSequence
var textViewHelpText = view.findViewById<TextView>(R.id.helpText)
textViewHelpText.updateTextAndVisibility(questionnaireItem.localizedHelpSpanned)
var textViewViewMore = view.findViewById<TextView>(R.id.textviewViewMore)
originalText = textViewHelpText.text
var isHelpCardViewVisible = false
var isHelpTextLineCountSet = false
helpButton.setOnClickListener {
if (isHelpCardViewVisible) {
isHelpCardViewVisible = false
helpCardView.visibility = GONE
} else {
isHelpCardViewVisible = true
helpCardView.visibility = VISIBLE

if (!isHelpTextLineCountSet) {
// Check if the TextView needs to be expanded or collapsed
textViewHelpText.viewTreeObserver.addOnPreDrawListener(
object : ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
textViewHelpText.viewTreeObserver.removeOnPreDrawListener(this)
if (textViewHelpText.lineCount > textViewHelpText.maxLines) {
textViewViewMore.visibility = VISIBLE
textViewViewMore.text =
textViewViewMore.context.applicationContext.getString(R.string.text_view_more)
}
return true
}
}
)
// Set a click listener on the TextView and the "View More" text view
textViewHelpText.setOnClickListener {
toggle(textViewHelpText, textViewViewMore, originalText)
}
textViewViewMore.setOnClickListener {
toggle(textViewHelpText, textViewViewMore, originalText)
}
isHelpTextLineCountSet = true
}
}
}
val originalText: CharSequence
var textViewHelpText = view.findViewById<TextView>(R.id.helpText)
textViewHelpText.updateTextAndVisibility(questionnaireItem.localizedHelpSpanned)
var textViewViewMore = view.findViewById<TextView>(R.id.textviewViewMore)
originalText = textViewHelpText.text
// Check if the TextView needs to be expanded or collapsed
// textViewHelpText.viewTreeObserver.addOnGlobalLayoutListener(
// object : ViewTreeObserver.OnGlobalLayoutListener {
// override fun onGlobalLayout() {
// // Remove the listener to avoid multiple calls
// textViewHelpText.viewTreeObserver.removeOnGlobalLayoutListener(this)
// // Check if the TextView needs to be expanded or collapsed
// textViewHelpText.measure(
// View.MeasureSpec.makeMeasureSpec(textViewHelpText.width, View.MeasureSpec.EXACTLY),
// View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
// )
//
// if (textViewHelpText.lineCount > textViewHelpText.maxLines) {
// textViewViewMore.visibility = VISIBLE
// }
// }
// }
// )
// Set a click listener on the TextView and the "View More" text view
textViewHelpText.setOnClickListener { toggle(textViewHelpText, textViewViewMore, originalText) }
// textViewViewMore.setOnClickListener { toggle(textViewHelpText, textViewViewMore, originalText)
// }
}

private fun toggle(
Expand All @@ -158,14 +163,14 @@ private fun toggle(
) {
if (textViewContent.maxLines == 2) {
textViewContent.text = originalText
// textViewViewMore.text =
// textViewContent.context.applicationContext.getString(R.string.text_view_less)
textViewViewMore.text =
textViewContent.context.applicationContext.getString(R.string.text_view_less)
textViewContent.maxLines = Integer.MAX_VALUE
} else {
textViewContent.text = originalText
textViewContent.maxLines = 2
// textViewViewMore.text =
// textViewContent.context.applicationContext.getString(R.string.text_view_more)
textViewViewMore.text =
textViewContent.context.applicationContext.getString(R.string.text_view_more)
}
}
/**
Expand Down

0 comments on commit f140865

Please sign in to comment.