Skip to content

Commit

Permalink
Merge pull request #59 from Rajnish23/compose_navigation
Browse files Browse the repository at this point in the history
Added Jetpack compose dependencies
  • Loading branch information
Spikeysanju authored Apr 5, 2021
2 parents c06cb70 + ecd6ce5 commit c377aa2
Show file tree
Hide file tree
Showing 17 changed files with 229 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

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

9 changes: 8 additions & 1 deletion .idea/misc.xml

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

7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.ui:ui-tooling:$compose_version"
implementation "androidx.compose.foundation:foundation:$compose_version"
implementation 'androidx.activity:activity-compose:1.3.0-alpha03'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-beta01'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

//compose navigation
implementation "androidx.navigation:navigation-compose:1.0.0-alpha09"


// Moshi
implementation("com.squareup.moshi:moshi-kotlin:1.11.0")
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
android:roundIcon="@drawable/ic_jetquotes_logo"
android:supportsRtl="true"
android:theme="@style/Theme.JetQuotes">
<activity
android:name=".view.QuoteDetails"
android:label="@string/title_activity_quote_details"
android:theme="@style/Theme.JetQuotes.NoActionBar" />

<activity
android:name=".view.QuotesActivity"
android:label="@string/app_name"
Expand Down
67 changes: 67 additions & 0 deletions app/src/main/java/www/spikeysanju/jetquotes/app/JetQuoteApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
*
* *
* * * MIT License
* * *
* * * Copyright (c) 2020 Sanju S
* * *
* * * Permission is hereby granted, free of charge, to any person obtaining a copy
* * * of this software and associated documentation files (the "Software"), to deal
* * * in the Software without restriction, including without limitation the rights
* * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* * * copies of the Software, and to permit persons to whom the Software is
* * * furnished to do so, subject to the following conditions:
* * *
* * * The above copyright notice and this permission notice shall be included in all
* * * copies or substantial portions of the Software.
* * *
* * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* * * SOFTWARE.
* *
*
*/

package www.spikeysanju.jetquotes.app

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import www.spikeysanju.jetquotes.ui.JetQuotesTheme
import www.spikeysanju.jetquotes.utils.Actions
import www.spikeysanju.jetquotes.utils.Destinations.QuoteDetails
import www.spikeysanju.jetquotes.utils.Destinations.QuoteDetailsArgs
import www.spikeysanju.jetquotes.utils.Destinations.Quotes
import www.spikeysanju.jetquotes.view.App
import www.spikeysanju.jetquotes.view.DetailQuoteApp

@Composable
fun JetQuoteApp(lifecycleScope: LifecycleCoroutineScope) {
val navController = rememberNavController()
val actions = remember(navController) {
Actions(navController = navController)
}

JetQuotesTheme {
NavHost(navController = navController, startDestination = Quotes) {
composable(Quotes) {
App(lifecycleScope = (lifecycleScope), actions = actions)

}
composable("$QuoteDetails/{${QuoteDetailsArgs.quote}}/{${QuoteDetailsArgs.author}}") { navBackStackEntry ->
DetailQuoteApp(
quote = navBackStackEntry.arguments?.getString(QuoteDetailsArgs.quote) ?: "",
author = navBackStackEntry.arguments?.getString(QuoteDetailsArgs.author) ?: "",
onBackPress = actions.navigateUp
)
}
}
}
}
11 changes: 6 additions & 5 deletions app/src/main/java/www/spikeysanju/jetquotes/components/Button.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,29 @@

package www.spikeysanju.jetquotes.components

import androidx.compose.foundation.Icon
import androidx.compose.foundation.Text
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.MaterialTheme.typography
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.VectorAsset
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp

