From bc782cf2a608bacb51a2e5d9863ee496517d770c Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Sat, 9 Jun 2018 11:33:03 +0200 Subject: [PATCH] Created a dialog for the main page content --- .../java/org/schabi/newpipe/MainActivity.java | 14 --- .../newpipe/fragments/MainFragment.java | 111 ++---------------- .../settings/ContentSettingsDialog.java | 98 ++++++++++++++++ .../settings/ContentSettingsFragment.java | 11 ++ app/src/main/res/drawable-hdpi/ic_add.png | Bin 0 -> 246 bytes app/src/main/res/drawable-mdpi/ic_add.png | Bin 0 -> 176 bytes app/src/main/res/drawable-xhdpi/ic_add.png | Bin 0 -> 220 bytes app/src/main/res/drawable-xxhdpi/ic_add.png | Bin 0 -> 371 bytes .../res/layout/dialog_contentsettings.xml | 60 ++++++++++ .../res/layout/dialog_contentsettingtab.xml | 43 +++++++ app/src/main/res/menu/main_menu.xml | 27 ----- app/src/main/res/values/strings.xml | 3 + app/src/main/res/xml/content_settings.xml | 9 +- 13 files changed, 225 insertions(+), 151 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/settings/ContentSettingsDialog.java create mode 100644 app/src/main/res/drawable-hdpi/ic_add.png create mode 100644 app/src/main/res/drawable-mdpi/ic_add.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_add.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_add.png create mode 100644 app/src/main/res/layout/dialog_contentsettings.xml create mode 100644 app/src/main/res/layout/dialog_contentsettingtab.xml delete mode 100644 app/src/main/res/menu/main_menu.xml diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index b26d0a5d7..764357e4d 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -404,9 +404,6 @@ public class MainActivity extends AppCompatActivity { if (!(fragment instanceof SearchFragment)) { findViewById(R.id.toolbar).findViewById(R.id.toolbar_search_container).setVisibility(View.GONE); - - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.main_menu, menu); } ActionBar actionBar = getSupportActionBar(); @@ -428,17 +425,6 @@ public class MainActivity extends AppCompatActivity { case android.R.id.home: onHomeButtonPressed(); return true; - case R.id.action_show_downloads: - return NavigationHelper.openDownloads(this); - case R.id.action_history: - NavigationHelper.openStatisticFragment(getSupportFragmentManager()); - return true; - case R.id.action_about: - NavigationHelper.openAbout(this); - return true; - case R.id.action_settings: - NavigationHelper.openSettings(this); - return true; default: return super.onOptionsItemSelected(item); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java index 31092d3e6..3c9edd957 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -87,6 +87,8 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte int whatsHotIcon = ThemeHelper.resolveResourceIdFromAttr(activity, R.attr.ic_hot); int bookmarkIcon = ThemeHelper.resolveResourceIdFromAttr(activity, R.attr.ic_bookmark); + //assign proper icons to tabs + /* if (isSubscriptionsPageOnlySelected()) { tabLayout.getTabAt(0).setIcon(channelIcon); tabLayout.getTabAt(1).setIcon(bookmarkIcon); @@ -95,6 +97,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte tabLayout.getTabAt(1).setIcon(channelIcon); tabLayout.getTabAt(2).setIcon(bookmarkIcon); } + */ } /*////////////////////////////////////////////////////////////////////////// @@ -106,16 +109,6 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte super.onCreateOptionsMenu(menu, inflater); if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "], inflater = [" + inflater + "]"); inflater.inflate(R.menu.main_fragment_menu, menu); - SubMenu kioskMenu = menu.addSubMenu(Menu.NONE, Menu.NONE, 200, getString(R.string.kiosk)); - try { - createKioskMenu(kioskMenu, inflater); - } catch (Exception e) { - ErrorActivity.reportError(activity, e, - activity.getClass(), - null, - ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, - "none", "", R.string.app_ui_crash)); - } ActionBar supportActionBar = activity.getSupportActionBar(); if (supportActionBar != null) { @@ -157,22 +150,8 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte @Override public Fragment getItem(int position) { - switch (position) { - case 0: - return isSubscriptionsPageOnlySelected() ? new SubscriptionFragment() : getMainPageFragment(); - case 1: - if(PreferenceManager.getDefaultSharedPreferences(getActivity()) - .getString(getString(R.string.main_page_content_key), getString(R.string.blank_page_key)) - .equals(getString(R.string.subscription_page_key))) { - return new BookmarkFragment(); - } else { - return new SubscriptionFragment(); - } - case 2: - return new BookmarkFragment(); - default: - return new BlankFragment(); - } + //return proper fragments + return new BlankFragment(); } @Override @@ -183,7 +162,8 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte @Override public int getCount() { - return isSubscriptionsPageOnlySelected() ? 2 : 3; + //return number of framgents + return 10; } } @@ -196,81 +176,4 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte .getString(getString(R.string.main_page_content_key), getString(R.string.blank_page_key)) .equals(getString(R.string.subscription_page_key)); } - - private Fragment getMainPageFragment() { - if (getActivity() == null) return new BlankFragment(); - - try { - SharedPreferences preferences = - PreferenceManager.getDefaultSharedPreferences(getActivity()); - final String setMainPage = preferences.getString(getString(R.string.main_page_content_key), - getString(R.string.main_page_selectd_kiosk_id)); - if (setMainPage.equals(getString(R.string.blank_page_key))) { - return new BlankFragment(); - } else if (setMainPage.equals(getString(R.string.kiosk_page_key))) { - int serviceId = preferences.getInt(getString(R.string.main_page_selected_service), - FALLBACK_SERVICE_ID); - String kioskId = preferences.getString(getString(R.string.main_page_selectd_kiosk_id), - FALLBACK_KIOSK_ID); - KioskFragment fragment = KioskFragment.getInstance(serviceId, kioskId); - fragment.useAsFrontPage(true); - return fragment; - } else if (setMainPage.equals(getString(R.string.feed_page_key))) { - FeedFragment fragment = new FeedFragment(); - fragment.useAsFrontPage(true); - return fragment; - } else if (setMainPage.equals(getString(R.string.channel_page_key))) { - int serviceId = preferences.getInt(getString(R.string.main_page_selected_service), - FALLBACK_SERVICE_ID); - String url = preferences.getString(getString(R.string.main_page_selected_channel_url), - FALLBACK_CHANNEL_URL); - String name = preferences.getString(getString(R.string.main_page_selected_channel_name), - FALLBACK_CHANNEL_NAME); - ChannelFragment fragment = ChannelFragment.getInstance(serviceId, url, name); - fragment.useAsFrontPage(true); - return fragment; - } 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(); - } - } - - /*////////////////////////////////////////////////////////////////////////// - // Select Kiosk - //////////////////////////////////////////////////////////////////////////*/ - - private void createKioskMenu(Menu menu, MenuInflater menuInflater) - throws Exception { - StreamingService service = NewPipe.getService(currentServiceId); - KioskList kl = service.getKioskList(); - int i = 0; - for (final String ks : kl.getAvailableKiosks()) { - menu.add(0, KIOSK_MENU_OFFSET + i, Menu.NONE, - KioskTranslator.getTranslatedKioskName(ks, getContext())) - .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - try { - NavigationHelper.openKioskFragment(getFragmentManager(), currentServiceId, ks); - } catch (Exception e) { - ErrorActivity.reportError(activity, e, - activity.getClass(), - null, - ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, - "none", "", R.string.app_ui_crash)); - } - return true; - } - }); - i++; - } - } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsDialog.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsDialog.java new file mode 100644 index 000000000..6cc63dd5e --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsDialog.java @@ -0,0 +1,98 @@ +package org.schabi.newpipe.settings; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.DialogFragment; +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.Button; +import android.widget.TextView; + +import org.schabi.newpipe.R; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ContentSettingsDialog extends DialogFragment { + + List usedTabs = new ArrayList<>(); + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return inflater.inflate(R.layout.dialog_contentsettings, container); + } + + @Override + public void onViewCreated(@NonNull View rootView, @Nullable Bundle savedInstanceState) { + super.onViewCreated(rootView, savedInstanceState); + RecyclerView allTabs = rootView.findViewById(R.id.tabs); + allTabs.setLayoutManager(new LinearLayoutManager(getContext())); + allTabs.setAdapter(new allAdapter()); + + RecyclerView usedTabs = rootView.findViewById(R.id.usedTabs); + usedTabs.setLayoutManager(new LinearLayoutManager(getContext())); + } + + public class allAdapter extends RecyclerView.Adapter{ + + @Override + public TabViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + + LayoutInflater inflater = LayoutInflater.from(getContext()); + View view = inflater.inflate(R.layout.dialog_contentsettingtab, parent, false); + return new TabViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull TabViewHolder holder, int position) { + holder.bind(position); + } + + + // Return the size of your dataset (invoked by the layout manager) + @Override + public int getItemCount() { + return 5; + } + + class TabViewHolder extends RecyclerView.ViewHolder { + + TextView text; + Button add; + + public TabViewHolder(View itemView) { + super(itemView); + + text = itemView.findViewById(R.id.tabName); + add = itemView.findViewById(R.id.buttonAddRemove); + } + + void bind(int position) { + add.setBackgroundResource(R.drawable.ic_add); + switch (position) { + case 0: + text.setText("Test"); + break; + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + break; + case 5: + break; + case 6: + break; + } + } + } + } +} 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 a02a9df34..724cd9d26 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -9,6 +9,7 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.app.FragmentManager; import android.support.v7.preference.ListPreference; import android.support.v7.preference.Preference; import android.util.Log; @@ -93,6 +94,8 @@ public class ContentSettingsFragment extends BasePreferenceFragment { addPreferencesFromResource(R.xml.content_settings); + /* + final ListPreference mainPageContentPref = (ListPreference) findPreference(getString(R.string.main_page_content_key)); mainPageContentPref.setOnPreferenceChangeListener((Preference preference, Object newValueO) -> { final String newValue = newValueO.toString(); @@ -155,6 +158,14 @@ public class ContentSettingsFragment extends BasePreferenceFragment { return true; }); + */ + + Preference contentPreference = findPreference(getString(R.string.main_page_content_key)); + contentPreference.setOnPreferenceClickListener((Preference p) -> { + new ContentSettingsDialog().show(getFragmentManager(),""); + return true; + }); + Preference importDataPreference = findPreference(getString(R.string.import_data)); importDataPreference.setOnPreferenceClickListener((Preference p) -> { Intent i = new Intent(getActivity(), FilePickerActivityHelper.class) diff --git a/app/src/main/res/drawable-hdpi/ic_add.png b/app/src/main/res/drawable-hdpi/ic_add.png new file mode 100644 index 0000000000000000000000000000000000000000..85172125ec3e2d2b559c145390254b0752e832d2 GIT binary patch literal 246 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpUty`CIR=C&P zpv&8*{GO5+E~F&jRIy}_ijrbH6C;a&0|Ss)QFvR&HM{mC>zb|4Fa3Izeti1vG{fT0 zLeK9M`{sVVttsDmZKYk&ekB7xp`|CKwbxB8T)X$nUXLki$12WFj}WUqEB(h!5Nwje pgZr$kcwN$2@knvzx5JD~4ImigP3~>Lt!FI>qb6h*~G7T zG^O=IgY|(+mx4}+@EaHzakWP>bn(?>IbO7!#SPNd@bEdqlcFZIpEV*qO@hn}Dnk8T U8}*yoflgrXboFyt=akR{03#GS3;+NC literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_add.png b/app/src/main/res/drawable-xhdpi/ic_add.png new file mode 100644 index 0000000000000000000000000000000000000000..cbe4b60000a1d1be03ca0f9b3896ef50fd594f57 GIT binary patch literal 220 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=i#=T&Ln>~)y>XDU*+8TrG2P3k zQNf~Px?j*6w!7D+&+eEW7SMd3|Gn0;V5N<(RXiuDcs>vDk}NuRxhlx(Z!$yD!SxP5 z)-6{88ifLS=RU8WY4Q8KHN*Sn>u>aHo5Ihp%oku_;AijPO<%+D-|xV6^gdaSW-r_4c-5_MrfghKm-r zcXd6Or#L~8^U3v{7CS;#+`UzQyIiq*LEr`V$yI!JJPl{?J5R|D1eyQ>1`$_E_pVv> z>g}Z?$sc8wYfj#zbN}|XyUTy>FxsuiWcj6b|Epc^jL)85+R5?JvtSvE00Se70|TRg z0|N%LVY&3(+m$7kIPWd7>}9c7=J7h_`20WjF3MJ0_n+ICIqQ8kk!+_;7x(zkADi*5P~S?)1Ks-TUVrAH?GacE+nN V&6NI_U0Mhd@O1TaS?83{1OP(sld}K- literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/dialog_contentsettings.xml b/app/src/main/res/layout/dialog_contentsettings.xml new file mode 100644 index 000000000..9303cb995 --- /dev/null +++ b/app/src/main/res/layout/dialog_contentsettings.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_contentsettingtab.xml b/app/src/main/res/layout/dialog_contentsettingtab.xml new file mode 100644 index 000000000..baad35b7b --- /dev/null +++ b/app/src/main/res/layout/dialog_contentsettingtab.xml @@ -0,0 +1,43 @@ + + + + + +