Skip to content

Commit

Permalink
🆕 feat: adding screenshots files
Browse files Browse the repository at this point in the history
  • Loading branch information
e-haikal committed Oct 17, 2024
1 parent dd1b1ea commit 82cd89f
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 12 deletions.
Binary file added DicodingEvent/screenshots/DicodingEvent.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions MyUnitTest/.idea/compiler.xml

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

10 changes: 10 additions & 0 deletions MyUnitTest/.idea/deploymentTargetSelector.xml

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

7 changes: 7 additions & 0 deletions MyUnitTest/.idea/gradle.xml

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

6 changes: 6 additions & 0 deletions MyUnitTest/.idea/kotlinc.xml

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

2 changes: 1 addition & 1 deletion MyUnitTest/.idea/misc.xml

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

3 changes: 3 additions & 0 deletions MyUnitTest/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ dependencies {
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

testImplementation(libs.mockito.core)
testImplementation(libs.mockito.inline)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
package com.siaptekno.myunittest

class CuboidModel {
private var width = 0.0
private var length = 0.0
private var height = 0.0

fun getVolume(): Double = width * length * height

fun getSurfaceArea(): Double {
val wl = width * length
val wh = width * height
val lh = length * height
return 2 * (wl + wh + lh)
}

fun getCircumference(): Double = 4 * (width + length + height)
fun save(width: Double, length: Double, height: Double) {
this.width = width
this.length = length
this.height = height
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package com.siaptekno.myunittest

import android.os.Bundle
import android.text.TextUtils
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.siaptekno.myunittest.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity(), View.OnClickListener {

private lateinit var activityMainBinding: ActivityMainBinding
private lateinit var mainViewModel: MainViewModel

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
Expand All @@ -16,5 +23,74 @@ class MainActivity : AppCompatActivity() {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}

activityMainBinding = ActivityMainBinding.inflate(layoutInflater)
setContentView(activityMainBinding.root)

mainViewModel = MainViewModel(CuboidModel())

activityMainBinding.btnSave.setOnClickListener(this)
activityMainBinding.btnCalculateSurfaceArea.setOnClickListener(this)
activityMainBinding.btnCalculateCircumference.setOnClickListener(this)
activityMainBinding.btnCalculateVolume.setOnClickListener(this)


}

override fun onClick(v: View?) {
val length = activityMainBinding.edtLength.text.toString().trim()
val width = activityMainBinding.edtWidth.text.toString().trim()
val height = activityMainBinding.edtHeight.text.toString().trim()
when {
TextUtils.isEmpty(length) -> {
activityMainBinding.edtLength.error = "Field ini tidak boleh kosong"
}
TextUtils.isEmpty(width) -> {
activityMainBinding.edtWidth.error = "Field ini tidak boleh kosong"
}
TextUtils.isEmpty(height) -> {
activityMainBinding.edtHeight.error = "Field ini tidak boleh kosong"
}
else -> {
val valueLength = length.toDouble()
val valueWidth = width.toDouble()
val valueHeight = height.toDouble()
when (v?.id) {
R.id.btn_save -> {
mainViewModel.save(valueLength, valueWidth, valueHeight)
visible()
}
R.id.btn_calculate_circumference -> {
activityMainBinding.tvResult.text = mainViewModel.getCircumference().toString()
gone()
}
R.id.btn_calculate_surface_area -> {
activityMainBinding.tvResult.text = mainViewModel.getSurfaceArea().toString()
gone()
}
R.id.btn_calculate_volume -> {
activityMainBinding.tvResult.text = mainViewModel.getVolume().toString()
gone()
}
}
}
}
}

private fun visible() {
activityMainBinding.btnCalculateVolume.visibility = View.VISIBLE
activityMainBinding.btnCalculateCircumference.visibility = View.VISIBLE
activityMainBinding.btnCalculateSurfaceArea.visibility = View.VISIBLE
activityMainBinding.btnSave.visibility = View.GONE
}
private fun gone() {
activityMainBinding.btnCalculateVolume.visibility = View.GONE
activityMainBinding.btnCalculateCircumference.visibility = View.GONE
activityMainBinding.btnCalculateSurfaceArea.visibility = View.GONE
activityMainBinding.btnSave.visibility = View.VISIBLE

}



}
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package com.siaptekno.myunittest

class MainViewModel {
class MainViewModel(private val cuboidModel: CuboidModel) {
fun getCircumference() = cuboidModel.getCircumference()
fun getSurfaceArea() = cuboidModel.getSurfaceArea()
fun getVolume() = cuboidModel.getVolume()
fun save(w: Double, l: Double, h: Double) {
cuboidModel.save(w, l, h)
}
}
87 changes: 78 additions & 9 deletions MyUnitTest/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:text="@string/length" />
<EditText
android:id="@+id/edt_length"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:inputType="numberDecimal"
android:lines="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/width" />
<EditText
android:id="@+id/edt_width"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:inputType="numberDecimal"
android:lines="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/height" />
<EditText
android:id="@+id/edt_height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:inputType="numberDecimal"
android:lines="1" />
<Button
android:id="@+id/btn_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/save" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:orientation="horizontal">
<Button
android:id="@+id/btn_calculate_volume"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/calculate_volume"
android:visibility="gone" />
<Button
android:id="@+id/btn_calculate_circumference"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="@string/calculate_circumference"
android:visibility="gone" />
<Button
android:id="@+id/btn_calculate_surface_area"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/calculate_surface_area"
android:visibility="gone" />
</LinearLayout>
<TextView
android:id="@+id/tv_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:gravity="center"
android:text="@string/result"
android:textSize="24sp"
android:textStyle="bold" />

</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
9 changes: 9 additions & 0 deletions MyUnitTest/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<resources>
<string name="app_name">MyUnitTest</string>

<string name="width">Lebar</string>
<string name="result">Hasil</string>
<string name="calculate_volume">Hitung Volume</string>
<string name="calculate_surface_area">Hitung Luas Area</string>
<string name="calculate_circumference">Hitung Keliling</string>
<string name="height">Tinggi</string>
<string name="length">Panjang</string>
<string name="save">Simpan</string>
</resources>
3 changes: 3 additions & 0 deletions MyUnitTest/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ appcompat = "1.7.0"
material = "1.12.0"
activity = "1.9.3"
constraintlayout = "2.1.4"
mockitoCore = "4.4.0"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand All @@ -19,6 +20,8 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockitoCore" }
mockito-inline = { module = "org.mockito:mockito-inline", version.ref = "mockitoCore" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down

0 comments on commit 82cd89f

Please sign in to comment.