Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cfc16d1
Added the ImageView containing the logo and the Button 'Add a Drop' i…
slidenerd Dec 23, 2015
1caa16c
Added the selector for background and text color of the Button 'Add a…
slidenerd Dec 24, 2015
a49c996
Added the toolbar to xml and setSupportActionBar to display the title…
slidenerd Dec 24, 2015
e7cb55b
Added Glide library to display background image and fixed the OutOfMe…
slidenerd Dec 24, 2015
3149e17
Added Event Handling using View.OnClickListener for the Button 'Add a…
slidenerd Dec 24, 2015
ae7e1ba
Added Event Handling using View.OnClickListener for the Button 'Add a…
slidenerd Dec 28, 2015
4bffaef
Added the Dialog Add class in java and initialized all views from the…
slidenerd Dec 28, 2015
ef7e465
Added a drop to realm through DialogAdd and used the RealmBrowser to …
slidenerd Dec 30, 2015
f86a373
Added the RecyclerView in XML
slidenerd Dec 30, 2015
5e8d0f0
Added the row_drop.xml and the selector bg_row_drop
slidenerd Dec 30, 2015
4415824
Added the implementation of RecyclerView.Adapter with dummy items ins…
slidenerd Dec 30, 2015
fdb8347
Displayed the data from the Realm Database inside the RecyclerView an…
slidenerd Dec 30, 2015
e90c201
Fixed the error 'plugin is too old' by updating gradle version from a…
slidenerd Dec 31, 2015
5fb65fb
Added an Adapter Data Observer to display an empty view when the Recy…
slidenerd Dec 31, 2015
787aede
Fixed a bug where an Image was not taking full screen width and heigh…
slidenerd Jan 2, 2016
51ec48f
Override the getItemViewType method and change the code inside onCrea…
slidenerd Jan 2, 2016
c4b73d7
Added a divider to the RecyclerView which is drawn on top of every it…
slidenerd Jan 3, 2016
751e1da
Added the AddListener interface that can be used to communicate betwe…
slidenerd Jan 3, 2016
e7428d1
Added Swipe to delete support with ItemTouchHelper.Callback and fixed…
slidenerd Jan 4, 2016
9b1b13e
Added the XML file for the Dialog Mark and changed the background col…
slidenerd Jan 4, 2016
e32d75c
Added the Dialog Mark in code and triggered it when an item from the …
slidenerd Jan 4, 2016
484e304
Marked the item as complete in the database by setting a different ba…
slidenerd Jan 4, 2016
8c9053b
Added the menu in XML and overriden the onCreateOptionsMenu and onOpt…
slidenerd Jan 5, 2016
8d9ce51
Displaying and storing dates in our App
slidenerd Jan 5, 2016
717fc6d
Added the code to sort data inside the RecyclerView on the basis of t…
slidenerd Jan 5, 2016
6d251f8
Added SharedPreferences to store user choice on how they want their d…
slidenerd Jan 5, 2016
5fbeb20
Added the NoItemsHolder to the Adapter to display "No Items to Displa…
slidenerd Jan 6, 2016
36b4c16
Override the getItemId to return a unique id for each item and call s…
slidenerd Jan 6, 2016
28322cf
Added code to disable Swipe on the Footer and the special "No Items t…
slidenerd Jan 6, 2016
fa14ae3
Added the reset listener to the app to maintain consistent ux when th…
slidenerd Jan 6, 2016
2f92273
Made the dialog full screen by adding a custom style for it and chang…
slidenerd Jan 9, 2016
7b0bdf1
Added the reset filter to keep the UX consistent
slidenerd Jan 10, 2016
08d49b5
Added a custom style for the Dialog and Toolbar
slidenerd Jan 10, 2016
2311552
Added the DatePickerWidget in XML with its essential drawables
slidenerd Jan 10, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'io.realm:realm-android:0.87.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="slidenerd.vivz.bucketdrops">

