added themeing for peertube, change peertube instance
This commit is contained in:
parent
9530af95f4
commit
845663f80f
36 changed files with 140 additions and 4 deletions
|
|
@ -50,6 +50,7 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
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;
|
||||
import org.schabi.newpipe.fragments.BackPressable;
|
||||
|
|
@ -95,6 +96,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
|
||||
|
||||
ServiceHelper.initServices(this);
|
||||
|
||||
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
|
|||
|
|
@ -18,9 +18,11 @@ import com.nostra13.universalimageloader.core.ImageLoader;
|
|||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.ServiceList;
|
||||
import org.schabi.newpipe.extractor.utils.Localization;
|
||||
import org.schabi.newpipe.report.ErrorActivity;
|
||||
import org.schabi.newpipe.report.UserAction;
|
||||
import org.schabi.newpipe.util.Constants;
|
||||
import org.schabi.newpipe.util.FilePickerActivityHelper;
|
||||
import org.schabi.newpipe.util.ZipHelper;
|
||||
|
||||
|
|
@ -39,6 +41,9 @@ import java.util.Map;
|
|||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||
|
||||
private static final int REQUEST_IMPORT_PATH = 8945;
|
||||
|
|
@ -122,6 +127,40 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
|||
NewPipe.setLocalization(new Localization((String) newCountry, oldLocal.getLanguage()));
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
Preference peerTubeInstance = findPreference(getString(R.string.peertube_instance_url_key));
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
peerTubeInstance.setDefaultValue(sharedPreferences.getString(getString(R.string.peertube_instance_url_key), ServiceList.PeerTube.getBaseUrl()));
|
||||
peerTubeInstance.setSummary(sharedPreferences.getString(getString(R.string.peertube_instance_url_key), ServiceList.PeerTube.getBaseUrl()));
|
||||
|
||||
peerTubeInstance.setOnPreferenceChangeListener((Preference p, Object newInstance) -> {
|
||||
String url = (String) newInstance;
|
||||
if(!url.startsWith("https://")){
|
||||
Toast.makeText(getActivity(), "instance url should start with https://",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}else{
|
||||
boolean shouldUpdate = Single.fromCallable(() -> {
|
||||
ServiceList.PeerTube.setInstance(url);
|
||||
return true;
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.onErrorReturnItem(false)
|
||||
.blockingGet();
|
||||
|
||||
if (shouldUpdate) {
|
||||
p.setSummary(url);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString(getString(R.string.peertube_instance_name_key), ServiceList.PeerTube.getServiceInfo().getName()).apply();
|
||||
editor.putString(getString(R.string.current_service_key), ServiceList.PeerTube.getServiceInfo().getName()).apply();
|
||||
editor.putBoolean(Constants.KEY_MAIN_PAGE_CHANGE, true).apply();
|
||||
}else{
|
||||
Toast.makeText(getActivity(), "unable to update instance",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return shouldUpdate;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@ public class KioskTranslator {
|
|||
return ThemeHelper.resolveResourceIdFromAttr(c, R.attr.ic_hot);
|
||||
case "New & hot":
|
||||
return ThemeHelper.resolveResourceIdFromAttr(c, R.attr.ic_hot);
|
||||
case "Local":
|
||||
return ThemeHelper.resolveResourceIdFromAttr(c, R.attr.ic_kiosk_local);
|
||||
case "Recently added":
|
||||
return ThemeHelper.resolveResourceIdFromAttr(c, R.attr.ic_kiosk_recent);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.StringRes;
|
||||
|
|
@ -10,7 +11,9 @@ 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;
|
||||
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
|
|
@ -24,9 +27,11 @@ public class ServiceHelper {
|
|||
case 0:
|
||||
return R.drawable.place_holder_youtube;
|
||||
case 1:
|
||||
return R.drawable.place_holder_circle;
|
||||
return R.drawable.place_holder_cloud;
|
||||
case 2:
|
||||
return R.drawable.place_holder_peertube;
|
||||
default:
|
||||
return R.drawable.service;
|
||||
return R.drawable.place_holder_circle;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,4 +132,19 @@ public class ServiceHelper {
|
|||
default: return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void initService(Context context, int serviceId) {
|
||||
if(serviceId == 2){
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String peerTubeInstanceUrl = sharedPreferences.getString(context.getString(R.string.peertube_instance_url_key), ServiceList.PeerTube.getBaseUrl());
|
||||
String peerTubeInstanceName = sharedPreferences.getString(context.getString(R.string.peertube_instance_name_key), ServiceList.PeerTube.getServiceInfo().getName());
|
||||
ServiceList.PeerTube.setInstance(peerTubeInstanceUrl, peerTubeInstanceName);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initServices(Context context){
|
||||
for(StreamingService s : ServiceList.all()){
|
||||
initService(context, s.getServiceId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,7 +136,14 @@ public class ThemeHelper {
|
|||
else if (selectedTheme.equals(blackTheme)) themeName = "BlackTheme";
|
||||
else if (selectedTheme.equals(darkTheme)) themeName = "DarkTheme";
|
||||
|
||||
themeName += "." + service.getServiceInfo().getName();
|
||||
switch (serviceId) {
|
||||
case 2:
|
||||
//service name for peertube depends on the instance
|
||||
themeName += ".PeerTube";
|
||||
break;
|
||||
default:
|
||||
themeName += "." + service.getServiceInfo().getName();
|
||||
}
|
||||
int resourceId = context.getResources().getIdentifier(themeName, "style", context.getPackageName());
|
||||
|
||||
if (resourceId > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue