add selection for front page

This commit is contained in:
Christian Schabesberger 2017-09-26 17:29:38 +02:00
parent 5ebde97352
commit 65c8b6e66a
9 changed files with 387 additions and 19 deletions

View file

@ -10,22 +10,22 @@ import org.schabi.newpipe.util.NavigationHelper;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
/* /**
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org> * Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
* RouterActivity .java is part of NewPipe. * RouterActivity.java is part of NewPipe.
* *
* OpenHitboxStreams is free software: you can redistribute it and/or modify * NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* OpenHitboxStreams is distributed in the hope that it will be useful, * NewPipe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with OpenHitboxStreams. If not, see <http://www.gnu.org/licenses/>. * along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**

View file

@ -25,6 +25,8 @@ import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
import java.util.concurrent.ExecutionException;
public class MainFragment extends BaseFragment implements TabLayout.OnTabSelectedListener { public class MainFragment extends BaseFragment implements TabLayout.OnTabSelectedListener {
private ViewPager viewPager; private ViewPager viewPager;
private boolean showBlankTab = false; private boolean showBlankTab = false;
@ -124,20 +126,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
case 1: case 1:
return new SubscriptionFragment(); return new SubscriptionFragment();
default: default:
if(showBlankTab) { return getMainPageFramgent();
return new BlankFragment();
} else {
try {
return KioskFragment.getInstance(currentServiceId);
} catch (Exception e) {
ErrorActivity.reportError(activity, e,
activity.getClass(),
null,
ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR,
"none", "", R.string.app_ui_crash));
return new BlankFragment();
}
}
} }
} }
@ -151,4 +140,36 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
return this.tabTitles.length; return this.tabTitles.length;
} }
} }
/*//////////////////////////////////////////////////////////////////////////
// Main page content
//////////////////////////////////////////////////////////////////////////*/
private Fragment getMainPageFramgent() {
try {
final String set_main_page = PreferenceManager.getDefaultSharedPreferences(getActivity())
.getString(getString(R.string.main_page_content_key),
getString(R.string.main_page_selectd_kiosk_id));
if(set_main_page.equals(getString(R.string.blank_page_key))) {
return new BlankFragment();
} else if(set_main_page.equals(getString(R.string.kiosk_page_key))) {
return KioskFragment.getInstance(currentServiceId);
} else if(set_main_page.equals(getString(R.string.feed_page_key))) {
return new BlankFragment();
} else if(set_main_page.equals(getString(R.string.channel_page_key))) {
return new BlankFragment();
} else {
return new BlankFragment();
}
} catch (Exception e) {
ErrorActivity.reportError(activity, e,
activity.getClass(),
null,
ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR,
"none", "", R.string.app_ui_crash));
return new BlankFragment();
}
}
} }

View file

@ -1,6 +1,9 @@
package org.schabi.newpipe.settings; package org.schabi.newpipe.settings;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.util.Log;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
@ -8,5 +11,51 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.content_settings); addPreferencesFromResource(R.xml.content_settings);
findPreference(getString(R.string.main_page_content_key))
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValueO) {
final String newValue = newValueO.toString();
if(newValue.equals(getString(R.string.kiosk_page_key))) {
//todo on multyservice support show a kiosk an service selector here
} else if(newValue.equals(getString(R.string.channel_page_key))) {
SelectChannelFragment selectChannelFragment = new SelectChannelFragment();
selectChannelFragment.setOnSelectedLisener(new SelectChannelFragment.OnSelectedLisener() {
@Override
public void onChannelSelected(String url, String name, int service) {
defaultPreferences.edit()
.putInt(getString(R.string.main_page_selected_service), service).apply();
defaultPreferences.edit()
.putString(getString(R.string.main_page_selected_channel_url), url).apply();
defaultPreferences.edit()
.putString(getString(R.string.main_page_selected_channel_name), name).apply();
//change summery
Preference pref = findPreference(getString(R.string.main_page_content_key));
pref.setSummary(name);
}
});
selectChannelFragment.show(getFragmentManager(), "select_channel");
}
return true;
}
});
}
@Override
public void onResume() {
super.onResume();
final String mainPageContentKey = getString(R.string.main_page_content_key);
if(defaultPreferences.getString(mainPageContentKey,
getString(R.string.blank_page_key))
.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"));
}
} }
} }

