Skip to content

Commit

Permalink
Merge pull request #11 from AliElDerawi/code_improvments
Browse files Browse the repository at this point in the history
refactor: Improve MainActivity class code.
  • Loading branch information
AliElDerawi authored Jan 6, 2025
2 parents 29a65b5 + c43b764 commit ed8bcfa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.udacity.shoestore.utils.AppSharedMethods.applyWindowsPadding
import com.udacity.shoestore.utils.AppSharedMethods.getCompatColor
import com.udacity.shoestore.utils.AppSharedMethods.setMenuColor
import com.udacity.shoestore.utils.AppSharedMethods.setStatusBarColorAndStyle
import com.udacity.shoestore.utils.AppSharedMethods.validateStartDestination
import org.koin.android.ext.android.inject
import timber.log.Timber

Expand Down Expand Up @@ -47,16 +48,7 @@ class MainActivity : AppCompatActivity() {
mAppBarConfiguration = AppBarConfiguration(mNavController.graph)

if (savedInstanceState == null) {
val navGraph = mNavController.navInflater.inflate(R.navigation.main_navigation).apply {
setStartDestination(
if (AppSharedMethods.isLogin()) {
R.id.shoesListFragment
} else {
R.id.loginFragment
}
)
}
mNavController.graph = navGraph
mNavController.validateStartDestination()
}

initViewModelObservers()
Expand Down
20 changes: 13 additions & 7 deletions app/src/main/java/com/udacity/shoestore/utils/AppSharedMethods.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.udacity.shoestore.utils

import android.app.ActionBar
import android.app.Activity
import android.app.Application
import android.content.Context
Expand All @@ -11,23 +10,18 @@ import android.os.Build
import android.util.Patterns
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.WindowInsets
import android.view.WindowInsetsController
import android.view.WindowManager
import android.widget.Button
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.ColorUtils
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.navigation.NavController
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey
import com.bumptech.glide.Glide
Expand Down Expand Up @@ -254,5 +248,17 @@ object AppSharedMethods {
overflowIcon?.setTint(context.getCompatColor(color))
}

fun NavController.validateStartDestination(){
val navGraph = navInflater.inflate(R.navigation.main_navigation).apply {
setStartDestination(
if (AppSharedMethods.isLogin()) {
R.id.shoesListFragment
} else {
R.id.loginFragment
}
)
}
graph = navGraph
}

}

0 comments on commit ed8bcfa

Please sign in to comment.