From 4789c4a405951b1c9d354246de9b2692f9ae19c6 Mon Sep 17 00:00:00 2001 From: s452641 Date: Sun, 21 Nov 2021 14:21:57 +0100 Subject: [PATCH] 'third' --- .idea/misc.xml | 1 + .../main/java/com/example/tasklist/Adding_tasks.kt | 2 +- .../main/java/com/example/tasklist/ChangePass.kt | 5 +---- .../main/java/com/example/tasklist/LoginPage.kt | 14 ++++++++++++-- app/src/main/java/com/example/tasklist/SetPass.kt | 2 ++ .../java/com/example/tasklist/data/dao/TaskDao.kt | 2 ++ app/src/main/res/layout/fragment_adding_tasks.xml | 1 - app/src/main/res/navigation/mobile_navigation.xml | 3 +++ 8 files changed, 22 insertions(+), 8 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index f3e48d2..7444b71 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,6 +7,7 @@ + diff --git a/app/src/main/java/com/example/tasklist/Adding_tasks.kt b/app/src/main/java/com/example/tasklist/Adding_tasks.kt index 749e113..11faf49 100644 --- a/app/src/main/java/com/example/tasklist/Adding_tasks.kt +++ b/app/src/main/java/com/example/tasklist/Adding_tasks.kt @@ -50,7 +50,7 @@ class Adding_tasks : Fragment() { val textTask = binding.editTextName.text.toString() val dateTask = simpleDateFormat.format(Date()) - if (textTask != "" && dateTask != "") { + if (textTask != "") { val ttask = Task(textTask, dateTask) Database.taskDao.addTask(ttask) } diff --git a/app/src/main/java/com/example/tasklist/ChangePass.kt b/app/src/main/java/com/example/tasklist/ChangePass.kt index d0b9c9c..1466dcb 100644 --- a/app/src/main/java/com/example/tasklist/ChangePass.kt +++ b/app/src/main/java/com/example/tasklist/ChangePass.kt @@ -31,9 +31,6 @@ class ChangePass : Fragment(){ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val sharedPreference = - requireActivity().getSharedPreferences("sharedPref", Context.MODE_PRIVATE) - Toast.makeText(requireActivity(),sharedPreference.getString("STRING_KEY", null),Toast.LENGTH_LONG).show() } override fun onCreateView( @@ -55,7 +52,7 @@ class ChangePass : Fragment(){ val sharedPreference = requireActivity().getSharedPreferences("sharedPref", Context.MODE_PRIVATE) - if(binding.passwordOld.text.toString().equals(sharedPreference.getString("STRING_KEY", null),true)) { + if(binding.passwordOld.text.toString().equals(sharedPreference.getString("STRING_KEY", null),false)) { if ((binding.passwordNew.text.toString()).length >= 4){ savePass() Toast.makeText(requireActivity(),"Password updated!",Toast.LENGTH_SHORT).show() diff --git a/app/src/main/java/com/example/tasklist/LoginPage.kt b/app/src/main/java/com/example/tasklist/LoginPage.kt index 8cc166b..b4943ba 100644 --- a/app/src/main/java/com/example/tasklist/LoginPage.kt +++ b/app/src/main/java/com/example/tasklist/LoginPage.kt @@ -28,9 +28,11 @@ class LoginPage : Fragment(){ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + } override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { @@ -39,6 +41,7 @@ class LoginPage : Fragment(){ inflater, R.layout.fragment_login_page, container, false ) + checkIfPassSet() binding.login = this@LoginPage return binding.root @@ -49,7 +52,7 @@ class LoginPage : Fragment(){ val sharedPreference = requireActivity().getSharedPreferences("sharedPref", Context.MODE_PRIVATE) - if(binding.password.text.toString().equals(sharedPreference.getString("STRING_KEY", null),true)){ + if(binding.password.text.toString().equals(sharedPreference.getString("STRING_KEY", null),false)){ savePass() findNavController().navigate(R.id.action_loginPage_to_taskListFragment) } @@ -69,7 +72,14 @@ class LoginPage : Fragment(){ editor.apply{ putString("STRING_KEY",insertedText) }.apply() - //Toast.makeText(requireActivity(),"Password updated",Toast.LENGTH_SHORT).show() } + + private fun checkIfPassSet(){ + val sharedPreference = + requireActivity().getSharedPreferences("sharedPref", Context.MODE_PRIVATE) + if(sharedPreference.getString("STRING_KEY", null) == null){ + findNavController().navigate(R.id.action_loginPage_to_setPass) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/SetPass.kt b/app/src/main/java/com/example/tasklist/SetPass.kt index a40f09f..2f03ea0 100644 --- a/app/src/main/java/com/example/tasklist/SetPass.kt +++ b/app/src/main/java/com/example/tasklist/SetPass.kt @@ -64,4 +64,6 @@ class SetPass : Fragment() { putString("STRING_KEY", insertedText) }.apply() } + + } diff --git a/app/src/main/java/com/example/tasklist/data/dao/TaskDao.kt b/app/src/main/java/com/example/tasklist/data/dao/TaskDao.kt index f8ca197..926c881 100644 --- a/app/src/main/java/com/example/tasklist/data/dao/TaskDao.kt +++ b/app/src/main/java/com/example/tasklist/data/dao/TaskDao.kt @@ -9,6 +9,8 @@ import com.google.gson.Gson import com.google.gson.reflect.TypeToken class TaskDao { + + fun getAllTasks() : ArrayList { return DataSource.zadanie } diff --git a/app/src/main/res/layout/fragment_adding_tasks.xml b/app/src/main/res/layout/fragment_adding_tasks.xml index 4160bb6..442a5a9 100644 --- a/app/src/main/res/layout/fragment_adding_tasks.xml +++ b/app/src/main/res/layout/fragment_adding_tasks.xml @@ -4,7 +4,6 @@ xmlns:tools="http://schemas.android.com/tools"> - diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index 90d1f8d..83de148 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -40,6 +40,9 @@ +