From 48e5679500a9d543e79ba6553aaa44239d6902bb Mon Sep 17 00:00:00 2001 From: abhishek Date: Thu, 31 Jan 2019 14:43:24 +0530 Subject: [PATCH 1/3] 1.All Test Passed 2.small bug fixes 3.three parameter constructor added to ToDoItem --- .idea/misc.xml | 13 +++--- app/app.iml | 40 +++++++++---------- .../minimaltodo/TestStoreRetrieveData.java | 5 ++- .../minimaltodo/Utility/ToDoItem.java | 9 +++++ 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 99202cc2..1dc74551 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,30 +5,31 @@ - - - - \ No newline at end of file diff --git a/app/app.iml b/app/app.iml index 2a197e74..61638d0f 100644 --- a/app/app.iml +++ b/app/app.iml @@ -50,13 +50,6 @@ - - - - - - - @@ -64,6 +57,13 @@ + + + + + + + @@ -71,13 +71,6 @@ - - - - - - - @@ -85,31 +78,36 @@ + + + + + + + - + + - - - + - + - @@ -122,8 +120,8 @@ - + diff --git a/app/src/androidTest/java/com/example/avjindersinghsekhon/minimaltodo/TestStoreRetrieveData.java b/app/src/androidTest/java/com/example/avjindersinghsekhon/minimaltodo/TestStoreRetrieveData.java index f698fe54..9c904b47 100644 --- a/app/src/androidTest/java/com/example/avjindersinghsekhon/minimaltodo/TestStoreRetrieveData.java +++ b/app/src/androidTest/java/com/example/avjindersinghsekhon/minimaltodo/TestStoreRetrieveData.java @@ -27,6 +27,7 @@ import android.test.ActivityUnitTestCase; import com.example.avjindersinghsekhon.minimaltodo.Main.MainActivity; +import com.example.avjindersinghsekhon.minimaltodo.Main.MainFragment; import com.example.avjindersinghsekhon.minimaltodo.Utility.StoreRetrieveData; import com.example.avjindersinghsekhon.minimaltodo.Utility.ToDoItem; @@ -42,7 +43,7 @@ public class TestStoreRetrieveData extends ActivityUnitTestCase { private MainActivity mMainActivity; private ArrayList mOriginalData; - ArrayList mTestData; + private ArrayList mTestData; public TestStoreRetrieveData() { super(MainActivity.class); @@ -168,6 +169,6 @@ public void testArrayListToJsonArrayConversion() { private StoreRetrieveData getDataStorage() { Context context = getInstrumentation().getTargetContext(); - return new StoreRetrieveData(context, MainActivity.FILENAME); + return new StoreRetrieveData(context, MainFragment.FILENAME); } } diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ToDoItem.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ToDoItem.java index 46ca6ba3..94904022 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ToDoItem.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ToDoItem.java @@ -35,6 +35,15 @@ public ToDoItem(String todoBody,String tododescription, boolean hasReminder, Da mTodoIdentifier = UUID.randomUUID(); } + public ToDoItem(String todoBody, boolean hasReminder, Date todoDate){ + mToDoText = todoBody; + mHasReminder = hasReminder; + mToDoDate = todoDate; + mTodoColor = 1677725; + mToDoDescription = ""; + mTodoIdentifier = UUID.randomUUID(); + } + public ToDoItem(JSONObject jsonObject) throws JSONException { mToDoText = jsonObject.getString(TODOTEXT); mToDoDescription = jsonObject.getString(TODODESCRIPTION); From da3a480d9d9f681d242e927e87cb2eed4ad9390c Mon Sep 17 00:00:00 2001 From: abhishek Date: Fri, 1 Feb 2019 21:08:31 +0530 Subject: [PATCH 2/3] Code added and changed to Remove Notification(If in Notification Bar) if ToDoItem is deleted from app --- .../minimaltodo/Main/MainFragment.java | 27 ++++++++++++++++--- .../Utility/DeleteNotificationService.java | 1 + .../Utility/TodoNotificationService.java | 4 ++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/MainFragment.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/MainFragment.java index 8577de1e..ff219f6a 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/MainFragment.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/MainFragment.java @@ -1,7 +1,9 @@ package com.example.avjindersinghsekhon.minimaltodo.Main; import android.app.AlarmManager; +import android.app.NotificationManager; import android.app.PendingIntent; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; @@ -35,6 +37,7 @@ import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication; import com.example.avjindersinghsekhon.minimaltodo.AppDefault.AppDefaultFragment; import com.example.avjindersinghsekhon.minimaltodo.R; +import com.example.avjindersinghsekhon.minimaltodo.Reminder.ReminderActivity; import com.example.avjindersinghsekhon.minimaltodo.Reminder.ReminderFragment; import com.example.avjindersinghsekhon.minimaltodo.Settings.SettingsActivity; import com.example.avjindersinghsekhon.minimaltodo.Utility.ItemTouchHelperClass; @@ -49,6 +52,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; +import java.util.UUID; import static android.app.Activity.RESULT_CANCELED; import static android.content.Context.ALARM_SERVICE; @@ -60,6 +64,7 @@ public class MainFragment extends AppDefaultFragment { private ArrayList mToDoItemsArrayList; private CoordinatorLayout mCoordLayout; public static final String TODOITEM = "com.avjindersinghsekhon.com.avjindersinghsekhon.minimaltodo.MainActivity"; + public static final String TAG = "MainFragment"; private MainFragment.BasicListAdapter adapter; private static final int REQUEST_ID_TODO_ITEM = 100; private ToDoItem mJustDeletedToDoItem; @@ -385,6 +390,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { if (!existed) { addToDataStore(item); } +// }); + } @@ -407,6 +414,7 @@ private void createAlarm(Intent i, int requestCode, long timeInMillis) { } private void deleteAlarm(Intent i, int requestCode) { + Log.d(TAG, "deleteAlarm: called"); if (doesPendingIntentExist(i, requestCode)) { PendingIntent pi = PendingIntent.getService(getContext(), requestCode, i, PendingIntent.FLAG_NO_CREATE); pi.cancel(); @@ -415,6 +423,17 @@ private void deleteAlarm(Intent i, int requestCode) { } } + private void deleteNotification(UUID mTodoUUID) { + int NOTIFICATION_ID = mTodoUUID.hashCode(); + Intent notificationIntent = new Intent(getContext(),ReminderActivity.class); + PendingIntent i = PendingIntent.getActivity(getContext(), NOTIFICATION_ID, notificationIntent, PendingIntent.FLAG_NO_CREATE); + + if (i != null){ + NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(NOTIFICATION_ID); + } + } + private void addToDataStore(ToDoItem item) { mToDoItemsArrayList.add(item); adapter.notifyItemInserted(mToDoItemsArrayList.size() - 1); @@ -431,8 +450,8 @@ public void makeUpItems(ArrayList items, int len) { } } - public class BasicListAdapter extends RecyclerView.Adapter implements ItemTouchHelperClass.ItemTouchHelperAdapter { + private ArrayList items; @Override @@ -451,6 +470,7 @@ public void onItemMoved(int fromPosition, int toPosition) { @Override public void onItemRemoved(final int position) { + Log.d(TAG, "onItemRemoved: position: "+position); //Remove this line if not using Google Analytics app.send(this, "Action", "Swiped Todo Away"); @@ -458,6 +478,7 @@ public void onItemRemoved(final int position) { mIndexOfDeletedToDoItem = position; Intent i = new Intent(getContext(), TodoNotificationService.class); deleteAlarm(i, mJustDeletedToDoItem.getIdentifier().hashCode()); + deleteNotification(mJustDeletedToDoItem.getIdentifier()); notifyItemRemoved(position); // String toShow = (mJustDeletedToDoItem.getToDoText().length()>20)?mJustDeletedToDoItem.getToDoText().substring(0, 20)+"...":mJustDeletedToDoItem.getToDoText(); @@ -559,7 +580,6 @@ public int getItemCount() { this.items = items; } - @SuppressWarnings("deprecation") public class ViewHolder extends RecyclerView.ViewHolder { @@ -569,6 +589,7 @@ public class ViewHolder extends RecyclerView.ViewHolder { // TextView mColorTextView; ImageView mColorImageView; TextView mTimeTextView; + // int color = -1; public ViewHolder(View v) { @@ -590,8 +611,8 @@ public void onClick(View v) { linearLayout = (LinearLayout) v.findViewById(R.id.listItemLinearLayout); } - } + } //Used when using custom fonts diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/DeleteNotificationService.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/DeleteNotificationService.java index 67d98657..3398ee14 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/DeleteNotificationService.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/DeleteNotificationService.java @@ -11,6 +11,7 @@ public class DeleteNotificationService extends IntentService { + public static final String TAG = "DeleteNotificationService"; private StoreRetrieveData storeRetrieveData; private ArrayList mToDoItems; private ToDoItem mItem; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/TodoNotificationService.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/TodoNotificationService.java index 87f379bb..8c710bee 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/TodoNotificationService.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/TodoNotificationService.java @@ -18,6 +18,7 @@ public class TodoNotificationService extends IntentService { public static final String TODOUUID = "com.avjindersekhon.todonotificationserviceuuid"; private String mTodoText; private UUID mTodoUUID; + private int mUUIDHash; private Context mContext; public TodoNotificationService() { @@ -28,6 +29,7 @@ public TodoNotificationService() { protected void onHandleIntent(Intent intent) { mTodoText = intent.getStringExtra(TODOTEXT); mTodoUUID = (UUID) intent.getSerializableExtra(TODOUUID); + mUUIDHash = mTodoUUID.hashCode(); Log.d("OskarSchindler", "onHandleIntent called"); NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); @@ -44,7 +46,7 @@ protected void onHandleIntent(Intent intent) { .setContentIntent(PendingIntent.getActivity(this, mTodoUUID.hashCode(), i, PendingIntent.FLAG_UPDATE_CURRENT)) .build(); - manager.notify(100, notification); + manager.notify(mUUIDHash, notification); // Uri defaultRingone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // MediaPlayer mp = new MediaPlayer(); // try{ From 3232c0ba810557e9af81678e1e9c27624ca99214 Mon Sep 17 00:00:00 2001 From: abhishek Date: Fri, 1 Feb 2019 21:17:47 +0530 Subject: [PATCH 3/3] Small Code Refactoring --- .../avjindersinghsekhon/minimaltodo/Main/MainFragment.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/MainFragment.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/MainFragment.java index ff219f6a..ffb52312 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/MainFragment.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/MainFragment.java @@ -404,6 +404,7 @@ private AlarmManager getAlarmManager() { private boolean doesPendingIntentExist(Intent i, int requestCode) { PendingIntent pi = PendingIntent.getService(getContext(), requestCode, i, PendingIntent.FLAG_NO_CREATE); return pi != null; + } private void createAlarm(Intent i, int requestCode, long timeInMillis) {