Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/externalDependencies.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ 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'
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 project(':congressdataapiaccess-debug')
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'android.arch.lifecycle:viewmodel:1.1.1'
}
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lambdaschool.congressdetails">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ListActivity">
<activity android:name=".activities.ListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.DetailCongressPerson"></activity>
</application>

</manifest>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.lambdaschool.congressdetails.activities;

import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.lambdaschool.congressdataapiaccess.CongresspersonDetails;
import com.lambdaschool.congressdetails.R;
import com.lambdaschool.congressdetails.viewModel.DetailCongressPersonViewModel;

public class DetailCongressPerson extends AppCompatActivity {

DetailCongressPersonViewModel viewModel;
TextView name;
TextView dateOfBirth;
TextView gender;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_congress_person);

name = findViewById(R.id.textViewName);
dateOfBirth = findViewById(R.id.textViewDateOfBirth);
gender = findViewById(R.id.textViewGender);

String congressPersonId = getIntent().getStringExtra(ListActivity.CONGRESS_PERSON_ID);
if (congressPersonId != null && congressPersonId != "") {
viewModel = ViewModelProviders.of(this).get(DetailCongressPersonViewModel.class);
viewModel.getDetails(congressPersonId).observe(this, new Observer<CongresspersonDetails>() {
@Override
public void onChanged(@Nullable CongresspersonDetails congresspersonDetails) {
if (congresspersonDetails != null) {
name.setText(new StringBuilder().append(congresspersonDetails.getFirstName()).append(" ").append(congresspersonDetails.getLastName()).toString());
dateOfBirth.setText(new StringBuilder().append("Born: ").append(congresspersonDetails.getDateOfBirth()).toString());
gender.setText(new StringBuilder().append("Gender: ").append(congresspersonDetails.getGender()).toString());
}
}
});
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.lambdaschool.congressdetails.activities;

import android.arch.lifecycle.Observer;
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.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lambdaschool.congressdataapiaccess.CongressDao;
import com.lambdaschool.congressdataapiaccess.CongresspersonOverview;
import com.lambdaschool.congressdetails.R;
import com.lambdaschool.congressdetails.viewModel.CongressOverviewViewModel;

import java.util.ArrayList;


public class ListActivity extends AppCompatActivity {

public static final String CONGRESS_PERSON_ID = "person_id";
Context context;
CongressOverviewViewModel viewModel;
LinearLayout parentLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);

context = this;
parentLayout = findViewById(R.id.parentlayout);

viewModel = ViewModelProviders.of(this).get(CongressOverviewViewModel.class);
viewModel.getOverView().observe(this, new Observer<ArrayList<CongresspersonOverview>>() {
@Override
public void onChanged(@Nullable ArrayList<CongresspersonOverview> congresspersonOverviews) {
if (congresspersonOverviews != null) {
for (CongresspersonOverview person : congresspersonOverviews) {
parentLayout.addView(getDefaultTextView(person));

}
}
}
});

CongressDao.getAllMembers();
}

TextView getDefaultTextView(final CongresspersonOverview person) {
TextView view = new TextView(context);
String personName = new StringBuilder().append(person.getFirstName()).append(" ").append(person.getLastName()).append("\n").append(person.getParty()).append("-").append(person.getState()).toString();
final String idTag = person.getId();
view.setTag(idTag);
view.setText(personName);
view.setTextSize(28);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentCongressPerson = new Intent(context, DetailCongressPerson.class);
intentCongressPerson.putExtra(CONGRESS_PERSON_ID, idTag);
startActivity(intentCongressPerson);
}
});

return view;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.lambdaschool.congressdetails.repo;

import android.arch.lifecycle.MutableLiveData;

import com.lambdaschool.congressdataapiaccess.CongressDao;
import com.lambdaschool.congressdataapiaccess.CongresspersonOverview;

import java.util.ArrayList;

public class CongressPersonOverviewRepository {

public static MutableLiveData<ArrayList<CongresspersonOverview>> getOverList() {
MutableLiveData<ArrayList<CongresspersonOverview>> liveData = new MutableLiveData<>();
ArrayList<CongresspersonOverview> rawData = CongressDao.getAllMembers();
liveData.setValue(rawData);
return liveData;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.lambdaschool.congressdetails.repo;

import android.arch.lifecycle.MutableLiveData;

import com.lambdaschool.congressdataapiaccess.CongressDao;
import com.lambdaschool.congressdataapiaccess.CongresspersonDetails;

public class DetailCongressPersonRepo {

public static MutableLiveData<CongresspersonDetails> getDetails(String id) {
final MutableLiveData<CongresspersonDetails> liveData = new MutableLiveData<>();
CongresspersonDetails profile = CongressDao.getMemberDetails(id);
liveData.setValue(profile);
return liveData;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.lambdaschool.congressdetails.viewModel;

import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;

import com.lambdaschool.congressdataapiaccess.CongresspersonOverview;
import com.lambdaschool.congressdetails.repo.CongressPersonOverviewRepository;

import java.util.ArrayList;

public class CongressOverviewViewModel extends ViewModel {

private MutableLiveData<ArrayList<CongresspersonOverview>> overviewList;

public MutableLiveData<ArrayList<CongresspersonOverview>> getOverView() {
if (overviewList == null) {
load();
}
return overviewList;
}

private void load() {
overviewList = CongressPersonOverviewRepository.getOverList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.lambdaschool.congressdetails.viewModel;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;

import com.lambdaschool.congressdataapiaccess.CongresspersonDetails;
import com.lambdaschool.congressdetails.repo.DetailCongressPersonRepo;

public class DetailCongressPersonViewModel extends ViewModel {
private MutableLiveData<CongresspersonDetails> liveData;

public LiveData<CongresspersonDetails> getDetails(String id) {
if (liveData == null) {
loadData(id);
}
return liveData;
}

private void loadData(String id) {
liveData = DetailCongressPersonRepo.getDetails(id);
}
}
43 changes: 43 additions & 0 deletions app/src/main/res/layout/activity_detail_congress_person.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.DetailCongressPerson">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin"
android:orientation="vertical">

<TextView
android:id="@+id/textViewName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin"
android:gravity="center"
android:textSize="@dimen/text_size" />

<TextView
android:id="@+id/textViewDateOfBirth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin"
android:gravity="center"
android:textSize="@dimen/text_size" />

<TextView
android:id="@+id/textViewGender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin"
android:gravity="center"
android:textSize="@dimen/text_size" />
</LinearLayout>
</ScrollView>
</LinearLayout>
28 changes: 17 additions & 11 deletions app/src/main/res/layout/activity_list.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
<?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"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ListActivity">
android:orientation="vertical"
tools:context=".activities.ListActivity">

<TextView
android:layout_width="wrap_content"
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_margin="@dimen/margin">

</android.support.constraint.ConstraintLayout>
<LinearLayout
android:id="@+id/parentlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin"
android:orientation="vertical">

</LinearLayout>
</ScrollView>

</LinearLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">24sp</dimen>
<dimen name="margin">8dp</dimen>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.2.1'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Sep 04 14:01:16 MDT 2018
#Sun Nov 11 07:55:31 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip