mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 07:13:00 +00:00 
			
		
		
		
	add menu to select kiosk of current service
This commit is contained in:
		| @@ -15,17 +15,22 @@ import android.view.LayoutInflater; | |||||||
| import android.view.Menu; | import android.view.Menu; | ||||||
| import android.view.MenuInflater; | import android.view.MenuInflater; | ||||||
| import android.view.MenuItem; | import android.view.MenuItem; | ||||||
|  | import android.view.SubMenu; | ||||||
| import android.view.View; | import android.view.View; | ||||||
| import android.view.ViewGroup; | import android.view.ViewGroup; | ||||||
|  |  | ||||||
| import org.schabi.newpipe.BaseFragment; | import org.schabi.newpipe.BaseFragment; | ||||||
| import org.schabi.newpipe.R; | import org.schabi.newpipe.R; | ||||||
|  | import org.schabi.newpipe.extractor.NewPipe; | ||||||
|  | import org.schabi.newpipe.extractor.StreamingService; | ||||||
|  | import org.schabi.newpipe.extractor.kiosk.KioskList; | ||||||
| import org.schabi.newpipe.fragments.list.channel.ChannelFragment; | import org.schabi.newpipe.fragments.list.channel.ChannelFragment; | ||||||
| import org.schabi.newpipe.fragments.list.feed.FeedFragment; | import org.schabi.newpipe.fragments.list.feed.FeedFragment; | ||||||
| import org.schabi.newpipe.fragments.list.kiosk.KioskFragment; | import org.schabi.newpipe.fragments.list.kiosk.KioskFragment; | ||||||
| import org.schabi.newpipe.fragments.subscription.SubscriptionFragment; | import org.schabi.newpipe.fragments.subscription.SubscriptionFragment; | ||||||
| import org.schabi.newpipe.report.ErrorActivity; | import org.schabi.newpipe.report.ErrorActivity; | ||||||
| import org.schabi.newpipe.report.UserAction; | import org.schabi.newpipe.report.UserAction; | ||||||
|  | import org.schabi.newpipe.util.KioskTranslator; | ||||||
| import org.schabi.newpipe.util.NavigationHelper; | import org.schabi.newpipe.util.NavigationHelper; | ||||||
|  |  | ||||||
| import java.util.concurrent.ExecutionException; | import java.util.concurrent.ExecutionException; | ||||||
| @@ -36,6 +41,12 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte | |||||||
|  |  | ||||||
|     public int currentServiceId = -1; |     public int currentServiceId = -1; | ||||||
|  |  | ||||||
|  |     /*////////////////////////////////////////////////////////////////////////// | ||||||
|  |     // Konst | ||||||
|  |     //////////////////////////////////////////////////////////////////////////*/ | ||||||
|  |  | ||||||
|  |     private static final int KIOSK_MENU_OFFSETT = 2000; | ||||||
|  |  | ||||||
|     /*////////////////////////////////////////////////////////////////////////// |     /*////////////////////////////////////////////////////////////////////////// | ||||||
|     // Fragment's LifeCycle |     // Fragment's LifeCycle | ||||||
|     //////////////////////////////////////////////////////////////////////////*/ |     //////////////////////////////////////////////////////////////////////////*/ | ||||||
| @@ -77,6 +88,16 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte | |||||||
|         super.onCreateOptionsMenu(menu, inflater); |         super.onCreateOptionsMenu(menu, inflater); | ||||||
|         if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "], inflater = [" + inflater + "]"); |         if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "], inflater = [" + inflater + "]"); | ||||||
|         inflater.inflate(R.menu.main_fragment_menu, menu); |         inflater.inflate(R.menu.main_fragment_menu, menu); | ||||||
|  |         SubMenu kioskMenu = menu.addSubMenu(getString(R.string.kiosk)); | ||||||
|  |         try { | ||||||
|  |             createKioskMenu(kioskMenu, inflater); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             ErrorActivity.reportError(activity, e, | ||||||
|  |                     activity.getClass(), | ||||||
|  |                     null, | ||||||
|  |                     ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, | ||||||
|  |                             "none", "", R.string.app_ui_crash)); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         ActionBar supportActionBar = activity.getSupportActionBar(); |         ActionBar supportActionBar = activity.getSupportActionBar(); | ||||||
|         if (supportActionBar != null) { |         if (supportActionBar != null) { | ||||||
| @@ -202,8 +223,33 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /*////////////////////////////////////////////////////////////////////////// |     /*////////////////////////////////////////////////////////////////////////// | ||||||
|     // Main page content |     // Select Kiosk | ||||||
|     //////////////////////////////////////////////////////////////////////////*/ |     //////////////////////////////////////////////////////////////////////////*/ | ||||||
|  |  | ||||||
|  |     private void createKioskMenu(Menu menu, MenuInflater menuInflater) | ||||||
|  |             throws Exception { | ||||||
|  |         StreamingService service = NewPipe.getService(currentServiceId); | ||||||
|  |         KioskList kl = service.getKioskList(); | ||||||
|  |         int i = 0; | ||||||
|  |         for(final String ks : kl.getAvailableKisoks()) { | ||||||
|  |             menu.add(0, KIOSK_MENU_OFFSETT + i, Menu.NONE, | ||||||
|  |                     KioskTranslator.getTranslatedKioskName(ks, getContext())) | ||||||
|  |                     .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { | ||||||
|  |                         @Override | ||||||
|  |                         public boolean onMenuItemClick(MenuItem menuItem) { | ||||||
|  |                             try { | ||||||
|  |                                 NavigationHelper.openKioskFragment(getFragmentManager(), currentServiceId, ks); | ||||||
|  |                             } catch (Exception e) { | ||||||
|  |                                 ErrorActivity.reportError(activity, e, | ||||||
|  |                                         activity.getClass(), | ||||||
|  |                                         null, | ||||||
|  |                                         ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, | ||||||
|  |                                                 "none", "", R.string.app_ui_crash)); | ||||||
|  |                             } | ||||||
|  |                             return true; | ||||||
|  |                         } | ||||||
|  |                     }); | ||||||
|  |             i++; | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -62,14 +62,20 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> { | |||||||
|  |  | ||||||
|     public static KioskFragment getInstance(int serviceId) |     public static KioskFragment getInstance(int serviceId) | ||||||
|             throws ExtractionException { |             throws ExtractionException { | ||||||
|  |         return getInstance(serviceId, NewPipe.getService(serviceId) | ||||||
|  |                 .getKioskList() | ||||||
|  |                 .getDefaultKioskId()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static KioskFragment getInstance(int serviceId, String kioskId) | ||||||
|  |             throws ExtractionException { | ||||||
|         KioskFragment instance = new KioskFragment(); |         KioskFragment instance = new KioskFragment(); | ||||||
|         StreamingService service = NewPipe.getService(serviceId); |         StreamingService service = NewPipe.getService(serviceId); | ||||||
|         String defaultKioskId = service.getKioskList().getDefaultKioskId(); |         UrlIdHandler kioskTypeUrlIdHandler = service.getKioskList() | ||||||
|         UrlIdHandler defaultKioskTypeUrlIdHandler = service.getKioskList() |                 .getUrlIdHandlerByType(kioskId); | ||||||
|                 .getUrlIdHandlerByType(defaultKioskId); |  | ||||||
|         instance.setInitialData(serviceId, |         instance.setInitialData(serviceId, | ||||||
|                 defaultKioskTypeUrlIdHandler.getUrl(defaultKioskId), |                 kioskTypeUrlIdHandler.getUrl(kioskId), | ||||||
|                 defaultKioskId); |                 kioskId); | ||||||
|         return instance; |         return instance; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ import org.schabi.newpipe.fragments.MainFragment; | |||||||
| import org.schabi.newpipe.fragments.detail.VideoDetailFragment; | import org.schabi.newpipe.fragments.detail.VideoDetailFragment; | ||||||
| import org.schabi.newpipe.fragments.list.channel.ChannelFragment; | import org.schabi.newpipe.fragments.list.channel.ChannelFragment; | ||||||
| import org.schabi.newpipe.fragments.list.feed.FeedFragment; | import org.schabi.newpipe.fragments.list.feed.FeedFragment; | ||||||
|  | import org.schabi.newpipe.fragments.list.kiosk.KioskFragment; | ||||||
| import org.schabi.newpipe.fragments.list.playlist.PlaylistFragment; | import org.schabi.newpipe.fragments.list.playlist.PlaylistFragment; | ||||||
| import org.schabi.newpipe.fragments.list.search.SearchFragment; | import org.schabi.newpipe.fragments.list.search.SearchFragment; | ||||||
| import org.schabi.newpipe.history.HistoryActivity; | import org.schabi.newpipe.history.HistoryActivity; | ||||||
| @@ -163,6 +164,15 @@ public class NavigationHelper { | |||||||
|                 .commit(); |                 .commit(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static void openKioskFragment(FragmentManager fragmentManager, int serviceId, String kioskId) | ||||||
|  |         throws ExtractionException { | ||||||
|  |         fragmentManager.beginTransaction() | ||||||
|  |                 .setCustomAnimations(R.animator.custom_fade_in, R.animator.custom_fade_out, R.animator.custom_fade_in, R.animator.custom_fade_out) | ||||||
|  |                 .replace(R.id.fragment_holder, KioskFragment.getInstance(serviceId, kioskId)) | ||||||
|  |                 .addToBackStack(null) | ||||||
|  |                 .commit(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /*////////////////////////////////////////////////////////////////////////// |     /*////////////////////////////////////////////////////////////////////////// | ||||||
|     // Through Intents |     // Through Intents | ||||||
|     //////////////////////////////////////////////////////////////////////////*/ |     //////////////////////////////////////////////////////////////////////////*/ | ||||||
|   | |||||||
| @@ -284,6 +284,7 @@ | |||||||
|     <string name="no_channel_subscribed_yet">No channel subscribed yet</string> |     <string name="no_channel_subscribed_yet">No channel subscribed yet</string> | ||||||
|  |  | ||||||
|     <!-- Kiosk Names --> |     <!-- Kiosk Names --> | ||||||
|  |     <string name="kiosk">Kisok</string> | ||||||
|     <string name="trending">Trending</string> |     <string name="trending">Trending</string> | ||||||
|     <string name="top_50">Top 50</string> |     <string name="top_50">Top 50</string> | ||||||
|     <string name="new_and_hot">New & hot</string> |     <string name="new_and_hot">New & hot</string> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Christian Schabesberger
					Christian Schabesberger