-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented RecyclerView for Hourly Forecast
- Loading branch information
Robert Henigan
committed
Apr 17, 2018
1 parent
e9fd75b
commit a993c75
Showing
18 changed files
with
664 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/example/rhenigan/stormy/HourlyForecastActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.example.rhenigan.stormy; | ||
|
||
import android.content.Intent; | ||
import android.os.Parcelable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
|
||
import com.example.rhenigan.stormy.UI.MainActivity; | ||
import com.example.rhenigan.stormy.adapters.HourAdapter; | ||
import com.example.rhenigan.stormy.weather.Hour; | ||
|
||
import java.util.Arrays; | ||
|
||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
|
||
public class HourlyForecastActivity extends AppCompatActivity { | ||
|
||
private Hour[] mHours; | ||
|
||
@BindView(R.id.recyclerView) RecyclerView mRecyclerView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_hourly_forecast); | ||
|
||
ButterKnife.bind(this); | ||
|
||
Intent intent = getIntent(); | ||
Parcelable[] parcelables = intent.getParcelableArrayExtra(MainActivity.HOURLY_FORECAST); | ||
mHours = Arrays.copyOf(parcelables, parcelables.length, Hour[].class); | ||
|
||
HourAdapter adapter = new HourAdapter(mHours); | ||
mRecyclerView.setAdapter(adapter); | ||
|
||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); | ||
mRecyclerView.setLayoutManager(layoutManager); | ||
|
||
mRecyclerView.setHasFixedSize(true); | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
.../rhenigan/stormy/AlertDialogFragment.java → ...enigan/stormy/UI/AlertDialogFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/main/java/com/example/rhenigan/stormy/adapters/HourAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.example.rhenigan.stormy.adapters; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.example.rhenigan.stormy.R; | ||
import com.example.rhenigan.stormy.weather.Hour; | ||
|
||
/** | ||
* Created by henig on 4/16/2018. | ||
* ------------------------------ | ||
*/ | ||
public class HourAdapter extends RecyclerView.Adapter<HourAdapter.HourViewHolder> { | ||
|
||
private Hour[] mHours; | ||
|
||
public HourAdapter(Hour[] hours) { | ||
mHours = hours; | ||
} | ||
|
||
public class HourViewHolder extends RecyclerView.ViewHolder { | ||
|
||
public TextView mTimeLabel; | ||
public TextView mSummaryLabel; | ||
public TextView mTempLabel; | ||
public ImageView mIconImageView; | ||
|
||
public HourViewHolder(View itemView) { | ||
super(itemView); | ||
|
||
mTimeLabel = itemView.findViewById(R.id.timeLabel); | ||
mSummaryLabel = itemView.findViewById(R.id.summaryLabel); | ||
mTempLabel = itemView.findViewById(R.id.tempLabel); | ||
mIconImageView = itemView.findViewById(R.id.iconImageView); | ||
} | ||
|
||
public void bindHour(Hour hour) { | ||
mTimeLabel.setText(hour.getHour()); | ||
mSummaryLabel.setText(hour.getSummary()); | ||
mTempLabel.setText(hour.getTemp() + ""); | ||
mIconImageView.setImageResource(hour.getIconId()); | ||
} | ||
} | ||
|
||
@Override | ||
public HourViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.hourly_list_item, parent, false); | ||
HourViewHolder viewHolder = new HourViewHolder(view); | ||
return viewHolder; | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(HourViewHolder holder, int position) { | ||
holder.bindHour(mHours[position]); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return mHours.length; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.