-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a proper error handling if user hit the convert button without en…
…tering any amount. Add Navigation, NavigationGraph.kt that contains splash screen and also main currency rate listing screen for better management of UI. Refactor MainNavigationActivity.kt name and its package.
- Loading branch information
1 parent
26525d3
commit 723d848
Showing
11 changed files
with
198 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/asad/currencyconverter/ui/MainNavigationActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.asad.currencyconverter.ui | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.activity.viewModels | ||
import com.asad.currencyconverter.ui.navgraph.Navigation | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class MainNavigationActivity : ComponentActivity() { | ||
private val viewModel: MainActivityViewModel by viewModels() | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
Navigation(viewModel) | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
.../currencyrates/CurrencyRatesRepository.kt → ...ad/currencyconverter/ui/MainRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ncyconverter/ui/currencyrates/UiStates.kt → ...com/asad/currencyconverter/ui/UiStates.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.asad.currencyconverter.ui.currencyrates | ||
package com.asad.currencyconverter.ui | ||
|
||
|
||
sealed class UiStates | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
app/src/main/java/com/asad/currencyconverter/ui/currencyrates/CurrencyRatesActivity.kt
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/asad/currencyconverter/ui/navgraph/NavigationGraph.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.asad.currencyconverter.ui.navgraph | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.compose.rememberNavController | ||
import com.asad.currencyconverter.ui.MainActivityViewModel | ||
import com.asad.currencyconverter.ui.currencyrates.CurrencyConverter | ||
import com.asad.currencyconverter.ui.splash.SplashScreen | ||
import kotlinx.coroutines.delay | ||
|
||
@Composable | ||
fun Navigation(viewModel: MainActivityViewModel) { | ||
val navController = rememberNavController() | ||
|
||
LaunchedEffect(Unit) { | ||
delay(500) | ||
navController.navigate(route = Screen.CurrencyRatesListScreen.route) { | ||
popUpTo(Screen.SplashScreen.route) { | ||
inclusive = true | ||
} | ||
} | ||
} | ||
|
||
NavHost(navController = navController, startDestination = Screen.SplashScreen.route) { | ||
composable(Screen.SplashScreen.route) { | ||
SplashScreen() | ||
} | ||
composable(route = Screen.CurrencyRatesListScreen.route) { | ||
CurrencyConverter(viewModel) | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/asad/currencyconverter/ui/navgraph/Screen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.asad.currencyconverter.ui.navgraph | ||
|
||
sealed class Screen(val route: String) { | ||
object SplashScreen : Screen("SplashScreen") | ||
object CurrencyRatesListScreen : Screen("CurrencyRatesListScreen") | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/asad/currencyconverter/ui/splash/SplashScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.asad.currencyconverter.ui.splash | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.painterResource | ||
import com.asad.currencyconverter.R | ||
|
||
@Composable | ||
fun SplashScreen() { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(color = Color.White), | ||
contentAlignment = Alignment.Center | ||
) { | ||
Image( | ||
painter = painterResource(id = R.drawable.ic_currency), contentDescription = null, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<style name="Theme.CurrencyConverter" parent="android:Theme.Material.Light.NoActionBar" /> | ||
<style name="Theme.CurrencyConverter" parent="android:Theme.Material.Light.NoActionBar"> | ||
<item name="android:windowDisablePreview">true</item> | ||
</style> | ||
</resources> |