kotlin
import android.app.Application
import androidx.room.Room
import androidx.work.WorkManager
class WasteScheduleApp : Application() {
lateinit var database: WasteDatabase
lateinit var scheduleRepository: ScheduleRepository
override fun onCreate() {
super.onCreate()
database = Room.databaseBuilder(
applicationContext,
WasteDatabase::class.java,
"waste_schedule_db"
).build()
scheduleRepository = ScheduleRepository(database.scheduleDao())
}
}
data class WasteCollection(
val date: LocalDate,
val category: WasteType,
val location: String
)
enum class WasteType {
MIXED, BIO, PLASTIC_METAL, GLASS, PAPER, ASH, LARGE_ITEMS
}
@Entity(tableName = "schedules")
data class ScheduleEntity(
@PrimaryKey val id: Int,
val date: LocalDate,
val type: WasteType,
val location: String
)
@Dao
interface ScheduleDao {
@Query("SELECT * FROM schedules WHERE location = :location")
fun getScheduleForLocation(location: String): List<ScheduleEntity>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertSchedules(schedules: List<ScheduleEntity>)
}
class ScheduleRepository(private val scheduleDao: ScheduleDao) {
fun loadScheduleFromPDF(pdfPath: String, location: String) {
// Logika parsowania PDF
val parsedSchedules = PdfParser.parse(pdfPath, location)
scheduleDao.insertSchedules(parsedSchedules)
}
fun getUpcomingCollections(location: String): List<WasteCollection> {
return scheduleDao.getScheduleForLocation(location)
.filter { it.date >= LocalDate.now() }
.map {
WasteCollection(it.date, it.type, it.location)
}
}
}
class NotificationService {
fun scheduleReminder(
collection: WasteCollection,
daysBefore: Int,
timeOfDay: LocalTime
) {
val notificationTime = collection.date.minusDays(daysBefore)
.atTime(timeOfDay)
// Konfiguracja powiadomienia systemowego
WorkManager.getInstance().scheduleNotification(
collection,
notificationTime
)
}
}
@Composable
fun WasteScheduleScreen(
viewModel: WasteScheduleViewModel
) {
var selectedLocation by remember { mutableStateOf("Wójtostwo") }
var reminderDays by remember { mutableStateOf(1) }
var reminderTime by remember { mutableStateOf(LocalTime.of(18, 0)) }
Column {
LocationSelector(
currentLocation = selectedLocation,
onLocationChanged = { selectedLocation = it }
)
UpcomingCollectionsList(
collections = viewModel.getUpcomingCollections(selectedLocation)
)
ReminderSettings(
daysBefore = reminderDays,
timeOfDay = reminderTime,
onReminderConfigChanged = { days, time ->
reminderDays = days
reminderTime = time
}
)
}
}
Uwaga: Kod jest szkicem koncepcyjnym. Wymaga dopracowania, obsługi błędów i pełnej implementacji komponentów takich jak PdfParser.