Skip to content

Commit

Permalink
Updated versions in gradle for 34 API support
Browse files Browse the repository at this point in the history
  • Loading branch information
TusharGogna committed Sep 29, 2023
1 parent 089ca38 commit 3b797b4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 88 deletions.
6 changes: 2 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

android {
namespace = "com.mdoc.termsandconditiondemo"
compileSdk = 33
compileSdk = 34

defaultConfig {
applicationId = "com.mdoc.termsandconditiondemo"
Expand Down Expand Up @@ -50,8 +50,7 @@ android {
}

dependencies {

implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.activity:activity-compose:1.7.2")
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
Expand All @@ -66,6 +65,5 @@ dependencies {
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")

implementation(project(mapOf("path" to ":terms_and_condition_compose")))
}
53 changes: 7 additions & 46 deletions app/src/main/java/com/mdoc/termsandconditiondemo/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,65 +1,26 @@
package com.mdoc.termsandconditiondemo

import android.graphics.Color
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import com.mdoc.termsandconditiondemo.ui.theme.TermsAndConditionDemoTheme
import com.mdoc.tnc_compose.TermsText


class MainActivity : ComponentActivity() {
private val termsArray =
arrayListOf("I agree to the ", "Terms and Conditions", " & ", "Privacy Policies")
arrayListOf("I agree to the", "Terms and Conditions", "&", "Privacy Policies")

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)


setContent {
TermsAndConditionDemoTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
TermsText(
24F,
Color.BLACK,
Color.BLUE,
termsArray,
"https://stackoverflow.com/",
"https://google.com/",
LocalContext.current
)
}
TermsText(
stringArray = termsArray,
termsURL = "https://www.stackoverflow.com",
policyURL = "https://www.google.com"
)
}
}
}
}

@Preview(showBackground = true)
@Composable
fun TermsPreview() {
val termsArray =
arrayListOf("I agree to the ", "Terms and Conditions", " & ", "Privacy Policies")

TermsAndConditionDemoTheme {
TermsText(
24F,
Color.BLACK,
Color.BLUE,
termsArray,
"https://stackoverflow.com/",
"https://google.com/",
LocalContext.current
)
}
}
}
4 changes: 2 additions & 2 deletions terms_and_condition_compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ android {
}

dependencies {
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.core:core-ktx:1.12.0")
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.foundation:foundation:1.4.0")
implementation("androidx.compose.foundation:foundation:1.5.2")
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,24 @@ import androidx.compose.foundation.text.ClickableText
*/

/**
* @param textSize is used to set the size of the TextView. Default value is set to 16F
* @param textColor is used to set the color to the non-clickable text.
* @param textLinkColor is used to set the color to the clickable text.
* @param list is an arraylist which will pick 4 String params used to set the actual text.
* @param stringArray is an arraylist which will pick 4 String params used to set the actual text.
* The texts on Index[0] & Index[2] will be non clickable where as
* the texts on Index[1] & Index[3] will be clickable and can only open URLs on Browsers.
* @param termsURL is a String which will take in the full URL of Terms and Condition page ideally.
* @param privacyURL is a String which will take in the full URL of Privacy Policy page ideally.
* @param context is simply the context needed to start the intent.
* @param policyURL is a String which will take in the full URL of Privacy Policy page ideally.
* @exception IllegalArgumentException is thrown if the stringArray size is less than 4.
*/
@Composable
private fun TermsText(
textSize: Float? = 16F,
textColor: Int? = Color.BLACK,
textLinkColor: Int? = Color.BLUE,
list: ArrayList<String> = arrayListOf(
fun TermsText(
stringArray: ArrayList<String> = arrayListOf(
"I agree to the ",
"Terms and Conditions",
" & ",
"Privacy Policy"
),
termsURL: String?,
privacyURL: String?,
context: Context?
policyURL: String?
) {
AndroidView(
factory = { _ ->
val textView = TextView(context)
textView.textSize = textSize!!
textView

},
update = { textView ->
customTextView(textView, textColor, textLinkColor, list, termsURL, privacyURL, context)
}
)
}

/**
* @param stringArray is an arraylist which will pick 4 String params used to set the actual text.
* The texts on Index[0] & Index[2] will be non clickable where as
* the texts on Index[1] & Index[3] will be clickable and can only open URLs on Browsers.
* @param termsURL is a String which will take in the full URL of Terms and Condition page ideally.
* @param policyURL is a String which will take in the full URL of Privacy Policy page ideally.
* @exception IllegalArgumentException is thrown if the stringArray size is less than 4.
*/
@Composable
fun TermsText(stringArray: ArrayList<String>, termsURL: String?, policyURL: String?) {
if (stringArray.size < 4) {
thread(name = "WatchdogThread") {
throw IllegalArgumentException("The Length of stringArray should be 4 where index values 1 and 3 are clickable.")
Expand Down Expand Up @@ -116,6 +86,48 @@ fun TermsText(stringArray: ArrayList<String>, termsURL: String?, policyURL: Stri
}
}


/**
* @param textSize is used to set the size of the TextView. Default value is set to 16F
* @param textColor is used to set the color to the non-clickable text.
* @param textLinkColor is used to set the color to the clickable text.
* @param list is an arraylist which will pick 4 String params used to set the actual text.
* The texts on Index[0] & Index[2] will be non clickable where as
* the texts on Index[1] & Index[3] will be clickable and can only open URLs on Browsers.
* @param termsURL is a String which will take in the full URL of Terms and Condition page ideally.
* @param privacyURL is a String which will take in the full URL of Privacy Policy page ideally.
* @param context is simply the context needed to start the intent.
*/
@Composable
@JvmName("TermsTextDeprecated")
private fun TermsText(
textSize: Float? = 16F,
textColor: Int? = Color.BLACK,
textLinkColor: Int? = Color.BLUE,
list: ArrayList<String> = arrayListOf(
"I agree to the ",
"Terms and Conditions",
" & ",
"Privacy Policy"
),
termsURL: String?,
privacyURL: String?,
context: Context?
) {
AndroidView(
factory = { _ ->
val textView = TextView(context)
textView.textSize = textSize!!
textView

},
update = { textView ->
customTextView(textView, textColor, textLinkColor, list, termsURL, privacyURL, context)
}
)
}


private fun customTextView(
view: TextView,
normalColor: Int?,
Expand Down

0 comments on commit 3b797b4

Please sign in to comment.