ver 1.6 sprzatanie kodu
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Właścicielem tego kodu jest Bartłomiej Janik.
|
||||||
|
*/
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application)
|
alias(libs.plugins.android.application)
|
||||||
alias(libs.plugins.kotlin.compose)
|
alias(libs.plugins.kotlin.compose)
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Właścicielem tego kodu jest Bartłomiej Janik.
|
||||||
|
*/
|
||||||
|
|
||||||
package com.bartek.iwentaryzacja
|
package com.bartek.iwentaryzacja
|
||||||
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* Właścicielem tego kodu jest Bartłomiej Janik.
|
||||||
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
@@ -103,6 +105,9 @@ class InventoryViewModel : ViewModel() {
|
|||||||
|
|
||||||
data class UpdateInfo(val versionCode: Int)
|
data class UpdateInfo(val versionCode: Int)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wczytuje stan aplikacji (notatki i listę maszyn) z pamięci urządzenia (SharedPreferences).
|
||||||
|
*/
|
||||||
fun loadState(context: Context) {
|
fun loadState(context: Context) {
|
||||||
val prefs = context.getSharedPreferences("inventory_prefs", Context.MODE_PRIVATE)
|
val prefs = context.getSharedPreferences("inventory_prefs", Context.MODE_PRIVATE)
|
||||||
_notes.value = prefs.getString("notes", "") ?: ""
|
_notes.value = prefs.getString("notes", "") ?: ""
|
||||||
@@ -133,6 +138,9 @@ class InventoryViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zapisuje bieżący stan aplikacji do pamięci urządzenia.
|
||||||
|
*/
|
||||||
private fun saveState(context: Context) {
|
private fun saveState(context: Context) {
|
||||||
val prefs = context.getSharedPreferences("inventory_prefs", Context.MODE_PRIVATE)
|
val prefs = context.getSharedPreferences("inventory_prefs", Context.MODE_PRIVATE)
|
||||||
val editor = prefs.edit()
|
val editor = prefs.edit()
|
||||||
@@ -185,6 +193,9 @@ class InventoryViewModel : ViewModel() {
|
|||||||
_filterMissing.value = !_filterMissing.value
|
_filterMissing.value = !_filterMissing.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sprawdza dostępność aktualizacji na serwerze zdalnym.
|
||||||
|
*/
|
||||||
fun checkForUpdates(context: Context) {
|
fun checkForUpdates(context: Context) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
@@ -248,62 +259,66 @@ class InventoryViewModel : ViewModel() {
|
|||||||
saveState(context)
|
saveState(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parser zoptymalizowany pod strukturę raportu z systemu
|
/**
|
||||||
|
* Parsuje plik Excel (.xls lub .xlsx) i wyodrębnia listę maszyn oraz nagłówki raportu.
|
||||||
|
*/
|
||||||
fun parseXlsFile(context: Context, inputStream: InputStream) {
|
fun parseXlsFile(context: Context, inputStream: InputStream) {
|
||||||
try {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
// WorkbookFactory automatycznie obsługuje zarówno .xls jak i .xlsx
|
|
||||||
val workbook = WorkbookFactory.create(inputStream)
|
|
||||||
val sheet = workbook.getSheetAt(0)
|
|
||||||
|
|
||||||
// Próba pobrania nazwy oddziału i daty z nagłówka (zazwyczaj wiersz 0 lub 1)
|
|
||||||
try {
|
try {
|
||||||
val headerRow = sheet.getRow(0)
|
// WorkbookFactory automatycznie obsługuje zarówno .xls jak i .xlsx
|
||||||
val branch = headerRow?.getCell(0)?.toString()?.trim() ?: ""
|
val workbook = WorkbookFactory.create(inputStream)
|
||||||
val date = headerRow?.getCell(4)?.toString()?.trim() ?: "" // Przykładowa kolumna dla daty
|
val sheet = workbook.getSheetAt(0)
|
||||||
|
|
||||||
// Usuwamy zbędny napis "raport:lista produktow" w różnych wariantach
|
// Próba pobrania nazwy oddziału i daty z nagłówka (wiersz 0)
|
||||||
val cleanedBranch = branch
|
try {
|
||||||
.replace(Regex("raport\\s*:", RegexOption.IGNORE_CASE), "")
|
val headerRow = sheet.getRow(0)
|
||||||
.replace(Regex("lista\\s*produktów", RegexOption.IGNORE_CASE), "")
|
val branch = headerRow?.getCell(0)?.toString()?.trim() ?: ""
|
||||||
.replace(Regex("lista\\s*produktow", RegexOption.IGNORE_CASE), "")
|
val date = headerRow?.getCell(4)?.toString()?.trim() ?: ""
|
||||||
.trim()
|
|
||||||
|
|
||||||
_branchName.value = cleanedBranch
|
// Usuwamy zbędny napis "raport:lista produktow" w różnych wariantach
|
||||||
_reportDate.value = date
|
val cleanedBranch = branch
|
||||||
|
.replace(Regex("raport\\s*:", RegexOption.IGNORE_CASE), "")
|
||||||
|
.replace(Regex("lista\\s*produktów", RegexOption.IGNORE_CASE), "")
|
||||||
|
.replace(Regex("lista\\s*produktow", RegexOption.IGNORE_CASE), "")
|
||||||
|
.trim()
|
||||||
|
|
||||||
|
_branchName.value = cleanedBranch
|
||||||
|
_reportDate.value = date
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
|
||||||
|
val parsedList = mutableListOf<Machine>()
|
||||||
|
|
||||||
|
// Dane maszyn zaczynają się zazwyczaj od wiersza indeks 2
|
||||||
|
for (rowIndex in 2..sheet.lastRowNum) {
|
||||||
|
val row = sheet.getRow(rowIndex) ?: continue
|
||||||
|
|
||||||
|
val category = row.getCell(1)?.toString()?.trim() ?: ""
|
||||||
|
val id = row.getCell(2)?.toString()?.trim() ?: ""
|
||||||
|
val name = row.getCell(3)?.toString()?.trim() ?: ""
|
||||||
|
val status = row.getCell(7)?.toString()?.trim() ?: ""
|
||||||
|
|
||||||
|
// Wczytujemy tylko, gdy pozycja ma nazwę i nr ewidencyjny
|
||||||
|
if (name.isNotEmpty() && id.isNotEmpty()) {
|
||||||
|
val isRented = status.contains("wypo", ignoreCase = true)
|
||||||
|
parsedList.add(
|
||||||
|
Machine(
|
||||||
|
id = id,
|
||||||
|
name = name,
|
||||||
|
category = category,
|
||||||
|
originalStatus = status,
|
||||||
|
isChecked = isRented // Automatycznie zaznaczamy wypożyczone
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_machines.value = parsedList
|
||||||
|
workbook.close()
|
||||||
|
saveState(context)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
val parsedList = mutableListOf<Machine>()
|
|
||||||
|
|
||||||
// Dane zaczynają się od wiersza indeks 2 (po 2 wierszach nagłówka)
|
|
||||||
for (rowIndex in 2..sheet.lastRowNum) {
|
|
||||||
val row = sheet.getRow(rowIndex) ?: continue
|
|
||||||
|
|
||||||
val category = row.getCell(1)?.toString()?.trim() ?: ""
|
|
||||||
val id = row.getCell(2)?.toString()?.trim() ?: ""
|
|
||||||
val name = row.getCell(3)?.toString()?.trim() ?: ""
|
|
||||||
val status = row.getCell(7)?.toString()?.trim() ?: ""
|
|
||||||
|
|
||||||
// Wczytujemy tylko, gdy pozycja ma nazwę i nr ewidencyjny
|
|
||||||
if (name.isNotEmpty() && id.isNotEmpty()) {
|
|
||||||
val isRented = status.contains("wypo", ignoreCase = true)
|
|
||||||
parsedList.add(
|
|
||||||
Machine(
|
|
||||||
id = id,
|
|
||||||
name = name,
|
|
||||||
category = category,
|
|
||||||
originalStatus = status,
|
|
||||||
isChecked = isRented // Automatycznie zaznaczamy wypożyczone
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_machines.value = parsedList
|
|
||||||
workbook.close()
|
|
||||||
saveState(context)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -346,6 +361,9 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ekran startowy aplikacji wyświetlany przez krótki czas po uruchomieniu.
|
||||||
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun SplashScreen() {
|
fun SplashScreen() {
|
||||||
Box(
|
Box(
|
||||||
@@ -381,6 +399,9 @@ fun SplashScreen() {
|
|||||||
// ==========================================
|
// ==========================================
|
||||||
// 4. EKRAN GŁÓWNY
|
// 4. EKRAN GŁÓWNY
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
/**
|
||||||
|
* Główny ekran aplikacji zarządzający listą maszyn i interfejsem użytkownika.
|
||||||
|
*/
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun InventoryScreen(viewModel: InventoryViewModel = viewModel()) {
|
fun InventoryScreen(viewModel: InventoryViewModel = viewModel()) {
|
||||||
@@ -698,6 +719,9 @@ fun InventoryScreen(viewModel: InventoryViewModel = viewModel()) {
|
|||||||
// ==========================================
|
// ==========================================
|
||||||
// 5. POJEDYNCZY ELEMENT LISTY
|
// 5. POJEDYNCZY ELEMENT LISTY
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
/**
|
||||||
|
* Komponent pojedynczego kafelka w górnym menu nawigacyjnym.
|
||||||
|
*/
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun DashboardTile(
|
fun DashboardTile(
|
||||||
@@ -733,6 +757,9 @@ fun DashboardTile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Okno dialogowe umożliwiające zbiorcze zaznaczanie maszyn na podstawie ich statusu.
|
||||||
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun StatusSelectionDialog(
|
fun StatusSelectionDialog(
|
||||||
statuses: List<String>,
|
statuses: List<String>,
|
||||||
@@ -790,6 +817,9 @@ fun StatusSelectionDialog(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Okno dialogowe notatnika do zapisywania uwag.
|
||||||
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun NotesDialog(
|
fun NotesDialog(
|
||||||
notes: String,
|
notes: String,
|
||||||
@@ -822,6 +852,9 @@ fun NotesDialog(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Niestandardowa klawiatura numeryczna do szybkiego filtrowania po numerach ID.
|
||||||
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun NumericKeyboard(
|
fun NumericKeyboard(
|
||||||
onDigitClick: (String) -> Unit,
|
onDigitClick: (String) -> Unit,
|
||||||
@@ -891,6 +924,9 @@ fun KeyButton(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Komponent pojedynczego elementu na liście maszyn.
|
||||||
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun MachineItem(
|
fun MachineItem(
|
||||||
machine: Machine,
|
machine: Machine,
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* Właścicielem tego kodu jest Bartłomiej Janik.
|
||||||
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
@@ -17,6 +19,9 @@ package com.bartek.iwentaryzacja.ui.theme
|
|||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Definicje kolorów używanych w motywie aplikacji.
|
||||||
|
*/
|
||||||
val Purple80 = Color(0xFFD0BCFF)
|
val Purple80 = Color(0xFFD0BCFF)
|
||||||
val PurpleGrey80 = Color(0xFFCCC2DC)
|
val PurpleGrey80 = Color(0xFFCCC2DC)
|
||||||
val Pink80 = Color(0xFFEFB8C8)
|
val Pink80 = Color(0xFFEFB8C8)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* Właścicielem tego kodu jest Bartłomiej Janik.
|
||||||
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
@@ -36,18 +38,11 @@ private val LightColorScheme = lightColorScheme(
|
|||||||
primary = Purple40,
|
primary = Purple40,
|
||||||
secondary = PurpleGrey40,
|
secondary = PurpleGrey40,
|
||||||
tertiary = Pink40
|
tertiary = Pink40
|
||||||
|
|
||||||
/* Other default colors to override
|
|
||||||
background = Color(0xFFFFFBFE),
|
|
||||||
surface = Color(0xFFFFFBFE),
|
|
||||||
onPrimary = Color.White,
|
|
||||||
onSecondary = Color.White,
|
|
||||||
onTertiary = Color.White,
|
|
||||||
onBackground = Color(0xFF1C1B1F),
|
|
||||||
onSurface = Color(0xFF1C1B1F),
|
|
||||||
*/
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Główny motyw aplikacji inwentARyzacja.
|
||||||
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun IwentARyzacjaTheme(
|
fun IwentARyzacjaTheme(
|
||||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* Właścicielem tego kodu jest Bartłomiej Janik.
|
||||||
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
@@ -21,7 +23,9 @@ import androidx.compose.ui.text.font.FontFamily
|
|||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
||||||
// Set of Material typography styles to start with
|
/**
|
||||||
|
* Definicje typografii dla interfejsu Compose.
|
||||||
|
*/
|
||||||
val Typography = Typography(
|
val Typography = Typography(
|
||||||
bodyLarge = TextStyle(
|
bodyLarge = TextStyle(
|
||||||
fontFamily = FontFamily.Default,
|
fontFamily = FontFamily.Default,
|
||||||
@@ -30,20 +34,4 @@ val Typography = Typography(
|
|||||||
lineHeight = 24.sp,
|
lineHeight = 24.sp,
|
||||||
letterSpacing = 0.5.sp
|
letterSpacing = 0.5.sp
|
||||||
)
|
)
|
||||||
/* Other default text styles to override
|
|
||||||
titleLarge = TextStyle(
|
|
||||||
fontFamily = FontFamily.Default,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
fontSize = 22.sp,
|
|
||||||
lineHeight = 28.sp,
|
|
||||||
letterSpacing = 0.sp
|
|
||||||
),
|
|
||||||
labelSmall = TextStyle(
|
|
||||||
fontFamily = FontFamily.Default,
|
|
||||||
fontWeight = FontWeight.Medium,
|
|
||||||
fontSize = 11.sp,
|
|
||||||
lineHeight = 16.sp,
|
|
||||||
letterSpacing = 0.5.sp
|
|
||||||
)
|
|
||||||
*/
|
|
||||||
)
|
)
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Właścicielem tego kodu jest Bartłomiej Janik.
|
||||||
|
*/
|
||||||
|
|
||||||
package com.bartek.iwentaryzacja
|
package com.bartek.iwentaryzacja
|
||||||
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|||||||
Reference in New Issue
Block a user