1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-02 06:50:13 +01:00

+ New Tab is now on the bottom

Made dialog more beautiful
This commit is contained in:
Somethingweirdhere 2018-06-16 12:52:26 +02:00 committed by Christian Schabesberger
parent 33f5ed5b14
commit 6d64215614
5 changed files with 42 additions and 62 deletions

View File

@ -57,7 +57,6 @@ public class ContentSettingsMain extends Fragment {
tabNames();
initUsedTabs();
initAddButton(rootView);
usedTabsView = rootView.findViewById(R.id.usedTabs);
usedTabsView.setLayoutManager(new LinearLayoutManager(getContext()));
@ -80,7 +79,6 @@ public class ContentSettingsMain extends Fragment {
save.append("\n");
}
}
saveString = save.toString();
}
@ -100,18 +98,6 @@ public class ContentSettingsMain extends Fragment {
usedTabs.addAll(Arrays.asList(tabs));
}
private void initAddButton(View rootView) {
Button addButton = rootView.findViewById(R.id.buttonAdd);
addButton.setBackgroundResource(ThemeHelper.getIconByAttr(R.attr.ic_add, getActivity()));
addButton.setOnClickListener(v -> {
ContentSettingsMainDialog contentSettingsMainDialog = new ContentSettingsMainDialog();
contentSettingsMainDialog.setOnAddListener((int position) -> {
addTab(position);
});
contentSettingsMainDialog.show(getFragmentManager(), "select_channel");
});
}
private void tabNames() {
allTabs[0] = getString(R.string.blank_page_summary);
allTabs[1] = getString(R.string.kiosk_page_summary);
@ -143,6 +129,10 @@ public class ContentSettingsMain extends Fragment {
// ... code from gist
@Override
public void onItemDismiss(int position) {
if(position==getItemCount() - 1) {
notifyDataSetChanged();
return;
}
usedTabs.remove(position);
notifyItemRemoved(position);
saveChanges();
@ -150,6 +140,7 @@ public class ContentSettingsMain extends Fragment {
@Override
public void onItemMove(int fromPosition, int toPosition) {
if(fromPosition==getItemCount() - 1 || toPosition==getItemCount() - 1) return;
if (fromPosition < toPosition) {
for (int i = fromPosition; i < toPosition; i++) {
Collections.swap(usedTabs, i, i + 1);
@ -178,21 +169,31 @@ public class ContentSettingsMain extends Fragment {
@Override
public int getItemCount() {
return usedTabs.size();
return usedTabs.size() + 1;
}
class TabViewHolder extends RecyclerView.ViewHolder {
TextView text;
View view;
public TabViewHolder(View itemView) {
super(itemView);
text = itemView.findViewById(R.id.tabName);
view = itemView;
}
void bind(int position) {
if(usedTabs.get(position).startsWith("6\t")) {
if(position == getItemCount() - 1) {
String newTabString = "+ " + getString(R.string.tab_new);
text.setText(newTabString);
view.setOnClickListener(v -> {
ContentSettingsMainDialog contentSettingsMainDialog = new ContentSettingsMainDialog();
contentSettingsMainDialog.setOnAddListener(ContentSettingsMain.this::addTab);
contentSettingsMainDialog.show(getFragmentManager(), "select_channel");
});
} else if(usedTabs.get(position).startsWith("6\t")) {
String channelInfo[] = usedTabs.get(position).split("\t");
String channelName = "";
if(channelInfo.length==4) channelName = channelInfo[2];
@ -273,6 +274,7 @@ public class ContentSettingsMain extends Fragment {
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
mAdapter.onItemDismiss(viewHolder.getAdapterPosition());
}
}

View File

@ -4,50 +4,10 @@
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
<android.support.v7.widget.RecyclerView
android:id="@+id/usedTabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_margin="2dp"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/topBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:orientation="horizontal"
android:paddingBottom="3dp"
android:paddingTop="3dp">
<TextView
android:id="@+id/secondText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:text="@string/chosenTabs"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/buttonAdd"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="@color/transparent_background_color"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="15dp"
android:paddingTop="5dp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/usedTabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp" />
</LinearLayout>
android:layout_margin="0dp" />
</RelativeLayout>

View File

@ -2,12 +2,27 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:padding="13dp">
<TextView
android:id="@+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/tab_chose"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="10dp"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/allTabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp" />
android:layout_below="@+id/titleTextView"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</RelativeLayout>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -35,6 +35,8 @@
<string name="tab_main">Main</string>
<string name="tab_subscriptions">Subscriptions</string>
<string name="tab_bookmarks">Bookmarks</string>
<string name="tab_new">New Tab</string>
<string name="tab_chose">Chose Tab</string>
<string name="fragment_whats_new">What\'s New</string>