<application
android:name=".AppBucketDrops"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
194 changes: 193 additions & 1 deletion app/src/main/java/slidenerd/vivz/bucketdrops/ActivityMain.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,205 @@
package slidenerd.vivz.bucketdrops;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import io.realm.Realm;
import io.realm.RealmChangeListener;
import io.realm.RealmResults;
import io.realm.Sort;
import slidenerd.vivz.bucketdrops.adapters.AdapterDrops;
import slidenerd.vivz.bucketdrops.adapters.AddListener;
import slidenerd.vivz.bucketdrops.adapters.CompleteListener;
import slidenerd.vivz.bucketdrops.adapters.Divider;
import slidenerd.vivz.bucketdrops.adapters.Filter;
import slidenerd.vivz.bucketdrops.adapters.MarkListener;
import slidenerd.vivz.bucketdrops.adapters.ResetListener;
import slidenerd.vivz.bucketdrops.adapters.SimpleTouchCallback;
import slidenerd.vivz.bucketdrops.beans.Drop;
import slidenerd.vivz.bucketdrops.widgets.BucketRecyclerView;

public class ActivityMain extends AppCompatActivity {

Toolbar mToolbar;
Button mBtnAdd;
BucketRecyclerView mRecycler;
Realm mRealm;
RealmResults<Drop> mResults;
View mEmptyView;
AdapterDrops mAdapter;
private View.OnClickListener mBtnAddListener = new View.OnClickListener() {

@Override
public void onClick(View v) {
showDialogAdd();
}
};
private AddListener mAddListener = new AddListener() {
@Override
public void add() {
showDialogAdd();
}
};

private RealmChangeListener mChangeListener = new RealmChangeListener() {
@Override
public void onChange() {
mAdapter.update(mResults);
}
};

private MarkListener mMarkListener = new MarkListener() {
@Override
public void onMark(int position) {
showDialogMark(position);
}
};

private CompleteListener mCompleteListener = new CompleteListener() {
@Override
public void onComplete(int position) {
mAdapter.markComplete(position);
}
};
private ResetListener mResetListener = new ResetListener() {
@Override
public void onReset() {
AppBucketDrops.save(ActivityMain.this, Filter.NONE);
loadResults(Filter.NONE);
}
};

private void showDialogAdd() {
DialogAdd dialog = new DialogAdd();
dialog.show(getSupportFragmentManager(), "Add");
}

private void showDialogMark(int position) {
DialogMark dialog = new DialogMark();
Bundle bundle = new Bundle();
bundle.putInt("POSITION", position);
dialog.setArguments(bundle);
dialog.setCompleteListener(mCompleteListener);
dialog.show(getSupportFragmentManager(), "Mark");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRealm = Realm.getDefaultInstance();
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mBtnAdd = (Button) findViewById(R.id.btn_add);
mBtnAdd.setOnClickListener(mBtnAddListener);

int filterOption = AppBucketDrops.load(this);
loadResults(filterOption);
mEmptyView = findViewById(R.id.empty_drops);
mRecycler = (BucketRecyclerView) findViewById(R.id.rv_drops);
mRecycler.addItemDecoration(new Divider(this, LinearLayoutManager.VERTICAL));
mRecycler.setItemAnimator(new DefaultItemAnimator());
mRecycler.hideIfEmpty(mToolbar);
mRecycler.showIfEmpty(mEmptyView);
mAdapter = new AdapterDrops(this, mRealm, mResults, mAddListener, mMarkListener, mResetListener);
mAdapter.setHasStableIds(true);
mRecycler.setAdapter(mAdapter);
SimpleTouchCallback callback = new SimpleTouchCallback(mAdapter);
ItemTouchHelper helper = new ItemTouchHelper(callback);
helper.attachToRecyclerView(mRecycler);
initBackgroundImage();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
boolean handled = true;
int filterOption = Filter.NONE;
switch (id) {
case R.id.action_add:
showDialogAdd();
break;
case R.id.action_sort_none:
filterOption = Filter.NONE;
break;
case R.id.action_sort_ascending_date:
filterOption = Filter.LEAST_TIME_LEFT;
break;
case R.id.action_sort_descending_date:
filterOption = Filter.MOST_TIME_LEFT;
break;
case R.id.action_show_complete:
filterOption = Filter.COMPLETE;
break;
case R.id.action_show_incomplete:
filterOption = Filter.INCOMPLETE;
break;
default:
handled = false;
break;
}
loadResults(filterOption);
AppBucketDrops.save(this, filterOption);
return handled;
}

private void loadResults(int filterOption) {
switch (filterOption) {
case Filter.NONE:
mResults = mRealm.where(Drop.class).findAllAsync();
break;
case Filter.LEAST_TIME_LEFT:
mResults = mRealm.where(Drop.class).findAllSortedAsync("when");
break;
case Filter.MOST_TIME_LEFT:
mResults = mRealm.where(Drop.class).findAllSortedAsync("when", Sort.DESCENDING);
break;
case Filter.COMPLETE:
mResults = mRealm.where(Drop.class).equalTo("completed", true).findAllAsync();
break;
case Filter.INCOMPLETE:
mResults = mRealm.where(Drop.class).equalTo("completed", false).findAllAsync();
break;
}
mResults.addChangeListener(mChangeListener);
}


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

@Override
protected void onStop() {
super.onStop();
mResults.removeChangeListener(mChangeListener);
}

private void initBackgroundImage() {
ImageView background = (ImageView) findViewById(R.id.iv_background);
Glide.with(this)
.load(R.drawable.background)
.centerCrop()
.into(background);
}

}
39 changes: 39 additions & 0 deletions app/src/main/java/slidenerd/vivz/bucketdrops/AppBucketDrops.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package slidenerd.vivz.bucketdrops;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import io.realm.Realm;
import io.realm.RealmConfiguration;
import slidenerd.vivz.bucketdrops.adapters.Filter;

