Skip to content

Commit

Permalink
Merge pull request #14 from AliElDerawi/code_improvements
Browse files Browse the repository at this point in the history
refactor: Apply general code improvements to util and model classes.
  • Loading branch information
AliElDerawi authored Jan 6, 2025
2 parents 10a7377 + 7546246 commit 2eea68b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.udacity.shoestore.data.GenericModelCallBack
data class InstructionModel(
val title: String,
val description: String,
var drawable: Int
val drawable: Int
) {

companion object{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class ShoeModel(
var size: Double,
var company: String,
var description: String,
val images: List<String> = mutableListOf()
var images: List<String> = mutableListOf()
) : Parcelable {

companion object{
Expand Down
16 changes: 3 additions & 13 deletions app/src/main/java/com/udacity/shoestore/utils/AppSharedMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,22 @@ object AppSharedMethods {

private var mToast: Toast? = null

fun Activity.showToast(message: String, duration: Int = Toast.LENGTH_LONG) {
mToast?.cancel()
mToast = Toast.makeText(ShoeStoreApp.getApp().applicationContext, message, duration)
mToast!!.show()
}

fun showToast(message: String, duration: Int = Toast.LENGTH_LONG) {
mToast?.cancel()
mToast = Toast.makeText(ShoeStoreApp.getApp().applicationContext, message, duration)
mToast!!.show()
}

fun showToast(message: Int, duration: Int = Toast.LENGTH_LONG) {
fun Activity.showToast(message: Int, duration: Int = Toast.LENGTH_LONG) {
mToast?.cancel()
mToast = Toast.makeText(ShoeStoreApp.getApp().applicationContext, message, duration)
mToast = Toast.makeText(ShoeStoreApp.getApp().applicationContext, getString(message), duration)
mToast!!.show()
}

fun EditText.isEmpty(): Boolean {
return this.text.toString().isEmpty()
}

fun EditText.isValidEmail(): Boolean {
return !this.isEmpty() && Patterns.EMAIL_ADDRESS.matcher(this.text.toString()).matches()
}

fun String.isValidEmail(): Boolean {
return this.isNotEmpty() && Patterns.EMAIL_ADDRESS.matcher(this).matches()
}
Expand Down Expand Up @@ -251,7 +241,7 @@ object AppSharedMethods {
fun NavController.validateStartDestination(){
val navGraph = navInflater.inflate(R.navigation.main_navigation).apply {
setStartDestination(
if (AppSharedMethods.isLogin()) {
if (isLogin()) {
R.id.shoesListFragment
} else {
R.id.loginFragment
Expand Down

0 comments on commit 2eea68b

Please sign in to comment.