pull/520/head
okjack 2 years ago
parent 9748a56789
commit b0ad5603f3
  1. 77
      app/src/main/java/com/fongmi/android/tv/utils/IDMUtil.java
  2. 1
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  3. 3
      app/src/mobile/java/com/fongmi/android/tv/ui/fragment/EpisodeFragment.java

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
@ -67,48 +68,54 @@ public class IDMUtil {
}
private static boolean downloadFilesInternal(@NonNull Activity activity, @Nullable Map<String, String> urlAndFileNames, @Nullable String url, @Nullable String referer, @Nullable String fileName, @Nullable String userAgent, @Nullable String cookies, @Nullable Map<String, String> headers, boolean secureUri, boolean askUserToInstall1DMIfNotInstalled){
int requiredVersionCode = secureUri ? SECURE_URI_1DM_SUPPORT_MIN_VERSION_CODE : !isEmpty(urlAndFileNames) || !isEmpty(headers) ? HEADERS_AND_MULTIPLE_LINKS_1DM_SUPPORT_MIN_VERSION_CODE : 0;
String packageName = "";
try {
packageName = get1DMInstalledPackageName(requiredVersionCode, askUserToInstall1DMIfNotInstalled);
} catch (Exception e) {
return false;
}
if (TextUtils.isEmpty(packageName)) return false;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName(packageName, DOWNLOADER_ACTIVITY_NAME_1DM));
intent.putExtra(EXTRA_SECURE_URI, secureUri);
if (isEmpty(urlAndFileNames)) {
intent.setData(Uri.parse(url));
if (!TextUtils.isEmpty(referer)) intent.putExtra(EXTRA_REFERER, referer);
if (!TextUtils.isEmpty(userAgent)) intent.putExtra(EXTRA_USERAGENT, userAgent);
if (!TextUtils.isEmpty(cookies)) intent.putExtra(EXTRA_COOKIES, cookies);
if (!TextUtils.isEmpty(fileName)) intent.putExtra(EXTRA_FILENAME, fileName);
} else {
ArrayList<String> urls = new ArrayList<>(urlAndFileNames.size());
ArrayList<String> names = new ArrayList<>(urlAndFileNames.size());
for (Map.Entry<String, String> entry : urlAndFileNames.entrySet()) {
if (TextUtils.isEmpty(entry.getKey())) continue;
urls.add(entry.getKey());
names.add(entry.getValue());
int requiredVersionCode = secureUri ? SECURE_URI_1DM_SUPPORT_MIN_VERSION_CODE : !isEmpty(urlAndFileNames) || !isEmpty(headers) ? HEADERS_AND_MULTIPLE_LINKS_1DM_SUPPORT_MIN_VERSION_CODE : 0;
String packageName = "";
try {
packageName = get1DMInstalledPackageName(requiredVersionCode, askUserToInstall1DMIfNotInstalled);
} catch (Exception e) {
return false;
}
if (TextUtils.isEmpty(packageName)) return false;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName(packageName, DOWNLOADER_ACTIVITY_NAME_1DM));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.putExtra(EXTRA_SECURE_URI, secureUri);
if (isEmpty(urlAndFileNames)) {
intent.setData(Uri.parse(url));
if (!TextUtils.isEmpty(referer)) intent.putExtra(EXTRA_REFERER, referer);
if (!TextUtils.isEmpty(userAgent)) intent.putExtra(EXTRA_USERAGENT, userAgent);
if (!TextUtils.isEmpty(cookies)) intent.putExtra(EXTRA_COOKIES, cookies);
if (!TextUtils.isEmpty(fileName)) intent.putExtra(EXTRA_FILENAME, fileName);
} else {
ArrayList<String> urls = new ArrayList<>(urlAndFileNames.size());
ArrayList<String> names = new ArrayList<>(urlAndFileNames.size());
for (Map.Entry<String, String> entry : urlAndFileNames.entrySet()) {
if (TextUtils.isEmpty(entry.getKey())) continue;
urls.add(entry.getKey());
names.add(entry.getValue());
}
if (urls.size() > 0) {
intent.putExtra(EXTRA_URL_LIST, urls);
intent.putExtra(EXTRA_URL_FILENAME_LIST, names);
intent.setData(Uri.parse(urls.get(0)));
}
}
if (urls.size() > 0) {
intent.putExtra(EXTRA_URL_LIST, urls);
intent.putExtra(EXTRA_URL_FILENAME_LIST, names);
intent.setData(Uri.parse(urls.get(0)));
if (!isEmpty(headers)) {
Bundle extra = new Bundle();
for (Map.Entry<String, String> entry : headers.entrySet()) extra.putString(entry.getKey(), entry.getValue());
intent.putExtra(EXTRA_HEADERS, extra);
}
activity.startActivity(intent);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
if (!isEmpty(headers)) {
Bundle extra = new Bundle();
for (Map.Entry<String, String> entry : headers.entrySet()) extra.putString(entry.getKey(), entry.getValue());
intent.putExtra(EXTRA_HEADERS, extra);
}
activity.startActivity(intent);
return true;
}
public static void install1DM(String packageName, boolean update) {
}
private static <S, T> boolean isEmpty(Map<S, T> map) {

@ -479,6 +479,7 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
hideSheet();
});
mViewModel.ep.observe(this, episode -> {
Notify.progress(this);
Download.get().title(mBinding.name.getText() + "-" + episode.getName());
mViewModel.download(getKey(), getFlag().getFlag(), episode.getUrl());
});

@ -77,8 +77,7 @@ public class EpisodeFragment extends BaseFragment implements EpisodeAdapter.OnCl
@Override
public void onItemClick(Episode item) {
boolean download = getDownload();
if (download) mViewModel.setDownload(item);
if (getDownload()) mViewModel.setDownload(item);
else mViewModel.setEpisode(item);
}
}

Loading…
Cancel
Save