Готово

This commit is contained in:
m.zargarov 2023-12-05 23:51:25 +04:00
parent 48d46fe9ba
commit 93752973fc
9 changed files with 39 additions and 80 deletions

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\Marat\.android\avd\Pixel_5_API_30.avd" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-12-05T17:47:31.084874500Z" />
</component>
</project>

View File

@ -38,16 +38,16 @@ fun BookText(id: Int) {
setBook(AppDatabase.getInstance(context).bookDao().getByUid(id)) setBook(AppDatabase.getInstance(context).bookDao().getByUid(id))
} }
} }
val textContent: String = assetManager.open(book?.text ?: "").bufferedReader().use { it.readText() } val textContent: String = if (book != null) {
assetManager.open(book.text).bufferedReader().use { it.readText() }
} else {
"Текст отсутствует"
}
Column( Column(
verticalArrangement = Arrangement.Center, verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally
modifier = Modifier.verticalScroll(rememberScrollState())
) { ) {
Button(onClick = { }) { Text(text = textContent, modifier = Modifier.verticalScroll(rememberScrollState()))
Text(text = "Добавить в избранное")
}
Text(text = textContent)
} }
} }
@ -59,7 +59,7 @@ fun BookTextPreview() {
Surface( Surface(
color = MaterialTheme.colorScheme.background color = MaterialTheme.colorScheme.background
) { ) {
BookText(id = 0) BookText(id = 1)
} }
} }
} }

View File

