diff --git a/app/src/main/java/com/scholar/center/MainActivity.kt b/app/src/main/java/com/scholar/center/MainActivity.kt index eec004a..747967f 100644 --- a/app/src/main/java/com/scholar/center/MainActivity.kt +++ b/app/src/main/java/com/scholar/center/MainActivity.kt @@ -1,20 +1,21 @@ package com.scholar.center -import androidx.appcompat.app.AppCompatActivity +import android.app.Application +import android.content.Context import android.os.Bundle -import android.util.Log import androidx.activity.viewModels +import androidx.appcompat.app.AppCompatActivity import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen -import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope -import androidx.lifecycle.repeatOnLifecycle import androidx.navigation.NavController import androidx.navigation.fragment.NavHostFragment import com.scholar.center.databinding.ActivityMainBinding +import com.scholar.center.unit.LocaleHelper import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch + @AndroidEntryPoint class MainActivity : AppCompatActivity() { @@ -22,6 +23,10 @@ class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding private lateinit var navController: NavController + companion object{ + + } + override fun onCreate(savedInstanceState: Bundle?) { installSplashScreen() @@ -31,10 +36,12 @@ class MainActivity : AppCompatActivity() { setContentView(binding.root) - val navHostFragment = supportFragmentManager.findFragmentById(binding.rootNavHostFragment.id) as NavHostFragment + val navHostFragment = + supportFragmentManager.findFragmentById(binding.rootNavHostFragment.id) as NavHostFragment navController = navHostFragment.navController val navGraph = navController.navInflater.inflate(R.navigation.root_nav_graph) + lifecycleScope.launch { viewModel.startDestination.collectLatest { startDestination -> startDestination?.let { @@ -43,6 +50,8 @@ class MainActivity : AppCompatActivity() { } } } + + } } \ No newline at end of file diff --git a/app/src/main/java/com/scholar/center/MainViewModel.kt b/app/src/main/java/com/scholar/center/MainViewModel.kt index be81775..3e71aba 100644 --- a/app/src/main/java/com/scholar/center/MainViewModel.kt +++ b/app/src/main/java/com/scholar/center/MainViewModel.kt @@ -1,17 +1,16 @@ package com.scholar.center -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData + import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.scholar.domain.repo.DataStorePreference import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import javax.inject.Inject + @HiltViewModel class MainViewModel @Inject constructor( @@ -20,9 +19,11 @@ constructor( var startDestination = MutableStateFlow(null) private set + init { viewModelScope.launch { - val isFirstOpen = dataStore.readValue(DataStorePreference.isAppFirstOpen).first() ?: true + val isFirstOpen = + dataStore.readValue(DataStorePreference.isAppFirstOpen).first() ?: true startDestination.value = if (isFirstOpen) { R.id.loginFragment } else { diff --git a/app/src/main/java/com/scholar/center/ui/credit/CreditFragment.kt b/app/src/main/java/com/scholar/center/ui/credit/CreditFragment.kt index ee1ae12..5729ffc 100644 --- a/app/src/main/java/com/scholar/center/ui/credit/CreditFragment.kt +++ b/app/src/main/java/com/scholar/center/ui/credit/CreditFragment.kt @@ -1,22 +1,186 @@ package com.scholar.center.ui.credit +import android.Manifest +import android.content.pm.PackageManager +import android.net.Uri import android.os.Bundle import android.view.View +import android.view.animation.AlphaAnimation +import android.widget.AdapterView +import android.widget.ArrayAdapter +import android.widget.Toast +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts +import androidx.core.content.ContextCompat +import androidx.core.widget.addTextChangedListener import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle +import androidx.navigation.fragment.findNavController import com.scholar.center.R import com.scholar.center.databinding.FragmentCreditBinding import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.launch +import java.io.File @AndroidEntryPoint -class CreditFragment :Fragment(R.layout.fragment_credit) { - lateinit var binding :FragmentCreditBinding - private val viewModel : CreditVM by viewModels() +class CreditFragment : Fragment(R.layout.fragment_credit) { + lateinit var binding: FragmentCreditBinding + private val viewModel: CreditVM by viewModels() + + private lateinit var permissionLauncher: ActivityResultLauncher + private lateinit var imagePickerLauncher: ActivityResultLauncher + private lateinit var methodAdapter: ArrayAdapter + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + methodAdapter = + ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item).apply { + setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) + } + } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding = FragmentCreditBinding.bind(view) + binding.creditAmountEditText.addTextChangedListener { + if (it.toString().isNotEmpty()) + viewModel.onAmountInputChanged(it.toString().toInt()) + } + binding.creditDescriptionEditText.addTextChangedListener { + viewModel.onDescriptionInputChanged(it.toString()) + } + + binding.addContactSend.setOnClickListener { + viewModel.onSendClick() + } + + binding.creditSpinnerMethod.adapter = methodAdapter + addMethod() + binding.creditSpinnerMethod.onItemSelectedListener = + object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, + view: View?, + position: Int, + id: Long, + ) { + viewModel.onMethodInputChanged(position) + } + + override fun onNothingSelected(parent: AdapterView<*>?) {} + } + + + binding.addImagePaymentLayout.setOnClickListener { + if (permissionGranted()) { + imagePickerLauncher.launch("image/*") + } else { + permissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE) + } + + } + + permissionLauncher = + registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean -> + if (isGranted) { + imagePickerLauncher.launch("image/*") + } else { + Toast.makeText(requireContext(), "Permission denied", Toast.LENGTH_SHORT).show() + } + } + + lifecycleScope.launch { + viewModel.message.collectLatest { message -> + message?.let { + Toast.makeText(requireContext(), it, Toast.LENGTH_SHORT).show() + } + } + } + imagePickerLauncher = registerForActivityResult( + ActivityResultContracts.GetContent() + ) { uri: Uri? -> + if (uri != null) { + val filePath = + requireContext().contentResolver?.openInputStream(uri)?.use { inputStream -> + val file = File(requireContext().cacheDir, "temp_file") + file.outputStream().use { outputStream -> + inputStream.copyTo(outputStream) + } + file.absolutePath + } + filePath?.let { viewModel.onLinkInputChanged(it) } + } + } + + viewLifecycleOwner.lifecycleScope.launch { + repeatOnLifecycle(state = Lifecycle.State.CREATED) { + viewModel.creditState.collect { state -> + binding.creditProgressBar.visibility = + if (state.isLoading) View.VISIBLE else View.GONE + + if (state.isInputValid || state.errorMessageInput == null) + hideTextError() else showTextError() + state.errorMessageInput?.let { error -> + binding.creditErrorText.text = getString(error) + } + if (state.linkInput.isNotEmpty()) { + binding.addImagePaymentImageview.setImageResource(R.drawable.check_mark) + } + val hasErrorMessage = state.errorMessageLoginProcess.isNullOrEmpty() + if (!hasErrorMessage) { + binding.creditErrorText.text = state.errorMessageLoginProcess + showTextError() + } + + if(state.isSuccessfullySend){ + findNavController().popBackStack() + } + } + } + } + } + + private fun addMethod(data: List = emptyList()) { + val mutableData = data.toMutableList() + mutableData.add(getString(R.string.select_method)) + mutableData.add("شركة الهرم") + mutableData.add("بنك البركة") + mutableData.add("بنك بيبلوس") + mutableData.add("بنك بيمو السعودي الفرنسي") + mutableData.add("MTN cash") + mutableData.add("SYRIATEL cash") + methodAdapter.clear() + methodAdapter.addAll(mutableData) + methodAdapter.notifyDataSetChanged() + } + + private fun permissionGranted(): Boolean { + return ContextCompat.checkSelfPermission( + requireContext(), Manifest.permission.READ_EXTERNAL_STORAGE + ) == PackageManager.PERMISSION_GRANTED + } + + private fun showTextError() { + // Fade in + if (binding.creditErrorText.visibility == View.VISIBLE) return + val alpha = AlphaAnimation(0f, 1f) + alpha.duration = 300 + binding.creditErrorText.startAnimation(alpha) + binding.creditErrorText.visibility = View.VISIBLE + } + + private fun hideTextError() { + // Fade out + if (binding.creditErrorText.visibility == View.GONE) return + val alpha = AlphaAnimation(1f, 0f) + alpha.duration = 300 + binding.creditErrorText.startAnimation(alpha) + binding.creditErrorText.visibility = View.GONE } } \ No newline at end of file diff --git a/app/src/main/java/com/scholar/center/ui/credit/CreditVM.kt b/app/src/main/java/com/scholar/center/ui/credit/CreditVM.kt index 74cc599..20c7367 100644 --- a/app/src/main/java/com/scholar/center/ui/credit/CreditVM.kt +++ b/app/src/main/java/com/scholar/center/ui/credit/CreditVM.kt @@ -1,11 +1,11 @@ package com.scholar.center.ui.credit +import android.net.Uri import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.scholar.center.R import com.scholar.domain.model.CreditInputValidationType import com.scholar.domain.model.CreditState -import com.scholar.domain.model.LoginInputValidationType import com.scholar.domain.model.Resource import com.scholar.domain.repo.DataStorePreference import com.scholar.domain.repo.StudentRepository @@ -13,6 +13,7 @@ import com.scholar.domain.usecase.ValidateCreditUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import javax.inject.Inject @@ -28,6 +29,10 @@ class CreditVM @Inject constructor( private set + private val _selectedUri = MutableStateFlow(Uri.EMPTY) + val selectedUri = _selectedUri.asStateFlow() + + private val _message = MutableStateFlow(null) val message = _message.asStateFlow() @@ -46,13 +51,18 @@ class CreditVM @Inject constructor( checkInputValidation() } - fun onLinkInputChanged(newValue: Int) { + fun onLinkInputChanged(newValue: String) { creditState.update { currentState -> currentState.copy(linkInput = newValue) } checkInputValidation() } + + fun setUri(uri: Uri) { + _selectedUri.value = uri + } + fun onDescriptionInputChanged(newValue: String) { creditState.update { currentState -> currentState.copy(descriptionInput = newValue) @@ -77,33 +87,42 @@ class CreditVM @Inject constructor( currentState.copy(isLoading = true) } viewModelScope.launch { -// val result = studentRepository.contact( -// name = contactState.value.nameInput, -// email = contactState.value.emailInput, -// phone = contactState.value.phoneInput, -// subject = contactState.value.subjectInput -// ) - when (result) { - is Resource.Success -> { - result.data?.let { data -> - _message.value = data.message - creditState.update { currentState -> - currentState.copy(isSuccessfullySend = true, isLoading = false) + val studentId = dataStore.readValue(DataStorePreference.userId).first() + if (studentId == null || studentId == 0) { + creditState.update { currentState -> + currentState.copy(errorMessageInput = R.string.please_sign_in) + } + return@launch + } else { + + + val result = studentRepository.purchaseCredit( + filePath = creditState.value.linkInput, + amount = creditState.value.amountInput, + paymentMethod = creditState.value.methodInput, + description = creditState.value.descriptionInput, + studentId = studentId + ) + when (result) { + is Resource.Success -> { + result.data?.let { data -> + _message.value = data + creditState.update { currentState -> + currentState.copy(isSuccessfullySend = true, isLoading = false) + } } } - } - - is Resource.Error -> { - creditState.update { currentState -> - currentState.copy( - errorMessageLoginProcess = result.message, - isLoading = false - ) + is Resource.Error -> { + creditState.update { currentState -> + currentState.copy( + errorMessageLoginProcess = result.message, + isLoading = false + ) + } } } } - } } @@ -123,12 +142,14 @@ class CreditVM @Inject constructor( isInputValid = false ) } + CreditInputValidationType.NoLink -> { currentState.copy( errorMessageInput = R.string.no_image_added, isInputValid = false ) } + CreditInputValidationType.Valid -> { currentState.copy(errorMessageInput = null, isInputValid = true) } diff --git a/app/src/main/java/com/scholar/center/ui/dialogs/ConfirmDialog.kt b/app/src/main/java/com/scholar/center/ui/dialogs/ConfirmDialog.kt new file mode 100644 index 0000000..7559760 --- /dev/null +++ b/app/src/main/java/com/scholar/center/ui/dialogs/ConfirmDialog.kt @@ -0,0 +1,21 @@ +package com.scholar.center.ui.dialogs + +import android.os.Bundle +import android.view.View +import androidx.fragment.app.DialogFragment +import com.scholar.center.R +import com.scholar.center.databinding.ConfirmDialogBinding + +class ConfirmDialog(val confirm: () -> Unit) : DialogFragment(R.layout.confirm_dialog) { + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + val binding = ConfirmDialogBinding.bind(view) + + binding.okButton.setOnClickListener { + confirm() + dismiss() + } + binding.closeButton.setOnClickListener { dismiss() } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/scholar/center/ui/dialogs/LanguageDialogFragment.kt b/app/src/main/java/com/scholar/center/ui/dialogs/LanguageDialogFragment.kt new file mode 100644 index 0000000..28c8a32 --- /dev/null +++ b/app/src/main/java/com/scholar/center/ui/dialogs/LanguageDialogFragment.kt @@ -0,0 +1,25 @@ +package com.scholar.center.ui.dialogs + +import android.os.Bundle +import android.view.View +import androidx.fragment.app.DialogFragment +import com.scholar.center.R +import com.scholar.center.databinding.LanguageDialogBinding +import java.util.Locale + +class LanguageDialogFragment(val setLanguage: (Locale) -> Unit) : + DialogFragment(R.layout.language_dialog) { + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val binding = LanguageDialogBinding.bind(view) + + binding.btnApply.setOnClickListener { + if (binding.radioArabic.isChecked) { + setLanguage(Locale("ar", "AE")) + } else if (binding.radioEnglish.isChecked) { + setLanguage(Locale("en","USA")) + } + dismiss() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialDetailFragment.kt b/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialDetailFragment.kt index e96070b..3a11597 100644 --- a/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialDetailFragment.kt +++ b/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialDetailFragment.kt @@ -3,6 +3,7 @@ package com.scholar.center.ui.materials.detail import android.graphics.Paint import android.os.Bundle import android.view.View +import android.widget.Toast import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle @@ -35,15 +36,12 @@ class MaterialDetailFragment : Fragment(R.layout.fragment_material_detail) { val tabLayout = binding.materialTabLayout val viewPager = binding.materialViewPager - val fragments = listOf( - MaterialInformationFragment(viewModel), MaterialReviewsFragment(viewModel), - ) + val fragments = mutableListOf() val materialAdapter = TeacherPagerAdapter( fragments = fragments, fragmentActivity = requireActivity() ) viewPager.adapter = materialAdapter - TabLayoutMediator(tabLayout, viewPager) { tab, position -> tab.text = when (position) { 0 -> getString(R.string.information) @@ -63,10 +61,17 @@ class MaterialDetailFragment : Fragment(R.layout.fragment_material_detail) { } } } + + lifecycleScope.launch { + viewModel.message.collect { msg -> + msg?.let { Toast.makeText(requireContext(), msg, Toast.LENGTH_SHORT).show() } + } + } viewLifecycleOwner.lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { viewModel.material.collect { it?.let { materialWithDetail -> +// todo materialAdapter.ad val material = materialWithDetail.material binding.materialName.text = material.title binding.materialType.text = materialWithDetail.category @@ -122,13 +127,14 @@ class MaterialDetailFragment : Fragment(R.layout.fragment_material_detail) { ) return@setOnClickListener } - if (material.price == null || material.price == 0) { - navigateTo(materialId = material.id, material.categoryId) - } else { - navigateTo(materialId = material.id, material.categoryId) - // purchase - - } + viewModel.purchase() +// if (material.price == null || material.price == 0) { +// navigateTo(materialId = material.id, material.categoryId) +// } else { +// navigateTo(materialId = material.id, material.categoryId) +// // purchase +// +// } } } } diff --git a/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialDetailVM.kt b/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialDetailVM.kt index 7419b75..67526dd 100644 --- a/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialDetailVM.kt +++ b/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialDetailVM.kt @@ -5,11 +5,14 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.scholar.center.unit.Constants.MATERIAL_ID_KEY import com.scholar.domain.model.MaterialWithDetail +import com.scholar.domain.model.Resource import com.scholar.domain.repo.DataStorePreference +import com.scholar.domain.repo.StudentRepository import com.scholar.domain.usecase.MaterialUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import javax.inject.Inject @@ -18,8 +21,10 @@ class MaterialDetailVM @Inject constructor( savedStateHandle: SavedStateHandle, private val materialUseCase: MaterialUseCase, private val dataStore: DataStorePreference, + private val studentRepository: StudentRepository, ) : ViewModel() { + private val materialId = requireNotNull(savedStateHandle.get(MATERIAL_ID_KEY)) { "Material id required" } @@ -32,6 +37,8 @@ class MaterialDetailVM @Inject constructor( private val _loading = MutableStateFlow(true) val loading = _loading.asStateFlow() + private val _message = MutableStateFlow(null) + val message = _message.asStateFlow() init { @@ -42,13 +49,31 @@ class MaterialDetailVM @Inject constructor( } } launch { - _loading.value=true + _loading.value = true materialUseCase(materialId).collect { _material.value = it - _loading.value=false + _loading.value = false } } + } + } + + fun purchase() { + viewModelScope.launch { + _loading.value = true + val studentID = dataStore.readValue(DataStorePreference.userId).first() + if (studentID == null || studentID == 0) return@launch + _loading.value = true + when(val result = studentRepository.purchaseMaterial(studentID, materialId)){ + is Resource.Success->{ + _message.value = result.data + } + is Resource.Error->{ + _message.value = result.message + } + } + _loading.value = false } } } \ No newline at end of file diff --git a/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialReviewsFragment.kt b/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialReviewsFragment.kt index bde5511..7592a57 100644 --- a/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialReviewsFragment.kt +++ b/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialReviewsFragment.kt @@ -13,6 +13,9 @@ import kotlinx.coroutines.launch class MaterialReviewsFragment(private val viewModel:MaterialDetailVM) : Fragment(R.layout.fragment_material_reviews) { + + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/app/src/main/java/com/scholar/center/ui/setting/SettingsFragment.kt b/app/src/main/java/com/scholar/center/ui/setting/SettingsFragment.kt index 39e2780..1852992 100644 --- a/app/src/main/java/com/scholar/center/ui/setting/SettingsFragment.kt +++ b/app/src/main/java/com/scholar/center/ui/setting/SettingsFragment.kt @@ -9,10 +9,13 @@ import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import androidx.navigation.findNavController import com.bumptech.glide.Glide +import com.scholar.center.MainActivity import com.scholar.center.R import com.scholar.center.databinding.FragmentProfileBinding +import com.scholar.center.ui.dialogs.LanguageDialogFragment import com.scholar.center.ui.main.MainFragmentDirections import com.scholar.center.unit.Constants.BASE_URL +import com.scholar.center.unit.LocaleHelper import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch @@ -83,6 +86,16 @@ class SettingsFragment : Fragment(R.layout.fragment_profile) { } + binding.profileFragmentLanguageListTile.root.setOnClickListener { + val dialogFragment = LanguageDialogFragment { + viewModel.changeLanguage(it.language) + LocaleHelper.setLocale(requireContext(), it) + (activity as MainActivity).recreate() + } + dialogFragment.show(parentFragmentManager, "LanguageDialog") + } + + } diff --git a/app/src/main/java/com/scholar/center/ui/setting/SettingsVM.kt b/app/src/main/java/com/scholar/center/ui/setting/SettingsVM.kt index a16a7e8..a464407 100644 --- a/app/src/main/java/com/scholar/center/ui/setting/SettingsVM.kt +++ b/app/src/main/java/com/scholar/center/ui/setting/SettingsVM.kt @@ -29,6 +29,12 @@ class SettingsVM @Inject constructor( getStudent() } + fun changeLanguage(lan: String) { + viewModelScope.launch { + dataStore.saveValue(DataStorePreference.language, lan) + } + } + private fun checkAuth() { viewModelScope.launch { dataStore.readValue(DataStorePreference.isUserLoggedIn).collect { diff --git a/app/src/main/java/com/scholar/center/ui/stories/add/AddStoryFragment.kt b/app/src/main/java/com/scholar/center/ui/stories/add/AddStoryFragment.kt index dc16ddb..c64ff0d 100644 --- a/app/src/main/java/com/scholar/center/ui/stories/add/AddStoryFragment.kt +++ b/app/src/main/java/com/scholar/center/ui/stories/add/AddStoryFragment.kt @@ -25,10 +25,6 @@ class AddStoryFragment : Fragment(R.layout.fragment_add_story) { private val viewModel: AddStoryVM by viewModels() - companion object { - private const val PICK_IMAGE_REQUEST = 1 - private const val PERMISSION_REQUEST = 2 - } private lateinit var permissionLauncher: ActivityResultLauncher private lateinit var imagePickerLauncher: ActivityResultLauncher diff --git a/app/src/main/java/com/scholar/center/unit/LocaleHelper.kt b/app/src/main/java/com/scholar/center/unit/LocaleHelper.kt new file mode 100644 index 0000000..983b41b --- /dev/null +++ b/app/src/main/java/com/scholar/center/unit/LocaleHelper.kt @@ -0,0 +1,19 @@ +package com.scholar.center.unit + +import android.content.Context +import androidx.core.text.layoutDirection +import java.util.* + + +object LocaleHelper { + + fun setLocale(context: Context,locale:Locale) { + + val config = context.resources.configuration + config.setLocale(locale) + config.setLayoutDirection(locale) + context.resources.updateConfiguration(config,null) + + } + +} diff --git a/app/src/main/res/layout/confirm_dialog.xml b/app/src/main/res/layout/confirm_dialog.xml new file mode 100644 index 0000000..8c18a54 --- /dev/null +++ b/app/src/main/res/layout/confirm_dialog.xml @@ -0,0 +1,43 @@ + + + + + + + + + +