diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-04-07 09:03:07 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-04-07 09:03:07 +0000 |
commit | eabbabb2b22e6cf97a226905276cfa79ad3887ef (patch) | |
tree | 8ee1dd08b9fa355055044976ab465a52dca4e325 /app | |
parent | bedcf6d0b626a447d4fec40e3e33b4fe0339ea38 (diff) | |
download | infinity-for-reddit-eabbabb2b22e6cf97a226905276cfa79ad3887ef.tar infinity-for-reddit-eabbabb2b22e6cf97a226905276cfa79ad3887ef.tar.gz infinity-for-reddit-eabbabb2b22e6cf97a226905276cfa79ad3887ef.tar.bz2 infinity-for-reddit-eabbabb2b22e6cf97a226905276cfa79ad3887ef.tar.lz infinity-for-reddit-eabbabb2b22e6cf97a226905276cfa79ad3887ef.tar.xz infinity-for-reddit-eabbabb2b22e6cf97a226905276cfa79ad3887ef.tar.zst infinity-for-reddit-eabbabb2b22e6cf97a226905276cfa79ad3887ef.zip |
Fix IllegalArgumentException when downloading media.
Diffstat (limited to 'app')
2 files changed, 7 insertions, 3 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java index 10de74cc..7f834f48 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java @@ -14,6 +14,8 @@ import androidx.browser.customtabs.CustomTabColorSchemeParams; import androidx.browser.customtabs.CustomTabsIntent; import androidx.browser.customtabs.CustomTabsService; +import org.apache.commons.io.FilenameUtils; + import java.util.ArrayList; import java.util.List; @@ -88,7 +90,7 @@ public class LinkResolverActivity extends AppCompatActivity { if (path.endsWith("jpg") || path.endsWith("png")) { Intent intent = new Intent(this, ViewImageOrGifActivity.class); String url = uri.toString(); - String fileName = url.substring(url.lastIndexOf('/') + 1); + String fileName = FilenameUtils.getName(path); intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, url); intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, fileName); intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, fileName); @@ -96,7 +98,7 @@ public class LinkResolverActivity extends AppCompatActivity { } else if (path.endsWith("gif")) { Intent intent = new Intent(this, ViewImageOrGifActivity.class); String url = uri.toString(); - String fileName = url.substring(url.lastIndexOf('/') + 1); + String fileName = FilenameUtils.getName(path); intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, url); intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, fileName); intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, fileName); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index 094657b9..61a12366 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -48,6 +48,8 @@ import com.google.android.material.snackbar.Snackbar; import com.thefuntasty.hauler.DragDirection; import com.thefuntasty.hauler.HaulerView; +import org.apache.commons.io.FilenameUtils; + import java.util.List; import javax.inject.Inject; @@ -289,7 +291,7 @@ public class ViewVideoActivity extends AppCompatActivity { } } else if (videoType == VIDEO_TYPE_DIRECT) { videoDownloadUrl = mVideoUri.toString(); - videoFileName = videoDownloadUrl.substring(videoDownloadUrl.lastIndexOf('/') + 1); + videoFileName = FilenameUtils.getName(videoDownloadUrl); // Produces DataSource instances through which media data is loaded. dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "Infinity")); // Prepare the player with the source. |