mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-25 01:20:34 +00:00
fix channel selection
This commit is contained in:
parent
3490273b49
commit
29fee28d1d
@ -19,8 +19,8 @@ public abstract class BasePreferenceFragment extends PreferenceFragmentCompat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
defaultPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
defaultPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,22 +3,27 @@ package org.schabi.newpipe.settings;
|
|||||||
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 android.util.Log;
|
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.util.Constants;
|
|
||||||
|
|
||||||
public class ContentSettingsFragment extends BasePreferenceFragment {
|
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))
|
final ListPreference mainPageContentPref = (ListPreference) findPreference(getString(R.string.main_page_content_key));
|
||||||
.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) {
|
||||||
final String newValue = newValueO.toString();
|
final String newValue = newValueO.toString();
|
||||||
|
|
||||||
|
final String mainPrefOldValue =
|
||||||
|
defaultPreferences.getString(getString(R.string.main_page_content_key), "blank_page");
|
||||||
|
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
|
//todo on multyservice support show a kiosk an service selector here
|
||||||
} else if(newValue.equals(getString(R.string.channel_page_key))) {
|
} else if(newValue.equals(getString(R.string.channel_page_key))) {
|
||||||
@ -34,15 +39,25 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
|||||||
.putString(getString(R.string.main_page_selected_channel_name), name).apply();
|
.putString(getString(R.string.main_page_selected_channel_name), name).apply();
|
||||||
|
|
||||||
//change summery
|
//change summery
|
||||||
Preference pref = findPreference(getString(R.string.main_page_content_key));
|
mainPageContentPref.setSummary(name);
|
||||||
pref.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");
|
selectChannelFragment.show(getFragmentManager(), "select_channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!newValue.equals(getString(R.string.channel_page_key))) {
|
||||||
|
mainPageContentPref.setSummary(getMainPageSummeryByKey(newValue));
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -60,4 +75,28 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
|||||||
pref.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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Utils
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
private String getMainPagePrefSummery(final String mainPrefOldValue, final ListPreference mainPageContentPref) {
|
||||||
|
if(mainPrefOldValue.equals(getString(R.string.channel_page_key))) {
|
||||||
|
return defaultPreferences.getString(getString(R.string.main_page_selected_channel_name), "error");
|
||||||
|
} else {
|
||||||
|
return mainPageContentPref.getSummary().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getMainPageSummeryByKey(final String key) {
|
||||||
|
if(key.equals(getString(R.string.blank_page_key))) {
|
||||||
|
return R.string.blank_page_summary;
|
||||||
|
} else if(key.equals(getString(R.string.kiosk_page_key))) {
|
||||||
|
return R.string.kiosk_page_summary;
|
||||||
|
} else if(key.equals(getString(R.string.feed_page_key))) {
|
||||||
|
return R.string.feed_page_summary;
|
||||||
|
} else if(key.equals(getString(R.string.channel_page_key))) {
|
||||||
|
return R.string.channel_page_summary;
|
||||||
|
}
|
||||||
|
return R.string.blank_page_summary;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,9 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||||
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.database.subscription.SubscriptionEntity;
|
import org.schabi.newpipe.database.subscription.SubscriptionEntity;
|
||||||
import org.schabi.newpipe.fragments.subscription.SubscriptionService;
|
import org.schabi.newpipe.fragments.subscription.SubscriptionService;
|
||||||
@ -50,6 +53,7 @@ import io.reactivex.schedulers.Schedulers;
|
|||||||
public class SelectChannelFragment extends DialogFragment {
|
public class SelectChannelFragment extends DialogFragment {
|
||||||
private SelectChannelAdapter channelAdapter;
|
private SelectChannelAdapter channelAdapter;
|
||||||
private SubscriptionService subscriptionService;
|
private SubscriptionService subscriptionService;
|
||||||
|
private ImageLoader imageLoader = ImageLoader.getInstance();
|
||||||
|
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
private TextView emptyView;
|
private TextView emptyView;
|
||||||
@ -57,15 +61,31 @@ public class SelectChannelFragment extends DialogFragment {
|
|||||||
|
|
||||||
private List<SubscriptionEntity> subscriptions = new Vector<>();
|
private List<SubscriptionEntity> subscriptions = new Vector<>();
|
||||||
|
|
||||||
public interface OnSelectedLisener {
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
public void onChannelSelected(String url, String name, int service);
|
// Interfaces
|
||||||
}
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
OnSelectedLisener onSelectedLisener;
|
public interface OnSelectedLisener {
|
||||||
|
void onChannelSelected(String url, String name, int service);
|
||||||
|
}
|
||||||
|
OnSelectedLisener onSelectedLisener = null;
|
||||||
public void setOnSelectedLisener(OnSelectedLisener listener) {
|
public void setOnSelectedLisener(OnSelectedLisener listener) {
|
||||||
onSelectedLisener = listener;
|
onSelectedLisener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface OnCancelListener {
|
||||||
|
void onCancel();
|
||||||
|
}
|
||||||
|
OnCancelListener onCancelListener = null;
|
||||||
|
public void setOnCancelListener(OnCancelListener listener) {
|
||||||
|
onCancelListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Init
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View v = inflater.inflate(R.layout.select_channel_fragment, container, false);
|
View v = inflater.inflate(R.layout.select_channel_fragment, container, false);
|
||||||
@ -90,6 +110,31 @@ public class SelectChannelFragment extends DialogFragment {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Handle actions
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel(final DialogInterface dialogInterface) {
|
||||||
|
super.onCancel(dialogInterface);
|
||||||
|
if(onCancelListener != null) {
|
||||||
|
onCancelListener.onCancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clickedItem(int position) {
|
||||||
|
if(onSelectedLisener != null) {
|
||||||
|
SubscriptionEntity entry = subscriptions.get(position);
|
||||||
|
onSelectedLisener.onChannelSelected(entry.getUrl(), entry.getName(), entry.getServiceId());
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Item handling
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
private void displayChannels(List<SubscriptionEntity> subscriptions) {
|
private void displayChannels(List<SubscriptionEntity> subscriptions) {
|
||||||
this.subscriptions = subscriptions;
|
this.subscriptions = subscriptions;
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
@ -101,14 +146,6 @@ public class SelectChannelFragment extends DialogFragment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
private Observer<List<SubscriptionEntity>> getSubscriptionObserver() {
|
||||||
return new Observer<List<SubscriptionEntity>>() {
|
return new Observer<List<SubscriptionEntity>>() {
|
||||||
@Override
|
@Override
|
||||||
@ -151,6 +188,7 @@ public class SelectChannelFragment extends DialogFragment {
|
|||||||
clickedItem(position);
|
clickedItem(position);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
imageLoader.displayImage(entry.getAvatarUrl(), holder.thumbnailView, DISPLAY_IMAGE_OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -171,6 +209,10 @@ public class SelectChannelFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Error
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
protected boolean onError(Throwable e) {
|
protected boolean onError(Throwable e) {
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
ErrorActivity.reportError(activity, e,
|
ErrorActivity.reportError(activity, e,
|
||||||
@ -180,4 +222,17 @@ public class SelectChannelFragment extends DialogFragment {
|
|||||||
"none", "", R.string.app_ui_crash));
|
"none", "", R.string.app_ui_crash));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// ImageLoaderOptions
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base display options
|
||||||
|
*/
|
||||||
|
public static final DisplayImageOptions DISPLAY_IMAGE_OPTIONS =
|
||||||
|
new DisplayImageOptions.Builder()
|
||||||
|
.cacheInMemory(true)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
@ -268,11 +268,15 @@
|
|||||||
|
|
||||||
<!-- Content -->
|
<!-- Content -->
|
||||||
<string name="main_page_content">Content of main page</string>
|
<string name="main_page_content">Content of main page</string>
|
||||||
|
<string name="blank_page_summary">Blank Page</string>
|
||||||
|
<string name="kiosk_page_summary">Kiosk Page</string>
|
||||||
|
<string name="feed_page_summary">Feed Page</string>
|
||||||
|
<string name="channel_page_summary">Channel Page</string>
|
||||||
<string-array name="main_page_content_names">
|
<string-array name="main_page_content_names">
|
||||||
<item>Blank Page</item>
|
<item>@string/blank_page_summary</item>
|
||||||
<item>Trending Page</item>
|
<item>@string/kiosk_page_summary</item>
|
||||||
<item>Feed Page</item>
|
<item>@string/feed_page_summary</item>
|
||||||
<item>Channel Page</item>
|
<item>@string/channel_page_summary</item>
|
||||||
</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>
|
||||||
|
Loading…
Reference in New Issue
Block a user