2017-04-09 19:34:00 +02:00
|
|
|
/*
|
2016-08-02 15:06:02 +02:00
|
|
|
* Created by Christian Schabesberger on 02.08.16.
|
2017-04-09 19:34:00 +02:00
|
|
|
* <p>
|
2016-09-12 00:33:11 +02:00
|
|
|
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
|
2016-09-27 21:33:26 +02:00
|
|
|
* DownloadActivity.java is part of NewPipe.
|
2017-04-09 19:34:00 +02:00
|
|
|
* <p>
|
2016-09-12 00:33:11 +02:00
|
|
|
* NewPipe is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2017-04-09 19:34:00 +02:00
|
|
|
* <p>
|
2016-09-12 00:33:11 +02:00
|
|
|
* NewPipe is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2017-04-09 19:34:00 +02:00
|
|
|
* <p>
|
2016-09-12 00:33:11 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
2016-08-02 15:06:02 +02:00
|
|
|
*/
|
2016-08-02 01:26:12 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
package org.schabi.newpipe;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
2017-06-05 21:33:01 +02:00
|
|
|
import android.content.SharedPreferences;
|
2018-04-06 23:19:45 +02:00
|
|
|
import android.content.pm.PackageManager;
|
2018-06-14 01:55:55 +02:00
|
|
|
import android.os.Build;
|
2017-04-09 19:34:00 +02:00
|
|
|
import android.os.Bundle;
|
2017-09-03 08:04:18 +02:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
2017-06-05 21:33:01 +02:00
|
|
|
import android.preference.PreferenceManager;
|
2017-04-26 21:32:04 +02:00
|
|
|
import android.util.Log;
|
2019-11-24 16:38:06 +01:00
|
|
|
import android.view.LayoutInflater;
|
2017-04-09 19:34:00 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2017-04-26 21:32:04 +02:00
|
|
|
import android.view.View;
|
2020-04-10 15:31:28 +02:00
|
|
|
import android.view.ViewGroup;
|
2018-06-14 01:55:55 +02:00
|
|
|
import android.view.Window;
|
|
|
|
import android.view.WindowManager;
|
2019-11-24 16:38:06 +01:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ArrayAdapter;
|
2018-02-16 14:45:52 +01:00
|
|
|
import android.widget.Button;
|
2018-06-14 03:29:49 +02:00
|
|
|
import android.widget.ImageView;
|
2019-11-24 16:38:06 +01:00
|
|
|
import android.widget.Spinner;
|
2018-02-16 23:56:04 +01:00
|
|
|
import android.widget.TextView;
|
2017-04-09 19:34:00 +02:00
|
|
|
|
2019-10-08 06:36:29 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.ActionBarDrawerToggle;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
import androidx.core.view.GravityCompat;
|
|
|
|
import androidx.drawerlayout.widget.DrawerLayout;
|
|
|
|
import androidx.fragment.app.Fragment;
|
2019-11-24 16:38:06 +01:00
|
|
|
import androidx.fragment.app.FragmentManager;
|
2019-10-08 06:36:29 +02:00
|
|
|
|
|
|
|
import com.google.android.material.navigation.NavigationView;
|
|
|
|
|
2018-02-19 21:04:13 +01:00
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
2017-04-09 19:34:00 +02:00
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
2018-06-08 21:07:25 +02:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
2019-11-24 16:38:06 +01:00
|
|
|
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.fragments.BackPressable;
|
2018-01-30 08:01:57 +01:00
|
|
|
import org.schabi.newpipe.fragments.MainFragment;
|
2017-04-09 19:34:00 +02:00
|
|
|
import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.fragments.list.search.SearchFragment;
|
2018-02-19 21:04:13 +01:00
|
|
|
import org.schabi.newpipe.report.ErrorActivity;
|
2020-01-28 21:16:50 +01:00
|
|
|
import org.schabi.newpipe.util.AndroidTvUtils;
|
2020-04-25 11:35:15 +02:00
|
|
|
import org.schabi.newpipe.util.Constants;
|
2018-06-08 21:07:25 +02:00
|
|
|
import org.schabi.newpipe.util.KioskTranslator;
|
2020-01-09 15:51:41 +01:00
|
|
|
import org.schabi.newpipe.util.Localization;
|
2017-04-09 19:34:00 +02:00
|
|
|
import org.schabi.newpipe.util.NavigationHelper;
|
2019-11-24 16:38:06 +01:00
|
|
|
import org.schabi.newpipe.util.PeertubeHelper;
|
2019-08-15 04:00:11 +02:00
|
|
|
import org.schabi.newpipe.util.PermissionHelper;
|
2018-01-30 08:01:57 +01:00
|
|
|
import org.schabi.newpipe.util.ServiceHelper;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.util.StateSaver;
|
2019-12-08 17:09:16 +01:00
|
|
|
import org.schabi.newpipe.util.TLSSocketFactoryCompat;
|
2017-04-09 19:34:00 +02:00
|
|
|
import org.schabi.newpipe.util.ThemeHelper;
|
2019-09-23 09:17:03 +02:00
|
|
|
import org.schabi.newpipe.views.FocusOverlayView;
|
2018-07-08 17:46:21 +02:00
|
|
|
|
2019-11-24 16:38:06 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2020-01-28 20:48:42 +01:00
|
|
|
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
2020-01-04 21:38:27 +01:00
|
|
|
|
2018-01-27 06:34:17 +01:00
|
|
|
public class MainActivity extends AppCompatActivity {
|
2017-08-12 06:50:25 +02:00
|
|
|
private static final String TAG = "MainActivity";
|
2018-01-30 08:01:57 +01:00
|
|
|
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
|
|
|
|
|
2020-03-22 20:26:53 +01:00
|
|
|
private ActionBarDrawerToggle toggle;
|
|
|
|
private DrawerLayout drawer;
|
|
|
|
private NavigationView drawerItems;
|
|
|
|
private ImageView headerServiceIcon;
|
|
|
|
private TextView headerServiceView;
|
|
|
|
private Button toggleServiceButton;
|
2016-08-02 15:06:02 +02:00
|
|
|
|
2018-06-14 03:29:49 +02:00
|
|
|
private boolean servicesShown = false;
|
|
|
|
private ImageView serviceArrow;
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private static final int ITEM_ID_SUBSCRIPTIONS = -1;
|
|
|
|
private static final int ITEM_ID_FEED = -2;
|
|
|
|
private static final int ITEM_ID_BOOKMARKS = -3;
|
|
|
|
private static final int ITEM_ID_DOWNLOADS = -4;
|
|
|
|
private static final int ITEM_ID_HISTORY = -5;
|
2018-06-16 13:11:45 +02:00
|
|
|
private static final int ITEM_ID_SETTINGS = 0;
|
|
|
|
private static final int ITEM_ID_ABOUT = 1;
|
|
|
|
|
|
|
|
private static final int ORDER = 0;
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Activity's LifeCycle
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2016-08-02 01:26:12 +02:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "onCreate() called with: "
|
|
|
|
+ "savedInstanceState = [" + savedInstanceState + "]");
|
|
|
|
}
|
2018-01-30 08:01:57 +01:00
|
|
|
|
2019-12-04 12:49:47 +01:00
|
|
|
// enable TLS1.1/1.2 for kitkat devices, to fix download and play for mediaCCC sources
|
|
|
|
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
|
2019-12-08 17:09:16 +01:00
|
|
|
TLSSocketFactoryCompat.setAsDefault();
|
2019-12-04 12:49:47 +01:00
|
|
|
}
|
2018-01-30 08:01:57 +01:00
|
|
|
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
|
|
|
|
|
2020-01-28 20:48:42 +01:00
|
|
|
assureCorrectAppLanguage(this);
|
2017-04-09 19:34:00 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2016-08-02 01:26:12 +02:00
|
|
|
setContentView(R.layout.activity_main);
|
2017-04-17 06:21:48 +02:00
|
|
|
|
2018-06-14 01:55:55 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
Window w = getWindow();
|
2020-03-31 19:20:15 +02:00
|
|
|
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
|
|
|
|
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
2018-06-14 01:55:55 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
if (getSupportFragmentManager() != null
|
|
|
|
&& getSupportFragmentManager().getBackStackEntryCount() == 0) {
|
2017-04-17 06:21:48 +02:00
|
|
|
initFragments();
|
|
|
|
}
|
2017-04-26 21:32:04 +02:00
|
|
|
|
2018-01-30 08:01:57 +01:00
|
|
|
setSupportActionBar(findViewById(R.id.toolbar));
|
2018-06-08 21:07:25 +02:00
|
|
|
try {
|
|
|
|
setupDrawer();
|
|
|
|
} catch (Exception e) {
|
|
|
|
ErrorActivity.reportUiError(this, e);
|
|
|
|
}
|
2019-09-23 09:17:03 +02:00
|
|
|
|
2020-04-25 11:35:15 +02:00
|
|
|
if (AndroidTvUtils.isTv(this)) {
|
2019-09-23 09:17:03 +02:00
|
|
|
FocusOverlayView.setupFocusObserver(this);
|
|
|
|
}
|
2018-01-30 08:01:57 +01:00
|
|
|
}
|
|
|
|
|
2018-06-08 21:07:25 +02:00
|
|
|
private void setupDrawer() throws Exception {
|
2017-11-19 17:21:46 +01:00
|
|
|
final Toolbar toolbar = findViewById(R.id.toolbar);
|
2018-02-16 23:56:04 +01:00
|
|
|
drawer = findViewById(R.id.drawer_layout);
|
|
|
|
drawerItems = findViewById(R.id.navigation);
|
2017-11-19 17:21:46 +01:00
|
|
|
|
2018-06-08 21:07:25 +02:00
|
|
|
//Tabs
|
|
|
|
int currentServiceId = ServiceHelper.getSelectedServiceId(this);
|
|
|
|
StreamingService service = NewPipe.getService(currentServiceId);
|
|
|
|
|
|
|
|
int kioskId = 0;
|
|
|
|
|
|
|
|
for (final String ks : service.getKioskList().getAvailableKiosks()) {
|
|
|
|
drawerItems.getMenu()
|
2020-03-31 19:20:15 +02:00
|
|
|
.add(R.id.menu_tabs_group, kioskId, 0, KioskTranslator
|
|
|
|
.getTranslatedKioskName(ks, this))
|
2018-06-08 21:07:25 +02:00
|
|
|
.setIcon(KioskTranslator.getKioskIcons(ks, this));
|
2020-03-31 19:20:15 +02:00
|
|
|
kioskId++;
|
2018-06-14 03:29:49 +02:00
|
|
|
}
|
2018-06-08 21:07:25 +02:00
|
|
|
|
|
|
|
drawerItems.getMenu()
|
2020-03-31 19:20:15 +02:00
|
|
|
.add(R.id.menu_tabs_group, ITEM_ID_SUBSCRIPTIONS, ORDER,
|
|
|
|
R.string.tab_subscriptions)
|
2018-06-08 21:07:25 +02:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_channel));
|
|
|
|
drawerItems.getMenu()
|
2019-10-11 06:09:28 +02:00
|
|
|
.add(R.id.menu_tabs_group, ITEM_ID_FEED, ORDER, R.string.fragment_feed_title)
|
2020-03-25 16:23:47 +01:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_rss));
|
2018-06-08 21:07:25 +02:00
|
|
|
drawerItems.getMenu()
|
2018-06-16 13:11:45 +02:00
|
|
|
.add(R.id.menu_tabs_group, ITEM_ID_BOOKMARKS, ORDER, R.string.tab_bookmarks)
|
2018-06-08 21:07:25 +02:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_bookmark));
|
|
|
|
drawerItems.getMenu()
|
2018-06-16 13:11:45 +02:00
|
|
|
.add(R.id.menu_tabs_group, ITEM_ID_DOWNLOADS, ORDER, R.string.downloads)
|
2020-03-25 16:23:47 +01:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_file_download));
|
2018-06-08 21:07:25 +02:00
|
|
|
drawerItems.getMenu()
|
2018-06-16 13:11:45 +02:00
|
|
|
.add(R.id.menu_tabs_group, ITEM_ID_HISTORY, ORDER, R.string.action_history)
|
2020-03-25 16:23:47 +01:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_history));
|
2018-06-08 21:07:25 +02:00
|
|
|
|
|
|
|
//Settings and About
|
|
|
|
drawerItems.getMenu()
|
2018-06-16 13:11:45 +02:00
|
|
|
.add(R.id.menu_options_about_group, ITEM_ID_SETTINGS, ORDER, R.string.settings)
|
2020-03-25 16:23:47 +01:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_settings));
|
2018-06-08 21:07:25 +02:00
|
|
|
drawerItems.getMenu()
|
2018-06-16 13:11:45 +02:00
|
|
|
.add(R.id.menu_options_about_group, ITEM_ID_ABOUT, ORDER, R.string.tab_about)
|
2020-03-25 16:23:47 +01:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_info_outline));
|
2018-06-08 21:07:25 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.drawer_open,
|
|
|
|
R.string.drawer_close);
|
2018-03-30 11:09:07 +02:00
|
|
|
toggle.syncState();
|
|
|
|
drawer.addDrawerListener(toggle);
|
|
|
|
drawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
|
|
|
|
private int lastService;
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onDrawerOpened(final View drawerView) {
|
2018-03-30 11:09:07 +02:00
|
|
|
lastService = ServiceHelper.getSelectedServiceId(MainActivity.this);
|
|
|
|
}
|
2017-11-19 17:21:46 +01:00
|
|
|
|
2018-03-30 11:09:07 +02:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onDrawerClosed(final View drawerView) {
|
|
|
|
if (servicesShown) {
|
2018-06-14 03:29:49 +02:00
|
|
|
toggleServices();
|
|
|
|
}
|
2018-03-30 11:09:07 +02:00
|
|
|
if (lastService != ServiceHelper.getSelectedServiceId(MainActivity.this)) {
|
|
|
|
new Handler(Looper.getMainLooper()).post(MainActivity.this::recreate);
|
2017-11-19 17:21:46 +01:00
|
|
|
}
|
2018-03-30 11:09:07 +02:00
|
|
|
}
|
|
|
|
});
|
2017-08-12 06:50:25 +02:00
|
|
|
|
2018-06-08 21:07:25 +02:00
|
|
|
drawerItems.setNavigationItemSelectedListener(this::drawerItemSelected);
|
2018-03-30 11:09:07 +02:00
|
|
|
setupDrawerHeader();
|
2017-08-12 06:50:25 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private boolean drawerItemSelected(final MenuItem item) {
|
2018-06-08 21:07:25 +02:00
|
|
|
switch (item.getGroupId()) {
|
|
|
|
case R.id.menu_services_group:
|
|
|
|
changeService(item);
|
|
|
|
break;
|
|
|
|
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;
|
|
|
|
}
|
2018-03-30 11:09:07 +02:00
|
|
|
|
2018-06-08 21:07:25 +02:00
|
|
|
drawer.closeDrawers();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private void changeService(final MenuItem item) {
|
|
|
|
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this))
|
|
|
|
.setChecked(false);
|
2018-06-15 07:21:30 +02:00
|
|
|
ServiceHelper.setSelectedServiceId(this, item.getItemId());
|
2020-03-31 19:20:15 +02:00
|
|
|
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this))
|
|
|
|
.setChecked(true);
|
2018-02-16 23:56:04 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private void tabSelected(final MenuItem item) throws ExtractionException {
|
|
|
|
switch (item.getItemId()) {
|
2018-06-16 13:11:45 +02:00
|
|
|
case ITEM_ID_SUBSCRIPTIONS:
|
2018-06-08 21:07:25 +02:00
|
|
|
NavigationHelper.openSubscriptionFragment(getSupportFragmentManager());
|
|
|
|
break;
|
2018-06-16 13:11:45 +02:00
|
|
|
case ITEM_ID_FEED:
|
2019-04-28 22:43:54 +02:00
|
|
|
NavigationHelper.openFeedFragment(getSupportFragmentManager());
|
2018-06-08 21:07:25 +02:00
|
|
|
break;
|
2018-06-16 13:11:45 +02:00
|
|
|
case ITEM_ID_BOOKMARKS:
|
2018-06-08 21:07:25 +02:00
|
|
|
NavigationHelper.openBookmarksFragment(getSupportFragmentManager());
|
|
|
|
break;
|
2018-06-16 13:11:45 +02:00
|
|
|
case ITEM_ID_DOWNLOADS:
|
2018-06-08 21:07:25 +02:00
|
|
|
NavigationHelper.openDownloads(this);
|
|
|
|
break;
|
2018-06-16 13:11:45 +02:00
|
|
|
case ITEM_ID_HISTORY:
|
2018-06-08 21:07:25 +02:00
|
|
|
NavigationHelper.openStatisticFragment(getSupportFragmentManager());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
int currentServiceId = ServiceHelper.getSelectedServiceId(this);
|
|
|
|
StreamingService service = NewPipe.getService(currentServiceId);
|
|
|
|
String serviceName = "";
|
2018-02-16 14:45:52 +01:00
|
|
|
|
2018-06-08 21:07:25 +02:00
|
|
|
int kioskId = 0;
|
|
|
|
for (final String ks : service.getKioskList().getAvailableKiosks()) {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (kioskId == item.getItemId()) {
|
2018-06-08 21:07:25 +02:00
|
|
|
serviceName = ks;
|
|
|
|
}
|
2020-03-31 19:20:15 +02:00
|
|
|
kioskId++;
|
2018-06-08 21:07:25 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
NavigationHelper.openKioskFragment(getSupportFragmentManager(), currentServiceId,
|
|
|
|
serviceName);
|
2018-06-08 21:07:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private void optionsAboutSelected(final MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2018-06-16 13:11:45 +02:00
|
|
|
case ITEM_ID_SETTINGS:
|
2018-06-08 21:07:25 +02:00
|
|
|
NavigationHelper.openSettings(this);
|
|
|
|
break;
|
2018-06-16 13:11:45 +02:00
|
|
|
case ITEM_ID_ABOUT:
|
2018-06-08 21:07:25 +02:00
|
|
|
NavigationHelper.openAbout(this);
|
|
|
|
break;
|
|
|
|
}
|
2018-02-16 14:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-02-16 23:56:04 +01:00
|
|
|
private void setupDrawerHeader() {
|
2018-06-13 22:35:20 +02:00
|
|
|
NavigationView navigationView = findViewById(R.id.navigation);
|
2020-03-31 19:20:15 +02:00
|
|
|
View hView = navigationView.getHeaderView(0);
|
2018-06-13 22:35:20 +02:00
|
|
|
|
2018-06-14 03:29:49 +02:00
|
|
|
serviceArrow = hView.findViewById(R.id.drawer_arrow);
|
2020-03-22 20:26:53 +01:00
|
|
|
headerServiceIcon = hView.findViewById(R.id.drawer_header_service_icon);
|
2018-06-13 22:35:20 +02:00
|
|
|
headerServiceView = hView.findViewById(R.id.drawer_header_service_view);
|
2019-09-22 11:59:50 +02:00
|
|
|
toggleServiceButton = hView.findViewById(R.id.drawer_header_action_button);
|
2020-03-22 20:26:53 +01:00
|
|
|
toggleServiceButton.setOnClickListener(view -> toggleServices());
|
2020-04-10 15:31:28 +02:00
|
|
|
|
|
|
|
// If the current app name is bigger than the default "NewPipe" (7 chars),
|
|
|
|
// let the text view grow a little more as well.
|
|
|
|
if (getString(R.string.app_name).length() > "NewPipe".length()) {
|
|
|
|
final TextView headerTitle = hView.findViewById(R.id.drawer_header_newpipe_title);
|
|
|
|
final ViewGroup.LayoutParams layoutParams = headerTitle.getLayoutParams();
|
|
|
|
layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
|
|
headerTitle.setLayoutParams(layoutParams);
|
|
|
|
headerTitle.setMaxLines(2);
|
|
|
|
headerTitle.setMinWidth(getResources()
|
|
|
|
.getDimensionPixelSize(R.dimen.drawer_header_newpipe_title_default_width));
|
|
|
|
headerTitle.setMaxWidth(getResources()
|
|
|
|
.getDimensionPixelSize(R.dimen.drawer_header_newpipe_title_max_width));
|
|
|
|
}
|
2018-02-16 23:56:04 +01:00
|
|
|
}
|
|
|
|
|
2018-06-14 03:29:49 +02:00
|
|
|
private void toggleServices() {
|
|
|
|
servicesShown = !servicesShown;
|
|
|
|
|
|
|
|
drawerItems.getMenu().removeGroup(R.id.menu_services_group);
|
|
|
|
drawerItems.getMenu().removeGroup(R.id.menu_tabs_group);
|
|
|
|
drawerItems.getMenu().removeGroup(R.id.menu_options_about_group);
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
if (servicesShown) {
|
2018-06-14 03:29:49 +02:00
|
|
|
showServices();
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
showTabs();
|
|
|
|
} catch (Exception e) {
|
|
|
|
ErrorActivity.reportUiError(this, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showServices() {
|
2020-03-25 16:23:47 +01:00
|
|
|
serviceArrow.setImageResource(R.drawable.ic_expand_less_white_24dp);
|
2018-06-14 03:29:49 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
for (StreamingService s : NewPipe.getServices()) {
|
|
|
|
final String title = s.getServiceInfo().getName()
|
|
|
|
+ (ServiceHelper.isBeta(s) ? " (beta)" : "");
|
2018-06-14 03:29:49 +02:00
|
|
|
|
2019-11-24 16:38:06 +01:00
|
|
|
MenuItem menuItem = drawerItems.getMenu()
|
2018-06-16 13:11:45 +02:00
|
|
|
.add(R.id.menu_services_group, s.getServiceId(), ORDER, title)
|
2018-06-14 03:29:49 +02:00
|
|
|
.setIcon(ServiceHelper.getIcon(s.getServiceId()));
|
2019-11-24 16:38:06 +01:00
|
|
|
|
|
|
|
// peertube specifics
|
2020-03-31 19:20:15 +02:00
|
|
|
if (s.getServiceId() == 3) {
|
2019-11-24 16:38:06 +01:00
|
|
|
enhancePeertubeMenu(s, menuItem);
|
|
|
|
}
|
2018-06-14 03:29:49 +02:00
|
|
|
}
|
2020-03-31 19:20:15 +02:00
|
|
|
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this))
|
|
|
|
.setChecked(true);
|
2018-06-14 03:29:49 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private void enhancePeertubeMenu(final StreamingService s, final MenuItem menuItem) {
|
2019-11-24 16:38:06 +01:00
|
|
|
PeertubeInstance currentInstace = PeertubeHelper.getCurrentInstance();
|
|
|
|
menuItem.setTitle(currentInstace.getName() + (ServiceHelper.isBeta(s) ? " (beta)" : ""));
|
2020-03-31 19:20:15 +02:00
|
|
|
Spinner spinner = (Spinner) LayoutInflater.from(this)
|
|
|
|
.inflate(R.layout.instance_spinner_layout, null);
|
2019-11-24 16:38:06 +01:00
|
|
|
List<PeertubeInstance> instances = PeertubeHelper.getInstanceList(this);
|
|
|
|
List<String> items = new ArrayList<>();
|
|
|
|
int defaultSelect = 0;
|
2020-03-31 19:20:15 +02:00
|
|
|
for (PeertubeInstance instance : instances) {
|
2019-11-24 16:38:06 +01:00
|
|
|
items.add(instance.getName());
|
2020-03-31 19:20:15 +02:00
|
|
|
if (instance.getUrl().equals(currentInstace.getUrl())) {
|
|
|
|
defaultSelect = items.size() - 1;
|
2019-11-24 16:38:06 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-31 19:20:15 +02:00
|
|
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
|
|
|
|
R.layout.instance_spinner_item, items);
|
2019-11-24 16:38:06 +01:00
|
|
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
|
|
spinner.setAdapter(adapter);
|
|
|
|
spinner.setSelection(defaultSelect, false);
|
|
|
|
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onItemSelected(final AdapterView<?> parent, final View view,
|
|
|
|
final int position, final long id) {
|
2019-11-24 16:38:06 +01:00
|
|
|
PeertubeInstance newInstance = instances.get(position);
|
2020-03-31 19:20:15 +02:00
|
|
|
if (newInstance.getUrl().equals(PeertubeHelper.getCurrentInstance().getUrl())) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-24 16:38:06 +01:00
|
|
|
PeertubeHelper.selectInstance(newInstance, getApplicationContext());
|
|
|
|
changeService(menuItem);
|
|
|
|
drawer.closeDrawers();
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
2020-03-31 19:20:15 +02:00
|
|
|
getSupportFragmentManager().popBackStack(null,
|
|
|
|
FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
2019-11-24 16:38:06 +01:00
|
|
|
recreate();
|
|
|
|
}, 300);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onNothingSelected(final AdapterView<?> parent) {
|
2019-11-24 16:38:06 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
menuItem.setActionView(spinner);
|
|
|
|
}
|
|
|
|
|
2018-06-14 03:29:49 +02:00
|
|
|
private void showTabs() throws ExtractionException {
|
2020-03-25 16:23:47 +01:00
|
|
|
serviceArrow.setImageResource(R.drawable.ic_expand_more_white_24dp);
|
2018-06-14 03:29:49 +02:00
|
|
|
|
|
|
|
//Tabs
|
|
|
|
int currentServiceId = ServiceHelper.getSelectedServiceId(this);
|
|
|
|
StreamingService service = NewPipe.getService(currentServiceId);
|
|
|
|
|
|
|
|
int kioskId = 0;
|
|
|
|
|
|
|
|
for (final String ks : service.getKioskList().getAvailableKiosks()) {
|
|
|
|
drawerItems.getMenu()
|
2020-03-31 19:20:15 +02:00
|
|
|
.add(R.id.menu_tabs_group, kioskId, ORDER,
|
|
|
|
KioskTranslator.getTranslatedKioskName(ks, this))
|
2018-06-14 03:29:49 +02:00
|
|
|
.setIcon(KioskTranslator.getKioskIcons(ks, this));
|
2020-03-31 19:20:15 +02:00
|
|
|
kioskId++;
|
2018-06-14 03:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
drawerItems.getMenu()
|
2018-06-16 13:11:45 +02:00
|
|
|
.add(R.id.menu_tabs_group, ITEM_ID_SUBSCRIPTIONS, ORDER, R.string.tab_subscriptions)
|
2018-06-14 03:29:49 +02:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_channel));
|
|
|
|
drawerItems.getMenu()
|
2019-10-11 06:09:28 +02:00
|
|
|
.add(R.id.menu_tabs_group, ITEM_ID_FEED, ORDER, R.string.fragment_feed_title)
|
2020-03-25 16:23:47 +01:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_rss));
|
2018-06-14 03:29:49 +02:00
|
|
|
drawerItems.getMenu()
|
2018-06-16 13:11:45 +02:00
|
|
|
.add(R.id.menu_tabs_group, ITEM_ID_BOOKMARKS, ORDER, R.string.tab_bookmarks)
|
2018-06-14 03:29:49 +02:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_bookmark));
|
|
|
|
drawerItems.getMenu()
|
2018-06-16 13:11:45 +02:00
|
|
|
.add(R.id.menu_tabs_group, ITEM_ID_DOWNLOADS, ORDER, R.string.downloads)
|
2020-03-25 16:23:47 +01:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_file_download));
|
2018-06-14 03:29:49 +02:00
|
|
|
drawerItems.getMenu()
|
2018-06-16 13:11:45 +02:00
|
|
|
.add(R.id.menu_tabs_group, ITEM_ID_HISTORY, ORDER, R.string.action_history)
|
2020-03-25 16:23:47 +01:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_history));
|
2018-06-14 03:29:49 +02:00
|
|
|
|
|
|
|
//Settings and About
|
|
|
|
drawerItems.getMenu()
|
2018-06-16 13:11:45 +02:00
|
|
|
.add(R.id.menu_options_about_group, ITEM_ID_SETTINGS, ORDER, R.string.settings)
|
2020-03-25 16:23:47 +01:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_settings));
|
2018-06-14 03:29:49 +02:00
|
|
|
drawerItems.getMenu()
|
2018-06-16 13:11:45 +02:00
|
|
|
.add(R.id.menu_options_about_group, ITEM_ID_ABOUT, ORDER, R.string.tab_about)
|
2020-03-25 16:23:47 +01:00
|
|
|
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_info_outline));
|
2018-06-14 03:29:49 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 06:50:25 +02:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
2017-09-03 08:04:18 +02:00
|
|
|
if (!isChangingConfigurations()) {
|
|
|
|
StateSaver.clearStateFiles();
|
|
|
|
}
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
|
|
|
|
2017-06-05 21:33:01 +02:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
2020-01-28 20:48:42 +01:00
|
|
|
assureCorrectAppLanguage(this);
|
2020-03-31 19:20:15 +02:00
|
|
|
// Change the date format to match the selected language on resume
|
|
|
|
Localization.init(getApplicationContext());
|
2017-06-05 21:33:01 +02:00
|
|
|
super.onResume();
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
// Close drawer on return, and don't show animation,
|
|
|
|
// so it looks like the drawer isn't open when the user returns to MainActivity
|
2019-10-08 06:36:29 +02:00
|
|
|
drawer.closeDrawer(GravityCompat.START, false);
|
2018-02-19 21:04:13 +01:00
|
|
|
try {
|
2020-03-22 20:26:53 +01:00
|
|
|
final int selectedServiceId = ServiceHelper.getSelectedServiceId(this);
|
2020-03-31 19:20:15 +02:00
|
|
|
final String selectedServiceName = NewPipe.getService(selectedServiceId)
|
|
|
|
.getServiceInfo().getName();
|
2018-03-30 11:09:07 +02:00
|
|
|
headerServiceView.setText(selectedServiceName);
|
2020-03-22 20:26:53 +01:00
|
|
|
headerServiceIcon.setImageResource(ServiceHelper.getIcon(selectedServiceId));
|
|
|
|
|
2019-03-09 20:32:25 +01:00
|
|
|
headerServiceView.post(() -> headerServiceView.setSelected(true));
|
2019-09-22 11:59:50 +02:00
|
|
|
toggleServiceButton.setContentDescription(
|
|
|
|
getString(R.string.drawer_header_description) + selectedServiceName);
|
2018-02-19 21:04:13 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
ErrorActivity.reportUiError(this, e);
|
|
|
|
}
|
2018-02-16 23:56:04 +01:00
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
2017-06-05 21:33:01 +02:00
|
|
|
if (sharedPreferences.getBoolean(Constants.KEY_THEME_CHANGE, false)) {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "Theme has changed, recreating activity...");
|
|
|
|
}
|
2017-06-05 21:33:01 +02:00
|
|
|
sharedPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, false).apply();
|
2020-03-31 19:20:15 +02:00
|
|
|
// https://stackoverflow.com/questions/10844112/
|
|
|
|
// Briefly, let the activity resume
|
|
|
|
// properly posting the recreate call to end of the message queue
|
2018-01-30 08:01:57 +01:00
|
|
|
new Handler(Looper.getMainLooper()).post(MainActivity.this::recreate);
|
2017-06-05 21:33:01 +02:00
|
|
|
}
|
|
|
|
|
2018-01-30 08:01:57 +01:00
|
|
|
if (sharedPreferences.getBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false)) {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "main page has changed, recreating main fragment...");
|
|
|
|
}
|
2017-10-13 13:49:31 +02:00
|
|
|
sharedPreferences.edit().putBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false).apply();
|
|
|
|
NavigationHelper.openMainActivity(this);
|
|
|
|
}
|
2020-01-14 19:30:36 +01:00
|
|
|
|
2020-02-22 11:34:08 +01:00
|
|
|
final boolean isHistoryEnabled = sharedPreferences.getBoolean(
|
|
|
|
getString(R.string.enable_watch_history_key), true);
|
|
|
|
drawerItems.getMenu().findItem(ITEM_ID_HISTORY).setVisible(isHistoryEnabled);
|
2017-06-05 21:33:01 +02:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
protected void onNewIntent(final Intent intent) {
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "onNewIntent() called with: intent = [" + intent + "]");
|
|
|
|
}
|
2017-04-17 06:21:48 +02:00
|
|
|
if (intent != null) {
|
|
|
|
// Return if launched from a launcher (e.g. Nova Launcher, Pixel Launcher ...)
|
|
|
|
// to not destroy the already created backstack
|
|
|
|
String action = intent.getAction();
|
2020-03-31 19:20:15 +02:00
|
|
|
if ((action != null && action.equals(Intent.ACTION_MAIN))
|
|
|
|
&& intent.hasCategory(Intent.CATEGORY_LAUNCHER)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-17 06:21:48 +02:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
super.onNewIntent(intent);
|
2017-04-17 06:21:48 +02:00
|
|
|
setIntent(intent);
|
2017-04-09 19:34:00 +02:00
|
|
|
handleIntent(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "onBackPressed() called");
|
|
|
|
}
|
2017-06-05 21:33:01 +02:00
|
|
|
|
2020-04-25 11:35:15 +02:00
|
|
|
if (AndroidTvUtils.isTv(this)) {
|
2020-04-03 01:57:52 +02:00
|
|
|
View drawerPanel = findViewById(R.id.navigation);
|
2019-09-20 11:07:27 +02:00
|
|
|
if (drawer.isDrawerOpen(drawerPanel)) {
|
|
|
|
drawer.closeDrawers();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
|
2020-03-31 19:20:15 +02:00
|
|
|
// If current fragment implements BackPressable (i.e. can/wanna handle back press)
|
|
|
|
// delegate the back press to it
|
2017-09-03 08:04:18 +02:00
|
|
|
if (fragment instanceof BackPressable) {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (((BackPressable) fragment).onBackPressed()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
2017-04-09 19:34:00 +02:00
|
|
|
|
2017-07-10 05:09:57 +02:00
|
|
|
if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
|
|
|
|
finish();
|
2020-03-31 19:20:15 +02:00
|
|
|
} else {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
2016-08-02 15:06:02 +02:00
|
|
|
}
|
|
|
|
|
2018-04-06 23:19:45 +02:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onRequestPermissionsResult(final int requestCode,
|
|
|
|
@NonNull final String[] permissions,
|
|
|
|
@NonNull final int[] grantResults) {
|
|
|
|
for (int i : grantResults) {
|
|
|
|
if (i == PackageManager.PERMISSION_DENIED) {
|
2018-04-07 19:32:02 +02:00
|
|
|
return;
|
2018-04-06 23:19:45 +02:00
|
|
|
}
|
2018-04-07 19:32:02 +02:00
|
|
|
}
|
2019-08-15 04:00:11 +02:00
|
|
|
switch (requestCode) {
|
|
|
|
case PermissionHelper.DOWNLOADS_REQUEST_CODE:
|
|
|
|
NavigationHelper.openDownloads(this);
|
|
|
|
break;
|
|
|
|
case PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE:
|
2020-03-31 19:20:15 +02:00
|
|
|
Fragment fragment = getSupportFragmentManager()
|
|
|
|
.findFragmentById(R.id.fragment_holder);
|
2019-08-15 04:00:11 +02:00
|
|
|
if (fragment instanceof VideoDetailFragment) {
|
|
|
|
((VideoDetailFragment) fragment).openDownloadDialog();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-04-06 23:19:45 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:03:55 +01:00
|
|
|
/**
|
|
|
|
* Implement the following diagram behavior for the up button:
|
|
|
|
* <pre>
|
|
|
|
* +---------------+
|
|
|
|
* | Main Screen +----+
|
|
|
|
* +-------+-------+ |
|
|
|
|
* | |
|
|
|
|
* ▲ Up | Search Button
|
|
|
|
* | |
|
|
|
|
* +----+-----+ |
|
|
|
|
* +------------+ Search |◄-----+
|
|
|
|
* | +----+-----+
|
|
|
|
* | Open |
|
|
|
|
* | something ▲ Up
|
|
|
|
* | |
|
|
|
|
* | +------------+-------------+
|
|
|
|
* | | |
|
|
|
|
* | | Video <-> Channel |
|
|
|
|
* +---►| Channel <-> Playlist |
|
|
|
|
* | Video <-> .... |
|
|
|
|
* | |
|
|
|
|
* +--------------------------+
|
|
|
|
* </pre>
|
|
|
|
*/
|
2018-01-30 08:01:57 +01:00
|
|
|
private void onHomeButtonPressed() {
|
2018-02-03 12:03:55 +01:00
|
|
|
// If search fragment wasn't found in the backstack...
|
|
|
|
if (!NavigationHelper.tryGotoSearchFragment(getSupportFragmentManager())) {
|
|
|
|
// ...go to the main fragment
|
|
|
|
NavigationHelper.gotoMainFragment(getSupportFragmentManager());
|
|
|
|
}
|
2018-01-30 08:01:57 +01:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Menu
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2016-12-07 22:11:39 +01:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public boolean onCreateOptionsMenu(final Menu menu) {
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "]");
|
|
|
|
}
|
2016-08-02 15:06:02 +02:00
|
|
|
super.onCreateOptionsMenu(menu);
|
2017-04-26 21:32:04 +02:00
|
|
|
|
|
|
|
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
|
|
|
|
if (!(fragment instanceof VideoDetailFragment)) {
|
|
|
|
findViewById(R.id.toolbar).findViewById(R.id.toolbar_spinner).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(fragment instanceof SearchFragment)) {
|
2020-03-31 19:20:15 +02:00
|
|
|
findViewById(R.id.toolbar).findViewById(R.id.toolbar_search_container)
|
|
|
|
.setVisibility(View.GONE);
|
2017-04-26 21:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(false);
|
|
|
|
}
|
2018-01-30 08:01:57 +01:00
|
|
|
|
|
|
|
updateDrawerNavigation();
|
|
|
|
|
2016-08-02 15:06:02 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "onOptionsItemSelected() called with: item = [" + item + "]");
|
|
|
|
}
|
2016-08-02 15:06:02 +02:00
|
|
|
int id = item.getItemId();
|
|
|
|
|
2017-02-15 15:21:36 +01:00
|
|
|
switch (id) {
|
2017-09-03 08:04:18 +02:00
|
|
|
case android.R.id.home:
|
2018-01-30 08:01:57 +01:00
|
|
|
onHomeButtonPressed();
|
2016-08-02 15:06:02 +02:00
|
|
|
return true;
|
|
|
|
default:
|
2017-01-19 19:38:33 +01:00
|
|
|
return super.onOptionsItemSelected(item);
|
2016-08-02 15:06:02 +02:00
|
|
|
}
|
2016-08-02 01:26:12 +02:00
|
|
|
}
|
2017-04-09 19:34:00 +02:00
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Init
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
private void initFragments() {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "initFragments() called");
|
|
|
|
}
|
2017-09-03 08:04:18 +02:00
|
|
|
StateSaver.clearStateFiles();
|
2017-07-10 05:09:57 +02:00
|
|
|
if (getIntent() != null && getIntent().hasExtra(Constants.KEY_LINK_TYPE)) {
|
2017-04-09 19:34:00 +02:00
|
|
|
handleIntent(getIntent());
|
2020-03-31 19:20:15 +02:00
|
|
|
} else {
|
|
|
|
NavigationHelper.gotoMainFragment(getSupportFragmentManager());
|
|
|
|
}
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Utils
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2018-01-30 08:01:57 +01:00
|
|
|
private void updateDrawerNavigation() {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (getSupportActionBar() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-30 08:01:57 +01:00
|
|
|
|
|
|
|
final Toolbar toolbar = findViewById(R.id.toolbar);
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
final Fragment fragment = getSupportFragmentManager()
|
|
|
|
.findFragmentById(R.id.fragment_holder);
|
2018-01-30 08:01:57 +01:00
|
|
|
if (fragment instanceof MainFragment) {
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
|
|
|
if (toggle != null) {
|
|
|
|
toggle.syncState();
|
|
|
|
toolbar.setNavigationOnClickListener(v -> drawer.openDrawer(GravityCompat.START));
|
|
|
|
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
toolbar.setNavigationOnClickListener(v -> onHomeButtonPressed());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private void handleIntent(final Intent intent) {
|
2018-07-08 17:46:21 +02:00
|
|
|
try {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "handleIntent() called with: intent = [" + intent + "]");
|
|
|
|
}
|
2018-07-08 17:46:21 +02:00
|
|
|
|
|
|
|
if (intent.hasExtra(Constants.KEY_LINK_TYPE)) {
|
|
|
|
String url = intent.getStringExtra(Constants.KEY_URL);
|
|
|
|
int serviceId = intent.getIntExtra(Constants.KEY_SERVICE_ID, 0);
|
|
|
|
String title = intent.getStringExtra(Constants.KEY_TITLE);
|
2020-03-31 19:20:15 +02:00
|
|
|
switch (((StreamingService.LinkType) intent
|
|
|
|
.getSerializableExtra(Constants.KEY_LINK_TYPE))) {
|
2018-07-08 17:46:21 +02:00
|
|
|
case STREAM:
|
2020-03-31 19:20:15 +02:00
|
|
|
boolean autoPlay = intent
|
|
|
|
.getBooleanExtra(VideoDetailFragment.AUTO_PLAY, false);
|
|
|
|
NavigationHelper.openVideoDetailFragment(getSupportFragmentManager(),
|
|
|
|
serviceId, url, title, autoPlay);
|
2018-07-08 17:46:21 +02:00
|
|
|
break;
|
|
|
|
case CHANNEL:
|
|
|
|
NavigationHelper.openChannelFragment(getSupportFragmentManager(),
|
|
|
|
serviceId,
|
2018-07-10 16:26:42 +02:00
|
|
|
url,
|
2018-07-08 17:46:21 +02:00
|
|
|
title);
|
|
|
|
break;
|
|
|
|
case PLAYLIST:
|
|
|
|
NavigationHelper.openPlaylistFragment(getSupportFragmentManager(),
|
|
|
|
serviceId,
|
2018-07-10 16:26:42 +02:00
|
|
|
url,
|
2018-07-08 17:46:21 +02:00
|
|
|
title);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (intent.hasExtra(Constants.KEY_OPEN_SEARCH)) {
|
|
|
|
String searchString = intent.getStringExtra(Constants.KEY_SEARCH_STRING);
|
2020-03-31 19:20:15 +02:00
|
|
|
if (searchString == null) {
|
|
|
|
searchString = "";
|
|
|
|
}
|
2018-07-08 17:46:21 +02:00
|
|
|
int serviceId = intent.getIntExtra(Constants.KEY_SERVICE_ID, 0);
|
|
|
|
NavigationHelper.openSearchFragment(
|
|
|
|
getSupportFragmentManager(),
|
|
|
|
serviceId,
|
2018-07-10 16:26:42 +02:00
|
|
|
searchString);
|
2018-07-08 17:46:21 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
NavigationHelper.gotoMainFragment(getSupportFragmentManager());
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
2018-07-08 17:46:21 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
ErrorActivity.reportUiError(this, e);
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-02 01:26:12 +02:00
|
|
|
}
|