Skip to content

Commit

Permalink
Merge pull request #5 from CristianRP/master
Browse files Browse the repository at this point in the history
Custom Hints, Button Pay Text and Fixed App Crashes
  • Loading branch information
fevziomurtekin authored Mar 4, 2024
2 parents 672e3c5 + 5fa5e01 commit ce65ac5
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 51 deletions.
64 changes: 64 additions & 0 deletions .idea/StickySelectionHighlights.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 32 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,32 @@ dependencies {
## Layout

```xml
<com.fevziomurtekin.payview.Payview
android:id="@+id/payview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBgColor="@android:color/holo_blue_light"
app:cardFgColor="@android:color/white"
app:cardTextColor="@color/black"
app:cardNameHelperText="Enter to card name. Max 25 characters."
app:cardCvTextSize="14"
app:cardNoTextSize="14"
app:cardNumberHelperText="You must enter your 16-digit card number."
app:cardYearTextSize="13"
app:cardNameTextSize="15"
app:cardMonthTextSize="13"
app:cardAnimationType="vertical"
app:cardCvErrorText="You must enter 3-digit characters"
app:cardMonthErrorText="You must enter 2-digit characters and you'll enter to number the most digit-value is '12'"
app:cardYearErrorText="You must enter 2-digit characters and you'll enter to number the most digit-value is '99'"
app:cardExpiredErrorText="Your card has expired. Please enter the usage date correctly."
/>
<com.fevziomurtekin.payview.Payview
android:id="@+id/payview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBgColor="@android:color/holo_blue_light"
app:cardFgColor="@android:color/white"
app:cardTextColor="@color/black"
app:cardNameHelperText="Enter to card name. Max 25 characters."
app:cardCvTextSize="14"
app:cardNoTextSize="14"
app:cardNumberHelperText="You must enter your 16-digit card number."
app:cardYearTextSize="13"
app:cardNameTextSize="15"
app:cardMonthTextSize="13"
app:cardAnimationType="vertical"
app:cardBtnPayText="Proceed to pay"
app:cardNameHintText="Name on card"
app:cardNoHintText="Card Number"
app:cardMonthHintText="MM"
app:cardYearHintText="YY"
app:cardCvHintText="CVV"
app:cardCvErrorText="You must enter 3-digit characters"
app:cardMonthErrorText="You must enter 2-digit characters and you'll enter to number the most digit-value is '12'"
app:cardYearErrorText="You must enter 2-digit characters and you'll enter to number the most digit-value is '99'"
app:cardExpiredErrorText="Your card has expired. Please enter the usage date correctly."
/>
```

## Listeners
Expand Down Expand Up @@ -101,6 +107,12 @@ dependencies {
|`cardMonthErrorText`|Default text ""You must enter 2-digit characters and you'll enter to number the most digit-value is '12'"|
|`cardYearErrorText`| Default text "You must enter 2-digit characters and you'll enter to number the most digit-value is '99'"|
|`cardExpiredErrorText`| Default text "Your card has expired. Please enter the usage date correctly."|
|`cardBtnPayText`| Default text "Pay"|
|`cardNameHintText`| Default text "Card Name"|
|`cardNoHintText`| Default text "Card No"|
|`cardMonthHintText`| Default text "Month"|
|`cardYearHintText`| Default text "Year"|
|`cardCvHintText`| Default text "Cv Code"|


## License
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
app:cardNameTextSize="15"
app:cardMonthTextSize="13"
app:cardAnimationType="vertical"
app:cardBtnPayText="Proceed to pay"
app:cardNameHintText="Name on card"
app:cardNoHintText="Card Number"
app:cardMonthHintText="MM"
app:cardYearHintText="YY"
app:cardCvHintText="CVV"
app:cardCvErrorText="You must enter 3-digit characters"
app:cardMonthErrorText="You must enter 2-digit characters and you'll enter to number the most digit-value is '12'"
app:cardYearErrorText="You must enter 2-digit characters and you'll enter to number the most digit-value is '99'"
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.40'
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jun 28 22:43:33 EET 2019
#Tue Jun 23 10:58:51 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
10 changes: 5 additions & 5 deletions payview/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
compileSdkVersion 29


defaultConfig {
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"

Expand All @@ -28,11 +28,11 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation "androidx.core:core-ktx:1.0.2"
implementation "androidx.core:core-ktx:1.3.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.android.material:material:1.0.0'
}
Expand Down
72 changes: 57 additions & 15 deletions payview/src/main/java/com/fevziomurtekin/payview/Payview.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class Payview : NestedScrollView, View.OnFocusChangeListener {
private var cardYearTextSize : Int = 13
private var cardMonthTextSize : Int = 13
private var cardCvTextSize : Int = 14
private var cardBtnPayText : String = resources.getString(R.string.pay)
private var cardNameHintText : String = resources.getString(R.string.cardname)
private var cardNoHintText : String = resources.getString(R.string.cardno)
private var cardMonthHintText : String = resources.getString(R.string.cardmonth)
private var cardYearHintText : String = resources.getString(R.string.cardyear)
private var cardCvHintText : String = resources.getString(R.string.cardcv)


/** Views on layout.*/
Expand Down Expand Up @@ -141,6 +147,18 @@ class Payview : NestedScrollView, View.OnFocusChangeListener {
cardYearTextSize=it.getInt(R.styleable.Payview_cardYearTextSize,13)
cardMonthTextSize=it.getInt(R.styleable.Payview_cardMonthTextSize,13)
cardCvTextSize=it.getInt(R.styleable.Payview_cardCvTextSize,14)
cardBtnPayText=it.getString(R.styleable.Payview_cardBtnPayText).let { s-> s?.toString()
?: cardBtnPayText }
cardNameHintText=it.getString(R.styleable.Payview_cardNameHintText).let { s-> s?.toString()
?: cardNameHintText }
cardNoHintText=it.getString(R.styleable.Payview_cardNoHintText).let { s-> s?.toString()
?: cardNoHintText }
cardMonthHintText=it.getString(R.styleable.Payview_cardMonthHintText).let { s-> s?.toString()
?: cardMonthHintText }
cardYearHintText=it.getString(R.styleable.Payview_cardYearHintText).let { s-> s?.toString()
?: cardYearHintText }
cardCvHintText=it.getString(R.styleable.Payview_cardCvHintText).let { s-> s?.toString()
?: cardCvHintText }
cardAnimationType=it.getInt(R.styleable.Payview_cardAnimationType,AnimationType.HORIZONTAL)
initViews()
initData()
Expand Down Expand Up @@ -223,6 +241,14 @@ class Payview : NestedScrollView, View.OnFocusChangeListener {
tev_card_year.textSize = cardYearTextSize.toFloat()
tev_card_month.textSize = cardMonthTextSize.toFloat()
tev_card_cv.textSize = cardCvTextSize.toFloat()
btn_pay.text = cardBtnPayText

// Custom Hint Text
til_card_name.hint = cardNameHintText
til_card_no.hint = cardNoHintText
til_card_month.hint = cardMonthHintText
til_card_year.hint = cardYearHintText
til_card_cv.hint = cardCvHintText

tev_card_name.onFocusChangeListener = this
tev_card_no.onFocusChangeListener = this
Expand Down Expand Up @@ -498,7 +524,7 @@ class Payview : NestedScrollView, View.OnFocusChangeListener {
&& tev_card_cv.text.toString().length==3
&& tev_card_month.text.toString().length==2
&& tev_card_year.text.toString().length==2
&& tev_card_no.text?.toString()?.replace(" ","")?.length==16){
&& tev_card_no.text?.toString()?.replace(" ","")?.length in 14..16){

/** card month/card year compare to now date.*/
val nowMonth = Calendar.getInstance().get(Calendar.MONTH)
Expand All @@ -512,34 +538,50 @@ class Payview : NestedScrollView, View.OnFocusChangeListener {
}else true
}
else{
if(tev_card_name.text.isNullOrEmpty())
var valid = true
if(tev_card_name.text.isNullOrEmpty()) {
tev_card_name.error = cardNameHelperText
if(tev_card_no.text?.toString()?.replace(" ","")?.length!=16)
valid = false
}
if(tev_card_no.text?.toString()?.replace(" ","")?.length!=16) {
tev_card_no.error = cardNoHelperText
valid = false
}
if(tev_card_cv.text.isNullOrEmpty()
|| tev_card_cv.text.toString().length!=3)
|| tev_card_cv.text.toString().length!=3) {
tev_card_cv.error = cardCvErrorText
valid = false
}


if(tev_card_year.text.isNullOrEmpty()
|| tev_card_year.text.toString().length!=2
|| tev_card_year.text.toString().toInt()>99)
|| tev_card_year.text.toString().toInt()>99) {
tev_card_year.error = cardYearErrorText
valid = false
}
if(tev_card_month.text.isNullOrEmpty()
|| tev_card_month.text.toString().length!=2
|| tev_card_month.text.toString().toInt()<12)
|| tev_card_month.text.toString().toInt()<12) {
tev_card_month.error = cardMonthErrorText
valid = false
}

/** card month/card year compare to now date.*/
val nowMonth = Calendar.getInstance().get(Calendar.MONTH)
val nowYear = Calendar.getInstance().get(Calendar.YEAR).toString().substring(2,4).toInt()
if(nowYear>tev_card_year.text.toString().toInt()
|| (nowYear==tev_card_year.text.toString().toInt()
&& nowMonth>=tev_card_month.text.toString().toInt())){
tev_card_year.error = cardExpiredError
tev_card_month.error = cardExpiredError
if (valid) {
/** card month/card year compare to now date.*/
val nowMonth = Calendar.getInstance().get(Calendar.MONTH)
val nowYear =
Calendar.getInstance().get(Calendar.YEAR).toString().substring(2, 4).toInt()
if (nowYear > tev_card_year.text.toString().toInt()
|| (nowYear == tev_card_year.text.toString().toInt()
&& nowMonth >= tev_card_month.text.toString().toInt())
) {
tev_card_year.error = cardExpiredError
tev_card_month.error = cardExpiredError
valid = false
}
}
return false
return valid
}
}
}
Expand Down
19 changes: 12 additions & 7 deletions payview/src/main/res/layout/payview_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
android:id="@+id/lv_card_layout"
android:orientation="horizontal"
android:layout_above="@+id/iv_card_type"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:layout_marginBottom="5dp"
>
<TextView
Expand Down Expand Up @@ -250,7 +250,8 @@
android:textColorHint="@android:color/black"
android:textColor="@android:color/black"
android:layout_marginBottom="10dp"
app:counterEnabled="true">
app:counterEnabled="true"
app:counterTextAppearance="@style/CounterText">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tev_card_name"
Expand Down Expand Up @@ -279,7 +280,8 @@
android:fontFamily="sans-serif"
app:helperTextTextAppearance="@style/HelperStyle"
app:passwordToggleDrawable="@drawable/ic_credit_card"
app:counterEnabled="true">
app:counterEnabled="true"
app:counterTextAppearance="@style/CounterText">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tev_card_no"
Expand Down Expand Up @@ -311,7 +313,8 @@
android:textColor="@android:color/black"
android:textColorHint="@android:color/black"
app:passwordToggleDrawable="@drawable/ic_credit_card"
app:counterEnabled="true">
app:counterEnabled="true"
app:counterTextAppearance="@style/CounterText">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tev_card_month"
Expand Down Expand Up @@ -348,7 +351,8 @@
app:counterMaxLength="2"
android:textColorHint="@android:color/black"
android:textColor="@android:color/black"
app:counterEnabled="true">
app:counterEnabled="true"
app:counterTextAppearance="@style/CounterText">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tev_card_year"
Expand Down Expand Up @@ -378,7 +382,8 @@
app:helperTextTextAppearance="@style/HelperStyle"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:passwordToggleDrawable="@drawable/ic_credit_card"
app:counterEnabled="true">
app:counterEnabled="true"
app:counterTextAppearance="@style/CounterText">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tev_card_cv"
Expand Down
6 changes: 6 additions & 0 deletions payview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<enum name="horizontal" value="0" />
<enum name="vertical" value="1" />
</attr>
<attr name="cardBtnPayText" format="string" />
<attr name="cardNameHintText" format="string" />
<attr name="cardNoHintText" format="string" />
<attr name="cardMonthHintText" format="string" />
<attr name="cardYearHintText" format="string" />
<attr name="cardCvHintText" format="string" />

</declare-styleable>

Expand Down
Loading

0 comments on commit ce65ac5

Please sign in to comment.