Skip to content

Commit

Permalink
Finish feature/OTC-651
Browse files Browse the repository at this point in the history
OTC-651 Implemented default language, fixed saved language
  • Loading branch information
dragos-dobre authored Aug 4, 2022
2 parents 4ab63f1 + 2944b1c commit 77cb6c9
Show file tree
Hide file tree
Showing 20 changed files with 363 additions and 1,047 deletions.
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ android {
buildConfigField "String", "RAR_PASSWORD", '")(#$1HsD"'
buildConfigField "String", "API_VERSION", '"3"'
buildConfigField "String", "APP_DIR", '"IMIS"'
buildConfigField "String", "DEFAULT_LANGUAGE_CODE", '"en"'
resValue "string", "app_name_policies", "Policies"
resValue "string", "ReleaseDateValue", getDate()
}
Expand All @@ -101,6 +102,7 @@ android {
buildConfigField "boolean", "SHOW_PAYMENT_MENU", 'true'
buildConfigField "boolean", "SHOW_BULK_CN_MENU", 'true'
buildConfigField "String", "APP_DIR", '"IMIS-CHFDEV"'
buildConfigField "String", "DEFAULT_LANGUAGE_CODE", '"en-tz"'
resValue "string", "app_name_policies", "Policies CHF DEV"
dimension = 'std'
}
Expand All @@ -117,6 +119,7 @@ android {
applicationId "org.openimis.imispolicies.bepha"
buildConfigField "String", "API_BASE_URL", '"http://149.210.235.40/devupgrade/rest/"'
buildConfigField "String", "APP_DIR", '"IMIS-BEPHADEV"'
buildConfigField "String", "DEFAULT_LANGUAGE_CODE", '"en-cm"'
resValue "string", "app_name_policies", "Policies BEPHA DEV"
dimension = 'std'
}
Expand Down Expand Up @@ -215,11 +218,11 @@ dependencies {
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'org.jetbrains:annotations:15.0'


androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testImplementation 'junit:junit:4.13.1'
//compile 'com.android.support:support-annotations:27.1.1'
}
448 changes: 0 additions & 448 deletions app/src/bepha/res/values-fr/strings.xml

This file was deleted.

448 changes: 0 additions & 448 deletions app/src/bepha/res/values/strings.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
Expand Down Expand Up @@ -158,6 +157,7 @@ public class ClientAndroidInterface {
Target imageTarget;
StorageManager storageManager;


ClientAndroidInterface(Context c) {
mContext = c;
global = (Global) mContext.getApplicationContext();
Expand Down Expand Up @@ -5217,12 +5217,7 @@ public void UpdateInsureePolicy(int PolicyId) {//herman new
public File[] getPhotos() {
String path = mContext.getApplicationInfo().dataDir + "/Images/";
File Directory = new File(path);
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
return filename.contains("0");
}
};
FilenameFilter filter = (dir, filename) -> filename.contains("0");
File[] newFiles = Directory.listFiles(filter);
return Directory.listFiles(filter);
}
Expand Down Expand Up @@ -5889,71 +5884,66 @@ public boolean CheckInternetAvailable() {

public void LoginDialogBox(final String page) {

((Activity) mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
// check internet connection
if (!CheckInternetAvailable())
return;
// get prompts.xml view
LayoutInflater li = LayoutInflater.from(mContext);
View promptsView = li.inflate(R.layout.login_dialog, null);

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);

// set prompts.xml to alertdialog builder
alertDialogBuilder.setView(promptsView);

final TextView username = (TextView) promptsView.findViewById(R.id.UserName);
final TextView password = (TextView) promptsView.findViewById(R.id.Password);

// set dialog message
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (!username.getText().toString().equals("") || !password.getText().toString().equals("")) {
boolean isUserLogged = false;
isUserLogged = LoginToken(username.getText().toString(), password.getText().toString());

if (isUserLogged) {
if (page.equals("Enquire")) {
((Enquire) mContext).finish();
Intent intent = new Intent(mContext, Enquire.class);
mContext.startActivity(intent);
}
if (page.equals("Renewals")) {
((RenewList) mContext).finish();
Intent intent = new Intent(mContext, RenewList.class);
mContext.startActivity(intent);
}
if (page.equals("Feedbacks")) {
((FeedbackList) mContext).finish();
Intent intent = new Intent(mContext, FeedbackList.class);
mContext.startActivity(intent);
}
if (page.equals("Reports")) {
((FeedbackList) mContext).finish();
Intent intent = new Intent(mContext, Reports.class);
mContext.startActivity(intent);
}

} else {
ShowDialog(mContext.getResources().getString(R.string.LoginFail));
}
} else {
Toast.makeText(mContext, "Please enter user name and password", Toast.LENGTH_LONG).show();
((Activity) mContext).runOnUiThread(() -> {
// check internet connection
if (!CheckInternetAvailable())
return;
// get prompts.xml view
LayoutInflater li = LayoutInflater.from(mContext);
View promptsView = li.inflate(R.layout.login_dialog, null);

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);

// set prompts.xml to alertdialog builder
alertDialogBuilder.setView(promptsView);

final TextView username = promptsView.findViewById(R.id.UserName);
final TextView password = promptsView.findViewById(R.id.Password);

// set dialog message
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("OK",
(dialog, id) -> {
if (!username.getText().toString().equals("") || !password.getText().toString().equals("")) {
boolean isUserLogged = false;
isUserLogged = LoginToken(username.getText().toString(), password.getText().toString());

if (isUserLogged) {
if (page.equals("Enquire")) {
((Enquire) mContext).finish();
Intent intent = new Intent(mContext, Enquire.class);
mContext.startActivity(intent);
}
if (page.equals("Renewals")) {
((RenewList) mContext).finish();
Intent intent = new Intent(mContext, RenewList.class);
mContext.startActivity(intent);
}
if (page.equals("Feedbacks")) {
((FeedbackList) mContext).finish();
Intent intent = new Intent(mContext, FeedbackList.class);
mContext.startActivity(intent);
}
if (page.equals("Reports")) {
((FeedbackList) mContext).finish();
Intent intent = new Intent(mContext, Reports.class);
mContext.startActivity(intent);
}

} else {
ShowDialog(mContext.getResources().getString(R.string.LoginFail));
}
});
} else {
Toast.makeText(mContext, "Please enter user name and password", Toast.LENGTH_LONG).show();
}
});

// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();

// show it
alertDialog.show();
}
// show it
alertDialog.show();
});

}
Expand Down
44 changes: 38 additions & 6 deletions app/src/main/java/org/openimis/imispolicies/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package org.openimis.imispolicies;

