mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-26 10:00:39 +00:00
Added drawer menu
This commit is contained in:
parent
72fa18742e
commit
c9b267b072
@ -49,12 +49,15 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.fragments.BackPressable;
|
import org.schabi.newpipe.fragments.BackPressable;
|
||||||
import org.schabi.newpipe.fragments.MainFragment;
|
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.search.SearchFragment;
|
import org.schabi.newpipe.fragments.list.search.SearchFragment;
|
||||||
import org.schabi.newpipe.report.ErrorActivity;
|
import org.schabi.newpipe.report.ErrorActivity;
|
||||||
|
import org.schabi.newpipe.report.UserAction;
|
||||||
import org.schabi.newpipe.util.Constants;
|
import org.schabi.newpipe.util.Constants;
|
||||||
|
import org.schabi.newpipe.util.KioskTranslator;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
import org.schabi.newpipe.util.PermissionHelper;
|
import org.schabi.newpipe.util.PermissionHelper;
|
||||||
import org.schabi.newpipe.util.ServiceHelper;
|
import org.schabi.newpipe.util.ServiceHelper;
|
||||||
@ -88,22 +91,68 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setSupportActionBar(findViewById(R.id.toolbar));
|
setSupportActionBar(findViewById(R.id.toolbar));
|
||||||
|
try {
|
||||||
setupDrawer();
|
setupDrawer();
|
||||||
|
} catch (Exception e) {
|
||||||
|
ErrorActivity.reportUiError(this, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDrawer() {
|
private void setupDrawer() throws Exception {
|
||||||
final Toolbar toolbar = findViewById(R.id.toolbar);
|
final Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
drawer = findViewById(R.id.drawer_layout);
|
drawer = findViewById(R.id.drawer_layout);
|
||||||
drawerItems = findViewById(R.id.navigation);
|
drawerItems = findViewById(R.id.navigation);
|
||||||
|
|
||||||
|
//Services
|
||||||
|
|
||||||
for(StreamingService s : NewPipe.getServices()) {
|
for(StreamingService s : NewPipe.getServices()) {
|
||||||
final String title = s.getServiceInfo().getName() +
|
final String title = s.getServiceInfo().getName() +
|
||||||
(ServiceHelper.isBeta(s) ? " (beta)" : "");
|
(ServiceHelper.isBeta(s) ? " (beta)" : "");
|
||||||
final MenuItem item = drawerItems.getMenu()
|
|
||||||
.add(R.id.menu_services_group, s.getServiceId(), 0, title);
|
drawerItems.getMenu()
|
||||||
item.setIcon(ServiceHelper.getIcon(s.getServiceId()));
|
.add(R.id.menu_services_group, s.getServiceId(), 0, title)
|
||||||
|
.setIcon(ServiceHelper.getIcon(s.getServiceId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Tabs
|
||||||
|
|
||||||
|
int currentServiceId = ServiceHelper.getSelectedServiceId(this);
|
||||||
|
StreamingService service = NewPipe.getService(currentServiceId);
|
||||||
|
|
||||||
|
int kioskId = 0;
|
||||||
|
|
||||||
|
for (final String ks : service.getKioskList().getAvailableKiosks()) {
|
||||||
|
drawerItems.getMenu()
|
||||||
|
.add(R.id.menu_tabs_group, kioskId, 0, KioskTranslator.getTranslatedKioskName(ks, this))
|
||||||
|
.setIcon(KioskTranslator.getKioskIcons(ks, this));
|
||||||
|
kioskId ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawerItems.getMenu()
|
||||||
|
.add(R.id.menu_tabs_group, -1, 0, R.string.tab_subscriptions)
|
||||||
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_channel));
|
||||||
|
drawerItems.getMenu()
|
||||||
|
.add(R.id.menu_tabs_group, -2, 0, R.string.fragment_whats_new)
|
||||||
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.rss));
|
||||||
|
drawerItems.getMenu()
|
||||||
|
.add(R.id.menu_tabs_group, -3, 0, R.string.tab_bookmarks)
|
||||||
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_bookmark));
|
||||||
|
drawerItems.getMenu()
|
||||||
|
.add(R.id.menu_tabs_group, -4, 0, R.string.downloads)
|
||||||
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.download));
|
||||||
|
drawerItems.getMenu()
|
||||||
|
.add(R.id.menu_tabs_group, -5, 0, R.string.action_history)
|
||||||
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.history));
|
||||||
|
|
||||||
|
//Settings and About
|
||||||
|
|
||||||
|
drawerItems.getMenu()
|
||||||
|
.add(R.id.menu_options_about_group, 0, 0, R.string.settings)
|
||||||
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.settings));
|
||||||
|
drawerItems.getMenu()
|
||||||
|
.add(R.id.menu_options_about_group, 1, 0, R.string.tab_about)
|
||||||
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.info));
|
||||||
|
|
||||||
|
|
||||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
||||||
|
|
||||||
@ -126,34 +175,84 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
drawerItems.setNavigationItemSelectedListener(this::changeService);
|
drawerItems.setNavigationItemSelectedListener(this::drawerItemSelected);
|
||||||
|
|
||||||
setupDrawerFooter();
|
|
||||||
setupDrawerHeader();
|
setupDrawerHeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean changeService(MenuItem item) {
|
private boolean drawerItemSelected(MenuItem item) {
|
||||||
if (item.getGroupId() == R.id.menu_services_group) {
|
switch (item.getGroupId()) {
|
||||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(false);
|
case R.id.menu_services_group:
|
||||||
ServiceHelper.setSelectedServiceId(this, item.getItemId());
|
changeService(item);
|
||||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
break;
|
||||||
} else {
|
case R.id.menu_tabs_group:
|
||||||
|
try {
|
||||||
|
tabSelected(item);
|
||||||
|
} catch (Exception e) {
|
||||||
|
ErrorActivity.reportUiError(this, e);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case R.id.menu_options_about_group:
|
||||||
|
optionsAboutSelected(item);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawer.closeDrawers();
|
drawer.closeDrawers();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDrawerFooter() {
|
private void changeService(MenuItem item) {
|
||||||
ImageButton settings = findViewById(R.id.drawer_settings);
|
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(false);
|
||||||
ImageButton downloads = findViewById(R.id.drawer_downloads);
|
ServiceHelper.setSelectedServiceId(this, item.getItemId());
|
||||||
ImageButton history = findViewById(R.id.drawer_history);
|
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
settings.setOnClickListener(view -> NavigationHelper.openSettings(this));
|
private void tabSelected(MenuItem item) throws ExtractionException {
|
||||||
downloads.setOnClickListener(view ->NavigationHelper.openDownloads(this));
|
switch(item.getItemId()) {
|
||||||
history.setOnClickListener(view ->
|
case -1:
|
||||||
NavigationHelper.openStatisticFragment(getSupportFragmentManager()));
|
NavigationHelper.openSubscriptionFragment(getSupportFragmentManager());
|
||||||
|
break;
|
||||||
|
case -2:
|
||||||
|
NavigationHelper.openWhatsNewFragment(getSupportFragmentManager());
|
||||||
|
break;
|
||||||
|
case -3:
|
||||||
|
NavigationHelper.openBookmarksFragment(getSupportFragmentManager());
|
||||||
|
break;
|
||||||
|
case -4:
|
||||||
|
NavigationHelper.openDownloads(this);
|
||||||
|
break;
|
||||||
|
case -5:
|
||||||
|
NavigationHelper.openStatisticFragment(getSupportFragmentManager());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
int currentServiceId = ServiceHelper.getSelectedServiceId(this);
|
||||||
|
StreamingService service = NewPipe.getService(currentServiceId);
|
||||||
|
String serviceName = "";
|
||||||
|
|
||||||
|
int kioskId = 0;
|
||||||
|
for (final String ks : service.getKioskList().getAvailableKiosks()) {
|
||||||
|
if(kioskId == item.getItemId()) {
|
||||||
|
serviceName = ks;
|
||||||
|
}
|
||||||
|
kioskId ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
NavigationHelper.openKioskFragment(getSupportFragmentManager(), currentServiceId, serviceName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void optionsAboutSelected(MenuItem item) {
|
||||||
|
switch(item.getItemId()) {
|
||||||
|
case 0:
|
||||||
|
NavigationHelper.openSettings(this);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
NavigationHelper.openAbout(this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDrawerHeader() {
|
private void setupDrawerHeader() {
|
||||||
|
@ -99,9 +99,15 @@ public final class BookmarkFragment
|
|||||||
itemListAdapter.setSelectedListener(new OnClickGesture<LocalItem>() {
|
itemListAdapter.setSelectedListener(new OnClickGesture<LocalItem>() {
|
||||||
@Override
|
@Override
|
||||||
public void selected(LocalItem selectedItem) {
|
public void selected(LocalItem selectedItem) {
|
||||||
// Requires the parent fragment to find holder for fragment replacement
|
|
||||||
if (getParentFragment() == null) return;
|
FragmentManager fragmentManager;
|
||||||
final FragmentManager fragmentManager = getParentFragment().getFragmentManager();
|
|
||||||
|
if (getParentFragment() == null)
|
||||||
|
{
|
||||||
|
fragmentManager = getFragmentManager();
|
||||||
|
} else {
|
||||||
|
fragmentManager = getParentFragment().getFragmentManager();
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedItem instanceof PlaylistMetadataEntry) {
|
if (selectedItem instanceof PlaylistMetadataEntry) {
|
||||||
final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem);
|
final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem);
|
||||||
|
@ -24,7 +24,7 @@ import org.schabi.newpipe.R;
|
|||||||
|
|
||||||
public class KioskTranslator {
|
public class KioskTranslator {
|
||||||
public static String getTranslatedKioskName(String kioskId, Context c) {
|
public static String getTranslatedKioskName(String kioskId, Context c) {
|
||||||
switch(kioskId) {
|
switch (kioskId) {
|
||||||
case "Trending":
|
case "Trending":
|
||||||
return c.getString(R.string.trending);
|
return c.getString(R.string.trending);
|
||||||
case "Top 50":
|
case "Top 50":
|
||||||
@ -35,4 +35,17 @@ public class KioskTranslator {
|
|||||||
return kioskId;
|
return kioskId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getKioskIcons(String kioskId, Context c) {
|
||||||
|
switch(kioskId) {
|
||||||
|
case "Trending":
|
||||||
|
return ThemeHelper.resolveResourceIdFromAttr(c, R.attr.ic_hot);
|
||||||
|
case "Top 50":
|
||||||
|
return ThemeHelper.resolveResourceIdFromAttr(c, R.attr.ic_hot);
|
||||||
|
case "New & hot":
|
||||||
|
return ThemeHelper.resolveResourceIdFromAttr(c, R.attr.ic_hot);
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,14 @@ import org.schabi.newpipe.extractor.stream.VideoStream;
|
|||||||
import org.schabi.newpipe.fragments.MainFragment;
|
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.local.bookmark.BookmarkFragment;
|
||||||
import org.schabi.newpipe.local.feed.FeedFragment;
|
import org.schabi.newpipe.local.feed.FeedFragment;
|
||||||
import org.schabi.newpipe.fragments.list.kiosk.KioskFragment;
|
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.local.history.StatisticsPlaylistFragment;
|
import org.schabi.newpipe.local.history.StatisticsPlaylistFragment;
|
||||||
import org.schabi.newpipe.local.playlist.LocalPlaylistFragment;
|
import org.schabi.newpipe.local.playlist.LocalPlaylistFragment;
|
||||||
|
import org.schabi.newpipe.local.subscription.SubscriptionFragment;
|
||||||
import org.schabi.newpipe.local.subscription.SubscriptionsImportFragment;
|
import org.schabi.newpipe.local.subscription.SubscriptionsImportFragment;
|
||||||
import org.schabi.newpipe.player.BackgroundPlayer;
|
import org.schabi.newpipe.player.BackgroundPlayer;
|
||||||
import org.schabi.newpipe.player.BackgroundPlayerActivity;
|
import org.schabi.newpipe.player.BackgroundPlayerActivity;
|
||||||
@ -335,6 +337,20 @@ public class NavigationHelper {
|
|||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void openBookmarksFragment(FragmentManager fragmentManager) {
|
||||||
|
defaultTransaction(fragmentManager)
|
||||||
|
.replace(R.id.fragment_holder, new BookmarkFragment())
|
||||||
|
.addToBackStack(null)
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openSubscriptionFragment(FragmentManager fragmentManager) {
|
||||||
|
defaultTransaction(fragmentManager)
|
||||||
|
.replace(R.id.fragment_holder, new SubscriptionFragment())
|
||||||
|
.addToBackStack(null)
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
|
||||||
public static void openKioskFragment(FragmentManager fragmentManager, int serviceId, String kioskId) throws ExtractionException {
|
public static void openKioskFragment(FragmentManager fragmentManager, int serviceId, String kioskId) throws ExtractionException {
|
||||||
defaultTransaction(fragmentManager)
|
defaultTransaction(fragmentManager)
|
||||||
.replace(R.id.fragment_holder, KioskFragment.getInstance(serviceId, kioskId))
|
.replace(R.id.fragment_holder, KioskFragment.getInstance(serviceId, kioskId))
|
||||||
|
@ -89,29 +89,6 @@
|
|||||||
android:layout_alignEnd="@id/navigation"
|
android:layout_alignEnd="@id/navigation"
|
||||||
|
|
||||||
android:layout_alignParentBottom="true">
|
android:layout_alignParentBottom="true">
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/drawer_settings"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
|
||||||
android:src="?attr/settings"/>
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/drawer_downloads"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
|
||||||
android:src="?attr/download" />
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/drawer_history"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
|
||||||
android:src="?attr/history"/>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
@ -2,13 +2,11 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<group
|
<group
|
||||||
android:id="@+id/menu_services_group">
|
android:id="@+id/menu_services_group">
|
||||||
<item
|
</group>
|
||||||
android:id="@+id/menu_service_youtube"
|
<group
|
||||||
android:icon="@drawable/place_holder_youtube"
|
android:id="@+id/menu_tabs_group">
|
||||||
android:title="@string/youtube"/>
|
</group>
|
||||||
<item
|
<group
|
||||||
android:id="@+id/menu_service_soundcloud"
|
android:id="@+id/menu_options_about_group">
|
||||||
android:icon="@drawable/place_holder_circle"
|
|
||||||
android:title="@string/soundcloud"/>
|
|
||||||
</group>
|
</group>
|
||||||
</menu>
|
</menu>
|
Loading…
Reference in New Issue
Block a user