Skip to content

Commit c377aa2

Browse files
authored
Merge pull request #59 from Rajnish23/compose_navigation
Added Jetpack compose dependencies
2 parents c06cb70 + ecd6ce5 commit c377aa2

17 files changed

+229
-149
lines changed

.idea/gradle.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+8-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

+6-1
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,18 @@ dependencies {
7878
implementation 'androidx.appcompat:appcompat:1.2.0'
7979
implementation 'com.google.android.material:material:1.2.1'
8080
implementation "androidx.compose.ui:ui:$compose_version"
81+
implementation "androidx.compose.ui:ui-tooling:$compose_version"
8182
implementation "androidx.compose.material:material:$compose_version"
82-
implementation "androidx.ui:ui-tooling:$compose_version"
83+
implementation "androidx.compose.foundation:foundation:$compose_version"
84+
implementation 'androidx.activity:activity-compose:1.3.0-alpha03'
8385
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-beta01'
8486
testImplementation 'junit:junit:4.13.1'
8587
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
8688
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
8789

90+
//compose navigation
91+
implementation "androidx.navigation:navigation-compose:1.0.0-alpha09"
92+
8893

8994
// Moshi
9095
implementation("com.squareup.moshi:moshi-kotlin:1.11.0")

app/src/main/AndroidManifest.xml

+1-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@
3838
android:roundIcon="@drawable/ic_jetquotes_logo"
3939
android:supportsRtl="true"
4040
android:theme="@style/Theme.JetQuotes">
41-
<activity
42-
android:name=".view.QuoteDetails"
43-
android:label="@string/title_activity_quote_details"
44-
android:theme="@style/Theme.JetQuotes.NoActionBar" />
41+
4542
<activity
4643
android:name=".view.QuotesActivity"
4744
android:label="@string/app_name"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
*
3+
* *
4+
* * * MIT License
5+
* * *
6+
* * * Copyright (c) 2020 Sanju S
7+
* * *
8+
* * * Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* * * of this software and associated documentation files (the "Software"), to deal
10+
* * * in the Software without restriction, including without limitation the rights
11+
* * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* * * copies of the Software, and to permit persons to whom the Software is
13+
* * * furnished to do so, subject to the following conditions:
14+
* * *
15+
* * * The above copyright notice and this permission notice shall be included in all
16+
* * * copies or substantial portions of the Software.
17+
* * *
18+
* * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* * * SOFTWARE.
25+
* *
26+
*
27+
*/
28+
29+
package www.spikeysanju.jetquotes.app
30+
31+
import androidx.compose.runtime.Composable
32+
import androidx.compose.runtime.remember
33+
import androidx.lifecycle.LifecycleCoroutineScope
34+
import androidx.navigation.compose.NavHost
35+
import androidx.navigation.compose.composable
36+
import androidx.navigation.compose.rememberNavController
37+
import www.spikeysanju.jetquotes.ui.JetQuotesTheme
38+
import www.spikeysanju.jetquotes.utils.Actions
39+
import www.spikeysanju.jetquotes.utils.Destinations.QuoteDetails
40+
import www.spikeysanju.jetquotes.utils.Destinations.QuoteDetailsArgs
41+
import www.spikeysanju.jetquotes.utils.Destinations.Quotes
42+
import www.spikeysanju.jetquotes.view.App
43+
import www.spikeysanju.jetquotes.view.DetailQuoteApp
44+
45+
@Composable
46+
fun JetQuoteApp(lifecycleScope: LifecycleCoroutineScope) {
47+
val navController = rememberNavController()
48+
val actions = remember(navController) {
49+
Actions(navController = navController)
50+
}
51+
52+
JetQuotesTheme {
53+
NavHost(navController = navController, startDestination = Quotes) {
54+
composable(Quotes) {
55+
App(lifecycleScope = (lifecycleScope), actions = actions)
56+
57+
}
58+
composable("$QuoteDetails/{${QuoteDetailsArgs.quote}}/{${QuoteDetailsArgs.author}}") { navBackStackEntry ->
59+
DetailQuoteApp(
60+
quote = navBackStackEntry.arguments?.getString(QuoteDetailsArgs.quote) ?: "",
61+
author = navBackStackEntry.arguments?.getString(QuoteDetailsArgs.author) ?: "",
62+
onBackPress = actions.navigateUp
63+
)
64+
}
65+
}
66+
}
67+
}

app/src/main/java/www/spikeysanju/jetquotes/components/Button.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,29 @@
2828

2929
package www.spikeysanju.jetquotes.components
3030

31-
import androidx.compose.foundation.Icon
32-
import androidx.compose.foundation.Text
3331
import androidx.compose.foundation.background
3432
import androidx.compose.foundation.layout.Column
3533
import androidx.compose.foundation.layout.Spacer
3634
import androidx.compose.foundation.layout.height
3735
import androidx.compose.foundation.layout.padding
36+
import androidx.compose.material.Icon
3837
import androidx.compose.material.MaterialTheme
3938
import androidx.compose.material.MaterialTheme.typography
39+
import androidx.compose.material.Text
4040
import androidx.compose.runtime.Composable
4141
import androidx.compose.ui.Modifier
42-
import androidx.compose.ui.graphics.vector.VectorAsset
42+
import androidx.compose.ui.graphics.painter.Painter
4343
import androidx.compose.ui.text.style.TextOverflow
4444
import androidx.compose.ui.unit.dp
4545

4646
@Composable
47-
fun Button(icon: VectorAsset, name: String?, modifier: Modifier) {
47+
fun Button(icon: Painter, name: String?, modifier: Modifier) {
4848
Column(
4949
modifier.background(MaterialTheme.colors.primaryVariant).padding(12.dp)) {
5050

5151
Icon(
52-
asset = icon
52+
painter = icon,
53+
contentDescription = ""
5354
)
5455
Spacer(modifier = Modifier.height(8.dp))
5556
Text(text = name.toString(),

app/src/main/java/www/spikeysanju/jetquotes/components/CTAButtons.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ import androidx.compose.material.MaterialTheme
3636
import androidx.compose.runtime.Composable
3737
import androidx.compose.ui.Alignment
3838
import androidx.compose.ui.Modifier
39-
import androidx.compose.ui.platform.ContextAmbient
40-
import androidx.compose.ui.res.vectorResource
39+
import androidx.compose.ui.platform.LocalContext
40+
import androidx.compose.ui.res.painterResource
4141
import androidx.compose.ui.unit.dp
4242
import www.spikeysanju.jetquotes.R
4343
import www.spikeysanju.jetquotes.utils.copyToClipboard
4444
import www.spikeysanju.jetquotes.utils.shareToOthers
4545

4646
@Composable
4747
fun CTAButtons(quote: String, author: String) {
48-
val context = ContextAmbient.current
48+
val context = LocalContext.current
4949
Box(modifier = Modifier.fillMaxSize()) {
5050
Row(
5151
modifier = Modifier.background(MaterialTheme.colors.primaryVariant)
@@ -54,7 +54,7 @@ fun CTAButtons(quote: String, author: String) {
5454
) {
5555

5656
Button(
57-
icon = vectorResource(id = R.drawable.ic_copy),
57+
icon = painterResource(id = R.drawable.ic_copy),
5858
name = "COPY",
5959
modifier = Modifier.clickable(onClick = {
6060
context.copyToClipboard(quote.plus("").plus("- $author"))
@@ -65,7 +65,7 @@ fun CTAButtons(quote: String, author: String) {
6565
Spacer(modifier = Modifier.width(30.dp))
6666

6767
Button(
68-
icon = vectorResource(id = R.drawable.ic_share),
68+
icon = painterResource(id = R.drawable.ic_share),
6969
name = "SHARE",
7070
modifier = Modifier.clickable(onClick = {
7171
context.shareToOthers(quote.plus("").plus("- $author"))

app/src/main/java/www/spikeysanju/jetquotes/components/DetailCard.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@
2929
package www.spikeysanju.jetquotes.components
3030

3131
import android.widget.Toast
32-
import androidx.compose.foundation.Text
3332
import androidx.compose.foundation.background
3433
import androidx.compose.foundation.clickable
3534
import androidx.compose.foundation.layout.*
3635
import androidx.compose.material.MaterialTheme
3736
import androidx.compose.material.MaterialTheme.typography
37+
import androidx.compose.material.Text
3838
import androidx.compose.runtime.Composable
3939
import androidx.compose.ui.Alignment
4040
import androidx.compose.ui.Modifier
41-
import androidx.compose.ui.platform.ContextAmbient
41+
import androidx.compose.ui.platform.LocalContext
4242
import androidx.compose.ui.text.style.TextAlign
4343
import androidx.compose.ui.unit.dp
4444
import www.spikeysanju.jetquotes.utils.copyToClipboard
4545

4646
@Composable
4747
fun DetailCard(quote: String, author: String) {
48-
val context = ContextAmbient.current
48+
val context = LocalContext.current
4949

5050
Box(modifier = Modifier.fillMaxSize()) {
5151

@@ -66,7 +66,7 @@ fun DetailCard(quote: String, author: String) {
6666
textAlign = TextAlign.Center
6767
)
6868

69-
Spacer(Modifier.preferredHeight(16.dp))
69+
Spacer(Modifier.height(16.dp))
7070

7171
Text(
7272
modifier = Modifier.align(Alignment.CenterHorizontally),
@@ -76,7 +76,7 @@ fun DetailCard(quote: String, author: String) {
7676
textAlign = TextAlign.Center
7777
)
7878

79-
Spacer(Modifier.preferredHeight(16.dp))
79+
Spacer(Modifier.height(16.dp))
8080

8181
Text(
8282
modifier = Modifier.align(Alignment.CenterHorizontally),

app/src/main/java/www/spikeysanju/jetquotes/components/QuotesCard.kt

+7-9
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,24 @@
2828

2929
package www.spikeysanju.jetquotes.components
3030

31-
import androidx.compose.foundation.Text
3231
import androidx.compose.foundation.background
3332
import androidx.compose.foundation.clickable
3433
import androidx.compose.foundation.layout.*
3534
import androidx.compose.material.MaterialTheme
3635
import androidx.compose.material.MaterialTheme.typography
36+
import androidx.compose.material.Text
3737
import androidx.compose.runtime.Composable
3838
import androidx.compose.ui.Alignment
3939
import androidx.compose.ui.Modifier
40-
import androidx.compose.ui.platform.ContextAmbient
4140
import androidx.compose.ui.unit.dp
4241
import www.spikeysanju.jetquotes.model.Quote
43-
import www.spikeysanju.jetquotes.view.QuotesActivity.Companion.launchQuoteDetails
42+
import www.spikeysanju.jetquotes.utils.Actions
4443

4544
@Composable
46-
fun QuotesCard(quote: Quote) {
47-
val context = ContextAmbient.current
45+
fun QuotesCard(quote: Quote, actions: Actions) {
4846

49-
Column(modifier = Modifier.clickable(onClick = {
50-
launchQuoteDetails(context, quote.quote.toString(), quote.author.toString())
47+
Column(modifier = Modifier.wrapContentSize().padding(12.dp).clickable(onClick = {
48+
actions.openQuoteDetails(quote.quote!!, quote.author!!)
5149

5250
}).background(MaterialTheme.colors.primaryVariant).padding(12.dp)) {
5351

@@ -64,7 +62,7 @@ fun QuotesCard(quote: Quote) {
6462
modifier = Modifier.padding(12.dp, 0.dp, 0.dp, 0.dp)
6563
)
6664

67-
Spacer(Modifier.preferredHeight(12.dp))
65+
Spacer(Modifier.height(12.dp))
6866

6967
Box(modifier = Modifier.fillMaxSize()) {
7068
Text(
@@ -73,7 +71,7 @@ fun QuotesCard(quote: Quote) {
7371
style = typography.caption,
7472
color = MaterialTheme.colors.onBackground
7573
)
76-
Spacer(Modifier.preferredHeight(8.dp))
74+
Spacer(Modifier.height(8.dp))
7775
}
7876

7977
}

app/src/main/java/www/spikeysanju/jetquotes/components/QuotesList.kt

+7-6
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@
2828

2929
package www.spikeysanju.jetquotes.components
3030

31-
import androidx.compose.foundation.layout.Column
3231
import androidx.compose.foundation.layout.padding
33-
import androidx.compose.foundation.lazy.LazyColumnFor
32+
import androidx.compose.foundation.lazy.LazyColumn
33+
import androidx.compose.foundation.lazy.items
3434
import androidx.compose.runtime.Composable
3535
import androidx.compose.ui.Modifier
3636
import androidx.compose.ui.unit.dp
3737
import www.spikeysanju.jetquotes.model.Quote
38+
import www.spikeysanju.jetquotes.utils.Actions
3839

3940

4041
@Composable
41-
fun QuotesList(quotes: List<Quote>) {
42-
LazyColumnFor(items = quotes) {
43-
Column(modifier = Modifier.padding(36.dp, 12.dp, 0.dp, 12.dp)) {
44-
QuotesCard(it)
42+
fun QuotesList(quotes: List<Quote>, actions: Actions) {
43+
LazyColumn(modifier = Modifier.padding(36.dp, 12.dp, 0.dp, 12.dp)) {
44+
items(items = quotes) { item ->
45+
QuotesCard(item, actions)
4546
}
4647
}
4748
}

app/src/main/java/www/spikeysanju/jetquotes/components/QuotesThemeSwitch.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ import androidx.compose.foundation.layout.padding
3333
import androidx.compose.material.Icon
3434
import androidx.compose.runtime.Composable
3535
import androidx.compose.ui.Modifier
36-
import androidx.compose.ui.res.vectorResource
36+
import androidx.compose.ui.res.painterResource
3737
import androidx.compose.ui.unit.dp
3838
import www.spikeysanju.jetquotes.R
3939

4040
@Composable
4141
fun QuotesThemeSwitch(onToggle: () -> Unit) {
42-
val icon = vectorResource(R.drawable.ic_day)
43-
Icon(icon, Modifier.padding(end = 8.dp).clickable(onClick = onToggle))
42+
val icon = painterResource(R.drawable.ic_day)
43+
Icon(painter = icon, contentDescription = "", Modifier.padding(end = 8.dp).clickable(onClick = onToggle))
4444
}

app/src/main/java/www/spikeysanju/jetquotes/ui/Type.kt

+5-7
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ package www.spikeysanju.jetquotes.ui
3030

3131

3232
import androidx.compose.material.Typography
33-
import androidx.compose.ui.text.font.FontWeight
34-
import androidx.compose.ui.text.font.font
35-
import androidx.compose.ui.text.font.fontFamily
33+
import androidx.compose.ui.text.font.*
3634
import www.spikeysanju.jetquotes.R
3735

3836

39-
private val futura = fontFamily(
40-
font(R.font.futurabook),
41-
font(R.font.futuramedium, FontWeight.W500),
42-
font(R.font.futurabold, FontWeight.Bold))
37+
private val futura = FontFamily(
38+
Font(R.font.futurabook),
39+
Font(R.font.futuramedium, FontWeight.W500),
40+
Font(R.font.futurabold, FontWeight.Bold))
4341

4442

4543
val typography = Typography(defaultFontFamily = futura)

0 commit comments

Comments
 (0)