diff --git a/app/build.gradle b/app/build.gradle index 31ec4776a..f88a43ffc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,7 +54,7 @@ dependencies { exclude module: 'support-annotations' }) - implementation 'com.github.yausername:NewPipeExtractor:df0db84' + implementation 'com.github.yausername:NewPipeExtractor:b1a77fa' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.23.0' diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index a9f2e9622..729bb2bd4 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -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); diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 82604f7da..5388d1821 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -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 diff --git a/app/src/main/java/org/schabi/newpipe/util/KioskTranslator.java b/app/src/main/java/org/schabi/newpipe/util/KioskTranslator.java index 392892cef..61bd2323d 100644 --- a/app/src/main/java/org/schabi/newpipe/util/KioskTranslator.java +++ b/app/src/main/java/org/schabi/newpipe/util/KioskTranslator.java @@ -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; } diff --git a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java index 7c781eb14..ab2d7c6b9 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java @@ -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()); + } + } } 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 1d1b66bf9..b8fba6ce5 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java @@ -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) { diff --git a/app/src/main/res/drawable-hdpi/ic_kiosklocal_black_24dp.png b/app/src/main/res/drawable-hdpi/ic_kiosklocal_black_24dp.png new file mode 100755 index 000000000..a9e2993eb Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_kiosklocal_black_24dp.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_kiosklocal_white_24dp.png b/app/src/main/res/drawable-hdpi/ic_kiosklocal_white_24dp.png new file mode 100755 index 000000000..a9af000b4 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_kiosklocal_white_24dp.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_kioskrecent_black_24dp.png b/app/src/main/res/drawable-hdpi/ic_kioskrecent_black_24dp.png new file mode 100755 index 000000000..13813ff82 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_kioskrecent_black_24dp.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_kioskrecent_white_24dp.png b/app/src/main/res/drawable-hdpi/ic_kioskrecent_white_24dp.png new file mode 100755 index 000000000..9054e0042 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_kioskrecent_white_24dp.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_kiosklocal_black_24dp.png b/app/src/main/res/drawable-mdpi/ic_kiosklocal_black_24dp.png new file mode 100755 index 000000000..1eba63792 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_kiosklocal_black_24dp.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_kiosklocal_white_24dp.png b/app/src/main/res/drawable-mdpi/ic_kiosklocal_white_24dp.png new file mode 100755 index 000000000..23d8145f5 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_kiosklocal_white_24dp.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_kioskrecent_black_24dp.png b/app/src/main/res/drawable-mdpi/ic_kioskrecent_black_24dp.png new file mode 100755 index 000000000..adc36b227 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_kioskrecent_black_24dp.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_kioskrecent_white_24dp.png b/app/src/main/res/drawable-mdpi/ic_kioskrecent_white_24dp.png new file mode 100755 index 000000000..c19bfe964 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_kioskrecent_white_24dp.png differ diff --git a/app/src/main/res/drawable-nodpi/place_holder_cloud.png b/app/src/main/res/drawable-nodpi/place_holder_cloud.png new file mode 100644 index 000000000..f78e846e1 Binary files /dev/null and b/app/src/main/res/drawable-nodpi/place_holder_cloud.png differ diff --git a/app/src/main/res/drawable-nodpi/place_holder_peertube.png b/app/src/main/res/drawable-nodpi/place_holder_peertube.png new file mode 100644 index 000000000..68850054d Binary files /dev/null and b/app/src/main/res/drawable-nodpi/place_holder_peertube.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_kiosklocal_black_24dp.png b/app/src/main/res/drawable-xhdpi/ic_kiosklocal_black_24dp.png new file mode 100755 index 000000000..e20865ab0 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_kiosklocal_black_24dp.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_kiosklocal_white_24dp.png b/app/src/main/res/drawable-xhdpi/ic_kiosklocal_white_24dp.png new file mode 100755 index 000000000..2d3474832 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_kiosklocal_white_24dp.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_kioskrecent_black_24dp.png b/app/src/main/res/drawable-xhdpi/ic_kioskrecent_black_24dp.png new file mode 100755 index 000000000..54e815980 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_kioskrecent_black_24dp.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_kioskrecent_white_24dp.png b/app/src/main/res/drawable-xhdpi/ic_kioskrecent_white_24dp.png new file mode 100755 index 000000000..3141a790d Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_kioskrecent_white_24dp.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_kiosklocal_black_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_kiosklocal_black_24dp.png new file mode 100755 index 000000000..bcbeb199c Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_kiosklocal_black_24dp.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_kiosklocal_white_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_kiosklocal_white_24dp.png new file mode 100755 index 000000000..6b27fb23c Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_kiosklocal_white_24dp.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_kioskrecent_black_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_kioskrecent_black_24dp.png new file mode 100755 index 000000000..92fc748ec Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_kioskrecent_black_24dp.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_kioskrecent_white_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_kioskrecent_white_24dp.png new file mode 100755 index 000000000..5b0aa6ae2 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_kioskrecent_white_24dp.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_kiosklocal_black_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_kiosklocal_black_24dp.png new file mode 100755 index 000000000..e208010a2 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_kiosklocal_black_24dp.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_kiosklocal_white_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_kiosklocal_white_24dp.png new file mode 100755 index 000000000..b04fd7a88 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_kiosklocal_white_24dp.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_kioskrecent_black_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_kioskrecent_black_24dp.png new file mode 100755 index 000000000..152259fab Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_kioskrecent_black_24dp.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_kioskrecent_white_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_kioskrecent_white_24dp.png new file mode 100755 index 000000000..1aac3b986 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_kioskrecent_white_24dp.png differ diff --git a/app/src/main/res/values-v21/styles_services.xml b/app/src/main/res/values-v21/styles_services.xml index e3d6c24e2..012772fc2 100644 --- a/app/src/main/res/values-v21/styles_services.xml +++ b/app/src/main/res/values-v21/styles_services.xml @@ -31,4 +31,23 @@ @color/dark_soundcloud_accent_color + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 7b879fb4c..c03defcd3 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -28,6 +28,8 @@ + + diff --git a/app/src/main/res/values/colors_services.xml b/app/src/main/res/values/colors_services.xml index 761b721d0..2aaa2d4e6 100644 --- a/app/src/main/res/values/colors_services.xml +++ b/app/src/main/res/values/colors_services.xml @@ -22,4 +22,15 @@ #FFFFFF #ff9100 + + #f97d46 + #c04e19 + #000000 + #f97d46 + + #f97d46 + #c04e19 + #FFFFFF + #f97d46 + \ No newline at end of file diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index be0709b66..7530bd8e8 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -143,6 +143,8 @@ en GB content_language + peertube_instance_url + peertube_instance_name content_country show_age_restricted_content use_tor diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 12a5d8ca7..ff9c04737 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -107,6 +107,7 @@ Default content country Service Default content language + PeerTube instance Player Behavior Video & audio diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 87e19cede..1ba7699eb 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -44,6 +44,8 @@ @drawable/ic_play_arrow_black_24dp @drawable/ic_settings_black_24dp @drawable/ic_whatshot_black_24dp + @drawable/ic_kiosklocal_black_24dp + @drawable/ic_kioskrecent_black_24dp @drawable/ic_channel_black_24dp @drawable/ic_bookmark_black_24dp @drawable/ic_playlist_add_black_24dp @@ -104,6 +106,8 @@ @drawable/ic_play_arrow_white_24dp @drawable/ic_settings_white_24dp @drawable/ic_whatshot_white_24dp + @drawable/ic_kiosklocal_white_24dp + @drawable/ic_kioskrecent_white_24dp @drawable/ic_channel_white_24dp @drawable/ic_bookmark_white_24dp @drawable/ic_playlist_add_white_24dp diff --git a/app/src/main/res/values/styles_services.xml b/app/src/main/res/values/styles_services.xml index 7ca9dacde..82eac26ab 100644 --- a/app/src/main/res/values/styles_services.xml +++ b/app/src/main/res/values/styles_services.xml @@ -28,4 +28,23 @@ @color/dark_soundcloud_accent_color + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index bd623f833..e998c96ab 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -18,6 +18,11 @@ android:summary="%s" android:title="@string/content_language_title"/> + +