Lab 05: add common folder

This commit is contained in:
abazov73 2023-12-05 23:05:54 +04:00
parent c40d14e9b4
commit 80318e7d8f
16 changed files with 21 additions and 128 deletions

View File

@ -1,8 +1,8 @@
package com.example.mobile_labs package com.example.mobile_labs
import android.app.Application import android.app.Application
import com.example.mobile_labs.database.AppContainer import com.example.mobile_labs.common.AppContainer
import com.example.mobile_labs.database.AppDataContainer import com.example.mobile_labs.common.AppDataContainer
class TheatreApplication : Application() { class TheatreApplication : Application() {
lateinit var container: AppContainer lateinit var container: AppContainer

View File

@ -1,12 +1,11 @@
package com.example.mobile_labs.database package com.example.mobile_labs.common
import android.content.Context import android.content.Context
import com.example.mobile_labs.database.event.repository.EventRepository import com.example.mobile_labs.database.event.repository.EventRepository
import com.example.mobile_labs.database.event.repository.OfflineEventRepository import com.example.mobile_labs.database.event.repository.OfflineEventRepository
import com.example.mobile_labs.database.performance.repository.OfflinePerformanceRepository import com.example.mobile_labs.database.performance.repository.OfflinePerformanceRepository
import com.example.mobile_labs.database.performance.repository.PerformanceRepository
import com.example.mobile_labs.database.person.repository.OfflinePersonRepository import com.example.mobile_labs.database.person.repository.OfflinePersonRepository
import com.example.mobile_labs.database.person.repository.PersonRepository import com.example.mobile_labs.database.AppDatabase
interface AppContainer { interface AppContainer {
val personRepository: PersonRepository val personRepository: PersonRepository

View File

@ -1,4 +1,4 @@
package com.example.mobile_labs.ui package com.example.mobile_labs.common
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.createSavedStateHandle import androidx.lifecycle.createSavedStateHandle

View File

@ -1,4 +1,4 @@
package com.example.mobile_labs.database.performance.repository package com.example.mobile_labs.common
import androidx.paging.PagingData import androidx.paging.PagingData
import com.example.mobile_labs.database.performance.model.Performance import com.example.mobile_labs.database.performance.model.Performance

View File

@ -1,4 +1,4 @@
package com.example.mobile_labs.database.person.repository package com.example.mobile_labs.common
import androidx.paging.PagingData import androidx.paging.PagingData
import com.example.mobile_labs.database.person.model.Person import com.example.mobile_labs.database.person.model.Person

View File

@ -3,13 +3,11 @@ package com.example.mobile_labs.database.event.repository
import androidx.paging.Pager import androidx.paging.Pager
import androidx.paging.PagingConfig import androidx.paging.PagingConfig
import androidx.paging.PagingData import androidx.paging.PagingData
import com.example.mobile_labs.database.AppDataContainer import com.example.mobile_labs.common.AppDataContainer
import com.example.mobile_labs.database.event.dao.EventDao import com.example.mobile_labs.database.event.dao.EventDao
import com.example.mobile_labs.database.event.model.Event import com.example.mobile_labs.database.event.model.Event
import com.example.mobile_labs.database.event.model.EventWithPerformance import com.example.mobile_labs.database.event.model.EventWithPerformance
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import java.time.LocalDate
import java.time.format.DateTimeFormatter
class OfflineEventRepository(private val eventDao: EventDao) : EventRepository { class OfflineEventRepository(private val eventDao: EventDao) : EventRepository {
override fun getAll(): Flow<List<Event>> = eventDao.getAll(); override fun getAll(): Flow<List<Event>> = eventDao.getAll();

View File

@ -3,13 +3,15 @@ package com.example.mobile_labs.database.performance.repository
import androidx.paging.Pager import androidx.paging.Pager
import androidx.paging.PagingConfig import androidx.paging.PagingConfig
import androidx.paging.PagingData import androidx.paging.PagingData
import com.example.mobile_labs.database.AppDataContainer import com.example.mobile_labs.common.PerformanceRepository
import com.example.mobile_labs.common.AppDataContainer
import com.example.mobile_labs.database.performance.dao.PerformanceDao import com.example.mobile_labs.database.performance.dao.PerformanceDao
import com.example.mobile_labs.database.performance.model.Performance import com.example.mobile_labs.database.performance.model.Performance
import com.example.mobile_labs.database.performance.model.PerformanceWithPeople import com.example.mobile_labs.database.performance.model.PerformanceWithPeople
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
class OfflinePerformanceRepository(private val performanceDao: PerformanceDao) : PerformanceRepository { class OfflinePerformanceRepository(private val performanceDao: PerformanceDao) :
PerformanceRepository {
override fun getAllPerformances(): Flow<PagingData<Performance>> = Pager( override fun getAllPerformances(): Flow<PagingData<Performance>> = Pager(
config = PagingConfig( config = PagingConfig(
pageSize = AppDataContainer.LIMIT, pageSize = AppDataContainer.LIMIT,

View File

@ -3,8 +3,8 @@ package com.example.mobile_labs.database.person.repository
import androidx.paging.Pager import androidx.paging.Pager
import androidx.paging.PagingConfig import androidx.paging.PagingConfig
import androidx.paging.PagingData import androidx.paging.PagingData
import com.example.mobile_labs.database.AppContainer import com.example.mobile_labs.common.PersonRepository
import com.example.mobile_labs.database.AppDataContainer import com.example.mobile_labs.common.AppDataContainer
import com.example.mobile_labs.database.person.dao.PersonDao import com.example.mobile_labs.database.person.dao.PersonDao
import com.example.mobile_labs.database.person.model.Person import com.example.mobile_labs.database.person.model.Person
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow

View File

@ -2,15 +2,9 @@ package com.example.mobile_labs.ui.event.list
import android.content.res.Configuration import android.content.res.Configuration
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.Card import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults import androidx.compose.material3.CardDefaults
@ -19,16 +13,8 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
@ -42,19 +28,11 @@ import androidx.paging.compose.itemContentType
import androidx.paging.compose.itemKey import androidx.paging.compose.itemKey
import coil.compose.AsyncImage import coil.compose.AsyncImage
import com.example.mobile_labs.R import com.example.mobile_labs.R
import com.example.mobile_labs.database.AppDatabase
import com.example.mobile_labs.database.event.model.Event
import com.example.mobile_labs.database.event.model.EventWithPerformance import com.example.mobile_labs.database.event.model.EventWithPerformance
import com.example.mobile_labs.database.performance.model.Performance import com.example.mobile_labs.common.AppViewModelProvider
import com.example.mobile_labs.database.person.model.Person
import com.example.mobile_labs.ui.AppViewModelProvider
import com.example.mobile_labs.ui.navigation.Screen import com.example.mobile_labs.ui.navigation.Screen
import com.example.mobile_labs.ui.person.list.PeopleListViewModel
import com.example.mobile_labs.ui.theme.Mobile_LabsTheme import com.example.mobile_labs.ui.theme.Mobile_LabsTheme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.withContext
import java.time.LocalDate
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
@Composable @Composable

View File

@ -1,17 +1,10 @@
package com.example.mobile_labs.ui.event.list package com.example.mobile_labs.ui.event.list
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData import androidx.paging.PagingData
import com.example.mobile_labs.database.AppDataContainer
import com.example.mobile_labs.database.event.repository.EventRepository import com.example.mobile_labs.database.event.repository.EventRepository
import com.example.mobile_labs.database.event.model.Event
import com.example.mobile_labs.database.event.model.EventWithPerformance import com.example.mobile_labs.database.event.model.EventWithPerformance
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
class EventListViewModel( class EventListViewModel(
private val eventRepository: EventRepository private val eventRepository: EventRepository

View File

@ -1,17 +1,10 @@
package com.example.mobile_labs.ui.performance.list package com.example.mobile_labs.ui.performance.list
import com.example.mobile_labs.ui.event.list.EventListViewModel
import android.content.res.Configuration import android.content.res.Configuration
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.Card import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults import androidx.compose.material3.CardDefaults
@ -20,16 +13,8 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
@ -43,21 +28,11 @@ import androidx.paging.compose.itemContentType
import androidx.paging.compose.itemKey import androidx.paging.compose.itemKey
import coil.compose.AsyncImage import coil.compose.AsyncImage
import com.example.mobile_labs.R import com.example.mobile_labs.R
import com.example.mobile_labs.database.AppDatabase
import com.example.mobile_labs.database.event.model.Event
import com.example.mobile_labs.database.event.model.EventWithPerformance
import com.example.mobile_labs.database.performance.model.Performance import com.example.mobile_labs.database.performance.model.Performance
import com.example.mobile_labs.database.person.model.Person import com.example.mobile_labs.common.AppViewModelProvider
import com.example.mobile_labs.ui.AppViewModelProvider
import com.example.mobile_labs.ui.navigation.Screen import com.example.mobile_labs.ui.navigation.Screen
import com.example.mobile_labs.ui.person.list.PeopleList
import com.example.mobile_labs.ui.person.list.PeopleListViewModel
import com.example.mobile_labs.ui.theme.Mobile_LabsTheme import com.example.mobile_labs.ui.theme.Mobile_LabsTheme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.withContext
import java.time.LocalDate
import java.time.format.DateTimeFormatter
@Composable @Composable
fun PerformanceList( fun PerformanceList(

View File

@ -1,17 +1,10 @@
package com.example.mobile_labs.ui.performance.list package com.example.mobile_labs.ui.performance.list
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData import androidx.paging.PagingData
import com.example.mobile_labs.database.AppDataContainer
import com.example.mobile_labs.database.performance.model.Performance import com.example.mobile_labs.database.performance.model.Performance
import com.example.mobile_labs.database.performance.repository.PerformanceRepository import com.example.mobile_labs.common.PerformanceRepository
import com.example.mobile_labs.database.person.model.Person
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
class PerformanceListViewModel( class PerformanceListViewModel(
private val performanceRepository: PerformanceRepository private val performanceRepository: PerformanceRepository

View File

@ -4,35 +4,24 @@ import android.content.res.Configuration
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview 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.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import coil.compose.AsyncImage import coil.compose.AsyncImage
import com.example.mobile_labs.R import com.example.mobile_labs.R
import com.example.mobile_labs.database.AppDatabase import com.example.mobile_labs.common.AppViewModelProvider
import com.example.mobile_labs.database.performance.model.PerformanceWithPeople
import com.example.mobile_labs.ui.AppViewModelProvider
import com.example.mobile_labs.ui.theme.Mobile_LabsTheme import com.example.mobile_labs.ui.theme.Mobile_LabsTheme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable

View File

@ -6,9 +6,8 @@ import androidx.compose.runtime.setValue
import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.example.mobile_labs.database.performance.model.Performance
import com.example.mobile_labs.database.performance.model.PerformanceWithPeople import com.example.mobile_labs.database.performance.model.PerformanceWithPeople
import com.example.mobile_labs.database.performance.repository.PerformanceRepository import com.example.mobile_labs.common.PerformanceRepository
import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch import kotlinx.coroutines.launch

View File

@ -5,42 +5,22 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
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.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Card import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import androidx.paging.PagingData import androidx.paging.PagingData
import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems
@ -48,17 +28,10 @@ import androidx.paging.compose.itemContentType
import androidx.paging.compose.itemKey import androidx.paging.compose.itemKey
import coil.compose.AsyncImage import coil.compose.AsyncImage
import com.example.mobile_labs.R import com.example.mobile_labs.R
import com.example.mobile_labs.ui.navigation.Screen
import com.example.mobile_labs.database.AppDatabase
import com.example.mobile_labs.database.event.model.EventWithPerformance
import com.example.mobile_labs.database.person.model.Person import com.example.mobile_labs.database.person.model.Person
import com.example.mobile_labs.ui.AppViewModelProvider import com.example.mobile_labs.common.AppViewModelProvider
import com.example.mobile_labs.ui.theme.Mobile_LabsTheme import com.example.mobile_labs.ui.theme.Mobile_LabsTheme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.withContext
import java.time.LocalDate
import java.time.format.DateTimeFormatter
@Composable @Composable
fun PeopleList( fun PeopleList(

View File

@ -1,16 +1,10 @@
package com.example.mobile_labs.ui.person.list package com.example.mobile_labs.ui.person.list
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData import androidx.paging.PagingData
import com.example.mobile_labs.database.AppDataContainer
import com.example.mobile_labs.database.person.model.Person import com.example.mobile_labs.database.person.model.Person
import com.example.mobile_labs.database.person.repository.PersonRepository import com.example.mobile_labs.common.PersonRepository
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
class PeopleListViewModel( class PeopleListViewModel(
private val personRepository: PersonRepository private val personRepository: PersonRepository