Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions app/src/main/java/dev/itsvic/parceltracker/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.toRoute
import com.squareup.moshi.JsonDataException
import dev.itsvic.parceltracker.api.APIKeyMissingException
import dev.itsvic.parceltracker.api.Parcel as APIParcel
import dev.itsvic.parceltracker.api.ParcelHistoryItem
Expand Down Expand Up @@ -196,6 +197,13 @@ fun ParcelAppNavigation(parcelToOpen: Int) {

LaunchedEffect(parcelWithStatus) {
if (dbParcel != null && !dbParcel.isArchived) {
fun apiParcelError(description: String, status: Status): APIParcel {
return APIParcel(
dbParcel.parcelId,
listOf(ParcelHistoryItem(description, LocalDateTime.now(), "")),
status)
}

launch(Dispatchers.IO) {
try {
apiParcel =
Expand All @@ -220,33 +228,30 @@ fun ParcelAppNavigation(parcelToOpen: Int) {
} catch (e: IOException) {
Log.w("MainActivity", "Failed fetch: $e")
apiParcel =
APIParcel(
dbParcel.parcelId,
listOf(
ParcelHistoryItem(
context.getString(R.string.network_failure_detail),
LocalDateTime.now(),
"")),
Status.NetworkFailure)
apiParcelError(
context.getString(R.string.network_failure_detail), Status.NetworkFailure)
} catch (_: ParcelNonExistentException) {
apiParcel =
APIParcel(
dbParcel.parcelId,
listOf(
ParcelHistoryItem(
context.getString(R.string.parcel_doesnt_exist_detail),
LocalDateTime.now(),
"")),
Status.NoData)
apiParcelError(
context.getString(R.string.parcel_doesnt_exist_detail), Status.NoData)
} catch (_: APIKeyMissingException) {
apiParcel =
APIParcel(
dbParcel.parcelId,
listOf(
ParcelHistoryItem(
context.getString(R.string.error_no_api_key_provided),
LocalDateTime.now(),
"")),
apiParcelError(
context.getString(R.string.error_no_api_key_provided), Status.NetworkFailure)
} catch (e: JsonDataException) {
Log.w(
"MainActivity",
"Unexpected JSON response that could not be converted: ${e.message}")
apiParcel =
apiParcelError(
context.getString(R.string.error_json_conversion).format(e.message),
Status.NetworkFailure)
} catch (e: Exception) {
// catchall to avoid crashes
Log.e("MainActivity", "Unexpected error", e)
apiParcel =
apiParcelError(
context.getString(R.string.error_unexpected_detail).format(e.message),
Status.NetworkFailure)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ object UPSDeliveryService : DeliveryService {
val tokens = getCsrfTokens(trackingId)

val language = LocaleList.getDefault().get(0)
val country =
if (language.country.isEmpty()) defaultRegionsForLanguageCode[language.language]
else language.country
val country = language.country.ifEmpty { defaultRegionsForLanguageCode[language.language] }
val locale = "${language.language}_$country"

val resp =
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<string name="dump_logs_button">Protokolle in Datei exportieren</string>
<string name="edit">Bearbeiten</string>
<string name="edit_parcel">Paket bearbeiten</string>
<string name="error_json_conversion">Beim Parsen der Serverantwort ist ein Fehler aufgetreten, möglicherweise aufgrund einer Änderung der API.\n\nFehlermeldung der JSON Konvertierung:\n%1$s</string>
<string name="error_no_api_key_provided">Dieser Zustelldienst erfordert einen API-Schlüssel, aber es wurde keiner angegeben. Weitere Informationen finden Sie in den App-Einstellungen.</string>
<string name="error_unexpected_detail">Ein unbekannter Fehler ist aufgetreten mit der Nachricht:\n%1$s.</string>
<string name="go_back">Zurück</string>
<string name="human_name_error_text">Name darf nicht leer sein.</string>
<string name="ignore">Ignorieren</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
<string name="dump_logs_button">Dump logs to file</string>
<string name="edit">Edit</string>
<string name="edit_parcel">Edit parcel</string>
<string name="error_json_conversion">There was an error parsing the response, possibly because the API changed.\n\nJSON conversion error message:\n%1$s</string>
<string name="error_no_api_key_provided">This delivery service requires an API key, but none was provided. Check the app\'s settings for more information.</string>
<string name="error_unexpected_detail">An unexpected error was encountered with the message:\n%1$s.</string>
<string name="go_back">Go back</string>
<string name="human_name_error_text">Name must not be blank.</string>
<string name="ignore">Ignore</string>
Expand Down