Fix IllegalArgumentException when downloading media.

This commit is contained in:
Alex Ning 2021-04-07 17:03:07 +08:00
parent bedcf6d0b6
commit eabbabb2b2
2 changed files with 7 additions and 3 deletions

View File

@ -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);

View File

@ -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.