This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from fictadvisor/user_profile
User profile
- Loading branch information
Showing
19 changed files
with
674 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/fictadvisor/android/data/remote/GlideModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.fictadvisor.android.data.remote | ||
|
||
import com.bumptech.glide.annotation.GlideModule | ||
import com.bumptech.glide.module.AppGlideModule | ||
|
||
@GlideModule | ||
class GlideModule: AppGlideModule() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
app/src/main/java/com/fictadvisor/android/ui/SecurityStudentProfileFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.fictadvisor.android.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.lifecycle.ViewModelProvider | ||
import androidx.navigation.Navigation | ||
import com.fictadvisor.android.R | ||
import com.fictadvisor.android.data.dto.AuthLoginResponse | ||
import com.fictadvisor.android.data.dto.BaseResponse | ||
import com.fictadvisor.android.databinding.FragmentSecurityStudentProfileBinding | ||
import com.fictadvisor.android.repository.AuthRepository | ||
import com.fictadvisor.android.utils.StorageUtil | ||
import com.fictadvisor.android.viewmodel.AuthViewModel | ||
import com.fictadvisor.android.viewmodel.AuthViewModelFactory | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
|
||
class SecurityStudentProfileFragment : Fragment() { | ||
private lateinit var binding: FragmentSecurityStudentProfileBinding | ||
private lateinit var authViewModel: AuthViewModel | ||
private val authRepository = AuthRepository() | ||
private lateinit var storageUtil: StorageUtil | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
arguments?.let { | ||
} | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
binding = FragmentSecurityStudentProfileBinding.inflate(inflater, container, false) | ||
val view = binding.root | ||
authViewModel = ViewModelProvider( | ||
this, | ||
AuthViewModelFactory(authRepository) | ||
).get(AuthViewModel::class.java) | ||
|
||
storageUtil = StorageUtil(requireContext()) | ||
|
||
if (storageUtil.getTokens()?.accessToken != null) { | ||
binding.buttonChangePassword.setOnClickListener { | ||
val oldPassword = binding.editTextOldPassword.text.toString() | ||
val newPassword = binding.editTextNewPassword.text.toString() | ||
val token = storageUtil.getTokens()?.accessToken.toString() | ||
updatePassword(token, oldPassword, newPassword) | ||
Navigation.findNavController(view).navigate(R.id.action_securityStudentProfileFragment_to_studentProfileFragment) | ||
} | ||
} | ||
|
||
binding.buttonPrevious.setOnClickListener { | ||
view.let { it1 -> Navigation.findNavController(it1).navigateUp() } | ||
} | ||
|
||
return view | ||
} | ||
|
||
private fun updatePassword(token: String, oldPassword: String, newPassword: String) { | ||
CoroutineScope(Dispatchers.IO).launch { | ||
authViewModel.updatePassword(token, oldPassword, newPassword) | ||
} | ||
|
||
authViewModel.authUpdatePasswordResponse.observe(viewLifecycleOwner) { updatePasswordResponse -> | ||
updatePasswordResponse?.let { | ||
handleUpdatePasswordResponse(it) | ||
} | ||
} | ||
} | ||
|
||
private fun handleUpdatePasswordResponse(response: BaseResponse<AuthLoginResponse>) { | ||
when (response) { | ||
is BaseResponse.Success -> { | ||
showSuccessLog("Пароль успішно змінено") | ||
} | ||
|
||
is BaseResponse.Error -> { | ||
showErrorLog("Помилка зміни паролю: ${response.error?.message}") | ||
} | ||
|
||
is BaseResponse.Loading -> { | ||
showSuccessLog("Завантаження...") | ||
} | ||
} | ||
} | ||
|
||
private fun showSuccessLog(message: String) { | ||
Log.d("SecurityStudentProfileFragment", message) | ||
} | ||
|
||
private fun showErrorLog(message: String) { | ||
Log.e("SecurityStudentProfileFragment", message) | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun newInstance() = SecurityStudentProfileFragment() | ||
} | ||
} |
Oops, something went wrong.