diff --git a/app/build.gradle b/app/build.gradle index b036fea..9bf0476 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,4 +25,7 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'android.arch.lifecycle:extensions:1.1.1' + implementation 'android.arch.lifecycle:viewmodel:1.1.1' + implementation project(':congressdataapiaccess-debug') } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 26b1cb9..dbdc015 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,6 +16,7 @@ + \ No newline at end of file diff --git a/app/src/main/java/com/lambdaschool/congressdetails/CongressPersonDetailsRepo.java b/app/src/main/java/com/lambdaschool/congressdetails/CongressPersonDetailsRepo.java new file mode 100644 index 0000000..97158a8 --- /dev/null +++ b/app/src/main/java/com/lambdaschool/congressdetails/CongressPersonDetailsRepo.java @@ -0,0 +1,18 @@ +package com.lambdaschool.congressdetails; + +import android.arch.lifecycle.MutableLiveData; + +import com.lambdaschool.congressdataapiaccess.CongressDao; +import com.lambdaschool.congressdataapiaccess.CongresspersonDetails; + +import java.util.ArrayList; + +public class CongressPersonDetailsRepo { + + public static MutableLiveData getDetails(String id) { + final MutableLiveData liveDataList = new MutableLiveData<>(); + CongresspersonDetails details = CongressDao.getMemberDetails(id); + liveDataList.setValue(details); + return liveDataList; + } +} diff --git a/app/src/main/java/com/lambdaschool/congressdetails/CongressPersonOverviewRepo.java b/app/src/main/java/com/lambdaschool/congressdetails/CongressPersonOverviewRepo.java new file mode 100644 index 0000000..dc03b5f --- /dev/null +++ b/app/src/main/java/com/lambdaschool/congressdetails/CongressPersonOverviewRepo.java @@ -0,0 +1,23 @@ +package com.lambdaschool.congressdetails; + +import android.arch.lifecycle.MutableLiveData; + +import com.lambdaschool.congressdataapiaccess.CongressDao; +import com.lambdaschool.congressdataapiaccess.CongresspersonOverview; + +import java.util.ArrayList; + +public class CongressPersonOverviewRepo { + + public static MutableLiveData> getOverviewList() { + final MutableLiveData> liveDataList = new MutableLiveData<>(); + + ArrayList rawdata = CongressDao.getAllMembers(); + liveDataList.setValue(rawdata); + return liveDataList; + } + + +} + + diff --git a/app/src/main/java/com/lambdaschool/congressdetails/CongressPersonViewModel.java b/app/src/main/java/com/lambdaschool/congressdetails/CongressPersonViewModel.java new file mode 100644 index 0000000..3deae9d --- /dev/null +++ b/app/src/main/java/com/lambdaschool/congressdetails/CongressPersonViewModel.java @@ -0,0 +1,26 @@ +package com.lambdaschool.congressdetails; + +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.MutableLiveData; +import android.arch.lifecycle.ViewModel; + +import com.lambdaschool.congressdataapiaccess.CongresspersonOverview; + +import java.util.ArrayList; + +public class CongressPersonViewModel extends ViewModel { + + private MutableLiveData> congressPersonDetailsList; + + + public LiveData> getCongresspersonOverviewList(){ + if(congressPersonDetailsList == null) { + loadlist(); + } + return congressPersonDetailsList; + } + + private void loadlist(){ + congressPersonDetailsList = CongressPersonOverviewRepo.getOverviewList(); + } +} diff --git a/app/src/main/java/com/lambdaschool/congressdetails/DetailsActivity.java b/app/src/main/java/com/lambdaschool/congressdetails/DetailsActivity.java new file mode 100644 index 0000000..8af77fa --- /dev/null +++ b/app/src/main/java/com/lambdaschool/congressdetails/DetailsActivity.java @@ -0,0 +1,16 @@ +package com.lambdaschool.congressdetails; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; + +public class DetailsActivity extends AppCompatActivity { + + public static final String CONGRESS_DETAILS_KEY = "congress_details"; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_details); + } +} diff --git a/app/src/main/java/com/lambdaschool/congressdetails/ListActivity.java b/app/src/main/java/com/lambdaschool/congressdetails/ListActivity.java index 3b2296e..6b3001b 100644 --- a/app/src/main/java/com/lambdaschool/congressdetails/ListActivity.java +++ b/app/src/main/java/com/lambdaschool/congressdetails/ListActivity.java @@ -1,13 +1,70 @@ package com.lambdaschool.congressdetails; +import android.arch.lifecycle.Observer; +import android.arch.lifecycle.ViewModelProviders; +import android.content.Context; +import android.content.Intent; +import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.lambdaschool.congressdataapiaccess.CongresspersonDetails; +import com.lambdaschool.congressdataapiaccess.CongresspersonOverview; + +import org.w3c.dom.Text; + +import java.util.ArrayList; public class ListActivity extends AppCompatActivity { + + private Context context; + private LinearLayout listlayout; + private CongressPersonViewModel viewModel; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); + + context = this; + listlayout = findViewById(R.id.list_layout); + + viewModel = ViewModelProviders.of(this).get(CongressPersonViewModel.class); + final Observer> observer = new Observer>() { + @Override + public void onChanged(@Nullable ArrayList congresspersonOverviews) { + if (congresspersonOverviews == null) { + refreshListView(congresspersonOverviews); + } + } + }; + + } + + private TextView getDefaultTextView(final CongresspersonOverview congresspersonOverviews){ + TextView textView = new TextView(context); + textView.setText(congresspersonOverviews.getFirstName() + " " + congresspersonOverviews.getLastName()); + textView.setTextSize(18); + textView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String id = congresspersonOverviews.getId(); + Intent intent = new Intent(context, DetailsActivity.class); + //intent.putExtra(DetailsActivity.CONGRESS_DETAILS_KEY, congresspersonOverviews); + //startActivityForResult(intent, ); + } + }); + } + + private void refreshListView(ArrayList congresspersonOverviews) { + listlayout.removeAllViews(); + + for(CongresspersonOverview cpOverview : congresspersonOverviews){ + //listlayout.addView(); + } } } diff --git a/app/src/main/res/layout/activity_details.xml b/app/src/main/res/layout/activity_details.xml new file mode 100644 index 0000000..1bea86b --- /dev/null +++ b/app/src/main/res/layout/activity_details.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + \ 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 index 1884df2..88c1196 100644 --- a/app/src/main/res/layout/activity_list.xml +++ b/app/src/main/res/layout/activity_list.xml @@ -6,13 +6,24 @@ android:layout_height="match_parent" tools:context=".ListActivity"> - + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 077cb2f..8d3ef8e 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 95d3e5f..a5ab4ee 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Sep 04 14:01:16 MDT 2018 +#Thu Nov 08 13:55:48 PST 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