From c46ce1170c52732fc0ad1e35f11c7f1f4408f0ea Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 2 Aug 2016 01:42:05 +0200 Subject: [PATCH] add search fragment --- app/build.gradle | 2 +- .../newpipe/SearchInfoItemFragment.java | 86 +++++++++++++++++++ .../schabi/newpipe/dummy/DummyContent.java | 72 ++++++++++++++++ app/src/main/res/layout/activity_main.xml | 10 ++- .../res/layout/fragment_searchinfoitem.xml | 13 +++ 5 files changed, 178 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/SearchInfoItemFragment.java create mode 100644 app/src/main/java/org/schabi/newpipe/dummy/DummyContent.java create mode 100644 app/src/main/res/layout/fragment_searchinfoitem.xml diff --git a/app/build.gradle b/app/build.gradle index cf45527ff..ba36c9480 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,6 +31,7 @@ android { } dependencies { + testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.1.1' compile 'com.android.support:support-v4:24.1.1' compile 'com.android.support:design:24.1.1' @@ -44,5 +45,4 @@ dependencies { compile 'com.google.android.exoplayer:exoplayer:r1.5.5' compile 'com.google.code.gson:gson:2.4' compile 'com.nononsenseapps:filepicker:2.0.5' - testCompile 'junit:junit:4.12' } diff --git a/app/src/main/java/org/schabi/newpipe/SearchInfoItemFragment.java b/app/src/main/java/org/schabi/newpipe/SearchInfoItemFragment.java new file mode 100644 index 000000000..373c009df --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/SearchInfoItemFragment.java @@ -0,0 +1,86 @@ +package org.schabi.newpipe; + +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v7.widget.GridLayoutManager; +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 org.schabi.newpipe.dummy.DummyContent; +import org.schabi.newpipe.dummy.DummyContent.DummyItem; + +import java.util.List; + +/** + * A fragment representing a list of Items. + *

+ * Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener} + * interface. + */ +public class SearchInfoItemFragment extends Fragment { + + // TODO: Customize parameter argument names + private static final String ARG_COLUMN_COUNT = "column-count"; + // TODO: Customize parameters + private int mColumnCount = 1; + + /** + * Mandatory empty constructor for the fragment manager to instantiate the + * fragment (e.g. upon screen orientation changes). + */ + public SearchInfoItemFragment() { + } + + // TODO: Customize parameter initialization + @SuppressWarnings("unused") + public static SearchInfoItemFragment newInstance(int columnCount) { + SearchInfoItemFragment fragment = new SearchInfoItemFragment(); + Bundle args = new Bundle(); + args.putInt(ARG_COLUMN_COUNT, columnCount); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (getArguments() != null) { + mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_searchinfoitem, container, false); + + // Set the adapter + if (view instanceof RecyclerView) { + Context context = view.getContext(); + RecyclerView recyclerView = (RecyclerView) view; + if (mColumnCount <= 1) { + recyclerView.setLayoutManager(new LinearLayoutManager(context)); + } else { + recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount)); + } + recyclerView.setAdapter(null); + } + return view; + } + + + @Override + public void onAttach(Context context) { + super.onAttach(context); + } + + @Override + public void onDetach() { + super.onDetach(); + } +} diff --git a/app/src/main/java/org/schabi/newpipe/dummy/DummyContent.java b/app/src/main/java/org/schabi/newpipe/dummy/DummyContent.java new file mode 100644 index 000000000..4b84286ae --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/dummy/DummyContent.java @@ -0,0 +1,72 @@ +package org.schabi.newpipe.dummy; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Helper class for providing sample content for user interfaces created by + * Android template wizards. + *

+ * TODO: Replace all uses of this class before publishing your app. + */ +public class DummyContent { + + /** + * An array of sample (dummy) items. + */ + public static final List ITEMS = new ArrayList(); + + /** + * A map of sample (dummy) items, by ID. + */ + public static final Map ITEM_MAP = new HashMap(); + + private static final int COUNT = 25; + + static { + // Add some sample items. + for (int i = 1; i <= COUNT; i++) { + addItem(createDummyItem(i)); + } + } + + private static void addItem(DummyItem item) { + ITEMS.add(item); + ITEM_MAP.put(item.id, item); + } + + private static DummyItem createDummyItem(int position) { + return new DummyItem(String.valueOf(position), "Item " + position, makeDetails(position)); + } + + private static String makeDetails(int position) { + StringBuilder builder = new StringBuilder(); + builder.append("Details about Item: ").append(position); + for (int i = 0; i < position; i++) { + builder.append("\nMore details information here."); + } + return builder.toString(); + } + + /** + * A dummy item representing a piece of content. + */ + public static class DummyItem { + public final String id; + public final String content; + public final String details; + + public DummyItem(String id, String content, String details) { + this.id = id; + this.content = content; + this.details = details; + } + + @Override + public String toString() { + return content; + } + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index dda225f91..f225e82fc 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -3,13 +3,15 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:paddingBottom="@dimen/activity_vertical_margin" - android:paddingLeft="@dimen/activity_horizontal_margin" - android:paddingRight="@dimen/activity_horizontal_margin" - android:paddingTop="@dimen/activity_vertical_margin" tools:context="org.schabi.newpipe.MainActivity" android:orientation="vertical"> + + diff --git a/app/src/main/res/layout/fragment_searchinfoitem.xml b/app/src/main/res/layout/fragment_searchinfoitem.xml new file mode 100644 index 000000000..b4b75ebfa --- /dev/null +++ b/app/src/main/res/layout/fragment_searchinfoitem.xml @@ -0,0 +1,13 @@ + +