Fix and improve service switching (introduced colors)
- Every service now have its own colors - Fix bug navigation button and backstack count - Fix and themed properly the icons and colors of the main fragment tabs - Re-organized the styles and colors (too much in one file)
This commit is contained in:
parent
1ce7d66fb1
commit
3a8b04e2d1
24 changed files with 421 additions and 283 deletions
67
app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java
Normal file
67
app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java
Normal file
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue