mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-24 17:10:33 +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
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
defaultPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,22 +3,27 @@ package org.schabi.newpipe.settings;
|
||||
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.util.Constants;
|
||||
|
||||
public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
|
||||
addPreferencesFromResource(R.xml.content_settings);
|
||||
|
||||
findPreference(getString(R.string.main_page_content_key))
|
||||
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
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) {
|
||||
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))) {
|
||||
//todo on multyservice support show a kiosk an service selector here
|
||||
} 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();
|
||||
|
||||
//change summery
|
||||
Preference pref = findPreference(getString(R.string.main_page_content_key));
|
||||
pref.setSummary(name);
|
||||
|
||||
|
||||
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))) {
|
||||
mainPageContentPref.setSummary(getMainPageSummeryByKey(newValue));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@ -60,4 +75,28 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||
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.TextView;
|
||||
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.database.subscription.SubscriptionEntity;
|
||||
import org.schabi.newpipe.fragments.subscription.SubscriptionService;
|
||||
@ -50,6 +53,7 @@ import io.reactivex.schedulers.Schedulers;
|
||||
public class SelectChannelFragment extends DialogFragment {
|
||||
private SelectChannelAdapter channelAdapter;
|
||||
private SubscriptionService subscriptionService;
|
||||
private ImageLoader imageLoader = ImageLoader.getInstance();
|
||||
|
||||
private ProgressBar progressBar;
|
||||
private TextView emptyView;
|
||||
@ -57,15 +61,31 @@ public class SelectChannelFragment extends DialogFragment {
|
||||
|
||||
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) {
|
||||
onSelectedLisener = listener;
|
||||
}
|
||||
|
||||
public interface OnCancelListener {
|
||||
void onCancel();
|
||||
}
|
||||
OnCancelListener onCancelListener = null;
|
||||
public void setOnCancelListener(OnCancelListener listener) {
|
||||
onCancelListener = listener;
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Init
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.select_channel_fragment, container, false);
|
||||
@ -90,6 +110,31 @@ public class SelectChannelFragment extends DialogFragment {
|
||||
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) {
|
||||
this.subscriptions = subscriptions;
|
||||
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() {
|
||||
return new Observer<List<SubscriptionEntity>>() {
|
||||
@Override
|
||||
@ -151,6 +188,7 @@ public class SelectChannelFragment extends DialogFragment {
|
||||
clickedItem(position);
|
||||
}
|
||||
});
|
||||
imageLoader.displayImage(entry.getAvatarUrl(), holder.thumbnailView, DISPLAY_IMAGE_OPTIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -171,6 +209,10 @@ public class SelectChannelFragment extends DialogFragment {
|
||||
}
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Error
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
protected boolean onError(Throwable e) {
|
||||
final Activity activity = getActivity();
|
||||
ErrorActivity.reportError(activity, e,
|
||||
@ -180,4 +222,17 @@ public class SelectChannelFragment extends DialogFragment {
|
||||
"none", "", R.string.app_ui_crash));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// ImageLoaderOptions
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
/**
|
||||
* Base display options
|
||||
*/
|
||||
public static final DisplayImageOptions DISPLAY_IMAGE_OPTIONS =
|
||||
new DisplayImageOptions.Builder()
|
||||
.cacheInMemory(true)
|
||||
.build();
|
||||
}
|
||||
|
@ -268,11 +268,15 @@
|
||||
|
||||
<!-- Content -->
|
||||
<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">
|
||||
<item>Blank Page</item>
|
||||
<item>Trending Page</item>
|
||||
<item>Feed Page</item>
|
||||
<item>Channel Page</item>
|
||||
<item>@string/blank_page_summary</item>
|
||||
<item>@string/kiosk_page_summary</item>
|
||||
<item>@string/feed_page_summary</item>
|
||||
<item>@string/channel_page_summary</item>
|
||||
</string-array>
|
||||
<string name="select_a_channel">Select a channel</string>
|
||||
<string name="no_channel_subscribed_yet">No channel subscribed yet</string>
|
||||
|
Loading…
Reference in New Issue
Block a user