Skip to content

Commit bf79aba

Browse files
committed
Fix crash when starting a mediathek show download from the mediathek list over a metered network #514
1 parent bd5c4fc commit bf79aba

6 files changed

Lines changed: 64 additions & 47 deletions

File tree

app/src/main/java/de/christinecoenen/code/zapp/app/mediathek/ui/detail/MediathekDetailFragment.kt

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ import androidx.lifecycle.Lifecycle
1111
import androidx.lifecycle.coroutineScope
1212
import androidx.navigation.fragment.findNavController
1313
import androidx.navigation.fragment.navArgs
14-
import com.google.android.material.snackbar.Snackbar
1514
import de.christinecoenen.code.zapp.R
1615
import de.christinecoenen.code.zapp.app.mediathek.controller.downloads.IDownloadController
17-
import de.christinecoenen.code.zapp.app.mediathek.controller.downloads.exceptions.NoNetworkException
18-
import de.christinecoenen.code.zapp.app.mediathek.controller.downloads.exceptions.WrongNetworkConditionException
1916
import de.christinecoenen.code.zapp.app.mediathek.ui.dialogs.ConfirmDeleteDownloadDialog
2017
import de.christinecoenen.code.zapp.app.mediathek.ui.dialogs.SelectQualityDialog
18+
import de.christinecoenen.code.zapp.app.mediathek.ui.helper.DownloadExceptionToastExtensions.showDownloadExeptionToast
2119
import de.christinecoenen.code.zapp.app.mediathek.ui.helper.ShowMenuProvider
2220
import de.christinecoenen.code.zapp.databinding.MediathekDetailFragmentBinding
2321
import de.christinecoenen.code.zapp.models.shows.DownloadStatus
@@ -289,46 +287,7 @@ class MediathekDetailFragment : Fragment() {
289287
try {
290288
downloadController.startDownload(persistedMediathekShow!!.id, downloadQuality)
291289
} catch (e: Exception) {
292-
onStartDownloadException(e)
293-
}
294-
}
295-
}
296-
297-
private fun onStartDownloadException(throwable: Throwable) {
298-
when (throwable) {
299-
is WrongNetworkConditionException -> {
300-
Snackbar
301-
.make(
302-
requireView(),
303-
R.string.error_mediathek_download_over_unmetered_network_only,
304-
Snackbar.LENGTH_LONG
305-
)
306-
.setAction(R.string.activity_settings_title) {
307-
val directions = MediathekDetailFragmentDirections.toSettingsFragment()
308-
findNavController().navigate(directions)
309-
}
310-
.show()
311-
}
312-
313-
is NoNetworkException -> {
314-
Snackbar
315-
.make(
316-
requireView(),
317-
R.string.error_mediathek_download_no_network,
318-
Snackbar.LENGTH_LONG
319-
)
320-
.show()
321-
}
322-
323-
else -> {
324-
Snackbar
325-
.make(
326-
requireView(),
327-
R.string.error_mediathek_generic_start_download_error,
328-
Snackbar.LENGTH_LONG
329-
)
330-
.show()
331-
Timber.e(throwable)
290+
showDownloadExeptionToast(e)
332291
}
333292
}
334293
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package de.christinecoenen.code.zapp.app.mediathek.ui.helper
2+
3+
import androidx.fragment.app.Fragment
4+
import androidx.navigation.fragment.findNavController
5+
import com.google.android.material.snackbar.Snackbar
6+
import de.christinecoenen.code.zapp.R
7+
import de.christinecoenen.code.zapp.app.mediathek.controller.downloads.exceptions.NoNetworkException
8+
import de.christinecoenen.code.zapp.app.mediathek.controller.downloads.exceptions.WrongNetworkConditionException
9+
import timber.log.Timber
10+
11+
object DownloadExceptionToastExtensions {
12+
13+
fun Fragment.showDownloadExeptionToast(throwable: Throwable) {
14+
when (throwable) {
15+
is WrongNetworkConditionException -> {
16+
Snackbar
17+
.make(
18+
requireView(),
19+
R.string.error_mediathek_download_over_unmetered_network_only,
20+
Snackbar.LENGTH_LONG
21+
)
22+
.setAction(R.string.activity_settings_title) {
23+
findNavController().navigate(R.id.global_to_settingsFragment)
24+
}
25+
.show()
26+
}
27+
28+
is NoNetworkException -> {
29+
Snackbar
30+
.make(
31+
requireView(),
32+
R.string.error_mediathek_download_no_network,
33+
Snackbar.LENGTH_LONG
34+
)
35+
.show()
36+
}
37+
38+
else -> {
39+
Snackbar
40+
.make(
41+
requireView(),
42+
R.string.error_mediathek_generic_start_download_error,
43+
Snackbar.LENGTH_LONG
44+
)
45+
.show()
46+
Timber.e(throwable)
47+
}
48+
}
49+
}
50+
}

app/src/main/java/de/christinecoenen/code/zapp/app/mediathek/ui/helper/ShowMenuHelper.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.lifecycle.coroutineScope
1313
import de.christinecoenen.code.zapp.R
1414
import de.christinecoenen.code.zapp.app.mediathek.ui.dialogs.ConfirmDeleteDownloadDialog
1515
import de.christinecoenen.code.zapp.app.mediathek.ui.dialogs.SelectQualityDialog
16+
import de.christinecoenen.code.zapp.app.mediathek.ui.helper.DownloadExceptionToastExtensions.showDownloadExeptionToast
1617
import de.christinecoenen.code.zapp.models.shows.MediathekShow
1718
import de.christinecoenen.code.zapp.utils.system.LifecycleOwnerHelper.launchOnCreated
1819
import kotlinx.coroutines.Job
@@ -151,7 +152,11 @@ class ShowMenuHelper(
151152
fragment.setFragmentResultListener(SelectQualityDialog.REQUEST_KEY_SELECT_QUALITY) { _, bundle ->
152153
val quality = SelectQualityDialog.getSelectedQuality(bundle)
153154
fragment.launchOnCreated {
154-
viewModel.startDownload(show, quality)
155+
try {
156+
viewModel.startDownload(show, quality)
157+
} catch (e: Exception) {
158+
fragment.showDownloadExeptionToast(e)
159+
}
155160
}
156161
}
157162

app/src/main/res/navigation/nav_graph.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@
165165
android:defaultValue="@null"
166166
app:argType="de.christinecoenen.code.zapp.models.shows.MediathekShow"
167167
app:nullable="true" />
168-
<action
169-
android:id="@+id/to_settingsFragment"
170-
app:destination="@id/settingsFragment" />
171168
<action
172169
android:id="@+id/to_mediathekPlayerActivity"
173170
app:destination="@id/mediathekPlayerActivity" />
@@ -184,4 +181,8 @@
184181
app:argType="integer" />
185182
</activity>
186183

184+
<action
185+
android:id="@+id/global_to_settingsFragment"
186+
app:destination="@id/settingsFragment" />
187+
187188
</navigation>

app/src/main/res/raw-en/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Fixed downloads sometimes showing up in notifications but in the user interface ([#508](https://github.com/mediathekview/zapp/issues/508))
99
* Fixed video title covered by the camera notch in portrait mode ([#512](https://github.com/mediathekview/zapp/issues/512))
1010
* Fixed crash when rotating the device while the program info in open ([#511](https://github.com/mediathekview/zapp/issues/511))
11+
* Fixed crash when starting a mediathek show download from the mediathek list over a metered network ([#514](https://github.com/mediathekview/zapp/issues/514))
1112

1213
# 9.1.1
1314
* Fixed a crash upon start when the channel order has been changed previously

app/src/main/res/raw/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Behoben, dass Downloads manchmal in Benachrichtigungen, aber nicht in der Benutzeroberfläche auftauchen ([#508](https://github.com/mediathekview/zapp/issues/508))
99
* Behoben, dass der Video-Titel im Hochvormat von Kamera-Notches verdeckt wird ([#512](https://github.com/mediathekview/zapp/issues/512))
1010
* Absturz behoben, wenn man das Gerät dreht während die Programminformationen geöffnet sind ([#511](https://github.com/mediathekview/zapp/issues/511))
11+
* Absturz behoben, wenn man von der Mediathekliste aus einen Download über ein kostenpflichtiges Netzwerk startet ([#514](https://github.com/mediathekview/zapp/issues/514))
1112

1213
# 9.1.1
1314
* Absturz beim Start behoben, wenn schon einmal die Sender-Reihenfolge angepasst wurde

0 commit comments

Comments
 (0)