Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6213bbf30f | ||
|
|
2c52c2c538 | ||
|
|
a7620302e9 |
No files matched your search
@@ -30,8 +30,8 @@ android {
|
||||
applicationId = "com.oqba26.monthlypaymentapp"
|
||||
minSdk = 25
|
||||
targetSdk = 34
|
||||
versionCode = 10
|
||||
versionName = "1.0.9"
|
||||
versionCode = 12
|
||||
versionName = "1.1.1"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables { useSupportLibrary = true }
|
||||
}
|
||||
@@ -76,7 +76,13 @@ android {
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
isCoreLibraryDesugaringEnabled = true
|
||||
}
|
||||
kotlinOptions { jvmTarget = "21" }
|
||||
kotlinOptions {
|
||||
jvmTarget = "21"
|
||||
freeCompilerArgs += listOf(
|
||||
"-opt-in=kotlinx.serialization.InternalSerializationApi",
|
||||
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
|
||||
)
|
||||
}
|
||||
kotlin { jvmToolchain(21) }
|
||||
|
||||
packaging {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@file:OptIn(InternalSerializationApi::class)
|
||||
|
||||
package com.oqba26.monthlypaymentapp.data.remote
|
||||
|
||||
import android.util.Log
|
||||
@@ -5,6 +7,7 @@ import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.okhttp.OkHttp
|
||||
import io.ktor.client.plugins.HttpTimeout
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.client.plugins.timeout
|
||||
import io.ktor.client.request.delete
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.header
|
||||
@@ -25,6 +28,7 @@ import io.ktor.utils.io.readUTF8Line
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.serialization.InternalSerializationApi
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
@@ -347,6 +351,10 @@ class PocketBaseClient(
|
||||
authToken?.let { token ->
|
||||
header(HttpHeaders.Authorization, "Bearer $token")
|
||||
}
|
||||
timeout {
|
||||
requestTimeoutMillis = HttpTimeout.INFINITE_TIMEOUT_MS
|
||||
socketTimeoutMillis = HttpTimeout.INFINITE_TIMEOUT_MS
|
||||
}
|
||||
}.execute { response ->
|
||||
val channel: ByteReadChannel = response.bodyAsChannel()
|
||||
var currentEvent = ""
|
||||
@@ -362,6 +370,7 @@ class PocketBaseClient(
|
||||
val connectObj = json.decodeFromString<PocketBaseConnectEvent>(dataJson)
|
||||
subscribeRealtime(cleanBaseUrl, connectObj.clientId, subscriptions)
|
||||
Log.d(TAG, "اتصال ریلتایم برقرار شد. ClientId: ${connectObj.clientId}")
|
||||
emit("PB_CONNECT")
|
||||
} else if (currentEvent.isNotEmpty()) {
|
||||
emit(currentEvent)
|
||||
}
|
||||
|
||||
+9
-31
@@ -14,9 +14,10 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.UUID
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
class NetworkRepository(
|
||||
private val settingsRepository: SettingsRepository? = null
|
||||
settingsRepository: SettingsRepository? = null
|
||||
) {
|
||||
|
||||
private val pocketBase = ApiClient.pocketBase
|
||||
@@ -43,6 +44,7 @@ class NetworkRepository(
|
||||
// --- Realtime Operations ---
|
||||
fun observeRealtimeChanges() {
|
||||
repositoryScope.launch {
|
||||
while (true) {
|
||||
try {
|
||||
pocketBase.listenRealtime(listOf("persons", "payments")).collect { event ->
|
||||
Log.d("PocketBase-Realtime", "Change detected in PocketBase: $event")
|
||||
@@ -51,6 +53,8 @@ class NetworkRepository(
|
||||
} catch (e: Exception) {
|
||||
Log.e("PocketBase-Realtime", "Realtime connection error, retrying...", e)
|
||||
}
|
||||
delay(3000.milliseconds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,31 +156,7 @@ class NetworkRepository(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updatePersonArchivedStatus(personId: String, isArchived: Boolean): Boolean {
|
||||
return try {
|
||||
val currentPerson = _personsFlow.value.find { it.id == personId }
|
||||
if (currentPerson != null) {
|
||||
pocketBase.upsertRecord("persons", "id='$personId'", currentPerson.copy(isArchived = isArchived))
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
Log.e("PocketBase", "updateArchived error", e)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updatePersonDisplayOrder(personId: String, displayOrder: Long): Boolean {
|
||||
return try {
|
||||
val currentPerson = _personsFlow.value.find { it.id == personId }
|
||||
if (currentPerson != null) {
|
||||
pocketBase.upsertRecord("persons", "id='$personId'", currentPerson.copy(displayOrder = displayOrder))
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
Log.e("PocketBase", "updateOrder error", e)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun getPersonsFlow(): Flow<List<Person>> = _personsFlow.asStateFlow()
|
||||
|
||||
@@ -192,19 +172,17 @@ class NetworkRepository(
|
||||
}
|
||||
|
||||
suspend fun deletePayment(paymentId: String): Boolean {
|
||||
var retries = 0
|
||||
val maxRetries = 2
|
||||
|
||||
while (retries <= maxRetries) {
|
||||
for (retries in 1..maxRetries) {
|
||||
try {
|
||||
pocketBase.deleteRecordByFilter("payments", "id='$paymentId'")
|
||||
Log.d("PocketBase", "deletePayment Success: $paymentId")
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
retries++
|
||||
Log.e("PocketBase", "deletePayment error (Attempt $retries): ${e.message}", e)
|
||||
if (retries > maxRetries) return false
|
||||
delay(1000L * retries)
|
||||
if (retries < maxRetries) {
|
||||
delay((1000L * retries).milliseconds)
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -1168,7 +1168,7 @@ fun FinancialReportDialog(
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(max = 600.dp),
|
||||
.heightIn(max = 650.dp),
|
||||
shape = RoundedCornerShape(24.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface)
|
||||
) {
|
||||
@@ -1195,6 +1195,11 @@ fun FinancialReportDialog(
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp)
|
||||
) {
|
||||
item {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.4f))
|
||||
@@ -1219,9 +1224,10 @@ fun FinancialReportDialog(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.debtors.isNotEmpty()) {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
item {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.15f))
|
||||
@@ -1247,19 +1253,22 @@ fun FinancialReportDialog(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
HorizontalDivider()
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
item {
|
||||
Column {
|
||||
HorizontalDivider(modifier = Modifier.padding(vertical = 4.dp))
|
||||
Text(
|
||||
text = "تفکیک درآمد ماهانه ماههای گذشته",
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier.padding(bottom = 8.dp)
|
||||
modifier = Modifier.padding(top = 4.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (data.monthlyReports.isEmpty()) {
|
||||
item {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -1268,11 +1277,8 @@ fun FinancialReportDialog(
|
||||
) {
|
||||
Text("هیچ دریافتی تا کنون ثبت نشده است.", style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LazyColumn(
|
||||
modifier = Modifier.weight(1f),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
items(data.monthlyReports) { report ->
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
@@ -1319,15 +1325,6 @@ fun FinancialReportDialog(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
TextButton(
|
||||
onClick = onDismiss,
|
||||
modifier = Modifier.align(Alignment.End)
|
||||
) {
|
||||
Text("بستن")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -633,7 +634,7 @@ fun OperatorModeSetting(
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp)
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -648,18 +649,24 @@ fun OperatorModeSetting(
|
||||
modifier = Modifier.size(24.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Column {
|
||||
Text(
|
||||
text = "حالت دسترسی برنامه",
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(
|
||||
text = if (isOperatorMode) "وضعیت فعلی: حالت اپراتور (محدود)" else "وضعیت فعلی: حالت مدیریت (کامل)",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = if (isOperatorMode) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primary
|
||||
)
|
||||
}
|
||||
|
||||
Surface(
|
||||
color = if (isOperatorMode) MaterialTheme.colorScheme.errorContainer else MaterialTheme.colorScheme.primaryContainer,
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
) {
|
||||
Text(
|
||||
text = if (isOperatorMode) "اپراتور (محدود)" else "مدیریت (کامل)",
|
||||
modifier = Modifier.padding(horizontal = 10.dp, vertical = 4.dp),
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = if (isOperatorMode) MaterialTheme.colorScheme.onErrorContainer else MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -674,38 +681,51 @@ fun OperatorModeSetting(
|
||||
showPinDialog = true
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(10.dp)
|
||||
shape = RoundedCornerShape(10.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primary)
|
||||
) {
|
||||
Icon(Icons.Default.LockOpen, contentDescription = null, modifier = Modifier.size(18.dp))
|
||||
Spacer(modifier = Modifier.width(6.dp))
|
||||
Text("خروج از حالت اپراتور (ورود رمز مدیر)")
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text("خروج از حالت اپراتور (ورود رمز مدیر)", style = MaterialTheme.typography.bodyMedium, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
} else {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Button(
|
||||
OutlinedButton(
|
||||
onClick = { onToggleMode(true) },
|
||||
modifier = Modifier.weight(1f),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(10.dp)
|
||||
) {
|
||||
Text("فعالسازی حالت اپراتور", style = MaterialTheme.typography.bodyMedium, fontWeight = FontWeight.Bold)
|
||||
Icon(Icons.Default.Lock, contentDescription = null, modifier = Modifier.size(18.dp))
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text("فعالسازی حالت اپراتور (محدودسازی)", style = MaterialTheme.typography.bodyMedium, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
|
||||
OutlinedButton(
|
||||
onClick = {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable {
|
||||
pinAction = PinAction.CHANGE_PIN
|
||||
enteredPin = ""
|
||||
newPinInput = ""
|
||||
errorMessage = ""
|
||||
showPinDialog = true
|
||||
},
|
||||
modifier = Modifier.weight(1f),
|
||||
shape = RoundedCornerShape(10.dp)
|
||||
) {
|
||||
Text("تغییر رمز مدیر", style = MaterialTheme.typography.bodyMedium, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
.padding(vertical = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Edit,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(18.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(6.dp))
|
||||
Text(
|
||||
text = "تغییر رمز عبور مدیریت",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"versionCode": 10,
|
||||
"versionName": "1.0.9",
|
||||
"url": "https://github.com/oqba26/MonthlyPaymentApp/releases/download/v1.0.9/MonthlyPaymentApp-v1.0.9.apk",
|
||||
"releaseNotes": "اصلاح اسکرول صفحه تنظیمات، بهبود ظاهری کارت حالت دسترسی و انتقال لیست اسامی بدهکاران به گزارش مالی",
|
||||
"versionCode": 12,
|
||||
"versionName": "1.1.1",
|
||||
"url": "https://github.com/oqba26/MonthlyPaymentApp/releases/download/v1.1.1/MonthlyPaymentApp-v1.1.1.apk",
|
||||
"releaseNotes": "بهبودهای همگامسازی شبکه و پایداری لایو PocketBase",
|
||||
"isForceUpdate": false
|
||||
}
|
||||
Reference in new issue
Block a user