@Composable
fun Button(icon: VectorAsset, name: String?, modifier: Modifier) {
fun Button(icon: Painter, name: String?, modifier: Modifier) {
Column(
modifier.background(MaterialTheme.colors.primaryVariant).padding(12.dp)) {

Icon(
asset = icon
painter = icon,
contentDescription = ""
)
Spacer(modifier = Modifier.height(8.dp))
Text(text = name.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ContextAmbient
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import www.spikeysanju.jetquotes.R
import www.spikeysanju.jetquotes.utils.copyToClipboard
import www.spikeysanju.jetquotes.utils.shareToOthers

@Composable
fun CTAButtons(quote: String, author: String) {
val context = ContextAmbient.current
val context = LocalContext.current
Box(modifier = Modifier.fillMaxSize()) {
Row(
modifier = Modifier.background(MaterialTheme.colors.primaryVariant)
Expand All @@ -54,7 +54,7 @@ fun CTAButtons(quote: String, author: String) {
) {

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

Button(
icon = vectorResource(id = R.drawable.ic_share),
icon = painterResource(id = R.drawable.ic_share),
name = "SHARE",
modifier = Modifier.clickable(onClick = {
context.shareToOthers(quote.plus("").plus("- $author"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@
package www.spikeysanju.jetquotes.components

import android.widget.Toast
import androidx.compose.foundation.Text
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.MaterialTheme.typography
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ContextAmbient
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import www.spikeysanju.jetquotes.utils.copyToClipboard

@Composable
fun DetailCard(quote: String, author: String) {
val context = ContextAmbient.current
val context = LocalContext.current

Box(modifier = Modifier.fillMaxSize()) {

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

Spacer(Modifier.preferredHeight(16.dp))
Spacer(Modifier.height(16.dp))

Text(
modifier = Modifier.align(Alignment.CenterHorizontally),
Expand All @@ -76,7 +76,7 @@ fun DetailCard(quote: String, author: String) {
textAlign = TextAlign.Center
)

Spacer(Modifier.preferredHeight(16.dp))
Spacer(Modifier.height(16.dp))

Text(
modifier = Modifier.align(Alignment.CenterHorizontally),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,24 @@

package www.spikeysanju.jetquotes.components

import androidx.compose.foundation.Text
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.MaterialTheme.typography
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ContextAmbient
import androidx.compose.ui.unit.dp
import www.spikeysanju.jetquotes.model.Quote
import www.spikeysanju.jetquotes.view.QuotesActivity.Companion.launchQuoteDetails
import www.spikeysanju.jetquotes.utils.Actions

@Composable
fun QuotesCard(quote: Quote) {
val context = ContextAmbient.current
fun QuotesCard(quote: Quote, actions: Actions) {

Column(modifier = Modifier.clickable(onClick = {
launchQuoteDetails(context, quote.quote.toString(), quote.author.toString())
Column(modifier = Modifier.wrapContentSize().padding(12.dp).clickable(onClick = {
actions.openQuoteDetails(quote.quote!!, quote.author!!)

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

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

Spacer(Modifier.preferredHeight(12.dp))
Spacer(Modifier.height(12.dp))

Box(modifier = Modifier.fillMaxSize()) {
Text(
Expand All @@ -73,7 +71,7 @@ fun QuotesCard(quote: Quote) {
style = typography.caption,
color = MaterialTheme.colors.onBackground
)
Spacer(Modifier.preferredHeight(8.dp))
Spacer(Modifier.height(8.dp))
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@

package www.spikeysanju.jetquotes.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumnFor
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import www.spikeysanju.jetquotes.model.Quote
import www.spikeysanju.jetquotes.utils.Actions


@Composable
fun QuotesList(quotes: List<Quote>) {
LazyColumnFor(items = quotes) {
Column(modifier = Modifier.padding(36.dp, 12.dp, 0.dp, 12.dp)) {
QuotesCard(it)
fun QuotesList(quotes: List<Quote>, actions: Actions) {
LazyColumn(modifier = Modifier.padding(36.dp, 12.dp, 0.dp, 12.dp)) {
items(items = quotes) { item ->
QuotesCard(item, actions)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import www.spikeysanju.jetquotes.R

@Composable
fun QuotesThemeSwitch(onToggle: () -> Unit) {
val icon = vectorResource(R.drawable.ic_day)
Icon(icon, Modifier.padding(end = 8.dp).clickable(onClick = onToggle))
val icon = painterResource(R.drawable.ic_day)
Icon(painter = icon, contentDescription = "", Modifier.padding(end = 8.dp).clickable(onClick = onToggle))
}
12 changes: 5 additions & 7 deletions app/src/main/java/www/spikeysanju/jetquotes/ui/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ package www.spikeysanju.jetquotes.ui


import androidx.compose.material.Typography
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.font.font
import androidx.compose.ui.text.font.fontFamily
import androidx.compose.ui.text.font.*
import www.spikeysanju.jetquotes.R


private val futura = fontFamily(
font(R.font.futurabook),
font(R.font.futuramedium, FontWeight.W500),
font(R.font.futurabold, FontWeight.Bold))
private val futura = FontFamily(
Font(R.font.futurabook),
Font(R.font.futuramedium, FontWeight.W500),
Font(R.font.futurabold, FontWeight.Bold))


val typography = Typography(defaultFontFamily = futura)
Loading

0 comments on commit c377aa2

Please sign in to comment.