From 3d66c6572ba3c79cd7395f7404aa6ffad8eb0c2f Mon Sep 17 00:00:00 2001 From: "Andrei.Rosca" Date: Sun, 6 May 2018 10:08:56 +0200 Subject: [PATCH 1/3] prevent infinite loop --- .../java/org/schabi/newpipe/settings/SelectChannelFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java index 107f8b7f0..e961de969 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java @@ -159,7 +159,7 @@ public class SelectChannelFragment extends DialogFragment { @Override public void onError(Throwable exception) { - onError(exception); + SelectChannelFragment.this.onError(exception); } @Override From 0a596df49786daaeaaccf2f339a8a7441d2edb80 Mon Sep 17 00:00:00 2001 From: "Andrei.Rosca" Date: Sun, 6 May 2018 10:14:24 +0200 Subject: [PATCH 2/3] default ViewHolder --- .../org/schabi/newpipe/info_list/InfoListAdapter.java | 3 ++- .../org/schabi/newpipe/local/LocalItemListAdapter.java | 3 ++- .../newpipe/player/playqueue/PlayQueueAdapter.java | 3 ++- .../org/schabi/newpipe/util/FallbackViewHolder.java | 10 ++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/util/FallbackViewHolder.java diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java index 9b3405484..cf12deb6f 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java @@ -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.StreamInfoItemHolder; import org.schabi.newpipe.info_list.holder.StreamMiniInfoItemHolder; +import org.schabi.newpipe.util.FallbackViewHolder; import org.schabi.newpipe.util.OnClickGesture; import java.util.ArrayList; @@ -238,7 +239,7 @@ public class InfoListAdapter extends RecyclerView.Adapter Date: Sun, 6 May 2018 10:50:02 +0200 Subject: [PATCH 3/3] fix context leaks --- .../schabi/newpipe/about/LicenseFragment.java | 3 +- .../newpipe/about/LicenseFragmentHelper.java | 35 ++++++++++--- .../giga/ui/adapter/MissionAdapter.java | 50 +++++++++++++++---- .../giga/ui/fragment/MissionsFragment.java | 2 +- 4 files changed, 71 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java b/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java index 272e27240..4f6a69dcc 100644 --- a/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java +++ b/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.about; +import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -39,7 +40,7 @@ public class LicenseFragment extends Fragment { * @param license the license to show */ public static void showLicense(Context context, License license) { - new LicenseFragmentHelper().execute(context, license); + new LicenseFragmentHelper((Activity) context).execute(license); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java b/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java index 726e97ec2..e4436322a 100644 --- a/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java +++ b/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java @@ -1,8 +1,11 @@ package org.schabi.newpipe.about; +import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.os.AsyncTask; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v7.app.AlertDialog; import android.webkit.WebView; import org.schabi.newpipe.R; @@ -10,26 +13,46 @@ import org.schabi.newpipe.util.ThemeHelper; import java.io.BufferedReader; import java.io.InputStreamReader; +import java.lang.ref.WeakReference; public class LicenseFragmentHelper extends AsyncTask { - private Context context; + WeakReference weakReference; 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 protected Integer doInBackground(Object... objects) { - context = (Context) objects[0]; - license = (License) objects[1]; + license = (License) objects[0]; return 1; } @Override protected void onPostExecute(Integer result){ - String webViewData = getFormattedLicense(context, license); - AlertDialog.Builder alert = new AlertDialog.Builder(context); + Activity activity = getActivity(); + if (activity == null) { + return; + } + + String webViewData = getFormattedLicense(activity, license); + AlertDialog.Builder alert = new AlertDialog.Builder(activity); alert.setTitle(license.getName()); - WebView wv = new WebView(context); + WebView wv = new WebView(activity); wv.loadData(webViewData, "text/html; charset=UTF-8", null); alert.setView(wv); diff --git a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java index af25eaecb..12c81c127 100644 --- a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java +++ b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java @@ -1,11 +1,14 @@ package us.shandian.giga.ui.adapter; +import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; import android.os.Build; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.content.FileProvider; import android.support.v4.view.ViewCompat; import android.support.v7.widget.RecyclerView; @@ -24,6 +27,7 @@ import android.widget.Toast; import org.schabi.newpipe.R; import java.io.File; +import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -46,13 +50,13 @@ public class MissionAdapter extends RecyclerView.Adapter { + private static class ChecksumTask extends AsyncTask { ProgressDialog prog; + WeakReference weakReference; + + ChecksumTask(@NonNull Activity activity) { + weakReference = new WeakReference<>(activity); + } @Override protected void onPreExecute() { super.onPreExecute(); - // Create dialog - prog = new ProgressDialog(mContext); - prog.setCancelable(false); - prog.setMessage(mContext.getString(R.string.msg_wait)); - prog.show(); + Activity activity = getActivity(); + if (activity != null) { + // Create dialog + prog = new ProgressDialog(activity); + prog.setCancelable(false); + prog.setMessage(activity.getString(R.string.msg_wait)); + prog.show(); + } } @Override @@ -374,8 +386,24 @@ public class MissionAdapter extends RecyclerView.Adapter