commit
9eb5bf9b87
|
@ -1,5 +1,6 @@
|
||||||
package org.schabi.newpipe.about;
|
package org.schabi.newpipe.about;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -39,7 +40,7 @@ public class LicenseFragment extends Fragment {
|
||||||
* @param license the license to show
|
* @param license the license to show
|
||||||
*/
|
*/
|
||||||
public static void showLicense(Context context, License license) {
|
public static void showLicense(Context context, License license) {
|
||||||
new LicenseFragmentHelper().execute(context, license);
|
new LicenseFragmentHelper((Activity) context).execute(license);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package org.schabi.newpipe.about;
|
package org.schabi.newpipe.about;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
|
@ -10,26 +13,46 @@ import org.schabi.newpipe.util.ThemeHelper;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
public class LicenseFragmentHelper extends AsyncTask<Object, Void, Integer> {
|
public class LicenseFragmentHelper extends AsyncTask<Object, Void, Integer> {
|
||||||
|
|
||||||
private Context context;
|
WeakReference<Activity> weakReference;
|
||||||
private License license;
|
private License license;
|
||||||
|
|
||||||
|
public LicenseFragmentHelper(@Nullable Activity activity) {
|
||||||
|
weakReference = new WeakReference<>(activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Activity getActivity() {
|
||||||
|
Activity activity = weakReference.get();
|
||||||
|
|
||||||
|
if (activity != null && activity.isFinishing()) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return activity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Integer doInBackground(Object... objects) {
|
protected Integer doInBackground(Object... objects) {
|
||||||
context = (Context) objects[0];
|
license = (License) objects[0];
|
||||||
license = (License) objects[1];
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Integer result){
|
protected void onPostExecute(Integer result){
|
||||||
String webViewData = getFormattedLicense(context, license);
|
Activity activity = getActivity();
|
||||||
AlertDialog.Builder alert = new AlertDialog.Builder(context);
|
if (activity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String webViewData = getFormattedLicense(activity, license);
|
||||||
|
AlertDialog.Builder alert = new AlertDialog.Builder(activity);
|
||||||
alert.setTitle(license.getName());
|
alert.setTitle(license.getName());
|
||||||
|
|
||||||
WebView wv = new WebView(context);
|
WebView wv = new WebView(activity);
|
||||||
wv.loadData(webViewData, "text/html; charset=UTF-8", null);
|
wv.loadData(webViewData, "text/html; charset=UTF-8", null);
|
||||||
|
|
||||||
alert.setView(wv);
|
alert.setView(wv);
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.schabi.newpipe.info_list.holder.PlaylistInfoItemHolder;
|
||||||
import org.schabi.newpipe.info_list.holder.PlaylistMiniInfoItemHolder;
|
import org.schabi.newpipe.info_list.holder.PlaylistMiniInfoItemHolder;
|
||||||
import org.schabi.newpipe.info_list.holder.StreamInfoItemHolder;
|
import org.schabi.newpipe.info_list.holder.StreamInfoItemHolder;
|
||||||
import org.schabi.newpipe.info_list.holder.StreamMiniInfoItemHolder;
|
import org.schabi.newpipe.info_list.holder.StreamMiniInfoItemHolder;
|
||||||
|
import org.schabi.newpipe.util.FallbackViewHolder;
|
||||||
import org.schabi.newpipe.util.OnClickGesture;
|
import org.schabi.newpipe.util.OnClickGesture;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -238,7 +239,7 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||||
return new PlaylistInfoItemHolder(infoItemBuilder, parent);
|
return new PlaylistInfoItemHolder(infoItemBuilder, parent);
|
||||||
default:
|
default:
|
||||||
Log.e(TAG, "Trollolo");
|
Log.e(TAG, "Trollolo");
|
||||||
return null;
|
return new FallbackViewHolder(new View(parent.getContext()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.schabi.newpipe.local.holder.LocalPlaylistItemHolder;
|
||||||
import org.schabi.newpipe.local.holder.LocalPlaylistStreamItemHolder;
|
import org.schabi.newpipe.local.holder.LocalPlaylistStreamItemHolder;
|
||||||
import org.schabi.newpipe.local.holder.LocalStatisticStreamItemHolder;
|
import org.schabi.newpipe.local.holder.LocalStatisticStreamItemHolder;
|
||||||
import org.schabi.newpipe.local.holder.RemotePlaylistItemHolder;
|
import org.schabi.newpipe.local.holder.RemotePlaylistItemHolder;
|
||||||
|
import org.schabi.newpipe.util.FallbackViewHolder;
|
||||||
import org.schabi.newpipe.util.Localization;
|
import org.schabi.newpipe.util.Localization;
|
||||||
import org.schabi.newpipe.util.OnClickGesture;
|
import org.schabi.newpipe.util.OnClickGesture;
|
||||||
|
|
||||||
|
@ -225,7 +226,7 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||||
return new LocalStatisticStreamItemHolder(localItemBuilder, parent);
|
return new LocalStatisticStreamItemHolder(localItemBuilder, parent);
|
||||||
default:
|
default:
|
||||||
Log.e(TAG, "No view type has been considered for holder: [" + type + "]");
|
Log.e(TAG, "No view type has been considered for holder: [" + type + "]");
|
||||||
return null;
|
return new FallbackViewHolder(new View(parent.getContext()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.schabi.newpipe.player.playqueue.events.MoveEvent;
|
||||||
import org.schabi.newpipe.player.playqueue.events.PlayQueueEvent;
|
import org.schabi.newpipe.player.playqueue.events.PlayQueueEvent;
|
||||||
import org.schabi.newpipe.player.playqueue.events.RemoveEvent;
|
import org.schabi.newpipe.player.playqueue.events.RemoveEvent;
|
||||||
import org.schabi.newpipe.player.playqueue.events.SelectEvent;
|
import org.schabi.newpipe.player.playqueue.events.SelectEvent;
|
||||||
|
import org.schabi.newpipe.util.FallbackViewHolder;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -188,7 +189,7 @@ public class PlayQueueAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
return new PlayQueueItemHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.play_queue_item, parent, false));
|
return new PlayQueueItemHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.play_queue_item, parent, false));
|
||||||
default:
|
default:
|
||||||
Log.e(TAG, "Attempting to create view holder with undefined type: " + type);
|
Log.e(TAG, "Attempting to create view holder with undefined type: " + type);
|
||||||
return null;
|
return new FallbackViewHolder(new View(parent.getContext()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ public class SelectChannelFragment extends DialogFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable exception) {
|
public void onError(Throwable exception) {
|
||||||
onError(exception);
|
SelectChannelFragment.this.onError(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package org.schabi.newpipe.util;
|
||||||
|
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
public class FallbackViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
public FallbackViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,14 @@
|
||||||
package us.shandian.giga.ui.adapter;
|
package us.shandian.giga.ui.adapter;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.FileProvider;
|
import android.support.v4.content.FileProvider;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
@ -24,6 +27,7 @@ import android.widget.Toast;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -46,13 +50,13 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
|
||||||
ALGORITHMS.put(R.id.sha1, "SHA1");
|
ALGORITHMS.put(R.id.sha1, "SHA1");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Context mContext;
|
private Activity mContext;
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private DownloadManager mManager;
|
private DownloadManager mManager;
|
||||||
private DownloadManagerService.DMBinder mBinder;
|
private DownloadManagerService.DMBinder mBinder;
|
||||||
private int mLayout;
|
private int mLayout;
|
||||||
|
|
||||||
public MissionAdapter(Context context, DownloadManagerService.DMBinder binder, DownloadManager manager, boolean isLinear) {
|
public MissionAdapter(Activity context, DownloadManagerService.DMBinder binder, DownloadManager manager, boolean isLinear) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mManager = manager;
|
mManager = manager;
|
||||||
mBinder = binder;
|
mBinder = binder;
|
||||||
|
@ -247,7 +251,7 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
|
||||||
case R.id.md5:
|
case R.id.md5:
|
||||||
case R.id.sha1:
|
case R.id.sha1:
|
||||||
DownloadMission mission = mManager.getMission(h.position);
|
DownloadMission mission = mManager.getMission(h.position);
|
||||||
new ChecksumTask().execute(mission.location + "/" + mission.name, ALGORITHMS.get(id));
|
new ChecksumTask(mContext).execute(mission.location + "/" + mission.name, ALGORITHMS.get(id));
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -352,18 +356,26 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ChecksumTask extends AsyncTask<String, Void, String> {
|
private static class ChecksumTask extends AsyncTask<String, Void, String> {
|
||||||
ProgressDialog prog;
|
ProgressDialog prog;
|
||||||
|
WeakReference<Activity> weakReference;
|
||||||
|
|
||||||
|
ChecksumTask(@NonNull Activity activity) {
|
||||||
|
weakReference = new WeakReference<>(activity);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
super.onPreExecute();
|
super.onPreExecute();
|
||||||
|
|
||||||
// Create dialog
|
Activity activity = getActivity();
|
||||||
prog = new ProgressDialog(mContext);
|
if (activity != null) {
|
||||||
prog.setCancelable(false);
|
// Create dialog
|
||||||
prog.setMessage(mContext.getString(R.string.msg_wait));
|
prog = new ProgressDialog(activity);
|
||||||
prog.show();
|
prog.setCancelable(false);
|
||||||
|
prog.setMessage(activity.getString(R.string.msg_wait));
|
||||||
|
prog.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -374,8 +386,24 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(String result) {
|
protected void onPostExecute(String result) {
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
prog.dismiss();
|
|
||||||
Utility.copyToClipboard(mContext, result);
|
if (prog != null) {
|
||||||
|
Utility.copyToClipboard(prog.getContext(), result);
|
||||||
|
if (getActivity() != null) {
|
||||||
|
prog.dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Activity getActivity() {
|
||||||
|
Activity activity = weakReference.get();
|
||||||
|
|
||||||
|
if (activity != null && activity.isFinishing()) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return activity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ public abstract class MissionsFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateList() {
|
private void updateList() {
|
||||||
mAdapter = new MissionAdapter(mActivity, mBinder, mManager, mLinear);
|
mAdapter = new MissionAdapter((Activity) mActivity, mBinder, mManager, mLinear);
|
||||||
|
|
||||||
if (mLinear) {
|
if (mLinear) {
|
||||||
mList.setLayoutManager(mLinearManager);
|
mList.setLayoutManager(mLinearManager);
|
||||||
|
|
Loading…
Reference in New Issue