Skip to content

Commit

Permalink
Restore the language set before logging out (#1923)
Browse files Browse the repository at this point in the history
* Restore the language set before logging out

* Restore the language set before logging out
  • Loading branch information
Aditya-gupta99 authored Jun 8, 2023
1 parent d8d181b commit 8f9ef31
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,38 @@ package com.mifos.mifosxdroid

import android.content.Intent
import android.os.Bundle
import androidx.core.app.ActivityCompat
import com.mifos.mifosxdroid.core.MifosBaseActivity
import com.mifos.mifosxdroid.online.DashboardActivity
import com.mifos.utils.Constants

/**
* Created by mayankjindal on 22/07/17.
*/
class SettingsActivity : MifosBaseActivity() {

private var hasLanguageSettingsChanged = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_toolbar_container)
setToolbarTitle(getString(R.string.settings))
showBackButton()
fragmentManager.beginTransaction()
.replace(R.id.container, SettingsFragment())
.commit()
.replace(R.id.container, SettingsFragment())
.commit()
if (intent.hasExtra(Constants.HAS_SETTING_CHANGED)) {
hasLanguageSettingsChanged = intent.getBooleanExtra(
Constants.HAS_SETTING_CHANGED,
false
)
}
}

override fun onBackPressed() {
super.onBackPressed()
if (hasLanguageSettingsChanged) {
val i = Intent(this, HomeActivity::class.java)
startActivity(i)
ActivityCompat.finishAffinity(this)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@ class SettingsFragment : PreferenceFragment(), SharedPreferences.OnSharedPrefere
}

private fun initSurveyPreferences() {
mEnableSyncSurvey = findPreference(resources.getString(R.string.sync_survey)) as SwitchPreference
mEnableSyncSurvey =
findPreference(resources.getString(R.string.sync_survey)) as SwitchPreference
mEnableSyncSurvey!!.onPreferenceChangeListener = OnPreferenceChangeListener { _, newValue ->
if (newValue as Boolean) {
val syncSurveysDialogFragment = SyncSurveysDialogFragment.newInstance()
val fragmentTransaction = fragmentManager.beginTransaction()
fragmentTransaction.addToBackStack(FragmentConstants.FRAG_SURVEYS_SYNC)
syncSurveysDialogFragment.isCancelable = false
syncSurveysDialogFragment.show(fragmentTransaction,
resources.getString(R.string.sync_clients))
syncSurveysDialogFragment.show(
fragmentTransaction,
resources.getString(R.string.sync_clients)
)
}
true
}
Expand Down Expand Up @@ -113,7 +116,9 @@ class SettingsFragment : PreferenceFragment(), SharedPreferences.OnSharedPrefere
val langPref = findPreference("language_type") as ListPreference
langPref.onPreferenceChangeListener = OnPreferenceChangeListener { _, newValue ->
LanguageHelper.setLocale(this.activity, newValue.toString())
startActivity(Intent(activity, activity.javaClass))
val intent = Intent(this.activity, activity.javaClass)
intent.putExtra(Constants.HAS_SETTING_CHANGED, true)
startActivity(intent)
activity.finish()
preferenceScreen = null
addPreferencesFromResource(R.xml.preferences)
Expand All @@ -123,7 +128,8 @@ class SettingsFragment : PreferenceFragment(), SharedPreferences.OnSharedPrefere
}

private fun initThemePreferences() {
val themePreference = findPreference(resources.getString(R.string.mode_key)) as ListPreference
val themePreference =
findPreference(resources.getString(R.string.mode_key)) as ListPreference
themePreference.onPreferenceChangeListener = OnPreferenceChangeListener { _, newValue ->
val themeOption = newValue as String
ThemeHelper.applyTheme(themeOption)
Expand All @@ -148,7 +154,10 @@ class SettingsFragment : PreferenceFragment(), SharedPreferences.OnSharedPrefere

interface LanguageCallback

override fun onPreferenceTreeClick(preferenceScreen: PreferenceScreen?, preference: Preference?): Boolean {
override fun onPreferenceTreeClick(
preferenceScreen: PreferenceScreen?,
preference: Preference?
): Boolean {
when (preference?.key) {
getString(R.string.password) -> {
// TODO("create changePasswordActivity and implement the logic for password change")
Expand Down
7 changes: 4 additions & 3 deletions mifosng-android/src/main/java/com/mifos/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class Constants {

public static final String ENTITY_ID = "entityId";

public static final String DOCUMENT_ACTIONS = "document_actions";
public static final String DOCUMENT_ACTIONS = "document_actions";

public static final String DOCUMENT = "document_title";

Expand Down Expand Up @@ -128,7 +128,7 @@ public class Constants {
public static final String SERVICE_STATUS = "service_status";

public static final String DATA_TABLE_NAME = "data_table_name";

public static final int DIALOG_FRAGMENT = 1;

public static final String ACTIVATE_CLIENT = "activate_client";
Expand Down Expand Up @@ -166,7 +166,6 @@ public class Constants {
public static final String FILLNOW = "FillNow";



//This needs to be 8 bits because validateRequestPermissionsRequestCode
// in FragmentActivity requires requestCode to be of 8 bits, meaning the range is from 0 to 255.
public static final int REQUEST_PERMISSION_SETTING = 254;
Expand Down Expand Up @@ -280,4 +279,6 @@ public class Constants {
public static final String ACTION_REPORT = "report";
public static final String CURR_PASSWORD = "currentPassword";
public static final String IS_TO_UPDATE_PASS_CODE = "updatePassCode";

public static final String HAS_SETTING_CHANGED = "hasSettingsChanged";
}
13 changes: 11 additions & 2 deletions mifosng-android/src/main/java/com/mifos/utils/PrefManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ public static SharedPreferences getPreferences() {
}

public static void clearPrefs() {
getPreferences().edit().clear().commit();
SharedPreferences.Editor editor = getPreferences().edit();
if (getPreferences() != null) {
for (String key : getPreferences().getAll().keySet()) {
if (!key.equals("language_type")) {
editor.remove(key);
}
}
}
editor.apply();
}

public static int getInt(String preferenceKey, int preferenceDefaultValue) {
Expand Down Expand Up @@ -101,6 +109,7 @@ public static User getUser() {
return gson.fromJson(getString(USER_DETAILS, "null"),
User.class);
}

public static void saveToken(String token) {
putString(TOKEN, token);
}
Expand Down Expand Up @@ -209,7 +218,7 @@ public static Boolean getPassCodeStatus() {
* @return true if app is launched is first time and set the value to
* false which is returned whenever next time it is called
*/
public static Boolean isAppFirstTimeLaunched() {
public static Boolean isAppFirstTimeLaunched() {
Boolean result = getBoolean(FIRST_TIME_APP_LAUNCH, true);
if (result) {
putBoolean(FIRST_TIME_APP_LAUNCH, false);
Expand Down

0 comments on commit 8f9ef31

Please sign in to comment.