-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from Spikeysanju/Add-Favourites
Add favourites
- Loading branch information
Showing
25 changed files
with
759 additions
and
106 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
132 changes: 132 additions & 0 deletions
132
app/src/main/java/www/spikeysanju/jetquotes/components/TopBarWithBack.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,132 @@ | ||
/* | ||
* | ||
* * | ||
* * * 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.components | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.wrapContentSize | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.ArrowBack | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.unit.dp | ||
import www.spikeysanju.jetquotes.R | ||
import www.spikeysanju.jetquotes.ui.typography | ||
|
||
|
||
@Composable | ||
fun TopBar(title: String, onToggle: () -> Unit, onFavouritesClick: () -> Unit) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height(70.dp) | ||
.background(MaterialTheme.colors.background), contentAlignment = Alignment.CenterStart | ||
) { | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
Text( | ||
text = title, | ||
style = typography.h5, | ||
color = MaterialTheme.colors.onPrimary, | ||
modifier = Modifier.padding(start = 16.dp) | ||
) | ||
Row(modifier = Modifier.wrapContentSize(), Arrangement.End) { | ||
|
||
IconButton( | ||
onClick = { onFavouritesClick() }, | ||
modifier = Modifier.padding(end = 16.dp) | ||
) { | ||
val settingsIcon: Painter = painterResource(id = R.drawable.ic_heart) | ||
Icon( | ||
painter = settingsIcon, | ||
contentDescription = "Favourites Icon", | ||
tint = MaterialTheme.colors.onPrimary | ||
) | ||
} | ||
|
||
IconButton(onClick = { onToggle() }, modifier = Modifier.padding(end = 16.dp)) { | ||
val toggleIcon = if (isSystemInDarkTheme()) | ||
painterResource(id = R.drawable.ic_night) | ||
else | ||
painterResource(id = R.drawable.ic_day) | ||
Icon( | ||
painter = toggleIcon, | ||
contentDescription = "Day/Night Icon", | ||
tint = MaterialTheme.colors.onPrimary | ||
) | ||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
|
||
@Composable | ||
fun TopBarWithBack(title: String, onBackClick: () -> Unit) { | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
Arrangement.Start, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
IconButton(onClick = { onBackClick() }, modifier = Modifier.padding(start = 16.dp)) { | ||
Icon( | ||
imageVector = Icons.Default.ArrowBack, | ||
contentDescription = "Back Icon", | ||
tint = MaterialTheme.colors.onPrimary | ||
) | ||
} | ||
|
||
Text( | ||
text = title, | ||
style = typography.h6, | ||
color = MaterialTheme.colors.onPrimary, | ||
modifier = Modifier.padding(start = 16.dp) | ||
) | ||
|
||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/www/spikeysanju/jetquotes/data/preference/db/FavouritesDao.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,55 @@ | ||
/* | ||
* | ||
* * | ||
* * * 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.data.preference.db | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Delete | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import androidx.room.Update | ||
import kotlinx.coroutines.flow.Flow | ||
import www.spikeysanju.jetquotes.model.Quote | ||
|
||
@Dao | ||
interface FavouritesDao { | ||
|
||
@Query("SELECT * FROM favourites") | ||
fun getAllFavourites(): Flow<List<Quote>> | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insertFavourite(quote: Quote) | ||
|
||
@Delete | ||
suspend fun delete(quote: Quote) | ||
|
||
@Update(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun updateFavourite(quote: Quote) | ||
|
||
} |
Oops, something went wrong.