View file

@ -0,0 +1,184 @@
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.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.schabi.newpipe.R;
import org.schabi.newpipe.database.subscription.SubscriptionEntity;
import org.schabi.newpipe.fragments.subscription.SubscriptionService;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
import java.util.List;
import java.util.Vector;
import de.hdodenhof.circleimageview.CircleImageView;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
/**
* Created by Christian Schabesberger on 26.09.17.
* SelectChannelFragment.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 SelectChannelFragment extends DialogFragment {
private SelectChannelAdapter channelAdapter;
private SubscriptionService subscriptionService;
private ProgressBar progressBar;
private TextView emptyView;
private RecyclerView recyclerView;
private List<SubscriptionEntity> subscriptions = new Vector<>();
public interface OnSelectedLisener {
public void onChannelSelected(String url, String name, int service);
}
OnSelectedLisener onSelectedLisener;
public void setOnSelectedLisener(OnSelectedLisener listener) {
onSelectedLisener = listener;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.select_channel_fragment, container, false);
recyclerView = (RecyclerView) v.findViewById(R.id.items_list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
channelAdapter = new SelectChannelAdapter();
recyclerView.setAdapter(channelAdapter);
progressBar = v.findViewById(R.id.progressBar);
emptyView = v.findViewById(R.id.empty_state_view);
progressBar.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
emptyView.setVisibility(View.GONE);
subscriptionService = SubscriptionService.getInstance();
subscriptionService.getSubscription().toObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(getSubscriptionObserver());
return v;
}
private void displayChannels(List<SubscriptionEntity> subscriptions) {
this.subscriptions = subscriptions;
progressBar.setVisibility(View.GONE);
if(subscriptions.isEmpty()) {
emptyView.setVisibility(View.VISIBLE);
return;
}
recyclerView.setVisibility(View.VISIBLE);
}
private void clickedItem(int position) {
if(onSelectedLisener != null) {
SubscriptionEntity entry = subscriptions.get(position);
onSelectedLisener.onChannelSelected(entry.getUrl(), entry.getName(), entry.getServiceId());
}
dismiss();
}
private Observer<List<SubscriptionEntity>> getSubscriptionObserver() {
return new Observer<List<SubscriptionEntity>>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(List<SubscriptionEntity> subscriptions) {
displayChannels(subscriptions);
}
@Override
public void onError(Throwable exception) {
onError(exception);
}
@Override
public void onComplete() {
}
};
}
private class SelectChannelAdapter extends
RecyclerView.Adapter<SelectChannelAdapter.SelectChannelItemHolder> {
@Override
public SelectChannelItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View item = LayoutInflater.from(parent.getContext())
.inflate(R.layout.select_channel_item, parent, false);
return new SelectChannelItemHolder(item);
}
@Override
public void onBindViewHolder(SelectChannelItemHolder holder, final int position) {
SubscriptionEntity entry = subscriptions.get(position);
holder.titleView.setText(entry.getName());
holder.view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
clickedItem(position);
}
});
}
@Override
public int getItemCount() {
return subscriptions.size();
}
public class SelectChannelItemHolder extends RecyclerView.ViewHolder {
public SelectChannelItemHolder(View v) {
super(v);
this.view = v;
thumbnailView = v.findViewById(R.id.itemThumbnailView);
titleView = v.findViewById(R.id.itemTitleView);
}
public View view;
public CircleImageView thumbnailView;
public TextView titleView;
}
}
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,42 @@
<?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_channel"
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_channel_item">
</android.support.v7.widget.RecyclerView>
<TextView
android:id="@+id/empty_state_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItem"
android:text="@string/no_channel_subscribed_yet"
android:layout_margin="10dp"/>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"/>
</LinearLayout>

View file

@ -0,0 +1,38 @@
<?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">
<de.hdodenhof.circleimageview.CircleImageView
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:contentDescription="@string/list_thumbnail_view_description"
android:src="@drawable/buddy"
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

@ -92,6 +92,7 @@
<item>@string/black_theme_title</item> <item>@string/black_theme_title</item>
</string-array> </string-array>
<!-- Content & History -->
<string name="show_search_suggestions_key" translatable="false">show_search_suggestions</string> <string name="show_search_suggestions_key" translatable="false">show_search_suggestions</string>
<string name="show_play_with_kodi_key" translatable="false">show_play_with_kodi</string> <string name="show_play_with_kodi_key" translatable="false">show_play_with_kodi</string>
<string name="show_next_video_key" translatable="false">show_next_video</string> <string name="show_next_video_key" translatable="false">show_next_video</string>
@ -101,6 +102,21 @@
<string name="use_tor_key" translatable="false">use_tor</string> <string name="use_tor_key" translatable="false">use_tor</string>
<string name="enable_search_history_key" translatable="false">enable_search_history</string> <string name="enable_search_history_key" translatable="false">enable_search_history</string>
<string name="enable_watch_history_key" translatable="false">enable_watch_history</string> <string name="enable_watch_history_key" translatable="false">enable_watch_history</string>
<string name="main_page_content_key" translatable="false">main_page_content</string>
<string name="blank_page_key" translatable="false">blank_page</string>
<string name="feed_page_key" translatable="false">feed_page</string>
<string name="kiosk_page_key" translatable="false">kiosk_page</string>
<string name="channel_page_key" translatable="false">channel_page</string>
<string-array name="main_page_content_pages" translatable="false">
<item>@string/blank_page_key</item>
<item>@string/kiosk_page_key</item>
<item>@string/feed_page_key</item>
<item>@string/channel_page_key</item>
</string-array>
<string name="main_page_selected_service" translatable="false">main_page_selected_service</string>
<string name="main_page_selected_channel_name" translatable="false">main_page_selected_channel_name</string>
<string name="main_page_selected_channel_url" translatable="false">main_page_selected_channel_url</string>
<string name="main_page_selectd_kiosk_id" translatable="false">main_page_selectd_kiosk_id</string>
<!-- FileName Downloads --> <!-- FileName Downloads -->
<string name="settings_file_charset_key" translatable="false">file_rename</string> <string name="settings_file_charset_key" translatable="false">file_rename</string>

View file

@ -265,4 +265,15 @@
<string name="history_empty">The history is empty</string> <string name="history_empty">The history is empty</string>
<string name="history_cleared">History cleared</string> <string name="history_cleared">History cleared</string>
<string name="item_deleted">Item deleted</string> <string name="item_deleted">Item deleted</string>
<!-- Content -->
<string name="main_page_content">Content of main page</string>
<string-array name="main_page_content_names">
<item>Blank Page</item>
<item>Trending Page</item>
<item>Feed Page</item>
<item>Channel Page</item>
</string-array>
<string name="select_a_channel">Select a channel</string>
<string name="no_channel_subscribed_yet">No channel subscribed yet</string>
</resources> </resources>

View file

@ -21,5 +21,12 @@
android:key="@string/show_search_suggestions_key" android:key="@string/show_search_suggestions_key"
android:summary="@string/show_search_suggestions_summary" android:summary="@string/show_search_suggestions_summary"
android:title="@string/show_search_suggestions_title"/> android:title="@string/show_search_suggestions_title"/>
<ListPreference
android:defaultValue="@string/kiosk_page_key"
android:entries="@array/main_page_content_names"
android:entryValues="@array/main_page_content_pages"
android:key="@string/main_page_content_key"
android:title="@string/main_page_content"
android:summary="%s"/>
</PreferenceScreen> </PreferenceScreen>