diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
deleted file mode 100644
index 30aa626..0000000
--- a/.idea/codeStyles/Project.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 0b6820d..6c48f58 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -20,10 +20,14 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
+ implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
+ implementation 'com.android.support:support-v4:28.0.0'
+ implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
implementation project(':congressdataapiaccess-debug')
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
+ implementation 'com.android.support:recyclerview-v7:28.0.0'
+ implementation 'android.arch.lifecycle:extensions:1.1.1'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 26b1cb9..a1d591b 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,6 +2,8 @@
+
+
-
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/lambdaschool/congressdetails/CPORepo.java b/app/src/main/java/com/lambdaschool/congressdetails/CPORepo.java
new file mode 100644
index 0000000..691ce96
--- /dev/null
+++ b/app/src/main/java/com/lambdaschool/congressdetails/CPORepo.java
@@ -0,0 +1,29 @@
+package com.lambdaschool.congressdetails;
+
+import android.arch.lifecycle.MutableLiveData;
+import android.content.Context;
+
+import com.lambdaschool.congressdataapiaccess.CongressDao;
+import com.lambdaschool.congressdataapiaccess.CongresspersonOverview;
+
+import java.util.ArrayList;
+
+public class CPORepo {
+ private ArrayList rawData;
+ private Context context;
+
+ public CPORepo(Context context) {
+ rawData = new ArrayList<>();
+ this.context = context;
+ }
+
+ public MutableLiveData> getData() {
+ final MutableLiveData> liveData =
+ new MutableLiveData<>();
+ rawData = CongressDao.getAllMembers();
+ liveData.setValue(rawData);
+ return liveData;
+ }
+
+
+}
diff --git a/app/src/main/java/com/lambdaschool/congressdetails/CPOViewModel.java b/app/src/main/java/com/lambdaschool/congressdetails/CPOViewModel.java
new file mode 100644
index 0000000..617d1f8
--- /dev/null
+++ b/app/src/main/java/com/lambdaschool/congressdetails/CPOViewModel.java
@@ -0,0 +1,29 @@
+package com.lambdaschool.congressdetails;
+
+import android.arch.lifecycle.LiveData;
+import android.arch.lifecycle.MutableLiveData;
+import android.arch.lifecycle.ViewModel;
+import android.content.Context;
+
+import com.lambdaschool.congressdataapiaccess.CongresspersonOverview;
+
+import java.util.ArrayList;
+
+public class CPOViewModel extends ViewModel {
+ private MutableLiveData> liveData;
+ private CPORepo repository;
+
+ public LiveData> getLiveData(Context context) {
+ if (liveData == null) {
+ loadData(context);
+ }
+ return liveData;
+ }
+
+ public void loadData(Context context) {
+ repository = new CPORepo(context);
+ liveData = repository.getData();
+ }
+
+
+}
diff --git a/app/src/main/java/com/lambdaschool/congressdetails/DetailsRepo.java b/app/src/main/java/com/lambdaschool/congressdetails/DetailsRepo.java
new file mode 100644
index 0000000..ebbb98f
--- /dev/null
+++ b/app/src/main/java/com/lambdaschool/congressdetails/DetailsRepo.java
@@ -0,0 +1,26 @@
+package com.lambdaschool.congressdetails;
+
+import android.arch.lifecycle.MutableLiveData;
+import android.content.Context;
+
+import com.lambdaschool.congressdataapiaccess.CongressDao;
+import com.lambdaschool.congressdataapiaccess.CongresspersonDetails;
+
+public class DetailsRepo {
+ private CongresspersonDetails details;
+ private String id;
+ private Context context;
+
+ public DetailsRepo(Context context, String id) {
+ this.context = context;
+ this.id = id;
+ }
+
+ public MutableLiveData getDetails() {
+ MutableLiveData liveDetails =
+ new MutableLiveData<>();
+ details = CongressDao.getMemberDetails(id);
+ liveDetails.setValue(details);
+ return liveDetails;
+ }
+}
diff --git a/app/src/main/java/com/lambdaschool/congressdetails/DetailsViewModel.java b/app/src/main/java/com/lambdaschool/congressdetails/DetailsViewModel.java
new file mode 100644
index 0000000..e0891e0
--- /dev/null
+++ b/app/src/main/java/com/lambdaschool/congressdetails/DetailsViewModel.java
@@ -0,0 +1,27 @@
+package com.lambdaschool.congressdetails;
+
+import android.arch.lifecycle.LiveData;
+import android.arch.lifecycle.MutableLiveData;
+import android.arch.lifecycle.ViewModel;
+import android.content.Context;
+
+import com.lambdaschool.congressdataapiaccess.CongresspersonDetails;
+
+
+public class DetailsViewModel extends ViewModel {
+
+ private MutableLiveData liveDetails;
+ private DetailsRepo detailsRepo;
+
+ public LiveData getLiveData(Context context, String id) {
+ if (liveDetails == null) {
+ loadData(context, id);
+ }
+ return liveDetails;
+ }
+
+ public void loadData(Context context, String id) {
+ detailsRepo = new DetailsRepo(context, id);
+ liveDetails = detailsRepo.getDetails();
+ }
+}
diff --git a/app/src/main/java/com/lambdaschool/congressdetails/ItemDetailActivity.java b/app/src/main/java/com/lambdaschool/congressdetails/ItemDetailActivity.java
new file mode 100644
index 0000000..1471427
--- /dev/null
+++ b/app/src/main/java/com/lambdaschool/congressdetails/ItemDetailActivity.java
@@ -0,0 +1,112 @@
+package com.lambdaschool.congressdetails;
+
+import android.arch.lifecycle.Observer;
+import android.arch.lifecycle.ViewModelProvider;
+import android.arch.lifecycle.ViewModelProviders;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.design.widget.FloatingActionButton;
+import android.support.design.widget.Snackbar;
+import android.support.v7.widget.Toolbar;
+import android.view.View;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.app.ActionBar;
+import android.view.MenuItem;
+
+import com.lambdaschool.congressdataapiaccess.CongresspersonDetails;
+
+/**
+ * An activity representing a single Item detail screen. This
+ * activity is only used on narrow width devices. On tablet-size devices,
+ * item details are presented side-by-side with a list of items
+ * in a {@link ItemListActivity}.
+ */
+public class ItemDetailActivity extends AppCompatActivity {
+
+ private DetailsViewModel detailsViewModel;
+ private Context context;
+ private CongresspersonDetails details;
+ private String id;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_item_detail);
+ context = this;
+ id = getIntent().getStringExtra(ItemDetailFragment.ARG_ITEM_ID);
+
+
+ detailsViewModel = ViewModelProviders.of(this).get(DetailsViewModel.class);
+ detailsViewModel.getLiveData(this, id ).observe(this, new Observer() {
+ @Override
+ public void onChanged(@Nullable CongresspersonDetails congresspersonDetails) {
+ Bundle arguments = new Bundle();
+ arguments.putString(ItemDetailFragment.ARG_ITEM_ID,
+ getIntent().getStringExtra(ItemDetailFragment.ARG_ITEM_ID));
+ ItemDetailFragment fragment = new ItemDetailFragment();
+ fragment.setArguments(arguments);
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.item_detail_container, fragment);
+ }
+ });
+
+
+ Toolbar toolbar = (Toolbar) findViewById(R.id.detail_toolbar);
+ setSupportActionBar(toolbar);
+
+ FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
+ fab.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Snackbar.make(view, "Replace with your own detail action", Snackbar.LENGTH_LONG)
+ .setAction("Action", null).show();
+ }
+ });
+
+ // Show the Up button in the action bar.
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+
+ // savedInstanceState is non-null when there is fragment state
+ // saved from previous configurations of this activity
+ // (e.g. when rotating the screen from portrait to landscape).
+ // In this case, the fragment will automatically be re-added
+ // to its container so we don't need to manually add it.
+ // For more information, see the Fragments API guide at:
+ //
+ // http://developer.android.com/guide/components/fragments.html
+ //
+ if (savedInstanceState == null) {
+ // Create the detail fragment and add it to the activity
+ // using a fragment transaction.
+ Bundle arguments = new Bundle();
+ arguments.putString(ItemDetailFragment.ARG_ITEM_ID,
+ getIntent().getStringExtra(ItemDetailFragment.ARG_ITEM_ID));
+ ItemDetailFragment fragment = new ItemDetailFragment();
+ fragment.setArguments(arguments);
+ getSupportFragmentManager().beginTransaction()
+ .add(R.id.item_detail_container, fragment)
+ .commit();
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+ if (id == android.R.id.home) {
+ // This ID represents the Home or Up button. In the case of this
+ // activity, the Up button is shown. For
+ // more details, see the Navigation pattern on Android Design:
+ //
+ // http://developer.android.com/design/patterns/navigation.html#up-vs-back
+ //
+ navigateUpTo(new Intent(this, ItemListActivity.class));
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/app/src/main/java/com/lambdaschool/congressdetails/ItemDetailFragment.java b/app/src/main/java/com/lambdaschool/congressdetails/ItemDetailFragment.java
new file mode 100644
index 0000000..4552a11
--- /dev/null
+++ b/app/src/main/java/com/lambdaschool/congressdetails/ItemDetailFragment.java
@@ -0,0 +1,88 @@
+package com.lambdaschool.congressdetails;
+
+import android.app.Activity;
+import android.arch.lifecycle.Observer;
+import android.arch.lifecycle.ViewModelProviders;
+import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.design.widget.CollapsingToolbarLayout;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.lambdaschool.congressdataapiaccess.CongresspersonDetails;
+
+
+/**
+ * A fragment representing a single Item detail screen.
+ * This fragment is either contained in a {@link ItemListActivity}
+ * in two-pane mode (on tablets) or a {@link ItemDetailActivity}
+ * on handsets.
+ */
+public class ItemDetailFragment extends Fragment {
+ /**
+ * The fragment argument representing the item ID that this fragment
+ * represents.
+ */
+ public static final String ARG_ITEM_ID = "item_id";
+
+ /**
+ * The dummy content this fragment is presenting.
+ */
+ private String mItem;
+ private DetailsViewModel detailsViewModel;
+
+ /**
+ * Mandatory empty constructor for the fragment manager to instantiate the
+ * fragment (e.g. upon screen orientation changes).
+ */
+ public ItemDetailFragment() {
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (getArguments().containsKey(ARG_ITEM_ID)) {
+ // Load the dummy content specified by the fragment
+ // arguments. In a real-world scenario, use a Loader
+ // to load content from a content provider.
+ mItem = getArguments().getString(ARG_ITEM_ID);
+
+ Activity activity = this.getActivity();
+ CollapsingToolbarLayout appBarLayout = (CollapsingToolbarLayout) activity.findViewById(R.id.toolbar_layout);
+ if (appBarLayout != null) {
+ appBarLayout.setTitle(mItem);
+ }
+ }
+
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ final View rootView = inflater.inflate(R.layout.item_detail, container, false);
+
+ // Show the dummy content as text in a TextView.
+ if (mItem != null) {
+
+ }
+ detailsViewModel = ViewModelProviders.of(this).get(DetailsViewModel.class);
+ detailsViewModel.getLiveData(getContext(), mItem ).observe(this, new Observer() {
+ @Override
+ public void onChanged(@Nullable CongresspersonDetails congresspersonDetails) {
+ ((TextView) rootView.findViewById(R.id.item_detail)).setText(congresspersonDetails.getCrpId() + "\n" +
+ congresspersonDetails.getCspanId() + "\n" +
+ congresspersonDetails.getCurrentParty() + "\n" +
+ congresspersonDetails.getDateOfBirth() + "\n" +
+ congresspersonDetails.getFacebookAccount() + "\n" +
+ congresspersonDetails.getGoogleEntityId());
+ }
+ });
+
+ return rootView;
+ }
+}
diff --git a/app/src/main/java/com/lambdaschool/congressdetails/ItemListActivity.java b/app/src/main/java/com/lambdaschool/congressdetails/ItemListActivity.java
new file mode 100644
index 0000000..07e3183
--- /dev/null
+++ b/app/src/main/java/com/lambdaschool/congressdetails/ItemListActivity.java
@@ -0,0 +1,160 @@
+package com.lambdaschool.congressdetails;
+
+import android.arch.lifecycle.Observer;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.Toolbar;
+import android.support.design.widget.FloatingActionButton;
+import android.support.design.widget.Snackbar;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+import android.arch.lifecycle.ViewModelProviders;
+
+import com.lambdaschool.congressdataapiaccess.CongresspersonOverview;
+
+import java.util.ArrayList;
+
+/**
+ * An activity representing a list of Items. This activity
+ * has different presentations for handset and tablet-size devices. On
+ * handsets, the activity presents a list of items, which when touched,
+ * lead to a {@link ItemDetailActivity} representing
+ * item details. On tablets, the activity presents the list of items and
+ * item details side-by-side using two vertical panes.
+ */
+public class ItemListActivity extends AppCompatActivity {
+
+ /**
+ * Whether or not the activity is in two-pane mode, i.e. running on a tablet
+ * device.
+ */
+ private boolean mTwoPane;
+ private CPOViewModel viewModel;
+ Context context;
+ RecyclerView recyclerView;
+ SimpleItemRecyclerViewAdapter adapter;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_item_list);
+ context = this;
+
+ viewModel = ViewModelProviders.of(this).get(CPOViewModel.class);
+
+ viewModel.getLiveData(this).observe(this, new Observer>() {
+ @Override
+ public void onChanged(@Nullable ArrayList congresspersonOverviews) {
+ adapter.notifyDataSetChanged();
+ }
+ });
+
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+ toolbar.setTitle(getTitle());
+
+ FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
+ fab.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
+ .setAction("Action", null).show();
+ }
+ });
+
+ if (findViewById(R.id.item_detail_container) != null) {
+ // The detail container view will be present only in the
+ // large-screen layouts (res/values-w900dp).
+ // If this view is present, then the
+ // activity should be in two-pane mode.
+ mTwoPane = true;
+ }
+
+ recyclerView = findViewById(R.id.item_list);
+ assert recyclerView != null;
+ adapter = new SimpleItemRecyclerViewAdapter(this,
+ viewModel.getLiveData(context).getValue(), mTwoPane);
+ recyclerView.setAdapter(adapter);
+ }
+
+ public static class SimpleItemRecyclerViewAdapter
+ extends RecyclerView.Adapter {
+
+ private final ItemListActivity mParentActivity;
+ private final ArrayList mValues;
+ private final boolean mTwoPane;
+ private final View.OnClickListener mOnClickListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ String item = (String) view.getTag();
+ if (mTwoPane) {
+ Bundle arguments = new Bundle();
+ arguments.putString(ItemDetailFragment.ARG_ITEM_ID, item);
+ ItemDetailFragment fragment = new ItemDetailFragment();
+ fragment.setArguments(arguments);
+ mParentActivity.getSupportFragmentManager().beginTransaction()
+ .replace(R.id.item_detail_container, fragment)
+ .commit();
+ } else {
+ Context context = view.getContext();
+ Intent intent = new Intent(context, ItemDetailActivity.class);
+ intent.putExtra(ItemDetailFragment.ARG_ITEM_ID, item);
+
+ context.startActivity(intent);
+ }
+ }
+ };
+
+ SimpleItemRecyclerViewAdapter(ItemListActivity parent,
+ ArrayList items,
+ boolean twoPane) {
+ mValues = items;
+ mParentActivity = parent;
+ mTwoPane = twoPane;
+ }
+
+ @Override
+ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ View view = LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.item_list_content, parent, false);
+ return new ViewHolder(view);
+ }
+
+ @Override
+ public void onBindViewHolder(final ViewHolder holder, int position) {
+ holder.firstName.setText(mValues.get(position).getFirstName());
+ holder.lastName.setText(mValues.get(position).getLastName());
+ holder.state.setText(mValues.get(position).getState());
+ holder.party.setText(mValues.get(position).getParty());
+
+ holder.itemView.setTag(mValues.get(position).getId());
+ holder.itemView.setOnClickListener(mOnClickListener);
+ }
+
+ @Override
+ public int getItemCount() {
+ return mValues.size();
+ }
+
+ class ViewHolder extends RecyclerView.ViewHolder {
+ final TextView firstName;
+ final TextView lastName;
+ final TextView party;
+ final TextView state;
+
+ ViewHolder(View view) {
+ super(view);
+ firstName = view.findViewById(R.id.first_name);
+ lastName = view.findViewById(R.id.last_name);
+ party = view.findViewById(R.id.party);
+ state = view.findViewById(R.id.state);
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/com/lambdaschool/congressdetails/ListActivity.java b/app/src/main/java/com/lambdaschool/congressdetails/ListActivity.java
deleted file mode 100644
index 8be745a..0000000
--- a/app/src/main/java/com/lambdaschool/congressdetails/ListActivity.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.lambdaschool.congressdetails;
-
-import android.support.v7.app.AppCompatActivity;
-import android.os.Bundle;
-
-import com.lambdaschool.congressdataapiaccess.CongressDao;
-
-
-public class ListActivity extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_list);
-
- CongressDao.getAllMembers();
- }
-}
diff --git a/app/src/main/res/layout-w900dp/item_list.xml b/app/src/main/res/layout-w900dp/item_list.xml
new file mode 100644
index 0000000..64e75f2
--- /dev/null
+++ b/app/src/main/res/layout-w900dp/item_list.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_item_detail.xml b/app/src/main/res/layout/activity_item_detail.xml
new file mode 100644
index 0000000..d6c4a73
--- /dev/null
+++ b/app/src/main/res/layout/activity_item_detail.xml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_item_list.xml b/app/src/main/res/layout/activity_item_list.xml
new file mode 100644
index 0000000..0e2bf4c
--- /dev/null
+++ b/app/src/main/res/layout/activity_item_list.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_list.xml b/app/src/main/res/layout/activity_list.xml
deleted file mode 100644
index 1884df2..0000000
--- a/app/src/main/res/layout/activity_list.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/item_detail.xml b/app/src/main/res/layout/item_detail.xml
new file mode 100644
index 0000000..bac2238
--- /dev/null
+++ b/app/src/main/res/layout/item_detail.xml
@@ -0,0 +1,10 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/item_list.xml b/app/src/main/res/layout/item_list.xml
new file mode 100644
index 0000000..5ba89c1
--- /dev/null
+++ b/app/src/main/res/layout/item_list.xml
@@ -0,0 +1,13 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/item_list_content.xml b/app/src/main/res/layout/item_list_content.xml
new file mode 100644
index 0000000..f83ab0e
--- /dev/null
+++ b/app/src/main/res/layout/item_list_content.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
new file mode 100644
index 0000000..868016b
--- /dev/null
+++ b/app/src/main/res/values/dimens.xml
@@ -0,0 +1,7 @@
+
+
+ 16dp
+ 200dp
+ 200dp
+ 16dp
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 53ad430..8af4935 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,3 +1,5 @@
Congress Details
+ Items
+ Item Detail
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 5885930..545b9c6 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -8,4 +8,13 @@
- @color/colorAccent
+
+
+
+
+
+