Не работает
This commit is contained in:
parent
31b936fe0e
commit
1e3fcaa50f
41
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
41
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
@ -15,15 +15,24 @@ import androidx.navigation.NavHostController
|
|||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import com.example.mobileapp.components.NavBar
|
import com.example.mobileapp.components.NavBar
|
||||||
|
import com.example.mobileapp.database.MobileAppDataBase
|
||||||
import com.example.mobileapp.entities.Mail
|
import com.example.mobileapp.entities.Mail
|
||||||
import com.example.mobileapp.entities.MailSingleton
|
import com.example.mobileapp.entities.MailSingleton
|
||||||
import com.example.mobileapp.entities.Story
|
import com.example.mobileapp.entities.Story
|
||||||
import com.example.mobileapp.entities.StorySingleton
|
import com.example.mobileapp.entities.StorySingleton
|
||||||
import com.example.mobileapp.ui.theme.MobileAppTheme
|
import com.example.mobileapp.ui.theme.MobileAppTheme
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
|
val database by lazy { MobileAppDataBase.getInstance(this) }
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
this.deleteDatabase("mobileApp.db")
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
MobileAppDataBase.initialDataBase()
|
||||||
|
}
|
||||||
setContent {
|
setContent {
|
||||||
MobileAppTheme {
|
MobileAppTheme {
|
||||||
// A surface container using the 'background' color from the theme
|
// A surface container using the 'background' color from the theme
|
||||||
@ -32,7 +41,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
color = MaterialTheme.colorScheme.background
|
color = MaterialTheme.colorScheme.background
|
||||||
) {
|
) {
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
val mailSingleton = MailSingleton()
|
/*val mailSingleton = MailSingleton()
|
||||||
mailSingleton.addMail(Mail(0, 0, "Дзюнзи Ито", "Выложил новый"))
|
mailSingleton.addMail(Mail(0, 0, "Дзюнзи Ито", "Выложил новый"))
|
||||||
mailSingleton.addMail(Mail(1, 1, "Стивен Кинг", "Меня отменили в Твиттере"))
|
mailSingleton.addMail(Mail(1, 1, "Стивен Кинг", "Меня отменили в Твиттере"))
|
||||||
mailSingleton.addMail(Mail(0, 0, "Дзюнзи Ито", "Выложил новый"))
|
mailSingleton.addMail(Mail(0, 0, "Дзюнзи Ито", "Выложил новый"))
|
||||||
@ -46,7 +55,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
storySingleton.addStory(Story(0, "Чужак", "Знаменитая книга стивена кинга", R.drawable.king))
|
storySingleton.addStory(Story(0, "Чужак", "Знаменитая книга стивена кинга", R.drawable.king))
|
||||||
storySingleton.addStory(Story(1, "Переулок", "История ужасов от Дзюнзи Ито", R.drawable.dzun))
|
storySingleton.addStory(Story(1, "Переулок", "История ужасов от Дзюнзи Ито", R.drawable.dzun))
|
||||||
storySingleton.addStory(Story(2, "Чужак", "Знаменитая книга стивена кинга", R.drawable.king))
|
storySingleton.addStory(Story(2, "Чужак", "Знаменитая книга стивена кинга", R.drawable.king))
|
||||||
storySingleton.addStory(Story(3, "Переулок", "История ужасов от Дзюнзи Ито", R.drawable.dzun))
|
storySingleton.addStory(Story(3, "Переулок", "История ужасов от Дзюнзи Ито", R.drawable.dzun))*/
|
||||||
|
|
||||||
NavBar(navController = navController)
|
NavBar(navController = navController)
|
||||||
}
|
}
|
||||||
|
@ -33,13 +33,14 @@ val buttonHeightStandard = 72.dp
|
|||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun PlaceholderInputField(label: String, isSingleLine: Boolean){
|
fun PlaceholderInputField(label: String, isSingleLine: Boolean, onTextChanged: (String) -> Unit){
|
||||||
var text = remember { mutableStateOf("") }
|
var text = remember { mutableStateOf("") }
|
||||||
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = text.value,
|
value = text.value,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
text.value = it
|
text.value = it
|
||||||
|
onTextChanged(it)
|
||||||
},
|
},
|
||||||
placeholder = {
|
placeholder = {
|
||||||
Text(label)
|
Text(label)
|
||||||
@ -54,13 +55,14 @@ fun PlaceholderInputField(label: String, isSingleLine: Boolean){
|
|||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun PasswordInputField(label: String){
|
fun PasswordInputField(label: String, onPasswordChanged: (String) -> Unit){
|
||||||
var text = remember { mutableStateOf("") }
|
var text = remember { mutableStateOf("") }
|
||||||
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = text.value,
|
value = text.value,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
text.value = it
|
text.value = it
|
||||||
|
onPasswordChanged(it)
|
||||||
},
|
},
|
||||||
placeholder = {
|
placeholder = {
|
||||||
Text(label)
|
Text(label)
|
||||||
@ -159,7 +161,7 @@ fun ActiveButton(label: String, backgroundColor: Color, textColor: Color, onClic
|
|||||||
fun PlaceholderTextFieldPreview() {
|
fun PlaceholderTextFieldPreview() {
|
||||||
MobileAppTheme {
|
MobileAppTheme {
|
||||||
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
|
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
|
||||||
PlaceholderInputField("Email", true)
|
PlaceholderInputField("Email", true, { })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,18 +27,16 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.asImageBitmap
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import com.example.mobileapp.R
|
import com.example.mobileapp.R
|
||||||
import com.example.mobileapp.entities.Mail
|
import com.example.mobileapp.database.entities.Mail
|
||||||
import com.example.mobileapp.entities.MailSingleton
|
import com.example.mobileapp.database.entities.Story
|
||||||
import com.example.mobileapp.entities.Story
|
|
||||||
import com.example.mobileapp.entities.StorySingleton
|
|
||||||
import com.example.mobileapp.ui.theme.BackgroundItem2
|
import com.example.mobileapp.ui.theme.BackgroundItem2
|
||||||
import com.example.mobileapp.ui.theme.ButtonColor1
|
import com.example.mobileapp.ui.theme.ButtonColor1
|
||||||
import com.example.mobileapp.ui.theme.ButtonColor2
|
import com.example.mobileapp.ui.theme.ButtonColor2
|
||||||
@ -92,7 +90,7 @@ fun StoryListItem(item: Story, navController: NavHostController){
|
|||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.Top
|
verticalAlignment = Alignment.Top
|
||||||
){
|
){
|
||||||
Image(painter = painterResource(id = item.cover),
|
Image(bitmap = item.cover.asImageBitmap(),
|
||||||
contentDescription = item.description,
|
contentDescription = item.description,
|
||||||
contentScale = ContentScale.Crop,
|
contentScale = ContentScale.Crop,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -117,8 +115,12 @@ fun StoryListItem(item: Story, navController: NavHostController){
|
|||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.End
|
horizontalArrangement = Arrangement.End
|
||||||
){
|
){
|
||||||
DataListItemButton("Изменить", ButtonColor2, Color.White, onClickAction = { navController.navigate("editstory") })
|
DataListItemButton("Изменить", ButtonColor2, Color.White, onClickAction = {
|
||||||
DataListItemButton("Удалить", Color.Red, Color.White, onClickAction = { })
|
navController.navigate("editstory/" + item.id)
|
||||||
|
})
|
||||||
|
DataListItemButton("Удалить", Color.Red, Color.White, onClickAction = {
|
||||||
|
navController.navigate("story")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,7 +182,7 @@ fun MailListItem(item: Mail){
|
|||||||
modifier = Modifier.padding(8.dp)
|
modifier = Modifier.padding(8.dp)
|
||||||
){
|
){
|
||||||
Text(
|
Text(
|
||||||
text = item.username,
|
text = "item.username",
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
fontWeight = FontWeight.Bold)
|
fontWeight = FontWeight.Bold)
|
||||||
Text(text = item.message)
|
Text(text = item.message)
|
||||||
|
@ -42,7 +42,7 @@ import com.example.mobileapp.screens.SettingsScreen
|
|||||||
|
|
||||||
val navBarItems = listOf(
|
val navBarItems = listOf(
|
||||||
NavBarItem(route = "main", label = "Главная", icon = R.drawable.home),
|
NavBarItem(route = "main", label = "Главная", icon = R.drawable.home),
|
||||||
NavBarItem(route = "listdata", label = "Создание", icon = R.drawable.edit),
|
NavBarItem(route = "story", label = "Создание", icon = R.drawable.edit),
|
||||||
NavBarItem(route = "mail", label = "Уведомления", icon = R.drawable.mail),
|
NavBarItem(route = "mail", label = "Уведомления", icon = R.drawable.mail),
|
||||||
NavBarItem(route = "settings", label = "Настройки", icon = R.drawable.settings),
|
NavBarItem(route = "settings", label = "Настройки", icon = R.drawable.settings),
|
||||||
)
|
)
|
||||||
@ -106,7 +106,7 @@ fun NavBar(navController: NavHostController) {
|
|||||||
MainScreen(navController = navController)
|
MainScreen(navController = navController)
|
||||||
bottomBarState.value = true
|
bottomBarState.value = true
|
||||||
}
|
}
|
||||||
composable("listdata"){
|
composable("story"){
|
||||||
ListDataScreen(navController = navController)
|
ListDataScreen(navController = navController)
|
||||||
bottomBarState.value = true
|
bottomBarState.value = true
|
||||||
}
|
}
|
||||||
@ -118,12 +118,14 @@ fun NavBar(navController: NavHostController) {
|
|||||||
SettingsScreen(navController = navController)
|
SettingsScreen(navController = navController)
|
||||||
bottomBarState.value = true
|
bottomBarState.value = true
|
||||||
}
|
}
|
||||||
composable("editstory"){
|
composable("editstory/{storyId}"){ navBackStackEntry ->
|
||||||
EditStoryScreen(navController = navController)
|
val storyId = navBackStackEntry.arguments?.getInt("storyId")
|
||||||
|
EditStoryScreen(navController = navController, storyId = storyId)
|
||||||
bottomBarState.value = false
|
bottomBarState.value = false
|
||||||
}
|
}
|
||||||
composable("editmail"){
|
composable("editmail/{mailId}"){ navBackStackEntry ->
|
||||||
EditMailScreen(navController = navController)
|
val mailId = navBackStackEntry.arguments?.getInt("mailId")
|
||||||
|
EditMailScreen(navController = navController, mailId = mailId)
|
||||||
bottomBarState.value = false
|
bottomBarState.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package com.example.mobileapp.database
|
package com.example.mobileapp.database
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
import androidx.room.Database
|
import androidx.room.Database
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.room.TypeConverters
|
import androidx.room.TypeConverters
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
import com.example.mobileapp.R
|
||||||
import com.example.mobileapp.database.dao.MailDao
|
import com.example.mobileapp.database.dao.MailDao
|
||||||
import com.example.mobileapp.database.dao.StoryDao
|
import com.example.mobileapp.database.dao.StoryDao
|
||||||
import com.example.mobileapp.database.dao.UserDao
|
import com.example.mobileapp.database.dao.UserDao
|
||||||
@ -17,7 +19,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Database(entities = [User::class, Story::class, Mail::class], version = 1, exportSchema = false)
|
@Database(entities = [User::class, Story::class, Mail::class], version = 4)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class MobileAppDataBase : RoomDatabase() {
|
abstract class MobileAppDataBase : RoomDatabase() {
|
||||||
abstract fun userDao(): UserDao
|
abstract fun userDao(): UserDao
|
||||||
@ -30,6 +32,24 @@ abstract class MobileAppDataBase : RoomDatabase() {
|
|||||||
@Volatile
|
@Volatile
|
||||||
private var INSTANCE: MobileAppDataBase? = null
|
private var INSTANCE: MobileAppDataBase? = null
|
||||||
|
|
||||||
|
suspend fun initialDataBase(){
|
||||||
|
INSTANCE?.let { database ->
|
||||||
|
val userDao = database.userDao()
|
||||||
|
userDao.insert(User(id = 1, login = "Дзюнзи Ито", password = "1234", email = "ito@gmail.com"))
|
||||||
|
userDao.insert(User(id = 2, login = "Стивен Кинг", password = "4321", email = "king@gmail.com"))
|
||||||
|
|
||||||
|
val storyDao = database.storyDao()
|
||||||
|
storyDao.insert(Story(title = "Переулок", description = "История ужасов от Дзюнзи Ито",
|
||||||
|
cover = BitmapFactory.decodeResource(null, R.drawable.dzun), userId = 1))
|
||||||
|
storyDao.insert(Story(title = "Чужак", description = "Знаменитая книга стивена кинга",
|
||||||
|
cover = BitmapFactory.decodeResource(null, R.drawable.king), userId = 2))
|
||||||
|
|
||||||
|
val mailDao = database.mailDao()
|
||||||
|
mailDao.insert(Mail(message = "Выложил новые страницы", userId = 1))
|
||||||
|
mailDao.insert(Mail(message = "Меня отменили в Твиттере", userId = 2))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getInstance(appContext: Context): MobileAppDataBase {
|
fun getInstance(appContext: Context): MobileAppDataBase {
|
||||||
return INSTANCE ?: synchronized(this) {
|
return INSTANCE ?: synchronized(this) {
|
||||||
Room.databaseBuilder(
|
Room.databaseBuilder(
|
||||||
@ -41,10 +61,11 @@ abstract class MobileAppDataBase : RoomDatabase() {
|
|||||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||||
super.onCreate(db)
|
super.onCreate(db)
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
//populateDatabase()
|
initialDataBase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.fallbackToDestructiveMigration()
|
||||||
.build()
|
.build()
|
||||||
.also { INSTANCE = it }
|
.also { INSTANCE = it }
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,9 @@ interface StoryDao {
|
|||||||
@Query("select * from stories where stories.id = :id")
|
@Query("select * from stories where stories.id = :id")
|
||||||
fun getById(id: Int): Story?
|
fun getById(id: Int): Story?
|
||||||
|
|
||||||
|
@Query("select * from stories where stories.user_id = :userId")
|
||||||
|
fun getByUserId(userId: Int): Flow<List<Story>>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
suspend fun insert(story: Story)
|
suspend fun insert(story: Story)
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ import android.graphics.Bitmap
|
|||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import androidx.room.TypeConverter
|
import androidx.room.TypeConverter
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
class Converters {
|
class Converters {
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
|
@ -4,6 +4,8 @@ import androidx.room.ColumnInfo
|
|||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.ForeignKey
|
import androidx.room.ForeignKey
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
import java.util.Calendar
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "mails",
|
tableName = "mails",
|
||||||
@ -22,6 +24,8 @@ data class Mail(
|
|||||||
var id: Int? = null,
|
var id: Int? = null,
|
||||||
@ColumnInfo(name = "message")
|
@ColumnInfo(name = "message")
|
||||||
val message: String,
|
val message: String,
|
||||||
|
@ColumnInfo(name = "postdate")
|
||||||
|
val postdate: Long? = Date().time,
|
||||||
@ColumnInfo(name="user_id")
|
@ColumnInfo(name="user_id")
|
||||||
val userId: Int
|
val userId: Int
|
||||||
){
|
){
|
||||||
|
@ -5,6 +5,8 @@ import androidx.room.ColumnInfo
|
|||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.ForeignKey
|
import androidx.room.ForeignKey
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
import java.util.Calendar
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "stories",
|
tableName = "stories",
|
||||||
@ -27,6 +29,8 @@ data class Story(
|
|||||||
val description: String,
|
val description: String,
|
||||||
@ColumnInfo(name = "cover")
|
@ColumnInfo(name = "cover")
|
||||||
val cover: Bitmap,
|
val cover: Bitmap,
|
||||||
|
@ColumnInfo(name = "postdate")
|
||||||
|
val postdate: Long? = Date().time,
|
||||||
@ColumnInfo(name="user_id")
|
@ColumnInfo(name="user_id")
|
||||||
val userId: Int
|
val userId: Int
|
||||||
){
|
){
|
||||||
|
@ -37,8 +37,8 @@ fun Authorization(navController: NavHostController){
|
|||||||
.size(512.dp)
|
.size(512.dp)
|
||||||
.padding(8.dp)
|
.padding(8.dp)
|
||||||
.align(Alignment.CenterHorizontally))
|
.align(Alignment.CenterHorizontally))
|
||||||
PlaceholderInputField(label = "Логин", true)
|
PlaceholderInputField(label = "Логин", true, onTextChanged = {})
|
||||||
PasswordInputField(label = "Пароль")
|
PasswordInputField(label = "Пароль", onPasswordChanged = {})
|
||||||
NavigationButton(navController = navController, destination = "main", label = "Вход",
|
NavigationButton(navController = navController, destination = "main", label = "Вход",
|
||||||
backgroundColor = ButtonColor2, textColor = Color.White)
|
backgroundColor = ButtonColor2, textColor = Color.White)
|
||||||
NavigationButton(navController = navController, destination = "registration", label = "Регистрация",
|
NavigationButton(navController = navController, destination = "registration", label = "Регистрация",
|
||||||
|
@ -7,10 +7,15 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
@ -19,11 +24,26 @@ import com.example.mobileapp.components.ActiveButton
|
|||||||
import com.example.mobileapp.components.NavigationButton
|
import com.example.mobileapp.components.NavigationButton
|
||||||
import com.example.mobileapp.components.PasswordInputField
|
import com.example.mobileapp.components.PasswordInputField
|
||||||
import com.example.mobileapp.components.PlaceholderInputField
|
import com.example.mobileapp.components.PlaceholderInputField
|
||||||
|
import com.example.mobileapp.database.MobileAppDataBase
|
||||||
|
import com.example.mobileapp.database.entities.Story
|
||||||
import com.example.mobileapp.ui.theme.ButtonColor1
|
import com.example.mobileapp.ui.theme.ButtonColor1
|
||||||
import com.example.mobileapp.ui.theme.ButtonColor2
|
import com.example.mobileapp.ui.theme.ButtonColor2
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun EditStoryScreen(navController: NavHostController) {
|
fun EditStoryScreen(navController: NavHostController, storyId: Int? = null) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val story = remember { mutableStateOf<Story?>(null) }
|
||||||
|
|
||||||
|
storyId?.let{
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
story.value = MobileAppDataBase.getInstance(context).storyDao().getById(storyId!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
@ -38,17 +58,21 @@ fun EditStoryScreen(navController: NavHostController) {
|
|||||||
.size(384.dp)
|
.size(384.dp)
|
||||||
.padding(8.dp)
|
.padding(8.dp)
|
||||||
.align(Alignment.CenterHorizontally))
|
.align(Alignment.CenterHorizontally))
|
||||||
PlaceholderInputField(label = "Название", true)
|
|
||||||
ActiveButton(label = "Выбрать обложку", backgroundColor = ButtonColor1, textColor = Color.Black, onClickAction = {})
|
ActiveButton(label = "Выбрать обложку", backgroundColor = ButtonColor1, textColor = Color.Black, onClickAction = {})
|
||||||
PlaceholderInputField(label = "Описание", true)
|
PlaceholderInputField(label = "Название", true, onTextChanged = { newName ->
|
||||||
|
|
||||||
|
})
|
||||||
|
PlaceholderInputField(label = "Описание", true, onTextChanged = { newDescription ->
|
||||||
|
|
||||||
|
})
|
||||||
ActiveButton(label = "Сохранить", backgroundColor = ButtonColor1, textColor = Color.Black, onClickAction = {})
|
ActiveButton(label = "Сохранить", backgroundColor = ButtonColor1, textColor = Color.Black, onClickAction = {})
|
||||||
NavigationButton(navController = navController, destination = "listdata", label = "Назад",
|
NavigationButton(navController = navController, destination = "story", label = "Назад",
|
||||||
backgroundColor = ButtonColor2, textColor = Color.White)
|
backgroundColor = ButtonColor2, textColor = Color.White)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun EditMailScreen(navController: NavHostController) {
|
fun EditMailScreen(navController: NavHostController, mailId: Int? = null) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
@ -63,7 +87,7 @@ fun EditMailScreen(navController: NavHostController) {
|
|||||||
.size(512.dp)
|
.size(512.dp)
|
||||||
.padding(8.dp)
|
.padding(8.dp)
|
||||||
.align(Alignment.CenterHorizontally))
|
.align(Alignment.CenterHorizontally))
|
||||||
PlaceholderInputField(label = "Текс поста", false)
|
PlaceholderInputField(label = "Текс поста", false, onTextChanged = {})
|
||||||
ActiveButton(label = "Сохранить", backgroundColor = ButtonColor1, textColor = Color.Black, onClickAction = {})
|
ActiveButton(label = "Сохранить", backgroundColor = ButtonColor1, textColor = Color.Black, onClickAction = {})
|
||||||
NavigationButton(navController = navController, destination = "mail", label = "Назад",
|
NavigationButton(navController = navController, destination = "mail", label = "Назад",
|
||||||
backgroundColor = ButtonColor2, textColor = Color.White)
|
backgroundColor = ButtonColor2, textColor = Color.White)
|
||||||
|
@ -8,22 +8,42 @@ import androidx.compose.foundation.layout.fillMaxHeight
|
|||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import com.example.mobileapp.components.DataListScroll
|
import com.example.mobileapp.components.DataListScroll
|
||||||
import com.example.mobileapp.components.NavBar
|
import com.example.mobileapp.components.NavBar
|
||||||
|
import com.example.mobileapp.database.MobileAppDataBase
|
||||||
|
import com.example.mobileapp.database.entities.Story
|
||||||
import com.example.mobileapp.entities.StorySingleton
|
import com.example.mobileapp.entities.StorySingleton
|
||||||
import com.example.mobileapp.ui.theme.BackgroundItem1
|
import com.example.mobileapp.ui.theme.BackgroundItem1
|
||||||
import com.example.mobileapp.ui.theme.BackgroundItem2
|
import com.example.mobileapp.ui.theme.BackgroundItem2
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ListDataScreen(navController: NavHostController){
|
fun ListDataScreen(navController: NavHostController){
|
||||||
val storySingleton = StorySingleton()
|
|
||||||
|
val context = LocalContext.current
|
||||||
|
val stories = remember { mutableStateListOf<Story>() }
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
MobileAppDataBase.getInstance(context).storyDao().getAll().collect { data ->
|
||||||
|
stories.clear()
|
||||||
|
stories.addAll(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.background(BackgroundItem1)
|
.background(BackgroundItem1)
|
||||||
) {
|
) {
|
||||||
DataListScroll(navController, storySingleton.getStoryList())
|
DataListScroll(navController, stories)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,20 +4,39 @@ import androidx.compose.foundation.background
|
|||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import com.example.mobileapp.components.DataListScroll
|
import com.example.mobileapp.components.DataListScroll
|
||||||
import com.example.mobileapp.entities.MailSingleton
|
import com.example.mobileapp.database.MobileAppDataBase
|
||||||
|
import com.example.mobileapp.database.entities.Mail
|
||||||
import com.example.mobileapp.ui.theme.BackgroundItem1
|
import com.example.mobileapp.ui.theme.BackgroundItem1
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ListMailScreen(navController: NavHostController){
|
fun ListMailScreen(navController: NavHostController){
|
||||||
val mailSingleton = MailSingleton()
|
|
||||||
|
val context = LocalContext.current
|
||||||
|
val mails = remember { mutableStateListOf<Mail>() }
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
MobileAppDataBase.getInstance(context).mailDao().getAll().collect { data ->
|
||||||
|
mails.clear()
|
||||||
|
mails.addAll(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.background(BackgroundItem1)
|
.background(BackgroundItem1)
|
||||||
) {
|
) {
|
||||||
DataListScroll(navController, mailSingleton.getMailList())
|
DataListScroll(navController, mails)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -37,10 +37,10 @@ fun Registration(navController: NavHostController){
|
|||||||
.size(384.dp)
|
.size(384.dp)
|
||||||
.padding(8.dp)
|
.padding(8.dp)
|
||||||
.align(Alignment.CenterHorizontally))
|
.align(Alignment.CenterHorizontally))
|
||||||
PlaceholderInputField(label = "Логин", true)
|
PlaceholderInputField(label = "Логин", true, onTextChanged = {})
|
||||||
PlaceholderInputField(label = "Email", true)
|
PlaceholderInputField(label = "Email", true, onTextChanged = {})
|
||||||
PasswordInputField(label = "Пароль")
|
PasswordInputField(label = "Пароль", onPasswordChanged = {})
|
||||||
PasswordInputField(label = "Пароль ещё раз")
|
PasswordInputField(label = "Пароль ещё раз", onPasswordChanged = {})
|
||||||
NavigationButton(navController = navController, destination = "main",
|
NavigationButton(navController = navController, destination = "main",
|
||||||
label = "Зарегистрироваться", backgroundColor = ButtonColor2, textColor = Color.White)
|
label = "Зарегистрироваться", backgroundColor = ButtonColor2, textColor = Color.White)
|
||||||
NavigationButton(navController = navController, destination = "authorization",
|
NavigationButton(navController = navController, destination = "authorization",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user