aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcinzelent <zelent.marcin@gmail.com>2018-04-26 13:34:40 +0200
committermarcinzelent <zelent.marcin@gmail.com>2018-04-26 13:34:40 +0200
commit9ecffe7854da65b39ae13b18be7da425777f1ee8 (patch)
tree431c18a13684d54c656c935ef4fdfcc93e0e81fc /app/src/main/java/org/marcinzelent/liberavem
parent4de306375a33b2abd067e65658a46d45cba5e56e (diff)
Riced the app, added Atlas and About views
Diffstat (limited to 'app/src/main/java/org/marcinzelent/liberavem')
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/AboutFragment.java142
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/AtlasFragment.java11
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/AtlasGridAdapter.java67
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/LoginActivity.java15
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/MainActivity.java15
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/NewObservationActivity.java2
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java6
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/ResetPasswordActivity.java8
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/SignupActivity.java12
9 files changed, 251 insertions, 27 deletions
diff --git a/app/src/main/java/org/marcinzelent/liberavem/AboutFragment.java b/app/src/main/java/org/marcinzelent/liberavem/AboutFragment.java
new file mode 100644
index 0000000..eb7897c
--- /dev/null
+++ b/app/src/main/java/org/marcinzelent/liberavem/AboutFragment.java
@@ -0,0 +1,142 @@
+package org.marcinzelent.liberavem;
+
+import android.content.Context;
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Html;
+import android.text.Spanned;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import org.jetbrains.annotations.Nullable;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ * Activities that contain this fragment must implement the
+ * {@link AboutFragment.OnFragmentInteractionListener} interface
+ * to handle interaction events.
+ * Use the {@link AboutFragment#newInstance} factory method to
+ * create an instance of this fragment.
+ */
+public class AboutFragment extends Fragment {
+ // TODO: Rename parameter arguments, choose names that match
+ // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
+ private static final String ARG_PARAM1 = "param1";
+ private static final String ARG_PARAM2 = "param2";
+
+ // TODO: Rename and change types of parameters
+ private String mParam1;
+ private String mParam2;
+
+ private OnFragmentInteractionListener mListener;
+
+ public AboutFragment() {
+ // Required empty public constructor
+ }
+
+ /**
+ * Use this factory method to create a new instance of
+ * this fragment using the provided parameters.
+ *
+ * @param param1 Parameter 1.
+ * @param param2 Parameter 2.
+ * @return A new instance of fragment AboutFragment.
+ */
+ // TODO: Rename and change types and number of parameters
+ public static AboutFragment newInstance(String param1, String param2) {
+ AboutFragment fragment = new AboutFragment();
+ Bundle args = new Bundle();
+ args.putString(ARG_PARAM1, param1);
+ args.putString(ARG_PARAM2, param2);
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (getArguments() != null) {
+ mParam1 = getArguments().getString(ARG_PARAM1);
+ mParam2 = getArguments().getString(ARG_PARAM2);
+ }
+
+ ((MainActivity) getActivity()).setActionBarTitle("About");
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_about, container, false);
+ }
+
+ @Override
+ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
+ InputStream inputStream = this.getResources().openRawResource(R.raw.gpl_3);
+
+ InputStreamReader inputreader = new InputStreamReader(inputStream);
+ BufferedReader buffreader = new BufferedReader(inputreader);
+ String line;
+ StringBuilder text = new StringBuilder();
+
+ try {
+ while (( line = buffreader.readLine()) != null) {
+ text.append(line);
+ text.append('\n');
+ }
+ } catch (IOException e) { }
+
+ Spanned license = Html.fromHtml(text.toString());
+
+ TextView aboutLicense = view.findViewById(R.id.about_license);
+ aboutLicense.setText(license);
+ }
+
+ // TODO: Rename method, update argument and hook method into UI event
+ public void onButtonPressed(Uri uri) {
+ if (mListener != null) {
+ mListener.onFragmentInteraction(uri);
+ }
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ if (context instanceof OnFragmentInteractionListener) {
+ mListener = (OnFragmentInteractionListener) context;
+ } else {
+ throw new RuntimeException(context.toString()
+ + " must implement OnFragmentInteractionListener");
+ }
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ mListener = null;
+ }
+
+ /**
+ * This interface must be implemented by activities that contain this
+ * fragment to allow an interaction in this fragment to be communicated
+ * to the activity and potentially other fragments contained in that
+ * activity.
+ * <p>
+ * See the Android Training lesson <a href=
+ * "http://developer.android.com/training/basics/fragments/communicating.html"
+ * >Communicating with Other Fragments</a> for more information.
+ */
+ public interface OnFragmentInteractionListener {
+ // TODO: Update argument type and name
+ void onFragmentInteraction(Uri uri);
+ }
+}
diff --git a/app/src/main/java/org/marcinzelent/liberavem/AtlasFragment.java b/app/src/main/java/org/marcinzelent/liberavem/AtlasFragment.java
index 6a65b26..f59ff6b 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/AtlasFragment.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/AtlasFragment.java
@@ -7,6 +7,9 @@ import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.GridView;
+
+import org.jetbrains.annotations.Nullable;
/**
@@ -58,6 +61,8 @@ public class AtlasFragment extends Fragment {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
+
+ ((MainActivity) getActivity()).setActionBarTitle("Atlas");
}
@Override
@@ -75,6 +80,12 @@ public class AtlasFragment extends Fragment {
}
@Override
+ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
+ GridView atlasGrid = view.findViewById(R.id.atlas_grid);
+ atlasGrid.setAdapter(new AtlasGridAdapter(getActivity(), DataKeeper.getInstance().getBirds()));
+ }
+
+ @Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
diff --git a/app/src/main/java/org/marcinzelent/liberavem/AtlasGridAdapter.java b/app/src/main/java/org/marcinzelent/liberavem/AtlasGridAdapter.java
new file mode 100644
index 0000000..0aa1ca5
--- /dev/null
+++ b/app/src/main/java/org/marcinzelent/liberavem/AtlasGridAdapter.java
@@ -0,0 +1,67 @@
+package org.marcinzelent.liberavem;
+
+import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.squareup.picasso.Picasso;
+
+public class AtlasGridAdapter extends BaseAdapter {
+
+ private Context mContext;
+ private Bird[] birds;
+
+ public AtlasGridAdapter(Context c, Bird[] b) {
+ mContext = c;
+ birds = b;
+ }
+
+ public int getCount() {
+ return birds.length;
+ }
+
+ public Object getItem(int position) {
+ return null;
+ }
+
+ public long getItemId(int position) {
+ return 0;
+ }
+
+ // create a new ImageView for each item referenced by the Adapter
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ViewHolder viewHolder;
+ final View result;
+
+ if (convertView == null) {
+
+ viewHolder = new ViewHolder();
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ convertView = inflater.inflate(R.layout.atlas_grid_item, parent, false);
+ viewHolder.photo = convertView.findViewById(R.id.atlas_photo);
+ viewHolder.name = convertView.findViewById(R.id.atlas_name);
+
+ result = convertView;
+
+ convertView.setTag(viewHolder);
+ } else {
+ viewHolder = (ViewHolder) convertView.getTag();
+ result = convertView;
+ }
+
+ Picasso.get().load(birds[position].getPhotoUrl()).into(viewHolder.photo);
+ viewHolder.name.setText(birds[position].getNameEnglish());
+
+ return convertView;
+ }
+
+ private static class ViewHolder {
+ ImageView photo;
+ TextView name;
+ }
+}
diff --git a/app/src/main/java/org/marcinzelent/liberavem/LoginActivity.java b/app/src/main/java/org/marcinzelent/liberavem/LoginActivity.java
index 25acb3d..354e786 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/LoginActivity.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/LoginActivity.java
@@ -39,15 +39,12 @@ public class LoginActivity extends AppCompatActivity {
// set the view now
setContentView(R.layout.activity_login);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
-
- inputEmail = (EditText) findViewById(R.id.email);
- inputPassword = (EditText) findViewById(R.id.password);
- progressBar = (ProgressBar) findViewById(R.id.progressBar);
- btnSignup = (Button) findViewById(R.id.btn_signup);
- btnLogin = (Button) findViewById(R.id.btn_login);
- btnReset = (Button) findViewById(R.id.btn_reset_password);
+ inputEmail = findViewById(R.id.email);
+ inputPassword = findViewById(R.id.password);
+ progressBar = findViewById(R.id.progressBar);
+ btnSignup = findViewById(R.id.btn_signup);
+ btnLogin = findViewById(R.id.btn_login);
+ btnReset = findViewById(R.id.btn_reset_password);
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();
diff --git a/app/src/main/java/org/marcinzelent/liberavem/MainActivity.java b/app/src/main/java/org/marcinzelent/liberavem/MainActivity.java
index e53a05c..37545b6 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/MainActivity.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/MainActivity.java
@@ -36,7 +36,8 @@ import java.util.List;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener,
ObservationsFragment.OnFragmentInteractionListener,
- AtlasFragment.OnFragmentInteractionListener {
+ AtlasFragment.OnFragmentInteractionListener,
+ AboutFragment.OnFragmentInteractionListener {
@Override
@@ -96,9 +97,9 @@ public class MainActivity extends AppCompatActivity
int id = item.getItemId();
//noinspection SimplifiableIfStatement
- if (id == R.id.action_search) {
- return true;
- }
+ //if (id == R.id.action_search) {
+ // return true;
+ //}
return super.onOptionsItemSelected(item);
}
@@ -119,7 +120,7 @@ public class MainActivity extends AppCompatActivity
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivity(settingsIntent);
} else if (id == R.id.nav_about) {
-
+ fragmentClass = AboutFragment.class;
} else if (id == R.id.nav_signout) {
FirebaseAuth auth = FirebaseAuth.getInstance();
auth.signOut();
@@ -146,4 +147,8 @@ public class MainActivity extends AppCompatActivity
public void onFragmentInteraction(Uri uri) {
}
+
+ public void setActionBarTitle(String title) {
+ getSupportActionBar().setTitle(title);
+ }
}
diff --git a/app/src/main/java/org/marcinzelent/liberavem/NewObservationActivity.java b/app/src/main/java/org/marcinzelent/liberavem/NewObservationActivity.java
index f6488e4..b331c01 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/NewObservationActivity.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/NewObservationActivity.java
@@ -157,7 +157,7 @@ public class NewObservationActivity extends AppCompatActivity {
}
@Override
- public byte[] getBody() throws AuthFailureError {
+ public byte[] getBody() {
try {
return requestBody == null ? null : requestBody.getBytes("utf-8");
} catch (UnsupportedEncodingException uee) {
diff --git a/app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java b/app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java
index e2df607..02e5512 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java
@@ -65,6 +65,8 @@ public class ObservationsFragment extends Fragment {
mParam2 = getArguments().getString(ARG_PARAM2);
}
+ ((MainActivity) getActivity()).setActionBarTitle("Observations");
+
DataKeeper.getInstance().clearFragments();
}
@@ -85,7 +87,7 @@ public class ObservationsFragment extends Fragment {
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
// Find the view pager that will allow the user to swipe between fragments
- ViewPager viewPager = (ViewPager) view.findViewById(R.id.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());
@@ -94,7 +96,7 @@ public class ObservationsFragment extends Fragment {
viewPager.setAdapter(adapter);
// Give the TabLayout the ViewPager
- TabLayout tabLayout = (TabLayout) view.findViewById(R.id.sliding_tabs);
+ TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(viewPager);
FloatingActionButton fab = view.findViewById(R.id.fab);
diff --git a/app/src/main/java/org/marcinzelent/liberavem/ResetPasswordActivity.java b/app/src/main/java/org/marcinzelent/liberavem/ResetPasswordActivity.java
index cd53374..225730e 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/ResetPasswordActivity.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/ResetPasswordActivity.java
@@ -26,10 +26,10 @@ public class ResetPasswordActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reset_password);
- inputEmail = (EditText) findViewById(R.id.email);
- btnReset = (Button) findViewById(R.id.btn_reset_password);
- btnBack = (Button) findViewById(R.id.btn_back);
- progressBar = (ProgressBar) findViewById(R.id.progressBar);
+ inputEmail = findViewById(R.id.email);
+ btnReset = findViewById(R.id.btn_reset_password);
+ btnBack = findViewById(R.id.btn_back);
+ progressBar = findViewById(R.id.progressBar);
auth = FirebaseAuth.getInstance();
diff --git a/app/src/main/java/org/marcinzelent/liberavem/SignupActivity.java b/app/src/main/java/org/marcinzelent/liberavem/SignupActivity.java
index 280072a..305f3bc 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/SignupActivity.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/SignupActivity.java
@@ -31,12 +31,12 @@ public class SignupActivity extends AppCompatActivity {
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();
- btnSignIn = (Button) findViewById(R.id.sign_in_button);
- btnSignUp = (Button) findViewById(R.id.sign_up_button);
- inputEmail = (EditText) findViewById(R.id.email);
- inputPassword = (EditText) findViewById(R.id.password);
- progressBar = (ProgressBar) findViewById(R.id.progressBar);
- btnResetPassword = (Button) findViewById(R.id.btn_reset_password);
+ btnSignIn = findViewById(R.id.sign_in_button);
+ btnSignUp = findViewById(R.id.sign_up_button);
+ inputEmail = findViewById(R.id.email);
+ inputPassword = findViewById(R.id.password);
+ progressBar = findViewById(R.id.progressBar);
+ btnResetPassword = findViewById(R.id.btn_reset_password);
btnResetPassword.setOnClickListener(new View.OnClickListener() {
@Override