Skip to content

Commit

Permalink
Merge pull request #133 from jianzhaojohn/develop
Browse files Browse the repository at this point in the history
develop to master for beta release
  • Loading branch information
jianzhaojohn authored Apr 13, 2018
2 parents c5b3c2d + 6dfeb38 commit 660d367
Show file tree
Hide file tree
Showing 25 changed files with 482 additions and 61 deletions.
Binary file added .idea/caches/build_file_checksums.ser
Binary file not shown.
18 changes: 1 addition & 17 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
* I want to be stimulated by my Habit Rabbit.
* Habit Rabbit will guilt me into keeping to my habits by accusing me of "murdering" my virtual rabbits if I do not do what I promised I would.

## Landing Page
https://habit-rabbit.000webhostapp.com/

## Beta Release
https://youtu.be/Xox4mv7I9XQ


## Project Description:

Expand All @@ -20,22 +26,34 @@ Users will be able to
* create/login
* input, remove and edit habits
* view habits in an agenda layout
* view Rabbit Hutch, which is filled with rabbits as you complete a habit, but kills the rabbits when you don’t (and notifies the user that they murdered their rabbits)
* view Rabbit Hutch, which is contain a cute rabit as you complete the habit, but kills the rabbit when you don’t (and notify user if theri rabit dies)
* show the habit history in a graph view form (so user can clearly see how they did in past)

### Add-on features
* sync with other apps to be kept accountable (such as Fitbit, MyFitnessPal, etc)
* push selected habits to google calendar
* add “friends” who will be able to shame them when they falsely enter that they did something that they didn’t
* bet money,using paypal, that they will complete all their habits for a given period of time. If they fail, the money is donated to a charity of their choice.

### How to use our app

when you first open up our app, you will see the login page pops up. you have 2 opetions here: first login with your existing account. second, creating an account. To create a account you simplly click on the register button and this will lead you to the registration page. there is 2 limits on creating account: for user name it must contain "@" and for passwords it has to have at least 4 characters.
After you done with register you can back to login page and login there. When you login, you will see our main page which contain only one rabit house. you can go to another page using the "hunberger" button ont he top left and top right.

In habit page, you can add and create new habit (just click on the button on the buttom right) and in the Agenda page you can see all your habit in a list view. Those data is update whenever you open you app (we update them through our database).

you can check the habit when you finish them and we will record how you did in a period and display them in a graph view (just click on the habit in habit page for detail). this give user a clearly view how they do in past to build up their habits.

Lastly, our notification works when you open the app and only when you open the app (we are thinking to make it run in background, but not sure if that is too "expensive" in resource for our app. So still thinking).

### How to Run

Test e-mail: [email protected]
Test password: test

You need these to log in once you have run the app.

#### If you have an android device with android version 7.0 (API 24) or above:
#### If you have an android device with android with API level 25 or above (to work properly):

1. Download the apk with your android device using the link provided below.
2. https://drive.google.com/file/d/0B5mPzcwLTPnPQ1VfbldDUHU5eXhTazFzVC1NWUJSQmUtaUpn/view?usp=sharing
Expand Down Expand Up @@ -64,3 +82,4 @@ https://youtu.be/g607Lzud3Ss

## Alpha Release
https://youtu.be/jdsvigK7bPs

7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@
android:name=".DeadRabbitActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_fullscreen"
android:theme="@style/FullscreenTheme"></activity>
android:theme="@style/FullscreenTheme" />

<receiver
android:name=".HabitCheckReciever"
android:enabled="true"
android:exported="true" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void onClick(View view) {
public void onClick(View v) {
//start new activity
startActivity(new Intent(AddHabitActivity.this, HabitListActivity.class));
finish();
}
});
}
Expand All @@ -85,12 +86,11 @@ private void addHabitRequest() {
final String reminder = mRemider.isChecked()?"1":"0";

// send add new habit request
RequestQueue queue = Volley.newRequestQueue(this);
RequestQueue queue = VolleySingleton.getInstance(this).getRequestQueue(this);
final String add_habit_url = "https://habit-rabbit.000webhostapp.com/add_habit.php";


// request server to add this habit to database
StringRequest loginReq = new StringRequest(Request.Method.POST, add_habit_url,
StringRequest addHabitReq = new StringRequest(Request.Method.POST, add_habit_url,
new Response.Listener<String>(){
@Override
public void onResponse(String response) {
Expand All @@ -110,8 +110,9 @@ public void onResponse(String response) {
//TODO: notify adapter

// jump to habit list page
startActivity(new Intent(AddHabitActivity.this, HabitListActivity.class));
// startActivity(new Intent(AddHabitActivity.this, HabitListActivity.class));
finish();
HabitListActivity.adapter.notifyItemInserted(HabitList.HABITS_list.size() - 1);
} else {
// show message when fails
AlertDialog.Builder builder = new AlertDialog.Builder(AddHabitActivity.this);
Expand Down Expand Up @@ -163,6 +164,6 @@ protected Map<String, String> getParams() {
}
};

queue.add(loginReq);
queue.add(addHabitReq);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
Expand Down Expand Up @@ -128,9 +130,26 @@ void bind(Habit event){
// listener
itemView.setOnLongClickListener(v -> {
Context context = v.getContext();
Intent intent = new Intent(context, HabitDetailActivity.class);
intent.putExtra(HabitDetailFragment.ARG_ITEM_ID, event.getHabitID()+"");
context.startActivity(intent);
PopupMenu popupMenu = new PopupMenu(context, itemView);
popupMenu.inflate(R.menu.agenda_popup_menu);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.detail:
Intent intent = new Intent(context, HabitDetailActivity.class);
intent.putExtra(HabitDetailFragment.ARG_ITEM_ID, event.getHabitID()+"");
context.startActivity(intent);
break;
case R.id.check:
addRecordRequest(event);
break;
}
return false;
}
});
popupMenu.show();

return true;
});
}
Expand All @@ -149,7 +168,7 @@ private void addRecordRequest(Habit habit) {
final String date = dateFormat.format(currentDate);
Context context = itemView.getContext();
// send delete habit request
RequestQueue queue = Volley.newRequestQueue(context);
RequestQueue queue = VolleySingleton.getInstance(context).getRequestQueue(context);
final String add_record_url = "https://habit-rabbit.000webhostapp.com/add_record.php";

// request server to add this habit to database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {

case Menu.FIRST:
startActivity(new Intent(CalendarActivity.this, LoginActivity.class));
break;
case R.id.nav_Profile:
startActivity(new Intent(CalendarActivity.this, ProfileActivity.class));
break;
Expand All @@ -53,7 +50,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
File file= new File(this.getFilesDir().getParent()+"/shared_prefs/"+fileName+".xml");
file.delete();

startActivity(new Intent(CalendarActivity.this, LoginActivity.class));
Intent intent = new Intent(this, LoginActivity.class);
intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_CLEAR_TOP | intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}catch(Exception e){}
break;
case R.id.nav_habits:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package comjianzhaojohnhabit_rabbit.httpsgithub.habit_rabbit;

import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Hashtable;


public class HabitCheckReciever extends BroadcastReceiver {
private static boolean timerOn = false;
private static SharedPreferences sharedPref;
private static SharedPreferences.Editor editor;
private static Context shared_context;
private static PendingIntent pendingIntent;
private static NotificationHelper notificationHelper;

@Override
public void onReceive(Context context, Intent intent) {
Log.d("alarm", "reciever");
checkHabits();
}

public static boolean isTimerOn() { return timerOn; }
public void setTimerOn(){timerOn = true; }

public static void setShared_context(Context context){
shared_context = context;
sharedPref = shared_context.getSharedPreferences("UserInfo", Context.MODE_PRIVATE);
editor = sharedPref.edit();
notificationHelper = new NotificationHelper(shared_context);
}


public static boolean rabbitIsAlive() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
int complete = 0;
Calendar today = Calendar.getInstance();
if (HabitList.HABITS_list != null) {
for (Habit x : HabitList.HABITS_list) {
Hashtable<String, Integer> rc = x.getRecords();
String period = x.getPeriod();
Calendar startDate = Calendar.getInstance();
startDate.clear();
startDate.setTime(x.getStartDate());
if (period.equals("week") && today.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
Calendar yesterday = Calendar.getInstance();
if (startDate.get(Calendar.YEAR) == yesterday.get(Calendar.YEAR) &&
startDate.get(Calendar.WEEK_OF_YEAR) == yesterday.get(Calendar.WEEK_OF_YEAR))
break;
yesterday.add(Calendar.DATE, -8);
yesterday.set(Calendar.DAY_OF_WEEK, 1);
for (int i = 0; i < 7; i++) {
String dateString = dateFormat.format(yesterday.getTime());
if (rc.contains(dateString)) {
complete += rc.get(dateString);
}
yesterday.add(Calendar.DATE, 1);
}
} else if (period.equals("month") && today.get(Calendar.DAY_OF_MONTH) == 1) {
Calendar yesterday = Calendar.getInstance();
if (startDate.get(Calendar.YEAR) == yesterday.get(Calendar.YEAR) &&
startDate.get(Calendar.MONTH) == yesterday.get(Calendar.MONTH))
break;
yesterday.add(Calendar.MONTH, -1);
yesterday.set(Calendar.DAY_OF_MONTH, 1);
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.setTime(yesterday.getTime());
for (calendar.setTime(yesterday.getTime()); calendar.get(Calendar.MONTH) == yesterday.get(Calendar.MONTH); calendar.add(Calendar.DATE, 1)) {
String dateString = dateFormat.format(calendar.getTime());
if (rc.contains(dateString)) {
complete += rc.get(dateString);
}
yesterday.add(Calendar.DATE, 1);
}
} else {
Calendar yesterday = Calendar.getInstance();
if (startDate.get(Calendar.DATE) == yesterday.get(Calendar.DATE))
break;
yesterday.add(Calendar.DATE, -1);
String dateString = dateFormat.format(yesterday.getTime());
if (rc.contains(dateString)) {
complete = rc.get(dateString);
}
}
if (complete < x.getTimesPerPeriod()) {
return false;
}
}

return true;
}
return true;
}



public static void checkHabits(){
editor.putInt("DayOfYear",Calendar.getInstance().get(Calendar.DAY_OF_YEAR));
editor.apply();

boolean rabbitAlive = rabbitIsAlive();
Log.d("alarm","checking rabbit state");
String notificationMessage;
if (!rabbitAlive){
notificationMessage = "MURDERER. Because you failed to complete your habits for today, your rabbit is going to die. His blood is on your hands!";
}
else {
notificationMessage = "You done good";
}
notificationHelper.sendNotification(notificationMessage);

editor.putBoolean("RabbitAlive",rabbitAlive);
editor.apply();
//TODO send to notification helper

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void editHabitRequest() {
final String reminder = mReminder.isChecked()?"1":"0";

// send edit habit request
RequestQueue queue = Volley.newRequestQueue(this);
RequestQueue queue = VolleySingleton.getInstance(this).getRequestQueue(this);
final String add_habit_url = "https://habit-rabbit.000webhostapp.com/edit_habit.php";

// request server to add this habit to database
Expand Down
Loading

0 comments on commit 660d367

Please sign in to comment.