1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

add selector for kiosk

This commit is contained in:
Christian Schabesberger 2017-10-09 14:22:27 +02:00
parent cbfc359a99
commit 7f9f075147
8 changed files with 466 additions and 12 deletions

View File

@ -1,10 +1,17 @@
package org.schabi.newpipe.settings; package org.schabi.newpipe.settings;
import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.preference.ListPreference; import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import org.schabi.newpipe.R; 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 { public class ContentSettingsFragment extends BasePreferenceFragment {
@ -14,7 +21,6 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
addPreferencesFromResource(R.xml.content_settings); addPreferencesFromResource(R.xml.content_settings);
final ListPreference mainPageContentPref = (ListPreference) findPreference(getString(R.string.main_page_content_key)); final ListPreference mainPageContentPref = (ListPreference) findPreference(getString(R.string.main_page_content_key));
mainPageContentPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { mainPageContentPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValueO) { public boolean onPreferenceChange(Preference preference, Object newValueO) {
@ -25,7 +31,36 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
final String mainPrefOldSummary = getMainPagePrefSummery(mainPrefOldValue, mainPageContentPref); final String mainPrefOldSummary = getMainPagePrefSummery(mainPrefOldValue, mainPageContentPref);
if(newValue.equals(getString(R.string.kiosk_page_key))) { 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))) { } else if(newValue.equals(getString(R.string.channel_page_key))) {
SelectChannelFragment selectChannelFragment = new SelectChannelFragment(); SelectChannelFragment selectChannelFragment = new SelectChannelFragment();
selectChannelFragment.setOnSelectedLisener(new SelectChannelFragment.OnSelectedLisener() { selectChannelFragment.setOnSelectedLisener(new SelectChannelFragment.OnSelectedLisener() {
@ -38,23 +73,18 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
defaultPreferences.edit() defaultPreferences.edit()
.putString(getString(R.string.main_page_selected_channel_name), name).apply(); .putString(getString(R.string.main_page_selected_channel_name), name).apply();
//change summery
mainPageContentPref.setSummary(name); mainPageContentPref.setSummary(name);
} }
}); });
selectChannelFragment.setOnCancelListener(new SelectChannelFragment.OnCancelListener() { selectChannelFragment.setOnCancelListener(new SelectChannelFragment.OnCancelListener() {
@Override @Override
public void onCancel() { public void onCancel() {
//defaultPreferences.edit()
// .putString(getString(R.string.main_page_content_key), mainPrefOldValue).apply();
mainPageContentPref.setSummary(mainPrefOldSummary); mainPageContentPref.setSummary(mainPrefOldSummary);
mainPageContentPref.setValue(mainPrefOldValue); mainPageContentPref.setValue(mainPrefOldValue);
} }
}); });
selectChannelFragment.show(getFragmentManager(), "select_channel"); selectChannelFragment.show(getFragmentManager(), "select_channel");
} } else {
if(!newValue.equals(getString(R.string.channel_page_key))) {
mainPageContentPref.setSummary(getMainPageSummeryByKey(newValue)); mainPageContentPref.setSummary(getMainPageSummeryByKey(newValue));
} }
@ -68,11 +98,28 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
super.onResume(); super.onResume();
final String mainPageContentKey = getString(R.string.main_page_content_key); final String mainPageContentKey = getString(R.string.main_page_content_key);
if(defaultPreferences.getString(mainPageContentKey, final Preference mainPagePref = findPreference(getString(R.string.main_page_content_key));
getString(R.string.blank_page_key)) final String bpk = getString(R.string.blank_page_key);
if(defaultPreferences.getString(mainPageContentKey, bpk)
.equals(getString(R.string.channel_page_key))) { .equals(getString(R.string.channel_page_key))) {
Preference pref = findPreference(getString(R.string.main_page_content_key)); mainPagePref.setSummary(defaultPreferences.getString(getString(R.string.main_page_selected_channel_name), "error"));
pref.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; 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;
}
} }

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<SelectKioskAdapter.SelectKioskItemHolder> {
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<Entry> 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;
}
}

View File

@ -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 <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;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/select_a_kiosk"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/items_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/select_kiosk_item">
</android.support.v7.widget.RecyclerView>
</LinearLayout>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="5dp">
<ImageView
android:id="@+id/itemThumbnailView"
android:layout_width="48dp"
android:layout_height="42dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginRight="5dp"
android:src="@drawable/service"
tools:ignore="RtlHardcoded"/>
<TextView
android:id="@+id/itemTitleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="@dimen/video_item_search_image_right_margin"
android:layout_toRightOf="@+id/itemThumbnailView"
android:layout_toEndOf="@+id/itemThumbnailView"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceListItem"
tools:text="Channel Title, Lorem ipsum"/>
</RelativeLayout>

View File

@ -282,6 +282,7 @@
</string-array> </string-array>
<string name="select_a_channel">Select a channel</string> <string name="select_a_channel">Select a channel</string>
<string name="no_channel_subscribed_yet">No channel subscribed yet</string> <string name="no_channel_subscribed_yet">No channel subscribed yet</string>
<string name="select_a_kiosk">Select a kiosk</string>
<!-- Kiosk Names --> <!-- Kiosk Names -->
<string name="kiosk">Kisok</string> <string name="kiosk">Kisok</string>

109
assets/service.svg Normal file
View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="200"
height="200"
viewBox="0 0 200 200"
id="svg2"
version="1.1"
inkscape:version="0.91 r"
sodipodi:docname="service.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.4"
inkscape:cx="81.080602"
inkscape:cy="119.84418"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:window-width="1865"
inkscape:window-height="1056"
inkscape:window-x="55"
inkscape:window-y="24"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-852.36216)">
<g
id="g4487"
transform="matrix(0.60000002,0,0,0.60000002,-242.14286,250.23051)">
<ellipse
ry="75"
rx="100"
cy="1052.3622"
cx="100"
id="path4152"
style="opacity:0.997;fill:#6c6c6c;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<circle
r="60"
cy="942.36218"
cx="100"
id="path4154"
style="opacity:0.997;fill:#6c6c6c;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
<g
id="g4209">
<rect
y="852.36218"
x="0"
height="200"
width="200"
id="rect4136"
style="opacity:0.997;fill:#999999;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.6875;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
ry="100" />
<g
id="g4204">
<circle
style="fill:#6c6c6c;fill-opacity:1;fill-rule:evenodd;stroke:#6c6c6c;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
id="path3354"
cx="32"
cy="952.36218"
r="17" />
<circle
style="fill:#6c6c6c;fill-opacity:1;fill-rule:evenodd;stroke:#6c6c6c;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
id="path3354-7"
cx="168"
cy="952.36218"
r="17"
inkscape:transform-center-x="194.28572"
inkscape:transform-center-y="3.8095239" />
<circle
style="fill:#6c6c6c;fill-opacity:1;fill-rule:evenodd;stroke:#6c6c6c;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
id="path3354-5"
cx="100"
cy="952.36218"
r="17" />
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.6 KiB