From 9d645afe2e38dc6553345fea2c400602b479458d Mon Sep 17 00:00:00 2001 From: "egecan.serbester" Date: Tue, 17 Oct 2023 10:03:11 +0300 Subject: [PATCH 01/11] #Creating registration related pages --- .../DisasterResponsePlatform/app/build.gradle | 6 ++ .../disasterresponseplatform/MainActivity.kt | 41 ++++++++++++- .../ui/HomePageFragment.kt | 59 +++++++++++++++++++ .../ui/registration/ChangePasswordFragment.kt | 9 +++ .../ui/registration/ForgotPasswordFragment.kt | 42 +++++++++++++ .../ui/registration/LoginFragment.kt | 53 +++++++++++++++++ .../ui/registration/RegistrationFragment.kt | 42 +++++++++++++ .../app/src/main/res/layout/activity_main.xml | 18 +----- .../res/layout/fragment_change_password.xml | 20 +++++++ .../res/layout/fragment_forgot_password.xml | 30 ++++++++++ .../main/res/layout/fragment_home_page.xml | 31 ++++++++++ .../src/main/res/layout/fragment_login.xml | 32 ++++++++++ .../main/res/layout/fragment_registration.xml | 31 ++++++++++ .../app/src/main/res/values/strings.xml | 7 +++ 14 files changed, 404 insertions(+), 17 deletions(-) create mode 100644 Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/HomePageFragment.kt create mode 100644 Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/ChangePasswordFragment.kt create mode 100644 Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/ForgotPasswordFragment.kt create mode 100644 Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/LoginFragment.kt create mode 100644 Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/RegistrationFragment.kt create mode 100644 Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/fragment_change_password.xml create mode 100644 Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/fragment_forgot_password.xml create mode 100644 Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/fragment_home_page.xml create mode 100644 Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/fragment_login.xml create mode 100644 Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/fragment_registration.xml diff --git a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/build.gradle b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/build.gradle index 6e8ca29a..71276da1 100644 --- a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/build.gradle +++ b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/build.gradle @@ -6,6 +6,11 @@ plugins { android { namespace 'com.example.disasterresponseplatform' compileSdk 34 + // These are for binding + buildFeatures { + viewBinding = true + dataBinding true + } defaultConfig { applicationId "com.example.disasterresponseplatform" @@ -41,4 +46,5 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + } \ No newline at end of file diff --git a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/MainActivity.kt b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/MainActivity.kt index d8dfd33b..9952e506 100644 --- a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/MainActivity.kt +++ b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/MainActivity.kt @@ -2,10 +2,49 @@ package com.example.disasterresponseplatform import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentTransaction +import com.example.disasterresponseplatform.databinding.ActivityMainBinding +import com.example.disasterresponseplatform.ui.HomePageFragment class MainActivity : AppCompatActivity() { + + private lateinit var binding: ActivityMainBinding + private var homePageFragment = HomePageFragment() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) + binding = ActivityMainBinding.inflate(layoutInflater) + //instead setContentView(R.layout.activity_main) doing that with binding + setContentView(binding.root) + replaceFragment(homePageFragment) + } + + + /** This adds fragments to the back stack, in this way user can return this fragment after the view has been changed. + * and replace fragment. + */ + fun addFragment(fragment: Fragment) { + val ft: FragmentTransaction = supportFragmentManager.beginTransaction() + ft.replace(R.id.container, fragment) + ft.addToBackStack(null) + ft.commit() + } + + /** + * This pops the fragment from fragment stack + */ + fun popFragment() { + supportFragmentManager.popBackStack() + } + + /** + * This is for replacing the fragment without adding it to the stack + * .apply means ft. in addFragment + */ + fun replaceFragment(fragment: Fragment) { + supportFragmentManager.beginTransaction().apply { + replace(R.id.container, fragment) //replacing fragment + commit() //call signals to the FragmentManager that all operations have been added to the transaction + } } } \ No newline at end of file diff --git a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/HomePageFragment.kt b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/HomePageFragment.kt new file mode 100644 index 00000000..75619f4d --- /dev/null +++ b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/HomePageFragment.kt @@ -0,0 +1,59 @@ +package com.example.disasterresponseplatform.ui + +import android.os.Bundle +import android.util.Log +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.FragmentTransaction +import com.example.disasterresponseplatform.R +import com.example.disasterresponseplatform.databinding.FragmentHomePageBinding +import com.example.disasterresponseplatform.ui.registration.LoginFragment + + +class HomePageFragment : Fragment() { + + private lateinit var binding: FragmentHomePageBinding + private var loginFragment = LoginFragment() + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + binding = FragmentHomePageBinding.inflate(inflater,container,false) + // Inflate the layout for this fragment + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + clickButtons() + } + + private fun clickButtons(){ + binding.loginButton.setOnClickListener { + addFragment(loginFragment) + Log.i("Login","Clicked") + } + } + + private fun addFragment(fragment: Fragment) { + val ft: FragmentTransaction = parentFragmentManager.beginTransaction() + ft.replace(R.id.container, fragment) + ft.addToBackStack(null) + ft.commit() + } + + fun popFragment() { + parentFragmentManager.popBackStack() + } + + fun replaceFragment(fragment: Fragment) { + parentFragmentManager.beginTransaction().apply { + replace(R.id.container, fragment) //replacing fragment + commit() //call signals to the FragmentManager that all operations have been added to the transaction + } + } + +} \ No newline at end of file diff --git a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/ChangePasswordFragment.kt b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/ChangePasswordFragment.kt new file mode 100644 index 00000000..27895336 --- /dev/null +++ b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/ChangePasswordFragment.kt @@ -0,0 +1,9 @@ +package com.example.disasterresponseplatform.ui.registration + +import androidx.fragment.app.Fragment +import com.example.disasterresponseplatform.R + + +class ChangePasswordFragment : Fragment(R.layout.fragment_change_password) { + +} \ No newline at end of file diff --git a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/ForgotPasswordFragment.kt b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/ForgotPasswordFragment.kt new file mode 100644 index 00000000..c242f968 --- /dev/null +++ b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/ForgotPasswordFragment.kt @@ -0,0 +1,42 @@ +package com.example.disasterresponseplatform.ui.registration + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.FragmentTransaction +import com.example.disasterresponseplatform.R +import com.example.disasterresponseplatform.databinding.FragmentForgotPasswordBinding + + +class ForgotPasswordFragment : Fragment() { + + private lateinit var binding: FragmentForgotPasswordBinding + private val changePasswordFragment = ChangePasswordFragment() + + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + binding = FragmentForgotPasswordBinding.inflate(inflater,container,false) + // Inflate the layout for this fragment + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + binding.btchangePassword.setOnClickListener { + addFragment(changePasswordFragment) + } + } + + private fun addFragment(fragment: Fragment) { + val ft: FragmentTransaction = parentFragmentManager.beginTransaction() + ft.replace(R.id.container, fragment) + ft.addToBackStack(null) + ft.commit() + } + +} \ No newline at end of file diff --git a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/LoginFragment.kt b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/LoginFragment.kt new file mode 100644 index 00000000..fbfd97dc --- /dev/null +++ b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/LoginFragment.kt @@ -0,0 +1,53 @@ +package com.example.disasterresponseplatform.ui.registration + +import android.graphics.Color +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.FragmentTransaction +import com.example.disasterresponseplatform.R +import com.example.disasterresponseplatform.databinding.FragmentLoginBinding + + +class LoginFragment : Fragment() { + + private lateinit var binding: FragmentLoginBinding + val registrationFragment = RegistrationFragment() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + // Inflate the layout for this fragment + binding = FragmentLoginBinding.inflate(inflater,container,false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + binding.clLogin.setBackgroundColor(Color.DKGRAY) + binding.tvLogin.setTextColor(Color.WHITE) + clickButtons() + } + + private fun clickButtons(){ + binding.registrationButton.setOnClickListener { + addFragment(registrationFragment) + } + } + + private fun addFragment(fragment: Fragment) { + val ft: FragmentTransaction = parentFragmentManager.beginTransaction() + ft.replace(R.id.container, fragment) + ft.addToBackStack(null) + ft.commit() + } + +} \ No newline at end of file diff --git a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/RegistrationFragment.kt b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/RegistrationFragment.kt new file mode 100644 index 00000000..ceb56fdd --- /dev/null +++ b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/registration/RegistrationFragment.kt @@ -0,0 +1,42 @@ +package com.example.disasterresponseplatform.ui.registration + +import android.graphics.Color +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentTransaction +import com.example.disasterresponseplatform.R +import com.example.disasterresponseplatform.databinding.FragmentRegistrationBinding + +class RegistrationFragment : Fragment() { + + private lateinit var binding: FragmentRegistrationBinding + private val forgotPasswordFragment = ForgotPasswordFragment() + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + // Inflate the layout for this fragment + binding = FragmentRegistrationBinding.inflate(inflater,container,false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + binding.clRegistration.setBackgroundColor(Color.GRAY) + binding.btForgotPassword.setOnClickListener { + addFragment(forgotPasswordFragment) + } + } + + private fun addFragment(fragment: Fragment) { + val ft: FragmentTransaction = parentFragmentManager.beginTransaction() + ft.replace(R.id.container, fragment) + ft.addToBackStack(null) + ft.commit() + } + +} \ No newline at end of file diff --git a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/activity_main.xml b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/activity_main.xml index fb7768a2..5442a376 100644 --- a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/activity_main.xml +++ b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/activity_main.xml @@ -6,29 +6,15 @@ android:layout_height="match_parent" tools:context=".MainActivity"> - + app:layout_constraintTop_toTopOf="parent"> - \ No newline at end of file diff --git a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/fragment_change_password.xml b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/fragment_change_password.xml new file mode 100644 index 00000000..388a461b --- /dev/null +++ b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/fragment_change_password.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/fragment_forgot_password.xml b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/fragment_forgot_password.xml new file mode 100644 index 00000000..369e7b97 --- /dev/null +++ b/Disaster-Response-Platform/mobile/DisasterResponsePlatform/app/src/main/res/layout/fragment_forgot_password.xml @@ -0,0 +1,30 @@ + + + + + + +