This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<string name="terms_conditions_prompt">Cliquez <annotation action="acceptTC">ici</annotation> pour accepter les <annotation action="openTC">termes et conditions</annotation></string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tv_terms_conditions.text = termsCopy | |
tv_terms_conditions.movementMethod = LinkMovementMethod.getInstance() | |
tv_terms_conditions.highlightColor = Color.TRANSPARENT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.text.TextPaint | |
import android.text.style.ClickableSpan | |
import android.view.View | |
import androidx.annotation.ColorInt | |
class CustomClickSpan( | |
private val onClickListener: () -> Unit, | |
@ColorInt private val textColor: Int, | |
private val shouldUnderline: Boolean = false | |
) : ClickableSpan() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun createClickSpan(action: String) = when (action.toLowerCase()) { | |
"accepttc" -> CustomClickSpan({ showToast("Terms ACCEPTED!") }, Color.RED) | |
"opentc" -> CustomClickSpan({ showToast("Terms and condition OPENED!") }, Color.BLUE, true) | |
else -> throw NotImplementedError("action $action not implemented") | |
} | |
private fun showToast(prompt: String) = Toast.makeText(this, prompt, Toast.LENGTH_SHORT).show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val termsCopy = SpannableString(termsText) | |
for (annotation in annotations) { | |
if (annotation.key == "action") { | |
termsCopy.setSpan( | |
createClickSpan(annotation.value), | |
termsText.getSpanStart(annotation), | |
termsText.getSpanEnd(annotation), | |
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<string name="terms_conditions_prompt">Cliquez <annotation action="acceptTC">ici</annotation> pour accepter les<annotation action="openTC">termes et conditions</annotation></string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<string name="terms_conditions_prompt">Click <annotation action="acceptTC">here</annotation> to accept the <annotation action="openTC">terms and conditions</annotation></string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val termsText = getText(R.string.terms_conditions_prompt) as SpannedString | |
val annotations = termsText.getSpans(0, termsText.length, Annotation::class.java) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
apply plugin: 'com.apollographql.android' //add the apollo plugin below the android plugin like this | |
android { | |
} | |
dependencies { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
//apollo graphQL classpath | |
classpath 'com.apollographql.apollo:apollo-gradle-plugin:1.0.0' | |
// NOTE: Do not place your application dependencies here; they belong | |
// in the individual module build.gradle files | |
} |