Improved external video link parser
This commit is contained in:
@@ -6,7 +6,6 @@ import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import com.vk.dto.common.VideoFile;
|
||||
|
||||
@@ -27,40 +26,31 @@ public class ExternalLinkHandler {
|
||||
private static final Map<String, String> qualities = new HashMap<>();
|
||||
|
||||
public static boolean parseVideoFile(VideoFile file, Context context) {
|
||||
if (!Prefs.isEnableExternalOpening()) return false;
|
||||
|
||||
if (checkYoutubeLink(file)) {
|
||||
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(file.n));
|
||||
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else if (checkVkVideo(file)) {
|
||||
|
||||
if (qualities.size() == 1) {
|
||||
|
||||
startExternalVideo((String) qualities.values().toArray()[0]);
|
||||
|
||||
} else {
|
||||
|
||||
String[] titles = qualities.keySet().toArray(new String[0]);
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setItems(titles, ((dialog, which) -> {
|
||||
|
||||
startExternalVideo(qualities.get(titles[which]));
|
||||
|
||||
}))
|
||||
.show();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!Prefs.isEnableExternalOpening()) return false;
|
||||
|
||||
if (checkVkVideo(file)) {
|
||||
if (qualities.size() == 1) {
|
||||
startExternalVideo((String) qualities.values().toArray()[0]);
|
||||
} else {
|
||||
String[] titles = qualities.keySet().toArray(new String[0]);
|
||||
new AlertDialog.Builder(context)
|
||||
.setItems(titles, ((dialog, which) -> {
|
||||
startExternalVideo(qualities.get(titles[which]));
|
||||
}))
|
||||
.show();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -71,7 +61,6 @@ public class ExternalLinkHandler {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -119,28 +108,21 @@ public class ExternalLinkHandler {
|
||||
|
||||
String packageName = getMXPlayerPackageName();
|
||||
if (!Helper.isEmpty(packageName)) {
|
||||
|
||||
intent.setPackage(packageName);
|
||||
intent.setDataAndType(uri, "application/mp4");
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
} else {
|
||||
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, "video/mp4");
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
}
|
||||
|
||||
Helper.GetContext().startActivity(intent);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user