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 4c0c7aec3..381c20ff1 100644
--- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java
@@ -1,10 +1,17 @@
package org.schabi.newpipe.settings;
+import android.app.Activity;
import android.os.Bundle;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import org.schabi.newpipe.R;
+import org.schabi.newpipe.extractor.NewPipe;
+import org.schabi.newpipe.extractor.StreamingService;
+import org.schabi.newpipe.extractor.exceptions.ExtractionException;
+import org.schabi.newpipe.report.ErrorActivity;
+import org.schabi.newpipe.report.UserAction;
+import org.schabi.newpipe.util.KioskTranslator;
public class ContentSettingsFragment extends BasePreferenceFragment {
@@ -14,7 +21,6 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
addPreferencesFromResource(R.xml.content_settings);
final ListPreference mainPageContentPref = (ListPreference) findPreference(getString(R.string.main_page_content_key));
-
mainPageContentPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValueO) {
@@ -25,7 +31,36 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
final String mainPrefOldSummary = getMainPagePrefSummery(mainPrefOldValue, mainPageContentPref);
if(newValue.equals(getString(R.string.kiosk_page_key))) {
- //todo on multyservice support show a kiosk an service selector here
+ SelectKioskFragment selectKioskFragment = new SelectKioskFragment();
+ selectKioskFragment.setOnSelectedLisener(new SelectKioskFragment.OnSelectedLisener() {
+ @Override
+ public void onKioskSelected(String kioskId, int service_id) {
+ defaultPreferences.edit()
+ .putInt(getString(R.string.main_page_selected_service), service_id).apply();
+ defaultPreferences.edit()
+ .putString(getString(R.string.main_page_selectd_kiosk_id), kioskId).apply();
+ String summary = "";
+ try {
+ summary += NewPipe.getService(service_id).getServiceInfo().name;
+ } catch (ExtractionException e) {
+ onError(e);
+ }
+ summary += "/";
+ summary += KioskTranslator.getTranslatedKioskName(kioskId, getContext());
+
+
+
+ mainPageContentPref.setSummary(summary);
+ }
+ });
+ selectKioskFragment.setOnCancelListener(new SelectKioskFragment.OnCancelListener() {
+ @Override
+ public void onCancel() {
+ mainPageContentPref.setSummary(mainPrefOldSummary);
+ mainPageContentPref.setValue(mainPrefOldValue);
+ }
+ });
+ selectKioskFragment.show(getFragmentManager(), "select_kiosk");
} else if(newValue.equals(getString(R.string.channel_page_key))) {
SelectChannelFragment selectChannelFragment = new SelectChannelFragment();
selectChannelFragment.setOnSelectedLisener(new SelectChannelFragment.OnSelectedLisener() {
@@ -38,23 +73,18 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
defaultPreferences.edit()
.putString(getString(R.string.main_page_selected_channel_name), name).apply();
- //change summery
mainPageContentPref.setSummary(name);
}
});
selectChannelFragment.setOnCancelListener(new SelectChannelFragment.OnCancelListener() {
@Override
public void onCancel() {
- //defaultPreferences.edit()
- // .putString(getString(R.string.main_page_content_key), mainPrefOldValue).apply();
mainPageContentPref.setSummary(mainPrefOldSummary);
mainPageContentPref.setValue(mainPrefOldValue);
}
});
selectChannelFragment.show(getFragmentManager(), "select_channel");
- }
-
- if(!newValue.equals(getString(R.string.channel_page_key))) {
+ } else {
mainPageContentPref.setSummary(getMainPageSummeryByKey(newValue));
}
@@ -68,11 +98,28 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
super.onResume();
final String mainPageContentKey = getString(R.string.main_page_content_key);
- if(defaultPreferences.getString(mainPageContentKey,
- getString(R.string.blank_page_key))
+ final Preference mainPagePref = findPreference(getString(R.string.main_page_content_key));
+ final String bpk = getString(R.string.blank_page_key);
+ if(defaultPreferences.getString(mainPageContentKey, bpk)
.equals(getString(R.string.channel_page_key))) {
- Preference pref = findPreference(getString(R.string.main_page_content_key));
- pref.setSummary(defaultPreferences.getString(getString(R.string.main_page_selected_channel_name), "error"));
+ mainPagePref.setSummary(defaultPreferences.getString(getString(R.string.main_page_selected_channel_name), "error"));
+ } else if(defaultPreferences.getString(mainPageContentKey, bpk)
+ .equals(getString(R.string.kiosk_page_key))) {
+ try {
+ StreamingService service = NewPipe.getService(
+ defaultPreferences.getInt(
+ getString(R.string.main_page_selected_service), 0));
+ String summary = "";
+ summary += service.getServiceInfo().name;
+ summary += "/";
+ summary += KioskTranslator.getTranslatedKioskName(
+ defaultPreferences.getString(
+ getString(R.string.main_page_selectd_kiosk_id), "Trending"),
+ getContext());
+ mainPagePref.setSummary(summary);
+ } catch (Exception e) {
+ onError(e);
+ }
}
}
@@ -101,4 +148,18 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
}
return R.string.blank_page_summary;
}
+
+ /*//////////////////////////////////////////////////////////////////////////
+ // Error
+ //////////////////////////////////////////////////////////////////////////*/
+
+ protected boolean onError(Throwable e) {
+ final Activity activity = getActivity();
+ ErrorActivity.reportError(activity, e,
+ activity.getClass(),
+ null,
+ ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR,
+ "none", "", R.string.app_ui_crash));
+ return true;
+ }
}
diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java
new file mode 100644
index 000000000..6e7ba191e
--- /dev/null
+++ b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java
@@ -0,0 +1,185 @@
+package org.schabi.newpipe.settings;
+
+import android.app.Activity;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+import android.support.v4.content.ContextCompat;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+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.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 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.
+ *
+ * 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 SelectKioskFragment extends DialogFragment {
+
+ RecyclerView recyclerView = null;
+ SelectKioskAdapter selectKioskAdapter = null;
+
+ /*//////////////////////////////////////////////////////////////////////////
+ // Interfaces
+ //////////////////////////////////////////////////////////////////////////*/
+
+ public interface OnSelectedLisener {
+ void onKioskSelected(String kioskId, int service_id);
+ }
+
+ OnSelectedLisener onSelectedLisener = null;
+ public void setOnSelectedLisener(OnSelectedLisener listener) {
+ onSelectedLisener = listener;
+ }
+
+ public interface OnCancelListener {
+ void onCancel();
+ }
+ OnCancelListener onCancelListener = null;
+ public void setOnCancelListener(OnCancelListener listener) {
+ onCancelListener = listener;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View v = inflater.inflate(R.layout.select_kiosk_fragment, container, false);
+ recyclerView = (RecyclerView) v.findViewById(R.id.items_list);
+ recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+ try {
+ selectKioskAdapter = new SelectKioskAdapter();
+ } catch (Exception e) {
+ onError(e);
+ }
+ recyclerView.setAdapter(selectKioskAdapter);
+
+ return v;
+ }
+
+ /*//////////////////////////////////////////////////////////////////////////
+ // Handle actions
+ //////////////////////////////////////////////////////////////////////////*/
+
+ @Override
+ public void onCancel(final DialogInterface dialogInterface) {
+ super.onCancel(dialogInterface);
+ if(onCancelListener != null) {
+ onCancelListener.onCancel();
+ }
+ }
+
+ private void clickedItem(SelectKioskAdapter.Entry entry) {
+ if(onSelectedLisener != null) {
+ onSelectedLisener.onKioskSelected(entry.kioskId, entry.serviceId);
+ }
+ dismiss();
+ }
+
+ private class SelectKioskAdapter
+ extends RecyclerView.Adapter {
+ public class Entry {
+ public Entry (int i, int si, String ki, String kn){
+ icon = i; serviceId=si; kioskId=ki; kioskName = kn;
+ }
+ int icon;
+ int serviceId;
+ String kioskId;
+ String kioskName;
+ };
+
+ private List kioskList = new Vector<>();
+
+ public SelectKioskAdapter()
+ throws Exception {
+ for(StreamingService service : NewPipe.getServices()) {
+ for(String kioskId : service.getKioskList().getAvailableKisoks()) {
+ kioskList.add(new Entry(
+ ServiceIconMapper.getIconResource(service.getServiceId()),
+ service.getServiceId(),
+ kioskId,
+ KioskTranslator.getTranslatedKioskName(kioskId, getContext())));
+ }
+ }
+ }
+
+ public int getItemCount() {
+ return kioskList.size();
+ }
+
+ public SelectKioskItemHolder onCreateViewHolder(ViewGroup parent, int type) {
+ View item = LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.select_kiosk_item, parent, false);
+ return new SelectKioskItemHolder(item);
+ }
+
+ public class SelectKioskItemHolder extends RecyclerView.ViewHolder {
+ public SelectKioskItemHolder(View v) {
+ super(v);
+ this.view = v;
+ thumbnailView = v.findViewById(R.id.itemThumbnailView);
+ titleView = v.findViewById(R.id.itemTitleView);
+ }
+ public View view;
+ public ImageView thumbnailView;
+ public TextView titleView;
+ }
+
+ public void onBindViewHolder(SelectKioskItemHolder holder, final int position) {
+ final Entry entry = kioskList.get(position);
+ holder.titleView.setText(entry.kioskName);
+ holder.thumbnailView.setImageDrawable(ContextCompat.getDrawable(getContext(), entry.icon));
+ holder.view.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ clickedItem(entry);
+ }
+ });
+ }
+ }
+
+ /*//////////////////////////////////////////////////////////////////////////
+ // Error
+ //////////////////////////////////////////////////////////////////////////*/
+
+ protected boolean onError(Throwable e) {
+ final Activity activity = getActivity();
+ ErrorActivity.reportError(activity, e,
+ activity.getClass(),
+ null,
+ ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR,
+ "none", "", R.string.app_ui_crash));
+ return true;
+ }
+}
diff --git a/app/src/main/java/org/schabi/newpipe/util/ServiceIconMapper.java b/app/src/main/java/org/schabi/newpipe/util/ServiceIconMapper.java
new file mode 100644
index 000000000..060013dd2
--- /dev/null
+++ b/app/src/main/java/org/schabi/newpipe/util/ServiceIconMapper.java
@@ -0,0 +1,35 @@
+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/res/drawable-nodpi/service.png b/app/src/main/res/drawable-nodpi/service.png
new file mode 100644
index 000000000..cfaff19e2
Binary files /dev/null and b/app/src/main/res/drawable-nodpi/service.png differ
diff --git a/app/src/main/res/layout/select_kiosk_fragment.xml b/app/src/main/res/layout/select_kiosk_fragment.xml
new file mode 100644
index 000000000..7be96754a
--- /dev/null
+++ b/app/src/main/res/layout/select_kiosk_fragment.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/select_kiosk_item.xml b/app/src/main/res/layout/select_kiosk_item.xml
new file mode 100644
index 000000000..818380849
--- /dev/null
+++ b/app/src/main/res/layout/select_kiosk_item.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e11483ac0..371ad1688 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -282,6 +282,7 @@
Select a channel
No channel subscribed yet
+ Select a kiosk
Kisok
diff --git a/assets/service.svg b/assets/service.svg
new file mode 100644
index 000000000..172cc106f
--- /dev/null
+++ b/assets/service.svg
@@ -0,0 +1,109 @@
+
+
+
+