-
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.
- Loading branch information
1 parent
82faf9f
commit 24252ea
Showing
10 changed files
with
250 additions
and
8 deletions.
There are no files selected for viewing
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
85 changes: 85 additions & 0 deletions
85
app/src/main/java/com/teinvdlugt/android/greekgods/AllPeopleActivity.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,85 @@ | ||
package com.teinvdlugt.android.greekgods; | ||
|
||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.os.AsyncTask; | ||
import android.os.Bundle; | ||
import android.os.PersistableBundle; | ||
import android.support.design.widget.Snackbar; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.MenuItem; | ||
|
||
import com.teinvdlugt.android.greekgods.models.Person; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AllPeopleActivity extends AppCompatActivity implements AllPeopleRecyclerViewAdapter.OnPersonClickListener { | ||
|
||
private RecyclerView recyclerView; | ||
private AllPeopleRecyclerViewAdapter adapter; | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_all_people); | ||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); | ||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
|
||
recyclerView = (RecyclerView) findViewById(R.id.recyclerView); | ||
recyclerView.setLayoutManager(new LinearLayoutManager(this)); | ||
adapter = new AllPeopleRecyclerViewAdapter(this, new ArrayList<Person>(), this); | ||
recyclerView.setAdapter(adapter); | ||
refresh(); | ||
} | ||
|
||
private void refresh() { | ||
new AsyncTask<Void, Void, List<Person>>() { | ||
@Override | ||
protected List<Person> doInBackground(Void... params) { | ||
SQLiteDatabase db = openOrCreateDatabase("data", 0, null); | ||
String[] columns = {"personId", "name"}; | ||
Cursor c = db.query("people", columns, null, null, null, null, "name"); | ||
int idColumn = c.getColumnIndex("personId"); | ||
int nameColumn = c.getColumnIndex("name"); | ||
|
||
List<Person> result = new ArrayList<>(); | ||
|
||
c.moveToFirst(); | ||
do { | ||
Person p = new Person(); | ||
p.setId(c.getInt(idColumn)); | ||
p.setName(c.getString(nameColumn)); | ||
result.add(p); | ||
} while (c.moveToNext()); | ||
c.close(); | ||
db.close(); | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(List<Person> persons) { | ||
adapter.setData(persons); | ||
} | ||
}.execute(); | ||
} | ||
|
||
@Override | ||
public void onClickPerson(Person person) { | ||
Snackbar.make(recyclerView, "Well done, you clicked " + person.getName() + "'s name!", Snackbar.LENGTH_LONG).show(); | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
if (item.getItemId() == android.R.id.home) { | ||
finish(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/teinvdlugt/android/greekgods/AllPeopleRecyclerViewAdapter.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,66 @@ | ||
package com.teinvdlugt.android.greekgods; | ||
|
||
import android.content.Context; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import com.teinvdlugt.android.greekgods.models.Person; | ||
|
||
import java.util.List; | ||
|
||
public class AllPeopleRecyclerViewAdapter extends RecyclerView.Adapter<AllPeopleRecyclerViewAdapter.ViewHolder> { | ||
|
||
private Context context; | ||
private List<Person> data; | ||
private OnPersonClickListener onPersonClickListener; | ||
|
||
public AllPeopleRecyclerViewAdapter(Context context, List<Person> data, OnPersonClickListener onPersonClickListener) { | ||
this.context = context; | ||
this.data = data; | ||
this.onPersonClickListener = onPersonClickListener; | ||
} | ||
|
||
public interface OnPersonClickListener { | ||
void onClickPerson(Person person); | ||
} | ||
|
||
public void setData(List<Person> data) { | ||
this.data = data; | ||
notifyDataSetChanged(); | ||
} | ||
|
||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.list_item_all_people, parent, false)); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(final ViewHolder holder, final int position) { | ||
holder.nameTextView.setText(data.get(position).getName()); | ||
holder.itemView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (onPersonClickListener != null) | ||
onPersonClickListener.onClickPerson(data.get(holder.getAdapterPosition())); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return data.size(); | ||
} | ||
|
||
static class ViewHolder extends RecyclerView.ViewHolder { | ||
private TextView nameTextView; | ||
|
||
public ViewHolder(View itemView) { | ||
super(itemView); | ||
|
||
nameTextView = (TextView) itemView.findViewById(R.id.name_textView); | ||
} | ||
} | ||
} |
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
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,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<android.support.design.widget.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:theme="@style/AppTheme.AppBarOverlay"> | ||
|
||
<android.support.v7.widget.Toolbar | ||
app:popupTheme="@style/AppTheme.PopupOverlay" | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:background="?attr/colorPrimary" | ||
app:layout_scrollFlags="scroll|snap|enterAlways" /> | ||
</android.support.design.widget.AppBarLayout> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/recyclerView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:scrollbars="vertical" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> | ||
</android.support.design.widget.CoordinatorLayout> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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" | ||
android:background="?selectableItemBackground" | ||
android:orientation="vertical"> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="0.5dp" | ||
android:background="@android:color/darker_gray" /> | ||
|
||
<TextView | ||
android:id="@+id/name_textView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="8dp" | ||
android:layout_marginLeft="16dp" | ||
android:layout_marginStart="16dp" | ||
android:layout_marginTop="8dp" | ||
android:textColor="@android:color/black" | ||
android:textSize="18sp" | ||
tools:text="Chaos" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="0.5dp" | ||
android:background="@android:color/darker_gray" /> | ||
</LinearLayout> |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<resources> | ||
<string name="app_name">Griekse Goden</string> | ||
<string name="all_people">Alle familieleden</string> | ||
</resources> |
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
</style> | ||
|
||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> | ||
|
||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> | ||
</resources> |