Skip to content

Commit

Permalink
Done S11.01- NewListItemLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
Gina committed Mar 23, 2018
1 parent 8d4d3fe commit 356bb79
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 24 deletions.
1 change: 1 addition & 0 deletions S11.01-Exercise-NewListItemLayout/app/build.gradle
Expand Up @@ -29,6 +29,7 @@ dependencies {
compile 'com.android.support:preference-v7:25.0.1'

// TODO (1) Add the ConstraintLayout dependency to your project
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta3'

compile 'com.firebase:firebase-jobdispatcher:0.5.0'

Expand Down
Expand Up @@ -22,6 +22,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.android.sunshine.utilities.SunshineDateUtils;
Expand Down Expand Up @@ -116,20 +117,35 @@ public void onBindViewHolder(ForecastAdapterViewHolder forecastAdapterViewHolder
long dateInMillis = mCursor.getLong(MainActivity.INDEX_WEATHER_DATE);
/* Get human readable string using our utility method */
String dateString = SunshineDateUtils.getFriendlyDateString(mContext, dateInMillis, false);
/* Use the weatherId to obtain the proper description */

/* Use the weatherId to obtain the proper description */
int weatherId = mCursor.getInt(MainActivity.INDEX_WEATHER_CONDITION_ID);
String description = SunshineWeatherUtils.getStringForWeatherCondition(mContext, weatherId);
/* Read high temperature from the cursor (in degrees celsius) */
String descriptionA11y = mContext.getString(R.string.a11y_forecast, description);

/* Read high temperature from the cursor (in degrees celsius) */
double highInCelsius = mCursor.getDouble(MainActivity.INDEX_WEATHER_MAX_TEMP);
/* Read low temperature from the cursor (in degrees celsius) */
String highTemp = SunshineWeatherUtils.formatTemperature(mContext,highInCelsius);
String highA11 = mContext.getString(R.string.a11y_high_temp, highTemp);

/* Read low temperature from the cursor (in degrees celsius) */
double lowInCelsius = mCursor.getDouble(MainActivity.INDEX_WEATHER_MIN_TEMP);
String lowTemp = SunshineWeatherUtils.formatTemperature(mContext,lowInCelsius);
String lowA11y = mContext.getString(R.string.a11y_low_temp, lowTemp);

String highAndLowTemperature =
SunshineWeatherUtils.formatHighLows(mContext, highInCelsius, lowInCelsius);
forecastAdapterViewHolder.dateView.setText(dateString);
forecastAdapterViewHolder.dateView.setContentDescription("Hello"+dateString);

String weatherSummary = dateString + " - " + description + " - " + highAndLowTemperature;
forecastAdapterViewHolder.descriptionView.setText(description);
forecastAdapterViewHolder.descriptionView.setContentDescription(descriptionA11y);

forecastAdapterViewHolder.weatherSummary.setText(weatherSummary);
forecastAdapterViewHolder.highTempView.setText(highTemp);
forecastAdapterViewHolder.highTempView.setContentDescription(highA11);

forecastAdapterViewHolder.lowTempView.setText(lowTemp);
forecastAdapterViewHolder.lowTempView.setContentDescription(lowA11y);

forecastAdapterViewHolder.iconView.setImageResource(SunshineWeatherUtils.getSmallArtResourceIdForWeatherCondition(weatherId));
}

/**
Expand Down Expand Up @@ -164,15 +180,26 @@ void swapCursor(Cursor newCursor) {
*/
class ForecastAdapterViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
// TODO (4) Replace the weatherSummary TextView with individual weather detail TextViews
final TextView weatherSummary;
//final TextView weatherSummary;
final TextView dateView;
final TextView descriptionView;
final TextView highTempView;
final TextView lowTempView;

// TODO (5) Add an ImageView for the weather icon
final ImageView iconView;

ForecastAdapterViewHolder(View view) {
super(view);

// TODO (6) Get references to all new views and delete this line
weatherSummary = (TextView) view.findViewById(R.id.tv_weather_data);
//weatherSummary = (TextView) view.findViewById(R.id.tv_weather_data);

iconView = (ImageView) view.findViewById(R.id.weather_icon);
descriptionView = (TextView)view.findViewById(R.id.weather_description);
dateView = (TextView)view.findViewById(R.id.date);
highTempView = (TextView)view.findViewById(R.id.high_temperature);
lowTempView = (TextView) view.findViewById(R.id.low_temperature);

view.setOnClickListener(this);
}
Expand Down
Expand Up @@ -16,26 +16,80 @@
-->
<!-- TODO (2) Remove the old layout -->
<!-- TODO (3) Use ConstraintLayout to create the new list item layout -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.constraint.ConstraintLayout 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="wrap_content"
android:orientation="vertical">
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingBottom="12dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="12dp">

<android.support.constraint.Guideline
android:id="@+id/guideLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />

<ImageView
android:id="@+id/weather_icon"
android:layout_width="40dp"
android:layout_height="40dp"
app:layout_constraintBottom_toTopOf="@+id/guideLine"

app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideLine"
tools:src="@drawable/art_clouds" />

<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"

app:layout_constraintBottom_toTopOf="@+id/guideLine"
app:layout_constraintLeft_toRightOf="@+id/weather_icon"
tools:text="Today, April 03" />

<!-- This TextView holds the weather data for one particular day in the forecast -->
<TextView
android:id="@+id/tv_weather_data"
style="@style/TextAppearance.AppCompat.Large"
android:id="@+id/weather_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"/>
android:layout_marginBottom="25dp"

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="@+id/date"
app:layout_constraintTop_toTopOf="@+id/guideLine"
tools:text="Rainy"/>


<TextView
android:id="@+id/high_temperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:textSize="28sp"


app:layout_constraintBottom_toTopOf="@+id/guideLine"
app:layout_constraintRight_toLeftOf="@+id/low_temperature"
app:layout_constraintTop_toTopOf="@+id/guideLine"
tools:text="19\u00b0" />

<TextView
android:id="@+id/low_temperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dp"
tools:text="10\u00b0"

app:layout_constraintBottom_toTopOf="@+id/guideLine"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideLine" />

<!-- This View serves as a visual divider between list items -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#dadada"/>

</LinearLayout>
</android.support.constraint.ConstraintLayout>

0 comments on commit 356bb79

Please sign in to comment.