diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 0b6cf50f7..f0a8d45e0 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -16,7 +16,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:logo="@mipmap/ic_launcher"
- android:theme="@style/DarkTheme"
+ android:theme="@style/OpeningTheme"
tools:ignore="AllowBackup">
+ android:launchMode="singleTask"/>
{
+ if (item.getGroupId() == R.id.menu_services_group) {
+ drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(false);
+ ServiceHelper.setSelectedServiceId(this, item.getTitle().toString());
+ drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
+ }
+ drawer.closeDrawers();
+ return true;
});
} else {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}
-
- getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
- @Override
- public void onBackStackChanged() {
- if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- toolbar.setNavigationOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- onBackPressed();
- }
- });
- } else {
- getSupportActionBar().setDisplayHomeAsUpEnabled(false);
- if (toggle != null) {
- toggle.syncState();
- toolbar.setNavigationOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- drawer.openDrawer(GravityCompat.START);
- }
- });
- }
- }
- }
- });
-
- sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
-
- initHistory();
}
@Override
@@ -171,20 +163,14 @@ public class MainActivity extends AppCompatActivity implements HistoryListener {
sharedPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, false).apply();
// https://stackoverflow.com/questions/10844112/runtimeexception-performing-pause-of-activity-that-is-not-resumed
// Briefly, let the activity resume properly posting the recreate call to end of the message queue
- new Handler(Looper.getMainLooper()).post(new Runnable() {
- @Override
- public void run() {
- MainActivity.this.recreate();
- }
- });
+ new Handler(Looper.getMainLooper()).post(MainActivity.this::recreate);
}
- if(sharedPreferences.getBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false)) {
+ if (sharedPreferences.getBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false)) {
if (DEBUG) Log.d(TAG, "main page has changed, recreating main fragment...");
sharedPreferences.edit().putBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false).apply();
NavigationHelper.openMainActivity(this);
}
-
}
@Override
@@ -218,6 +204,10 @@ public class MainActivity extends AppCompatActivity implements HistoryListener {
} else super.onBackPressed();
}
+ private void onHomeButtonPressed() {
+ NavigationHelper.gotoMainFragment(getSupportFragmentManager());
+ }
+
/*//////////////////////////////////////////////////////////////////////////
// Menu
//////////////////////////////////////////////////////////////////////////*/
@@ -243,9 +233,17 @@ public class MainActivity extends AppCompatActivity implements HistoryListener {
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
}
+
+ updateDrawerNavigation();
+
return true;
}
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ return super.onPrepareOptionsMenu(menu);
+ }
+
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (DEBUG) Log.d(TAG, "onOptionsItemSelected() called with: item = [" + item + "]");
@@ -253,7 +251,7 @@ public class MainActivity extends AppCompatActivity implements HistoryListener {
switch (id) {
case android.R.id.home:
- NavigationHelper.gotoMainFragment(getSupportFragmentManager());
+ onHomeButtonPressed();
return true;
case R.id.action_settings:
NavigationHelper.openSettings(this);
@@ -287,6 +285,27 @@ public class MainActivity extends AppCompatActivity implements HistoryListener {
// Utils
//////////////////////////////////////////////////////////////////////////*/
+ private void updateDrawerNavigation() {
+ if (getSupportActionBar() == null) return;
+
+ final Toolbar toolbar = findViewById(R.id.toolbar);
+ final DrawerLayout drawer = findViewById(R.id.drawer_layout);
+
+ final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
+ 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());
+ }
+ }
+
private void handleIntent(Intent intent) {
if (DEBUG) Log.d(TAG, "handleIntent() called with: intent = [" + intent + "]");
diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java
index 645049078..a75c8561f 100644
--- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java
@@ -19,7 +19,6 @@ import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R;
import org.schabi.newpipe.ReCaptchaActivity;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
-import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.util.ExtractorHelper;
@@ -247,6 +246,12 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC
// Utils
//////////////////////////////////////////////////////////////////////////*/
+ public void setTitle(String title) {
+ if (DEBUG) Log.d(TAG, "setTitle() called with: title = [" + title + "]");
+ if (activity != null && activity.getSupportActionBar() != null) {
+ activity.getSupportActionBar().setTitle(title);
+ }
+ }
protected void openUrlInBrowser(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java
index be3422706..3a8c7569c 100644
--- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java
@@ -23,6 +23,7 @@ import android.view.ViewGroup;
import org.schabi.newpipe.BaseFragment;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.kiosk.KioskList;
import org.schabi.newpipe.fragments.list.channel.ChannelFragment;
@@ -33,23 +34,20 @@ import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.util.KioskTranslator;
import org.schabi.newpipe.util.NavigationHelper;
+import org.schabi.newpipe.util.ServiceHelper;
import org.schabi.newpipe.util.ThemeHelper;
public class MainFragment extends BaseFragment implements TabLayout.OnTabSelectedListener {
- private ViewPager viewPager;
- private boolean showBlankTab = false;
public int currentServiceId = -1;
-
+ private ViewPager viewPager;
/*//////////////////////////////////////////////////////////////////////////
// Constants
//////////////////////////////////////////////////////////////////////////*/
-
- private static final int FALLBACK_SERVICE_ID = 0; // Youtube
- private static final String FALLBACK_CHANNEL_URL =
- "https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ";
+ private static final int FALLBACK_SERVICE_ID = ServiceList.YouTube.getId();
+ private static final String FALLBACK_CHANNEL_URL = "https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ";
private static final String FALLBACK_CHANNEL_NAME = "Music";
private static final String FALLBACK_KIOSK_ID = "Trending";
private static final int KIOSK_MENU_OFFSET = 2000;
@@ -66,8 +64,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
- currentServiceId = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getActivity())
- .getString(getString(R.string.current_service_key), "0"));
+ currentServiceId = ServiceHelper.getSelectedServiceId(activity);
return inflater.inflate(R.layout.fragment_main, container, false);
}
@@ -85,22 +82,10 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
tabLayout.setupWithViewPager(viewPager);
- int channelIcon;
- int whatsHotIcon;
+ int channelIcon = ThemeHelper.resolveResourceIdFromAttr(activity, R.attr.ic_channel);
+ int whatsHotIcon = ThemeHelper.resolveResourceIdFromAttr(activity, R.attr.ic_hot);
- if (ThemeHelper.isLightThemeSelected(getActivity())) {
- tabLayout.setBackgroundColor(getResources().getColor(R.color.light_youtube_primary_color));
- channelIcon = R.drawable.ic_channel_black_24dp;
- whatsHotIcon = R.drawable.ic_whatshot_black_24dp;
- } else {
- channelIcon = R.drawable.ic_channel_white_24dp;
- whatsHotIcon = R.drawable.ic_whatshot_white_24dp;
- }
-
-
- if (PreferenceManager.getDefaultSharedPreferences(getActivity())
- .getString(getString(R.string.main_page_content_key), getString(R.string.blank_page_key))
- .equals(getString(R.string.subscription_page_key))) {
+ if (isSubscriptionsPageOnlySelected()) {
tabLayout.getTabAt(0).setIcon(channelIcon);
} else {
tabLayout.getTabAt(0).setIcon(whatsHotIcon);
@@ -138,7 +123,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_search:
- NavigationHelper.openSearchFragment(getFragmentManager(), NewPipe.getIdOfService(PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("service", "YouTube")), "");
+ NavigationHelper.openSearchFragment(getFragmentManager(), ServiceHelper.getSelectedServiceId(activity), "");
return true;
}
return super.onOptionsItemSelected(item);
@@ -163,11 +148,6 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
private class PagerAdapter extends FragmentPagerAdapter {
- private int[] tabTitles = new int[]{
- R.string.tab_main,
- R.string.tab_subscriptions
- };
-
PagerAdapter(FragmentManager fm) {
super(fm);
}
@@ -176,13 +156,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
public Fragment getItem(int position) {
switch (position) {
case 0:
- if(PreferenceManager.getDefaultSharedPreferences(getActivity())
- .getString(getString(R.string.main_page_content_key), getString(R.string.blank_page_key))
- .equals(getString(R.string.subscription_page_key))) {
- return new SubscriptionFragment();
- } else {
- return getMainPageFragment();
- }
+ return isSubscriptionsPageOnlySelected() ? new SubscriptionFragment() : getMainPageFragment();
case 1:
return new SubscriptionFragment();
default:
@@ -198,13 +172,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
@Override
public int getCount() {
- if(PreferenceManager.getDefaultSharedPreferences(getActivity())
- .getString(getString(R.string.main_page_content_key), getString(R.string.blank_page_key))
- .equals(getString(R.string.subscription_page_key))) {
- return 1;
- } else {
- return 2;
- }
+ return isSubscriptionsPageOnlySelected() ? 1 : 2;
}
}
@@ -212,28 +180,33 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
// Main page content
//////////////////////////////////////////////////////////////////////////*/
+ private boolean isSubscriptionsPageOnlySelected() {
+ return PreferenceManager.getDefaultSharedPreferences(activity)
+ .getString(getString(R.string.main_page_content_key), getString(R.string.blank_page_key))
+ .equals(getString(R.string.subscription_page_key));
+ }
+
private Fragment getMainPageFragment() {
try {
SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(getActivity());
final String setMainPage = preferences.getString(getString(R.string.main_page_content_key),
- getString(R.string.main_page_selectd_kiosk_id));
- if(setMainPage.equals(getString(R.string.blank_page_key))) {
+ getString(R.string.main_page_selectd_kiosk_id));
+ if (setMainPage.equals(getString(R.string.blank_page_key))) {
return new BlankFragment();
- } else if(setMainPage.equals(getString(R.string.kiosk_page_key))) {
+ } else if (setMainPage.equals(getString(R.string.kiosk_page_key))) {
int serviceId = preferences.getInt(getString(R.string.main_page_selected_service),
FALLBACK_SERVICE_ID);
String kioskId = preferences.getString(getString(R.string.main_page_selectd_kiosk_id),
FALLBACK_KIOSK_ID);
- KioskFragment fragment = KioskFragment.getInstance(serviceId, kioskId
- );
+ KioskFragment fragment = KioskFragment.getInstance(serviceId, kioskId);
fragment.useAsFrontPage(true);
return fragment;
- } else if(setMainPage.equals(getString(R.string.feed_page_key))) {
+ } else if (setMainPage.equals(getString(R.string.feed_page_key))) {
FeedFragment fragment = new FeedFragment();
fragment.useAsFrontPage(true);
return fragment;
- } else if(setMainPage.equals(getString(R.string.channel_page_key))) {
+ } else if (setMainPage.equals(getString(R.string.channel_page_key))) {
int serviceId = preferences.getInt(getString(R.string.main_page_selected_service),
FALLBACK_SERVICE_ID);
String url = preferences.getString(getString(R.string.main_page_selected_channel_url),
@@ -266,7 +239,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
StreamingService service = NewPipe.getService(currentServiceId);
KioskList kl = service.getKioskList();
int i = 0;
- for(final String ks : kl.getAvailableKiosks()) {
+ for (final String ks : kl.getAvailableKiosks()) {
menu.add(0, KIOSK_MENU_OFFSET + i, Menu.NONE,
KioskTranslator.getTranslatedKioskName(ks, getContext()))
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java
index 57e77d97a..8a26d81aa 100644
--- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java
@@ -84,17 +84,6 @@ public abstract class BaseListInfoFragment extends BaseListF
currentNextItemsUrl = (String) savedObjects.poll();
}
- /*//////////////////////////////////////////////////////////////////////////
- // Utils
- //////////////////////////////////////////////////////////////////////////*/
-
- public void setTitle(String title) {
- Log.d(TAG, "setTitle() called with: title = [" + title + "]");
- if (activity.getSupportActionBar() != null) {
- activity.getSupportActionBar().setTitle(title);
- }
- }
-
/*//////////////////////////////////////////////////////////////////////////
// Load and handle
//////////////////////////////////////////////////////////////////////////*/
diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java
index 0cc5cabf3..1b24a5dce 100644
--- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java
@@ -43,7 +43,6 @@ import org.schabi.newpipe.util.AnimationUtils;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper;
-import org.schabi.newpipe.util.PermissionHelper;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -102,11 +101,7 @@ public class ChannelFragment extends BaseListInfoFragment {
if(activity != null
&& useAsFrontPage
&& isVisibleToUser) {
- try {
- activity.getSupportActionBar().setTitle(currentInfo.getName());
- } catch (Exception e) {
- onError(e);
- }
+ setTitle(currentInfo != null ? currentInfo.getName() : name);
}
}
diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java
index 424d28276..830471b73 100644
--- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java
@@ -57,6 +57,7 @@ public class KioskFragment extends BaseListInfoFragment {
@State
protected String kioskId = "";
+ protected String kioskTranslatedName;
/*//////////////////////////////////////////////////////////////////////////
// Views
@@ -87,16 +88,11 @@ public class KioskFragment extends BaseListInfoFragment {
//////////////////////////////////////////////////////////////////////////*/
@Override
- public void onActivityCreated(Bundle savedState) {
- super.onActivityCreated(savedState);
- try {
- activity.getSupportActionBar()
- .setTitle(KioskTranslator.getTranslatedKioskName(kioskId, getActivity()));
- } catch (Exception e) {
- onUnrecoverableError(e, UserAction.UI_ERROR,
- "none",
- "none", R.string.app_ui_crash);
- }
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ kioskTranslatedName = KioskTranslator.getTranslatedKioskName(kioskId, activity);
+ name = kioskTranslatedName;
}
@Override
@@ -104,8 +100,7 @@ public class KioskFragment extends BaseListInfoFragment {
super.setUserVisibleHint(isVisibleToUser);
if(useAsFrontPage && isVisibleToUser && activity != null) {
try {
- activity.getSupportActionBar()
- .setTitle(KioskTranslator.getTranslatedKioskName(kioskId, getActivity()));
+ setTitle(kioskTranslatedName);
} catch (Exception e) {
onUnrecoverableError(e, UserAction.UI_ERROR,
"none",
@@ -115,11 +110,8 @@ public class KioskFragment extends BaseListInfoFragment {
}
@Override
- public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_kiosk, container, false);
- activity.getSupportActionBar()
- .setTitle(KioskTranslator.getTranslatedKioskName(kioskId, getActivity()));
- return view;
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.fragment_kiosk, container, false);
}
/*//////////////////////////////////////////////////////////////////////////
@@ -171,9 +163,8 @@ public class KioskFragment extends BaseListInfoFragment {
public void handleResult(@NonNull final KioskInfo result) {
super.handleResult(result);
- String title = KioskTranslator.getTranslatedKioskName(result.id, getActivity());
- ActionBar supportActionBar = activity.getSupportActionBar();
- supportActionBar.setTitle(title);
+ name = kioskTranslatedName;
+ setTitle(kioskTranslatedName);
if (!result.getErrors().isEmpty()) {
showSnackBarError(result.getErrors(),
diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java
index 9e5420b6e..167b6f31b 100644
--- a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java
@@ -14,21 +14,17 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.schabi.newpipe.R;
-import org.schabi.newpipe.database.subscription.SubscriptionEntity;
import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.StreamingService;
-import org.schabi.newpipe.fragments.subscription.SubscriptionService;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.util.KioskTranslator;
-import org.schabi.newpipe.util.ServiceIconMapper;
+import org.schabi.newpipe.util.ServiceHelper;
import java.util.List;
import java.util.Vector;
-import io.reactivex.android.schedulers.AndroidSchedulers;
-import io.reactivex.schedulers.Schedulers;
-
/**
* Created by Christian Schabesberger on 09.10.17.
* SelectKioskFragment.java is part of NewPipe.
@@ -125,13 +121,15 @@ public class SelectKioskFragment extends DialogFragment {
throws Exception {
for(StreamingService service : NewPipe.getServices()) {
+ //TODO: Multi-service support
+ if (service.getServiceId() != ServiceList.YouTube.getId()) continue;
+
for(String kioskId : service.getKioskList().getAvailableKiosks()) {
String name = String.format(getString(R.string.service_kiosk_string),
service.getServiceInfo().name,
KioskTranslator.getTranslatedKioskName(kioskId, getContext()));
kioskList.add(new Entry(
- //ServiceIconMapper.getIconResource(service.getServiceId()),
- ServiceIconMapper.getIconResource(-1),
+ ServiceHelper.getIcon(service.getServiceId()),
service.getServiceId(),
kioskId,
name));
@@ -140,9 +138,7 @@ public class SelectKioskFragment extends DialogFragment {
}
public int getItemCount() {
- //todo: uncommend this line on multyservice support
- //return kioskList.size();
- return 1;
+ return kioskList.size();
}
public SelectKioskItemHolder onCreateViewHolder(ViewGroup parent, int type) {
diff --git a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java
new file mode 100644
index 000000000..e8a051849
--- /dev/null
+++ b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java
@@ -0,0 +1,67 @@
+package org.schabi.newpipe.util;
+
+import android.content.Context;
+import android.preference.PreferenceManager;
+import android.support.annotation.DrawableRes;
+
+import org.schabi.newpipe.BuildConfig;
+import org.schabi.newpipe.R;
+import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.ServiceList;
+import org.schabi.newpipe.extractor.StreamingService;
+import org.schabi.newpipe.extractor.exceptions.ExtractionException;
+
+public class ServiceHelper {
+ private static final StreamingService DEFAULT_FALLBACK_SERVICE = ServiceList.YouTube.getService();
+
+ @DrawableRes
+ public static int getIcon(int serviceId) {
+ switch (serviceId) {
+ case 0:
+ return R.drawable.youtube;
+ case 1:
+ return R.drawable.soundcloud;
+ default:
+ return R.drawable.service;
+ }
+ }
+
+ public static int getSelectedServiceId(Context context) {
+ if (BuildConfig.BUILD_TYPE.equals("release")) return DEFAULT_FALLBACK_SERVICE.getServiceId();
+
+ final String serviceName = PreferenceManager.getDefaultSharedPreferences(context)
+ .getString(context.getString(R.string.current_service_key), context.getString(R.string.default_service_value));
+
+ int serviceId;
+ try {
+ serviceId = NewPipe.getService(serviceName).getServiceId();
+ } catch (ExtractionException e) {
+ serviceId = DEFAULT_FALLBACK_SERVICE.getServiceId();
+ }
+
+ return serviceId;
+ }
+
+ public static void setSelectedServiceId(Context context, int serviceId) {
+ String serviceName;
+ try {
+ serviceName = NewPipe.getService(serviceId).getServiceInfo().name;
+ } catch (ExtractionException e) {
+ serviceName = DEFAULT_FALLBACK_SERVICE.getServiceInfo().name;
+ }
+
+ setSelectedServicePreferences(context, serviceName);
+ }
+
+ public static void setSelectedServiceId(Context context, String serviceName) {
+ int serviceId = NewPipe.getIdOfService(serviceName);
+ if (serviceId == -1) serviceName = DEFAULT_FALLBACK_SERVICE.getServiceInfo().name;
+
+ setSelectedServicePreferences(context, serviceName);
+ }
+
+ private static void setSelectedServicePreferences(Context context, String serviceName) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit().
+ putString(context.getString(R.string.current_service_key), serviceName).apply();
+ }
+}
diff --git a/app/src/main/java/org/schabi/newpipe/util/ServiceIconMapper.java b/app/src/main/java/org/schabi/newpipe/util/ServiceIconMapper.java
deleted file mode 100644
index 060013dd2..000000000
--- a/app/src/main/java/org/schabi/newpipe/util/ServiceIconMapper.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.schabi.newpipe.util;
-
-import org.schabi.newpipe.R;
-import org.schabi.newpipe.extractor.NewPipe;
-
-/**
- * Created by Chrsitian Schabesberger on 09.10.17.
- * ServiceIconMapper.java is part of NewPipe.
- *
- * 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.
- *
- * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with NewPipe. If not, see .
- */
-
-public class ServiceIconMapper {
- public static int getIconResource(int service_id) {
- switch(service_id) {
- case 0:
- return R.drawable.youtube;
- case 1:
- return R.drawable.soud_cloud;
- default:
- return R.drawable.service;
- }
- }
-}
diff --git a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java
index b2a20c491..b0e00465a 100644
--- a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java
+++ b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java
@@ -7,16 +7,32 @@ import android.support.annotation.AttrRes;
import android.support.annotation.StyleRes;
import org.schabi.newpipe.R;
+import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.StreamingService;
+import org.schabi.newpipe.extractor.exceptions.ExtractionException;
public class ThemeHelper {
/**
* Apply the selected theme (on NewPipe settings) in the context
+ * with the default style (see {@link #setTheme(Context, int)}).
*
* @param context context that the theme will be applied
*/
public static void setTheme(Context context) {
- context.setTheme(getSelectedThemeStyle(context));
+ setTheme(context, -1);
+ }
+
+ /**
+ * Apply the selected theme (on NewPipe settings) in the context,
+ * themed according with the styles defined for the service .
+ *
+ * @param context context that the theme will be applied
+ * @param serviceId the theme will be styled to the service with this id,
+ * pass -1 to get the default style
+ */
+ public static void setTheme(Context context, int serviceId) {
+ context.setTheme(getThemeForService(context, serviceId));
}
/**
@@ -29,18 +45,42 @@ public class ThemeHelper {
}
@StyleRes
- public static int getSelectedThemeStyle(Context context) {
+ public static int getThemeForService(Context context, int serviceId) {
String lightTheme = context.getResources().getString(R.string.light_theme_key);
String darkTheme = context.getResources().getString(R.string.dark_theme_key);
String blackTheme = context.getResources().getString(R.string.black_theme_key);
String selectedTheme = getSelectedTheme(context);
- if (selectedTheme.equals(lightTheme)) return R.style.LightTheme;
- else if (selectedTheme.equals(blackTheme)) return R.style.BlackTheme;
- else if (selectedTheme.equals(darkTheme)) return R.style.DarkTheme;
- // Fallback
- else return R.style.DarkTheme;
+ int defaultTheme = R.style.DarkTheme;
+ if (selectedTheme.equals(lightTheme)) defaultTheme = R.style.LightTheme;
+ else if (selectedTheme.equals(blackTheme)) defaultTheme = R.style.BlackTheme;
+ else if (selectedTheme.equals(darkTheme)) defaultTheme = R.style.DarkTheme;
+
+ if (serviceId <= -1) {
+ return defaultTheme;
+ }
+
+ final StreamingService service;
+ try {
+ service = NewPipe.getService(serviceId);
+ } catch (ExtractionException ignored) {
+ return defaultTheme;
+ }
+
+ String themeName = "DarkTheme";
+ if (selectedTheme.equals(lightTheme)) themeName = "LightTheme";
+ else if (selectedTheme.equals(blackTheme)) themeName = "BlackTheme";
+ else if (selectedTheme.equals(darkTheme)) themeName = "DarkTheme";
+
+ themeName += "." + service.getServiceInfo().name;
+ int resourceId = context.getResources().getIdentifier(themeName, "style", context.getPackageName());
+
+ if (resourceId > 0) {
+ return resourceId;
+ }
+
+ return defaultTheme;
}
public static String getSelectedTheme(Context context) {
diff --git a/app/src/main/res/anim/switch_service_in.xml b/app/src/main/res/anim/switch_service_in.xml
new file mode 100644
index 000000000..a49d1daba
--- /dev/null
+++ b/app/src/main/res/anim/switch_service_in.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/app/src/main/res/anim/switch_service_out.xml b/app/src/main/res/anim/switch_service_out.xml
new file mode 100644
index 000000000..635d1630e
--- /dev/null
+++ b/app/src/main/res/anim/switch_service_out.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/app/src/main/res/drawable-nodpi/soud_cloud.png b/app/src/main/res/drawable-nodpi/soundcloud.png
similarity index 100%
rename from app/src/main/res/drawable-nodpi/soud_cloud.png
rename to app/src/main/res/drawable-nodpi/soundcloud.png
diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml
index b1dd3e20b..abbe69ff7 100644
--- a/app/src/main/res/layout/fragment_main.xml
+++ b/app/src/main/res/layout/fragment_main.xml
@@ -11,7 +11,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
- android:background="@color/dark_youtube_primary_color"
+ android:background="?attr/colorPrimary"
app:tabGravity="fill"/>
\ No newline at end of file
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index a2aa5f648..e7a459c07 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -328,5 +328,4 @@
Obtention des infos…
Le contenu demandé est en chargement
-\@string/preferred_player_settings_title
diff --git a/app/src/main/res/values-nb-rNO/strings.xml b/app/src/main/res/values-nb-rNO/strings.xml
index 2e14fa438..95c4d63e2 100644
--- a/app/src/main/res/values-nb-rNO/strings.xml
+++ b/app/src/main/res/values-nb-rNO/strings.xml
@@ -314,7 +314,6 @@
Fant ingen videostrømmer
Fant ingen lydstrømmer
- \@string/preferred_player_settings_title
Åpne med foretrukket avspiller
Foretrukket avpsiller
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
index e14d9cb80..61bc5e520 100644
--- a/app/src/main/res/values/attrs.xml
+++ b/app/src/main/res/values/attrs.xml
@@ -1,5 +1,6 @@
+
@@ -23,6 +24,8 @@
+
+
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 1b9d102bf..21f19fc7b 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -1,11 +1,9 @@
+ #CD201F
#EEEEEE
- #e53935
- #d32f2f
- #000000
#e53935
#32000000
#48868686
@@ -18,9 +16,6 @@
#222222
- #CD322E
- #BC211D
- #FFFFFF
#ff5252
#0affffff
#48ffffff
diff --git a/app/src/main/res/values/colors_services.xml b/app/src/main/res/values/colors_services.xml
new file mode 100644
index 000000000..36a292453
--- /dev/null
+++ b/app/src/main/res/values/colors_services.xml
@@ -0,0 +1,21 @@
+
+
+
+ #e53935
+ #d32f2f
+ #000000
+
+ #CD322E
+ #BC211D
+ #FFFFFF
+
+
+ #f57c00
+ #ef6c00
+ #000000
+
+ #f57c00
+ #ef6c00
+ #FFFFFF
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/ic_launcher_background.xml b/app/src/main/res/values/ic_launcher_background.xml
deleted file mode 100644
index 1633e193a..000000000
--- a/app/src/main/res/values/ic_launcher_background.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
- #CD201F
-
diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml
index 7a34d296b..c817ae5f9 100644
--- a/app/src/main/res/values/settings_keys.xml
+++ b/app/src/main/res/values/settings_keys.xml
@@ -1,7 +1,12 @@
- current_service
+
+ - @string/youtube
+ - @string/soundcloud
+
+ service
+ @string/youtube
download_path
@@ -46,12 +51,6 @@
- 144p
-
- - @string/youtube
- - @string/soundcloud
-
- service
- @string/youtube
video_mp4
video_webm
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6d5e48d2d..60132ccad 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -345,7 +345,7 @@
SoundCloud
- @string/preferred_player_settings_title
+ @string/preferred_player_settings_title
Open with preferred player
Preferred player
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index a71e01743..ee526ca41 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -1,6 +1,15 @@
-
+
+
+
+
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/styles_services.xml b/app/src/main/res/values/styles_services.xml
new file mode 100644
index 000000000..6ed8c29e9
--- /dev/null
+++ b/app/src/main/res/values/styles_services.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file