diff --git a/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java b/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java index a16f7dd79..e3c52cdad 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java @@ -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 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 9b3ffb5ae..02038f9fa 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -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; + } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java index 16b68196a..97af11f1b 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java @@ -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 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 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> getSubscriptionObserver() { return new Observer>() { @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(); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e16bfca16..b71bfa7db 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -268,11 +268,15 @@ Content of main page + Blank Page + Kiosk Page + Feed Page + Channel Page - Blank Page - Trending Page - Feed Page - Channel Page + @string/blank_page_summary + @string/kiosk_page_summary + @string/feed_page_summary + @string/channel_page_summary Select a channel No channel subscribed yet