diff options
-rw-r--r-- | .idea/caches/build_file_checksums.ser | bin | 508 -> 508 bytes | |||
-rw-r--r-- | app/src/main/java/org/marcinzelent/liberavem/AllObservationsFragment.java | 29 | ||||
-rw-r--r-- | app/src/main/java/org/marcinzelent/liberavem/MyObservationsFragment.java | 46 | ||||
-rw-r--r-- | app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java | 20 | ||||
-rw-r--r-- | app/src/main/java/org/marcinzelent/liberavem/ViewPagerAdapter.java | 47 | ||||
-rw-r--r-- | app/src/main/res/layout/fragment_observations.xml | 29 | ||||
-rw-r--r-- | app/src/main/res/layout/observations_list.xml | 16 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 2 |
8 files changed, 169 insertions, 20 deletions
diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser Binary files differindex f7888ee..d0a563d 100644 --- a/.idea/caches/build_file_checksums.ser +++ b/.idea/caches/build_file_checksums.ser diff --git a/app/src/main/java/org/marcinzelent/liberavem/AllObservationsFragment.java b/app/src/main/java/org/marcinzelent/liberavem/AllObservationsFragment.java new file mode 100644 index 0000000..ee07682 --- /dev/null +++ b/app/src/main/java/org/marcinzelent/liberavem/AllObservationsFragment.java @@ -0,0 +1,29 @@ +package org.marcinzelent.liberavem; + + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +/** + * A simple {@link Fragment} subclass. + */ +public class AllObservationsFragment extends Fragment { + + + public AllObservationsFragment() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.observations_list, container, false); + + return rootView; + } + +} diff --git a/app/src/main/java/org/marcinzelent/liberavem/MyObservationsFragment.java b/app/src/main/java/org/marcinzelent/liberavem/MyObservationsFragment.java new file mode 100644 index 0000000..bcc9067 --- /dev/null +++ b/app/src/main/java/org/marcinzelent/liberavem/MyObservationsFragment.java @@ -0,0 +1,46 @@ +package org.marcinzelent.liberavem; + + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; + +/** + * A simple {@link Fragment} subclass. + */ +public class MyObservationsFragment extends Fragment { + + + public MyObservationsFragment() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.observations_list, container, false); + + return rootView; + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + String[] list = new String[] { + "String 1", + "String 2", + "String 3" + }; + ListView observationsListView = view.findViewById(R.id.observations_list_view); + ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, list); + observationsListView.setAdapter(adapter); + } +} diff --git a/app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java b/app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java index ce25892..aefaaf4 100644 --- a/app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java +++ b/app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java @@ -6,11 +6,14 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; +import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; +import android.widget.ListView; /** @@ -80,7 +83,20 @@ public class ObservationsFragment extends Fragment { @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - FloatingActionButton fab = getView().findViewById(R.id.fab); + // Find the view pager that will allow the user to swipe between fragments + ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewpager); + + // Create an adapter that knows which fragment should be shown on each page + ViewPagerAdapter adapter = new ViewPagerAdapter(getContext(), getChildFragmentManager()); + + // Set the adapter onto the view pager + viewPager.setAdapter(adapter); + + // Give the TabLayout the ViewPager + TabLayout tabLayout = (TabLayout) view.findViewById(R.id.sliding_tabs); + tabLayout.setupWithViewPager(viewPager); + + FloatingActionButton fab = view.findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { diff --git a/app/src/main/java/org/marcinzelent/liberavem/ViewPagerAdapter.java b/app/src/main/java/org/marcinzelent/liberavem/ViewPagerAdapter.java new file mode 100644 index 0000000..8c20fc9 --- /dev/null +++ b/app/src/main/java/org/marcinzelent/liberavem/ViewPagerAdapter.java @@ -0,0 +1,47 @@ +package org.marcinzelent.liberavem; + +import android.content.Context; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; + +public class ViewPagerAdapter extends FragmentPagerAdapter { + + private Context mContext; + + public ViewPagerAdapter(Context context, FragmentManager fm) { + super(fm); + mContext = context; + } + + // This determines the fragment for each tab + @Override + public Fragment getItem(int position) { + if (position == 0) { + return new MyObservationsFragment(); + } else { + return new AllObservationsFragment(); + } + } + + // This determines the number of tabs + @Override + public int getCount() { + return 2; + } + + // This determines the title for each tab + @Override + public CharSequence getPageTitle(int position) { + // Generate title based on item position + switch (position) { + case 0: + return mContext.getString(R.string.my_observations); + case 1: + return mContext.getString(R.string.all_observations); + default: + return null; + } + } + +} diff --git a/app/src/main/res/layout/fragment_observations.xml b/app/src/main/res/layout/fragment_observations.xml index 791c16c..3396fcc 100644 --- a/app/src/main/res/layout/fragment_observations.xml +++ b/app/src/main/res/layout/fragment_observations.xml @@ -7,32 +7,25 @@ android:layout_height="match_parent" tools:context=".ObservationsFragment"> - <android.support.v4.view.ViewPager - xmlns:android="http://schemas.android.com/apk/res/android" + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" - xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - app:layout_behavior="@string/appbar_scrolling_view_behavior" - tools:context="org.marcinzelent.liberavem.MainActivity" - tools:showIn="@layout/app_bar_main"> + android:orientation="vertical"> <android.support.design.widget.TabLayout + android:id="@+id/sliding_tabs" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + app:tabMode="fixed" /> - <android.support.design.widget.TabItem - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="My observations" /> - - <android.support.design.widget.TabItem - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="All observations" /> + <android.support.v4.view.ViewPager + android:id="@+id/viewpager" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@android:color/white" /> - </android.support.design.widget.TabLayout> - </android.support.v4.view.ViewPager> + </LinearLayout> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" diff --git a/app/src/main/res/layout/observations_list.xml b/app/src/main/res/layout/observations_list.xml new file mode 100644 index 0000000..8be21a1 --- /dev/null +++ b/app/src/main/res/layout/observations_list.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.constraint.ConstraintLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <ListView + android:id="@+id/observations_list_view" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> +</android.support.constraint.ConstraintLayout>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d6ef134..1f045bd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -86,4 +86,6 @@ <!-- TODO: Remove or change this placeholder text --> <string name="hello_blank_fragment">Hello blank fragment</string> + <string name="my_observations">My observations</string> + <string name="all_observations">All observations</string> </resources> |