/**
* Created by vivz on 30/12/15.
* TODO change to custom fonts wherever appropriate
*/
public class AppBucketDrops extends Application {
public static final String TAG = "VIVZ";

@Override
public void onCreate() {
super.onCreate();
RealmConfiguration configuration = new RealmConfiguration.Builder(this).build();
Realm.setDefaultConfiguration(configuration);
}

public static void save(Context context, int filterOption) {

SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = pref.edit();
editor.putInt("filter", filterOption);
editor.apply();
}

public static int load(Context context) {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
int filterOption = pref.getInt("filter", Filter.NONE);
return filterOption;
}
}
92 changes: 92 additions & 0 deletions app/src/main/java/slidenerd/vivz/bucketdrops/DialogAdd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package slidenerd.vivz.bucketdrops;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;

import java.util.Calendar;

import io.realm.Realm;
import slidenerd.vivz.bucketdrops.beans.Drop;

/**
* Created by vivz on 28/12/15.
* TODO make it full screen + custom fonts
* TODO add custom date picker
*/
public class DialogAdd extends DialogFragment {

private ImageButton mBtnClose;
private EditText mInputWhat;
private DatePicker mInputWhen;
private Button mBtnAdd;

private View.OnClickListener mBtnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.btn_add_it:
addAction();
break;
}
dismiss();
}
};

private void addAction() {
//get the value of the 'goal' or 'to-do'
//get the time when it was added
String what = mInputWhat.getText().toString();
String date = mInputWhen.getDayOfMonth() + "/" + mInputWhen.getMonth() + "/" + mInputWhen.getYear();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, mInputWhen.getDayOfMonth());
calendar.set(Calendar.MONTH, mInputWhen.getMonth());
calendar.set(Calendar.YEAR, mInputWhen.getYear());
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
long now = System.currentTimeMillis();
Realm realm = Realm.getDefaultInstance();
Drop drop = new Drop(what, now, calendar.getTimeInMillis(), false);
realm.beginTransaction();
realm.copyToRealm(drop);
realm.commitTransaction();
realm.close();

}

public DialogAdd() {
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogTheme);
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.dialog_add, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mBtnClose = (ImageButton) view.findViewById(R.id.btn_close);
mInputWhat = (EditText) view.findViewById(R.id.et_drop);
mInputWhen = (DatePicker) view.findViewById(R.id.bpv_date);
mBtnAdd = (Button) view.findViewById(R.id.btn_add_it);

mBtnClose.setOnClickListener(mBtnClickListener);
mBtnAdd.setOnClickListener(mBtnClickListener);
}
}
Loading