diff --git a/Final report Images/Room architecture.png b/Final report Images/Room architecture.png
new file mode 100644
index 00000000..cdf526d5
Binary files /dev/null and b/Final report Images/Room architecture.png differ
diff --git a/Final report Images/badge_room_old.gif b/Final report Images/badge_room_old.gif
new file mode 100644
index 00000000..4e85922a
Binary files /dev/null and b/Final report Images/badge_room_old.gif differ
diff --git a/Final report Images/badge_screen_notification.gif b/Final report Images/badge_screen_notification.gif
new file mode 100644
index 00000000..d6b8dd4c
Binary files /dev/null and b/Final report Images/badge_screen_notification.gif differ
diff --git a/Final report Images/banner.png b/Final report Images/banner.png
new file mode 100644
index 00000000..e32c5ce0
Binary files /dev/null and b/Final report Images/banner.png differ
diff --git a/Final report Images/edit_user_profile.gif b/Final report Images/edit_user_profile.gif
new file mode 100644
index 00000000..22c7face
Binary files /dev/null and b/Final report Images/edit_user_profile.gif differ
diff --git a/Final report Images/games_old.gif b/Final report Images/games_old.gif
new file mode 100644
index 00000000..35bdc27a
Binary files /dev/null and b/Final report Images/games_old.gif differ
diff --git a/Final report Images/home_old.gif b/Final report Images/home_old.gif
new file mode 100644
index 00000000..d7ec8303
Binary files /dev/null and b/Final report Images/home_old.gif differ
diff --git a/Final report Images/home_screen_analysis.gif b/Final report Images/home_screen_analysis.gif
new file mode 100644
index 00000000..cf473ece
Binary files /dev/null and b/Final report Images/home_screen_analysis.gif differ
diff --git a/Final report Images/medicineStore_old.gif b/Final report Images/medicineStore_old.gif
new file mode 100644
index 00000000..a98491c3
Binary files /dev/null and b/Final report Images/medicineStore_old.gif differ
diff --git a/Final report Images/medicine_store_warning.gif b/Final report Images/medicine_store_warning.gif
new file mode 100644
index 00000000..201f6082
Binary files /dev/null and b/Final report Images/medicine_store_warning.gif differ
diff --git a/Final report Images/merged powerup work.gif b/Final report Images/merged powerup work.gif
new file mode 100644
index 00000000..23c7e630
Binary files /dev/null and b/Final report Images/merged powerup work.gif differ
diff --git a/Final report Images/old_apk_overdraw.gif b/Final report Images/old_apk_overdraw.gif
new file mode 100644
index 00000000..6ee29004
Binary files /dev/null and b/Final report Images/old_apk_overdraw.gif differ
diff --git a/Final report Images/over_new_apk.gif b/Final report Images/over_new_apk.gif
new file mode 100644
index 00000000..06457bdd
Binary files /dev/null and b/Final report Images/over_new_apk.gif differ
diff --git a/Final report Images/performanceGifUpdated.gif b/Final report Images/performanceGifUpdated.gif
new file mode 100644
index 00000000..40a0085f
Binary files /dev/null and b/Final report Images/performanceGifUpdated.gif differ
diff --git a/Final report Images/performanceOldapk.gif b/Final report Images/performanceOldapk.gif
new file mode 100644
index 00000000..2acd2328
Binary files /dev/null and b/Final report Images/performanceOldapk.gif differ
diff --git a/Final report Images/play_games.gif b/Final report Images/play_games.gif
new file mode 100644
index 00000000..5c285ed6
Binary files /dev/null and b/Final report Images/play_games.gif differ
diff --git a/Final report Images/report.md b/Final report Images/report.md
new file mode 100644
index 00000000..8d07a67e
--- /dev/null
+++ b/Final report Images/report.md
@@ -0,0 +1,162 @@
+# Infrastructure Android - GSoC'18 Final Report
+
+
+I, Anamika Tripathi, proposed to work for [Google Summer of Code](https://summerofcode.withgoogle.com/) 2018 edition
+ with [Systers Open Source](https://github.com/systers) for Infrastructure/automation of community's Android projects.
+
+## Purpose
+* Maintain consistency in Android projects throughout the community
+* Follow Android standard android guidelines
+* Improve Android performance (Memory leak, overdraw, cpu usage, etc)
+* Improve User Interface
+* Improve User Experience
+
+
+You can checkout about the final presentation [here](https://docs.google.com/presentation/d/1C4k81wwxbFU2T5v290TeWAMDeVRYNw7sGYpsaC2OLBE/edit#slide=id.g402636dd07_0_214)
+
+## Work Done
+During the GSoC period, I have worked on two Android repositories:
+* [PowerUp Android](http://github.com/systers/powerup-android/)
+* [Malaria Android](http://github.com/systers/malaria-app-android/)
+
+## Phase I
+
+I worked mainly on shifting sqlite database to use Room Library - an architecture component.
+During the shifting database, I searched various ways to handle background threads in android.
+I and my mentors agreed upon using Executors to handle Room queries in background.
+After implementing repository pattern for PowerUp-Android database(sqlite and preferences),
+I have replaced all usages of old sqlite database to Room queries.
+For handling callbacks easily, I shifted all existing activities(with db usages) to Model-View-Presenter architecture.
+
+### Accomplishments
+* Completed shifting Sqlite db to use Room library
+* Drafted a document for Android standard guidelines
+* Replaced old database handler functions with Room's queries
+* Removed redundant code, used Model-View-Presenter architecture for various activities
+* Implemented Repository pattern for database usage (Room for sqlite + preferences)
+* Added comments in repository for better understanding
+
+### Demo
+
+
+### Links
+Click [here](https://github.com/systers/powerup-android/search?q=is%3Apr+author%3Ageekanamika+created%3A2018-05-14..2018-08-14&unscoped_q=is%3Apr+author%3Ageekanamika+created%3A2018-05-14..2018-08-14&type=Issues)
+to see PRs during GSoC period for PowerUp-Android
+
+Click [here](https://github.com/systers/powerup-android/search?q=is%3Aissue+involves%3Ageekanamika+created%3A2018-05-14..2018-08-14&unscoped_q=is%3Aissue+involves%3Ageekanamika+created%3A2018-05-14..2018-08-14&type=Issues)
+to see issues created during GSoC period for PowerUp-Android
+
+
+## Phase II + Phase III
+
+I started with implementing repository pattern for project. For sqlite database, I shifted it to Room Library.
+Later on, I've shifted all preference usage in application to one file inside data directory.
+In next step, I started with shifting project to Model-View-Presenter architecture. Along with MVP implementation,
+I have followed Material Design guidelines for user interface. In last phase, I've also measured application's performance, made relevant changes to improve performance.
+
+### Accomplishments
+* Completed shifting sqlite db to use Room library
+* Implemented Repository pattern for database usage(Room for sqlite + preferences)
+* Shifted project to follow MVP architecture
+* Created new layouts, improved many layouts to follow material design guidelines
+* Measured, improved application performance(Memory, cpu, overdraw)
+
+###Demo
+
+### Demo + UI Comparison
+
+**User Profile**
+- Allow user to add name, email, age, medicine
+- If already submitted, provide edit option with auto-fill from preference data
+
+
+
+
+
+
+
+
+
+
+### Performance Comparison
+**Memory usage**
+
+New apk - memory usage
+
+
+Old apk - memormy usage
+
+
+**Overdraw**
+
+
+### Links
+Click [here](https://github.com/systers/malaria-app-android/search?q=is%3Aissue+involves%3Ageekanamika+created%3A2018-05-14..2018-08-14&type=Issues)
+to see issues during GSoC period for Malaria-Android
+
+Click [here](https://github.com/systers/malaria-app-android/search?p=1&q=is%3Apr+involves%3Ageekanamika+created%3A2018-05-14..2018-08-14&type=Issues&unscoped_q=is%3Apr+involves%3Ageekanamika+created%3A2018-05-14..2018-08-14)
+to see PRs created during GSoC period for Malaria-Android
+
+## Technical Aspects
+- [Butterknife library]( http://jakewharton.github.io/butterknife/) to reduce the boilerplate code and make it more structured
+- Constraint Layouts to develop flexible layouts and reduce overdraw
+- TimeLine view to display User's data analysis in malaria-android
+- TapTargetViewer to provide feature detection in malaria-android games
+- Room Library to reduce boiler plate code, compile time verification
+- Repository pattern for easy database access
+- Material design suggested diff types of dialogs, bottom navigation, fonts, colors, styles
+
+## Challenges
+- Research for Android best practices for every implementation
+- git merge conflicts
+- Collaboration with two GSoC student (Due to two android projects)
+- Working in background thread for Database, Callbacks
+- Working Remotely (Primary Mentor in PST, Admin in ET )
+- Codacy errors
+
+
+## Future Developements
+**PowerUp-Android**
+
+- Improve mini-games to follow MVP infrastructure
+- Shift Session History to preferences
+- Improve performance (remove overdraw, reduce existing boilerplate code, etc)
+
+**Malaria-android**
+- Add animation within fragments and activities
+- Write Unit tests
+- Add feature: create Setting screen instead of resetting database by dialog
+- Add feature: show list of Trips created, allow users to delete particular trip details
+- Create layouts for larger devices/landscape version
+
+
+## Take Away
+- Learnt Android best practices (MVP, Repository pattern, etc)
+- Used Libraries: Room, Butterknife, Constraint layout, TimelineView, TapTargetViewer etc
+- Worked as a developer who worries about application performance
+- Researched in material design guidelines
+- Used Receiver, Services, Alarm manager
+- Project documentation
+- Improved blogging skills (7/13 blogs published in different publications)
+- Improved Soft skills: telephonic conversation, project presentation, time management, etc
+- Remote working experience
+
+## Important Links
+- [Project Documentation](https://drive.google.com/open?id=1CDMo5UDnyAVoBVvAky9qasYuiacuUj_2jyM2JlJX0lA)
+- [Final Demo youtube live](https://www.youtube.com/watch?v=HZUwu-GiDIc&list=PLhVJyXjT75i_T-F70O0DGfz_Fu9aBpnI6&index=3&t=2s)
+- [Final Demo powerpoint presentation](https://docs.google.com/presentation/d/1C4k81wwxbFU2T5v290TeWAMDeVRYNw7sGYpsaC2OLBE/edit?usp=sharing)
+- [Full application video](https://drive.google.com/open?id=141ZAorloucZSJ9A7xkp_9xse7WCI7UmJ)
+
+## Team
+**Student:**
+- [Anamika Tripathi](https://github.com/geekanamika)
+
+**Mentors:**
+- [Manju](https://github.com/manjumegh) - All phases
+- [Nikita](https://github.com/m-murad) - All phases
+- [Manisha](https://github.com/manishakeim) - First phase
+
+**Admin:**
+ - [May](https://github.com/ExactlyMay) - All phases
\ No newline at end of file
diff --git a/Final report Images/trip_old.gif b/Final report Images/trip_old.gif
new file mode 100644
index 00000000..5e63e6a2
Binary files /dev/null and b/Final report Images/trip_old.gif differ
diff --git a/Final report Images/trip_screen.gif b/Final report Images/trip_screen.gif
new file mode 100644
index 00000000..11e0cd2c
Binary files /dev/null and b/Final report Images/trip_screen.gif differ
diff --git a/Final report Images/user_profile_old.gif b/Final report Images/user_profile_old.gif
new file mode 100644
index 00000000..65a22a55
Binary files /dev/null and b/Final report Images/user_profile_old.gif differ
diff --git a/build.gradle b/build.gradle
index f35bbd74..348a2e75 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,6 +1,5 @@
buildscript {
repositories {
- mavenCentral()
jcenter()
google()
}
@@ -12,8 +11,8 @@ buildscript {
allprojects {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
- mavenCentral()
google()
+ jcenter()
}
}
diff --git a/malaria-app-android/build.gradle b/malaria-app-android/build.gradle
index 8dfe3603..c881da32 100644
--- a/malaria-app-android/build.gradle
+++ b/malaria-app-android/build.gradle
@@ -31,7 +31,8 @@ android {
}
dependencies {
- implementation "com.android.support:support-v4:$rootProject.ext.supportLibraryVersion" // v4
+ implementation "com.android.support:support-v4:$rootProject.ext.supportLibraryVersion"
+ // v4
implementation "com.viewpagerindicator:library:$rootProject.ext.viewPagerIndicatorVersion"
implementation "com.android.support:design:$rootProject.ext.supportLibraryVersion"
implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
@@ -40,6 +41,8 @@ dependencies {
implementation files('libs/GraphView-3.1.2.jar')
implementation 'com.android.support:support-v4:26.1.0'
testImplementation 'junit:junit:4.12'
+ compile 'com.github.vipulasri:timelineview:1.0.6'
+ implementation 'com.getkeepsafe.taptargetview:taptargetview:1.12.0'
//Room
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
diff --git a/malaria-app-android/src/main/AndroidManifest.xml b/malaria-app-android/src/main/AndroidManifest.xml
index 2c537c40..09bc2b48 100644
--- a/malaria-app-android/src/main/AndroidManifest.xml
+++ b/malaria-app-android/src/main/AndroidManifest.xml
@@ -13,21 +13,21 @@
-
+
-
+
@@ -55,8 +55,13 @@
+
+
+
+
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/activities/DayFragmentActivity.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/activities/DayFragmentActivity.java
index fa6bbdfd..7d361ba3 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/activities/DayFragmentActivity.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/activities/DayFragmentActivity.java
@@ -354,7 +354,6 @@ public long checkDrugTakenTimeInterval(String time,long day_time) {
calt.add(Calendar.MONTH, 2);
Date start = calt.getTime();
Date end = cal.getTime();
- //Todo idk what key it is, check later
SharedPreferenceStore.mEditor.putLong("com.peacecorps.malaria."
+ time, takenDate).apply();
if (SharedPreferenceStore.mPrefsStore.getBoolean("com.peacecorps.malaria.isWeekly", false)) {
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/adapter/FragmentAdapter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/adapter/FragmentAdapter.java
deleted file mode 100755
index a6affaca..00000000
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/adapter/FragmentAdapter.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.peacecorps.malaria.code.adapter;
-
-import com.peacecorps.malaria.code.fragment.HomeScreenFragment;
-import com.peacecorps.malaria.code.fragment.SecondAnalyticFragment;
-import com.peacecorps.malaria.code.fragment.FirstAnalyticFragment;
-import com.viewpagerindicator.IconPagerAdapter;
-
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
-import android.support.v4.app.FragmentStatePagerAdapter;
-
-/**Usd for creating sliding Fragment Screen after the the Home Screen**/
-
-public class FragmentAdapter extends FragmentStatePagerAdapter implements
- IconPagerAdapter {
-
- public FragmentAdapter(FragmentManager fm) {
- super(fm);
-
- }
-
- @Override
- public int getIconResId(int index) {
-
- return 0;
- }
-
- @Override
- public Fragment getItem(int position) {
- //Deciding the fragment on the basis of position no.
- Fragment fragment = new HomeScreenFragment();
- switch (position) {
- case 0:
- fragment = new HomeScreenFragment();
- break;
- case 1:
- fragment = new FirstAnalyticFragment();
- break;
-
- case 2:
- fragment = new SecondAnalyticFragment();
- break;
-
- }
- return fragment;
- }
-
- @Override
- public int getCount() {
- //total no. of fragments
- return 3;
- }
-
- @Override
- public int getItemPosition(Object object) {
- return POSITION_NONE;
- }
-
-}
\ No newline at end of file
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/FirstAnalyticFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/FirstAnalyticFragment.java
deleted file mode 100755
index 96f0c464..00000000
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/FirstAnalyticFragment.java
+++ /dev/null
@@ -1,252 +0,0 @@
-package com.peacecorps.malaria.code.fragment;
-
-import android.app.Dialog;
-import android.content.Context;
-import android.content.Intent;
-import android.graphics.Typeface;
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Button;
-import android.widget.TextView;
-
-import com.peacecorps.malaria.R;
-import com.peacecorps.malaria.code.model.SharedPreferenceStore;
-import com.peacecorps.malaria.ui.user_medicine_setting.MedicineSettingsActivity;
-import com.peacecorps.malaria.db.DatabaseSQLiteHelper;
-import com.peacecorps.malaria.utils.CalendarFunction;
-
-import java.util.Calendar;
-import java.util.Date;
-
-
-public class FirstAnalyticFragment extends Fragment {
-
-
- private static SharedPreferenceStore mSharedPreferenceStore;
- private static View rootView;
- public static TextView checkMediLastTakenTime = null;
- public static TextView doses = null;
- public static TextView adherence = null;
- private Button mSettingsButton;
- private String TAGFAF = "FirstAnalyticFragment";
- private Dialog dialog = null;
-
-
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- rootView = inflater
- .inflate(R.layout.fragment_first_analytic_screen, null);
-
- //declaring views
- mSettingsButton = (Button) rootView.findViewById(R.id.fragment_first_screen_settings_button);
- checkMediLastTakenTime = (TextView) rootView.findViewById(R.id.checkMediLastTakenTime);
- doses = (TextView) rootView.findViewById(R.id.doses);
- adherence = (TextView) rootView.findViewById(R.id.adherence);
- updateUI();
- TextView mlt = (TextView) rootView.findViewById(R.id.mlt);
- TextView dinr = (TextView) rootView.findViewById(R.id.dinr);
- TextView atm = (TextView) rootView.findViewById(R.id.atm);
- //setting fonts
- Typeface cf = Typeface.createFromAsset(getActivity().getAssets(), "fonts/garreg.ttf");
- mlt.setTypeface(cf);
- dinr.setTypeface(cf);
- atm.setTypeface(cf);
-
- return rootView;
-
- }
-
- @Override
- public void onResume(){
- updateUI();
- super.onResume();
-
- }
-
- public void updateUI(){
-
- //calling functions
- updateMediLastTime();
- Log.d(TAGFAF,"AFTER CHK MEDI LAST TIME");
- if (checkMediLastTakenTime != null)
- updateDoses();
- Log.d(TAGFAF, "AFTER UPDATE DOSES");
- updateAdherence();
- Log.d(TAGFAF, "AFTER UPDATE ADHERENCE");
- getSharedPreferences();
- Log.d(TAGFAF, "AFTER SHARED PREFS");
- addButtonListeners();
- Log.d(TAGFAF, "AFTER BUTTON LISTENERS");
- }
-
-
- public void addButtonListeners() {
- mSettingsButton.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
-
- addDialog();
-
- }
- });
- }
-
- public void getSharedPreferences() {
-
- mSharedPreferenceStore.mPrefsStore = getActivity()
- .getSharedPreferences("com.peacecorps.malaria.storeTimePicked",
- Context.MODE_PRIVATE);
- mSharedPreferenceStore.mEditor = mSharedPreferenceStore.mPrefsStore
- .edit();
- }
-
-
- public long checkDrugTakenTimeInterval(String time) {
- //finding the interval of time between today and the 'time'
- long interval = 0;
- long today = new Date().getTime();
- Date tdy= Calendar.getInstance().getTime();
- tdy.setTime(today);
- DatabaseSQLiteHelper sqLite= new DatabaseSQLiteHelper(getActivity());
- long takenDate= sqLite.getFirstTime();
- if(time.compareTo("firstRunTime")==0) {
- if(takenDate!=0) {
- Log.d(TAGFAF, "First Run Time at FAF->" + takenDate);
- Calendar cal=Calendar.getInstance();
- cal.setTimeInMillis(takenDate);
- cal.add(Calendar.MONTH, 1);
- Date start=cal.getTime();
- int weekDay=cal.get(Calendar.DAY_OF_WEEK);
- //calaculating no. of weekdays for weekly drug
- if(SharedPreferenceStore.mPrefsStore.getBoolean("com.peacecorps.malaria.isWeekly",false))
- interval= CalendarFunction.getIntervalWeekly(start,tdy,weekDay);
- else
- interval=CalendarFunction.getIntervalDaily(start,tdy);
- //^for daily drug only the no. of days
- SharedPreferenceStore.mEditor.putLong("com.peacecorps.malaria."
- + time, takenDate).apply();
- return interval;
- }
- else
- return 1;
- }
- else {
- takenDate=SharedPreferenceStore.mPrefsStore.getLong("com.peacecorps.malaria."
- + time, takenDate);
- long oneDay = 1000 * 60 * 60 * 24;
- interval = (today - takenDate) / oneDay;
- return interval;
- }
- }
-
- public void updateAdherence(){
-
- /**Calculating Adherence**/
- long interval = checkDrugTakenTimeInterval("firstRunTime");
- DatabaseSQLiteHelper sqLite = new DatabaseSQLiteHelper(getActivity());
- long takenCount = sqLite.getCountTaken();
- double adherenceRate;
- Log.d(TAGFAF,"taken Count:"+takenCount);
- if(interval!=1)
- adherenceRate = ((double)takenCount / (double)interval) * 100;
- else
- adherenceRate = 100;
-
- String ar = String.format("%.2f %%", adherenceRate);
- Log.d(TAGFAF,"Adherence Rate:"+ar);
- //adherence.setText(ar);
-
- }
-
- public void updateDoses()
- {
- /*Updating Doses in a Row for Weekly and Daily Pill Seperately*/
- DatabaseSQLiteHelper sqLite = new DatabaseSQLiteHelper(getActivity());
- Log.d(TAGFAF, "INSIDE updateDoses");
- if(mSharedPreferenceStore.mPrefsStore.getBoolean("com.peacecorps.malaria.isWeekly",false)) {
- int d = sqLite.getDosesInaRowWeekly();
- mSharedPreferenceStore.mEditor.putInt("com.peacecorps.malaria.weeklyDose", d).apply();
- doses.setText("" + d/*mSharedPreferenceStore.mPrefsStore.getInt("com.peacecorps.malaria.weeklyDose", 0)*/);
- }
- else
- {
- int d = sqLite.getDosesInaRowDaily();
- mSharedPreferenceStore.mEditor.putInt("com.peacecorps.malaria.dailyDose",d).apply();
- doses.setText("" + mSharedPreferenceStore.mPrefsStore.getInt("com.peacecorps.malaria.dailyDose", 0));
- }
- }
-
- public void updateMediLastTime() {
- /*Updating the most recent time medication was taken*/
- /* if (checkMediLastTakenTime != null) {
- checkMediLastTakenTime.setText(mSharedPreferenceStore.mPrefsStore.getString("com.peacecorps.malaria.checkMediLastTakenTime", "").toString());
- }*/
- DatabaseSQLiteHelper sqLite = new DatabaseSQLiteHelper(getActivity());
- String lastTaken= sqLite.getLastTaken();
- checkMediLastTakenTime.setText(lastTaken);
- }
-
- public void addDialog()
- { /*Opens the Reset Dialog*/
- dialog = new Dialog(this.getActivity(),android.R.style.Theme_DeviceDefault_Dialog_NoActionBar);
- dialog.setContentView(R.layout.resetdata_dialog);
- dialog.setTitle("Reset Data");
-
- //final RadioGroup btnRadGroup = (RadioGroup) dialog.findViewById(R.id.radioGroupReset);
- Button btnOK = (Button) dialog.findViewById(R.id.btn_dialog_reset_okay);
-
- btnOK.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-
- /* // get selected radio button from radioGroup
- int selectedId = btnRadGroup.getCheckedRadioButtonId();
-
- // find the radiobutton by returned id
- RadioButton btnRadButton = (RadioButton) dialog.findViewById(selectedId);
-
- String ch = btnRadButton.getText().toString();
-
- if(ch.equalsIgnoreCase("yes"))
- { //if yes, reset the database
- DatabaseSQLiteHelper sqLite = new DatabaseSQLiteHelper(getActivity());
- sqLite.resetDatabase();
- mSharedPreferenceStore.mEditor.clear().commit();
- startActivity(new Intent(getActivity(),
- MedicineSettingsActivity.class));
- getActivity().finish();
- }
- else
- {
- dialog.dismiss();
- }*/
-
- DatabaseSQLiteHelper sqLite = new DatabaseSQLiteHelper(getActivity());
- sqLite.resetDatabase();
- mSharedPreferenceStore.mEditor.clear().commit();
- startActivity(new Intent(getActivity(),
- MedicineSettingsActivity.class));
- getActivity().finish();
-
- }
-
- });
-
- Button btnCancel = (Button) dialog.findViewById(R.id.btn_dialog_reset_cancel);
- btnCancel.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- dialog.dismiss();
- }
- });
- dialog.show();
-
- }
-
-}
-
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/HomeScreenFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/HomeScreenFragment.java
deleted file mode 100755
index 68aa53e4..00000000
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/HomeScreenFragment.java
+++ /dev/null
@@ -1,537 +0,0 @@
-package com.peacecorps.malaria.code.fragment;
-
-import android.app.Dialog;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.graphics.Color;
-import android.graphics.Typeface;
-import android.media.MediaPlayer;
-import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.support.v4.app.Fragment;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Button;
-import android.widget.TextView;
-
-import com.peacecorps.malaria.R;
-import com.peacecorps.malaria.code.activities.RemainderToneActivity;
-import com.peacecorps.malaria.code.model.SharedPreferenceStore;
-import com.peacecorps.malaria.db.DatabaseSQLiteHelper;
-import com.peacecorps.malaria.services.AlarmService;
-import com.peacecorps.malaria.ui.user_medicine_setting.MedicineSettingsActivity;
-import com.peacecorps.malaria.utils.CalendarFunction;
-import com.peacecorps.malaria.utils.ToastLogSnackBarUtil;
-
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-
-//Todo many preferences usage, need to look it in detail and then create function inside pref_file, skipped for now.
-public class HomeScreenFragment extends Fragment {
-
- private Button mAcceptMedicationButton;
- private Button mRejectMedicationButton;
- private Button mSettingsButton;
- private Button mRemainderToneButton;
- private TextView mCurrentDateLabel;
- private TextView mCurrentDayOfweekLabel;
- private static CharSequence mGetCurrentDate;
- private static int mDrugAcceptedCount;
- private static int drugRejectedCount;
- private Calendar mCalendar;
- private String[] mPossibledays = {"Sunday", "Monday", "Tuesday",
- "Wednesday", "Thursday", "Friday", "Saturday"};
- private static View rootView;
- private static String TAGHSF = "HomeScreenFragment";
- private SharedPreferences sharedPreferences;
-
- private int checkDay = -1;
-
- private static SharedPreferenceStore mSharedPreferenceStore;
- private Dialog dialog = null;
-
-
- @Override
- public void onResume() {
-
- super.onResume();
- updateUI();
-
- }
-
- public void getSharedPreferences() {
-
- mSharedPreferenceStore.mPrefsStore = getActivity()
- .getSharedPreferences("com.peacecorps.malaria.storeTimePicked",
- Context.MODE_PRIVATE);
- mSharedPreferenceStore.mEditor = mSharedPreferenceStore.mPrefsStore
- .edit();
- }
-
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- rootView = inflater.inflate(R.layout.fragment_home_screen, null);
-
- updateUI();
- return rootView;
-
- }
-
- public double computeAdherenceRate() {
- long interval = checkDrugTakenTimeInterval("firstRunTime");
- DatabaseSQLiteHelper sqLite = new DatabaseSQLiteHelper(this.getActivity());
- long takenCount = sqLite.getCountTaken();
- double adherenceRate = ((double)takenCount / (double)interval) * 100;
- Log.d(TAGHSF, "adherence:" + adherenceRate);
- return adherenceRate;
- }
-
- public void addButtonListeners() {
- mSettingsButton.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
-
- addDialog();
-
- }
- });
-
- mRemainderToneButton.setOnClickListener(new View.OnClickListener(){
-
- @Override
- public void onClick(View v) {
-
- Intent myIntent = new Intent(getActivity(), RemainderToneActivity.class);
- startActivity(myIntent);
-
- }
- });
- mAcceptMedicationButton.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- MediaPlayer.create(getActivity(), R.raw.accept_button_sound)
- .start();
- mDrugAcceptedCount += 1;
- int value = SharedPreferenceStore.mPrefsStore.getInt(
- "com.peacecorps.malaria.AcceptedCount", 0) + 1;
- SharedPreferenceStore.mEditor.putInt("com.peacecorps.malaria.AcceptedCount",
- value).commit();
- if (mSharedPreferenceStore.mPrefsStore.getBoolean(
- "com.peacecorps.malaria.isWeekly", false)) {
-
- decideDrugTakenUIBoolean(true, true);
- DatabaseSQLiteHelper databaseSQLiteHelper = new DatabaseSQLiteHelper(getActivity());
- databaseSQLiteHelper.getUserMedicationSelection(getActivity(), "weekly", Calendar.getInstance().getTime(), "yes", computeAdherenceRate());
-
- int currentDose = databaseSQLiteHelper.getDosesInaRowWeekly();
- mSharedPreferenceStore.mEditor.putInt("com.peacecorps.malaria.weeklyDose", currentDose).commit();
-
- } else {
- decideDrugTakenUIBoolean(false, true);
-
- DatabaseSQLiteHelper databaseSQLiteHelper = new DatabaseSQLiteHelper(getActivity());
- databaseSQLiteHelper.getUserMedicationSelection(getActivity(), "daily", Calendar.getInstance().getTime(), "yes", computeAdherenceRate());
-
- int currentDose = databaseSQLiteHelper.getDosesInaRowDaily();
- mSharedPreferenceStore.mEditor.putInt("com.peacecorps.malaria.dailyDose", currentDose).commit();
- }
- //get user's score
- int score=sharedPreferences.getInt("userScore", 0);
- //get medicine in store
- int medicineStore=sharedPreferences.getInt("medicineStore",0);
- SharedPreferences.Editor editor=sharedPreferences.edit();
- //increase score if medicine is taken
- editor.putInt("userScore",score+1);
- //decrease medicine store by one if medicine is taken
- editor.putInt("medicineStore",medicineStore-1);
- editor.commit();
- Log.d("check","score updated");
- }
- });
-
- mRejectMedicationButton.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- MediaPlayer.create(getActivity(), R.raw.reject_button_sound)
- .start();
- drugRejectedCount += 1;
- if (mSharedPreferenceStore.mPrefsStore.getBoolean(
- "com.peacecorps.malaria.isWeekly", false)) {
- decideDrugTakenUIBoolean(true, false);
- DatabaseSQLiteHelper databaseSQLiteHelper = new DatabaseSQLiteHelper(getActivity());
- databaseSQLiteHelper.getUserMedicationSelection(getActivity(), "weekly", Calendar.getInstance().getTime(), "no", computeAdherenceRate());
-
- } else {
- decideDrugTakenUIBoolean(false, false);
- DatabaseSQLiteHelper databaseSQLiteHelper = new DatabaseSQLiteHelper(getActivity());
- databaseSQLiteHelper.getUserMedicationSelection(getActivity(), "daily", Calendar.getInstance().getTime(), "no", computeAdherenceRate());
-
- }
-
- }
- });
- }
-
- public void createView() {
-
- mAcceptMedicationButton = (Button) rootView
- .findViewById(R.id.btn_accept_medication);
- mRejectMedicationButton = (Button) rootView
- .findViewById(R.id.btn_reject_medication);
- mSettingsButton = (Button) rootView
- .findViewById(R.id.fragment_home_screen_settings_button);
- mRemainderToneButton=(Button) rootView
- .findViewById(R.id.fragment_home_screen_set_tone_button);
- mCurrentDateLabel = (TextView) rootView
- .findViewById(R.id.tv_current_date);
- mCurrentDayOfweekLabel = (TextView) rootView
- .findViewById(R.id.tv_day_of_week);
- //yatna
- TextView warningView = rootView
- .findViewById(R.id.warningView);
- sharedPreferences= PreferenceManager.getDefaultSharedPreferences(getActivity());
- //get the limit set by user from shared preference
- //Todo check it's usage later
- int alertTime=sharedPreferences.getInt("alertTime",-1);
- //display warning if medicine in store is less than the limit set
- if(alertTime!=-1 && sharedPreferences.getInt("medicineStore",0) 0) {
- if ((mSharedPreferenceStore.mPrefsStore.getBoolean(
- "com.peacecorps.malaria.isWeeklyDrugTaken", false))) {
- isDrugTakenUI();
- } else {
- missedWeekUI();
- newDayUI();
- }
- } else if (checkDrugTakenTimeInterval("weeklyDate") > 7) {
- SharedPreferenceStore.mEditor.putInt(
- "com.peacecorps.malaria.AcceptedCount", 0).commit();
- missedWeekUI();
- newDayUI();
- }
- }
- } else { //if drug is taken daily//
- if (checkDrugTakenTimeInterval("dateDrugTaken") == 0) {
- if (mSharedPreferenceStore.mPrefsStore.getBoolean(
- "com.peacecorps.malaria.isDrugTaken", false)) {
- isDrugTakenUI();
- } else {
-
- isDrugNotTakenUI();
- }
-
- } else {
-
- if (checkDrugTakenTimeInterval("dateDrugTaken") > 1) {
- mSharedPreferenceStore.mEditor.putInt("com.peacecorps.malaria.dailyDose", 0).apply();
- }
-
- newDayUI();
- }
- }
- }
-
- public long checkDrugTakenTimeInterval(String time) {
-
- long interval = 0;
- long today = new Date().getTime();
- DatabaseSQLiteHelper sqLite= new DatabaseSQLiteHelper(getActivity());
- long takenDate= sqLite.getFirstTime();
- if(time.compareTo("firstRunTime")==0) {
- if(takenDate!=0) {
- Log.d(TAGHSF, "First Run Time at FAF->" + takenDate);
- Calendar cal = Calendar.getInstance();
- cal.setTimeInMillis(takenDate);
- cal.add(Calendar.MONTH, 1);
- Log.d(TAGHSF,"CURRENT : "+cal.get(Calendar.MONTH));
- Date start= cal.getTime();
- Date end= Calendar.getInstance().getTime();
- end.setTime(today);
- SharedPreferenceStore.mEditor.putLong("com.peacecorps.malaria."
- + time, takenDate).apply();
- if(SharedPreferenceStore.mPrefsStore.getBoolean("com.peacecorps.malaria.isWeekly",false)) {
- interval = CalendarFunction.getIntervalWeekly(start,end,SharedPreferenceStore.mPrefsStore.getInt("com.peacecorps.malaria.weeklyDay",1));
- }
- else
- {
- interval = CalendarFunction.getIntervalDaily(start,end);
- }
-
- /*long oneDay = 1000 * 60 * 60 * 24;
- interval = (today - takenDate) / oneDay;*/
- return interval;
- }
- else
- return 1;
- }
- else {
- takenDate=SharedPreferenceStore.mPrefsStore.getLong("com.peacecorps.malaria."
- + time, takenDate);
- long oneDay = 1000 * 60 * 60 * 24;
- interval = (today - takenDate) / oneDay;
- return interval;
- }
- }
-
- public void newDayUI() {
- mAcceptMedicationButton
- .setBackgroundResource(R.drawable.accept_medi_checked_);
- mRejectMedicationButton
- .setBackgroundResource(R.drawable.reject_medi_checked);
- setButtonState(true);
-
- }
-
- public void isDrugNotTakenUI() {
- mAcceptMedicationButton
- .setBackgroundResource(R.drawable.accept_medi_grayscale);
- mRejectMedicationButton
- .setBackgroundResource(R.drawable.reject_medi_checked);
- setButtonState(false);
- }
-
- public void isDrugTakenUI() {
- mCurrentDateLabel.setTextColor(Color.rgb(89, 43, 21));
- mCurrentDayOfweekLabel.setTextColor(Color.rgb(89, 43, 21));
- mAcceptMedicationButton
- .setBackgroundResource(R.drawable.accept_medi_checked_);
- mRejectMedicationButton
- .setBackgroundResource(R.drawable.reject_medi_grayscale);
- setButtonState(false);
- storeMediTimeLastChecked();
-
- }
-
- public void setButtonState(boolean state) {
- mAcceptMedicationButton.setEnabled(state);
- mRejectMedicationButton.setEnabled(state);
- }
-
- public void decideDrugTakenUIBoolean(Boolean isWeekly, Boolean isTaken) {
- if (isWeekly && checkDrugTakenTimeInterval("weeklyDate") > 1) {
- changeWeeklyAlarmTime();
- }
- saveUsersettings(isTaken, isWeekly);
- if (isTaken) {
- isDrugTakenUI();
- } else {
- isDrugNotTakenUI();
- }
- }
-
- public void storeMediTimeLastChecked() {
- CharSequence lastMedicationCheckedTime = "";
- Calendar c = Calendar.getInstance();
- lastMedicationCheckedTime = new SimpleDateFormat("dd/MM",
- Locale.getDefault()).format(c.getTime());
-
- mSharedPreferenceStore.mEditor.putString(
- "com.peacecorps.malaria.checkMediLastTakenTime",
- lastMedicationCheckedTime.toString()).commit();
- }
-
- public void changeWeeklyAlarmTime() {
- int hour = Calendar.getInstance().get(Calendar.HOUR);
- int minute = Calendar.getInstance().get(Calendar.MINUTE) - 1;
- getActivity().startService(
- new Intent(getActivity(), AlarmService.class));
- mSharedPreferenceStore.mEditor.putInt("com.peacecorps.malaria.AlarmHour", hour)
- .commit();
- mSharedPreferenceStore.mEditor.putInt("com.peacecorps.malaria.AlarmMinute", minute)
- .commit();
- }
-
-
- public String decideDayofWeek(int checkDay, String possibleDays[]) {
- String currentDayOfWeek = null;
- switch (checkDay) {
- case 1:
- currentDayOfWeek = possibleDays[0];
- break;
- case 2:
- currentDayOfWeek = possibleDays[1];
- break;
- case 3:
- currentDayOfWeek = possibleDays[2];
- break;
- case 4:
- currentDayOfWeek = possibleDays[3];
- break;
- case 5:
- currentDayOfWeek = possibleDays[4];
- break;
- case 6:
- currentDayOfWeek = possibleDays[5];
- break;
- case 7:
- currentDayOfWeek = possibleDays[6];
- break;
- default:
- ToastLogSnackBarUtil.showErrorLog("HomeScreenFragment: invalid option");
- }
- return currentDayOfWeek;
- }
-
-
- public void missedDayRecord(int day, int month, int year){
-
- DatabaseSQLiteHelper sqLH = new DatabaseSQLiteHelper(getActivity());
- sqLH.insertOrUpdateMissedMedicationEntry(day,month,year,computeAdherenceRate());
-
- }
-
- public void addDialog()
- {
- dialog = new Dialog(this.getActivity(),android.R.style.Theme_DeviceDefault_Dialog_NoActionBar);
- dialog.setContentView(R.layout.resetdata_dialog);
- dialog.setTitle("Reset Data");
-
- //final RadioGroup btnRadGroup = (RadioGroup) dialog.findViewById(R.id.radioGroupReset);
- Button btnOK = (Button) dialog.findViewById(R.id.btn_dialog_reset_okay);
-
- btnOK.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-
- /* // get selected radio button from radioGroup
- int selectedId = btnRadGroup.getCheckedRadioButtonId();
-
- // find the radiobutton by returned id
- RadioButton btnRadButton = (RadioButton) dialog.findViewById(selectedId);
-
- String ch = btnRadButton.getText().toString();
-
- if(ch.equalsIgnoreCase("yes"))
- {
- DatabaseSQLiteHelper sqLite = new DatabaseSQLiteHelper(getActivity());
- sqLite.resetDatabase();
- mSharedPreferenceStore.mEditor.clear().commit();
- SharedPreferenceStore.mEditor.clear().commit();
- startActivity(new Intent(getActivity(),
- MedicineSettingsActivity.class));
- getActivity().finish();
- }
- else
- {
- dialog.dismiss();
- }*/
- DatabaseSQLiteHelper sqLite = new DatabaseSQLiteHelper(getActivity());
- sqLite.resetDatabase();
- mSharedPreferenceStore.mEditor.clear().commit();
- SharedPreferenceStore.mEditor.clear().commit();
- startActivity(new Intent(getActivity(),
- MedicineSettingsActivity.class));
- getActivity().finish();
-
- }
- });
-
- Button btnCancel = (Button) dialog.findViewById(R.id.btn_dialog_reset_cancel);
- btnCancel.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- dialog.dismiss();
- }
- });
- dialog.show();
-
- }
-
- /*public void updateMediLastTime() {
- if (FirstAnalyticFragment.checkMediLastTakenTime != null) {
- FirstAnalyticFragment.checkMediLastTakenTime.setText(mSharedPreferenceStore.mPrefsStore.getString("com.peacecorps.malaria.checkMediLastTakenTime", "").toString());
- }
- }*/
-
-}
\ No newline at end of file
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/SecondAnalyticFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/SecondAnalyticFragment.java
deleted file mode 100755
index 28b617a3..00000000
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/SecondAnalyticFragment.java
+++ /dev/null
@@ -1,373 +0,0 @@
-
-package com.peacecorps.malaria.code.fragment;
-
-import android.app.Dialog;
-import android.content.Context;
-import android.content.Intent;
-import android.graphics.Typeface;
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.*;
-
-import com.jjoe64.graphview.CustomLabelFormatter;
-import com.jjoe64.graphview.GraphView;
-
-import com.jjoe64.graphview.GraphView.GraphViewData;
-import com.jjoe64.graphview.GraphViewSeries;
-import com.jjoe64.graphview.GraphViewStyle;
-import com.jjoe64.graphview.LineGraphView;
-import com.peacecorps.malaria.R;
-import com.peacecorps.malaria.code.model.SharedPreferenceStore;
-import com.peacecorps.malaria.db.DatabaseSQLiteHelper;
-
-import java.util.Calendar;
-
-/**
- * Second Analytic Fragment
- * It shows the Progress Bars and Graph
- **/
-public class SecondAnalyticFragment extends Fragment {
-
- private TextView firstMonthProgressLabel, secondMonthProgressLabel, thirdMonthProgressLabel, fourthMonthProgressLabel;
- private TextView firstMonthProgressPercent, secondMonthProgressPercent, thirdMonthProgressPercent, fourthMonthProgressPercent;
- private ProgressBar firstMonthProgressBar, secondMonthProgressBar, thirdMonthProgressBar, fourthMonthProgressBar;
- private View rootView;
- public final static String MONTH_REQ = "com.peacecorps.malaria.secondanalyticfragment.MONTHREQ";
-
- static SharedPreferenceStore mSharedPreferenceStore;
-
-
- private static final String DATABASE_NAME = "MalariaDatabase";
- private static final String userMedicationChoiceTable = "userSettings";
- private final int[] daysOfMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30,
- 31, 30, 31};
- private String TAGSAF = "SecondAnalyticFragment";
-
- GraphViewSeries drugGraphSeries;
- private GraphViewData[] graphViewData;
- private int date;
- private String choice;
- private Dialog dialog = null;
-
-
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- //Declaring the Views
- rootView = inflater.inflate(R.layout.fragment_second_analytic_screen,
- null);
- Log.e("MyTag", "Error message with my own tag");
-
- firstMonthProgressLabel = (TextView) rootView.findViewById(R.id.firstMonthProgressLabel);
- secondMonthProgressLabel = (TextView) rootView.findViewById(R.id.secondMonthProgressLabel);
- thirdMonthProgressLabel = (TextView) rootView.findViewById(R.id.thirdMonthProgressLabel);
- fourthMonthProgressLabel = (TextView) rootView.findViewById(R.id.fourthMonthProgressLabel);
-
- firstMonthProgressPercent = (TextView) rootView.findViewById(R.id.firstMonthProgressPercent);
- secondMonthProgressPercent = (TextView) rootView.findViewById(R.id.secondMonthProgressPercent);
- thirdMonthProgressPercent = (TextView) rootView.findViewById(R.id.thirdMonthProgressPercent);
- fourthMonthProgressPercent = (TextView) rootView.findViewById(R.id.fourthMonthProgressPercent);
-
- firstMonthProgressBar = (ProgressBar) rootView.findViewById(R.id.firstMonthProgressBar);
- secondMonthProgressBar = (ProgressBar) rootView.findViewById(R.id.secondMonthProgressBar);
- thirdMonthProgressBar = (ProgressBar) rootView.findViewById(R.id.thirdMonthProgressBar);
- fourthMonthProgressBar = (ProgressBar) rootView.findViewById(R.id.fourthMonthProgressBar);
-
-
- Calendar cal = Calendar.getInstance();
-
- date = Calendar.getInstance().get(Calendar.MONTH);
- //checking choic of pill whether weekly or daily
- if (mSharedPreferenceStore.mPrefsStore.getBoolean(
- "com.peacecorps.malaria.isWeekly", false)) {
- choice = "weekly";
- } else {
- choice = "daily";
- }
-
- updateUI(choice, date);
-
-
- return rootView;
- }
-
-
- @Override
- public void onResume() {
- super.onResume();
- updateUI(choice, date);
-
- }
-
- int mdate;
- int myear;
-
- //finding month from its integer
- public String getMonth(int date) {
- String month[] = getResources().getStringArray(R.array.array_month);
- if (date == -1) {
- date = 11;
- myear = Calendar.getInstance().get(Calendar.YEAR) - 1;
- } else if (date == -2) {
- date = 10;
- myear = Calendar.getInstance().get(Calendar.YEAR) - 1;
- } else if (date == -3) {
- date = 9;
- myear = Calendar.getInstance().get(Calendar.YEAR) - 1;
- } else {
- myear = Calendar.getInstance().get(Calendar.YEAR);
- mdate = date;
- }
- return month[date];
- }
-
- /*Opening Dialog on Clicking Gear Icon*/
- public void addButtonListeners() {
- /*On Clicking the Progress Bars Opens Calendar of that Specific Month*/
- firstMonthProgressBar.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-
- Intent intent = new Intent(getActivity(), ThirdAnalyticFragment.class);
- String mon = firstMonthProgressLabel.getText().toString();
- intent.putExtra(MONTH_REQ, mon); //transfering the month Information for displaying Calendar of Specific Month
- startActivity(intent);
- Toast.makeText(getActivity(), "First progress", Toast.LENGTH_SHORT).show();
- }
- });
-
- secondMonthProgressBar.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-
- Intent intent = new Intent(getActivity(), ThirdAnalyticFragment.class);
- String mon = secondMonthProgressLabel.getText().toString();
- intent.putExtra(MONTH_REQ, mon); //transfering the month Information for displaying Calendar of Specific Month
- startActivity(intent);
- Toast.makeText(getActivity(), "Second progress", Toast.LENGTH_SHORT).show();
- }
- });
-
- thirdMonthProgressBar.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-
- Intent intent = new Intent(getActivity(), ThirdAnalyticFragment.class);
- String mon = thirdMonthProgressLabel.getText().toString();
- intent.putExtra(MONTH_REQ, mon); //transfering the month Information for displaying Calendar of Specific Month
- //yatna
- startActivityForResult(intent, 3);
- Toast.makeText(getActivity(), "Third progress", Toast.LENGTH_SHORT).show();
- }
- });
-
- fourthMonthProgressBar.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(getActivity(), ThirdAnalyticFragment.class);
- String mon = fourthMonthProgressLabel.getText().toString();
- intent.putExtra(MONTH_REQ, mon); //transfering the month Information for displaying Calendar of Specific Month
- //yatna
- startActivityForResult(intent, 2);
- Toast.makeText(getActivity(), "Fourth progress", Toast.LENGTH_SHORT).show();
- }
- });
-
-
- }
-
- /*yatna*/
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- // check if the request code is same as what is passed here it is 2
- //Todo Creating error now, keeping for future reference
-// if (requestCode == 2 || requestCode == 3) {
-// ViewPager vp=(ViewPager)getActivity().findViewById(R.id.vPager);
-// //refresh all the pagers in view pager
-// vp.getAdapter().notifyDataSetChanged();
- }
-
- /*Fetching the Details and Settings from Shared Preferences*/
- public void getSharedPreferences() {
-
- mSharedPreferenceStore.mPrefsStore = getActivity()
- .getSharedPreferences("com.peacecorps.malaria.storeTimePicked",
- Context.MODE_PRIVATE);
- mSharedPreferenceStore.mEditor = mSharedPreferenceStore.mPrefsStore
- .edit();
- }
-
- /*Finding No. of Days in Month*/
- public int getNumberOfDaysInMonth(int month) {
- return daysOfMonth[month];
- }
-
- /*Updating the Progress Bars
- * On the basis of drugs taken or not
- * Also on the basis of status of each day modified later in the calendar
- * */
- public void updateProgressBar(String choice, int date) {
- DatabaseSQLiteHelper sqLH = new DatabaseSQLiteHelper(getActivity());
- Typeface cf = Typeface.createFromAsset(getActivity().getAssets(), "fonts/garreg.ttf");
- int SetupMonth = mSharedPreferenceStore.mPrefsStore.getInt("com.peacecorps.malaria.SetupMonth", -1);
- int SetupYear = mSharedPreferenceStore.mPrefsStore.getInt("com.peacecorps.malaria.SetupYear", -1);
- Log.d("setupYear/myear ", Integer.toString(SetupYear) + " " + Integer.toString(myear));
- firstMonthProgressLabel.setText(getMonth(date - 3));
- firstMonthProgressLabel.setTypeface(cf);
- int progress = sqLH.getData(mdate, myear, choice);
- float progressp = 0;
- if (choice.equalsIgnoreCase("daily"))
- progressp = (float) progress / getNumberOfDaysInMonth(mdate) * 100;
- else
- progressp = progress * 25;
-
- if (progressp >= 50) {
- firstMonthProgressBar.setProgressDrawable(getResources().getDrawable(R.drawable.saf_progress_bar_green));
- firstMonthProgressBar.setBackground(getResources().getDrawable(R.drawable.progress_bg_green));
-
- }
- firstMonthProgressBar.setProgress((int) progressp);
- if ((date - 3) >= SetupMonth || myear != SetupYear || (int) progressp != 0)
- firstMonthProgressPercent.setText("" + (int) progressp + "%");
- else
- firstMonthProgressPercent.setText("N.A");
-
- firstMonthProgressPercent.setTypeface(cf);
-
- secondMonthProgressLabel.setText(getMonth(date - 2));
- secondMonthProgressLabel.setTypeface(cf);
- progress = sqLH.getData(mdate, myear, choice);
- if (choice.equalsIgnoreCase("daily"))
- progressp = (float) progress / getNumberOfDaysInMonth(mdate) * 100;
- else
- progressp = progress * 25;
-
- if (progressp >= 50) {
- secondMonthProgressBar.setProgressDrawable(getResources().getDrawable(R.drawable.saf_progress_bar_green));
- secondMonthProgressBar.setBackground(getResources().getDrawable(R.drawable.progress_bg_green));
-
- }
- secondMonthProgressBar.setProgress((int) progressp);
- if ((date - 2) >= SetupMonth || myear != SetupYear || (int) progressp != 0)
- secondMonthProgressPercent.setText("" + (int) progressp + "%");
- else
- secondMonthProgressPercent.setText("N.A");
-
- secondMonthProgressPercent.setTypeface(cf);
-
- thirdMonthProgressLabel.setText(getMonth(date - 1));
- thirdMonthProgressLabel.setTypeface(cf);
- progress = sqLH.getData(mdate, myear, choice);
- if (choice.equalsIgnoreCase("daily"))
- progressp = (float) progress / getNumberOfDaysInMonth(mdate) * 100;
- else
- progressp = progress * 25;
-
- if (progressp >= 50) {
- thirdMonthProgressBar.setBackground(getResources().getDrawable(R.drawable.progress_bg_green));
- thirdMonthProgressBar.setProgressDrawable(getResources().getDrawable(R.drawable.saf_progress_bar_green));
- }
- thirdMonthProgressBar.setProgress((int) progressp);
- if ((date - 1) >= SetupMonth || myear != SetupYear || (int) progressp != 0)
- thirdMonthProgressPercent.setText("" + (int) progressp + "%");
- else
- thirdMonthProgressPercent.setText("N.A");
- thirdMonthProgressPercent.setTypeface(cf);
-
- fourthMonthProgressLabel.setText(getMonth(date));
- fourthMonthProgressLabel.setTypeface(cf);
- progress = sqLH.getData(mdate, myear, choice);
- Log.d(TAGSAF, "Query Return: " + progress);
- if (choice.equalsIgnoreCase("daily"))
- progressp = (float) progress / getNumberOfDaysInMonth(mdate) * 100;
- else
- progressp = progress * 25;
- Log.d(TAGSAF, "" + getNumberOfDaysInMonth(mdate));
- Log.d(TAGSAF, "" + progress);
- Log.d(TAGSAF, "" + progressp);
-
- if (progressp >= 50) {
- fourthMonthProgressBar.setBackground(getResources().getDrawable(R.drawable.progress_bg_green));
- fourthMonthProgressBar.setProgressDrawable(getResources().getDrawable(R.drawable.saf_progress_bar_green));
- }
- fourthMonthProgressBar.setProgress((int) progressp);
- fourthMonthProgressPercent.setText("" + (int) progressp + "%");
- fourthMonthProgressPercent.setTypeface(cf);
- }
-
- /**
- * Update UI is called on resume to Update the Graph and Progress Bars
- **/
- public void updateUI(String choice, int date) {
-
- updateProgressBar(choice, date);
- DatabaseSQLiteHelper sqLite = new DatabaseSQLiteHelper(getActivity());
- if (sqLite.getDosesInaRowDaily() != 0) {
- SetupAndShowGraph();
- }
- getSharedPreferences();
- addButtonListeners();
-
- }
-
- /**
- * Setting Up Graph
- **/
- public void SetupAndShowGraph() {
-
-
- GraphViewData graphViewData[] = new GraphViewData[DatabaseSQLiteHelper.date.size()];
- String verLabels[] = {"100%", "50%", "25%", "0%"};
- //adding data
- for (int index = 0; index < DatabaseSQLiteHelper.percentage.size(); index++) {
-
- graphViewData[index] = new GraphViewData(DatabaseSQLiteHelper.date.get(index), Double.parseDouble("" + DatabaseSQLiteHelper.percentage.get(index)));
- }
- drugGraphSeries = new GraphViewSeries(graphViewData);
-
- GraphView lineGraphView = new LineGraphView(getActivity(), "");
- //styling graph
- lineGraphView.getGraphViewStyle().setGridColor(getResources().getColor(R.color.lightest_brown));
- lineGraphView.getGraphViewStyle().setGridStyle(GraphViewStyle.GridStyle.BOTH);
- lineGraphView.getGraphViewStyle().setHorizontalLabelsColor(getResources().getColor(R.color.text_color_primary));
- lineGraphView.getGraphViewStyle().setVerticalLabelsColor(getResources().getColor(R.color.text_color_primary));
- lineGraphView.setBackground(getResources().getDrawable(R.drawable.graph_bg));
- lineGraphView.getGraphViewStyle().setTextSize(8.0F);
- lineGraphView.setVerticalLabels(verLabels);
-
- lineGraphView.setTitle("Adherence Rate vs DayWise");
-
-
- lineGraphView.setScrollable(true);
- lineGraphView.setScalable(true);
-
- lineGraphView.setCustomLabelFormatter(new CustomLabelFormatter() {
- @Override
- public String formatLabel(double value, boolean isXAxis) {
-
-
- return null;
- }
- });
-
- ((LineGraphView) lineGraphView).setDrawBackground(true);
- ((LineGraphView) lineGraphView).setDrawDataPoints(true);
- ((LineGraphView) lineGraphView).setBackgroundColor(getResources().getColor(R.color.light_blue));
- float r = (float) 0.20;
- ((LineGraphView) lineGraphView).setDataPointsRadius(r);
- //plotting data
- Log.d("Length", " " + graphViewData.length);
-
- lineGraphView.addSeries(drugGraphSeries);
-
- //showing graph
- LinearLayout linearLayout = (LinearLayout) rootView.findViewById(R.id.graphView);
- linearLayout.addView(lineGraphView);
-
-
- }
-}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/ThirdAnalyticFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/ThirdAnalyticFragment.java
index dec03b7a..2911b142 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/ThirdAnalyticFragment.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/fragment/ThirdAnalyticFragment.java
@@ -62,7 +62,7 @@ public void onCreate(Bundle savedInstanceState) {
/** Added by Ankita for getting specific month **/
Intent intent = getIntent();
- String mon= intent.getStringExtra(SecondAnalyticFragment.MONTH_REQ);
+ String mon= intent.getStringExtra("sendMonth");
Calendar cal; int intmon=0; Date dat;
try{
dat = new SimpleDateFormat("MMMM").parse(mon);
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/interfaces/GetUserCallback.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/interfaces/GetUserCallback.java
deleted file mode 100644
index 0f5f4667..00000000
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/interfaces/GetUserCallback.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.peacecorps.malaria.code.interfaces;
-
-/**
- * Created by yatna on 10/7/16.
- */
-public interface GetUserCallback {
- public abstract void done(String status);
-}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/model/AppUserModel.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/model/AppUserModel.java
deleted file mode 100644
index 38e0d23b..00000000
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/model/AppUserModel.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.peacecorps.malaria.code.model;
-
-/**
- * Created by yatna on 10/7/16.
- */
-public class AppUserModel {
- private String email;
- private String name;
- private int age;
- private String medicineType;
- //construct a user's model
- public AppUserModel getAppUser(String name, String email, int age, String medicineType){
- this.name=name;
- this.email=email;
- this.age=age;
- this.medicineType=medicineType;
- return this;
- }
- //getters
- public String getName(){
- return this.name;
- }
- public String getEmail(){
- return this.email;
- }
- public int getAge(){
- return this.age;
- }
- public String getMedicineType(){
- return this.medicineType;
- }
-}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/AlarmAutoStart.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/AlarmAutoStart.java
deleted file mode 100755
index 1e6b6569..00000000
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/AlarmAutoStart.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.peacecorps.malaria.code.reciever;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-import com.peacecorps.malaria.services.AlarmService;
-import com.peacecorps.malaria.R;
-
-public class AlarmAutoStart extends BroadcastReceiver {
-
- @Override
- public void onReceive(Context context, Intent intent) {
-
- if (intent.getAction().equals(R.string.alarm_auto_start_boot_completed_intent_check)) {
- context.startService(new Intent(context, AlarmService.class));
- }
- }
-
-}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/AlarmHandlerClass.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/AlarmHandlerClass.java
deleted file mode 100755
index 7b5b1812..00000000
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/AlarmHandlerClass.java
+++ /dev/null
@@ -1,98 +0,0 @@
-package com.peacecorps.malaria.code.reciever;
-
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.os.PowerManager;
-
-import com.peacecorps.malaria.code.model.SharedPreferenceStore;
-import com.peacecorps.malaria.code.notification.DrugReminderNotification;
-
-import java.util.Calendar;
-import java.util.Date;
-
-public class AlarmHandlerClass extends BroadcastReceiver {
-
- /**Class is for Handling the Alarm**/
-
- public static Calendar mAlarmScheduleTime;
- private final int INTERVAL_WEEK = 604800000;
- public static AlarmManager mAlarmManager;
-
- private static SharedPreferenceStore mSharedPreferenceStore;
-
- @Override
- public void onReceive(Context context, Intent intent) {
-
- /**On Receiving the call for Alarm, it sets one on the date and time specified. **/
- PowerManager powerManager = (PowerManager) context
- .getSystemService(Context.POWER_SERVICE);
- PowerManager.WakeLock wakeLock = powerManager.newWakeLock(
- PowerManager.PARTIAL_WAKE_LOCK, "");
- wakeLock.acquire();
-
- /**Shows the notification with Taken, Snooze and Not Taken Button**/
- new DrugReminderNotification(context);
- //Todo incorrect wakelock usage
- wakeLock.release();
- }
-
- public void getSharedPreferences(Context context) {
- /**Initializing the Shared Preferences for Storing Details**/
- mSharedPreferenceStore.mPrefsStore = context.getSharedPreferences(
- "com.peacecorps.malaria.storeTimePicked", Context.MODE_PRIVATE);
- mSharedPreferenceStore.mEditor = mSharedPreferenceStore.mPrefsStore
- .edit();
- }
-
- public void setAlarm(Context context) {
- getSharedPreferences(context);
- /**Getting the Time**/
- int hour = mSharedPreferenceStore.mPrefsStore.getInt(
- "com.peacecorps.malaria.AlarmHour", -1);
- int minute = mSharedPreferenceStore.mPrefsStore.getInt(
- "com.peacecorps.malaria.AlarmMinute", -1);
- if ((hour != -1) && (minute != -1)) {
- alarmTime(context, hour, minute);
- /**Setting Alarm**/
- mAlarmManager = (AlarmManager) context
- .getSystemService(Context.ALARM_SERVICE);
- Intent alarmIntent = new Intent(
- "com.peacecorps.malaria.START_ALARM");
- PendingIntent pendingAlarm = PendingIntent.getBroadcast(context, 0,
- alarmIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
- if (mSharedPreferenceStore.mPrefsStore.getBoolean(
- "com.peacecorps.malaria.isWeekly", false)) {
- /**Weekly Alarm**/
- mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
- mAlarmScheduleTime.getTimeInMillis(), INTERVAL_WEEK,
- pendingAlarm);
- } else {
- /**Daily Alarm**/
- mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
- mAlarmScheduleTime.getTimeInMillis(),
- AlarmManager.INTERVAL_DAY, pendingAlarm);
- }
- }
- }
-
- public void alarmTime(Context context, int hour, int minute) {
- /**Setting The Alarm Time **/
- Date date = new Date();
- mAlarmScheduleTime = Calendar.getInstance();
- mAlarmScheduleTime.setTime(date);
-
- Calendar dateNow = Calendar.getInstance();
- dateNow.setTime(date);
-
- mAlarmScheduleTime.set(Calendar.HOUR_OF_DAY, hour);
- mAlarmScheduleTime.set(Calendar.MINUTE, minute);
-
- if (mAlarmScheduleTime.before(dateNow)) {
- mAlarmScheduleTime.add(Calendar.DATE, 1);
- }
-
- }
-}
\ No newline at end of file
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/DrugReminderCallerReceiver.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/DrugReminderCallerReceiver.java
index 5c102b96..cc129504 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/DrugReminderCallerReceiver.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/DrugReminderCallerReceiver.java
@@ -4,11 +4,11 @@
import android.content.Context;
import android.content.Intent;
-import com.peacecorps.malaria.code.notification.DrugReminderNotification;
+import com.peacecorps.malaria.notifications.DrugNotificationUtils;
public class DrugReminderCallerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- new DrugReminderNotification(context);
+ DrugNotificationUtils.startNotificationCheckSnooze(context);
}
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/DrugReminderReceiver.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/DrugReminderReceiver.java
index 8c4ad195..998a2a2a 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/DrugReminderReceiver.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/DrugReminderReceiver.java
@@ -14,7 +14,7 @@
import com.peacecorps.malaria.R;
import com.peacecorps.malaria.db.DatabaseSQLiteHelper;
import com.peacecorps.malaria.code.model.SharedPreferenceStore;
-import com.peacecorps.malaria.services.AlarmService;
+import com.peacecorps.malaria.notifications.service.AlarmService;
import com.peacecorps.malaria.utils.CalendarFunction;
import java.util.Calendar;
@@ -23,14 +23,13 @@
public class DrugReminderReceiver extends BroadcastReceiver {
static SharedPreferenceStore mSharedPreferenceStore;
private static int mDrugAcceptedCount;
- private NotificationManager alarmNotificationManager;
private static int mDrugRejectedCount;
private int flag;
String TAG = getClass().getName();
@Override
public void onReceive(Context context, Intent intent) {
- alarmNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ NotificationManager alarmNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
switch (intent.getAction()) {
case "0":
//not taken
@@ -68,14 +67,18 @@ private void notTaken(Context context) {
saveUsersettings(context,true, false);
/**Marked as Not Taken. No reminders now,it ll be for next time now.**/
DatabaseSQLiteHelper databaseSQLiteHelper = new DatabaseSQLiteHelper(context);
- databaseSQLiteHelper.getUserMedicationSelection(context, "weekly", Calendar.getInstance().getTime(), "no", computeAdherenceRate(context));
+ databaseSQLiteHelper.getUserMedicationSelection(context, "weekly",
+ Calendar.getInstance().getTime(),
+ "no", computeAdherenceRate(context));
changeWeeklyAlarmTime(context);
} else {
if (checkDrugTakenTimeInterval("dateDrugTaken",context) > 0) {
saveUsersettings(context,false, false);
DatabaseSQLiteHelper databaseSQLiteHelper = new DatabaseSQLiteHelper(context);
- databaseSQLiteHelper.getUserMedicationSelection(context, "daily", Calendar.getInstance().getTime(), "no", computeAdherenceRate(context));
+ databaseSQLiteHelper.getUserMedicationSelection(context, "daily",
+ Calendar.getInstance().getTime(),
+ "no", computeAdherenceRate(context));
}
}
@@ -110,6 +113,7 @@ public void getSettings(Context context) {
int d = c.get(Calendar.DATE);
int m = c.get(Calendar.MONTH);
int y = c.get(Calendar.YEAR);
+
DatabaseSQLiteHelper sqLite = new DatabaseSQLiteHelper(context);
if (sqLite.getStatus(d, m, y).equalsIgnoreCase("yes") == true) {
flag = 1;
@@ -190,7 +194,8 @@ private void taken(Context context) {
/**Updates the date when weekly drug was taken and set the alarm for nex weekly Date**/
saveUsersettings(context,true, true);
DatabaseSQLiteHelper databaseSQLiteHelper = new DatabaseSQLiteHelper(context);
- databaseSQLiteHelper.getUserMedicationSelection(context, "weekly", Calendar.getInstance().getTime(), "yes", computeAdherenceRate(context));
+ databaseSQLiteHelper.getUserMedicationSelection(context, "weekly", Calendar.getInstance().getTime(),
+ "yes", computeAdherenceRate(context));
changeWeeklyAlarmTime(context);
} else {
@@ -198,7 +203,8 @@ private void taken(Context context) {
if (checkDrugTakenTimeInterval("dateDrugTaken", context) > 0) {
saveUsersettings(context,true, false);
DatabaseSQLiteHelper databaseSQLiteHelper = new DatabaseSQLiteHelper(context);
- databaseSQLiteHelper.getUserMedicationSelection(context, "daily", Calendar.getInstance().getTime(), "yes", computeAdherenceRate(context));
+ databaseSQLiteHelper.getUserMedicationSelection(context, "daily", Calendar.getInstance().getTime(),
+ "yes", computeAdherenceRate(context));
}
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/TripAlarmReceiver.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/TripAlarmReceiver.java
index ed3578f8..d3a1a7e4 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/TripAlarmReceiver.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/TripAlarmReceiver.java
@@ -15,7 +15,7 @@
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;
-import com.peacecorps.malaria.services.TripAlarmService;
+import com.peacecorps.malaria.code.reciever.services.TripAlarmService;
/**
* On receiving the calarm call from Alarm Service,
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/notification/DrugReminderNotification.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/notification/DrugReminderNotification.java
similarity index 92%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/code/notification/DrugReminderNotification.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/notification/DrugReminderNotification.java
index 03acb825..1ca388dc 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/notification/DrugReminderNotification.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/notification/DrugReminderNotification.java
@@ -1,4 +1,4 @@
-package com.peacecorps.malaria.code.notification;
+package com.peacecorps.malaria.code.reciever.notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -9,14 +9,14 @@
import android.util.Log;
import com.peacecorps.malaria.R;
-import com.peacecorps.malaria.ui.home_screen.MainActivity;
+import com.peacecorps.malaria.ui.main.MainActivity;
import com.peacecorps.malaria.code.reciever.DrugReminderReceiver;
import com.peacecorps.malaria.db.DatabaseSQLiteHelper;
import java.util.Calendar;
public class DrugReminderNotification {
- Context context;
+ private Context context;
public DrugReminderNotification(Context context) {
this.context = context;
@@ -35,7 +35,8 @@ private void buildNotification() {
/*Action Not Taken*/
Intent intentNotTaken = new Intent(context, DrugReminderReceiver.class);
intentNotTaken.setAction(context.getString(R.string.notification_action_code_not_taken));
- PendingIntent pendingIntentNotTaken = PendingIntent.getBroadcast(context, 0, intentNotTaken, PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent pendingIntentNotTaken = PendingIntent.getBroadcast(context, 0, intentNotTaken,
+ PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action actionNotTaken;
actionNotTaken = new NotificationCompat.Action(R.drawable.ic_cancel_black_18dp, context.getString(R.string.drug_reminder_notification_action_not_taken)
, pendingIntentNotTaken);
@@ -64,7 +65,8 @@ private void buildNotification() {
/*Action Snooze*/
Intent intentSnooze = new Intent(context, DrugReminderReceiver.class);
intentSnooze.setAction(context.getString(R.string.notification_action_code_snooze));
- PendingIntent pendingIntentSnooze = PendingIntent.getBroadcast(context, 0, intentSnooze, PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent pendingIntentSnooze = PendingIntent.getBroadcast(context, 0, intentSnooze,
+ PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action actionSnooze;
actionSnooze = new NotificationCompat.Action(R.drawable.ic_snooze_black_18dp, context.getString(R.string.drug_reminder_notification_action_snooze)
, pendingIntentSnooze);
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/services/TripAlarmService.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/services/TripAlarmService.java
similarity index 81%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/services/TripAlarmService.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/services/TripAlarmService.java
index 07194b63..0acc7f6a 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/services/TripAlarmService.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/code/reciever/services/TripAlarmService.java
@@ -1,4 +1,4 @@
-package com.peacecorps.malaria.services;
+package com.peacecorps.malaria.code.reciever.services;
/**
* Created by Ankita on 8/8/2015.
@@ -14,9 +14,10 @@
import com.peacecorps.malaria.R;
import com.peacecorps.malaria.code.activities.TripAlarmActivity;
+import com.peacecorps.malaria.data.AppDataManager;
+import com.peacecorps.malaria.utils.InjectionClass;
public class TripAlarmService extends IntentService {
- private NotificationManager alarmNotificationManager;
public TripAlarmService() {
super("TripAlarmService");
@@ -24,14 +25,16 @@ public TripAlarmService() {
@Override
public void onHandleIntent(Intent intent) {
+ AppDataManager dataManager = InjectionClass.provideDataManager(this);
SharedPreferences preferences = getSharedPreferences("WidgetReminder", Context.MODE_PRIVATE);
- sendNotification("Get Ready to Pack your Bags!" + "\n" + preferences.getString("view_upcoming_reminder",""), intent);
+ sendNotification("Get Ready to Pack your Bags!" + "\n"
+ + dataManager.getReminderMessageForTrip(), intent);
}
private void sendNotification(String msg,Intent intent) {
Log.d("AlarmService", "Preparing to send notification...: " + msg);
- alarmNotificationManager = (NotificationManager) this
+ NotificationManager alarmNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent activIntent = new Intent(this,TripAlarmActivity.class);
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/AppDataManager.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/AppDataManager.java
index c87bcc54..593f4b40 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/AppDataManager.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/AppDataManager.java
@@ -24,7 +24,7 @@ public void getCountForProgressBar(int month, int year, String status, String ch
}
@Override
- public void setUserMedicineSelection(int drug, String choice, Date date, String status, Double percentage) {
+ public void setUserMedicineSelection(String drug, String choice, Date date, String status, Double percentage) {
dbHelper.setUserMedicineSelection(drug, choice, date, status, percentage);
}
@@ -44,7 +44,7 @@ public void updateMedicationEntry(int date, int month, int year, String entry, d
}
@Override
- public void insertOrUpdateMissedMedicationEntry(int drug, String ch, int date, int month, int year, double percentage) {
+ public void insertOrUpdateMissedMedicationEntry(String drug, String ch, int date, int month, int year, double percentage) {
dbHelper.insertOrUpdateMissedMedicationEntry(drug, ch, date, month, year, percentage);
}
@@ -54,13 +54,13 @@ public void isEntered(int date, int month, int year, LoadIntegerCallback callbac
}
@Override
- public void getFirstTimeTimeStamp(LoadLongCallback callback) {
- dbHelper.getFirstTimeTimeStamp(callback);
+ public void getFirstTimeByTimeStamp(LoadLongCallback callback) {
+ dbHelper.getFirstTimeByTimeStamp(callback);
}
@Override
- public void getStatus(int date, int month, int year, LoadStringCallback callback) {
- dbHelper.getStatus(date, month, year, callback);
+ public void getDailyStatus(int date, int month, int year, LoadStringCallback callback) {
+ dbHelper.getDailyStatus(date, month, year, callback);
}
@Override
@@ -68,6 +68,11 @@ public void getDosesInaRowWeekly(LoadIntegerCallback callback) {
dbHelper.getDosesInaRowWeekly(callback);
}
+ @Override
+ public void getDosesInaRowDaily(LoadIntegerCallback callback) {
+ dbHelper.getDosesInaRowDaily(callback);
+ }
+
@Override
public void resetDatabase() {
dbHelper.resetDatabase();
@@ -153,6 +158,11 @@ public void insertAlarmData(AlarmTime time) {
dbHelper.insertAlarmData(time);
}
+ @Override
+ public void updateAlarmTime(int hour, int min) {
+ dbHelper.updateAlarmTime(hour, min);
+ }
+
@Override
public boolean hasUserSetPreferences() {
return preferencesHelper.hasUserSetPreferences();
@@ -219,8 +229,8 @@ public boolean isDosesWeekly() {
}
@Override
- public void setDoesWeekly(boolean value) {
- preferencesHelper.setDoesWeekly(value);
+ public void setDoseWeekly(boolean value) {
+ preferencesHelper.setDoseWeekly(value);
}
@Override
@@ -228,11 +238,21 @@ public int checkDosesDaily() {
return preferencesHelper.checkDosesDaily();
}
+ @Override
+ public int getDayWeekly() {
+ return preferencesHelper.getDayWeekly();
+ }
+
@Override
public void setDosesDaily(int value) {
preferencesHelper.setDosesDaily(value);
}
+ @Override
+ public void setDayWeekly(int value) {
+ preferencesHelper.setDayWeekly(value);
+ }
+
@Override
public int checkDosesWeekly() {
return preferencesHelper.checkDosesWeekly();
@@ -263,26 +283,6 @@ public void setMedicineLastTakenTime(String time) {
preferencesHelper.setMedicineLastTakenTime(time);
}
- @Override
- public boolean getMythFactGame() {
- return preferencesHelper.getMythFactGame();
- }
-
- @Override
- public void setMythFactGame(boolean val) {
- preferencesHelper.setMythFactGame(val);
- }
-
- @Override
- public boolean getRapidFireGame() {
- return preferencesHelper.getRapidFireGame();
- }
-
- @Override
- public void setRapidFireGame(boolean val) {
- preferencesHelper.setRapidFireGame(val);
- }
-
@Override
public String getToneUri() {
return preferencesHelper.getToneUri();
@@ -382,4 +382,74 @@ public String getReminderMessageForTrip() {
public void setReminderMessageForTrip(String messageForTrip) {
preferencesHelper.setReminderMessageForTrip(messageForTrip);
}
+
+ @Override
+ public void setLongWeeklyDate(long value) {
+ preferencesHelper.setLongWeeklyDate(value);
+ }
+
+ @Override
+ public long getLongWeeklyDate() {
+ return preferencesHelper.getLongWeeklyDate();
+ }
+
+ @Override
+ public void setDateDrugTaken(long value) {
+ preferencesHelper.setDateDrugTaken(value);
+ }
+
+ @Override
+ public long getDateDrug() {
+ return preferencesHelper.getDateDrug();
+ }
+
+ @Override
+ public void setWeeklyDrugTaken(boolean value) {
+ preferencesHelper.setWeeklyDrugTaken(value);
+ }
+
+ @Override
+ public boolean isWeeklyDrugTaken() {
+ return preferencesHelper.isWeeklyDrugTaken();
+ }
+
+ @Override
+ public void setDailyDrugTaken(boolean value) {
+ preferencesHelper.setDailyDrugTaken(value);
+ }
+
+ @Override
+ public boolean isDailyDrugTaken() {
+ return preferencesHelper.isDailyDrugTaken();
+ }
+
+ @Override
+ public int getDrugRejectedCount() {
+ return preferencesHelper.getDrugRejectedCount();
+ }
+
+ @Override
+ public void setDrugRejectedCount(int value) {
+ preferencesHelper.setDrugRejectedCount(value);
+ }
+
+ @Override
+ public boolean checkRapidFireTarget() {
+ return preferencesHelper.checkRapidFireTarget();
+ }
+
+ @Override
+ public void setRapidFireTarget(boolean value) {
+ preferencesHelper.setRapidFireTarget(value);
+ }
+
+ @Override
+ public boolean checkMythFactTarget() {
+ return preferencesHelper.checkMythFactTarget();
+ }
+
+ @Override
+ public void setMythFactTarget(boolean value) {
+ preferencesHelper.setMythFactTarget(value);
+ }
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/AppDbHelper.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/AppDbHelper.java
index 518aa3c7..41de8d10 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/AppDbHelper.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/AppDbHelper.java
@@ -87,14 +87,21 @@ public void run() {
* Used in Home Screen Fragment for updating the current status through tick marks
**/
@Override
- public void setUserMedicineSelection(int drug, String choice, Date date, String status, Double percentage) {
+ public void setUserMedicineSelection(String drug, String choice, Date date, String status, Double percentage) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
- String ts = "";
+ String ts;
+ int month = cal.get(Calendar.MONTH) + 1 ;
+ String monthStr;
+ if ((cal.get(Calendar.MONTH)) < 10) {
+ monthStr = "0" + month;
+ } else {
+ monthStr = "" + month;
+ }
if ((cal.get(Calendar.DATE)) >= 10) {
- ts = "" + cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
+ ts = "" + cal.get(Calendar.YEAR) + "/" + monthStr + "/" + cal.get(Calendar.DATE);
} else {
- ts = "" + cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-0" + cal.get(Calendar.DATE);
+ ts = "" + cal.get(Calendar.YEAR) + "/" + monthStr + "/0" + cal.get(Calendar.DATE);
}
final UserMedicine userMedicine = new UserMedicine(drug, choice, cal.get(Calendar.MONTH), cal.get(Calendar.YEAR), cal.get(Calendar.DATE), status, percentage, ts);
Runnable medicineRunnable = new Runnable() {
@@ -174,7 +181,7 @@ public void run() {
/*If No Entry will be found it will enter in the database, so that it can be later updated.
* Usage is in Day Fragment Activity **/
@Override
- public void insertOrUpdateMissedMedicationEntry(final int drug, final String ch, final int date, final int month, final int year, final double percentage) {
+ public void insertOrUpdateMissedMedicationEntry(final String drug, final String ch, final int date, final int month, final int year, final double percentage) {
Runnable runnable = new Runnable() {
@Override
public void run() {
@@ -187,9 +194,9 @@ public void run() {
}
int flag = 0;
List statusList = userMedicineDao.getStatusListByDateMonthYear(date, month, year);
- for (String status : statusList) {
+ if (statusList.size() > 0)
flag = 1;
- }
+
if (flag == 0) {
UserMedicine userMedicine = new UserMedicine(drug, ch, month, year, date, "", percentage, ts);
userMedicineDao.setUserMedicineSelection(userMedicine);
@@ -247,17 +254,17 @@ public void run() {
* Getting the oldest registered entry of Pill
**/
@Override
- public void getFirstTimeTimeStamp(final LoadLongCallback callback) {
+ public void getFirstTimeByTimeStamp(final LoadLongCallback callback) {
Runnable runnable = new Runnable() {
@Override
public void run() {
String timeStamp = userMedicineDao.getFirstTimeTimeStamp();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
+ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
Date comp_date = Calendar.getInstance().getTime();
try {
comp_date = sdf.parse(timeStamp);
} catch (Exception e) {
- ToastLogSnackBarUtil.showErrorLog("AppDbHelper: Exception in parsing date");
+ ToastLogSnackBarUtil.showErrorLog("AppDbHelper: Exception in parsing date " + timeStamp);
}
final Calendar cal = Calendar.getInstance();
cal.setTime(comp_date);
@@ -279,11 +286,11 @@ public void run() {
* Usages in Day Fragment Activity for getting the previous status of day before updating it as not taken.
**/
@Override
- public void getStatus(final int date, final int month, final int year, final LoadStringCallback callback) {
+ public void getDailyStatus(final int date, final int month, final int year, final LoadStringCallback callback) {
Runnable runnable = new Runnable() {
@Override
public void run() {
- final String status = userMedicineDao.getStatus(date, month, year);
+ final String status = userMedicineDao.getDailyStatus(date, month, year);
appExecutors.mainThread().execute(new Runnable() {
@Override
public void run() {
@@ -310,13 +317,16 @@ public void getDosesInaRowWeekly(final LoadIntegerCallback callback) {
Runnable runnable = new Runnable() {
@Override
public void run() {
- List userMedicines = userMedicineDao.getDosesInaRowWeekly();
- int dosesInaRow = 1, aMonth = 0, pMonth = 0;
+ List userMedicines = userMedicineDao.getDosesInaRow();
+ int dosesInaRow = 1;
+ int aMonth;
+ int pMonth;
Date ado, pdo;
- int pPara = 0;
- long aPara = 0;
- int numDays = 0;
- String ats = "", pts = "";
+ int pPara;
+ long aPara;
+ int numDays;
+ String ats;
+ String pts;
if (userMedicines != null) {
ats = userMedicines.get(0).getTimeStamp();
aMonth = userMedicines.get(0).getMonth() + 1;
@@ -337,7 +347,6 @@ public void run() {
} else {
break;
}
- ats = pts;
ado = pdo;
}
@@ -355,6 +364,76 @@ public void run() {
appExecutors.diskIO().execute(runnable);
}
+ @Override
+ public void getDosesInaRowDaily(final LoadIntegerCallback callback) {
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ List userMedicines = userMedicineDao.getDosesInaRow();
+ int dosesInaRow = 0;
+ int prevDate = 0;
+ int currDate;
+ int currDateMonth;
+ int prevDateMonth = 0;
+ int currDateYear;
+
+ String ts;
+ /**One Iteration is done before entering the while loop for updating the previous and current date**/
+ if (userMedicines.size() > 0) {
+ ts = userMedicines.get(0).getTimeStamp();
+ currDate = userMedicines.get(0).getDate();
+ ToastLogSnackBarUtil.showDebugLog("curr date 1->" + ts);
+
+ if (userMedicines.get(0).getStatus() != null && (userMedicines.get(0).getStatus().compareTo("yes") == 0)) {
+ prevDate = userMedicines.get(0).getDate();
+ prevDateMonth = userMedicines.get(0).getMonth();
+ if (Math.abs(currDate - prevDate) <= 1)
+ dosesInaRow++;
+ }
+
+ /**Since Previous and Current Date our Updated,
+ * Now backwards scan is done till we receive consecutive previous and current date **/
+ for (UserMedicine medicine : userMedicines) {
+ currDate = medicine.getDate();
+ currDateMonth = medicine.getMonth();
+ currDateYear = medicine.getYear();
+ ts = medicine.getTimeStamp();
+ ToastLogSnackBarUtil.showDebugLog("curr date -> " + ts);
+
+ int parameter = Math.abs(currDate - prevDate);
+ if (medicine.getStatus() != null) {
+ if (currDateMonth == prevDateMonth) {
+ if (medicine.getStatus().compareTo("yes") == 0 && parameter == 1) {
+ dosesInaRow++;
+ } else
+ break;
+ } else {
+ parameter = Math.abs(currDate - prevDate) %
+ (CalendarFunction.getNumberOfDaysInMonth(currDateMonth, currDateYear) - 1);
+ if (medicine.getStatus().compareTo("yes") == 0 && parameter <= 1) {
+ dosesInaRow++;
+ } else
+ break;
+ }
+ }
+ prevDate = currDate;
+ prevDateMonth = currDateMonth;
+ ToastLogSnackBarUtil.showDebugLog("Doses in Row-> " + dosesInaRow);
+ }
+ }
+ ToastLogSnackBarUtil.showDebugLog("Final doses in row-> " + dosesInaRow);
+ final int finalDosesInaRow = dosesInaRow;
+ appExecutors.mainThread().execute(new Runnable() {
+ @Override
+ public void run() {
+ callback.onDataLoaded(finalDosesInaRow);
+ }
+ });
+ }
+ };
+ appExecutors.diskIO().execute(runnable);
+ }
+
/*Deleting the Database*/
@Override
public void resetDatabase() {
@@ -507,7 +586,7 @@ public void run() {
}
/**
- * @param status : defines the packing status, defined by checkbox status
+ * @param status : defines the packing status, defined by checkbox status
* @param position : defines the row position in table
*/
@Override
@@ -559,7 +638,7 @@ public void getPackedMedDetails(final LoadPackingCallback callback) {
@Override
public void run() {
final Packing packing = packingDao.getPackedMedicine();
- if(packing!=null) {
+ if (packing != null) {
appExecutors.mainThread().execute(new Runnable() {
@Override
public void run() {
@@ -587,7 +666,8 @@ public void run() {
appExecutors.mainThread().execute(new Runnable() {
@Override
public void run() {
- callback.onDataLoaded(medicines.get(medicines.size() - 1));
+ if (medicines.size() > 0)
+ callback.onDataLoaded(medicines.get(medicines.size() - 1));
}
});
}
@@ -626,12 +706,12 @@ public void run() {
List timeStampList = userMedicineDao.getLastTaken("yes");
int count = 0;
for (String time : timeStampList) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
+ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
Date curr = Calendar.getInstance().getTime();
try {
curr = sdf.parse(time);
} catch (ParseException e1) {
- ToastLogSnackBarUtil.showErrorLog("AppDbHelper: Parse Exception during parsing timestamp from database " + time);
+ ToastLogSnackBarUtil.showErrorLog("AppDbHelper/getCountTakenBetween: Parse Exception " + time);
}
long currt = curr.getTime();
long endt = e.getTime();
@@ -692,4 +772,15 @@ public void run() {
appExecutors.diskIO().execute(runnable);
}
+
+ @Override
+ public void updateAlarmTime(final int hour, final int min) {
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ alarmDao.updateTime(hour, min);
+ }
+ };
+ appExecutors.diskIO().execute(runnable);
+ }
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/DbHelper.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/DbHelper.java
index 4b860d12..b17f155f 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/DbHelper.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/DbHelper.java
@@ -41,7 +41,7 @@ interface LoadAlarmDataCallback {
void getCountForProgressBar( int month, int year, String status, String choice, LoadIntegerCallback callback);
- void setUserMedicineSelection(int drug, String choice, Date date, String status, Double percentage);
+ void setUserMedicineSelection(String drug, String choice, Date date, String status, Double percentage);
void insertAppSettings(String drug, String choice, long date);
@@ -49,16 +49,18 @@ interface LoadAlarmDataCallback {
void updateMedicationEntry(int date, int month, int year, String entry,double percentage);
- void insertOrUpdateMissedMedicationEntry(int drug, String ch, int date, int month, int year,double percentage);
+ void insertOrUpdateMissedMedicationEntry(String drug, String ch, int date, int month, int year,double percentage);
void isEntered(int date,int month, int year, LoadIntegerCallback callback);
- void getFirstTimeTimeStamp(LoadLongCallback callback);
+ void getFirstTimeByTimeStamp(LoadLongCallback callback);
- void getStatus(int date,int month,int year, LoadStringCallback callback);
+ void getDailyStatus(int date,int month,int year, LoadStringCallback callback);
void getDosesInaRowWeekly(LoadIntegerCallback callback);
+ void getDosesInaRowDaily(LoadIntegerCallback callback);
+
void resetDatabase();
void insertLocation(String location);
@@ -92,4 +94,6 @@ interface LoadAlarmDataCallback {
void getAlarmData(LoadAlarmDataCallback callback);
void insertAlarmData(AlarmTime time);
+
+ void updateAlarmTime(int hour, int min);
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/dao/AlarmDao.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/dao/AlarmDao.java
index 015fb7ce..df7409fc 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/dao/AlarmDao.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/dao/AlarmDao.java
@@ -11,6 +11,9 @@ public interface AlarmDao {
@Insert
void insertAlarmData(AlarmTime data);
- @Query("SELECT * FROM alarmtime")
+ @Query("SELECT * FROM alarmtime WHERE id = 1")
AlarmTime getAlarmData();
+
+ @Query("UPDATE alarmtime SET hour= :hour , minute= :minute")
+ void updateTime(int hour, int minute);
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/dao/UserMedicineDao.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/dao/UserMedicineDao.java
index d4e5639d..2d704a2e 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/dao/UserMedicineDao.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/dao/UserMedicineDao.java
@@ -33,10 +33,10 @@ public interface UserMedicineDao {
String getFirstTimeTimeStamp();
@Query("SELECT status FROM usermedicine WHERE date= :date and month= :month and year= :year")
- String getStatus(int date,int month,int year);
+ String getDailyStatus(int date,int month,int year);
@Query("SELECT * FROM UserMedicine ORDER BY timeStamp DESC")
- List getDosesInaRowWeekly();
+ List getDosesInaRow();
@Query("DELETE FROM UserMedicine")
void deleteTableRows();
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/entities/UserMedicine.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/entities/UserMedicine.java
index c461adf5..c39b2e36 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/entities/UserMedicine.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/db/entities/UserMedicine.java
@@ -7,7 +7,7 @@
public class UserMedicine {
@PrimaryKey(autoGenerate = true)
private int userMedicineId;
- private int drug;
+ private String drug;
private String choice;
private int month;
private int year;
@@ -16,7 +16,8 @@ public class UserMedicine {
private double percentage;
private String timeStamp;
- public UserMedicine(int drug, String choice, int month, int year, int date, String status, double percentage, String timeStamp) {
+ public UserMedicine(String drug, String choice, int month, int year, int date, String status,
+ double percentage, String timeStamp) {
this.drug = drug;
this.choice = choice;
this.month = month;
@@ -67,11 +68,11 @@ public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
- public int getDrug() {
+ public String getDrug() {
return drug;
}
- public void setDrug(int drug) {
+ public void setDrug(String drug) {
this.drug = drug;
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/prefs/AppPreferencesHelper.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/prefs/AppPreferencesHelper.java
index 9872c549..69a8fb6d 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/prefs/AppPreferencesHelper.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/prefs/AppPreferencesHelper.java
@@ -11,13 +11,9 @@ public class AppPreferencesHelper implements PreferencesHelper{
private static final String PREF_KEY_DRUG_PICKED = "com_peacecorps_malaria_drugPicked";
private static final String PREF_KEY_FIRST_RUN_TIME = "com_peacecorps_malaria_firstRunTime";
private static final String PREF_KEY_DRUG_ACCEPTED_COUNTED = "com_peacecorps_malaria_drugAcceptedCount";
- private static final String PREF_KEY_IS_WEEKLY = "com_peacecorps_malaria_isWeekly";
- private static final String PREF_KEY_DOSES_DAILY = "com_peacecorps_malaria_daily_dose";
- private static final String PREF_KEY_DOSES_WEEKLY = "com_peacecorps_malaria_weekly_dose";
+ private static final String PREF_KEY_DRUG_REJECTED_COUNT = "com.peacecorps.malaria.isRejected";
private static final String PREF_KEY_MEDICINE_STORE = "MEDICINE_STORE";
private static final String PREF_KEY_MEDICINE_LAST_TAKEN_TIME = "check_medicine_last_taken_time";
- private static final String PREF_KEY_MYTH_FACT_GAME = "myth_fact_game";
- private static final String PREF_KEY_RAPID_FIRE_GAME= "rapid_fire_game";
private static final String PREF_KEY_TONE_URI = "TONE_URI";
private static final String PREF_KEY_TRIP_DATE = "com_peacecorps_malaria_trip_date";
private static final String PREF_KEY_TRIP_LOCATION = "TRIP_LOCATION";
@@ -25,10 +21,23 @@ public class AppPreferencesHelper implements PreferencesHelper{
private static final String PREF_KEY_USER_EMAIL = "USER_EMAIL";
private static final String PREF_KEY_USER_AGE = "USER_AGE";
private static final String PREF_KEY_IS_FIRST_RUN = "IS_FIRST_RUN";
- private static final String PREF_KEY_IS_DRUG_TAKEN = "com_peacecorps_malaria_is_drug_taken";
private static final String PREF_KEY_ALERT_TIME = "NUMBER_ALERT_TIME";
private static final String PREF_KEY_TRIP_REMINDER = "view_upcoming_reminder";
+ private static final String PREF_KEY_WEEKLY_DATE = "com.peacecorps.malaria.weekly_date";
+ private static final String PREF_KEY_IS_WEEKLY_DRUG_TAKEN = "com.peacecorps.malaria.isWeeklyDrugTaken";
+ private static final String PREF_KEY_DOSES_WEEKLY = "com_peacecorps_malaria_weekly_dose";
+ private static final String PREF_KEY_IS_WEEKLY = "com_peacecorps_malaria_isWeekly";
+ private static final String PREF_KEY_WEEKLY_DAY = "com_peacecorps_malaria_weeklyDay";
+ private static final String PREF_KEY_DOSES_DAILY = "com_peacecorps_malaria_daily_dose";
+ private static final String PREF_KEY_IS_DAILY_DRUG_TAKEN = "com.peacecorps.malaria.isDailyDrugTaken";
+ private static final String PREF_KEY_DAILY_DRUG_DATE = "com_peacecorps_malaria_date_drug_taken";
+ private static final String PREF_KEY_IS_DRUG_TAKEN = "com_peacecorps_malaria_is_drug_taken";
+ private static final String PREF_KEY_RAPID_FIRE_TARGET = "rapid_fire_game";
+ private static final String PREF_KEY_MYTH_FACT_TARGET = "myth_fact_game";
+
+
+
private final SharedPreferences mPrefs;
public AppPreferencesHelper(Context context, String prefFileName) {
@@ -100,7 +109,7 @@ public boolean isDosesWeekly() {
}
@Override
- public void setDoesWeekly(boolean value) {
+ public void setDoseWeekly(boolean value) {
mPrefs.edit().putBoolean(PREF_KEY_IS_WEEKLY, value).apply();
}
@@ -109,11 +118,21 @@ public int checkDosesDaily() {
return mPrefs.getInt(PREF_KEY_DOSES_DAILY, 0);
}
+ @Override
+ public int getDayWeekly() {
+ return mPrefs.getInt(PREF_KEY_WEEKLY_DAY,1);
+ }
+
@Override
public void setDosesDaily(int value) {
mPrefs.edit().putInt(PREF_KEY_DOSES_DAILY, value).apply();
}
+ @Override
+ public void setDayWeekly(int value) {
+ mPrefs.edit().putInt(PREF_KEY_WEEKLY_DAY,value).apply();
+ }
+
@Override
public int checkDosesWeekly() {
return mPrefs.getInt(PREF_KEY_DOSES_WEEKLY, 0);
@@ -144,30 +163,9 @@ public void setMedicineLastTakenTime(String time) {
mPrefs.edit().putString(PREF_KEY_MEDICINE_LAST_TAKEN_TIME, time).apply();
}
- @Override
- public boolean getMythFactGame() {
- return mPrefs.getBoolean(PREF_KEY_MYTH_FACT_GAME, true);
- }
-
- @Override
- public void setMythFactGame(boolean val) {
- mPrefs.edit().putBoolean(PREF_KEY_MYTH_FACT_GAME, val).apply();
- }
-
- @Override
- public boolean getRapidFireGame() {
- return mPrefs.getBoolean(PREF_KEY_RAPID_FIRE_GAME, true);
- }
-
- @Override
- public void setRapidFireGame(boolean val) {
- mPrefs.edit().putBoolean(PREF_KEY_RAPID_FIRE_GAME, val).apply();
- }
-
- //Todo check default value once again
@Override
public String getToneUri() {
- return mPrefs.getString(PREF_KEY_TONE_URI, null);
+ return mPrefs.getString(PREF_KEY_TONE_URI, "");
}
@Override
@@ -264,4 +262,74 @@ public String getReminderMessageForTrip() {
public void setReminderMessageForTrip(String messageForTrip) {
mPrefs.edit().putString(PREF_KEY_TRIP_REMINDER, messageForTrip).apply();
}
+
+ @Override
+ public void setLongWeeklyDate(long value) {
+ mPrefs.edit().putLong(PREF_KEY_WEEKLY_DATE, value).apply();
+ }
+
+ @Override
+ public long getLongWeeklyDate() {
+ return mPrefs.getLong(PREF_KEY_WEEKLY_DATE, 0);
+ }
+
+ @Override
+ public void setDateDrugTaken(long value) {
+ mPrefs.edit().putLong(PREF_KEY_DAILY_DRUG_DATE, value).apply();
+ }
+
+ @Override
+ public long getDateDrug() {
+ return mPrefs.getLong(PREF_KEY_DAILY_DRUG_DATE, 0);
+ }
+
+ @Override
+ public void setWeeklyDrugTaken(boolean value) {
+ mPrefs.edit().putBoolean(PREF_KEY_IS_WEEKLY_DRUG_TAKEN, value).apply();
+ }
+
+ @Override
+ public boolean isWeeklyDrugTaken() {
+ return mPrefs.getBoolean(PREF_KEY_IS_WEEKLY_DRUG_TAKEN, false);
+ }
+
+ @Override
+ public boolean isDailyDrugTaken() {
+ return mPrefs.getBoolean(PREF_KEY_IS_DAILY_DRUG_TAKEN, false);
+ }
+
+ @Override
+ public void setDailyDrugTaken(boolean value) {
+ mPrefs.edit().putBoolean(PREF_KEY_IS_DAILY_DRUG_TAKEN, value).apply();
+ }
+
+ @Override
+ public int getDrugRejectedCount() {
+ return mPrefs.getInt(PREF_KEY_DRUG_REJECTED_COUNT, 0);
+ }
+
+ @Override
+ public void setDrugRejectedCount(int value) {
+ mPrefs.edit().putInt(PREF_KEY_DRUG_REJECTED_COUNT, value).apply();
+ }
+
+ @Override
+ public boolean checkRapidFireTarget() {
+ return mPrefs.getBoolean(PREF_KEY_RAPID_FIRE_TARGET, false);
+ }
+
+ @Override
+ public void setRapidFireTarget(boolean value) {
+ mPrefs.edit().putBoolean(PREF_KEY_RAPID_FIRE_TARGET, value).apply();
+ }
+
+ @Override
+ public boolean checkMythFactTarget() {
+ return mPrefs.getBoolean(PREF_KEY_MYTH_FACT_TARGET, false);
+ }
+
+ @Override
+ public void setMythFactTarget(boolean value) {
+ mPrefs.edit().putBoolean(PREF_KEY_MYTH_FACT_TARGET, value).apply();
+ }
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/prefs/PreferencesHelper.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/prefs/PreferencesHelper.java
index 9e31f63a..f4bddc68 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/data/prefs/PreferencesHelper.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/data/prefs/PreferencesHelper.java
@@ -14,19 +14,17 @@ public interface PreferencesHelper {
int getDrugAcceptedCount();
void setDrugAcceptedCount(int value);
boolean isDosesWeekly();
- void setDoesWeekly(boolean value);
+ void setDoseWeekly(boolean value);
int checkDosesDaily();
+ int getDayWeekly();
void setDosesDaily(int value);
+ void setDayWeekly(int value);
int checkDosesWeekly();
void setDosesWeekly(int value);
int getMedicineStoreValue();
void setMedicineStoreValue(int value);
String getMedicineLastTakenTime();
void setMedicineLastTakenTime(String time);
- boolean getMythFactGame();
- void setMythFactGame(boolean val);
- boolean getRapidFireGame();
- void setRapidFireGame(boolean val);
String getToneUri();
void setToneUri(String uri);
String getTripDate();
@@ -47,5 +45,18 @@ public interface PreferencesHelper {
void setAlertNumberDaysOrWeeks(int value);
String getReminderMessageForTrip();
void setReminderMessageForTrip(String messageForTrip);
-
+ void setLongWeeklyDate(long value);
+ long getLongWeeklyDate();
+ void setDateDrugTaken(long value);
+ long getDateDrug();
+ void setWeeklyDrugTaken(boolean value);
+ boolean isWeeklyDrugTaken();
+ void setDailyDrugTaken(boolean value);
+ boolean isDailyDrugTaken();
+ int getDrugRejectedCount();
+ void setDrugRejectedCount(int value);
+ boolean checkRapidFireTarget();
+ void setRapidFireTarget(boolean value);
+ boolean checkMythFactTarget();
+ void setMythFactTarget(boolean value);
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/db/DatabaseSQLiteHelper.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/db/DatabaseSQLiteHelper.java
index 5a717850..944af60b 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/db/DatabaseSQLiteHelper.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/db/DatabaseSQLiteHelper.java
@@ -10,9 +10,7 @@
import com.peacecorps.malaria.code.model.SharedPreferenceStore;
import com.peacecorps.malaria.utils.CalendarFunction;
-import com.peacecorps.malaria.utils.*;
-import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@@ -379,7 +377,8 @@ public String getStatus(int date,int month,int year){
SQLiteDatabase sqDB = getWritableDatabase();
String []column = {"Status"};
String []selArgs = {""+date,""+month,""+year};
- Cursor cursor= sqDB.query(userMedicationChoiceTable,column,"Date =? AND Month =? AND Year =?",selArgs,null,null,null,null);
+ Cursor cursor= sqDB.query(userMedicationChoiceTable,column,"Date =? AND Month =? AND Year =?",
+ selArgs,null,null,null,null);
while(cursor.moveToNext())
{
@@ -393,7 +392,6 @@ public String getStatus(int date,int month,int year){
/**From the Last Time Pill was Taken it Calculates the maximum days in a row medication was taken
* Need at Home Screen, First Analytic Scrren, Second Analytic Scrren, Day Fragment Screen
* Main Activity for updating the dosesInArow as it changes according to the status we enter.**/
- //Todo make it later
public int getDosesInaRowDaily()
{
SQLiteDatabase sqDB = getWritableDatabase();
@@ -708,7 +706,8 @@ public int getCountTaken()
{
SQLiteDatabase sqDB = getWritableDatabase();
String []column={"Status","Timestamp","Date","Month","Year","Choice"};
- Cursor cursor= sqDB.query(userMedicationChoiceTable,column,null,null,null,null,"Timestamp ASC");
+ Cursor cursor= sqDB.query(userMedicationChoiceTable,column,null,null,null,
+ null,"Timestamp ASC");
int count=0;
if(cursor!=null)
{
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/notifications/DrugNotificationUtils.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/notifications/DrugNotificationUtils.java
new file mode 100644
index 00000000..0772fe06
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/notifications/DrugNotificationUtils.java
@@ -0,0 +1,159 @@
+package com.peacecorps.malaria.notifications;
+
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Build;
+import android.support.v4.app.NotificationCompat;
+import android.support.v4.content.ContextCompat;
+
+import com.peacecorps.malaria.R;
+import com.peacecorps.malaria.data.AppDataManager;
+import com.peacecorps.malaria.data.db.DbHelper;
+import com.peacecorps.malaria.notifications.receiver.DrugNotificationReceiver;
+import com.peacecorps.malaria.ui.main.MainActivity;
+import com.peacecorps.malaria.utils.InjectionClass;
+import com.peacecorps.malaria.utils.ToastLogSnackBarUtil;
+
+import java.util.Calendar;
+
+public class DrugNotificationUtils {
+ private static final int START_ACTIVITY_PENDING_INTENT_ID = 245;
+ private static final int ACTION_ACCEPT_PENDING_INTENT_ID = 502;
+ private static final int ACTION_REJECT_PENDING_INTENT_ID = 504;
+ public static final int ACTION_SNOOZE_PENDING_INTENT_ID = 506;
+ private static final String NOTIFICATION_CHANNEL_ID = "drug_reminder_channel_id";
+ private static final int NOTIFICATION_MANAGER_ID = 568;
+
+ public static final String ACTION_ACCEPTED_MEDICINE = "ACTION_ACCEPTED_MEDICINE";
+ public static final String ACTION_REJECT_MEDICINE = "ACTION_REJECT_MEDICINE";
+ public static final String ACTION_SNOOZE_MEDICINE = "ACTION_SNOOZE_MEDICINE";
+
+ // function to create and start notification for drug reminder
+ private static void startNotificationForDrugs(boolean snooze, Context context) {
+ NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+
+ if(Build.VERSION.SDK_INT>Build.VERSION_CODES.O) {
+ NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
+ context.getString(R.string.drug_reminder_notification_title),
+ NotificationManager.IMPORTANCE_DEFAULT);
+ if (manager != null) {
+ manager.createNotificationChannel(channel);
+ }
+ }
+
+ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
+ .setColor(ContextCompat.getColor(context, R.color.lightest_brown))
+ .setContentTitle(context.getString(R.string.drug_reminder_notification_title))
+ .setContentText(context.getString(R.string.drug_reminder_notification_message))
+ .setContentIntent(contentIntent(context))
+ .setDefaults(Notification.DEFAULT_VIBRATE)
+ .setSmallIcon(R.drawable.app_icon)
+ .setStyle(new NotificationCompat.BigTextStyle().bigText(
+ context.getString(R.string.drug_reminder_notification_message)))
+ .addAction(acceptMedicineAction(context))
+ .addAction(rejectMedicineAction(context))
+ .setWhen(0)
+ .setAutoCancel(true);
+
+ if(snooze) {
+ notificationBuilder.addAction(snoozeAction(context));
+ }
+
+ Uri sound = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.soundsmedication);
+
+ if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN &&
+ Build.VERSION.SDK_INT 0) {
+ saveUserSettings(state, false);
+ calculateAdherenceAndSetUserSelection(interval, drugPicked, "daily", status);
+ }
+ }
+
+ private void calculateAdherenceAndSetUserSelection(final double interval, final String drugPicked, final String choice,
+ final String status) {
+ dataManager.getMedicineCountTaken(new DbHelper.LoadIntegerCallback() {
+ @Override
+ public void onDataLoaded(int takenCount) {
+ double adherenceRate = ((double) takenCount / interval) * 100;
+ dataManager.setUserMedicineSelection(drugPicked, choice, Calendar.getInstance().getTime(),
+ status, adherenceRate);
+ }
+ });
+ }
+
+ private void playBlackGroundSound(Context context) {
+ Uri sound = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.soundsmedication);
+ final MediaPlayer mp = MediaPlayer.create(context, sound);
+ mp.start();
+ }
+
+ /**
+ * Function to set the alarm for next week
+ */
+ private void changeWeeklyAlarmTime(Context context) {
+ int hour = Calendar.getInstance().get(Calendar.HOUR);
+ int minute = Calendar.getInstance().get(Calendar.MINUTE) - 1;
+ context.startService(
+ new Intent(context, AlarmService.class));
+ dataManager.updateAlarmTime(hour, minute);
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/services/AlarmService.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/notifications/service/AlarmService.java
similarity index 63%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/services/AlarmService.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/notifications/service/AlarmService.java
index 7409bdec..abb78d29 100755
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/services/AlarmService.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/notifications/service/AlarmService.java
@@ -1,16 +1,17 @@
-package com.peacecorps.malaria.services;
+package com.peacecorps.malaria.notifications.service;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
-import com.peacecorps.malaria.code.reciever.AlarmHandlerClass;
+import com.peacecorps.malaria.notifications.receiver.AlarmHandlerClass;
+/**
+ * setting up alarm using the service
+ */
public class AlarmService extends Service {
- /**Setting up Alarm Calls his Alarm Service**/
-
- AlarmHandlerClass alarmHandlerClass = new AlarmHandlerClass();
+ private AlarmHandlerClass alarmHandlerClass = new AlarmHandlerClass();
@Override
public IBinder onBind(Intent intent) {
@@ -19,7 +20,6 @@ public IBinder onBind(Intent intent) {
}
public void onStart(Intent intent, int startId) {
-
alarmHandlerClass.setAlarm(AlarmService.this);
}
@@ -30,9 +30,12 @@ public void onCreate() {
}
+ /**
+ * alarm service request made
+ * alarm handler will start alarm
+ */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- /**Alarm Service Request Made and Alarm Handler will Handle It. **/
alarmHandlerClass.setAlarm(AlarmService.this);
return START_STICKY;
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/services/NotificationUtils.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/services/NotificationUtils.java
deleted file mode 100644
index e9f2bb97..00000000
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/services/NotificationUtils.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.peacecorps.malaria.services;
-
-import android.app.Notification;
-import android.app.NotificationChannel;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Build;
-import android.support.v4.app.NotificationCompat;
-import android.support.v4.content.ContextCompat;
-
-import com.peacecorps.malaria.R;
-import com.peacecorps.malaria.ui.home_screen.MainActivity;
-
-public class NotificationUtils {
- private static final int PENDING_INTENT_ID = 245;
- private static final String NOTICATION_CHANNEL_ID = "drug_reminder_channel_id";
- private static final int NOTICATION_MANAGER_ID = 568;
-
- // function to create and start notification for drug reminder
- public void startNotificationForDrugs(Context context) {
- NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
-
- if(Build.VERSION.SDK_INT>Build.VERSION_CODES.O) {
- NotificationChannel channel = new NotificationChannel(NOTICATION_CHANNEL_ID,
- context.getString(R.string.drug_reminder_notification_title),
- NotificationManager.IMPORTANCE_DEFAULT);
- if (manager != null) {
- manager.createNotificationChannel(channel);
- }
- }
-
-// //Todo can still add large icon, small icon & style
- NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
- .setColor(ContextCompat.getColor(context, R.color.lightest_brown))
- .setContentTitle(context.getString(R.string.drug_reminder_notification_title))
- .setContentText(context.getString(R.string.drug_reminder_notification_message))
- .setContentIntent(contentIntent(context))
- .setDefaults(Notification.DEFAULT_VIBRATE)
- .setAutoCancel(true);
-
- if (manager != null) {
- manager.notify(NOTICATION_MANAGER_ID, notificationBuilder.build());
- }
-
-
- }
-
- // returns a pending intent for main activity
- private PendingIntent contentIntent(Context context) {
- Intent activityIntent = new Intent(context, MainActivity.class);
- return PendingIntent.getActivity(context, PENDING_INTENT_ID, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
- }
-}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/base/MyApp.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/base/MyApp.java
new file mode 100644
index 00000000..bddf7856
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/base/MyApp.java
@@ -0,0 +1,19 @@
+package com.peacecorps.malaria.ui.base;
+
+import android.app.Application;
+
+import com.peacecorps.malaria.utils.TypefaceUtil;
+
+/**
+ * Created by Anamika Tripathi on 7/8/18.
+ */
+public class MyApp extends Application {
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ TypefaceUtil.overrideFont(getApplicationContext(), "SERIF",
+ "fonts/garreg.ttf");
+
+ }
+}
\ No newline at end of file
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/HomeContract.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/HomeContract.java
index 247b57c7..15909d79 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/HomeContract.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/HomeContract.java
@@ -1,13 +1,35 @@
package com.peacecorps.malaria.ui.home_screen;
+import com.peacecorps.malaria.ui.base.MvpPresenter;
import com.peacecorps.malaria.ui.base.MvpView;
+/**
+ * Created by Anamika Tripathi on 5/8/18.
+ */
public interface HomeContract {
- interface IHomeView extends MvpView {
- void startMedicineSettingActivity();
+
+ interface HomeMvpView extends MvpView{
+ void setCurrentDayAndDate(String date, String day);
+ void setWarningText();
+ void isDrugTakenUI();
+ void isDrugNotTakenUI();
+ void newDayUI();
+ void missedWeekUI();
+ void startAlarmServiceClass();
+
}
- interface IHomePresenter {
- void resetDatabase();
+ interface HomeMvpPresenter extends MvpPresenter {
+ void checkDayDateOfWeek();
+ void checkWarningVisibility();
+ void increaseDrugAcceptedCount();
+ void updateUserMedicineSelection(double adherenceRate, boolean isAcceptButton);
+ void checkDrugIntervalFirstRunTime(boolean isAcceptButton);
+ void decideDrugTakenUIBoolean(boolean isWeekly, boolean isTaken);
+ void increaseDrugRejectCount();
+ void decideDrugTakenForUI();
+ void checkDrugIntervalWeeklyDate();
+ void storeMediTimeLastChecked();
+
}
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/HomePresenter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/HomePresenter.java
index 424fd8d2..22404a2d 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/HomePresenter.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/HomePresenter.java
@@ -1,20 +1,325 @@
package com.peacecorps.malaria.ui.home_screen;
+import android.annotation.SuppressLint;
import android.content.Context;
+import android.content.Intent;
import com.peacecorps.malaria.data.AppDataManager;
+import com.peacecorps.malaria.data.db.DbHelper;
+import com.peacecorps.malaria.notifications.service.AlarmService;
import com.peacecorps.malaria.ui.base.BasePresenter;
-import com.peacecorps.malaria.ui.home_screen.HomeContract.IHomePresenter;
+import com.peacecorps.malaria.ui.home_screen.HomeContract.HomeMvpView;
+import com.peacecorps.malaria.utils.CalendarFunction;
+import com.peacecorps.malaria.utils.ToastLogSnackBarUtil;
-public class HomePresenter extends BasePresenter implements IHomePresenter {
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+/**
+ * Created by Anamika Tripathi on 5/8/18.
+ */
+public class HomePresenter extends BasePresenter implements HomeContract.HomeMvpPresenter {
HomePresenter(AppDataManager manager, Context context) {
super(manager, context);
}
+ /**
+ * takes date from calendar, uses SimpleDataFormat to parse date in to current Day & date in specific format
+ * calls setCurrentDayAndDelete to set date+day in fragment
+ */
@Override
- public void resetDatabase() {
- //Todo reset preferences too
- getDataManager().resetDatabase();
+ public void checkDayDateOfWeek() {
+ @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("EEEE", Locale.getDefault());
+ Date d = new Date();
+ String dayOfTheWeek = sdf.format(d);
+ String date = new SimpleDateFormat("dd/MM/yyyy",
+ Locale.getDefault()).format(d);
+ getView().setCurrentDayAndDate(date, dayOfTheWeek);
}
+
+ /**
+ * check if medicine in Store count is less than user's setting for warning?
+ * If yes, show warning message
+ */
+ @Override
+ public void checkWarningVisibility() {
+ // alert ime set by user in MedicineStoreFragment
+ int alertTime = getDataManager().getAlertNumberDaysOrWeeks();
+ int medicineCount = getDataManager().getMedicineStoreValue();
+ //display warning
+ if (alertTime != 1 && medicineCount < alertTime) {
+ getView().setWarningText();
+ }
+
+ }
+
+ /**
+ * decides UI decision by drug history saved in preferences
+ * calls appropriate getView function to update UI
+ */
+ @Override
+ public void decideDrugTakenForUI() {
+ final long today = new Date().getTime();
+ getDataManager().getFirstTimeByTimeStamp(new DbHelper.LoadLongCallback() {
+ @Override
+ public void onDataLoaded(Long value) {
+ long takenWeeklyDate = getDataManager().getLongWeeklyDate();
+ long takenDailyDate = getDataManager().getDateDrug();
+ boolean isWeekly = getDataManager().isDosesWeekly();
+ boolean isWeeklyDrugTaken = getDataManager().isWeeklyDrugTaken();
+ if (isWeekly) {
+ long interval;
+ long oneDay = 1000 * 60 * 60 * 24;
+ interval = (today - takenWeeklyDate) / oneDay;
+
+ if (interval == 0) {
+ if (isWeeklyDrugTaken) {
+ getView().isDrugTakenUI();
+ } else {
+ getView().newDayUI();
+ }
+ } else {
+ if (interval < 7 && interval > 0) {
+ if (isWeeklyDrugTaken) {
+ getView().isDrugTakenUI();
+ } else {
+ getDataManager().setDosesWeekly(0);
+ getView().missedWeekUI();
+ getView().newDayUI();
+ }
+ } else if (interval > 7) {
+ getDataManager().setDrugAcceptedCount(0);
+ getDataManager().setDosesWeekly(0);
+ getView().missedWeekUI();
+ getView().newDayUI();
+ }
+ }
+ } else {
+ long interval;
+ long oneDay = 1000 * 60 * 60 * 24;
+ interval = (today - takenDailyDate) / oneDay;
+ if (interval == 0) {
+ if (getDataManager().isDrugTaken()) {
+ getView().isDrugTakenUI();
+ } else {
+ getView().isDrugNotTakenUI();
+ }
+ } else {
+ if (interval > 1) {
+ getDataManager().setDosesDaily(0);
+ }
+ getView().newDayUI();
+ }
+ }
+ }
+ });
+
+ }
+
+ /**
+ * increases drug accepted count in preferences
+ */
+ @Override
+ public void increaseDrugAcceptedCount() {
+ // get the value
+ int value = getDataManager().getDrugAcceptedCount();
+ // increase by 1
+ getDataManager().setDrugAcceptedCount(value + 1);
+ }
+
+ /**
+ * used to update in db if medicine is taken or not
+ * decrease current medicine count in preferences if taken
+ * increase user-points in preferences if taken
+ */
+ @Override
+ public void updateUserMedicineSelection(double adherenceRate, boolean isAcceptButton) {
+ // returns true if weekly or false for daily
+ boolean isWeekly = getDataManager().isDosesWeekly();
+ String drugPicked = getDataManager().getDrugPicked();
+ Date date = Calendar.getInstance().getTime();
+ if (isAcceptButton) {
+ if (isWeekly) {
+ decideDrugTakenUIBoolean(true, true);
+ getDataManager().setUserMedicineSelection(drugPicked, "weekly", date,
+ "yes", adherenceRate);
+ getDataManager().getDosesInaRowWeekly(new DbHelper.LoadIntegerCallback() {
+ @Override
+ public void onDataLoaded(int value) {
+ getDataManager().setDosesWeekly(value);
+ }
+ });
+ } else {
+ decideDrugTakenUIBoolean(false, true);
+ getDataManager().setUserMedicineSelection(drugPicked, "daily", date, "yes", adherenceRate);
+ getDataManager().getDosesInaRowDaily(new DbHelper.LoadIntegerCallback() {
+ @Override
+ public void onDataLoaded(int value) {
+ getDataManager().setDosesDaily(value);
+ }
+ });
+ }
+ //get user's score
+ int score = getDataManager().getUserScore();
+ //get medicine in store
+ int medicineStore = getDataManager().getMedicineStoreValue();
+ //increase score if medicine is taken
+ getDataManager().setUserScore(score + 1);
+ //decrease medicine store by one if medicine is taken
+ getDataManager().setMedicineStoreValue(medicineStore - 1);
+ ToastLogSnackBarUtil.showDebugLog("HomePresenter/updateUserMedicineSelection: score updated");
+ } else {
+ if (isWeekly) {
+ decideDrugTakenUIBoolean(true, false);
+ getDataManager().setUserMedicineSelection(drugPicked, "weekly", date, "no", adherenceRate);
+ } else {
+ decideDrugTakenUIBoolean(false, false);
+ getDataManager().setUserMedicineSelection(drugPicked, "daily", date, "no", adherenceRate);
+ }
+ }
+ }
+
+ /**
+ * determines interval for firstRunTime and calls computerAdherenceInterval to calculate adherence
+ */
+ @Override
+ public void checkDrugIntervalFirstRunTime(final boolean isAcceptButton) {
+
+ final long today = new Date().getTime();
+ getDataManager().getFirstTimeByTimeStamp(new DbHelper.LoadLongCallback() {
+ @Override
+ public void onDataLoaded(Long value) {
+ long interval;
+ if (value != 0) {
+ ToastLogSnackBarUtil.showDebugLog("First Run Time at FAF->" + value);
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(value);
+ cal.add(Calendar.MONTH, 1);
+
+ Date start = cal.getTime();
+ Date end = Calendar.getInstance().getTime();
+ end.setTime(today);
+ // saving in preferences
+ getDataManager().setFirstRunTime(value);
+ if (getDataManager().isDosesWeekly()) {
+ int dayWeekly = getDataManager().getDayWeekly();
+ interval = CalendarFunction.getIntervalWeekly(start, end, dayWeekly);
+ } else {
+ interval = CalendarFunction.getIntervalDaily(start, end);
+ }
+ } else {
+ interval = 1;
+ }
+ computeAdherenceRate(interval, isAcceptButton);
+ }
+ });
+
+ }
+
+ @Override
+ public void checkDrugIntervalWeeklyDate() {
+ final long today = new Date().getTime();
+ final long takenDate = getDataManager().getLongWeeklyDate();
+ getDataManager().getFirstTimeByTimeStamp(new DbHelper.LoadLongCallback() {
+ @Override
+ public void onDataLoaded(Long value) {
+ if (takenDate == 0) {
+ long oneDay = 1000 * 60 * 60 * 24;
+ long interval;
+ interval = (today - takenDate) / oneDay;
+ if (interval > 1) {
+ changeWeeklyAlarmTime();
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * @param interval : interval between drug taken time
+ * desc : calculates adherence rate & calls updateUserMedicineSelection
+ */
+ private void computeAdherenceRate(final long interval, final boolean isAcceptButton) {
+ getDataManager().getMedicineCountTaken(new DbHelper.LoadIntegerCallback() {
+ @Override
+ public void onDataLoaded(int value) {
+ double adherenceRate = ((double) value / (double) interval) * 100;
+ ToastLogSnackBarUtil.showDebugLog("HomePresenter/computerAdherence: " + interval + " " + value + " " + adherenceRate);
+ updateUserMedicineSelection(adherenceRate, isAcceptButton);
+ }
+ });
+ }
+
+ /**
+ * @param isWeekly : determines if drug is weekly or daily
+ * @param isTaken : determines if it is taken or not/depends on accept or reject button
+ */
+ @Override
+ public void decideDrugTakenUIBoolean(boolean isWeekly, boolean isTaken) {
+ if (isWeekly) {
+ checkDrugIntervalWeeklyDate();
+ }
+ saveUserSettings(isTaken, isWeekly);
+ if (isTaken) {
+ getView().isDrugTakenUI();
+ } else {
+ getView().isDrugNotTakenUI();
+ }
+ }
+
+ /**
+ * increase drug reject count in preferences
+ */
+ @Override
+ public void increaseDrugRejectCount() {
+ int value = getDataManager().getDrugRejectedCount();
+ getDataManager().setDrugRejectedCount(value + 1);
+ }
+
+ /**
+ * set last medicine taken time
+ * used in isDrugTakenUI
+ */
+ @Override
+ public void storeMediTimeLastChecked() {
+ String lastMedicationCheckedTime = "";
+ Calendar c = Calendar.getInstance();
+ lastMedicationCheckedTime = new SimpleDateFormat("dd/MM/yyyy",
+ Locale.getDefault()).format(c.getTime());
+ getDataManager().setMedicineLastTakenTime(lastMedicationCheckedTime);
+ }
+
+ /**
+ * @param isTaken : determines if it is taken or not/depends on accept or reject button
+ * @param isWeekly : determines if drug is weekly or daily
+ * desc : checks weekly or daily drug, updates preference data
+ */
+ private void saveUserSettings(boolean isTaken, boolean isWeekly) {
+ if (isWeekly) {
+ // updates on last taken date
+ getDataManager().setLongWeeklyDate(new Date().getTime());
+ // sets true or false if drug is taken or not
+ getDataManager().setWeeklyDrugTaken(isTaken);
+ } else {
+ getDataManager().setDateDrugTaken(new Date().getTime());
+ getDataManager().setDrugTaken(isTaken);
+ }
+ // increases drug accepted count
+ int count = getDataManager().getDrugAcceptedCount();
+ getDataManager().setDrugAcceptedCount(count + 1);
+ }
+
+ private void changeWeeklyAlarmTime() {
+ int hour = Calendar.getInstance().get(Calendar.HOUR);
+ int minute = Calendar.getInstance().get(Calendar.MINUTE) - 1;
+
+ if (getContext() != null) {
+ getContext().startService(new Intent(getContext(), AlarmService.class));
+ }
+ getView().startAlarmServiceClass();
+ getDataManager().updateAlarmTime(hour, minute);
+ }
+
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/HomeScreenFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/HomeScreenFragment.java
new file mode 100644
index 00000000..de9d998c
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/HomeScreenFragment.java
@@ -0,0 +1,187 @@
+package com.peacecorps.malaria.ui.home_screen;
+
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Color;
+import android.graphics.Typeface;
+import android.media.MediaPlayer;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.TextView;
+
+import com.peacecorps.malaria.R;
+import com.peacecorps.malaria.notifications.service.AlarmService;
+import com.peacecorps.malaria.ui.base.BaseFragment;
+import com.peacecorps.malaria.utils.InjectionClass;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
+
+/**
+ * Created by Anamika Tripathi on 5/8/18.
+ */
+public class HomeScreenFragment extends BaseFragment implements HomeContract.HomeMvpView {
+
+
+ private Context context;
+ private HomePresenter presenter;
+ @BindView(R.id.btn_accept_medication)
+ Button mAcceptMedicationButton;
+ @BindView(R.id.btn_reject_medication)
+ Button mRejectMedicationButton;
+ @BindView(R.id.tv_current_date)
+ TextView mCurrentDateLabel;
+ @BindView(R.id.tv_day_of_week)
+ TextView mCurrentDayOfweekLabel;
+ @BindView(R.id.warningView)
+ TextView warningView;
+ @BindView(R.id.warningButton)
+ Button warningButton;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
+ @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_home_screen, container, false);
+ context = getContext();
+ ButterKnife.bind(this, view);
+ presenter = new HomePresenter<>(InjectionClass.provideDataManager(context), context);
+ presenter.attachView(this);
+ return view;
+ }
+
+ @Override
+ protected int getContentResource() {
+ return R.layout.fragment_home_screen;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ init();
+ }
+
+ // get drug accepted + rejected count from preferences
+ @Override
+ protected void init() {
+ // setting font for day & date labels
+ setFont();
+ // checking current date and day
+ presenter.checkDayDateOfWeek();
+ // checking visibility of warning text using preferences
+ presenter.checkWarningVisibility();
+ // decide drug taken for UI
+ presenter.decideDrugTakenForUI();
+ }
+
+ // set current date and day
+ @Override
+ public void setCurrentDayAndDate(String date, String day) {
+ mCurrentDateLabel.setText(date);
+ mCurrentDayOfweekLabel.setText(day);
+ }
+
+ // make warning text visible
+ @Override
+ public void setWarningText() {
+ warningView.setVisibility(View.VISIBLE);
+ warningButton.setVisibility(View.VISIBLE);
+
+ }
+
+ @Override
+ public void isDrugTakenUI() {
+ mCurrentDateLabel.setTextColor(Color.rgb(89, 43, 21));
+ mCurrentDayOfweekLabel.setTextColor(Color.rgb(89, 43, 21));
+ mAcceptMedicationButton
+ .setBackgroundResource(R.drawable.accept_medi_checked_);
+ mRejectMedicationButton
+ .setBackgroundResource(R.drawable.reject_medi_grayscale);
+ setButtonState(false);
+ presenter.storeMediTimeLastChecked();
+ }
+
+ @Override
+ public void isDrugNotTakenUI() {
+ mAcceptMedicationButton
+ .setBackgroundResource(R.drawable.accept_medi_grayscale);
+ mRejectMedicationButton
+ .setBackgroundResource(R.drawable.reject_medi_checked);
+ setButtonState(false);
+ }
+
+ @Override
+ public void newDayUI() {
+ mAcceptMedicationButton
+ .setBackgroundResource(R.drawable.accept_medi_checked_);
+ mRejectMedicationButton
+ .setBackgroundResource(R.drawable.reject_medi_checked);
+ setButtonState(true);
+ }
+
+ @Override
+ public void missedWeekUI() {
+ mCurrentDateLabel.setTextColor(Color.RED);
+ mCurrentDayOfweekLabel.setTextColor(Color.RED);
+ }
+
+ @Override
+ public void startAlarmServiceClass() {
+ if (getActivity() != null) {
+ getActivity().startService(
+ new Intent(getActivity(), AlarmService.class));
+ }
+ }
+
+ public void setButtonState(boolean state) {
+ mAcceptMedicationButton.setEnabled(state);
+ mRejectMedicationButton.setEnabled(state);
+ }
+
+ // setting fonts from assets file
+ private void setFont() {
+ if (getActivity() != null) {
+ Typeface custom_font = Typeface.createFromAsset(context.getAssets(), "fonts/garreg.ttf");
+ mCurrentDayOfweekLabel.setTypeface(custom_font);
+ mCurrentDateLabel.setTypeface(custom_font);
+ }
+ }
+
+ @OnClick(R.id.fragment_home_screen_set_tone_button)
+ public void reminderButtonListener() {
+ Intent myIntent = new Intent(getActivity(), ReminderToneActivity.class);
+ startActivity(myIntent);
+ }
+
+ @OnClick(R.id.btn_accept_medication)
+ public void acceptButtonListener() {
+ // create media player for sound
+ MediaPlayer.create(getActivity(), R.raw.accept_button_sound)
+ .start();
+ // increase drug accepted count by 1
+ presenter.increaseDrugAcceptedCount();
+
+ presenter.checkDrugIntervalFirstRunTime(true);
+ }
+
+ @OnClick(R.id.btn_reject_medication)
+ public void rejectButtonListener() {
+
+ MediaPlayer.create(getActivity(), R.raw.reject_button_sound)
+ .start();
+ presenter.increaseDrugRejectCount();
+
+ presenter.checkDrugIntervalFirstRunTime(false);
+ }
+
+// @OnClick(R.id.fragment_home_screen_settings_button)
+// public void settingListener() {
+// DrugNotificationUtils.startNotificationCheckSnooze(context);
+// }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/activities/RemainderToneActivity.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/ReminderToneActivity.java
similarity index 59%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/code/activities/RemainderToneActivity.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/ReminderToneActivity.java
index 27833f1c..a798dd08 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/activities/RemainderToneActivity.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/ReminderToneActivity.java
@@ -1,37 +1,33 @@
-package com.peacecorps.malaria.code.activities;
+package com.peacecorps.malaria.ui.home_screen;
import android.app.Activity;
import android.content.Intent;
-import android.content.SharedPreferences;
-import android.media.Ringtone;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
-import android.widget.Toast;
import com.peacecorps.malaria.R;
+import com.peacecorps.malaria.data.AppDataManager;
+import com.peacecorps.malaria.utils.InjectionClass;
+import com.peacecorps.malaria.utils.ToastLogSnackBarUtil;
+
/**
* Created by DELL on 1/16/2016.
*/
-public class RemainderToneActivity extends Activity implements View.OnClickListener{
+public class ReminderToneActivity extends Activity implements View.OnClickListener{
- Button btnBrowse;
- EditText path;
- Button btnOK ;
- Button btnCancel;
- Ringtone ringtone;
- String MP3Path;
- Uri audioFileUri;
+ private EditText path;
+ private Uri audioFileUri;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.remainder_tone_dialog);
- btnBrowse=(Button)findViewById(R.id.browse);
- path=(EditText)findViewById(R.id.tone_path);
- btnOK=(Button)findViewById(R.id.dialogButtonOKReminder);
- btnCancel= (Button)findViewById(R.id.dialogButtonCancelReminder);
+ Button btnBrowse = findViewById(R.id.browse);
+ path= findViewById(R.id.tone_path);
+ Button btnOK = findViewById(R.id.dialogButtonOKReminder);
+ Button btnCancel = findViewById(R.id.dialogButtonCancelReminder);
btnBrowse.setOnClickListener(this);
btnOK.setOnClickListener(this);
btnCancel.setOnClickListener(this);
@@ -54,25 +50,26 @@ public void onClick(View v) {
path.setError("Specify valid path");
break;
}
- SharedPreferences.Editor editor = getSharedPreferences("ringtone", MODE_PRIVATE).edit();
- editor.putString("toneUri", audioFileUri.toString());
- editor.commit();
- Toast.makeText(getApplicationContext(), "Reminder Tone Set", Toast.LENGTH_SHORT).show();
+ AppDataManager dataManager = InjectionClass.provideDataManager(this);
+ dataManager.setToneUri(audioFileUri.toString());
+ ToastLogSnackBarUtil.showToast(this, "Reminder Tone Set");
+ dataManager = null;
this.finish();
break;
case R.id.dialogButtonCancelReminder:
this.finish();
break;
+ default: ToastLogSnackBarUtil.showErrorLog("ReminderToneActivity: Invalid id");
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (resultCode == RESULT_OK) {
- if (requestCode == 1) {
- audioFileUri = data.getData();
- MP3Path = audioFileUri.getPath();
+ if (resultCode == RESULT_OK && requestCode == 1) {
+ audioFileUri = data.getData();
+ if(audioFileUri!=null) {
+ String MP3Path = audioFileUri.getPath();
path.setText(MP3Path);
}
}
@@ -80,8 +77,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
public boolean isAudioFile() {
if(audioFileUri!=null) {
String type= getContentResolver().getType(audioFileUri);
- boolean isAudio= "audio/mpeg".equals(type);
- return isAudio;
+ return "audio/mpeg".equals(type);
}
return false;
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/MainActivity.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/main/MainActivity.java
similarity index 72%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/MainActivity.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/ui/main/MainActivity.java
index 756a8885..900777bc 100755
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/home_screen/MainActivity.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/main/MainActivity.java
@@ -1,5 +1,4 @@
-package com.peacecorps.malaria.ui.home_screen;
-
+package com.peacecorps.malaria.ui.main;
import android.app.Dialog;
import android.content.Intent;
@@ -15,42 +14,37 @@
import android.view.View;
import com.peacecorps.malaria.R;
-import com.peacecorps.malaria.code.fragment.HomeScreenFragment;
import com.peacecorps.malaria.data.AppDataManager;
import com.peacecorps.malaria.data.db.entities.Packing;
import com.peacecorps.malaria.ui.base.BaseActivity;
-import com.peacecorps.malaria.ui.home_screen.HomeContract.IHomeView;
+import com.peacecorps.malaria.ui.home_screen.HomeScreenFragment;
+import com.peacecorps.malaria.ui.main.MainContract.IHomeView;
import com.peacecorps.malaria.ui.info_hub.InfoHubFragment;
+import com.peacecorps.malaria.ui.medicine_store.MedicineStoreActivity;
import com.peacecorps.malaria.ui.play.PlayFragment;
-import com.peacecorps.malaria.ui.play.PlayFragment.OnPlayFragmentListener;
-import com.peacecorps.malaria.ui.play.badge_screen.BadgeScreenFragment;
-import com.peacecorps.malaria.ui.play.medicine_store.MedicineStoreFragment;
-import com.peacecorps.malaria.ui.play.myth_vs_fact.MythFactFragment;
-import com.peacecorps.malaria.ui.play.rapid_fire.RapidFireFragment;
-import com.peacecorps.malaria.ui.play.rapid_fire.RapidFireFragment.OnRapidFragmentListener;
import com.peacecorps.malaria.ui.trip_reminder.PlanTripFragment;
import com.peacecorps.malaria.ui.trip_reminder.PlanTripFragment.OnPlanFragmentListener;
import com.peacecorps.malaria.ui.trip_reminder.trip_select_item.ItemDialogFragment;
import com.peacecorps.malaria.ui.trip_reminder.trip_select_item.ItemDialogFragment.OnSaveDialogListener;
import com.peacecorps.malaria.ui.user_medicine_setting.MedicineSettingsActivity;
-import com.peacecorps.malaria.ui.user_profile.UserProfileFragment;
-import com.peacecorps.malaria.ui.user_profile.UserProfileFragment.OnUserFragmentListener;
+import com.peacecorps.malaria.ui.user_profile.ProfileFragment;
import com.peacecorps.malaria.utils.BottomNavigationViewHelper;
import com.peacecorps.malaria.utils.InjectionClass;
-import com.peacecorps.malaria.utils.ToastLogSnackBarUtil;
-
-import static com.peacecorps.malaria.ui.play.myth_vs_fact.MythFactFragment.OnMythFragmentListener;
-public class MainActivity extends BaseActivity implements IHomeView, OnUserFragmentListener,
- OnPlayFragmentListener, OnMythFragmentListener, OnRapidFragmentListener, OnPlanFragmentListener,OnSaveDialogListener {
+public class MainActivity extends BaseActivity implements IHomeView,
+ OnPlanFragmentListener, OnSaveDialogListener {
- private HomePresenter presenter;
- private BottomNavigationView bottomNavigationView;
+ private Toolbar toolbar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+
+ if (savedInstanceState == null) {
+ Fragment fragment = new HomeScreenFragment();
+ loadFragment(fragment);
+ }
init();
}
@@ -58,12 +52,11 @@ public void onCreate(Bundle savedInstanceState) {
public void init() {
// setting up presenter and attaching views
AppDataManager dataManager = InjectionClass.provideDataManager(this);
- presenter = new HomePresenter<>(dataManager, this);
+ MainPresenter presenter = new MainPresenter<>(dataManager, this);
presenter.attachView(this);
- Toolbar mToolbar = findViewById(R.id.toolbar);
-
- setSupportActionBar(mToolbar);
+ toolbar = findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
// adding ic_launcher icon to the Toolbar
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@@ -74,24 +67,25 @@ public void init() {
setBottomNavigation();
}
+ @Override
+ protected void onStop() {
+ super.onStop();
+ }
+
@Override
protected void onDestroy() {
super.onDestroy();
- // detach view & make presenter null
- presenter.detachView();
- presenter = null;
}
private void setBottomNavigation() {
- bottomNavigationView = findViewById(R.id.bottom_navigation);
+ BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
// disables moving/shifting mode (by default available for >3 items in bottom navigation) for application
BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
// set home icon to be default selected & add Home screen fragment in Frame layout
bottomNavigationView.setSelectedItemId(R.id.home_screen_fragment);
bottomNavigationView.getMenu().findItem(R.id.bnv_home).setChecked(true);
- Fragment fragment = new HomeScreenFragment();
- loadFragment(fragment);
+
// listener implementation for bottom navigation, replaces frame layout with different fragments
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@@ -101,26 +95,31 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.bnv_home:
fragment = new HomeScreenFragment();
+ toolbar.setTitle(getString(R.string.app_name));
loadFragment(fragment);
break;
case R.id.bnv_trip_button:
fragment = new PlanTripFragment();
+ toolbar.setTitle("Trip details");
loadFragment(fragment);
break;
case R.id.bnv_info_button:
fragment = new InfoHubFragment();
+ toolbar.setTitle("Information hub");
loadFragment(fragment);
break;
case R.id.bnv_play_button:
fragment = new PlayFragment();
+ toolbar.setTitle("Game screen");
loadFragment(fragment);
break;
case R.id.bnv_user_profile:
- fragment = new UserProfileFragment();
+ fragment = new ProfileFragment();
+ toolbar.setTitle("Profile");
loadFragment(fragment);
break;
default:
@@ -172,6 +171,9 @@ public void onClick(View v) {
});
dialog.show();
return true;
+ } else if(item.getItemId() == R.id.btn_menu_store) {
+ startActivity(new Intent(MainActivity.this, MedicineStoreActivity.class));
+ return true;
}
return super.onOptionsItemSelected(item);
}
@@ -183,43 +185,6 @@ public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
- // starts homes fragment
- @Override
- public void startHomeFragment() {
- bottomNavigationView.setSelectedItemId(R.id.home_screen_fragment);
- loadFragment(new HomeScreenFragment());
- }
-
- /**
- * @param id : Checks id received (button IDs in playFragment, loads respective fragment)
- */
- @Override
- public void replacePlayFragment(int id) {
- switch (id) {
- case R.id.btn_badge_screen:
- loadFragment(new BadgeScreenFragment());
- break;
- case R.id.btn_myth_vs_fact:
- loadFragment(new MythFactFragment());
- break;
- case R.id.btn_medicine_store:
- loadFragment(new MedicineStoreFragment());
- break;
-
- case R.id.btn_rapid_fire:
- loadFragment(new RapidFireFragment());
- break;
- default:
- ToastLogSnackBarUtil.showToast(this, "Wrong button ");
- }
- }
-
- // starts playFragment from another child fragment
- @Override
- public void goBackToPlayFragment() {
- loadFragment(new PlayFragment());
- }
-
// replaces trip fragment with select item fragment
@Override
public void startSelectItemFragment(long quantity) {
@@ -239,7 +204,7 @@ public void startSelectItemFragment(long quantity) {
public void passMedicineSelected(Packing packing) {
Fragment fragmentInFrame = getSupportFragmentManager()
.findFragmentById(R.id.frame_container);
- if(fragmentInFrame instanceof PlanTripFragment) {
+ if (fragmentInFrame instanceof PlanTripFragment) {
PlanTripFragment tripFragment = (PlanTripFragment) fragmentInFrame;
tripFragment.updateSelectItemText(packing.getPackingItem() + ":" + packing.getPackingQuantity());
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/main/MainContract.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/main/MainContract.java
new file mode 100644
index 00000000..57998306
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/main/MainContract.java
@@ -0,0 +1,13 @@
+package com.peacecorps.malaria.ui.main;
+
+import com.peacecorps.malaria.ui.base.MvpView;
+
+public interface MainContract {
+ interface IHomeView extends MvpView {
+ void startMedicineSettingActivity();
+ }
+
+ interface IHomePresenter {
+ void resetDatabase();
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/main/MainPresenter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/main/MainPresenter.java
new file mode 100644
index 00000000..7df0ee9f
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/main/MainPresenter.java
@@ -0,0 +1,20 @@
+package com.peacecorps.malaria.ui.main;
+
+import android.content.Context;
+
+import com.peacecorps.malaria.data.AppDataManager;
+import com.peacecorps.malaria.ui.base.BasePresenter;
+import com.peacecorps.malaria.ui.main.MainContract.IHomePresenter;
+
+public class MainPresenter extends BasePresenter implements IHomePresenter {
+
+ MainPresenter(AppDataManager manager, Context context) {
+ super(manager, context);
+ }
+
+ @Override
+ public void resetDatabase() {
+ //Todo reset preferences too
+ getDataManager().resetDatabase();
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/medicine_store/MedicineStoreActivity.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/medicine_store/MedicineStoreActivity.java
new file mode 100644
index 00000000..5d14d3b8
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/medicine_store/MedicineStoreActivity.java
@@ -0,0 +1,69 @@
+package com.peacecorps.malaria.ui.medicine_store;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v7.widget.Toolbar;
+import android.view.MenuItem;
+
+import com.peacecorps.malaria.R;
+import com.peacecorps.malaria.ui.base.BaseActivity;
+
+/**
+ * Created by Anamika Tripathi on 12/8/18.
+ */
+public class MedicineStoreActivity extends BaseActivity {
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_medicine_store);
+ init();
+ }
+
+
+ @Override
+ protected void init() {
+ Toolbar toolbar = findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+ toolbar.setTitle("Medicine Store");
+ if (getSupportActionBar() != null) {
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+
+ Fragment fragment = new MedicineStoreFragment();
+ loadFragment(fragment);
+ }
+
+
+ /**
+ * @param fragment : replaces frame layout with parameter received in main activity
+ */
+ private void loadFragment(Fragment fragment) {
+ // load fragment
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+ transaction.replace(R.id.medicine_store_container, fragment, "medicine store");
+ transaction.setTransition(FragmentTransaction.TRANSIT_ENTER_MASK);
+ transaction.addToBackStack(null);
+ transaction.commit();
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+ if (id == android.R.id.home) {
+ // close activity
+ finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public void onBackPressed() {
+ super.onBackPressed();
+ finish();
+ }
+
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/medicine_store/MedicineStoreContract.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/medicine_store/MedicineStoreContract.java
similarity index 93%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/medicine_store/MedicineStoreContract.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/ui/medicine_store/MedicineStoreContract.java
index 36550951..a208799b 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/medicine_store/MedicineStoreContract.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/medicine_store/MedicineStoreContract.java
@@ -1,4 +1,4 @@
-package com.peacecorps.malaria.ui.play.medicine_store;
+package com.peacecorps.malaria.ui.medicine_store;
import com.peacecorps.malaria.ui.base.MvpPresenter;
import com.peacecorps.malaria.ui.base.MvpView;
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/medicine_store/MedicineStoreFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/medicine_store/MedicineStoreFragment.java
similarity index 96%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/medicine_store/MedicineStoreFragment.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/ui/medicine_store/MedicineStoreFragment.java
index 0b093afd..117813ec 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/medicine_store/MedicineStoreFragment.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/medicine_store/MedicineStoreFragment.java
@@ -1,4 +1,4 @@
-package com.peacecorps.malaria.ui.play.medicine_store;
+package com.peacecorps.malaria.ui.medicine_store;
import android.app.Dialog;
import android.content.Context;
@@ -17,7 +17,7 @@
import com.peacecorps.malaria.R;
import com.peacecorps.malaria.ui.base.BaseFragment;
-import com.peacecorps.malaria.ui.play.medicine_store.MedicineStoreContract.MedicineMvpView;
+import com.peacecorps.malaria.ui.medicine_store.MedicineStoreContract.MedicineMvpView;
import com.peacecorps.malaria.utils.InjectionClass;
import butterknife.BindView;
@@ -72,7 +72,7 @@ public void displayMedicineStoreValues(String drugName, String days) {
}
@OnClick(R.id.btn_add_medicine)
- public void addMedicineListener(View view) {
+ public void addMedicineListener() {
final Dialog addMedicineDialog = new Dialog(context, android.R.style.Theme_DeviceDefault_Dialog_NoActionBar);
addMedicineDialog.setContentView(R.layout.add_medicine_dialog);
@@ -103,7 +103,7 @@ public void onClick(View view) {
}
@OnClick(R.id.btn_order_medicine)
- public void orderMedicineListener(View view) {
+ public void orderMedicineListener() {
final Dialog orderMedicineDialog = new Dialog(context, android.R.style.Theme_DeviceDefault_Dialog_NoActionBar);
orderMedicineDialog.setContentView(R.layout.order_medicine_dialog);
@@ -160,7 +160,7 @@ public void onClick(View view) {
// setting button listener in medicine store fragment
@OnClick(R.id.btn_dialog_setting)
- public void settingDialogListener(View view) {
+ public void settingDialogListener() {
final Dialog settingsDialog = new Dialog(context, android.R.style.Theme_DeviceDefault_Dialog_NoActionBar);
settingsDialog.setContentView(R.layout.reminder_screen_setting_dialog);
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/medicine_store/MedicineStorePresenter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/medicine_store/MedicineStorePresenter.java
similarity index 93%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/medicine_store/MedicineStorePresenter.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/ui/medicine_store/MedicineStorePresenter.java
index 976becd9..89149f30 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/medicine_store/MedicineStorePresenter.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/medicine_store/MedicineStorePresenter.java
@@ -1,4 +1,4 @@
-package com.peacecorps.malaria.ui.play.medicine_store;
+package com.peacecorps.malaria.ui.medicine_store;
import android.content.Context;
import android.text.TextUtils;
@@ -6,8 +6,8 @@
import com.peacecorps.malaria.R;
import com.peacecorps.malaria.data.AppDataManager;
import com.peacecorps.malaria.ui.base.BasePresenter;
-import com.peacecorps.malaria.ui.play.medicine_store.MedicineStoreContract.MedicineMvpPresenter;
-import com.peacecorps.malaria.ui.play.medicine_store.MedicineStoreContract.MedicineMvpView;
+import com.peacecorps.malaria.ui.medicine_store.MedicineStoreContract.MedicineMvpPresenter;
+import com.peacecorps.malaria.ui.medicine_store.MedicineStoreContract.MedicineMvpView;
/**
* Created by Anamika Tripathi on 18/7/18.
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/PlayFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/PlayFragment.java
index 02b8e215..3fefd90e 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/PlayFragment.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/PlayFragment.java
@@ -1,6 +1,6 @@
package com.peacecorps.malaria.ui.play;
-import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -10,7 +10,8 @@
import com.peacecorps.malaria.R;
import com.peacecorps.malaria.ui.base.BaseFragment;
-import com.peacecorps.malaria.utils.ToastLogSnackBarUtil;
+import com.peacecorps.malaria.ui.play.myth_vs_fact.MythFactActivity;
+import com.peacecorps.malaria.ui.play.rapid_fire.RapidFireActivity;
import butterknife.ButterKnife;
import butterknife.OnClick;
@@ -20,8 +21,6 @@
*/
public class PlayFragment extends BaseFragment {
- private OnPlayFragmentListener listener;
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -40,30 +39,18 @@ protected int getContentResource() {
return R.layout.fragment_play;
}
- // listener for badge button in play fragment
- @OnClick(R.id.btn_badge_screen)
- public void badgeScreenListener(View view) {
- listener.replacePlayFragment(R.id.btn_badge_screen);
- }
-
// listener for badge button in play fragment
@OnClick(R.id.btn_myth_vs_fact)
public void mythVsFactListener(View view) {
- // calls interface method which is implemented by mainActivity - replaces play fragment with MythVsFactFragment
- listener.replacePlayFragment(R.id.btn_myth_vs_fact);
+ // start MythFactActivity
+ startActivity(new Intent(getContext(), MythFactActivity.class));
}
// listener for rapid fire button in play fragment
@OnClick(R.id.btn_rapid_fire)
public void rapidFireListener(View view) {
- // replaces play fragment with RapidFireFragment
- listener.replacePlayFragment(R.id.btn_rapid_fire);
- }
-
- @OnClick(R.id.btn_medicine_store)
- public void medicineStoreListener(View view) {
- // replaces play fragment with MedicineStore Fragment
- listener.replacePlayFragment(R.id.btn_medicine_store);
+ // start Rapid fire activity
+ startActivity(new Intent(getContext(), RapidFireActivity.class));
}
@Override
@@ -71,33 +58,9 @@ protected void init() {
}
- // it needs to be implemented by main activity
- public interface OnPlayFragmentListener {
- void replacePlayFragment(int id);
- }
-
- // Container Activity must implement this interface
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
- // This makes sure that the container activity has implemented
- // the callback interface. If not, it throws an exception
- if (context instanceof OnPlayFragmentListener) {
- listener = (OnPlayFragmentListener) context;
- } else {
- // Show error Log for debugging & display snackbar to user
- ToastLogSnackBarUtil.showErrorLog(context.toString() + " must implement OnPlayFragmentListener");
- if (getActivity() != null) {
- ToastLogSnackBarUtil.showSnackBar(context, getActivity().findViewById(android.R.id.content),
- "Something went wrong!");
- }
- }
- }
-
// setting null values to the listener, presenter
@Override
public void onDetach() {
super.onDetach();
- listener = null;
}
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactActivity.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactActivity.java
new file mode 100644
index 00000000..7308e949
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactActivity.java
@@ -0,0 +1,72 @@
+package com.peacecorps.malaria.ui.play.myth_vs_fact;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v7.widget.Toolbar;
+import android.view.MenuItem;
+
+import com.peacecorps.malaria.R;
+import com.peacecorps.malaria.ui.base.BaseActivity;
+
+/**
+ * Created by Anamika Tripathi on 13/8/18.
+ */
+public class MythFactActivity extends BaseActivity implements MythFactFragment.OnMythFragmentListener {
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_myth_fact);
+ init();
+ }
+
+ @Override
+ protected void init() {
+
+ Toolbar toolbar = findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+ toolbar.setTitle("Myth Vs Fact");
+ if (getSupportActionBar() != null) {
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+
+ Fragment fragment = new MythFactFragment();
+ loadFragment(fragment);
+ }
+
+ /**
+ * @param fragment : replaces frame layout with parameter received in main activity
+ */
+ private void loadFragment(Fragment fragment) {
+ // load fragment
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+ transaction.replace(R.id.myth_fact_container, fragment, "");
+ transaction.setTransition(FragmentTransaction.TRANSIT_ENTER_MASK);
+ transaction.addToBackStack(null);
+ transaction.commit();
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+ if (id == android.R.id.home) {
+ // close activity
+ finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public void onBackPressed() {
+ super.onBackPressed();
+ finish();
+ }
+
+ @Override
+ public void goBackToPlayFragment() {
+ finish();
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactContract.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactContract.java
index 9279811b..07f9e33d 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactContract.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactContract.java
@@ -8,10 +8,11 @@
*/
public interface MythFactContract {
interface MythFactMvpView extends MvpView {
-
+ void playTapTargetViewer();
}
interface MythFactMvpPresenter extends MvpPresenter {
void updateGameScore(int currPoints);
+ void checkFirstTime();
}
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactFragment.java
index cf4c4124..89921f97 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactFragment.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactFragment.java
@@ -16,6 +16,8 @@
import android.widget.Button;
import android.widget.TextView;
+import com.getkeepsafe.taptargetview.TapTarget;
+import com.getkeepsafe.taptargetview.TapTargetSequence;
import com.peacecorps.malaria.R;
import com.peacecorps.malaria.ui.base.BaseFragment;
import com.peacecorps.malaria.ui.play.myth_vs_fact.MythFactContract.MythFactMvpView;
@@ -42,6 +44,8 @@ public class MythFactFragment extends BaseFragment implements MythFactMvpView {
TextView tvQuestion;
@BindView(R.id.btn_next)
Button nextButton;
+ @BindView(R.id.btn_exit)
+ Button exitButton;
@BindView(R.id.chest)
TextView chest;
@BindView(R.id.trash)
@@ -57,6 +61,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
context = getContext();
ButterKnife.bind(this, view);
presenter = new MythFactPresenter<>(InjectionClass.provideDataManager(context), context);
+ presenter.attachView(this);
return view;
}
@@ -79,6 +84,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
@Override
protected void init() {
+ presenter.checkFirstTime();
//setup questions
questions = Arrays.asList(getResources().getStringArray(R.array.array_myth_vs_fact_questions));
//setup answers
@@ -265,4 +271,84 @@ public void onDetach() {
super.onDetach();
listener = null;
}
+
+
+ @Override
+ public void playTapTargetViewer() {
+ new TapTargetSequence(getActivity())
+ .continueOnCancel(true)
+ .targets(
+ TapTarget.forView(tvQuestion, getString(R.string.help_myth_fact_question_title),
+ getString(R.string.help_myth_fact_question_description))
+ .drawShadow(true)
+ .tintTarget(true)
+ .targetRadius(60)
+ .titleTextColor(R.color.textColorPrimary)
+ .descriptionTextColor(R.color.white)
+ .targetCircleColor(R.color.colorAccent)
+ .outerCircleAlpha(0.90f).id(3),
+ TapTarget.forView(chest, getString(R.string.help_myth_fact_chest_title),
+ "")
+ .drawShadow(true)
+ .tintTarget(true)
+ .titleTextColor(R.color.textColorPrimary)
+ .descriptionTextColor(R.color.white)
+ .targetRadius(60)
+ .targetCircleColor(R.color.colorAccent)
+ .outerCircleAlpha(0.90f).id(3),
+ TapTarget.forView(trash, getString(R.string.help_myth_fact_bin_title),
+ "")
+ .drawShadow(true)
+ .tintTarget(true)
+ .titleTextColor(R.color.textColorPrimary)
+ .descriptionTextColor(R.color.white)
+ .targetRadius(60)
+ .targetCircleColor(R.color.colorAccent)
+ .outerCircleAlpha(0.90f).id(3),
+ TapTarget.forView(tvUserPoints, getString(R.string.help_myth_fact_score_title),
+ "")
+ .drawShadow(true)
+ .tintTarget(true)
+ .titleTextColor(R.color.textColorPrimary)
+ .descriptionTextColor(R.color.white)
+ .targetRadius(60)
+ .targetCircleColor(R.color.colorAccent)
+ .outerCircleAlpha(0.90f).id(3),
+ TapTarget.forView(nextButton, getString(R.string.help_myth_fact_next_title),
+ getString(R.string.help_myth_fact_next_description))
+ .drawShadow(true)
+ .tintTarget(true)
+ .titleTextColor(R.color.textColorPrimary)
+ .descriptionTextColor(R.color.white)
+ .targetRadius(60)
+ .targetCircleColor(R.color.colorAccent)
+ .outerCircleAlpha(0.90f).id(3),
+ TapTarget.forView(exitButton, getString(R.string.help_myth_fact_exit_title),
+ "")
+ .drawShadow(true)
+ .tintTarget(true)
+ .titleTextColor(R.color.textColorPrimary)
+ .descriptionTextColor(R.color.white)
+ .targetRadius(60)
+ .targetCircleColor(R.color.colorAccent)
+ .outerCircleAlpha(0.90f).id(3)
+ )
+ .listener(new TapTargetSequence.Listener() {
+ @Override
+ public void onSequenceFinish() {
+ presenter.getDataManager().setMythFactTarget(true);
+ }
+
+ @Override
+ public void onSequenceStep(TapTarget lastTarget, boolean targetClicked) {
+ // no need currently, compulsory overridden method
+ }
+
+ @Override
+ public void onSequenceCanceled(TapTarget lastTarget) {
+ // no need currently, compulsory overridden method
+ }
+ }).start();
+ }
+
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactPresenter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactPresenter.java
index 25e6f7e5..7b3e6f30 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactPresenter.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/myth_vs_fact/MythFactPresenter.java
@@ -21,4 +21,11 @@ public void updateGameScore(int currPoints) {
int oldPoints = getDataManager().getGameScore();
getDataManager().setGameScore(oldPoints + currPoints);
}
+
+ @Override
+ public void checkFirstTime() {
+ if(!getDataManager().checkMythFactTarget()) {
+ getView().playTapTargetViewer();
+ }
+ }
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFireActivity.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFireActivity.java
new file mode 100644
index 00000000..c01698df
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFireActivity.java
@@ -0,0 +1,71 @@
+package com.peacecorps.malaria.ui.play.rapid_fire;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v7.widget.Toolbar;
+import android.view.MenuItem;
+
+import com.peacecorps.malaria.R;
+import com.peacecorps.malaria.ui.base.BaseActivity;
+
+/**
+ * Created by Anamika Tripathi on 13/8/18.
+ */
+public class RapidFireActivity extends BaseActivity implements RapidFireFragment.OnRapidFragmentListener {
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_rapid_fire);
+ init();
+ }
+
+ @Override
+ protected void init() {
+
+ Toolbar toolbar = findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+ toolbar.setTitle("Rapid Fire");
+ if (getSupportActionBar() != null) {
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+
+ Fragment fragment = new RapidFireFragment();
+ loadFragment(fragment);
+ }
+
+ /**
+ * @param fragment : replaces frame layout with parameter received in main activity
+ */
+ private void loadFragment(Fragment fragment) {
+ // load fragment
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+ transaction.replace(R.id.rapid_fire_container, fragment, "");
+ transaction.setTransition(FragmentTransaction.TRANSIT_ENTER_MASK);
+ transaction.addToBackStack(null);
+ transaction.commit();
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+ if (id == android.R.id.home) {
+ // close activity
+ finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public void onBackPressed() {
+ super.onBackPressed();
+ finish();
+ }
+
+ @Override
+ public void goBackToPlayFragment() {
+ finish();
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFireContract.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFireContract.java
index e139c0db..ad0c1805 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFireContract.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFireContract.java
@@ -12,6 +12,7 @@ interface RapidFireMvpView extends MvpView {
void prepareQuestionAndOptions();
void enableOptions(boolean val);
void updateTimer(long miliLeft);
+ void playTapTargetViewer();
}
interface RapidFireMvpPresenter extends MvpPresenter {
@@ -19,5 +20,6 @@ interface RapidFireMvpPresenter extends MvpPresenter
int questionListSize();
QuestionModel getQuestionModel(int i);
void updateGameScore(int currPoints);
+ void checkFirstTime();
}
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFireFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFireFragment.java
index aa29eb4c..57bea70d 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFireFragment.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFireFragment.java
@@ -13,6 +13,8 @@
import android.widget.Button;
import android.widget.TextView;
+import com.getkeepsafe.taptargetview.TapTarget;
+import com.getkeepsafe.taptargetview.TapTargetSequence;
import com.peacecorps.malaria.R;
import com.peacecorps.malaria.ui.base.BaseFragment;
import com.peacecorps.malaria.ui.play.rapid_fire.RapidFireContract.RapidFireMvpView;
@@ -48,6 +50,8 @@ public class RapidFireFragment extends BaseFragment implements RapidFireMvpView
// timer textView
@BindView(R.id.tv_timers)
TextView timerView;
+ @BindView(R.id.btn_rapid_fire_exit)
+ Button exitButton;
private RapidFirePresenter presenter;
private Context context;
@@ -83,16 +87,10 @@ protected int getContentResource() {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
init();
- if (savedInstanceState != null) {
- // saved values from orientation changes
- restoreFromInstanceState(savedInstanceState);
- } else {
- init();
- }
setGameScore();
//displays the time left for the next question
updateTimer(millisLeft / 1000);
- presenter.prepareQuestionList(quesNo);
+ //presenter.prepareQuestionList(quesNo);
}
// option one for game listener
@@ -187,9 +185,6 @@ public void onClick(DialogInterface dialog, int which) {
AlertDialog dialog = builder.create();
// display dialog
dialog.show();
-
- //Todo check do keep works or not
- // doKeepDialog(alertDialog);
}
// sets score value by appending to the string
@@ -197,15 +192,6 @@ private void setGameScore() {
totalScore.setText(getString(R.string.label_rapid_fire_total_score, gameScore));
}
- // in case the game is coming from saved instance, below parameters are changed to saved values
- private void restoreFromInstanceState(Bundle savedInstanceState) {
- if (savedInstanceState != null) {
- millisLeft = savedInstanceState.getLong(COUNTER_MILLIS_LEFT);
- gameScore = savedInstanceState.getInt(GAME_SCORE);
- quesNo = savedInstanceState.getInt(QUES_NO);
- }
- }
-
@Override
protected void init() {
// below parameters are initialized with their initial value when game starts
@@ -213,6 +199,8 @@ protected void init() {
gameScore = 0;
millisLeft = 6000;
+ presenter.checkFirstTime();
+
}
private void prepNextQues() {
@@ -304,21 +292,8 @@ public void onClick(DialogInterface dialog, int which) {
AlertDialog dialog = builder.create();
// display dialog
dialog.show();
-// doKeepDialog(alertDialog);
}
-// --Commented out App crashes here:
-// // attaches the dialog with WindowManager to avoid cancelling on orientation change
-// private static void doKeepDialog(Dialog dialog) {
-// WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
-// if (dialog.getWindow() != null) {
-// lp.copyFrom(dialog.getWindow().getAttributes());
-// lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
-// lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
-// dialog.getWindow().setAttributes(lp);
-// }
-// }
-// --Commented out App crashes here
// saving value in case of orientation changes
@Override
@@ -380,4 +355,74 @@ public void onAttach(Context context) {
}
}
}
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ counter.cancel();
+ }
+
+ @Override
+ public void playTapTargetViewer() {
+ new TapTargetSequence(getActivity())
+ .continueOnCancel(true)
+ .targets(
+ TapTarget.forView(tvQuestion, getString(R.string.help_rapid_fire_question_title),
+ getString(R.string.help_rapid_fire_question_description))
+ .drawShadow(true)
+ .tintTarget(true)
+ .targetRadius(60)
+ .titleTextColor(R.color.textColorPrimary)
+ .descriptionTextColor(R.color.white)
+ .targetCircleColor(R.color.colorAccent)
+ .outerCircleAlpha(0.90f).id(3),
+ TapTarget.forView(totalScore, getString(R.string.help_rapid_fire_score_title),
+ "")
+ .drawShadow(true)
+ .tintTarget(true)
+ .titleTextColor(R.color.textColorPrimary)
+ .descriptionTextColor(R.color.white)
+ .targetRadius(60)
+ .targetCircleColor(R.color.colorAccent)
+ .outerCircleAlpha(0.90f).id(3),
+ TapTarget.forView(timerView, getString(R.string.help_rapid_fire_timer_title),
+ getString(R.string.help_rapid_fire_timer_description))
+ .drawShadow(true)
+ .tintTarget(true)
+ .titleTextColor(R.color.textColorPrimary)
+ .descriptionTextColor(R.color.white)
+ .targetRadius(60)
+ .targetCircleColor(R.color.colorAccent)
+ .outerCircleAlpha(0.90f).id(3),
+ TapTarget.forView(exitButton, getString(R.string.help_rapid_fire_exit_title),
+ "")
+ .drawShadow(true)
+ .tintTarget(true)
+ .titleTextColor(R.color.textColorPrimary)
+ .descriptionTextColor(R.color.white)
+ .targetRadius(60)
+ .targetCircleColor(R.color.colorAccent)
+ .outerCircleAlpha(0.90f).id(3)
+
+ )
+ .listener(new TapTargetSequence.Listener() {
+ @Override
+ public void onSequenceFinish() {
+ presenter.getDataManager().setRapidFireTarget(true);
+ presenter.prepareQuestionList(quesNo);
+ }
+
+ @Override
+ public void onSequenceStep(TapTarget lastTarget, boolean targetClicked) {
+ // no need currently, compulsory overridden method
+ }
+
+ @Override
+ public void onSequenceCanceled(TapTarget lastTarget) {
+ // no need currently, compulsory overridden method
+ }
+ }).start();
+ }
+
+
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFirePresenter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFirePresenter.java
index 3af0cea1..9aaf045e 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFirePresenter.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/rapid_fire/RapidFirePresenter.java
@@ -24,7 +24,7 @@ public class RapidFirePresenter extends BasePresente
// preparing question, answer in beginning of test.
@Override
public void prepareQuestionList(int num) {
- questionList=new ArrayList();
+ questionList= new ArrayList<>();
//adding questions
questionList.add(new QuestionModel("Melfoquine should be taken ", "Daily", "Weekly", "Monthly", 2));
questionList.add(new QuestionModel("Malaria is caused by ", "Virus", "Bacteria", "Protozoa",3));
@@ -61,4 +61,13 @@ public void updateGameScore(int currPoints) {
int oldPoints = getDataManager().getGameScore();
getDataManager().setGameScore(oldPoints + currPoints);
}
+
+ @Override
+ public void checkFirstTime() {
+ if(!getDataManager().checkRapidFireTarget()) {
+ getView().playTapTargetViewer();
+ } else {
+ prepareQuestionList(0);
+ }
+ }
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/trip_reminder/PlanTripFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/trip_reminder/PlanTripFragment.java
index f9500f9c..9da83e96 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/trip_reminder/PlanTripFragment.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/trip_reminder/PlanTripFragment.java
@@ -159,7 +159,7 @@ public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP &&
(event.getRawX() >= (etReminderTime.getRight() - etReminderTime.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()))) {
- checkDepartureOrArrivalEt = false;
+ checkDepartureOrArrivalEt = true;
// creating show date picker dialog
showTimePicker();
return true;
@@ -171,6 +171,18 @@ public boolean onTouch(View v, MotionEvent event) {
});
}
+ @OnClick(R.id.et_departure_date)
+ public void departureDateListener() {
+ checkDepartureOrArrivalEt = true;
+ showDatePicker();
+ }
+
+ @OnClick(R.id.et_arrival_date)
+ public void arrivalDateListener() {
+ checkDepartureOrArrivalEt = false;
+ showDatePicker();
+ }
+
private void showDatePicker() {
DatePickerFragment date = new DatePickerFragment();
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/trip_reminder/PlanTripPresenter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/trip_reminder/PlanTripPresenter.java
index 0090282d..2a1d398f 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/trip_reminder/PlanTripPresenter.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/trip_reminder/PlanTripPresenter.java
@@ -49,20 +49,22 @@ public void onDataLoaded(List data) {
@Override
public String convertToTwelveHours(int hr, int mins) {
String timeSet;
- String minutes;
int hour = 0;
if (hr > 12) {
- hour -= 12;
+ hour = hr -12;
timeSet = "PM";
} else if (hr == 0) {
hour += 12;
timeSet = "AM";
} else if (hr == 12) {
timeSet = "PM";
+ hour = hr;
} else {
timeSet = "AM";
+ hour = hr;
}
+ String minutes;
if (mins < 10) {
minutes = getContext().getResources().getString(R.string.add_zero_beginning, mins);
} else {
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/trip_reminder/trip_select_item/ItemDialogFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/trip_reminder/trip_select_item/ItemDialogFragment.java
index 1015d4c5..6c0df03a 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/trip_reminder/trip_select_item/ItemDialogFragment.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/trip_reminder/trip_select_item/ItemDialogFragment.java
@@ -120,7 +120,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
presenter = new ItemDialogPresenter<>(InjectionClass.provideDataManager(context), context);
presenter.attachView(this);
- if(presenter.isViewAttached()) {
+ if (presenter.isViewAttached()) {
init(view);
} else {
ToastLogSnackBarUtil.showErrorLog("ItemDialogFragment: View not attached");
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/adapter/DrugArrayAdapter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/DrugArrayAdapter.java
similarity index 72%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/code/adapter/DrugArrayAdapter.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/DrugArrayAdapter.java
index c85ee0f1..d4ee1758 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/code/adapter/DrugArrayAdapter.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/DrugArrayAdapter.java
@@ -1,19 +1,17 @@
-package com.peacecorps.malaria.code.adapter;
+package com.peacecorps.malaria.ui.user_medicine_setting;
/**
* Created by Ankita on 8/13/2015.
*/
-import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
+import android.support.annotation.NonNull;
import android.view.LayoutInflater;
-import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
-import android.widget.TableLayout;
import android.widget.TextView;
import com.peacecorps.malaria.R;
@@ -24,8 +22,8 @@ public class DrugArrayAdapter extends ArrayAdapter{
private final String[] dname;
private final Integer[] imageId;
private final String[] drugDescriptions;
- public DrugArrayAdapter(Activity context,
- String[] dname, Integer[] imageId, String[] drugDescriptions) {
+ DrugArrayAdapter(Activity context,
+ String[] dname, Integer[] imageId, String[] drugDescriptions) {
super(context, R.layout.trip_drug_item, dname);
this.context = context;
this.dname = dname;
@@ -33,14 +31,15 @@ public DrugArrayAdapter(Activity context,
this.drugDescriptions = drugDescriptions;
}
+ @NonNull
@Override
- public View getView(int position, View view, ViewGroup parent) {
+ public View getView(int position, View view, @NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
//inflating the customized view
View rowView= inflater.inflate(R.layout.trip_drug_item, null, true);
- TextView txtTitle = (TextView) rowView.findViewById(R.id.drugItem);
+ TextView txtTitle = rowView.findViewById(R.id.drugItem);
- ImageView imageView = (ImageView) rowView.findViewById(R.id.imgDrug);
+ ImageView imageView = rowView.findViewById(R.id.imgDrug);
txtTitle.setText(dname[position]);
imageView.setImageResource(imageId[position]);
@@ -48,12 +47,12 @@ public View getView(int position, View view, ViewGroup parent) {
}
@Override
- public View getDropDownView(int position, View View, ViewGroup parent) {
+ public View getDropDownView(int position, View View, @NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
//inflating the customized view
View rowView= inflater.inflate(R.layout.trip_drug_info, null, true);
- final TextView txtTitle = (TextView) rowView.findViewById(R.id.nameDrug);
- Button infoButton = (Button) rowView.findViewById(R.id.infoDrug);
+ final TextView txtTitle = rowView.findViewById(R.id.nameDrug);
+ Button infoButton = rowView.findViewById(R.id.infoDrug);
txtTitle.setText(dname[position]);
addClickListener(position, infoButton);
@@ -61,7 +60,7 @@ public View getDropDownView(int position, View View, ViewGroup parent) {
return rowView;
}
//When the info button is clicked for the drug, an alert dialog will show its description
- public void addClickListener(final int position, Button infoButton) {
+ private void addClickListener(final int position, Button infoButton) {
infoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/MedicineSettingContract.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/MedicineSettingContract.java
index bbb75368..2c43630d 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/MedicineSettingContract.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/MedicineSettingContract.java
@@ -7,7 +7,7 @@ public interface MedicineSettingContract {
interface SettingMvpView extends MvpView {
void startMainActivity();
void setSelectedTime(String theTime);
- void enableDoneButton();
+ void enableDoneButton(int h, int min);
}
interface Presenter extends MvpPresenter {
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/MedicineSettingPresenter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/MedicineSettingPresenter.java
index c87a6536..31827bb4 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/MedicineSettingPresenter.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/MedicineSettingPresenter.java
@@ -1,11 +1,14 @@
package com.peacecorps.malaria.ui.user_medicine_setting;
import android.content.Context;
+import android.content.Intent;
import com.peacecorps.malaria.R;
import com.peacecorps.malaria.data.AppDataManager;
import com.peacecorps.malaria.data.db.entities.AlarmTime;
+import com.peacecorps.malaria.notifications.service.AlarmService;
import com.peacecorps.malaria.ui.base.BasePresenter;
+import com.peacecorps.malaria.utils.ToastLogSnackBarUtil;
import java.util.Calendar;
import java.util.Date;
@@ -50,25 +53,25 @@ public void setUserAndMedicationPreference(int hour, int minute, int mDrugPicked
int checkDay = calendar.get(Calendar.DAY_OF_WEEK);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);
-
+ ToastLogSnackBarUtil.showDebugLog("day "+ checkDay + "month " + month + "year " + year + " " + hour + " " + minute );
// inserted the alarm timing and days
getDataManager().insertAlarmData(new AlarmTime(hour, minute, month, year, checkDay));
switch (mDrugPicked) {
case 0:
- getDataManager().setDoesWeekly(false);
+ getDataManager().setDoseWeekly(false);
getDataManager().setDrugPicked(getContext().getString(R.string.med_option_one));
break;
case 1:
- getDataManager().setDoesWeekly(false);
+ getDataManager().setDoseWeekly(false);
getDataManager().setDrugPicked(getContext().getString(R.string.med_option_two));
break;
case 2:
- getDataManager().setDoesWeekly(true);
+ getDataManager().setDoseWeekly(true);
getDataManager().setDrugPicked(getContext().getString(R.string.med_option_three));
break;
default:
- getDataManager().setDoesWeekly(false);
+ getDataManager().setDoseWeekly(false);
getDataManager().setDrugPicked(getContext().getString(R.string.med_option_one));
}
if (getDataManager().isFirstRun()) {
@@ -77,9 +80,8 @@ public void setUserAndMedicationPreference(int hour, int minute, int mDrugPicked
}
getDataManager().setDrugTaken(false);
getDataManager().setUserPreferences(true);
- //Todo IMP start a alarm service
-// mFragmentContext.startService(new Intent(mFragmentContext,
-// AlarmService.class));
+ // starting alarm service for reminding user for medicine
+ getContext().startService(new Intent(getContext(), AlarmService.class));
}
/**
@@ -88,18 +90,21 @@ public void setUserAndMedicationPreference(int hour, int minute, int mDrugPicked
*/
@Override
public void convertToTwelveHours(int hr, int mins) {
+ ToastLogSnackBarUtil.showDebugLog("" + hr + mins);
String timeSet;
int hour = 0;
if (hr > 12) {
- hour -= 12;
+ hour = hr -12;
timeSet = "PM";
} else if (hr == 0) {
hour += 12;
timeSet = "AM";
} else if (hr == 12) {
timeSet = "PM";
+ hour = hr;
} else {
timeSet = "AM";
+ hour = hr;
}
String minutes;
@@ -112,6 +117,6 @@ public void convertToTwelveHours(int hr, int mins) {
String theTime = getContext().getResources().getString(R.string.time_picker, hour, minutes, timeSet);
getView().setSelectedTime(theTime);
- getView().enableDoneButton();
+ getView().enableDoneButton(hr, mins);
}
}
\ No newline at end of file
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/MedicineSettingsActivity.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/MedicineSettingsActivity.java
index cf252ab8..2ab19b19 100755
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/MedicineSettingsActivity.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_medicine_setting/MedicineSettingsActivity.java
@@ -17,8 +17,7 @@
import android.widget.Toast;
import com.peacecorps.malaria.R;
-import com.peacecorps.malaria.ui.home_screen.MainActivity;
-import com.peacecorps.malaria.code.adapter.DrugArrayAdapter;
+import com.peacecorps.malaria.ui.main.MainActivity;
import com.peacecorps.malaria.ui.base.BaseActivity;
import com.peacecorps.malaria.utils.Constants;
import com.peacecorps.malaria.utils.InjectionClass;
@@ -170,8 +169,10 @@ public void setSelectedTime(String time) {
*Done button is enabled if the user have setup a time
*/
@Override
- public void enableDoneButton() {
+ public void enableDoneButton(int hr, int min) {
mDoneButton.setEnabled(true);
+ mHour = hr;
+ mMinute = min;
}
/*Overrided Method called by the create Drug Selection Spinner to check which drug was chosen */
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/ProfileFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/ProfileFragment.java
new file mode 100644
index 00000000..ca88a9d3
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/ProfileFragment.java
@@ -0,0 +1,126 @@
+package com.peacecorps.malaria.ui.user_profile;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.design.widget.TabLayout;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentPagerAdapter;
+import android.support.v4.view.ViewPager;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.peacecorps.malaria.R;
+import com.peacecorps.malaria.ui.base.BaseFragment;
+import com.peacecorps.malaria.ui.user_profile.first_ananlysis.FirstAnalysisFragment;
+import com.peacecorps.malaria.ui.user_profile.second_analysis.SecondAnalysisFragment;
+import com.peacecorps.malaria.ui.user_profile.badge_screen.BadgeScreenFragment;
+import com.peacecorps.malaria.ui.user_profile.edit_profile.EditProfileActivity;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by Anamika Tripathi on 8/8/18.
+ */
+public class ProfileFragment extends BaseFragment {
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setHasOptionsMenu(true);
+ }
+
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+
+ View view = inflater.inflate(R.layout.fragment_tabs_profile, container, false);
+ // Setting ViewPager for each Tabs
+ ViewPager viewPager = view.findViewById(R.id.viewpager);
+ setupViewPager(viewPager);
+ // Set Tabs inside Toolbar
+ TabLayout tabs = view.findViewById(R.id.result_tabs);
+ tabs.setTabGravity(TabLayout.GRAVITY_FILL);
+ tabs.setupWithViewPager(viewPager);
+ return view;
+
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ inflater.inflate(R.menu.menu_profile, menu);
+ super.onCreateOptionsMenu(menu, inflater);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle item selection
+ switch (item.getItemId()) {
+ case R.id.action_edit_profile:
+ startActivity(new Intent(getActivity(), EditProfileActivity.class));
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ // Add Fragments to Tabs
+ private void setupViewPager(ViewPager viewPager) {
+ Adapter adapter = new Adapter(getChildFragmentManager());
+ adapter.addFragment(new FirstAnalysisFragment(), "First");
+ adapter.addFragment(new SecondAnalysisFragment(), "Second");
+ adapter.addFragment(new BadgeScreenFragment(), "Badge");
+ viewPager.setAdapter(adapter);
+ }
+
+ static class Adapter extends FragmentPagerAdapter {
+ private final List mFragmentList = new ArrayList<>();
+ private final List mFragmentTitleList = new ArrayList<>();
+
+ Adapter(FragmentManager manager) {
+ super(manager);
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ return mFragmentList.get(position);
+ }
+
+ @Override
+ public int getCount() {
+ return mFragmentList.size();
+ }
+
+ void addFragment(Fragment fragment, String title) {
+ mFragmentList.add(fragment);
+ mFragmentTitleList.add(title);
+ }
+
+ @Override
+ public CharSequence getPageTitle(int position) {
+ return mFragmentTitleList.get(position);
+ }
+ }
+
+
+ @Override
+ protected int getContentResource() {
+ return R.layout.fragment_tabs_profile;
+ }
+
+ @Override
+ protected void init() {
+ // not needed here now, over-ridden method
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/badge_screen/BadgeScreenContract.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/badge_screen/BadgeScreenContract.java
similarity index 91%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/badge_screen/BadgeScreenContract.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/badge_screen/BadgeScreenContract.java
index 1206acc7..a1d96694 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/badge_screen/BadgeScreenContract.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/badge_screen/BadgeScreenContract.java
@@ -1,4 +1,4 @@
-package com.peacecorps.malaria.ui.play.badge_screen;
+package com.peacecorps.malaria.ui.user_profile.badge_screen;
import android.graphics.drawable.Drawable;
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/badge_screen/BadgeScreenFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/badge_screen/BadgeScreenFragment.java
similarity index 85%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/badge_screen/BadgeScreenFragment.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/badge_screen/BadgeScreenFragment.java
index ba5cd7ed..ec54dc11 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/badge_screen/BadgeScreenFragment.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/badge_screen/BadgeScreenFragment.java
@@ -1,4 +1,4 @@
-package com.peacecorps.malaria.ui.play.badge_screen;
+package com.peacecorps.malaria.ui.user_profile.badge_screen;
import android.app.Dialog;
import android.content.Context;
@@ -10,16 +10,18 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.TextView;
import com.peacecorps.malaria.R;
import com.peacecorps.malaria.ui.base.BaseFragment;
import com.peacecorps.malaria.utils.InjectionClass;
+import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
-import static com.peacecorps.malaria.ui.play.badge_screen.BadgeScreenContract.*;
+import static com.peacecorps.malaria.ui.user_profile.badge_screen.BadgeScreenContract.*;
/**
* Created by Anamika Tripathi on 24/7/18.
@@ -28,8 +30,11 @@ public class BadgeScreenFragment extends BaseFragment implements BadgeMvpView {
private Dialog achievementDialog;
private Context context;
+
private TextView badgeText;
- private TextView achievementCatTv;
+ private ImageView badgeImage;
+ @BindView(R.id.btn_achievement_medicine)
+ TextView achievementCatTv;
private BadgeScreenPresenter presenter;
@Nullable
@@ -46,6 +51,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
+ init();
}
@Override
@@ -63,6 +69,7 @@ private void setUpDialog() {
achievementDialog = new Dialog(context, android.R.style.Theme_DeviceDefault_Dialog_NoActionBar);
achievementDialog.setContentView(R.layout.badge_room_dialog);
badgeText = achievementDialog.findViewById(R.id.badge_text);
+ badgeImage = achievementDialog.findViewById(R.id.badge_image);
achievementCatTv = achievementDialog.findViewById(R.id.achievement_category);
}
@@ -89,15 +96,15 @@ public void achievementQAListener(View view) {
@Override
public void startCategoryMedicineDialog(Drawable badgeDrawable) {
achievementCatTv.setText(R.string.heading_achievement_one);
- badgeText.setCompoundDrawables(null, null, null, badgeDrawable);
- badgeText.setText(R.string.label_achievement_one);
+ badgeText.setText(R.string.label_first_achievement);
+ badgeImage.setImageDrawable(badgeDrawable);
achievementDialog.show();
}
@Override
public void startCategoryQADialog(Drawable badgeDrawable) {
achievementCatTv.setText(R.string.heading_achievement_two);
- badgeText.setCompoundDrawables(null, null, null, badgeDrawable);
+ badgeImage.setImageDrawable(badgeDrawable);
badgeText.setText(R.string.label_achievement_two);
achievementDialog.show();
}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/badge_screen/BadgeScreenPresenter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/badge_screen/BadgeScreenPresenter.java
similarity index 89%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/badge_screen/BadgeScreenPresenter.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/badge_screen/BadgeScreenPresenter.java
index 77a3e536..41590820 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/play/badge_screen/BadgeScreenPresenter.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/badge_screen/BadgeScreenPresenter.java
@@ -1,4 +1,4 @@
-package com.peacecorps.malaria.ui.play.badge_screen;
+package com.peacecorps.malaria.ui.user_profile.badge_screen;
import android.content.Context;
import android.graphics.drawable.Drawable;
@@ -6,8 +6,8 @@
import com.peacecorps.malaria.R;
import com.peacecorps.malaria.data.AppDataManager;
import com.peacecorps.malaria.ui.base.BasePresenter;
-import com.peacecorps.malaria.ui.play.badge_screen.BadgeScreenContract.BadgeMvpPresenter;
-import com.peacecorps.malaria.ui.play.badge_screen.BadgeScreenContract.BadgeMvpView;
+import com.peacecorps.malaria.ui.user_profile.badge_screen.BadgeScreenContract.BadgeMvpPresenter;
+import com.peacecorps.malaria.ui.user_profile.badge_screen.BadgeScreenContract.BadgeMvpView;
/**
* Created by Anamika Tripathi on 24/7/18.
@@ -40,7 +40,7 @@ public String getUserName() {
//get badge based on medication score
@Override
public void selectUserBadge() {
- Drawable badgeDrawable= null;
+ Drawable badgeDrawable;
int userScore = getDataManager().getUserScore();
//set badge according to score
if(userScore<2){
@@ -64,7 +64,7 @@ public void selectUserBadge() {
@Override
public void selectGameBadge() {
int gameScore = getDataManager().getGameScore();
- Drawable badgeDrawable= null;
+ Drawable badgeDrawable;
//set badge according to score
if(gameScore<2){
badgeDrawable=getContext().getResources().getDrawable(R.drawable.y_b1);
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/edit_profile/EditProfileActivity.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/edit_profile/EditProfileActivity.java
new file mode 100644
index 00000000..6cdd6690
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/edit_profile/EditProfileActivity.java
@@ -0,0 +1,72 @@
+package com.peacecorps.malaria.ui.user_profile.edit_profile;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v7.widget.Toolbar;
+import android.view.MenuItem;
+
+import com.peacecorps.malaria.R;
+import com.peacecorps.malaria.ui.base.BaseActivity;
+
+/**
+ * Created by Anamika Tripathi on 8/8/18.
+ */
+public class EditProfileActivity extends BaseActivity implements UserProfileFragment.OnUserFragmentListener {
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_edit_profile);
+ init();
+ }
+
+ @Override
+ protected void init() {
+
+ Toolbar toolbar = findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+ toolbar.setTitle("Edit Profile");
+ if (getSupportActionBar() != null) {
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+
+ Fragment fragment = new UserProfileFragment();
+ loadFragment(fragment);
+ }
+
+ /**
+ * @param fragment : replaces frame layout with parameter received in main activity
+ */
+ private void loadFragment(Fragment fragment) {
+ // load fragment
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+ transaction.replace(R.id.edit_profile_container, fragment, "");
+ transaction.setTransition(FragmentTransaction.TRANSIT_ENTER_MASK);
+ transaction.addToBackStack(null);
+ transaction.commit();
+ }
+
+ @Override
+ public void startHomeFragment() {
+ finish();
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+ if (id == android.R.id.home) {
+ // close activity
+ finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public void onBackPressed() {
+ super.onBackPressed();
+ finish();
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/UserProfileContract.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/edit_profile/UserProfileContract.java
similarity index 93%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/UserProfileContract.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/edit_profile/UserProfileContract.java
index a17c53b1..ffc9159e 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/UserProfileContract.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/edit_profile/UserProfileContract.java
@@ -1,4 +1,4 @@
-package com.peacecorps.malaria.ui.user_profile;
+package com.peacecorps.malaria.ui.user_profile.edit_profile;
import com.peacecorps.malaria.ui.base.MvpPresenter;
import com.peacecorps.malaria.ui.base.MvpView;
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/UserProfileFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/edit_profile/UserProfileFragment.java
similarity index 98%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/UserProfileFragment.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/edit_profile/UserProfileFragment.java
index ad6222a4..0b8b0925 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/UserProfileFragment.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/edit_profile/UserProfileFragment.java
@@ -1,4 +1,4 @@
-package com.peacecorps.malaria.ui.user_profile;
+package com.peacecorps.malaria.ui.user_profile.edit_profile;
/*
* Created by Anamika Tripathi on 13/7/18.
@@ -106,9 +106,9 @@ public void onDetach() {
// set initial details from shared preferences
@Override
public void setInitialValuesIfAvailable(String name, String email, int age, String medicine) {
- if (!name.equals(""))
+ if (!"".equals(name))
userName.setText(name);
- if (!email.equals(""))
+ if (!"".equals(email))
userEmail.setText(email);
if (age > 0)
userAge.setText(String.valueOf(age));
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/UserProfilePresenter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/edit_profile/UserProfilePresenter.java
similarity index 89%
rename from malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/UserProfilePresenter.java
rename to malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/edit_profile/UserProfilePresenter.java
index e81e333a..3c315c22 100644
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/UserProfilePresenter.java
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/edit_profile/UserProfilePresenter.java
@@ -1,12 +1,12 @@
-package com.peacecorps.malaria.ui.user_profile;
+package com.peacecorps.malaria.ui.user_profile.edit_profile;
import android.content.Context;
import android.text.TextUtils;
import com.peacecorps.malaria.data.AppDataManager;
import com.peacecorps.malaria.ui.base.BasePresenter;
-import com.peacecorps.malaria.ui.user_profile.UserProfileContract.UserProfileMvpPresenter;
-import com.peacecorps.malaria.ui.user_profile.UserProfileContract.UserProfileMvpView;
+import com.peacecorps.malaria.ui.user_profile.edit_profile.UserProfileContract.UserProfileMvpPresenter;
+import com.peacecorps.malaria.ui.user_profile.edit_profile.UserProfileContract.UserProfileMvpView;
/**
* Created by Anamika Tripathi on 13/7/18.
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/first_ananlysis/FirstAnalysisContract.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/first_ananlysis/FirstAnalysisContract.java
new file mode 100644
index 00000000..84dcac97
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/first_ananlysis/FirstAnalysisContract.java
@@ -0,0 +1,25 @@
+package com.peacecorps.malaria.ui.user_profile.first_ananlysis;
+
+import com.peacecorps.malaria.ui.base.MvpPresenter;
+import com.peacecorps.malaria.ui.base.MvpView;
+
+/**
+ * Created by Anamika Tripathi on 7/8/18.
+ */
+public interface FirstAnalysisContract {
+ interface FirstAnalysisMvpView extends MvpView {
+ void setLastTakenTime(String data);
+
+ void setDosesText(int data);
+
+ void setAdherenceRate(String data);
+ }
+
+ interface FirstAnalysisMvpPresenter extends MvpPresenter {
+ void updateMediLastTime();
+
+ void updateDoses();
+
+ void getAdherenceData();
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/first_ananlysis/FirstAnalysisFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/first_ananlysis/FirstAnalysisFragment.java
new file mode 100644
index 00000000..b4d042aa
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/first_ananlysis/FirstAnalysisFragment.java
@@ -0,0 +1,90 @@
+package com.peacecorps.malaria.ui.user_profile.first_ananlysis;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.peacecorps.malaria.R;
+import com.peacecorps.malaria.ui.base.BaseFragment;
+import com.peacecorps.malaria.ui.user_profile.first_ananlysis.FirstAnalysisContract.FirstAnalysisMvpView;
+import com.peacecorps.malaria.utils.InjectionClass;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+
+/**
+ * Created by Anamika Tripathi on 7/8/18.
+ */
+public class FirstAnalysisFragment extends BaseFragment implements FirstAnalysisMvpView {
+
+ private FirstAnalysisPresenter presenter;
+
+ @BindView(R.id.tv_check_last_time)
+ TextView tvCheckMediLastTakenTime;
+ @BindView(R.id.tv_doses_in_row)
+ TextView tvDoses;
+ @BindView(R.id.tv_adherence)
+ TextView adherence;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
+ @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_first_analytic_screen, container, false);
+ ButterKnife.bind(this, view);
+ Context context = getContext();
+ presenter = new FirstAnalysisPresenter<>(InjectionClass.provideDataManager(context), context);
+ presenter.attachView(this);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ init();
+ }
+
+ @Override
+ protected int getContentResource() {
+ return R.layout.fragment_first_analytic_screen;
+ }
+
+ /**
+ * initialize everyTime this fragment's onViewCreated gets called
+ * calls presenter's function which further calls setter method to set data for Textview
+ */
+ @Override
+ protected void init() {
+ presenter.updateMediLastTime();
+ presenter.updateDoses();
+ presenter.getAdherenceData();
+ }
+
+ /**
+ * @param data : string value of last time medicine was taken
+ * desc: sets value to checkMediLastTakenTime
+ */
+ @Override
+ public void setLastTakenTime(String data) {
+ tvCheckMediLastTakenTime.setText(data);
+ }
+
+ /**
+ * @param data : doses in a row value (checked before if it's weekly or daily)
+ * desc: sets data to doses textView
+ */
+ @Override
+ public void setDosesText(int data) {
+ tvDoses.setText(getString(R.string.blank_text, data));
+ }
+
+ @Override
+ public void setAdherenceRate(String data) {
+ adherence.setText(data);
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/first_ananlysis/FirstAnalysisPresenter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/first_ananlysis/FirstAnalysisPresenter.java
new file mode 100644
index 00000000..97f7548f
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/first_ananlysis/FirstAnalysisPresenter.java
@@ -0,0 +1,114 @@
+package com.peacecorps.malaria.ui.user_profile.first_ananlysis;
+
+import android.content.Context;
+
+import com.peacecorps.malaria.data.AppDataManager;
+import com.peacecorps.malaria.data.db.DbHelper;
+import com.peacecorps.malaria.ui.base.BasePresenter;
+import com.peacecorps.malaria.ui.user_profile.first_ananlysis.FirstAnalysisContract.FirstAnalysisMvpPresenter;
+import com.peacecorps.malaria.ui.user_profile.first_ananlysis.FirstAnalysisContract.FirstAnalysisMvpView;
+import com.peacecorps.malaria.utils.CalendarFunction;
+
+import java.text.DecimalFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * Created by Anamika Tripathi on 7/8/18.
+ */
+public class FirstAnalysisPresenter extends BasePresenter implements FirstAnalysisMvpPresenter {
+
+ FirstAnalysisPresenter(AppDataManager manager, Context context) {
+ super(manager, context);
+ }
+
+ /**
+ * gets data from db, calls view's setLastTakenTime method to set on text
+ */
+ @Override
+ public void updateMediLastTime() {
+ getDataManager().getLastTaken(new DbHelper.LoadStringCallback() {
+ @Override
+ public void onDataLoaded(String data) {
+ getView().setLastTakenTime(data);
+ }
+ });
+ }
+
+ /**
+ * Updating Doses in a Row for Weekly and Daily Pill separately
+ */
+ @Override
+ public void updateDoses() {
+ boolean isWeekly = getDataManager().isDosesWeekly();
+ if (isWeekly) {
+ getDataManager().getDosesInaRowWeekly(new DbHelper.LoadIntegerCallback() {
+ @Override
+ public void onDataLoaded(int value) {
+ getDataManager().setDosesWeekly(value);
+ getView().setDosesText(value);
+ }
+ });
+ } else {
+ getDataManager().getDosesInaRowDaily(new DbHelper.LoadIntegerCallback() {
+ @Override
+ public void onDataLoaded(int value) {
+ getDataManager().setDosesDaily(value);
+ getView().setDosesText(value);
+ }
+ });
+ }
+ }
+
+ // Calculating Adherence & calls setAdherenceText
+ @Override
+ public void getAdherenceData() {
+
+ //finding the interval of time between today and the 'time'
+ long today = new Date().getTime();
+ final Date date = Calendar.getInstance().getTime();
+ date.setTime(today);
+
+ getDataManager().getFirstTimeByTimeStamp(new DbHelper.LoadLongCallback() {
+ @Override
+ public void onDataLoaded(Long takenDate) {
+ // calculate interval first on the basis of weekly or daily
+ final long interval;
+ if (takenDate != 0) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(takenDate);
+
+ cal.add(Calendar.MONTH, 1);
+ Date start = cal.getTime();
+ int weekDay = cal.get(Calendar.DAY_OF_WEEK);
+
+ //calculating no. of weekdays for weekly drug
+ boolean isWeekly = getDataManager().isDosesWeekly();
+ if (isWeekly) {
+ interval = CalendarFunction.getIntervalWeekly(start, date, weekDay);
+ } else {
+ //for daily drug only the no. of days
+ interval = CalendarFunction.getIntervalDaily(start, date);
+ }
+ getDataManager().setFirstRunTime(takenDate);
+
+ } else {
+ interval = 1;
+ }
+ getDataManager().getMedicineCountTaken(new DbHelper.LoadIntegerCallback() {
+ @Override
+ public void onDataLoaded(int count) {
+ double adherence;
+ if (interval != 1) {
+ adherence = ((double) count / (double) interval) * 100;
+ } else {
+ adherence = 100;
+ }
+ String adherenceText = String.valueOf((new DecimalFormat("#.##").format(adherence)));
+ getView().setAdherenceRate(adherenceText);
+ }
+ });
+ }
+ });
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/AnalysisModel.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/AnalysisModel.java
new file mode 100644
index 00000000..1d6cb66c
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/AnalysisModel.java
@@ -0,0 +1,30 @@
+package com.peacecorps.malaria.ui.user_profile.second_analysis;
+
+/**
+ * Created by Anamika Tripathi on 8/8/18.
+ */
+public class AnalysisModel {
+ private String month;
+ private String percentage;
+
+ public AnalysisModel(String month, String percentage) {
+ this.month = month;
+ this.percentage = percentage;
+ }
+
+ public String getMonth() {
+ return month;
+ }
+
+ public void setMonth(String month) {
+ this.month = month;
+ }
+
+ public String getPercentage() {
+ return percentage;
+ }
+
+ public void setPercentage(String percentage) {
+ this.percentage = percentage;
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/SecondAnalysisContract.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/SecondAnalysisContract.java
new file mode 100644
index 00000000..84fe20e1
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/SecondAnalysisContract.java
@@ -0,0 +1,18 @@
+package com.peacecorps.malaria.ui.user_profile.second_analysis;
+
+import com.peacecorps.malaria.ui.base.MvpPresenter;
+import com.peacecorps.malaria.ui.base.MvpView;
+
+/**
+ * Created by Anamika Tripathi on 7/8/18.
+ */
+public interface SecondAnalysisContract {
+ interface SecondAnalysisMvpView extends MvpView {
+ void startRecyclerView();
+ }
+
+ interface SecondAnalysisMvpPresenter extends MvpPresenter {
+ void getDataForProgressBar();
+
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/SecondAnalysisFragment.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/SecondAnalysisFragment.java
new file mode 100644
index 00000000..faef922a
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/SecondAnalysisFragment.java
@@ -0,0 +1,64 @@
+package com.peacecorps.malaria.ui.user_profile.second_analysis;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.peacecorps.malaria.R;
+import com.peacecorps.malaria.ui.base.BaseFragment;
+import com.peacecorps.malaria.ui.user_profile.second_analysis.SecondAnalysisContract.SecondAnalysisMvpView;
+import com.peacecorps.malaria.utils.InjectionClass;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+
+/**
+ * Created by Anamika Tripathi on 7/8/18.
+ */
+public class SecondAnalysisFragment extends BaseFragment implements SecondAnalysisMvpView {
+ private SecondAnalysisPresenter presenter;
+ @BindView(R.id.rv_timeline)
+ RecyclerView recyclerView;
+ private Context context;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
+ @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_second_analytic_screen, container, false);
+ ButterKnife.bind(this, view);
+ context = getContext();
+ presenter = new SecondAnalysisPresenter<>(InjectionClass.provideDataManager(context), context);
+ presenter.attachView(this);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ init();
+ }
+
+ @Override
+ protected int getContentResource() {
+ return R.layout.fragment_second_analytic_screen;
+ }
+
+ @Override
+ protected void init() {
+ presenter.getDataForProgressBar();
+ }
+
+ @Override
+ public void startRecyclerView() {
+ recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+ TimelineAdapter adapter = new TimelineAdapter(presenter, context);
+ recyclerView.setAdapter(adapter);
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/SecondAnalysisPresenter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/SecondAnalysisPresenter.java
new file mode 100644
index 00000000..1e22f92c
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/SecondAnalysisPresenter.java
@@ -0,0 +1,190 @@
+package com.peacecorps.malaria.ui.user_profile.second_analysis;
+
+import android.content.Context;
+
+import com.peacecorps.malaria.R;
+import com.peacecorps.malaria.data.AppDataManager;
+import com.peacecorps.malaria.data.db.DbHelper;
+import com.peacecorps.malaria.data.db.entities.AlarmTime;
+import com.peacecorps.malaria.ui.base.BasePresenter;
+import com.peacecorps.malaria.ui.user_profile.second_analysis.SecondAnalysisContract.SecondAnalysisMvpPresenter;
+import com.peacecorps.malaria.ui.user_profile.second_analysis.SecondAnalysisContract.SecondAnalysisMvpView;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+/**
+ * Created by Anamika Tripathi on 7/8/18.
+ */
+public class SecondAnalysisPresenter extends BasePresenter implements SecondAnalysisMvpPresenter {
+ private int mDate;
+ private int mYear;
+ private final int[] daysOfMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30,
+ 31, 30, 31};
+ private String[] monthList;
+
+ private List dataList;
+
+ SecondAnalysisPresenter(AppDataManager manager, Context context) {
+ super(manager, context);
+ dataList = new ArrayList<>();
+ monthList = getContext().getResources().getStringArray(R.array.array_month);
+ }
+
+ @Override
+ public void getDataForProgressBar() {
+
+ getDataManager().getAlarmData(new DbHelper.LoadAlarmDataCallback() {
+ @Override
+ public void onDataLoaded(AlarmTime time) {
+ final int setUpMonth = time.getMonth();
+ final int setUpYear = time.getYear();
+ getAnalysisData(setUpMonth, setUpYear);
+ }
+ });
+ }
+
+ private void getAnalysisData(final int setUpMonth, final int setUpYear) {
+ final int date = Calendar.getInstance().get(Calendar.MONTH);
+ final String choice;
+ final boolean isWeekly = getDataManager().isDosesWeekly();
+ //checking choice of pill whether weekly or daily
+ if (isWeekly) {
+ choice = "weekly";
+ } else {
+ choice = "daily";
+ }
+
+ fourthMonthData(setUpMonth, setUpYear, date, choice, isWeekly);
+ thirdMonthData(setUpMonth, setUpYear, date, choice, isWeekly);
+ secondMonthData(setUpMonth, setUpYear, date, choice, isWeekly);
+ firstMonthData(setUpMonth, setUpYear, date, choice, isWeekly);
+
+ }
+
+ private void fourthMonthData(final int setUpMonth, final int setUpYear, final int date, String choice, final boolean isWeekly) {
+ final String fourthMonth = getMonth(date);
+ getDataManager().getCountForProgressBar(mDate, mYear, "yes", choice, new DbHelper.LoadIntegerCallback() {
+ @Override
+ public void onDataLoaded(int count) {
+ float progressPercentage;
+ if (!isWeekly) {
+ progressPercentage = (float) count / getNumberOfDaysInMonth(mDate) * 100;
+ } else {
+ progressPercentage = count * 25;
+ }
+ String fourthPer;
+ if ((date - 1) >= setUpMonth || mYear != setUpYear || progressPercentage != 0) {
+ fourthPer = "" + (int) progressPercentage + "%";
+ } else {
+ fourthPer = "N.A";
+ }
+ dataList.add(new AnalysisModel(fourthMonth, fourthPer));
+ }
+ });
+ }
+
+ private void thirdMonthData(final int setUpMonth, final int setUpYear, final int date, final String choice, final boolean isWeekly) {
+ final String thirdMonth = getMonth(date - 1);
+ getDataManager().getCountForProgressBar(mDate, mYear, "yes", choice, new DbHelper.LoadIntegerCallback() {
+ @Override
+ public void onDataLoaded(int count) {
+ float progressPercentage;
+ if (!isWeekly) {
+ progressPercentage = (float) count / getNumberOfDaysInMonth(mDate) * 100;
+ } else {
+ progressPercentage = count * 25;
+ }
+ String thirdPer;
+ if ((date - 1) >= setUpMonth || mYear != setUpYear || progressPercentage != 0) {
+ thirdPer = "" + (int) progressPercentage;
+ } else {
+ thirdPer = "N.A";
+ }
+ dataList.add(new AnalysisModel(thirdMonth, thirdPer));
+ }
+ });
+ }
+
+ private void secondMonthData(final int setUpMonth, final int setUpYear, final int date, final String choice, final boolean isWeekly) {
+ final String secondMonth = getMonth(date - 2);
+ getDataManager().getCountForProgressBar(mDate, mYear, "yes", choice, new DbHelper.LoadIntegerCallback() {
+ @Override
+ public void onDataLoaded(int count) {
+ float progressPercentage;
+ if (!isWeekly) {
+ progressPercentage = (float) count / getNumberOfDaysInMonth(mDate) * 100;
+ } else {
+ progressPercentage = count * 25;
+ }
+ String secondPer;
+ if ((date - 2) >= setUpMonth || mYear != setUpYear || progressPercentage != 0) {
+ secondPer = "" + (int) progressPercentage;
+ } else {
+ secondPer = "N.A";
+ }
+ dataList.add(new AnalysisModel(secondMonth, secondPer));
+ }
+ });
+ }
+
+ private void firstMonthData(final int setUpMonth, final int setUpYear, final int date, final String choice, final boolean isWeekly) {
+ final String firstMonth = getMonth(date - 3);
+
+ getDataManager().getCountForProgressBar(mDate, mYear, "yes", choice,
+ new DbHelper.LoadIntegerCallback() {
+ @Override
+ public void onDataLoaded(int count) {
+ float progressPercentage;
+ if (!isWeekly) {
+ progressPercentage = (float) count / getNumberOfDaysInMonth(mDate) * 100;
+ } else {
+ progressPercentage = count * 25;
+ }
+ String firstPer;
+ if ((date - 3) >= setUpMonth || mYear != setUpYear || progressPercentage != 0) {
+ firstPer = "" + (int) progressPercentage;
+ } else {
+ firstPer = "N.A";
+ }
+ dataList.add(new AnalysisModel(firstMonth, firstPer));
+ getView().startRecyclerView();
+
+ }
+ });
+ }
+
+ //finding month from its integer
+ private String getMonth(int date) {
+ int d;
+ if (date == -1) {
+ d = 11;
+ mYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
+ } else if (date == -2) {
+ d = 10;
+ mYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
+ } else if (date == -3) {
+ d = 9;
+ mYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
+ } else {
+ d = date;
+ mYear = Calendar.getInstance().get(Calendar.YEAR);
+ mDate = date;
+ }
+ return monthList[d];
+ }
+
+ /*Finding No. of Days in Month*/
+ private int getNumberOfDaysInMonth(int month) {
+ return daysOfMonth[month];
+ }
+
+ public List getDataList() {
+ return dataList;
+ }
+
+ public void setDataList(List dataList) {
+ this.dataList = dataList;
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/TimelineAdapter.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/TimelineAdapter.java
new file mode 100644
index 00000000..d4d272c8
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/ui/user_profile/second_analysis/TimelineAdapter.java
@@ -0,0 +1,67 @@
+package com.peacecorps.malaria.ui.user_profile.second_analysis;
+
+import android.content.Context;
+import android.support.annotation.NonNull;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.github.vipulasri.timelineview.TimelineView;
+import com.peacecorps.malaria.R;
+
+/**
+ * Created by Anamika Tripathi on 11/8/18.
+ */
+public class TimelineAdapter extends RecyclerView.Adapter {
+
+ private SecondAnalysisPresenter presenter;
+ private Context context;
+
+ TimelineAdapter(SecondAnalysisPresenter presenter, Context context) {
+ this.presenter = presenter;
+ this.context = context;
+ }
+
+ @NonNull
+ @Override
+ public TimelineHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ View view;
+ view = View.inflate(context, R.layout.item_analysis_timeline, null);
+ return new TimelineHolder(view, viewType);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull TimelineHolder holder, int position) {
+ holder.description.setText(presenter.getDataList().get(position).getPercentage());
+ holder.title.setText(presenter.getDataList().get(position).getMonth());
+ }
+
+
+ @Override
+ public int getItemCount() {
+ if (presenter.getDataList() == null)
+ return 0;
+ return presenter.getDataList().size();
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ return TimelineView.getTimeLineViewType(position,getItemCount());
+ }
+
+ class TimelineHolder extends RecyclerView.ViewHolder {
+
+ private TimelineView timelineView;
+ private TextView title, description;
+
+ TimelineHolder(View itemView, int viewType) {
+ super(itemView);
+ timelineView = itemView.findViewById(R.id.time_marker);
+ title = itemView.findViewById(R.id.text_timeline_title);
+ description = itemView.findViewById(R.id.text_timeline_description);
+ timelineView.initLine(viewType);
+ }
+
+ }
+}
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/utils/ServerRequests.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/utils/ServerRequests.java
deleted file mode 100644
index a6c7757f..00000000
--- a/malaria-app-android/src/main/java/com/peacecorps/malaria/utils/ServerRequests.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package com.peacecorps.malaria.utils;
-
-import android.app.ProgressDialog;
-import android.content.Context;
-
-import com.peacecorps.malaria.code.interfaces.GetUserCallback;
-import com.peacecorps.malaria.code.model.AppUserModel;
-
-//import org.apache.http.HttpResponse;
-//import org.apache.http.NameValuePair;
-//import org.apache.http.client.HttpClient;
-//import org.apache.http.client.entity.UrlEncodedFormEntity;
-//import org.apache.http.client.methods.HttpPost;
-//import org.apache.http.impl.client.DefaultHttpClient;
-//import org.apache.http.message.BasicNameValuePair;
-//import org.apache.http.params.BasicHttpParams;
-
-
-// TODO: Since servers are not working,http errors should be fixed after community's decision. Issue #281 ;)
-
-/**
- * Created by yatna on 10/7/16.
- */
-public class ServerRequests {
- ProgressDialog progressDialog;
- public static final int CONNECTION_TIMEOUT = 1000 * 15;
- public static final String SERVER_ADDRESS = "http://pc-web-dev.systers.org/api/malaria_users/";
-
- //define a progress dialog on start
- public ServerRequests(Context context) {
- progressDialog = new ProgressDialog(context);
- progressDialog.setCancelable(false);
- progressDialog.setMessage("Please wait...");
- }
-
- public void storeUserDataInBackground(AppUserModel user, GetUserCallback userCallBack) {
- progressDialog.show();
- // new StoreUserDataAsyncTask(user, userCallBack).execute();
- }
-
-// public class StoreUserDataAsyncTask extends AsyncTask {
-// AppUserModel user;
-// GetUserCallback userCallBack;
-//
-// public StoreUserDataAsyncTask(AppUserModel user, GetUserCallback userCallBack) {
-// this.user = user;
-// this.userCallBack = userCallBack;
-// }
-//
-// @Override
-// protected String doInBackground(Void... params) {
-// //add details to send
-// ArrayList dataToSend = new ArrayList<>();
-// dataToSend.add(new BasicNameValuePair("name", user.getName()));
-// dataToSend.add(new BasicNameValuePair("email", user.getEmail()));
-// dataToSend.add(new BasicNameValuePair("age", user.getAge()+""));
-// dataToSend.add(new BasicNameValuePair("medicine", user.getMedicineType()));
-//
-// HttpParams httpRequestParams = getHttpRequestParams();
-// HttpClient client = new DefaultHttpClient(httpRequestParams);
-// HttpPost post = new HttpPost(SERVER_ADDRESS);
-// String status="";
-// try {
-// post.setEntity(new UrlEncodedFormEntity(dataToSend));
-// HttpResponse response=client.execute(post);
-// status=response.getStatusLine().getStatusCode()+"";
-// Log.d("MyResponseCode ", "-> "+status);
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-//
-// return status;
-// }
-//
-// @Override
-// protected void onPostExecute(String result) {
-// super.onPostExecute(result);
-// progressDialog.dismiss();
-// userCallBack.done(result);
-// }
-//
-// private HttpParams getHttpRequestParams() {
-// HttpParams httpRequestParams = new BasicHttpParams();
-// HttpConnectionParams.setConnectionTimeout(httpRequestParams,
-// CONNECTION_TIMEOUT);
-// HttpConnectionParams.setSoTimeout(httpRequestParams,
-// CONNECTION_TIMEOUT);
-// return httpRequestParams;
-// }
-//
-// }
-
-}
-
diff --git a/malaria-app-android/src/main/java/com/peacecorps/malaria/utils/TypefaceUtil.java b/malaria-app-android/src/main/java/com/peacecorps/malaria/utils/TypefaceUtil.java
new file mode 100644
index 00000000..eb974189
--- /dev/null
+++ b/malaria-app-android/src/main/java/com/peacecorps/malaria/utils/TypefaceUtil.java
@@ -0,0 +1,29 @@
+package com.peacecorps.malaria.utils;
+
+import android.content.Context;
+import android.graphics.Typeface;
+
+import java.lang.reflect.Field;
+
+/**
+ * Created by Anamika Tripathi on 7/8/18.
+ */
+public class TypefaceUtil {
+
+ /**
+ * @param context to work with assets
+ * @param defaultFontNameToOverride for example "serif"
+ * @param customFontFileNameInAssets file name of the font from assets
+ */
+ public static void overrideFont(Context context, String defaultFontNameToOverride, String customFontFileNameInAssets) {
+ try {
+ final Typeface customFontTypeface = Typeface.createFromAsset(context.getAssets(), customFontFileNameInAssets);
+
+ final Field defaultFontTypefaceField = Typeface.class.getDeclaredField(defaultFontNameToOverride);
+ defaultFontTypefaceField.setAccessible(true);
+ defaultFontTypefaceField.set(null, customFontTypeface);
+ } catch (Exception e) {
+ ToastLogSnackBarUtil.showErrorLog("Can't set custom font instead!");
+ }
+ }
+}
\ No newline at end of file
diff --git a/malaria-app-android/src/main/res/drawable-hdpi/action_edit_account.png b/malaria-app-android/src/main/res/drawable-hdpi/action_edit_account.png
new file mode 100644
index 00000000..be070986
Binary files /dev/null and b/malaria-app-android/src/main/res/drawable-hdpi/action_edit_account.png differ
diff --git a/malaria-app-android/src/main/res/drawable-hdpi/action_medicine_store.png b/malaria-app-android/src/main/res/drawable-hdpi/action_medicine_store.png
new file mode 100644
index 00000000..f667c003
Binary files /dev/null and b/malaria-app-android/src/main/res/drawable-hdpi/action_medicine_store.png differ
diff --git a/malaria-app-android/src/main/res/drawable-mdpi/action_edit_account.png b/malaria-app-android/src/main/res/drawable-mdpi/action_edit_account.png
new file mode 100644
index 00000000..29fa671e
Binary files /dev/null and b/malaria-app-android/src/main/res/drawable-mdpi/action_edit_account.png differ
diff --git a/malaria-app-android/src/main/res/drawable-mdpi/action_medicine_store.png b/malaria-app-android/src/main/res/drawable-mdpi/action_medicine_store.png
new file mode 100644
index 00000000..87c9364c
Binary files /dev/null and b/malaria-app-android/src/main/res/drawable-mdpi/action_medicine_store.png differ
diff --git a/malaria-app-android/src/main/res/drawable-xhdpi/action_edit_account.png b/malaria-app-android/src/main/res/drawable-xhdpi/action_edit_account.png
new file mode 100644
index 00000000..a12a9151
Binary files /dev/null and b/malaria-app-android/src/main/res/drawable-xhdpi/action_edit_account.png differ
diff --git a/malaria-app-android/src/main/res/drawable-xhdpi/action_medicine_store.png b/malaria-app-android/src/main/res/drawable-xhdpi/action_medicine_store.png
new file mode 100644
index 00000000..7f115676
Binary files /dev/null and b/malaria-app-android/src/main/res/drawable-xhdpi/action_medicine_store.png differ
diff --git a/malaria-app-android/src/main/res/drawable-xxhdpi/action_edit_account.png b/malaria-app-android/src/main/res/drawable-xxhdpi/action_edit_account.png
new file mode 100644
index 00000000..19b61453
Binary files /dev/null and b/malaria-app-android/src/main/res/drawable-xxhdpi/action_edit_account.png differ
diff --git a/malaria-app-android/src/main/res/drawable-xxhdpi/action_medicine_store.png b/malaria-app-android/src/main/res/drawable-xxhdpi/action_medicine_store.png
new file mode 100644
index 00000000..7b062392
Binary files /dev/null and b/malaria-app-android/src/main/res/drawable-xxhdpi/action_medicine_store.png differ
diff --git a/malaria-app-android/src/main/res/drawable-xxxhdpi/btn_add_medicine.png b/malaria-app-android/src/main/res/drawable-xxxhdpi/btn_add_medicine.png
new file mode 100644
index 00000000..1090af56
Binary files /dev/null and b/malaria-app-android/src/main/res/drawable-xxxhdpi/btn_add_medicine.png differ
diff --git a/malaria-app-android/src/main/res/drawable-xxxhdpi/btn_medicine_reminder.png b/malaria-app-android/src/main/res/drawable-xxxhdpi/btn_medicine_reminder.png
new file mode 100644
index 00000000..cd8e9a5f
Binary files /dev/null and b/malaria-app-android/src/main/res/drawable-xxxhdpi/btn_medicine_reminder.png differ
diff --git a/malaria-app-android/src/main/res/drawable-xxxhdpi/warning.png b/malaria-app-android/src/main/res/drawable-xxxhdpi/warning.png
new file mode 100644
index 00000000..404ae22e
Binary files /dev/null and b/malaria-app-android/src/main/res/drawable-xxxhdpi/warning.png differ
diff --git a/malaria-app-android/src/main/res/drawable/timeline_marker.xml b/malaria-app-android/src/main/res/drawable/timeline_marker.xml
new file mode 100644
index 00000000..4d558049
--- /dev/null
+++ b/malaria-app-android/src/main/res/drawable/timeline_marker.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/malaria-app-android/src/main/res/drawable/warning.png b/malaria-app-android/src/main/res/drawable/warning.png
deleted file mode 100644
index a31605ea..00000000
Binary files a/malaria-app-android/src/main/res/drawable/warning.png and /dev/null differ
diff --git a/malaria-app-android/src/main/res/layout/activity_edit_profile.xml b/malaria-app-android/src/main/res/layout/activity_edit_profile.xml
new file mode 100644
index 00000000..b9bd3f95
--- /dev/null
+++ b/malaria-app-android/src/main/res/layout/activity_edit_profile.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
diff --git a/malaria-app-android/src/main/res/layout/activity_medicine_store.xml b/malaria-app-android/src/main/res/layout/activity_medicine_store.xml
new file mode 100644
index 00000000..52ac8ae5
--- /dev/null
+++ b/malaria-app-android/src/main/res/layout/activity_medicine_store.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
diff --git a/malaria-app-android/src/main/res/layout/activity_myth_fact.xml b/malaria-app-android/src/main/res/layout/activity_myth_fact.xml
new file mode 100644
index 00000000..853fb78f
--- /dev/null
+++ b/malaria-app-android/src/main/res/layout/activity_myth_fact.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
diff --git a/malaria-app-android/src/main/res/layout/activity_rapid_fire.xml b/malaria-app-android/src/main/res/layout/activity_rapid_fire.xml
new file mode 100644
index 00000000..cbd7cafa
--- /dev/null
+++ b/malaria-app-android/src/main/res/layout/activity_rapid_fire.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
diff --git a/malaria-app-android/src/main/res/layout/badge_room.xml b/malaria-app-android/src/main/res/layout/badge_room.xml
index 1aae09ed..ced53084 100644
--- a/malaria-app-android/src/main/res/layout/badge_room.xml
+++ b/malaria-app-android/src/main/res/layout/badge_room.xml
@@ -13,7 +13,7 @@
android:layout_marginLeft="@dimen/margin_10dp"
android:layout_marginStart="@dimen/margin_10dp"
android:layout_marginTop="@dimen/margin_10dp"
- android:layout_weight="0.6"
+ android:layout_weight="0.3"
android:clickable="true"
android:focusable="true">
diff --git a/malaria-app-android/src/main/res/layout/badge_room_dialog.xml b/malaria-app-android/src/main/res/layout/badge_room_dialog.xml
index e46ec82c..7fe94b89 100644
--- a/malaria-app-android/src/main/res/layout/badge_room_dialog.xml
+++ b/malaria-app-android/src/main/res/layout/badge_room_dialog.xml
@@ -23,15 +23,22 @@
+
+
diff --git a/malaria-app-android/src/main/res/layout/fragment_first_analytic_screen.xml b/malaria-app-android/src/main/res/layout/fragment_first_analytic_screen.xml
index da758354..6c349b72 100644
--- a/malaria-app-android/src/main/res/layout/fragment_first_analytic_screen.xml
+++ b/malaria-app-android/src/main/res/layout/fragment_first_analytic_screen.xml
@@ -3,25 +3,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
- android:background="@drawable/background"
android:orientation="vertical"
android:padding="@dimen/padding_2dp">
-
@@ -13,14 +12,22 @@
android:layout_gravity="end"
android:padding="@dimen/padding_2dp">
+
+
-
-
+ android:textStyle="bold"
+ android:textColor="@color/textColorPrimary" />
+ android:background="@drawable/reject_medi_checked" />
+ android:background="@drawable/accept_medi_checked_"
+ android:scaleType="fitCenter" />
\ No newline at end of file
diff --git a/malaria-app-android/src/main/res/layout/fragment_plan_trip.xml b/malaria-app-android/src/main/res/layout/fragment_plan_trip.xml
index 86c598d5..95d2f5c9 100644
--- a/malaria-app-android/src/main/res/layout/fragment_plan_trip.xml
+++ b/malaria-app-android/src/main/res/layout/fragment_plan_trip.xml
@@ -14,7 +14,7 @@
android:drawableTop="@drawable/peacecorps_small"
android:text="@string/plan_my_trip_label"
android:textColor="@color/textColorPrimary"
- android:textSize="@dimen/text_size_25sp"
+ android:textSize="@dimen/text_size_16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
@@ -23,13 +23,14 @@
@@ -46,13 +47,14 @@
@@ -69,12 +71,13 @@
@@ -91,13 +94,14 @@
@@ -112,13 +116,14 @@
@@ -134,14 +139,19 @@
+ app:layout_constraintTop_toBottomOf="@id/tvl_reminder_time"
+ app:layout_constraintVertical_bias="0.094" />
\ No newline at end of file
diff --git a/malaria-app-android/src/main/res/layout/fragment_play.xml b/malaria-app-android/src/main/res/layout/fragment_play.xml
index f76ae7fe..057fbc47 100644
--- a/malaria-app-android/src/main/res/layout/fragment_play.xml
+++ b/malaria-app-android/src/main/res/layout/fragment_play.xml
@@ -1,79 +1,33 @@
-
-
-
+ android:gravity="center"
+ android:orientation="vertical">
+ android:textSize="@dimen/text_size_16sp"
+ android:textStyle="bold" />
-
-
-
-
\ No newline at end of file
+ android:textSize="@dimen/text_size_16sp"
+ android:textStyle="bold" />
+
diff --git a/malaria-app-android/src/main/res/layout/fragment_second_analytic_screen.xml b/malaria-app-android/src/main/res/layout/fragment_second_analytic_screen.xml
index b1c2f70e..25bc1d1d 100644
--- a/malaria-app-android/src/main/res/layout/fragment_second_analytic_screen.xml
+++ b/malaria-app-android/src/main/res/layout/fragment_second_analytic_screen.xml
@@ -3,26 +3,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
- android:background="@drawable/background"
android:orientation="vertical"
- android:padding="@dimen/padding_2dp" >
+ android:padding="@dimen/padding_2dp">
-
+
-
-
-
diff --git a/malaria-app-android/src/main/res/layout/fragment_second_analytic_screen_progress.xml b/malaria-app-android/src/main/res/layout/fragment_second_analytic_screen_progress.xml
index e7e220c8..355a87a8 100644
--- a/malaria-app-android/src/main/res/layout/fragment_second_analytic_screen_progress.xml
+++ b/malaria-app-android/src/main/res/layout/fragment_second_analytic_screen_progress.xml
@@ -2,6 +2,7 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/malaria-app-android/src/main/res/layout/fragment_user_profile.xml b/malaria-app-android/src/main/res/layout/fragment_user_profile.xml
index 3136f4f3..5d031d87 100644
--- a/malaria-app-android/src/main/res/layout/fragment_user_profile.xml
+++ b/malaria-app-android/src/main/res/layout/fragment_user_profile.xml
@@ -7,16 +7,21 @@
@@ -78,11 +83,16 @@
+ Every question is given with 3 options
+ Read the question carefully, and quickly select one of the 3 options.
+ For every correct option, a point is awarded
+ Timer shows seconds left for each question
+ The questions have to be answered under 5 seconds.
+ Exit the game by clicking here
+
+ Read the statement carefully
+ If it is a fact, drag it to the chest
+ If it is a myth, drag it to the trash bin
+ Decide whether it is a myth or a fact.
+ For every correct option, a point is awarded
+ Exit the game by clicking here
+ Click \"Next\" to go to next question
+ For every question, it is disabled. You can not skip a question.
+
"Departure date cannot be less than current date""Arrival date cannot be before the Departure date"
@@ -157,7 +173,7 @@
Age in yearsEnter Your Email AddressEnter Your Name
- reset
+ ResetEg 7
@@ -211,7 +227,7 @@
Drug:...Taken:
- 15/07
+ 11/08Arrival Date (DD/MM/YYYY)Select ItemsReminder (Hour/Minutes)
@@ -222,7 +238,7 @@
This text will get replaced automatically in the NewHomeActivity.7 DaysPeace Corps Policy
- Question Here
+ Melfoquine should be takenOption hereSET REMINDER TONESpecify file path
@@ -237,6 +253,7 @@
Add ItemsVolunteer Adherence Rates0
+ Edit Profile
diff --git a/malaria-app-android/src/main/res/values/styles.xml b/malaria-app-android/src/main/res/values/styles.xml
index e927b244..92f6b71a 100644
--- a/malaria-app-android/src/main/res/values/styles.xml
+++ b/malaria-app-android/src/main/res/values/styles.xml
@@ -13,8 +13,9 @@
@style/MyDatePicker@color/text_color_primary
- @drawable/background
+ @color/creamtrue
+ serif
@@ -125,12 +126,6 @@
25sp
-
-