mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-30 23:03:00 +00:00 
			
		
		
		
	Restore license pop up after orientation change
This commit is contained in:
		| @@ -4,10 +4,12 @@ import android.net.Uri; | |||||||
| import android.os.Parcel; | import android.os.Parcel; | ||||||
| import android.os.Parcelable; | import android.os.Parcelable; | ||||||
|  |  | ||||||
|  | import java.io.Serializable; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Class for storing information about a software license. |  * Class for storing information about a software license. | ||||||
|  */ |  */ | ||||||
| public class License implements Parcelable { | public class License implements Parcelable, Serializable { | ||||||
|     public static final Creator<License> CREATOR = new Creator<License>() { |     public static final Creator<License> CREATOR = new Creator<License>() { | ||||||
|         @Override |         @Override | ||||||
|         public License createFromParcel(final Parcel source) { |         public License createFromParcel(final Parcel source) { | ||||||
|   | |||||||
| @@ -1,7 +1,6 @@ | |||||||
| package org.schabi.newpipe.about; | package org.schabi.newpipe.about; | ||||||
|  |  | ||||||
| import android.app.Activity; | import android.app.Activity; | ||||||
| import android.content.Context; |  | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| import android.view.ContextMenu; | import android.view.ContextMenu; | ||||||
| import android.view.LayoutInflater; | import android.view.LayoutInflater; | ||||||
| @@ -11,12 +10,14 @@ import android.view.View; | |||||||
| import android.view.ViewGroup; | import android.view.ViewGroup; | ||||||
| import android.widget.TextView; | import android.widget.TextView; | ||||||
|  |  | ||||||
|  | import androidx.annotation.NonNull; | ||||||
| import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||||
| import androidx.fragment.app.Fragment; | import androidx.fragment.app.Fragment; | ||||||
|  |  | ||||||
| import org.schabi.newpipe.R; | import org.schabi.newpipe.R; | ||||||
| import org.schabi.newpipe.util.ShareUtils; | import org.schabi.newpipe.util.ShareUtils; | ||||||
|  |  | ||||||
|  | import java.io.Serializable; | ||||||
| import java.util.Arrays; | import java.util.Arrays; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -26,6 +27,8 @@ public class LicenseFragment extends Fragment { | |||||||
|     private static final String ARG_COMPONENTS = "components"; |     private static final String ARG_COMPONENTS = "components"; | ||||||
|     private SoftwareComponent[] softwareComponents; |     private SoftwareComponent[] softwareComponents; | ||||||
|     private SoftwareComponent componentForContextMenu; |     private SoftwareComponent componentForContextMenu; | ||||||
|  |     private License activeLicense; | ||||||
|  |     private static final String LICENSE_KEY = "ACTIVE_LICENSE"; | ||||||
|  |  | ||||||
|     public static LicenseFragment newInstance(final SoftwareComponent[] softwareComponents) { |     public static LicenseFragment newInstance(final SoftwareComponent[] softwareComponents) { | ||||||
|         if (softwareComponents == null) { |         if (softwareComponents == null) { | ||||||
| @@ -44,8 +47,8 @@ public class LicenseFragment extends Fragment { | |||||||
|      * @param context the context to use |      * @param context the context to use | ||||||
|      * @param license the license to show |      * @param license the license to show | ||||||
|      */ |      */ | ||||||
|     private static void showLicense(final Context context, final License license) { |     private static void showLicense(final Activity context, final License license) { | ||||||
|         new LicenseFragmentHelper((Activity) context).execute(license); |         new LicenseFragmentHelper(context).execute(license); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
| @@ -54,6 +57,12 @@ public class LicenseFragment extends Fragment { | |||||||
|         softwareComponents = (SoftwareComponent[]) getArguments() |         softwareComponents = (SoftwareComponent[]) getArguments() | ||||||
|                 .getParcelableArray(ARG_COMPONENTS); |                 .getParcelableArray(ARG_COMPONENTS); | ||||||
|  |  | ||||||
|  |         if (savedInstanceState != null) { | ||||||
|  |             final Serializable license = savedInstanceState.getSerializable(LICENSE_KEY); | ||||||
|  |             if (license != null) { | ||||||
|  |                 activeLicense = (License) license; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|         // Sort components by name |         // Sort components by name | ||||||
|         Arrays.sort(softwareComponents, (o1, o2) -> o1.getName().compareTo(o2.getName())); |         Arrays.sort(softwareComponents, (o1, o2) -> o1.getName().compareTo(o2.getName())); | ||||||
|     } |     } | ||||||
| @@ -66,8 +75,10 @@ public class LicenseFragment extends Fragment { | |||||||
|         final ViewGroup softwareComponentsView = rootView.findViewById(R.id.software_components); |         final ViewGroup softwareComponentsView = rootView.findViewById(R.id.software_components); | ||||||
|  |  | ||||||
|         final View licenseLink = rootView.findViewById(R.id.app_read_license); |         final View licenseLink = rootView.findViewById(R.id.app_read_license); | ||||||
|         licenseLink.setOnClickListener(v -> |         licenseLink.setOnClickListener(v -> { | ||||||
|                 showLicense(getActivity(), StandardLicenses.GPL3)); |                 activeLicense = StandardLicenses.GPL3; | ||||||
|  |                 showLicense(getActivity(), StandardLicenses.GPL3); | ||||||
|  |         }); | ||||||
|  |  | ||||||
|         for (final SoftwareComponent component : softwareComponents) { |         for (final SoftwareComponent component : softwareComponents) { | ||||||
|             final View componentView = inflater |             final View componentView = inflater | ||||||
| @@ -81,11 +92,16 @@ public class LicenseFragment extends Fragment { | |||||||
|                     component.getLicense().getAbbreviation())); |                     component.getLicense().getAbbreviation())); | ||||||
|  |  | ||||||
|             componentView.setTag(component); |             componentView.setTag(component); | ||||||
|             componentView.setOnClickListener(v -> |             componentView.setOnClickListener(v -> { | ||||||
|                     showLicense(getActivity(), component.getLicense())); |                 activeLicense = component.getLicense(); | ||||||
|  |                 showLicense(getActivity(), component.getLicense()); | ||||||
|  |             }); | ||||||
|             softwareComponentsView.addView(componentView); |             softwareComponentsView.addView(componentView); | ||||||
|             registerForContextMenu(componentView); |             registerForContextMenu(componentView); | ||||||
|         } |         } | ||||||
|  |         if (activeLicense != null) { | ||||||
|  |             showLicense(getActivity(), activeLicense); | ||||||
|  |         } | ||||||
|         return rootView; |         return rootView; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -101,7 +117,7 @@ public class LicenseFragment extends Fragment { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public boolean onContextItemSelected(final MenuItem item) { |     public boolean onContextItemSelected(@NonNull final MenuItem item) { | ||||||
|         // item.getMenuInfo() is null so we use the tag of the view |         // item.getMenuInfo() is null so we use the tag of the view | ||||||
|         final SoftwareComponent component = componentForContextMenu; |         final SoftwareComponent component = componentForContextMenu; | ||||||
|         if (component == null) { |         if (component == null) { | ||||||
| @@ -116,4 +132,12 @@ public class LicenseFragment extends Fragment { | |||||||
|         } |         } | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public void onSaveInstanceState(@NonNull final Bundle savedInstanceState) { | ||||||
|  |         super.onSaveInstanceState(savedInstanceState); | ||||||
|  |         if (activeLicense != null) { | ||||||
|  |             savedInstanceState.putSerializable(LICENSE_KEY, activeLicense); | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 nmurali94
					nmurali94