mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
Null check. Fixes https://github.com/austinhuang0131/barinsta/issues/862
This commit is contained in:
parent
8f72796891
commit
a60e934162
@ -1,10 +1,8 @@
|
|||||||
package awais.instagrabber.utils;
|
package awais.instagrabber.utils;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
@ -13,8 +11,6 @@ import android.widget.Toast;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.core.app.ActivityCompat;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.work.Constraints;
|
import androidx.work.Constraints;
|
||||||
import androidx.work.Data;
|
import androidx.work.Data;
|
||||||
import androidx.work.NetworkType;
|
import androidx.work.NetworkType;
|
||||||
@ -90,17 +86,17 @@ public final class DownloadUtils {
|
|||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static void dmDownload(@NonNull final Context context,
|
// public static void dmDownload(@NonNull final Context context,
|
||||||
// @Nullable final String username,
|
// @Nullable final String username,
|
||||||
// final String modelId,
|
// final String modelId,
|
||||||
// final String url) {
|
// final String url) {
|
||||||
// if (url == null) return;
|
// if (url == null) return;
|
||||||
// if (ContextCompat.checkSelfPermission(context, PERMS[0]) == PackageManager.PERMISSION_GRANTED) {
|
// if (ContextCompat.checkSelfPermission(context, PERMS[0]) == PackageManager.PERMISSION_GRANTED) {
|
||||||
// dmDownloadImpl(context, username, modelId, url);
|
// dmDownloadImpl(context, username, modelId, url);
|
||||||
// } else if (context instanceof Activity) {
|
// } else if (context instanceof Activity) {
|
||||||
// ActivityCompat.requestPermissions((Activity) context, PERMS, 8020);
|
// ActivityCompat.requestPermissions((Activity) context, PERMS, 8020);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
private static void dmDownloadImpl(@NonNull final Context context,
|
private static void dmDownloadImpl(@NonNull final Context context,
|
||||||
@Nullable final String username,
|
@Nullable final String username,
|
||||||
@ -294,7 +290,8 @@ public final class DownloadUtils {
|
|||||||
final int childPositionIfSingle) {
|
final int childPositionIfSingle) {
|
||||||
final Map<String, String> map = new HashMap<>();
|
final Map<String, String> map = new HashMap<>();
|
||||||
for (final Media media : feedModels) {
|
for (final Media media : feedModels) {
|
||||||
final File downloadDir = getDownloadDir(context, "@" + media.getUser().getUsername());
|
final User mediaUser = media.getUser();
|
||||||
|
final File downloadDir = getDownloadDir(context, mediaUser == null ? "" : "@" + mediaUser.getUsername());
|
||||||
if (downloadDir == null) return;
|
if (downloadDir == null) return;
|
||||||
switch (media.getMediaType()) {
|
switch (media.getMediaType()) {
|
||||||
case MEDIA_TYPE_IMAGE:
|
case MEDIA_TYPE_IMAGE:
|
||||||
@ -307,9 +304,8 @@ public final class DownloadUtils {
|
|||||||
case MEDIA_TYPE_VOICE: {
|
case MEDIA_TYPE_VOICE: {
|
||||||
final String url = getUrlOfType(media);
|
final String url = getUrlOfType(media);
|
||||||
String fileName = media.getId();
|
String fileName = media.getId();
|
||||||
final User user = media.getUser();
|
if (mediaUser != null) {
|
||||||
if (user != null) {
|
fileName = mediaUser.getUsername() + "_" + fileName;
|
||||||
fileName = user.getUsername() + "_" + fileName;
|
|
||||||
}
|
}
|
||||||
final File file = getDownloadSaveFile(downloadDir, fileName, url);
|
final File file = getDownloadSaveFile(downloadDir, fileName, url);
|
||||||
map.put(url, file.getAbsolutePath());
|
map.put(url, file.getAbsolutePath());
|
||||||
|
Loading…
Reference in New Issue
Block a user