import android.Manifest;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
Expand All @@ -38,13 +39,15 @@
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;

import org.openimis.imispolicies.tools.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.openimis.imispolicies.util.LocaleUtil;
import org.openimis.imispolicies.util.StreamUtils;

import java.io.File;
Expand All @@ -61,6 +64,7 @@
public class Global extends Application {
private static Global GlobalContext;
public static final String PREF_NAME = "CMPref";
public static final String PREF_LANGUAGE_KEY = "Language";
public static final String PREF_LOG_TAG = "PREFS";
public static final String FILE_IO_LOG_TAG = "FILEIO";

Expand Down Expand Up @@ -206,12 +210,40 @@ public int isSDCardAvailable() {
}
}

public void changeLanguage(Context ctx, String Language) {
Resources res = ctx.getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration config = res.getConfiguration();
config.locale = new Locale(Language.toLowerCase());
res.updateConfiguration(config, dm);
public boolean isCurrentLanguage(@NonNull String language) {
String currentLanguage = LocaleUtil.getLanguageTag(Locale.getDefault()).toLowerCase(Locale.ROOT);
return language.toLowerCase(Locale.ROOT).equals(currentLanguage);
}

public void setLanguage(@NonNull Context context, @NonNull String language) {
String newLanguage = language.toLowerCase(Locale.ROOT);
if(!isCurrentLanguage(language)) {
changeLanguage(context, newLanguage);
if (context instanceof Activity) {
((Activity) context).recreate();
}
}
}

private void changeLanguage(@NonNull Context context, @NonNull String newLanguage) {
Resources resources = context.getResources();
DisplayMetrics displayMetrics = resources.getDisplayMetrics();
Configuration config = resources.getConfiguration();
config.locale = LocaleUtil.getLocaleFromTag(newLanguage);
resources.updateConfiguration(config, displayMetrics);
Locale.setDefault(config.locale);
onConfigurationChanged(config);
setStoredLanguage(newLanguage);
}


public void setStoredLanguage(String locale) {
setStringKey(PREF_LANGUAGE_KEY, locale);
}

public String getStoredLanguage() {
String defaultLanguage = new SQLHandler(this).getDefaultLanguage();
return getStringKey(PREF_LANGUAGE_KEY, defaultLanguage);
}

private String createOrCheckDirectory(String path) {
Expand Down
Loading

0 comments on commit 77cb6c9

Please sign in to comment.