Skip to content

Commit ca5b0ec

Browse files
committed
Add terms link to the yat display screen. Bump build number and version.
1 parent 01f6781 commit ca5b0ec

File tree

13 files changed

+179
-8
lines changed

13 files changed

+179
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class YatLib {
1919
internal const val userActivationAPIBaseURL = "https://partner.scratch.emojid.me"
2020
internal const val yatAPIBaseURL = "https://api-dev.yat.rocks/"
2121
internal const val yatWebAppBaseURL = "https://dev.yat.rocks"
22+
internal const val yatTermsURL = "https://pre-waitlist.y.at/terms"
2223

2324
// ...
2425

@@ -50,7 +51,7 @@ class YatLib {
5051
5152
```gradle
5253
dependencies {
53-
implementation 'com.github.yat-labs:yat-lib-android:0.1.1'
54+
implementation 'com.github.yat-labs:yat-lib-android:0.1.2'
5455
}
5556
5657
## Usage

yat-lib-example/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "yat.yat_lib_example"
1111
minSdkVersion 24
1212
targetSdkVersion 30
13-
versionCode 1
14-
versionName "0.1.0"
13+
versionCode 2
14+
versionName "0.1.2"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}

yat-lib-example/src/main/java/yat/yat_lib_example/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ internal class MainActivity :
6969
config = config,
7070
userId = UUID.randomUUID().toString().substring(0, 15),
7171
userPassword = UUID.randomUUID().toString().substring(0, 15),
72-
colorMode = YatLib.ColorMode.LIGHT,
72+
colorMode = YatLib.ColorMode.DARK,
7373
delegate = this,
7474
yatRecords = yatRecords
7575
)

yat-lib/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
defaultConfig {
1111
minSdkVersion 24
1212
targetSdkVersion 30
13-
versionCode 1
14-
versionName "0.1.0"
13+
versionCode 2
14+
versionName "0.1.2"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}

yat-lib/src/main/java/yat/android/YatLib.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class YatLib {
8080
internal const val userActivationAPIBaseURL = "https://partner.scratch.emojid.me"
8181
internal const val yatAPIBaseURL = "https://api-dev.yat.rocks/"
8282
internal const val yatWebAppBaseURL = "https://dev.yat.rocks"
83+
internal const val yatTermsURL = "https://pre-waitlist.y.at/terms"
8384

8485
internal lateinit var config: YatAppConfig
8586
internal lateinit var userId: String

yat-lib/src/main/java/yat/android/ui/activity/YatLibActivity.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,13 @@ internal class YatLibActivity :
175175
startActivity(browserIntent)
176176
}
177177

178+
override fun onViewTerms(fragment: DisplayYatFragment) {
179+
val url = YatLib.yatTermsURL
180+
val browserIntent = Intent(
181+
Intent.ACTION_VIEW,
182+
Uri.parse(url)
183+
)
184+
startActivity(browserIntent)
185+
}
186+
178187
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2021 Yat Labs
3+
*
4+
* Redistribution and use in source and binary forms, with or
5+
* without modification, are permitted provided that the
6+
* following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form must reproduce the above
12+
* copyright notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* 3. Neither the name of the copyright holder nor the names of
16+
* its contributors may be used to endorse or promote products
17+
* derived from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
20+
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30+
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
package yat.android.ui.extension
34+
35+
import android.content.Context
36+
import androidx.annotation.AttrRes
37+
import androidx.annotation.ColorInt
38+
39+
@ColorInt
40+
fun Context.getColorFromAttr(
41+
@AttrRes attrColor: Int
42+
): Int {
43+
val typedArray = theme.obtainStyledAttributes(intArrayOf(attrColor))
44+
val textColor = typedArray.getColor(0, 0)
45+
typedArray.recycle()
46+
return textColor
47+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2021 Yat Labs
3+
*
4+
* Redistribution and use in source and binary forms, with or
5+
* without modification, are permitted provided that the
6+
* following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form must reproduce the above
12+
* copyright notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* 3. Neither the name of the copyright holder nor the names of
16+
* its contributors may be used to endorse or promote products
17+
* derived from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
20+
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30+
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
package yat.android.ui.extension
34+
35+
import android.text.SpannableString
36+
import android.text.Spanned
37+
import android.text.style.ForegroundColorSpan
38+
39+
internal fun String.applyColorStyle(
40+
defaultColor: Int,
41+
search: List<String>,
42+
styleColor: Int,
43+
applyToOnlyFirstOccurence: Boolean = false
44+
): SpannableString {
45+
val spannableString = SpannableString(this)
46+
spannableString.setSpan(
47+
ForegroundColorSpan(defaultColor),
48+
0,
49+
length,
50+
Spanned.SPAN_INTERMEDIATE
51+
)
52+
search.forEach {
53+
spannableString.applyColorStyle(
54+
it,
55+
styleColor,
56+
applyToOnlyFirstOccurence
57+
)
58+
}
59+
return spannableString
60+
}
61+
62+
private fun SpannableString.applyColorStyle(
63+
search: String,
64+
color: Int,
65+
applyToOnlyFirstOccurence: Boolean = false
66+
) {
67+
var index = this.indexOf(search)
68+
while (index >= 0) {
69+
setSpan(
70+
ForegroundColorSpan(color),
71+
index,
72+
index + search.length,
73+
Spanned.SPAN_INTERMEDIATE
74+
)
75+
if (applyToOnlyFirstOccurence) {
76+
break
77+
}
78+
index = this.indexOf(search, index + 1)
79+
}
80+
}

yat-lib/src/main/java/yat/android/ui/fragment/DisplayYatFragment.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ internal class DisplayYatFragment(
6161
fun onClose(fragment: DisplayYatFragment)
6262
fun onComplete(fragment: DisplayYatFragment, yat: String)
6363
fun onUpgradeToCustomYat(fragment: DisplayYatFragment)
64+
fun onViewTerms(fragment: DisplayYatFragment)
6465

6566
}
6667

@@ -118,6 +119,15 @@ internal class DisplayYatFragment(
118119
it.temporarilyDisableClick()
119120
onUpgradeToCustomYat()
120121
}
122+
ui.termsTextView.text = resources.getString(R.string.display_yat_terms).applyColorStyle(
123+
resources.getColor(R.color.x_light_gray, null),
124+
listOf(resources.getString(R.string.display_yat_terms_colored)),
125+
requireContext().getColorFromAttr(R.attr.primaryButtonColor)
126+
)
127+
ui.termsTextView.setOnClickListener {
128+
it.temporarilyDisableClick()
129+
delegateWeakReference.get()?.onViewTerms(this)
130+
}
121131
}
122132

123133
override fun onDestroyView() {

yat-lib/src/main/res/layout/fragment_display_yat.xml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@
122122
android:id="@+id/upgrade_to_a_custom_yat_button"
123123
android:layout_width="match_parent"
124124
android:layout_height="48dp"
125-
android:layout_alignParentBottom="true"
125+
android:layout_above="@id/terms_text_view"
126126
android:layout_marginStart="16dp"
127127
android:layout_marginEnd="16dp"
128-
android:layout_marginBottom="48dp"
128+
android:layout_marginBottom="@dimen/display_yat_custom_yat_button_bottom_margin"
129129
android:background="@drawable/display_yat_page_upgrade_to_a_custom_yat_button_bg"
130130
android:text="@string/display_yat_upgrade_to_custom_yat"
131131
android:textAllCaps="false"
@@ -162,4 +162,21 @@
162162
android:visibility="visible" />
163163
</LinearLayout>
164164

165+
<yat.android.ui.component.CustomFontTextView
166+
android:id="@+id/terms_text_view"
167+
android:layout_width="wrap_content"
168+
android:layout_height="wrap_content"
169+
android:layout_alignParentBottom="true"
170+
android:layout_centerHorizontal="true"
171+
android:layout_marginBottom="@dimen/display_yat_terms_bottom_margin"
172+
android:clickable="true"
173+
android:focusable="true"
174+
android:gravity="center"
175+
android:letterSpacing="0.01"
176+
android:lineSpacingExtra="6dp"
177+
android:text="@string/display_yat_terms"
178+
android:textColor="@color/x_light_gray"
179+
android:textSize="@dimen/info_description_font_size"
180+
app:customFont="?infoDescriptionFont" />
181+
165182
</RelativeLayout>

0 commit comments

Comments
 (0)