Skip to content

Commit

Permalink
Merge branch 'master' into askutarenko-notification-style
Browse files Browse the repository at this point in the history
closes #50
  • Loading branch information
aaronj1335 committed Aug 20, 2016
2 parents 70af968 + fef3dd3 commit 6b246df
Show file tree
Hide file tree
Showing 21 changed files with 499 additions and 299 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})

def supportLibVersion = '24.2.0'
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:cardview-v7:${supportLibVersion}"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/g11x/checklistapp/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ protected int getNavDrawerItemIndex() {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/g11x/checklistapp/AppPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void setLanguageOverride(@NonNull Context context,
@Nullable Language language) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sp.edit();
if (language == null) {
if (language == null || language.equals(Language.SystemDefault)) {
editor.remove(PREF_PREFERRED_LANGUAGE);
} else {
editor.putString(PREF_PREFERRED_LANGUAGE, language.name());
Expand All @@ -65,7 +65,7 @@ public static void setLanguageOverride(@NonNull Context context,
}

/**
* Returns the language override or null when not set.
* Returns the language override setting.
*
* @param context component context used to retrieve shared preferences
*/
Expand All @@ -74,7 +74,7 @@ public static Language getLanguageOverride(@NonNull Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String value = sp.getString(PREF_PREFERRED_LANGUAGE, null);
if (value == null) {
return null;
return Language.SystemDefault;
}
return Language.valueOf(value);
}
Expand Down
51 changes: 46 additions & 5 deletions app/src/main/java/com/g11x/checklistapp/ChecklistActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package com.g11x.checklistapp;

import android.content.Intent;
import android.database.Cursor;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand All @@ -26,26 +28,37 @@

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.g11x.checklistapp.data.ChecklistItem;
import com.g11x.checklistapp.data.Database;
import com.g11x.checklistapp.language.Language;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class ChecklistActivity extends NavigationActivity {

private FirebaseRecyclerAdapter<ChecklistItem, ChecklistItemHolder> checklistAdapter;
private DatabaseReference databaseRef;
private AppPreferences.LanguageChangeListener languageChangeListener;
private Language language;

@Override
protected int getNavDrawerItemIndex() {
return NavigationActivity.NAVDRAWER_ITEM_CHECKLIST;
}


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

databaseRef = FirebaseDatabase.getInstance().getReference()
language = AppPreferences.getLanguageOverride(this);
languageChangeListener = new AppPreferences.LanguageChangeListener(this) {

@Override
public void onChanged(String newValue) {
ChecklistActivity.this.onLanguageChange(newValue);
}
};

DatabaseReference databaseRef = FirebaseDatabase.getInstance().getReference()
.child("checklists")
.child("basic");

Expand All @@ -57,10 +70,16 @@ protected void onCreate(Bundle savedInstanceState) {
ChecklistItem.class, R.layout.view_checklist_item, ChecklistItemHolder.class,
databaseRef) {

@Override
public void onBindViewHolder(ChecklistItemHolder viewHolder, int position) {
super.onBindViewHolder(viewHolder, position);
}

@Override
protected void populateViewHolder(
final ChecklistItemHolder itemHolder, ChecklistItem model, final int position) {
itemHolder.setText(model.getName());
itemHolder.markDone(model.isDone(getContentResolver()));
itemHolder.setText(model.getName(language));
itemHolder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -77,22 +96,44 @@ public void onClick(View view) {
@Override
protected void onStart() {
super.onStart();
// Need to populate done status at onStart as well.
Cursor donenessCursor = getContentResolver().query(Database.ChecklistItem.CONTENT_URI,
ChecklistItem.PROJECTION, null, null, null);
if (donenessCursor.moveToFirst()) {
for (int i = 0; i < donenessCursor.getCount(); i++) {
String itemHash = donenessCursor.getString(ChecklistItem.ITEM_HASH_COLUMN_INDEX);
int done = donenessCursor.getInt(ChecklistItem.DONE_COLUMN_INDEX);
donenessCursor.moveToNext();
}
}
}

private void onLanguageChange(String newValue) {
language = Language.valueOf(newValue);
}

@Override
protected void onDestroy() {
super.onDestroy();
checklistAdapter.cleanup();
languageChangeListener.unregister(this);
}

public static class ChecklistItemHolder extends RecyclerView.ViewHolder {
View view;
final View view;

public ChecklistItemHolder(View itemView) {
super(itemView);
view = itemView;
}

public void markDone(boolean done) {
if (done) {
TextView textView = (TextView) view.findViewById(R.id.info_text);
textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
}

public void setText(String title) {
TextView textView = (TextView) view.findViewById(R.id.info_text);
textView.setText(title);
Expand Down
41 changes: 29 additions & 12 deletions app/src/main/java/com/g11x/checklistapp/ChecklistItemActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.g11x.checklistapp;

import android.content.ContentResolver;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -27,7 +28,7 @@
import android.widget.ToggleButton;

import com.g11x.checklistapp.data.ChecklistItem;
import com.g11x.checklistapp.data.ChecklistManager;
import com.g11x.checklistapp.language.Language;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
Expand All @@ -39,14 +40,25 @@ public class ChecklistItemActivity extends AppCompatActivity {
private ChecklistItem checklistItem;
private ToggleButton isDone;
private DatabaseReference databaseRef;
private Language language;
private AppPreferences.LanguageChangeListener languageChangeListener;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
setContentView(R.layout.activity_checklist_item);

databaseRef = FirebaseDatabase.getInstance().getReferenceFromUrl(
language = AppPreferences.getLanguageOverride(this);
languageChangeListener = new AppPreferences.LanguageChangeListener(this) {

@Override
public void onChanged(String newValue) {
ChecklistItemActivity.this.onLanguageChange(newValue);
}
};

DatabaseReference databaseRef = FirebaseDatabase.getInstance().getReferenceFromUrl(
this.getIntent().getStringExtra("databaseRefUrl"));

databaseRef.addValueEventListener(new ValueEventListener() {
Expand All @@ -64,12 +76,22 @@ public void onCancelled(DatabaseError databaseError) {

}

private void onLanguageChange(String newValue) {
language = Language.valueOf(newValue);
}

@Override
protected void onDestroy() {
super.onDestroy();
languageChangeListener.unregister(this);
}

private void createUI() {
TextView name = (TextView) findViewById(R.id.name);
name.setText(checklistItem.getName());
name.setText(checklistItem.getName(language));

TextView description = (TextView) findViewById(R.id.description);
description.setText(checklistItem.getDescription());
description.setText(checklistItem.getDescription(language));

Button getDirections = (Button) findViewById(R.id.directions);
getDirections.setOnClickListener(new View.OnClickListener() {
Expand All @@ -80,7 +102,7 @@ public void onClick(View view) {
});

isDone = (ToggleButton) findViewById(R.id.doneness);
isDone.setChecked(checklistItem.isDone());
isDone.setChecked(checklistItem.isDone(getContentResolver()));
isDone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -89,14 +111,9 @@ public void onClick(View view) {
});
}

@Override
protected void onStart() {
super.onStart();
}

private void onClickIsDone() {
checklistItem.setDone(!checklistItem.isDone());
ChecklistManager.save(getApplicationContext(), ChecklistManager.get(getApplicationContext()));
ContentResolver contentResolver = getContentResolver();
checklistItem.setDone(contentResolver, !checklistItem.isDone(contentResolver));
}

private void onClickGetDirections() {
Expand Down
21 changes: 20 additions & 1 deletion app/src/main/java/com/g11x/checklistapp/LanguageActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.g11x.checklistapp;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.CardView;
Expand All @@ -42,7 +43,9 @@ protected void onCreate(Bundle savedInstanceState) {

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_content);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(new LanguageSelectionAdapter());
Language language = AppPreferences.getLanguageOverride(this);
recyclerView.setAdapter(new LanguageSelectionAdapter(language));

}

@Override
Expand All @@ -52,6 +55,12 @@ protected int getNavDrawerItemIndex() {

static class LanguageSelectionAdapter extends RecyclerView.Adapter<LanguageSelectionAdapter.ViewHolder> {
private Language[] dataSet = Language.values();
@NonNull
private final Language language;

LanguageSelectionAdapter(@NonNull Language lang) {
language = lang;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Expand All @@ -64,6 +73,14 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public void onBindViewHolder(ViewHolder holder, int position) {
holder.language = dataSet[position];
holder.textView.setText(dataSet[position].getNativeDescription());
if (language.equals(holder.language)) {
holder.cardView.setSelected(true);
holder.cardView.setActivated(true);
holder.cardView.setCardBackgroundColor(holder.cardView.getResources().getColor(R.color.accent));
} else {
holder.cardView.setSelected(false);
holder.cardView.setActivated(false);
}
}

@Override
Expand All @@ -74,8 +91,10 @@ public int getItemCount() {
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView textView;
private Language language;
private CardView cardView;
ViewHolder(final CardView view) {
super(view);
cardView = view;
textView = (TextView)view.findViewById(R.id.checkbox);
view.setOnClickListener(this);
}
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/com/g11x/checklistapp/LocalRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,22 @@ public String getType(@NonNull Uri uri) {
@Nullable
@Override
public Uri insert(@NonNull Uri uri, ContentValues contentValues) {
return Database.insert(openHelper.getWritableDatabase(), uri, contentValues);
Uri insertUri = Database.insert(openHelper.getWritableDatabase(), uri, contentValues);
getContext().getContentResolver().notifyChange(uri, null);
getContext().getContentResolver().notifyChange(insertUri, null);
return insertUri;
}

@Override
public int delete(@NonNull Uri uri, String s, String[] strings) {
return 0;
throw new UnsupportedOperationException();
}

@Override
public int update(@NonNull Uri uri, ContentValues contentValues, String selection, String[] selectionArgs) {
return Database.update(openHelper.getWritableDatabase(), uri, contentValues, selection, selectionArgs);
int updateValue = Database.update(openHelper.getWritableDatabase(), uri, contentValues, selection, selectionArgs);
getContext().getContentResolver().notifyChange(uri, null);
return updateValue;
}

// Helper class that actually creates and manages the provider's underlying data repository.
Expand Down
Loading

0 comments on commit 6b246df

Please sign in to comment.