mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
Created a dialog for the main page content
This commit is contained in:
parent
edb75c4bab
commit
8ecbe4c8ad
@ -417,9 +417,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();
|
||||
@ -441,17 +438,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);
|
||||
}
|
||||
|
@ -88,6 +88,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);
|
||||
@ -96,6 +98,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
||||
tabLayout.getTabAt(1).setIcon(channelIcon);
|
||||
tabLayout.getTabAt(2).setIcon(bookmarkIcon);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
@ -107,16 +110,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) {
|
||||
@ -165,22 +158,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
|
||||
@ -191,7 +170,8 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return isSubscriptionsPageOnlySelected() ? 2 : 3;
|
||||
//return number of framgents
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,76 +184,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(menuItem -> {
|
||||
try {
|
||||
NavigationHelper.openKioskFragment(getFragmentManager(), currentServiceId, ks);
|
||||
} catch (Exception e) {
|
||||
ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<String> 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<allAdapter.TabViewHolder>{
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
@ -98,6 +99,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();
|
||||
@ -160,6 +163,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)
|
||||
|
BIN
app/src/main/res/drawable-hdpi/ic_add.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_add.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 246 B |
BIN
app/src/main/res/drawable-mdpi/ic_add.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_add.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 176 B |
BIN
app/src/main/res/drawable-xhdpi/ic_add.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_add.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 220 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_add.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_add.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 371 B |
60
app/src/main/res/layout/dialog_contentsettings.xml
Normal file
60
app/src/main/res/layout/dialog_contentsettings.xml
Normal file
@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/firstText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/selection"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/tabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/secondText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/chosenTabs"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/usedTabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:orientation="horizontal"
|
||||
android:padding="4dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cancelText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:padding="4dp"
|
||||
android:paddingLeft="6dp"
|
||||
android:paddingRight="6dp"
|
||||
android:text="@string/cancel"
|
||||
android:textColor="@color/black_settings_accent_color" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/confirmText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:padding="4dp"
|
||||
android:text="@string/accept"
|
||||
android:textColor="@color/black_settings_accent_color" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
43
app/src/main/res/layout/dialog_contentsettingtab.xml
Normal file
43
app/src/main/res/layout/dialog_contentsettingtab.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tabName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="22dp"
|
||||
android:layout_marginStart="22dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonAddRemove"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginEnd="22dp"
|
||||
android:background="@color/dark_background_color"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginRight="22dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonDown"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_toStartOf="@+id/buttonAddRemove"
|
||||
android:background="@color/dark_background_color"
|
||||
android:layout_toLeftOf="@+id/buttonAddRemove" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonUp"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_toLeftOf="@+id/buttonDown"
|
||||
android:layout_toStartOf="@+id/buttonDown"
|
||||
android:background="@color/dark_background_color" />
|
||||
|
||||
</RelativeLayout>
|
@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_show_downloads"
|
||||
android:orderInCategory="980"
|
||||
android:title="@string/downloads"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_history"
|
||||
android:orderInCategory="981"
|
||||
android:title="@string/action_history"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="990"
|
||||
android:title="@string/settings"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_about"
|
||||
android:orderInCategory="1000"
|
||||
android:title="@string/action_about"/>
|
||||
</menu>
|
@ -357,6 +357,9 @@
|
||||
|
||||
<!-- Content -->
|
||||
<string name="main_page_content">Content of main page</string>
|
||||
<string name="main_page_content_summary">What tabs are shown on the main page</string>
|
||||
<string name="selection">Selection</string>
|
||||
<string name="chosenTabs">Your tabs</string>
|
||||
<string name="blank_page_summary">Blank Page</string>
|
||||
<string name="kiosk_page_summary">Kiosk Page</string>
|
||||
<string name="subscription_page_summary">Subscription Page</string>
|
||||
|
@ -43,13 +43,10 @@
|
||||
android:title="@string/download_thumbnail_title"
|
||||
android:summary="@string/download_thumbnail_summary"/>
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="@string/kiosk_page_key"
|
||||
android:entries="@array/main_page_content_names"
|
||||
android:entryValues="@array/main_page_content_pages"
|
||||
<Preference
|
||||
android:summary="@string/main_page_content_summary"
|
||||
android:key="@string/main_page_content_key"
|
||||
android:title="@string/main_page_content"
|
||||
android:summary="%s"/>
|
||||
android:title="@string/main_page_content"/>
|
||||
|
||||
<Preference
|
||||
android:summary="@string/import_data_summary"
|
||||
|
Loading…
Reference in New Issue
Block a user