ver 1.6 sprzatanie kodu
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Właścicielem tego kodu jest Bartłomiej Janik.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Właścicielem tego kodu jest Bartłomiej Janik.
|
||||
*/
|
||||
|
||||
package com.bartek.iwentaryzacja
|
||||
|
||||
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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
@@ -103,6 +105,9 @@ class InventoryViewModel : ViewModel() {
|
||||
|
||||
data class UpdateInfo(val versionCode: Int)
|
||||
|
||||
/**
|
||||
* Wczytuje stan aplikacji (notatki i listę maszyn) z pamięci urządzenia (SharedPreferences).
|
||||
*/
|
||||
fun loadState(context: Context) {
|
||||
val prefs = context.getSharedPreferences("inventory_prefs", Context.MODE_PRIVATE)
|
||||
_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) {
|
||||
val prefs = context.getSharedPreferences("inventory_prefs", Context.MODE_PRIVATE)
|
||||
val editor = prefs.edit()
|
||||
@@ -185,6 +193,9 @@ class InventoryViewModel : ViewModel() {
|
||||
_filterMissing.value = !_filterMissing.value
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprawdza dostępność aktualizacji na serwerze zdalnym.
|
||||
*/
|
||||
fun checkForUpdates(context: Context) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
@@ -248,62 +259,66 @@ class InventoryViewModel : ViewModel() {
|
||||
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) {
|
||||
try {
|
||||
// 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)
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val headerRow = sheet.getRow(0)
|
||||
val branch = headerRow?.getCell(0)?.toString()?.trim() ?: ""
|
||||
val date = headerRow?.getCell(4)?.toString()?.trim() ?: "" // Przykładowa kolumna dla daty
|
||||
// WorkbookFactory automatycznie obsługuje zarówno .xls jak i .xlsx
|
||||
val workbook = WorkbookFactory.create(inputStream)
|
||||
val sheet = workbook.getSheetAt(0)
|
||||
|
||||
// Usuwamy zbędny napis "raport:lista produktow" w różnych wariantach
|
||||
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
|
||||
// Próba pobrania nazwy oddziału i daty z nagłówka (wiersz 0)
|
||||
try {
|
||||
val headerRow = sheet.getRow(0)
|
||||
val branch = headerRow?.getCell(0)?.toString()?.trim() ?: ""
|
||||
val date = headerRow?.getCell(4)?.toString()?.trim() ?: ""
|
||||
|
||||
// Usuwamy zbędny napis "raport:lista produktow" w różnych wariantach
|
||||
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) {
|
||||
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
|
||||
fun SplashScreen() {
|
||||
Box(
|
||||
@@ -381,6 +399,9 @@ fun SplashScreen() {
|
||||
// ==========================================
|
||||
// 4. EKRAN GŁÓWNY
|
||||
// ==========================================
|
||||
/**
|
||||
* Główny ekran aplikacji zarządzający listą maszyn i interfejsem użytkownika.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun InventoryScreen(viewModel: InventoryViewModel = viewModel()) {
|
||||
@@ -698,6 +719,9 @@ fun InventoryScreen(viewModel: InventoryViewModel = viewModel()) {
|
||||
// ==========================================
|
||||
// 5. POJEDYNCZY ELEMENT LISTY
|
||||
// ==========================================
|
||||
/**
|
||||
* Komponent pojedynczego kafelka w górnym menu nawigacyjnym.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DashboardTile(
|
||||
@@ -733,6 +757,9 @@ fun DashboardTile(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Okno dialogowe umożliwiające zbiorcze zaznaczanie maszyn na podstawie ich statusu.
|
||||
*/
|
||||
@Composable
|
||||
fun StatusSelectionDialog(
|
||||
statuses: List<String>,
|
||||
@@ -790,6 +817,9 @@ fun StatusSelectionDialog(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Okno dialogowe notatnika do zapisywania uwag.
|
||||
*/
|
||||
@Composable
|
||||
fun NotesDialog(
|
||||
notes: String,
|
||||
@@ -822,6 +852,9 @@ fun NotesDialog(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Niestandardowa klawiatura numeryczna do szybkiego filtrowania po numerach ID.
|
||||
*/
|
||||
@Composable
|
||||
fun NumericKeyboard(
|
||||
onDigitClick: (String) -> Unit,
|
||||
@@ -891,6 +924,9 @@ fun KeyButton(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Komponent pojedynczego elementu na liście maszyn.
|
||||
*/
|
||||
@Composable
|
||||
fun MachineItem(
|
||||
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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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
|
||||
|
||||
/**
|
||||
* Definicje kolorów używanych w motywie aplikacji.
|
||||
*/
|
||||
val Purple80 = Color(0xFFD0BCFF)
|
||||
val PurpleGrey80 = Color(0xFFCCC2DC)
|
||||
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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
@@ -36,18 +38,11 @@ private val LightColorScheme = lightColorScheme(
|
||||
primary = Purple40,
|
||||
secondary = PurpleGrey40,
|
||||
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
|
||||
fun IwentARyzacjaTheme(
|
||||
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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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.unit.sp
|
||||
|
||||
// Set of Material typography styles to start with
|
||||
/**
|
||||
* Definicje typografii dla interfejsu Compose.
|
||||
*/
|
||||
val Typography = Typography(
|
||||
bodyLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
@@ -30,20 +34,4 @@ val Typography = Typography(
|
||||
lineHeight = 24.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
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
Reference in New Issue
Block a user