-
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.
Implemented ProgressView and first alpha release
Signed-off-by: dracarys18 <[email protected]>
- Loading branch information
1 parent
1f1994f
commit 0adb493
Showing
11 changed files
with
337 additions
and
21 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
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
4 changes: 3 additions & 1 deletion
4
app/src/main/java/com/karthihegde/readlist/navigation/screens/Screens.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
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
139 changes: 139 additions & 0 deletions
139
app/src/main/java/com/karthihegde/readlist/ui/EditBookProgress.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,139 @@ | ||
package com.karthihegde.readlist.ui | ||
|
||
import android.app.Application | ||
import android.widget.Toast | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.foundation.text.KeyboardActions | ||
import androidx.compose.material.* | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.ArrowBackIosNew | ||
import androidx.compose.material.icons.filled.Check | ||
import androidx.compose.runtime.* | ||
import androidx.compose.runtime.livedata.observeAsState | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.shadow | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.navigation.NavController | ||
import com.karthihegde.readlist.database.BookViewModel | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import kotlin.math.abs | ||
|
||
@Composable | ||
fun EditBookProgress(navController: NavController, id: String) { | ||
val context = LocalContext.current | ||
var newPage = 0 | ||
val viewModel = BookViewModel(context.applicationContext as Application) | ||
val bookData by viewModel.dao.getBookFromId(id).observeAsState() | ||
val pagesRead = bookData?.pagesRead?.toString() ?: "" | ||
var isError by remember { | ||
mutableStateOf(false) | ||
} | ||
var text by remember { | ||
mutableStateOf("") | ||
} | ||
val borderColor = if (isSystemInDarkTheme()) Color.DarkGray else Color.LightGray | ||
val totalPages = bookData?.totalPages ?: Int.MAX_VALUE | ||
fun onDoneAction() { | ||
if (!isError && text.isNotEmpty()) { | ||
val scope = CoroutineScope(Job() + Dispatchers.IO) | ||
scope.launch { | ||
viewModel.dao.updatePages(pages = newPage, id = id) | ||
} | ||
navController.popBackStack() | ||
} else | ||
Toast.makeText( | ||
context, | ||
"Enter a Proper Page Number", | ||
Toast.LENGTH_SHORT | ||
).show() | ||
} | ||
Scaffold(topBar = { | ||
Box( | ||
modifier = Modifier | ||
.padding(top = 8.dp) | ||
.fillMaxWidth() | ||
) { | ||
IconButton( | ||
onClick = { navController.popBackStack() }, | ||
modifier = Modifier.align(Alignment.TopStart) | ||
) { | ||
Icon( | ||
Icons.Filled.ArrowBackIosNew, | ||
contentDescription = "", | ||
tint = MaterialTheme.colors.onBackground, | ||
modifier = Modifier.shadow(elevation = 8.dp, clip = true) | ||
) | ||
} | ||
} | ||
}) { | ||
Column(modifier = Modifier.fillMaxSize()) { | ||
Row( | ||
modifier = Modifier.padding(8.dp) | ||
) { | ||
Text( | ||
text = "Pages Read:", | ||
fontSize = 20.sp, | ||
color = MaterialTheme.colors.onBackground, | ||
modifier = Modifier.padding(20.dp) | ||
) | ||
Row { | ||
OutlinedTextField( | ||
value = text, | ||
onValueChange = { value -> | ||
text = value | ||
isError = try { | ||
newPage = abs(value.toInt()) | ||
newPage > totalPages | ||
} catch (e: NumberFormatException) { | ||
true | ||
} | ||
}, | ||
placeholder = { Text(pagesRead, textAlign = TextAlign.Center) }, | ||
isError = isError, | ||
singleLine = true, | ||
keyboardActions = KeyboardActions(onDone = { onDoneAction() }), | ||
modifier = Modifier | ||
.wrapContentHeight() | ||
.fillMaxWidth(0.6f) | ||
.padding(top = 10.dp) | ||
.border(1.dp, color = borderColor, shape = RoundedCornerShape(12.dp)), | ||
colors = TextFieldDefaults.textFieldColors( | ||
backgroundColor = MaterialTheme.colors.background, | ||
focusedIndicatorColor = Color.Transparent, | ||
unfocusedIndicatorColor = Color.Transparent | ||
) | ||
) | ||
Text( | ||
text = "/$totalPages", | ||
fontSize = 20.sp, | ||
color = MaterialTheme.colors.onBackground, | ||
modifier = Modifier.padding(20.dp) | ||
) | ||
} | ||
} | ||
Row { | ||
Spacer(modifier = Modifier.fillMaxWidth(0.8f)) | ||
OutlinedButton( | ||
onClick = { | ||
onDoneAction() | ||
}, | ||
shape = RoundedCornerShape(50), | ||
colors = ButtonDefaults.buttonColors(backgroundColor = MaterialTheme.colors.secondary) | ||
) { | ||
Icon(Icons.Default.Check, contentDescription = "") | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.