@ -29,6 +29,7 @@ abstract class AppDatabase : RoomDatabase() {
private suspend fun populateDatabase() { private suspend fun populateDatabase() {
INSTANCE?.let { database -> INSTANCE?.let { database ->
// Books // Books
val bookDao = database.bookDao() val bookDao = database.bookDao()
val book1 = Book("Книга 1", "Автор 1", 18, "booktexts/dostoevskiy_besy.txt", "images/dostoevskiy_besy.jpg") val book1 = Book("Книга 1", "Автор 1", 18, "booktexts/dostoevskiy_besy.txt", "images/dostoevskiy_besy.jpg")
@ -36,11 +37,13 @@ abstract class AppDatabase : RoomDatabase() {
val book3 = Book("Книга 3", "Автор 3", 12, "booktexts/dostoevskiy_besy.txt", "images/dostoevskiy_besy.jpg") val book3 = Book("Книга 3", "Автор 3", 12, "booktexts/dostoevskiy_besy.txt", "images/dostoevskiy_besy.jpg")
val book4 = Book("Книга 4", "Автор 4", 12, "booktexts/dostoevskiy_besy.txt", "images/dostoevskiy_besy.jpg") val book4 = Book("Книга 4", "Автор 4", 12, "booktexts/dostoevskiy_besy.txt", "images/dostoevskiy_besy.jpg")
val book5 = Book("Книга 5", "Автор 5", 12, "booktexts/dostoevskiy_besy.txt", "images/dostoevskiy_besy.jpg") val book5 = Book("Книга 5", "Автор 5", 12, "booktexts/dostoevskiy_besy.txt", "images/dostoevskiy_besy.jpg")
val book6 = Book("Книга 6", "Автор 5", 12, "booktexts/dostoevskiy_besy.txt", "images/dostoevskiy_besy.jpg")
bookDao.insert(book1) bookDao.insert(book1)
bookDao.insert(book2) bookDao.insert(book2)
bookDao.insert(book3) bookDao.insert(book3)
bookDao.insert(book4) bookDao.insert(book4)
bookDao.insert(book5) bookDao.insert(book5)
bookDao.insert(book6)
// Users // Users
val userDao = database.userDao() val userDao = database.userDao()
@ -54,8 +57,8 @@ abstract class AppDatabase : RoomDatabase() {
val userBook1= UserBookCrossRef(1,2) val userBook1= UserBookCrossRef(1,2)
val userBook2= UserBookCrossRef(1,3) val userBook2= UserBookCrossRef(1,3)
val userBook3= UserBookCrossRef(1,4) val userBook3= UserBookCrossRef(1,4)
val userBook4= UserBookCrossRef(2,0) val userBook4= UserBookCrossRef(2,1)
val userBook5= UserBookCrossRef(2,1) val userBook5= UserBookCrossRef(2,2)
val userBook6= UserBookCrossRef(2,4) val userBook6= UserBookCrossRef(2,4)
userBookDao.insert(userBook1) userBookDao.insert(userBook1)
@ -64,7 +67,6 @@ abstract class AppDatabase : RoomDatabase() {
userBookDao.insert(userBook4) userBookDao.insert(userBook4)
userBookDao.insert(userBook5) userBookDao.insert(userBook5)
userBookDao.insert(userBook6) userBookDao.insert(userBook6)
} }
} }

View File

@ -118,7 +118,7 @@ fun BookListPreview() {
Surface( Surface(
color = MaterialTheme.colorScheme.background color = MaterialTheme.colorScheme.background
) { ) {
FavoriteList(navController = null,uid=0) FavoriteList(navController = null,uid=1)
} }
} }
} }

View File

@ -1,54 +0,0 @@
//package com.example.shortbooks.favorite.composeui
//
//import android.content.res.AssetManager
//import android.content.res.Configuration
//import androidx.compose.foundation.layout.Arrangement
//import androidx.compose.foundation.layout.Column
//import androidx.compose.foundation.rememberScrollState
//import androidx.compose.foundation.verticalScroll
//import androidx.compose.material3.Button
//import androidx.compose.material3.ExperimentalMaterial3Api
//import androidx.compose.material3.MaterialTheme
//import androidx.compose.material3.Surface
//import androidx.compose.material3.Text
//import androidx.compose.runtime.Composable
//import androidx.compose.ui.Alignment
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.platform.LocalContext
//import androidx.compose.ui.tooling.preview.Preview
//import com.example.shortbooks.favorite.model.getFavorites
//import com.example.shortbooks.ui.theme.ShortBooksTheme
//
//@OptIn(ExperimentalMaterial3Api::class)
//@Composable
//fun FavoriteText(id: Int) {
//
// val context = LocalContext.current
// val assetManager: AssetManager = context.assets
//
//
// val favorite = getFavorites()[id]
// val textContent: String = assetManager.open(favorite.text).bufferedReader().use { it.readText() }
// Column(
// verticalArrangement = Arrangement.Center,
// horizontalAlignment = Alignment.CenterHorizontally
// ) {
// Button(onClick = { }) {
// Text(text = "Удалить из избранного")
// }
// Text(text = textContent, modifier = Modifier.verticalScroll(rememberScrollState()))
// }
//}
//
//@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
//@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
//@Composable
//fun BookTextPreview() {
// ShortBooksTheme {
// Surface(
// color = MaterialTheme.colorScheme.background
// ) {
// FavoriteText(id = 0)
// }
// }
//}

View File

@ -3,8 +3,10 @@ package com.example.shortbooks.favorite.dao
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Delete import androidx.room.Delete
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import androidx.room.Update import androidx.room.Update
import com.example.shortbooks.book.model.Book
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import com.example.shortbooks.favorite.model.UserBookCrossRef import com.example.shortbooks.favorite.model.UserBookCrossRef
import com.example.shortbooks.favorite.model.UserWithBooks import com.example.shortbooks.favorite.model.UserWithBooks
@ -14,10 +16,10 @@ interface UserBookDao {
@Query("select * from user_books") @Query("select * from user_books")
fun getAll(): Flow<List<UserBookCrossRef>> fun getAll(): Flow<List<UserBookCrossRef>>
@Query("select * from users where user_uid==:uid") @Query("select * from users where user_uid=:uid")
suspend fun getByUid(uid: Int): UserWithBooks suspend fun getByUid(uid: Int): UserWithBooks
@Insert @Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(userBookCrossRef: UserBookCrossRef) suspend fun insert(userBookCrossRef: UserBookCrossRef)
@Update @Update

View File

@ -1,5 +1,6 @@
package com.example.shortbooks.favorite.model package com.example.shortbooks.favorite.model
import androidx.room.ColumnInfo
import androidx.room.Entity import androidx.room.Entity

View File

@ -70,16 +70,8 @@ fun Navhost(
modifier.padding(innerPadding) modifier.padding(innerPadding)
) { ) {
composable(Screen.BookList.route) { BookList(navController) } composable(Screen.BookList.route) { BookList(navController) }
composable(Screen.FavoriteList.route, composable(Screen.FavoriteList.route) { FavoriteList(navController,1) }
arguments = listOf(navArgument("id") { type = NavType.IntType })) composable(Screen.UserInfo.route){ UserInfo(1)}
{ backStackEntry ->
backStackEntry.arguments?.let { FavoriteList(navController,it.getInt("id")) }
}
composable(Screen.UserInfo.route,
arguments = listOf(navArgument("id") { type = NavType.IntType }))
{ backStackEntry ->
backStackEntry.arguments?.let { UserInfo(it.getInt("id")) }
}
composable( composable(
Screen.BookText.route, Screen.BookText.route,
arguments = listOf(navArgument("id") { type = NavType.IntType }) arguments = listOf(navArgument("id") { type = NavType.IntType })

View File

@ -20,7 +20,6 @@ interface UserDao {
@Update @Update
suspend fun update(user: User) suspend fun update(user: User)
@Delete @Delete
suspend fun delete(user: User) suspend fun delete(user: User)
} }