Skip to content

Commit

Permalink
Do not crash if no gallery app is installed.
Browse files Browse the repository at this point in the history
  • Loading branch information
mopsalarm committed Nov 26, 2017
1 parent d8eae34 commit 93f9f09
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ class UploadActivity : BaseAppCompatActivity("UploadActivity"), ChooseMediaTypeF
}

internal fun showUploadFragment(type: String?, addToBackstack: Boolean) {
val arguments = Bundle()

val fragment = if (intent?.action == Intent.ACTION_SEND) {
val url = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
UploadFragment.forLocalUri(url)
Expand Down
23 changes: 19 additions & 4 deletions app/src/main/java/com/pr0gramm/app/ui/upload/UploadFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ class UploadFragment : BaseFragment("UploadFragment") {
handleImageUri(uri)

} else if (savedInstanceState == null) {
val intent = Intent(Intent.ACTION_PICK)
intent.type = mediaTypeArgument
startActivityForResult(intent, RequestCodes.SELECT_MEDIA)
handleImagePickRequest()
}

// enable auto-complete
Expand All @@ -108,12 +106,29 @@ class UploadFragment : BaseFragment("UploadFragment") {
}
}

private fun handleImagePickRequest() {
val intent = Intent(Intent.ACTION_PICK)
intent.type = mediaTypeArgument

// check if someone can handle this intent
if (!context.canStartIntent(intent)) {
showDialog(this) {
content(R.string.error_no_gallery_app)
positive { activity?.finish() }
}

return
}

startActivityForResult(intent, RequestCodes.SELECT_MEDIA)
}

private fun onUploadClicked() {
val file = file
if (file == null) {
showDialog(this) {
content(R.string.hint_upload_something_happen_try_again)
positive(R.string.okay, { activity?.finish() })
positive(R.string.okay) { activity?.finish() }
}
return
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/pr0gramm/app/util/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.pr0gramm.app.util

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.res.TypedArray
import android.database.Cursor
Expand Down Expand Up @@ -383,3 +384,7 @@ val <T : Result> PendingResult<T>.rx: Observable<T>
emitter.onCompleted()
}
}

fun Context.canStartIntent(intent: Intent): Boolean {
return packageManager.resolveActivity(intent, 0) != null
}
4 changes: 4 additions & 0 deletions app/src/main/res/raw/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
{
"type": "Fix",
"change": "Hintergrund auf der Login Seite ist nun wieder da."
},
{
"type": "Fix",
"change": "Ist keine Galerie App installiert, ist die App beim Versuch einen Upload zu machen, abgestürzt. Dies ist nun nicht mehr der Fall."
}
]
},
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -501,4 +501,5 @@
<string name="cast">Cast</string>
<string name="error_feed_not_found">Der angefragte Post existiert nicht mehr.</string>
<string name="menu_new_badge">NEU</string>
<string name="error_no_gallery_app">Es ist keine App zum Auswählen von Bildern und Videos installiert. Bitte installiere eine Galerie App wie \'Google Photos\' oder \'Simple Gallery\'</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -521,5 +521,6 @@
<string name="cast">Cast</string>
<string name="error_feed_not_found">The requested post does not exist.</string>
<string name="menu_new_badge">NEW</string>
<string name="error_no_gallery_app">There is no app installed on your device that can handle an image picking request. Please install a gallery app like \'Simple Gallery\' or \'Google Photos\'.</string>
</resources>

0 comments on commit 93f9f09

Please sign in to comment.