Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: smoother download error handling (fixes #4919) #4922

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
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 26
targetSdkVersion 34
versionCode 2160
versionName "0.21.60"
versionCode 2161
versionName "0.21.61"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.ole.planet.myplanet.MainApplication.Companion.context
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.callback.OnHomeItemClickListener
import org.ole.planet.myplanet.datamanager.DatabaseService
import org.ole.planet.myplanet.datamanager.MyDownloadService
import org.ole.planet.myplanet.datamanager.Service
import org.ole.planet.myplanet.datamanager.Service.PlanetAvailableListener
import org.ole.planet.myplanet.model.Download
Expand Down Expand Up @@ -89,6 +90,7 @@ abstract class BaseResourceFragment : Fragment() {
if (!download?.failed!!) {
setProgress(download)
} else {
prgDialog.dismiss()
download.message?.let { showError(prgDialog, it) }
}
}
Expand Down Expand Up @@ -168,6 +170,27 @@ abstract class BaseResourceFragment : Fragment() {
}.setPositiveButton(R.string.dismiss, null).show()
}

private val resourceNotFoundReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
showResourceNotFoundDialog()
}
}

private fun showResourceNotFoundDialog() {
if (isAdded) {
if (prgDialog.isShowing()) {
prgDialog.dismiss()
}
AlertDialog.Builder(requireContext())
.setTitle(R.string.resource_not_found)
.setMessage(R.string.resource_not_found_message)
.setNegativeButton(R.string.close) { dialog, _ ->
dialog.dismiss()
}
.show()
}
}

fun startDownload(urls: ArrayList<String>) {
if (isAdded) {
Service(requireActivity()).isPlanetAvailable(object : PlanetAvailableListener {
Expand Down Expand Up @@ -221,17 +244,21 @@ abstract class BaseResourceFragment : Fragment() {

private fun registerReceiver() {
val bManager = LocalBroadcastManager.getInstance(requireActivity())

val intentFilter = IntentFilter()
intentFilter.addAction(DashboardActivity.MESSAGE_PROGRESS)
bManager.registerReceiver(broadcastReceiver, intentFilter)

val intentFilter2 = IntentFilter()
intentFilter2.addAction("ACTION_NETWORK_CHANGED")
LocalBroadcastManager.getInstance(MainApplication.context).registerReceiver(receiver, intentFilter2)
bManager.registerReceiver(receiver, intentFilter2)

val intentFilter3 = IntentFilter()
intentFilter3.addAction("SHOW_WIFI_ALERT")
LocalBroadcastManager.getInstance(MainApplication.context).registerReceiver(stateReceiver, intentFilter3)
bManager.registerReceiver(stateReceiver, intentFilter3)

val resourceNotFoundFilter = IntentFilter(MyDownloadService.RESOURCE_NOT_FOUND_ACTION)
bManager.registerReceiver(resourceNotFoundReceiver, resourceNotFoundFilter)
}

fun getLibraryList(mRealm: Realm): List<RealmMyLibrary> {
Expand All @@ -248,9 +275,11 @@ abstract class BaseResourceFragment : Fragment() {

override fun onPause() {
super.onPause()
LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(receiver)
LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(broadcastReceiver)
LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(stateReceiver)
val bManager = LocalBroadcastManager.getInstance(requireActivity())
bManager.unregisterReceiver(receiver)
bManager.unregisterReceiver(broadcastReceiver)
bManager.unregisterReceiver(stateReceiver)
bManager.unregisterReceiver(resourceNotFoundReceiver)
}

fun removeFromShelf(`object`: RealmObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ class MyDownloadService : Service() {
this.message = message
}
sendIntent(download, fromSync)

if (message == "File Not Found") {
val intent = Intent(RESOURCE_NOT_FOUND_ACTION)
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
}
}

@Throws(IOException::class)
Expand Down Expand Up @@ -231,7 +236,7 @@ class MyDownloadService : Service() {
companion object {
const val PREFS_NAME = "MyPrefsFile"
const val MESSAGE_PROGRESS = "message_progress"

const val RESOURCE_NOT_FOUND_ACTION = "resource_not_found_action"
fun startService(context: Context, urlsKey: String, fromSync: Boolean) {
val intent = Intent(context, MyDownloadService::class.java).apply {
putExtra("urls_key", urlsKey)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="resource_not_found">لم يتم العثور على المورد</string>
<string name="resource_not_found_message">لا يمكن العثور على المورد المطلوب.</string>
<string name="community_earnings">إجمالي أرباح المجتمع: **$%1$d** /$500</string>
<string name="your_earnings">أرباحك الإجمالية: **$%1$d** /$11</string>
<string name="congratulations">تهانينا! التحدي مكتمل</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="resource_not_found">Recurso no encontrado</string>
<string name="resource_not_found_message">No se pudo encontrar el recurso solicitado</string>
<string name="community_earnings">Ingresos totales de la comunidad: **$%1$d** /$500</string>
<string name="your_earnings">Tus ganancias totales: **$%1$d** /$11</string>
<string name="congratulations">¡Felicidades! Reto Completado</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="resource_not_found">Ressource introuvable</string>
<string name="resource_not_found_message">La ressource demandée est introuvable</string>
<string name="community_earnings">Revenus totaux de la communauté: **$%1$d** /$500</string>
<string name="your_earnings">Vos gains totaux: **$%1$d** /$11</string>
<string name="congratulations">Félicitations! Défi terminé</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ne/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="resource_not_found">स्रोत फेला परेन</string>
<string name="resource_not_found_message">अनुरोध गरिएको स्रोत फेला पार्न सकिएन</string>
<string name="community_earnings">समुदायको कुल आम्दानी: **$%1$d** /$500</string>
<string name="your_earnings">तपाईंको कुल आम्दानी: **$%1$d** /$11</string>
<string name="congratulations">बधाई छ! चुनौती पूरा भयो</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-so/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="resource_not_found">Ilaha lama helin</string>
<string name="resource_not_found_message">Ilaha la codsaday waa la heli waayay</string>
<string name="community_earnings">Dakhliga guud ee bulshada: **$%1$d** /$500</string>
<string name="your_earnings">Dakhligaaga guud: **$%1$d** /$11</string>
<string name="congratulations">Hambalyo! Tartanka waa la dhameeyay</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
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="resource_not_found">Resource not found</string>
<string name="resource_not_found_message">The requested resource could not be found</string>
<string name="community_earnings">Community total earnings: **$%1$d** /$500</string>
<string name="your_earnings">Your total earnings: **$%1$d** /$11</string>
<string name="congratulations">Congratulations! Challenge Completed</string>
Expand Down
Loading