From a80472874e0694b5a97e3c530cd72e2479bd4ad8 Mon Sep 17 00:00:00 2001 From: Justinas Cepkauskas Date: Wed, 21 Feb 2018 07:50:46 +0000 Subject: [PATCH 01/12] Create packages and put appropriate classes to those packages to seperate all files being in one place --- .idea/.name | 1 - .idea/gradle.xml | 7 +- .idea/misc.xml | 15 +-- app/app.iml | 98 ++++++++++++------- app/build.gradle | 2 +- .../minimaltodo/TestStoreRetrieveData.java | 4 + .../minimaltodo/TestTodoItem.java | 2 + app/src/main/AndroidManifest.xml | 22 ++--- .../{ => About}/AboutActivity.java | 7 +- .../{ => AddToDo}/AddToDoActivity.java | 6 +- .../{ => Analytics}/AnalyticsApplication.java | 3 +- .../CustomRecyclerScrollViewListener.java | 2 +- .../minimaltodo/{ => Main}/MainActivity.java | 13 ++- .../{ => Reminder}/ReminderActivity.java | 9 +- .../{ => Settings}/SettingsActivity.java | 6 +- .../{ => Settings}/SettingsFragment.java | 7 +- .../{ => Utility}/CustomTextInputLayout.java | 2 +- .../DeleteNotificationService.java | 7 +- .../{ => Utility}/ItemTouchHelperClass.java | 2 +- .../{ => Utility}/PreferenceKeys.java | 6 +- .../RecyclerViewEmptySupport.java | 2 +- .../{ => Utility}/ScrollingFABBehaviour.java | 4 +- .../{ => Utility}/StoreRetrieveData.java | 4 +- .../minimaltodo/{ => Utility}/ToDoItem.java | 2 +- .../TodoNotificationService.java | 5 +- .../minimaltodo/{ => Utility}/Utils.java | 4 +- .../main/res/layout/activity_add_to_do.xml | 4 +- app/src/main/res/layout/activity_main.xml | 2 +- .../main/res/layout/activity_todo_test.xml | 4 +- app/src/main/res/menu/menu_main.xml | 2 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 32 files changed, 162 insertions(+), 98 deletions(-) delete mode 100644 .idea/.name rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => About}/AboutActivity.java (92%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => AddToDo}/AddToDoActivity.java (98%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Analytics}/AnalyticsApplication.java (95%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Main}/CustomRecyclerScrollViewListener.java (94%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Main}/MainActivity.java (96%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Reminder}/ReminderActivity.java (93%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Settings}/SettingsActivity.java (89%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Settings}/SettingsFragment.java (86%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Utility}/CustomTextInputLayout.java (96%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Utility}/DeleteNotificationService.java (84%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Utility}/ItemTouchHelperClass.java (97%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Utility}/PreferenceKeys.java (61%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Utility}/RecyclerViewEmptySupport.java (96%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Utility}/ScrollingFABBehaviour.java (94%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Utility}/StoreRetrieveData.java (95%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Utility}/ToDoItem.java (97%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Utility}/TodoNotificationService.java (92%) rename app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/{ => Utility}/Utils.java (80%) diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 3aabfafe..00000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Minimal \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 9c6b7d2b..18623c08 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -13,12 +13,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index 1a3eaffb..ba7052b8 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,8 +1,5 @@ - - - - - - - - - - - - - - + diff --git a/app/app.iml b/app/app.iml index f53f2619..984579e2 100644 --- a/app/app.iml +++ b/app/app.iml @@ -9,13 +9,9 @@ - + - + + @@ -38,73 +35,100 @@ + + - + + + + + + + + + + + + + + + - + + + + + + + + - + + + - - - - - - - - - - - - - - + + + + + + + + - + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 52163b93..d8909ba0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,7 +11,7 @@ android { } } compileSdkVersion 23 - buildToolsVersion "23.0.1" + buildToolsVersion '25.0.0' defaultConfig { applicationId "com.avjindersinghsekhon.minimaltodo" minSdkVersion 16 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 32111b58..f698fe54 100644 --- a/app/src/androidTest/java/com/example/avjindersinghsekhon/minimaltodo/TestStoreRetrieveData.java +++ b/app/src/androidTest/java/com/example/avjindersinghsekhon/minimaltodo/TestStoreRetrieveData.java @@ -26,6 +26,10 @@ import android.content.Context; import android.test.ActivityUnitTestCase; +import com.example.avjindersinghsekhon.minimaltodo.Main.MainActivity; +import com.example.avjindersinghsekhon.minimaltodo.Utility.StoreRetrieveData; +import com.example.avjindersinghsekhon.minimaltodo.Utility.ToDoItem; + import org.json.JSONArray; import java.util.ArrayList; diff --git a/app/src/androidTest/java/com/example/avjindersinghsekhon/minimaltodo/TestTodoItem.java b/app/src/androidTest/java/com/example/avjindersinghsekhon/minimaltodo/TestTodoItem.java index b835e8bb..8a4faf04 100644 --- a/app/src/androidTest/java/com/example/avjindersinghsekhon/minimaltodo/TestTodoItem.java +++ b/app/src/androidTest/java/com/example/avjindersinghsekhon/minimaltodo/TestTodoItem.java @@ -23,6 +23,8 @@ package com.example.avjindersinghsekhon.minimaltodo; +import com.example.avjindersinghsekhon.minimaltodo.Utility.ToDoItem; + import junit.framework.TestCase; import org.json.JSONException; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8f233448..a7d00cb2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,14 +10,14 @@ about 1 second, but it's jarring if users have set Night Mode to true. --> @@ -28,26 +28,26 @@ - - - - - - diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AboutActivity.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/About/AboutActivity.java similarity index 92% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AboutActivity.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/About/AboutActivity.java index 38bf6f0e..addf57ef 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AboutActivity.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/About/AboutActivity.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.About; import android.content.Intent; import android.content.pm.PackageInfo; @@ -14,7 +14,12 @@ import android.view.View; import android.widget.TextView; +import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication; +import com.example.avjindersinghsekhon.minimaltodo.Main.MainActivity; +import com.example.avjindersinghsekhon.minimaltodo.R; + public class AboutActivity extends AppCompatActivity { + private TextView mVersionTextView; private String appVersion = "0.1"; private Toolbar toolbar; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDoActivity.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDo/AddToDoActivity.java similarity index 98% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDoActivity.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDo/AddToDoActivity.java index 0ef821c0..d2ce25a4 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDoActivity.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDo/AddToDoActivity.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.AddToDo; import android.animation.Animator; import android.content.Intent; @@ -26,6 +26,10 @@ import android.widget.TextView; import android.widget.Toast; +import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication; +import com.example.avjindersinghsekhon.minimaltodo.Main.MainActivity; +import com.example.avjindersinghsekhon.minimaltodo.R; +import com.example.avjindersinghsekhon.minimaltodo.Utility.ToDoItem; import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; import com.wdullaer.materialdatetimepicker.time.RadialPickerLayout; import com.wdullaer.materialdatetimepicker.time.TimePickerDialog; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AnalyticsApplication.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Analytics/AnalyticsApplication.java similarity index 95% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AnalyticsApplication.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Analytics/AnalyticsApplication.java index 5c0620c5..906c5956 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AnalyticsApplication.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Analytics/AnalyticsApplication.java @@ -1,8 +1,9 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Analytics; import android.app.Application; import android.content.pm.PackageManager; +import com.example.avjindersinghsekhon.minimaltodo.R; import com.google.android.gms.analytics.GoogleAnalytics; import com.google.android.gms.analytics.HitBuilders; import com.google.android.gms.analytics.Tracker; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/CustomRecyclerScrollViewListener.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/CustomRecyclerScrollViewListener.java similarity index 94% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/CustomRecyclerScrollViewListener.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/CustomRecyclerScrollViewListener.java index ccad9b63..0485ea40 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/CustomRecyclerScrollViewListener.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/CustomRecyclerScrollViewListener.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Main; import android.support.v7.widget.RecyclerView; import android.util.Log; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/MainActivity.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/MainActivity.java similarity index 96% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/MainActivity.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/MainActivity.java index dc102b92..96f8b435 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/MainActivity.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Main/MainActivity.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Main; import android.app.AlarmManager; import android.app.PendingIntent; @@ -29,6 +29,17 @@ import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; +import com.example.avjindersinghsekhon.minimaltodo.About.AboutActivity; +import com.example.avjindersinghsekhon.minimaltodo.AddToDo.AddToDoActivity; +import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication; +import com.example.avjindersinghsekhon.minimaltodo.Utility.ItemTouchHelperClass; +import com.example.avjindersinghsekhon.minimaltodo.R; +import com.example.avjindersinghsekhon.minimaltodo.Utility.RecyclerViewEmptySupport; +import com.example.avjindersinghsekhon.minimaltodo.Reminder.ReminderActivity; +import com.example.avjindersinghsekhon.minimaltodo.Settings.SettingsActivity; +import com.example.avjindersinghsekhon.minimaltodo.Utility.StoreRetrieveData; +import com.example.avjindersinghsekhon.minimaltodo.Utility.ToDoItem; +import com.example.avjindersinghsekhon.minimaltodo.Utility.TodoNotificationService; import org.json.JSONException; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/ReminderActivity.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Reminder/ReminderActivity.java similarity index 93% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/ReminderActivity.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Reminder/ReminderActivity.java index 1b742905..073c6639 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/ReminderActivity.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Reminder/ReminderActivity.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Reminder; import android.content.Intent; import android.content.SharedPreferences; @@ -14,6 +14,13 @@ import android.widget.Button; import android.widget.TextView; +import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication; +import com.example.avjindersinghsekhon.minimaltodo.Main.MainActivity; +import com.example.avjindersinghsekhon.minimaltodo.R; +import com.example.avjindersinghsekhon.minimaltodo.Utility.StoreRetrieveData; +import com.example.avjindersinghsekhon.minimaltodo.Utility.ToDoItem; +import com.example.avjindersinghsekhon.minimaltodo.Utility.TodoNotificationService; + import org.json.JSONException; import java.io.IOException; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsActivity.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Settings/SettingsActivity.java similarity index 89% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsActivity.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Settings/SettingsActivity.java index ddbd9906..2588449f 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsActivity.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Settings/SettingsActivity.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Settings; import android.app.FragmentManager; import android.graphics.Color; @@ -10,6 +10,10 @@ import android.support.v7.widget.Toolbar; import android.view.MenuItem; +import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication; +import com.example.avjindersinghsekhon.minimaltodo.Main.MainActivity; +import com.example.avjindersinghsekhon.minimaltodo.R; + public class SettingsActivity extends AppCompatActivity{ AnalyticsApplication app; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsFragment.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Settings/SettingsFragment.java similarity index 86% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsFragment.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Settings/SettingsFragment.java index 3a7a508d..b5d7d0cf 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsFragment.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Settings/SettingsFragment.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Settings; import android.content.Context; import android.content.SharedPreferences; @@ -6,6 +6,11 @@ import android.preference.CheckBoxPreference; import android.preference.PreferenceFragment; +import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication; +import com.example.avjindersinghsekhon.minimaltodo.Main.MainActivity; +import com.example.avjindersinghsekhon.minimaltodo.Utility.PreferenceKeys; +import com.example.avjindersinghsekhon.minimaltodo.R; + public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener{ AnalyticsApplication app; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/CustomTextInputLayout.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/CustomTextInputLayout.java similarity index 96% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/CustomTextInputLayout.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/CustomTextInputLayout.java index 02bb8e01..31838bca 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/CustomTextInputLayout.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/CustomTextInputLayout.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Utility; import android.content.Context; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/DeleteNotificationService.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/DeleteNotificationService.java similarity index 84% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/DeleteNotificationService.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/DeleteNotificationService.java index 54ca55a5..33e4dd13 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/DeleteNotificationService.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/DeleteNotificationService.java @@ -1,9 +1,14 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Utility; import android.app.IntentService; import android.content.Intent; import android.content.SharedPreferences; +import com.example.avjindersinghsekhon.minimaltodo.Main.MainActivity; +import com.example.avjindersinghsekhon.minimaltodo.Utility.StoreRetrieveData; +import com.example.avjindersinghsekhon.minimaltodo.Utility.ToDoItem; +import com.example.avjindersinghsekhon.minimaltodo.Utility.TodoNotificationService; + import java.util.ArrayList; import java.util.UUID; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/ItemTouchHelperClass.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ItemTouchHelperClass.java similarity index 97% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/ItemTouchHelperClass.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ItemTouchHelperClass.java index 5d45848a..d444e383 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/ItemTouchHelperClass.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ItemTouchHelperClass.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Utility; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/PreferenceKeys.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/PreferenceKeys.java similarity index 61% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/PreferenceKeys.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/PreferenceKeys.java index 4f3f5cbb..0cc27d5e 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/PreferenceKeys.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/PreferenceKeys.java @@ -1,12 +1,14 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Utility; import android.content.res.Resources; +import com.example.avjindersinghsekhon.minimaltodo.R; + /** * Created by avjindersinghsekhon on 9/21/15. */ public class PreferenceKeys { - final String night_mode_pref_key; + public final String night_mode_pref_key; public PreferenceKeys(Resources resources){ night_mode_pref_key = resources.getString(R.string.night_mode_pref_key); diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/RecyclerViewEmptySupport.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/RecyclerViewEmptySupport.java similarity index 96% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/RecyclerViewEmptySupport.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/RecyclerViewEmptySupport.java index 1b760a81..6ce60f47 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/RecyclerViewEmptySupport.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/RecyclerViewEmptySupport.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Utility; import android.content.Context; import android.support.v7.widget.RecyclerView; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/ScrollingFABBehaviour.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ScrollingFABBehaviour.java similarity index 94% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/ScrollingFABBehaviour.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ScrollingFABBehaviour.java index 4183e585..e57da359 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/ScrollingFABBehaviour.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ScrollingFABBehaviour.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Utility; import android.content.Context; import android.support.design.widget.CoordinatorLayout; @@ -8,6 +8,8 @@ import android.util.AttributeSet; import android.view.View; +import com.example.avjindersinghsekhon.minimaltodo.Utility.Utils; + public class ScrollingFABBehaviour extends CoordinatorLayout.Behavior { private int toolbarHeight; private static boolean scrolledUp = false; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/StoreRetrieveData.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/StoreRetrieveData.java similarity index 95% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/StoreRetrieveData.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/StoreRetrieveData.java index 9773ca89..e62c0168 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/StoreRetrieveData.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/StoreRetrieveData.java @@ -1,7 +1,9 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Utility; import android.content.Context; +import com.example.avjindersinghsekhon.minimaltodo.Utility.ToDoItem; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/ToDoItem.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ToDoItem.java similarity index 97% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/ToDoItem.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ToDoItem.java index 872f1f37..f23c5482 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/ToDoItem.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/ToDoItem.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Utility; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/TodoNotificationService.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/TodoNotificationService.java similarity index 92% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/TodoNotificationService.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/TodoNotificationService.java index 16bd938e..b0f6ee65 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/TodoNotificationService.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/TodoNotificationService.java @@ -1,4 +1,4 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Utility; import android.app.IntentService; import android.app.Notification; @@ -8,6 +8,9 @@ import android.content.Intent; import android.util.Log; +import com.example.avjindersinghsekhon.minimaltodo.R; +import com.example.avjindersinghsekhon.minimaltodo.Reminder.ReminderActivity; + import java.util.UUID; public class TodoNotificationService extends IntentService { diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utils.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/Utils.java similarity index 80% rename from app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utils.java rename to app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/Utils.java index 119e748e..0b99bc02 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utils.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/Utility/Utils.java @@ -1,8 +1,10 @@ -package com.example.avjindersinghsekhon.minimaltodo; +package com.example.avjindersinghsekhon.minimaltodo.Utility; import android.content.Context; import android.content.res.TypedArray; +import com.example.avjindersinghsekhon.minimaltodo.R; + public class Utils { diff --git a/app/src/main/res/layout/activity_add_to_do.xml b/app/src/main/res/layout/activity_add_to_do.xml index cc25bf61..4365e3cf 100644 --- a/app/src/main/res/layout/activity_add_to_do.xml +++ b/app/src/main/res/layout/activity_add_to_do.xml @@ -28,7 +28,7 @@ android:layout_height="0dp"> - - + --> - - - + + tools:context=".AddToDo.AddToDoActivity"> diff --git a/build.gradle b/build.gradle index 2174a6ba..244e59fc 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.3.0' + classpath 'com.android.tools.build:gradle:3.0.1' classpath 'com.google.gms:google-services:1.3.0-beta1' // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41984045..f279f061 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Sep 07 15:41:13 GMT+05:30 2015 +#Tue Feb 06 14:47:31 GMT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip From 34747e8a88369319d8e9ef4e98d45d628a794553 Mon Sep 17 00:00:00 2001 From: Justinas Cepkauskas Date: Wed, 28 Mar 2018 19:50:22 +0100 Subject: [PATCH 02/12] add fragment container layout file --- app/src/main/res/layout/layout_fragment_container.xml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 app/src/main/res/layout/layout_fragment_container.xml diff --git a/app/src/main/res/layout/layout_fragment_container.xml b/app/src/main/res/layout/layout_fragment_container.xml new file mode 100644 index 00000000..2155c6fc --- /dev/null +++ b/app/src/main/res/layout/layout_fragment_container.xml @@ -0,0 +1,6 @@ + + \ No newline at end of file From d8c547989dc4bd898f3f32fd2d86602170d252e1 Mon Sep 17 00:00:00 2001 From: Justinas Cepkauskas Date: Wed, 28 Mar 2018 19:58:36 +0100 Subject: [PATCH 03/12] Create about fragment layout --- app/src/main/res/layout/fragment_about.xml | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 app/src/main/res/layout/fragment_about.xml diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml new file mode 100644 index 00000000..1ac36b53 --- /dev/null +++ b/app/src/main/res/layout/fragment_about.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + \ No newline at end of file From 2f6094b4bc2c2b838a57e5d5b72474c7dfde707d Mon Sep 17 00:00:00 2001 From: Justinas Cepkauskas Date: Sat, 31 Mar 2018 13:21:54 +0100 Subject: [PATCH 04/12] Create AppDefaultActivity --- .../AppDefault/AppDefaultActivity.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AppDefault/AppDefaultActivity.java diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AppDefault/AppDefaultActivity.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AppDefault/AppDefaultActivity.java new file mode 100644 index 00000000..de2d3771 --- /dev/null +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AppDefault/AppDefaultActivity.java @@ -0,0 +1,36 @@ +package com.example.avjindersinghsekhon.minimaltodo.AppDefault; + +import android.os.Bundle; +import android.support.annotation.LayoutRes; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.StringRes; +import android.support.v4.app.Fragment; +import android.support.v7.app.AppCompatActivity; + +import com.example.avjindersinghsekhon.minimaltodo.R; + +public abstract class AppDefaultActivity extends AppCompatActivity { + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(contentViewLayoutRes()); + setUpInitialFragment(savedInstanceState); + + } + + private void setUpInitialFragment(@Nullable Bundle savedInstanceState) { + if (savedInstanceState == null) { + getSupportFragmentManager() + .beginTransaction() + .replace(R.id.fragment_container, createInitialFragment()) + .commit(); + } + } + + @LayoutRes + protected abstract int contentViewLayoutRes(); + + @NonNull + protected abstract Fragment createInitialFragment(); +} From 9bdde83560280e51b7afaf9cfd81e487ef9f5626 Mon Sep 17 00:00:00 2001 From: Justinas Cepkauskas Date: Sat, 31 Mar 2018 13:22:39 +0100 Subject: [PATCH 05/12] Create AppDefaultFragment --- .../AppDefault/AppDefaultFragment.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AppDefault/AppDefaultFragment.java diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AppDefault/AppDefaultFragment.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AppDefault/AppDefaultFragment.java new file mode 100644 index 00000000..9c61f10f --- /dev/null +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AppDefault/AppDefaultFragment.java @@ -0,0 +1,30 @@ +package com.example.avjindersinghsekhon.minimaltodo.AppDefault; + +import android.os.Bundle; +import android.support.annotation.LayoutRes; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +public abstract class AppDefaultFragment extends Fragment { + + @Nullable + @Override + public View onCreateView( + LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState + ) { + return inflater.inflate(layoutRes(), container, false); + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + @LayoutRes + protected abstract int layoutRes(); +} From b269656d546d0b3a290b59535f6989842f2e0129 Mon Sep 17 00:00:00 2001 From: Justinas Cepkauskas Date: Sat, 31 Mar 2018 13:23:53 +0100 Subject: [PATCH 06/12] Create AboutFragment and recreate same funcionality in AboutFragment from AboutActivity --- .../minimaltodo/About/AboutActivity.java | 64 ++++++++----------- .../minimaltodo/About/AboutFragment.java | 56 ++++++++++++++++ app/src/main/res/layout/about_layout.xml | 55 +--------------- app/src/main/res/layout/fragment_about.xml | 1 + 4 files changed, 85 insertions(+), 91 deletions(-) create mode 100644 app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/About/AboutFragment.java diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/About/AboutActivity.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/About/AboutActivity.java index addf57ef..95463fdb 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/About/AboutActivity.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/About/AboutActivity.java @@ -1,93 +1,83 @@ package com.example.avjindersinghsekhon.minimaltodo.About; -import android.content.Intent; import android.content.pm.PackageInfo; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.Fragment; import android.support.v4.app.NavUtils; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.MenuItem; -import android.view.View; import android.widget.TextView; import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication; -import com.example.avjindersinghsekhon.minimaltodo.Main.MainActivity; +import com.example.avjindersinghsekhon.minimaltodo.AppDefault.AppDefaultActivity; +import com.example.avjindersinghsekhon.minimaltodo.Main.MainFragment; import com.example.avjindersinghsekhon.minimaltodo.R; -public class AboutActivity extends AppCompatActivity { +public class AboutActivity extends AppDefaultActivity { private TextView mVersionTextView; private String appVersion = "0.1"; private Toolbar toolbar; private TextView contactMe; String theme; -// private UUID mId; + // private UUID mId; private AnalyticsApplication app; @Override protected void onCreate(Bundle savedInstanceState) { - app = (AnalyticsApplication)getApplication(); - app.send(this); - theme = getSharedPreferences(MainActivity.THEME_PREFERENCES, MODE_PRIVATE).getString(MainActivity.THEME_SAVED, MainActivity.LIGHTTHEME); - if(theme.equals(MainActivity.DARKTHEME)){ + + theme = getSharedPreferences(MainFragment.THEME_PREFERENCES, MODE_PRIVATE).getString(MainFragment.THEME_SAVED, MainFragment.LIGHTTHEME); + if (theme.equals(MainFragment.DARKTHEME)) { Log.d("OskarSchindler", "One"); setTheme(R.style.CustomStyle_DarkTheme); - } - else{ + } else { Log.d("OskarSchindler", "One"); setTheme(R.style.CustomStyle_LightTheme); } super.onCreate(savedInstanceState); - setContentView(R.layout.about_layout); - - Intent i = getIntent(); // mId = (UUID)i.getSerializableExtra(TodoNotificationService.TODOUUID); final Drawable backArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha); - if(backArrow!=null){ + if (backArrow != null) { backArrow.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP); - } - try{ + try { PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0); appVersion = info.versionName; - } - catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } - - mVersionTextView = (TextView)findViewById(R.id.aboutVersionTextView); - mVersionTextView.setText(String.format(getResources().getString(R.string.app_version), appVersion)); - toolbar = (Toolbar)findViewById(R.id.toolbar); - contactMe = (TextView)findViewById(R.id.aboutContactMe); - - contactMe.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - app.send(this, "Action", "Feedback"); - } - }); - - + toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); - if(getSupportActionBar()!=null){ + if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeAsUpIndicator(backArrow); } } + @Override + protected int contentViewLayoutRes() { + return R.layout.about_layout; + } + + @NonNull + protected Fragment createInitialFragment() { + return AboutFragment.newInstance(); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()){ + switch (item.getItemId()) { case android.R.id.home: - if(NavUtils.getParentActivityName(this)!=null){ + if (NavUtils.getParentActivityName(this) != null) { NavUtils.navigateUpFromSameTask(this); } return true; diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/About/AboutFragment.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/About/AboutFragment.java new file mode 100644 index 00000000..44275854 --- /dev/null +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/About/AboutFragment.java @@ -0,0 +1,56 @@ +package com.example.avjindersinghsekhon.minimaltodo.About; + +import android.os.Bundle; +import android.support.annotation.LayoutRes; +import android.support.annotation.Nullable; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.widget.TextView; + +import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication; +import com.example.avjindersinghsekhon.minimaltodo.AppDefault.AppDefaultFragment; +import com.example.avjindersinghsekhon.minimaltodo.R; + +public class AboutFragment extends AppDefaultFragment { + + private TextView mVersionTextView; + private String appVersion = "0.1"; + private Toolbar toolbar; + private TextView contactMe; + private AnalyticsApplication app; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + app = (AnalyticsApplication)getActivity().getApplication(); + app.send(this); + mVersionTextView = (TextView)view.findViewById(R.id.aboutVersionTextView); + mVersionTextView.setText(String.format(getResources().getString(R.string.app_version), appVersion)); + toolbar = (Toolbar)view.findViewById(R.id.toolbar); + + contactMe = (TextView) view.findViewById(R.id.aboutContactMe); + + contactMe.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + app.send(this, "Action", "Feedback"); + } + }); + } + + @LayoutRes + protected int layoutRes() { + return R.layout.fragment_about; + } + + public static AboutFragment newInstance() { + return new AboutFragment(); + } +} diff --git a/app/src/main/res/layout/about_layout.xml b/app/src/main/res/layout/about_layout.xml index c3c79a8b..bd07ca02 100644 --- a/app/src/main/res/layout/about_layout.xml +++ b/app/src/main/res/layout/about_layout.xml @@ -5,58 +5,5 @@ android:layout_height="match_parent"> - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml index 1ac36b53..41efcbd3 100644 --- a/app/src/main/res/layout/fragment_about.xml +++ b/app/src/main/res/layout/fragment_about.xml @@ -2,6 +2,7 @@ Date: Sat, 31 Mar 2018 13:24:31 +0100 Subject: [PATCH 07/12] Create AddToDoFragment and recreate same funcionality in AddToDoFragment from AddToDoActivity --- .../minimaltodo/AddToDo/AddToDoActivity.java | 658 +----------------- .../minimaltodo/AddToDo/AddToDoFragment.java | 653 +++++++++++++++++ .../main/res/layout/activity_add_to_do.xml | 165 +---- .../main/res/layout/fragment_add_to_do.xml | 187 +++++ 4 files changed, 852 insertions(+), 811 deletions(-) create mode 100644 app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDo/AddToDoFragment.java create mode 100644 app/src/main/res/layout/fragment_add_to_do.xml diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDo/AddToDoActivity.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDo/AddToDoActivity.java index d2ce25a4..25bc73f3 100644 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDo/AddToDoActivity.java +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDo/AddToDoActivity.java @@ -1,673 +1,37 @@ package com.example.avjindersinghsekhon.minimaltodo.AddToDo; -import android.animation.Animator; -import android.content.Intent; -import android.graphics.Color; -import android.graphics.PorterDuff; -import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.app.NavUtils; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.SwitchCompat; -import android.support.v7.widget.Toolbar; -import android.text.Editable; -import android.text.TextWatcher; -import android.text.format.DateFormat; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.view.inputmethod.InputMethodManager; -import android.widget.Button; -import android.widget.CompoundButton; -import android.widget.EditText; -import android.widget.ImageButton; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; +import android.support.annotation.NonNull; +import android.support.v4.app.Fragment; -import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication; -import com.example.avjindersinghsekhon.minimaltodo.Main.MainActivity; +import com.example.avjindersinghsekhon.minimaltodo.AppDefault.AppDefaultActivity; import com.example.avjindersinghsekhon.minimaltodo.R; -import com.example.avjindersinghsekhon.minimaltodo.Utility.ToDoItem; -import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; -import com.wdullaer.materialdatetimepicker.time.RadialPickerLayout; -import com.wdullaer.materialdatetimepicker.time.TimePickerDialog; - -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; - -public class AddToDoActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener{ - private Date mLastEdited; - private EditText mToDoTextBodyEditText; - private SwitchCompat mToDoDateSwitch; -// private TextView mLastSeenTextView; - private LinearLayout mUserDateSpinnerContainingLinearLayout; - private TextView mReminderTextView; - - private EditText mDateEditText; - private EditText mTimeEditText; - private String mDefaultTimeOptions12H[]; - private String mDefaultTimeOptions24H[]; - - private Button mChooseDateButton; - private Button mChooseTimeButton; - private ToDoItem mUserToDoItem; - private FloatingActionButton mToDoSendFloatingActionButton; - public static final String DATE_FORMAT = "MMM d, yyyy"; - public static final String DATE_FORMAT_MONTH_DAY = "MMM d"; - public static final String DATE_FORMAT_TIME = "H:m"; - - private String mUserEnteredText; - private boolean mUserHasReminder; - private Toolbar mToolbar; - private Date mUserReminderDate; - private int mUserColor; - private boolean setDateButtonClickedOnce = false; - private boolean setTimeButtonClickedOnce = false; - private LinearLayout mContainerLayout; - private String theme; - AnalyticsApplication app; - - @Override - protected void onResume() { - super.onResume(); - app.send(this); - } +public class AddToDoActivity extends AppDefaultActivity { @SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { - app = (AnalyticsApplication)getApplication(); -// setContentView(R.layout.new_to_do_layout); - //Need references to these to change them during light/dark mode - ImageButton reminderIconImageButton; - TextView reminderRemindMeTextView; - - - theme = getSharedPreferences(MainActivity.THEME_PREFERENCES, MODE_PRIVATE).getString(MainActivity.THEME_SAVED, MainActivity.LIGHTTHEME); - if(theme.equals(MainActivity.LIGHTTHEME)){ - setTheme(R.style.CustomStyle_LightTheme); - Log.d("OskarSchindler", "Light Theme"); - } - else{ - setTheme(R.style.CustomStyle_DarkTheme); - } super.onCreate(savedInstanceState); -// setContentView(R.layout.activity_add_to_do); - //Testing out a new layout - setContentView(R.layout.activity_todo_test); - - //Show an X in place of <- - final Drawable cross = getResources().getDrawable(R.drawable.ic_clear_white_24dp); - if(cross !=null){ - cross.setColorFilter(getResources().getColor(R.color.icons), PorterDuff.Mode.SRC_ATOP); - } - - mToolbar = (Toolbar)findViewById(R.id.toolbar); - setSupportActionBar(mToolbar); - - if(getSupportActionBar()!=null){ - getSupportActionBar().setElevation(0); - getSupportActionBar().setDisplayShowTitleEnabled(false); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setHomeAsUpIndicator(cross ); - - } - - - mUserToDoItem = (ToDoItem)getIntent().getSerializableExtra(MainActivity.TODOITEM); - - mUserEnteredText = mUserToDoItem.getToDoText(); - mUserHasReminder = mUserToDoItem.hasReminder(); - mUserReminderDate = mUserToDoItem.getToDoDate(); - mUserColor = mUserToDoItem.getTodoColor(); - - -// if(mUserToDoItem.getLastEdited()==null) { -// mLastEdited = new Date(); -// } -// else{ -// mLastEdited = mUserToDoItem.getLastEdited(); -// } - - - reminderIconImageButton = (ImageButton)findViewById(R.id.userToDoReminderIconImageButton); - reminderRemindMeTextView = (TextView)findViewById(R.id.userToDoRemindMeTextView); - if(theme.equals(MainActivity.DARKTHEME)){ - reminderIconImageButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_alarm_add_white_24dp)); - reminderRemindMeTextView.setTextColor(Color.WHITE); - } - - - mContainerLayout = (LinearLayout)findViewById(R.id.todoReminderAndDateContainerLayout); - mUserDateSpinnerContainingLinearLayout = (LinearLayout)findViewById(R.id.toDoEnterDateLinearLayout); - mToDoTextBodyEditText = (EditText)findViewById(R.id.userToDoEditText); - mToDoDateSwitch = (SwitchCompat)findViewById(R.id.toDoHasDateSwitchCompat); -// mLastSeenTextView = (TextView)findViewById(R.id.toDoLastEditedTextView); - mToDoSendFloatingActionButton = (FloatingActionButton)findViewById(R.id.makeToDoFloatingActionButton); - mReminderTextView = (TextView)findViewById(R.id.newToDoDateTimeReminderTextView); - - - mContainerLayout.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - hideKeyboard(mToDoTextBodyEditText); - } - }); - - - if(mUserHasReminder && (mUserReminderDate!=null)){ -// mUserDateSpinnerContainingLinearLayout.setVisibility(View.VISIBLE); - setReminderTextView(); - setEnterDateLayoutVisibleWithAnimations(true); - } - if(mUserReminderDate==null){ - mToDoDateSwitch.setChecked(false); - mReminderTextView.setVisibility(View.INVISIBLE); - } - -// TextInputLayout til = (TextInputLayout)findViewById(R.id.toDoCustomTextInput); -// til.requestFocus(); - mToDoTextBodyEditText.requestFocus(); - mToDoTextBodyEditText.setText(mUserEnteredText); - InputMethodManager imm = (InputMethodManager)this.getSystemService(INPUT_METHOD_SERVICE); -// imm.showSoftInput(mToDoTextBodyEditText, InputMethodManager.SHOW_IMPLICIT); - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); - mToDoTextBodyEditText.setSelection(mToDoTextBodyEditText.length()); - - - mToDoTextBodyEditText.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - mUserEnteredText = s.toString(); - - } - - @Override - public void afterTextChanged(Editable s) { - - } - }); - - -// String lastSeen = formatDate(DATE_FORMAT, mLastEdited); -// mLastSeenTextView.setText(String.format(getResources().getString(R.string.last_edited), lastSeen)); - - setEnterDateLayoutVisible(mToDoDateSwitch.isChecked()); - - mToDoDateSwitch.setChecked(mUserHasReminder && (mUserReminderDate != null)); - mToDoDateSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if(isChecked){ - app.send(this, "Action", "Reminder Set"); - } - else{ - app.send(this, "Action", "Reminder Removed"); - - } - - if (!isChecked) { - mUserReminderDate = null; - } - mUserHasReminder = isChecked; - setDateAndTimeEditText(); - setEnterDateLayoutVisibleWithAnimations(isChecked); - hideKeyboard(mToDoTextBodyEditText); - } - }); - - - mToDoSendFloatingActionButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (mToDoTextBodyEditText.length() <= 0){ - mToDoTextBodyEditText.setError(getString(R.string.todo_error)); - } - else if(mUserReminderDate!=null && mUserReminderDate.before(new Date())){ - app.send(this, "Action", "Date in the Past"); - makeResult(RESULT_CANCELED); - } - else{ - app.send(this, "Action", "Make Todo"); - makeResult(RESULT_OK); - finish(); - } - hideKeyboard(mToDoTextBodyEditText); - } - }); - - - mDateEditText = (EditText)findViewById(R.id.newTodoDateEditText); - mTimeEditText = (EditText)findViewById(R.id.newTodoTimeEditText); - - mDateEditText.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - Date date; - hideKeyboard(mToDoTextBodyEditText); - if(mUserToDoItem.getToDoDate()!=null){ -// date = mUserToDoItem.getToDoDate(); - date = mUserReminderDate; - } - else{ - date = new Date(); - } - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - int year = calendar.get(Calendar.YEAR); - int month = calendar.get(Calendar.MONTH); - int day = calendar.get(Calendar.DAY_OF_MONTH); - - - DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(AddToDoActivity.this, year, month, day); - if(theme.equals(MainActivity.DARKTHEME)){ - datePickerDialog.setThemeDark(true); - } - datePickerDialog.show(getFragmentManager(), "DateFragment"); - - } - }); - - - mTimeEditText.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - Date date; - hideKeyboard(mToDoTextBodyEditText); - if(mUserToDoItem.getToDoDate()!=null){ -// date = mUserToDoItem.getToDoDate(); - date = mUserReminderDate; - } - else{ - date = new Date(); - } - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - int hour = calendar.get(Calendar.HOUR_OF_DAY); - int minute = calendar.get(Calendar.MINUTE); - - TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(AddToDoActivity.this, hour, minute, DateFormat.is24HourFormat(AddToDoActivity.this)); - if(theme.equals(MainActivity.DARKTHEME)){ - timePickerDialog.setThemeDark(true); - } - timePickerDialog.show(getFragmentManager(), "TimeFragment"); - } - }); - -// mDefaultTimeOptions12H = new String[]{"9:00 AM", "12:00 PM", "3:00 PM", "6:00 PM", "9:00 PM", "12:00 AM"}; -// mDefaultTimeOptions24H = new String[]{"9:00", "12:00", "15:00", "18:00", "21:00", "24:00"}; - setDateAndTimeEditText(); -// -// mChooseDateButton = (Button)findViewById(R.id.newToDoChooseDateButton); -// mChooseTimeButton = (Button)findViewById(R.id.newToDoChooseTimeButton); -// -// mChooseDateButton.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// Date date; -// hideKeyboard(mToDoTextBodyEditText); -// if(mUserToDoItem.getToDoDate()!=null){ -// date = mUserToDoItem.getToDoDate(); -// } -// else{ -// date = new Date(); -// } -// Calendar calendar = Calendar.getInstance(); -// calendar.setTime(date); -// int year = calendar.get(Calendar.YEAR); -// int month = calendar.get(Calendar.MONTH); -// int day = calendar.get(Calendar.DAY_OF_MONTH); -// -// -// DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(AddToDoActivity.this, year, month, day); -// if(theme.equals(MainActivity.DARKTHEME)){ -// datePickerDialog.setThemeDark(true); -// } -// datePickerDialog.show(getFragmentManager(), "DateFragment"); -// } -// }); -// -// mChooseTimeButton.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// Date date; -// hideKeyboard(mToDoTextBodyEditText); -// if(mUserToDoItem.getToDoDate()!=null){ -// date = mUserToDoItem.getToDoDate(); -// } -// else{ -// date = new Date(); -// } -// Calendar calendar = Calendar.getInstance(); -// calendar.setTime(date); -// int hour = calendar.get(Calendar.HOUR_OF_DAY); -// int minute = calendar.get(Calendar.MINUTE); -// -// TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(AddToDoActivity.this, hour, minute, DateFormat.is24HourFormat(AddToDoActivity.this)); -// if(theme.equals(MainActivity.DARKTHEME)){ -// timePickerDialog.setThemeDark(true); -// } -// timePickerDialog.show(getFragmentManager(), "TimeFragment"); -// } -// }); - - } - - private void setDateAndTimeEditText(){ - - if(mUserToDoItem.hasReminder() && mUserReminderDate!=null){ - String userDate = formatDate("d MMM, yyyy", mUserReminderDate); - String formatToUse; - if(DateFormat.is24HourFormat(this)){ - formatToUse = "k:mm"; - } - else{ - formatToUse = "h:mm a"; - - } - String userTime = formatDate(formatToUse, mUserReminderDate); - mTimeEditText.setText(userTime); - mDateEditText.setText(userDate); - - } - else{ - mDateEditText.setText(getString(R.string.date_reminder_default)); -// mUserReminderDate = new Date(); - boolean time24 = DateFormat.is24HourFormat(this); - Calendar cal = Calendar.getInstance(); - if(time24){ - cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY)+1); - } - else{ - cal.set(Calendar.HOUR, cal.get(Calendar.HOUR)+1); - } - cal.set(Calendar.MINUTE, 0); - mUserReminderDate = cal.getTime(); - Log.d("OskarSchindler", "Imagined Date: "+mUserReminderDate); - String timeString; - if(time24){ - timeString = formatDate("k:mm", mUserReminderDate); - } - else{ - timeString = formatDate("h:mm a", mUserReminderDate); - } - mTimeEditText.setText(timeString); -// int hour = calendar.get(Calendar.HOUR_OF_DAY); -// if(hour<9){ -// timeOption = time24?mDefaultTimeOptions24H[0]:mDefaultTimeOptions12H[0]; -// } -// else if(hour < 12){ -// timeOption = time24?mDefaultTimeOptions24H[1]:mDefaultTimeOptions12H[1]; -// } -// else if(hour < 15){ -// timeOption = time24?mDefaultTimeOptions24H[2]:mDefaultTimeOptions12H[2]; -// } -// else if(hour < 18){ -// timeOption = time24?mDefaultTimeOptions24H[3]:mDefaultTimeOptions12H[3]; -// } -// else if(hour < 21){ -// timeOption = time24?mDefaultTimeOptions24H[4]:mDefaultTimeOptions12H[4]; -// } -// else{ -// timeOption = time24?mDefaultTimeOptions24H[5]:mDefaultTimeOptions12H[5]; -// } -// mTimeEditText.setText(timeOption); - } - } - - private String getThemeSet(){ - return getSharedPreferences(MainActivity.THEME_PREFERENCES, MODE_PRIVATE).getString(MainActivity.THEME_SAVED, MainActivity.LIGHTTHEME); - } - public void hideKeyboard(EditText et){ - - InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(et.getWindowToken(), 0); - } - - - - public void setDate(int year, int month, int day){ - Calendar calendar = Calendar.getInstance(); - int hour, minute; -// int currentYear = calendar.get(Calendar.YEAR); -// int currentMonth = calendar.get(Calendar.MONTH); -// int currentDay = calendar.get(Calendar.DAY_OF_MONTH); - - Calendar reminderCalendar = Calendar.getInstance(); - reminderCalendar.set(year, month, day); - - if(reminderCalendar.before(calendar)){ - Toast.makeText(this, "My time-machine is a bit rusty", Toast.LENGTH_SHORT).show(); - return; - } - - if(mUserReminderDate!=null){ - calendar.setTime(mUserReminderDate); - } - - if(DateFormat.is24HourFormat(this)){ - hour = calendar.get(Calendar.HOUR_OF_DAY); - } - else{ - - hour = calendar.get(Calendar.HOUR); - } - minute = calendar.get(Calendar.MINUTE); - - calendar.set(year, month, day, hour, minute); - mUserReminderDate = calendar.getTime(); - setReminderTextView(); -// setDateAndTimeEditText(); - setDateEditText(); - } - - public void setTime(int hour, int minute){ - Calendar calendar = Calendar.getInstance(); - if(mUserReminderDate!=null){ - calendar.setTime(mUserReminderDate); - } - -// if(DateFormat.is24HourFormat(this) && hour == 0){ -// //done for 24h time -// hour = 24; -// } - int year = calendar.get(Calendar.YEAR); - int month = calendar.get(Calendar.MONTH); - int day = calendar.get(Calendar.DAY_OF_MONTH); - Log.d("OskarSchindler", "Time set: "+hour); - calendar.set(year, month, day, hour, minute, 0); - mUserReminderDate = calendar.getTime(); - - setReminderTextView(); -// setDateAndTimeEditText(); - setTimeEditText(); - } - - public void setDateEditText(){ - String dateFormat = "d MMM, yyyy"; - mDateEditText.setText(formatDate(dateFormat, mUserReminderDate)); - } - - public void setTimeEditText(){ - String dateFormat; - if(DateFormat.is24HourFormat(this)){ - dateFormat = "k:mm"; - } - else{ - dateFormat = "h:mm a"; - - } - mTimeEditText.setText(formatDate(dateFormat, mUserReminderDate)); - } - - public void setReminderTextView(){ - if(mUserReminderDate!=null){ - mReminderTextView.setVisibility(View.VISIBLE); - if(mUserReminderDate.before(new Date())){ - Log.d("OskarSchindler", "DATE is "+mUserReminderDate); - mReminderTextView.setText(getString(R.string.date_error_check_again)); - mReminderTextView.setTextColor(Color.RED); - return; - } - Date date = mUserReminderDate; - String dateString = formatDate("d MMM, yyyy", date); - String timeString; - String amPmString = ""; - - if(DateFormat.is24HourFormat(this)){ - timeString = formatDate("k:mm", date); - } - else{ - timeString = formatDate("h:mm", date); - amPmString = formatDate("a", date); - } - String finalString = String.format(getResources().getString(R.string.remind_date_and_time), dateString, timeString, amPmString); - mReminderTextView.setTextColor(getResources().getColor(R.color.secondary_text)); - mReminderTextView.setText(finalString); - } - else{ - mReminderTextView.setVisibility(View.INVISIBLE); - - } - } - - public void makeResult(int result){ - Intent i = new Intent(); - if(mUserEnteredText.length()>0){ - - String capitalizedString = Character.toUpperCase(mUserEnteredText.charAt(0))+mUserEnteredText.substring(1); - mUserToDoItem.setToDoText(capitalizedString); - } - else{ - mUserToDoItem.setToDoText(mUserEnteredText); - } -// mUserToDoItem.setLastEdited(mLastEdited); - if(mUserReminderDate!=null){ - Calendar calendar = Calendar.getInstance(); - calendar.setTime(mUserReminderDate); - calendar.set(Calendar.SECOND, 0); - mUserReminderDate = calendar.getTime(); - } - mUserToDoItem.setHasReminder(mUserHasReminder); - mUserToDoItem.setToDoDate(mUserReminderDate); - mUserToDoItem.setTodoColor(mUserColor); - i.putExtra(MainActivity.TODOITEM, mUserToDoItem); - setResult(result, i); } @Override - public void onBackPressed() { - if(mUserReminderDate.before(new Date())){ - mUserToDoItem.setToDoDate(null); - } - makeResult(RESULT_OK); - super.onBackPressed(); + protected int contentViewLayoutRes() { + return R.layout.activity_add_to_do; } + @NonNull @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()){ - case android.R.id.home: - if(NavUtils.getParentActivityName(this)!=null){ - app.send(this, "Action", "Discard Todo"); - makeResult(RESULT_CANCELED); - NavUtils.navigateUpFromSameTask(this); - } - hideKeyboard(mToDoTextBodyEditText); - return true; - - default: - return super.onOptionsItemSelected(item); - } - } - - public static String formatDate(String formatString, Date dateToFormat){ - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatString); - return simpleDateFormat.format(dateToFormat); + protected Fragment createInitialFragment() { + return AddToDoFragment.newInstance(); } @Override - public void onTimeSet(RadialPickerLayout radialPickerLayout, int hour, int minute) { - setTime(hour, minute); - } - - @Override - public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) { - setDate(year, month, day); - } - - public void setEnterDateLayoutVisible(boolean checked){ - if(checked){ - mUserDateSpinnerContainingLinearLayout.setVisibility(View.VISIBLE); - } - else{ - mUserDateSpinnerContainingLinearLayout.setVisibility(View.INVISIBLE); - } + protected void onResume() { + super.onResume(); } - public void setEnterDateLayoutVisibleWithAnimations(boolean checked){ - if(checked){ - setReminderTextView(); - mUserDateSpinnerContainingLinearLayout.animate().alpha(1.0f).setDuration(500).setListener( - new Animator.AnimatorListener() { - @Override - public void onAnimationStart(Animator animation) { - mUserDateSpinnerContainingLinearLayout.setVisibility(View.VISIBLE); - } - - @Override - public void onAnimationEnd(Animator animation) { - } - - @Override - public void onAnimationCancel(Animator animation) { - } - - @Override - public void onAnimationRepeat(Animator animation) { - } - } - ); - } - else{ - mUserDateSpinnerContainingLinearLayout.animate().alpha(0.0f).setDuration(500).setListener( - new Animator.AnimatorListener() { - @Override - public void onAnimationStart(Animator animation) { - - } - - @Override - public void onAnimationEnd(Animator animation) { - mUserDateSpinnerContainingLinearLayout.setVisibility(View.INVISIBLE); - } - - @Override - public void onAnimationCancel(Animator animation) { - - } - - @Override - public void onAnimationRepeat(Animator animation) { - - } - } - ); - } - - } } diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDo/AddToDoFragment.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDo/AddToDoFragment.java new file mode 100644 index 00000000..249f912d --- /dev/null +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/AddToDo/AddToDoFragment.java @@ -0,0 +1,653 @@ +package com.example.avjindersinghsekhon.minimaltodo.AddToDo; + +import android.animation.Animator; +import android.content.Intent; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.design.widget.FloatingActionButton; +import android.support.v4.app.NavUtils; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.SwitchCompat; +import android.support.v7.widget.Toolbar; +import android.text.Editable; +import android.text.TextWatcher; +import android.text.format.DateFormat; +import android.util.Log; +import android.view.MenuItem; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.CompoundButton; +import android.widget.EditText; +import android.widget.ImageButton; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication; +import com.example.avjindersinghsekhon.minimaltodo.AppDefault.AppDefaultFragment; +import com.example.avjindersinghsekhon.minimaltodo.Main.MainFragment; +import com.example.avjindersinghsekhon.minimaltodo.R; +import com.example.avjindersinghsekhon.minimaltodo.Utility.ToDoItem; +import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; +import com.wdullaer.materialdatetimepicker.time.RadialPickerLayout; +import com.wdullaer.materialdatetimepicker.time.TimePickerDialog; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +import static android.app.Activity.RESULT_CANCELED; +import static android.app.Activity.RESULT_OK; +import static android.content.Context.INPUT_METHOD_SERVICE; +import static android.content.Context.MODE_PRIVATE; + +public class AddToDoFragment extends AppDefaultFragment implements DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener { + private Date mLastEdited; + private EditText mToDoTextBodyEditText; + private SwitchCompat mToDoDateSwitch; + // private TextView mLastSeenTextView; + private LinearLayout mUserDateSpinnerContainingLinearLayout; + private TextView mReminderTextView; + + private EditText mDateEditText; + private EditText mTimeEditText; + private String mDefaultTimeOptions12H[]; + private String mDefaultTimeOptions24H[]; + + private Button mChooseDateButton; + private Button mChooseTimeButton; + private ToDoItem mUserToDoItem; + private FloatingActionButton mToDoSendFloatingActionButton; + public static final String DATE_FORMAT = "MMM d, yyyy"; + public static final String DATE_FORMAT_MONTH_DAY = "MMM d"; + public static final String DATE_FORMAT_TIME = "H:m"; + + private String mUserEnteredText; + private boolean mUserHasReminder; + private Toolbar mToolbar; + private Date mUserReminderDate; + private int mUserColor; + private boolean setDateButtonClickedOnce = false; + private boolean setTimeButtonClickedOnce = false; + private LinearLayout mContainerLayout; + private String theme; + AnalyticsApplication app; + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + app = (AnalyticsApplication) getActivity().getApplication(); +// setContentView(R.layout.new_to_do_layout); + //Need references to these to change them during light/dark mode + ImageButton reminderIconImageButton; + TextView reminderRemindMeTextView; + + + theme = getActivity().getSharedPreferences(MainFragment.THEME_PREFERENCES, MODE_PRIVATE).getString(MainFragment.THEME_SAVED, MainFragment.LIGHTTHEME); + if (theme.equals(MainFragment.LIGHTTHEME)) { + getActivity().setTheme(R.style.CustomStyle_LightTheme); + Log.d("OskarSchindler", "Light Theme"); + } else { + getActivity().setTheme(R.style.CustomStyle_DarkTheme); + } + + + //Show an X in place of <- + final Drawable cross = getResources().getDrawable(R.drawable.ic_clear_white_24dp); + if (cross != null) { + cross.setColorFilter(getResources().getColor(R.color.icons), PorterDuff.Mode.SRC_ATOP); + } + + mToolbar = (Toolbar) view.findViewById(R.id.toolbar); + ((AppCompatActivity) getActivity()).setSupportActionBar(mToolbar); + + if (((AppCompatActivity) getActivity()).getSupportActionBar() != null) { + ((AppCompatActivity) getActivity()).getSupportActionBar().setElevation(0); + ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false); + ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); + ((AppCompatActivity) getActivity()).getSupportActionBar().setHomeAsUpIndicator(cross); + + } + + + mUserToDoItem = (ToDoItem) getActivity().getIntent().getSerializableExtra(MainFragment.TODOITEM); + + mUserEnteredText = mUserToDoItem.getToDoText(); + mUserHasReminder = mUserToDoItem.hasReminder(); + mUserReminderDate = mUserToDoItem.getToDoDate(); + mUserColor = mUserToDoItem.getTodoColor(); + + +// if(mUserToDoItem.getLastEdited()==null) { +// mLastEdited = new Date(); +// } +// else{ +// mLastEdited = mUserToDoItem.getLastEdited(); +// } + + + reminderIconImageButton = (ImageButton) view.findViewById(R.id.userToDoReminderIconImageButton); + reminderRemindMeTextView = (TextView) view.findViewById(R.id.userToDoRemindMeTextView); + if (theme.equals(MainFragment.DARKTHEME)) { + reminderIconImageButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_alarm_add_white_24dp)); + reminderRemindMeTextView.setTextColor(Color.WHITE); + } + + + mContainerLayout = (LinearLayout) view.findViewById(R.id.todoReminderAndDateContainerLayout); + mUserDateSpinnerContainingLinearLayout = (LinearLayout) view.findViewById(R.id.toDoEnterDateLinearLayout); + mToDoTextBodyEditText = (EditText) view.findViewById(R.id.userToDoEditText); + mToDoDateSwitch = (SwitchCompat) view.findViewById(R.id.toDoHasDateSwitchCompat); +// mLastSeenTextView = (TextView)findViewById(R.id.toDoLastEditedTextView); + mToDoSendFloatingActionButton = (FloatingActionButton) view.findViewById(R.id.makeToDoFloatingActionButton); + mReminderTextView = (TextView) view.findViewById(R.id.newToDoDateTimeReminderTextView); + + + mContainerLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + hideKeyboard(mToDoTextBodyEditText); + } + }); + + + if (mUserHasReminder && (mUserReminderDate != null)) { +// mUserDateSpinnerContainingLinearLayout.setVisibility(View.VISIBLE); + setReminderTextView(); + setEnterDateLayoutVisibleWithAnimations(true); + } + if (mUserReminderDate == null) { + mToDoDateSwitch.setChecked(false); + mReminderTextView.setVisibility(View.INVISIBLE); + } + +// TextInputLayout til = (TextInputLayout)findViewById(R.id.toDoCustomTextInput); +// til.requestFocus(); + mToDoTextBodyEditText.requestFocus(); + mToDoTextBodyEditText.setText(mUserEnteredText); + InputMethodManager imm = (InputMethodManager) this.getActivity().getSystemService(INPUT_METHOD_SERVICE); +// imm.showSoftInput(mToDoTextBodyEditText, InputMethodManager.SHOW_IMPLICIT); + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); + mToDoTextBodyEditText.setSelection(mToDoTextBodyEditText.length()); + + + mToDoTextBodyEditText.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + mUserEnteredText = s.toString(); + + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + +// String lastSeen = formatDate(DATE_FORMAT, mLastEdited); +// mLastSeenTextView.setText(String.format(getResources().getString(R.string.last_edited), lastSeen)); + + setEnterDateLayoutVisible(mToDoDateSwitch.isChecked()); + + mToDoDateSwitch.setChecked(mUserHasReminder && (mUserReminderDate != null)); + mToDoDateSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + app.send(this, "Action", "Reminder Set"); + } else { + app.send(this, "Action", "Reminder Removed"); + + } + + if (!isChecked) { + mUserReminderDate = null; + } + mUserHasReminder = isChecked; + setDateAndTimeEditText(); + setEnterDateLayoutVisibleWithAnimations(isChecked); + hideKeyboard(mToDoTextBodyEditText); + } + }); + + + mToDoSendFloatingActionButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mToDoTextBodyEditText.length() <= 0) { + mToDoTextBodyEditText.setError(getString(R.string.todo_error)); + } else if (mUserReminderDate != null && mUserReminderDate.before(new Date())) { + app.send(this, "Action", "Date in the Past"); + makeResult(RESULT_CANCELED); + } else { + app.send(this, "Action", "Make Todo"); + makeResult(RESULT_OK); + getActivity().finish(); + } + hideKeyboard(mToDoTextBodyEditText); + } + }); + + + mDateEditText = (EditText) view.findViewById(R.id.newTodoDateEditText); + mTimeEditText = (EditText) view.findViewById(R.id.newTodoTimeEditText); + + mDateEditText.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + Date date; + hideKeyboard(mToDoTextBodyEditText); + if (mUserToDoItem.getToDoDate() != null) { +// date = mUserToDoItem.getToDoDate(); + date = mUserReminderDate; + } else { + date = new Date(); + } + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH); + int day = calendar.get(Calendar.DAY_OF_MONTH); + + + DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(AddToDoFragment.this, year, month, day); + if (theme.equals(MainFragment.DARKTHEME)) { + datePickerDialog.setThemeDark(true); + } + datePickerDialog.show(getActivity().getFragmentManager(), "DateFragment"); + + } + }); + + + mTimeEditText.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + Date date; + hideKeyboard(mToDoTextBodyEditText); + if (mUserToDoItem.getToDoDate() != null) { +// date = mUserToDoItem.getToDoDate(); + date = mUserReminderDate; + } else { + date = new Date(); + } + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + int hour = calendar.get(Calendar.HOUR_OF_DAY); + int minute = calendar.get(Calendar.MINUTE); + + TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(AddToDoFragment.this, hour, minute, DateFormat.is24HourFormat(getContext())); + if (theme.equals(MainFragment.DARKTHEME)) { + timePickerDialog.setThemeDark(true); + } + timePickerDialog.show(getActivity().getFragmentManager(), "TimeFragment"); + } + }); + +// mDefaultTimeOptions12H = new String[]{"9:00 AM", "12:00 PM", "3:00 PM", "6:00 PM", "9:00 PM", "12:00 AM"}; +// mDefaultTimeOptions24H = new String[]{"9:00", "12:00", "15:00", "18:00", "21:00", "24:00"}; + setDateAndTimeEditText(); + +// + +// mChooseDateButton = (Button)findViewById(R.id.newToDoChooseDateButton); +// mChooseTimeButton = (Button)findViewById(R.id.newToDoChooseTimeButton); +// +// mChooseDateButton.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// Date date; +// hideKeyboard(mToDoTextBodyEditText); +// if(mUserToDoItem.getToDoDate()!=null){ +// date = mUserToDoItem.getToDoDate(); +// } +// else{ +// date = new Date(); +// } +// Calendar calendar = Calendar.getInstance(); +// calendar.setTime(date); +// int year = calendar.get(Calendar.YEAR); +// int month = calendar.get(Calendar.MONTH); +// int day = calendar.get(Calendar.DAY_OF_MONTH); +// +// +// DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(AddToDoActivity.this, year, month, day); +// if(theme.equals(MainActivity.DARKTHEME)){ +// datePickerDialog.setThemeDark(true); +// } +// datePickerDialog.show(getFragmentManager(), "DateFragment"); +// } +// }); +// +// mChooseTimeButton.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// Date date; +// hideKeyboard(mToDoTextBodyEditText); +// if(mUserToDoItem.getToDoDate()!=null){ +// date = mUserToDoItem.getToDoDate(); +// } +// else{ +// date = new Date(); +// } +// Calendar calendar = Calendar.getInstance(); +// calendar.setTime(date); +// int hour = calendar.get(Calendar.HOUR_OF_DAY); +// int minute = calendar.get(Calendar.MINUTE); +// +// TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(AddToDoActivity.this, hour, minute, DateFormat.is24HourFormat(AddToDoActivity.this)); +// if(theme.equals(MainActivity.DARKTHEME)){ +// timePickerDialog.setThemeDark(true); +// } +// timePickerDialog.show(getFragmentManager(), "TimeFragment"); +// } +// }); + + } + + private void setDateAndTimeEditText() { + + if (mUserToDoItem.hasReminder() && mUserReminderDate != null) { + String userDate = formatDate("d MMM, yyyy", mUserReminderDate); + String formatToUse; + if (DateFormat.is24HourFormat(getContext())) { + formatToUse = "k:mm"; + } else { + formatToUse = "h:mm a"; + + } + String userTime = formatDate(formatToUse, mUserReminderDate); + mTimeEditText.setText(userTime); + mDateEditText.setText(userDate); + + } else { + mDateEditText.setText(getString(R.string.date_reminder_default)); +// mUserReminderDate = new Date(); + boolean time24 = DateFormat.is24HourFormat(getContext()); + Calendar cal = Calendar.getInstance(); + if (time24) { + cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) + 1); + } else { + cal.set(Calendar.HOUR, cal.get(Calendar.HOUR) + 1); + } + cal.set(Calendar.MINUTE, 0); + mUserReminderDate = cal.getTime(); + Log.d("OskarSchindler", "Imagined Date: " + mUserReminderDate); + String timeString; + if (time24) { + timeString = formatDate("k:mm", mUserReminderDate); + } else { + timeString = formatDate("h:mm a", mUserReminderDate); + } + mTimeEditText.setText(timeString); +// int hour = calendar.get(Calendar.HOUR_OF_DAY); +// if(hour<9){ +// timeOption = time24?mDefaultTimeOptions24H[0]:mDefaultTimeOptions12H[0]; +// } +// else if(hour < 12){ +// timeOption = time24?mDefaultTimeOptions24H[1]:mDefaultTimeOptions12H[1]; +// } +// else if(hour < 15){ +// timeOption = time24?mDefaultTimeOptions24H[2]:mDefaultTimeOptions12H[2]; +// } +// else if(hour < 18){ +// timeOption = time24?mDefaultTimeOptions24H[3]:mDefaultTimeOptions12H[3]; +// } +// else if(hour < 21){ +// timeOption = time24?mDefaultTimeOptions24H[4]:mDefaultTimeOptions12H[4]; +// } +// else{ +// timeOption = time24?mDefaultTimeOptions24H[5]:mDefaultTimeOptions12H[5]; +// } +// mTimeEditText.setText(timeOption); + } + } + + private String getThemeSet() { + return getActivity().getSharedPreferences(MainFragment.THEME_PREFERENCES, MODE_PRIVATE).getString(MainFragment.THEME_SAVED, MainFragment.LIGHTTHEME); + } + + public void hideKeyboard(EditText et) { + + InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(et.getWindowToken(), 0); + } + + + public void setDate(int year, int month, int day) { + Calendar calendar = Calendar.getInstance(); + int hour, minute; +// int currentYear = calendar.get(Calendar.YEAR); +// int currentMonth = calendar.get(Calendar.MONTH); +// int currentDay = calendar.get(Calendar.DAY_OF_MONTH); + + Calendar reminderCalendar = Calendar.getInstance(); + reminderCalendar.set(year, month, day); + + if (reminderCalendar.before(calendar)) { + // Toast.makeText(this, "My time-machine is a bit rusty", Toast.LENGTH_SHORT).show(); + return; + } + + if (mUserReminderDate != null) { + calendar.setTime(mUserReminderDate); + } + + if (DateFormat.is24HourFormat(getContext())) { + hour = calendar.get(Calendar.HOUR_OF_DAY); + } else { + + hour = calendar.get(Calendar.HOUR); + } + minute = calendar.get(Calendar.MINUTE); + + calendar.set(year, month, day, hour, minute); + mUserReminderDate = calendar.getTime(); + setReminderTextView(); +// setDateAndTimeEditText(); + setDateEditText(); + } + + public void setTime(int hour, int minute) { + Calendar calendar = Calendar.getInstance(); + if (mUserReminderDate != null) { + calendar.setTime(mUserReminderDate); + } + +// if(DateFormat.is24HourFormat(this) && hour == 0){ +// //done for 24h time +// hour = 24; +// } + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH); + int day = calendar.get(Calendar.DAY_OF_MONTH); + Log.d("OskarSchindler", "Time set: " + hour); + calendar.set(year, month, day, hour, minute, 0); + mUserReminderDate = calendar.getTime(); + + setReminderTextView(); +// setDateAndTimeEditText(); + setTimeEditText(); + } + + public void setDateEditText() { + String dateFormat = "d MMM, yyyy"; + mDateEditText.setText(formatDate(dateFormat, mUserReminderDate)); + } + + public void setTimeEditText() { + String dateFormat; + if (DateFormat.is24HourFormat(getContext())) { + dateFormat = "k:mm"; + } else { + dateFormat = "h:mm a"; + + } + mTimeEditText.setText(formatDate(dateFormat, mUserReminderDate)); + } + + public void setReminderTextView() { + if (mUserReminderDate != null) { + mReminderTextView.setVisibility(View.VISIBLE); + if (mUserReminderDate.before(new Date())) { + Log.d("OskarSchindler", "DATE is " + mUserReminderDate); + mReminderTextView.setText(getString(R.string.date_error_check_again)); + mReminderTextView.setTextColor(Color.RED); + return; + } + Date date = mUserReminderDate; + String dateString = formatDate("d MMM, yyyy", date); + String timeString; + String amPmString = ""; + + if (DateFormat.is24HourFormat(getContext())) { + timeString = formatDate("k:mm", date); + } else { + timeString = formatDate("h:mm", date); + amPmString = formatDate("a", date); + } + String finalString = String.format(getResources().getString(R.string.remind_date_and_time), dateString, timeString, amPmString); + mReminderTextView.setTextColor(getResources().getColor(R.color.secondary_text)); + mReminderTextView.setText(finalString); + } else { + mReminderTextView.setVisibility(View.INVISIBLE); + + } + } + + public void makeResult(int result) { + Intent i = new Intent(); + if (mUserEnteredText.length() > 0) { + + String capitalizedString = Character.toUpperCase(mUserEnteredText.charAt(0)) + mUserEnteredText.substring(1); + mUserToDoItem.setToDoText(capitalizedString); + } else { + mUserToDoItem.setToDoText(mUserEnteredText); + } +// mUserToDoItem.setLastEdited(mLastEdited); + if (mUserReminderDate != null) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(mUserReminderDate); + calendar.set(Calendar.SECOND, 0); + mUserReminderDate = calendar.getTime(); + } + mUserToDoItem.setHasReminder(mUserHasReminder); + mUserToDoItem.setToDoDate(mUserReminderDate); + mUserToDoItem.setTodoColor(mUserColor); + i.putExtra(MainFragment.TODOITEM, mUserToDoItem); + getActivity().setResult(result, i); + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + if (NavUtils.getParentActivityName(getActivity()) != null) { + app.send(this, "Action", "Discard Todo"); + makeResult(RESULT_CANCELED); + NavUtils.navigateUpFromSameTask(getActivity()); + } + hideKeyboard(mToDoTextBodyEditText); + return true; + + default: + return super.onOptionsItemSelected(item); + } + } + + public static String formatDate(String formatString, Date dateToFormat) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatString); + return simpleDateFormat.format(dateToFormat); + } + + @Override + public void onTimeSet(RadialPickerLayout radialPickerLayout, int hour, int minute) { + setTime(hour, minute); + } + + @Override + public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) { + setDate(year, month, day); + } + + public void setEnterDateLayoutVisible(boolean checked) { + if (checked) { + mUserDateSpinnerContainingLinearLayout.setVisibility(View.VISIBLE); + } else { + mUserDateSpinnerContainingLinearLayout.setVisibility(View.INVISIBLE); + } + } + + public void setEnterDateLayoutVisibleWithAnimations(boolean checked) { + if (checked) { + setReminderTextView(); + mUserDateSpinnerContainingLinearLayout.animate().alpha(1.0f).setDuration(500).setListener( + new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animation) { + mUserDateSpinnerContainingLinearLayout.setVisibility(View.VISIBLE); + } + + @Override + public void onAnimationEnd(Animator animation) { + } + + @Override + public void onAnimationCancel(Animator animation) { + } + + @Override + public void onAnimationRepeat(Animator animation) { + } + } + ); + } else { + mUserDateSpinnerContainingLinearLayout.animate().alpha(0.0f).setDuration(500).setListener( + new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animation) { + + } + + @Override + public void onAnimationEnd(Animator animation) { + mUserDateSpinnerContainingLinearLayout.setVisibility(View.INVISIBLE); + } + + @Override + public void onAnimationCancel(Animator animation) { + + } + + @Override + public void onAnimationRepeat(Animator animation) { + + } + } + ); + } + + } + + + @Override + protected int layoutRes() { + return R.layout.fragment_add_to_do; + } + + public static AddToDoFragment newInstance() { + return new AddToDoFragment(); + } +} diff --git a/app/src/main/res/layout/activity_add_to_do.xml b/app/src/main/res/layout/activity_add_to_do.xml index 4365e3cf..7549ef03 100644 --- a/app/src/main/res/layout/activity_add_to_do.xml +++ b/app/src/main/res/layout/activity_add_to_do.xml @@ -1,174 +1,11 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - -