Skip to content

Commit 0a034fa

Browse files
author
MichaelSDavid
committed
Fixed tip calculator crash bug for -> update 1.1
1 parent 1a2ca0a commit 0a034fa

9 files changed

Lines changed: 33 additions & 15 deletions

File tree

app/build.gradle

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 30
5-
//noinspection GradleDependency
6-
buildToolsVersion "30.0.0"
5+
buildToolsVersion "30.0.1"
76

87
defaultConfig {
98
applicationId "com.matdevtech.multility"
109
minSdkVersion 29
1110
targetSdkVersion 30
12-
versionCode 1
13-
versionName "1.0"
11+
versionCode 2
12+
versionName "1.1"
1413

1514
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1615
}
@@ -39,24 +38,19 @@ dependencies {
3938
implementation 'org.apache.commons:commons-lang3:3.11'
4039
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
4140
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
42-
43-
4441
implementation 'androidx.recyclerview:recyclerview:1.1.0'
45-
4642
//Image
4743
//noinspection GradleDependency
4844
implementation 'com.github.bumptech.glide:glide:4.7.1'
4945
//noinspection GradleDependency
5046
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
51-
5247
//Network
5348
//noinspection GradleDependency
5449
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
5550
//noinspection GradleDependency
5651
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
5752
//noinspection GradleDependency
5853
implementation 'com.google.code.gson:gson:2.8.6'
59-
6054
//Times Formatter
6155
implementation 'org.ocpsoft.prettytime:prettytime:4.0.5.Final'
6256
}

app/src/main/java/com/matdevtech/multility/TipCalculator.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import android.widget.Button;
1212
import android.widget.EditText;
1313
import android.widget.TextView;
14+
import android.widget.Toast;
15+
1416
import androidx.annotation.Nullable;
1517
import androidx.fragment.app.Fragment;
1618
import java.util.Objects;
@@ -100,14 +102,22 @@ public void onClick(View view) {
100102
percentage_tip.setText("");
101103
}
102104

103-
float total_price_int = Float.parseFloat(total_price.getText().toString());
104-
float percentage_tip_int = Float.parseFloat(percentage_tip.getText().toString());
105+
float total_price_int;
106+
float percentage_tip_int;
107+
float calculated_tip;
108+
double rounded_tip;
109+
110+
try{
111+
total_price_int = Float.parseFloat(total_price.getText().toString());
112+
percentage_tip_int = Float.parseFloat(percentage_tip.getText().toString());
105113

106-
float calculated_tip = (total_price_int * (percentage_tip_int / 100));
107-
double rounded_tip = Math.round(calculated_tip * 100.0) / 100.0;
114+
calculated_tip = (total_price_int * (percentage_tip_int / 100));
115+
rounded_tip = Math.round(calculated_tip * 100.0) / 100.0;
108116

109-
// String formatting for displaying a trailing zero if there is only a value in the tenths
110-
tip_result.setText("TIP: $" + String.format("%.2f", rounded_tip));
117+
tip_result.setText("TIP: $" + String.format("%.2f", rounded_tip));
118+
}catch(Exception e){
119+
Toast.makeText(getActivity(), "Enter Price/Percentage Info!", Toast.LENGTH_SHORT).show();
120+
}
111121
}
112122
});
113123
}

app/src/main/res/layout-hdpi/item.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
android:layout_alignParentRight="true"
7676
android:layout_marginRight="18dp"
7777
android:layout_marginTop="-50dp"
78+
android:visibility="invisible"
7879
tools:ignore="RtlHardcoded">
7980

8081
<TextView
@@ -146,6 +147,7 @@
146147
android:ellipsize="end"
147148
android:text="Time"
148149
android:textColor="@color/colorPrimaryDark"
150+
android:visibility="invisible"
149151
tools:ignore="HardcodedText,RtlHardcoded"/>
150152

151153
</RelativeLayout>

app/src/main/res/layout-ldpi/item.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
android:layout_alignParentRight="true"
7676
android:layout_marginRight="18dp"
7777
android:layout_marginTop="-50dp"
78+
android:visibility="invisible"
7879
tools:ignore="RtlHardcoded">
7980

8081
<TextView
@@ -146,6 +147,7 @@
146147
android:ellipsize="end"
147148
android:text="Time"
148149
android:textColor="@color/colorPrimaryDark"
150+
android:visibility="invisible"
149151
tools:ignore="HardcodedText,RtlHardcoded"/>
150152

151153
</RelativeLayout>

app/src/main/res/layout-mdpi/item.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
android:layout_alignParentRight="true"
7676
android:layout_marginRight="18dp"
7777
android:layout_marginTop="-50dp"
78+
android:visibility="invisible"
7879
tools:ignore="RtlHardcoded">
7980

8081
<TextView
@@ -146,6 +147,7 @@
146147
android:ellipsize="end"
147148
android:text="Time"
148149
android:textColor="@color/colorPrimaryDark"
150+
android:visibility="invisible"
149151
tools:ignore="HardcodedText,RtlHardcoded"/>
150152

151153
</RelativeLayout>

app/src/main/res/layout-xhdpi/item.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
android:layout_alignParentRight="true"
7676
android:layout_marginRight="18dp"
7777
android:layout_marginTop="-50dp"
78+
android:visibility="invisible"
7879
tools:ignore="RtlHardcoded">
7980

8081
<TextView
@@ -146,6 +147,7 @@
146147
android:ellipsize="end"
147148
android:text="Time"
148149
android:textColor="@color/colorPrimaryDark"
150+
android:visibility="invisible"
149151
tools:ignore="HardcodedText,RtlHardcoded"/>
150152

151153
</RelativeLayout>

app/src/main/res/layout-xxhdpi/item.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
android:layout_alignParentRight="true"
7676
android:layout_marginRight="18dp"
7777
android:layout_marginTop="-50dp"
78+
android:visibility="invisible"
7879
tools:ignore="RtlHardcoded">
7980

8081
<TextView
@@ -146,6 +147,7 @@
146147
android:ellipsize="end"
147148
android:text="Time"
148149
android:textColor="@color/colorPrimaryDark"
150+
android:visibility="invisible"
149151
tools:ignore="HardcodedText,RtlHardcoded"/>
150152

151153
</RelativeLayout>

app/src/main/res/layout-xxxhdpi/item.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
android:layout_alignParentRight="true"
7676
android:layout_marginRight="18dp"
7777
android:layout_marginTop="-50dp"
78+
android:visibility="invisible"
7879
tools:ignore="RtlHardcoded">
7980

8081
<TextView
@@ -146,6 +147,7 @@
146147
android:ellipsize="end"
147148
android:text="Time"
148149
android:textColor="@color/colorPrimaryDark"
150+
android:visibility="invisible"
149151
tools:ignore="HardcodedText,RtlHardcoded"/>
150152

151153
</RelativeLayout>

app/src/main/res/layout/item.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
android:layout_alignParentRight="true"
7676
android:layout_marginRight="18dp"
7777
android:layout_marginTop="-50dp"
78+
android:visibility="invisible"
7879
tools:ignore="RtlHardcoded">
7980

8081
<TextView
@@ -146,6 +147,7 @@
146147
android:ellipsize="end"
147148
android:text="Time"
148149
android:textColor="@color/colorPrimaryDark"
150+
android:visibility="invisible"
149151
tools:ignore="HardcodedText,RtlHardcoded"/>
150152

151153
</RelativeLayout>

0 commit comments

Comments
 (0)