Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ fastlane/test_output
fastlane/readme.md

app/release/output.json
.DS_Store

# Custom product flavours

*custom-flavours.gradle
*.aab

#DS_Store files
*.DS_Store
.DS_Store
./.DS_Store
./.git/.DS_Store
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Parameters:
* ```RAR_PASSWORD``` represents the password to be used for the offline extract.
* ```SHOW_CONTROL_NUMBER_MENU``` allow to show or hide the Control Number menu item in case the implementation does not implement the ePayment module.
* ```app_name_policies``` is a resource string allowing to change the name of the application.
* ```sentry_dsn``` allow to define the sentry dsn of your project where error and exception events from your application will be sent

Escape procedures can be configured and language resource files can be changed. Please follow the ```sourceSets``` record. Look in ```app\src\demo``` folder for an example.

Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ android {
buildConfigField "boolean", "IS_PAYMENT_ENABLED", 'false'
resValue "string", "app_name_policies", "Policies"
resValue "string", "ReleaseDateValue", getDate()
resValue "string", "sentry_dsn", ""
}
buildTypes {
release {
Expand Down Expand Up @@ -263,6 +264,7 @@ dependencies {

// unit tests
testImplementation 'junit:junit:4.13.2'
implementation 'io.sentry:sentry-android:8.25.0'
testImplementation 'org.mockito:mockito-core:5.5.0'
testImplementation 'org.robolectric:robolectric:4.11.1'
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
android:resource="@xml/paths" />
</provider>

<meta-data android:name="io.sentry.dsn" android:value="@string/sentry_dsn" />

<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|locale"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
import javax.crypto.spec.SecretKeySpec;
import javax.net.ssl.HttpsURLConnection;

import io.sentry.Sentry;

public class ClientAndroidInterface {
private static final String LOG_TAG_RENEWAL = "RENEWAL";
public static String filePath = null;
Expand Down Expand Up @@ -786,6 +788,7 @@ public int SaveFamily(String FamilyData, String InsureeData) {
return FamilyId;

} catch (UserException e) {
Sentry.captureException(e);
e.printStackTrace();
if (InsureeId != 0)
sqlHandler.deleteData("tblInsuree", "InsureeId = ?", new String[]{String.valueOf(InsureeId)});
Expand Down Expand Up @@ -1045,6 +1048,7 @@ else if (ExceedThreshold == 0)
);
}
} catch (NumberFormatException | UserException e) {
Sentry.captureException(e);
e.printStackTrace();
throw new Exception(e.getMessage());
}
Expand Down Expand Up @@ -1699,8 +1703,10 @@ public int SavePolicy(String PolicyData, int FamilyId, int PolicyId) throws Exce
}
inProgress = false;
} catch (NumberFormatException e) {
Sentry.captureException(e);
e.printStackTrace();
} catch (UserException e) {
Sentry.captureException(e);
e.printStackTrace();
throw new Exception(e.getMessage());
}
Expand Down Expand Up @@ -1891,8 +1897,10 @@ public int SavePremiums(String PremiumData, int PolicyId, int PremiumId, int Fam
}
inProgress = false;
} catch (NumberFormatException e) {
Sentry.captureException(e);
e.printStackTrace();
} catch (UserException e) {
Sentry.captureException(e);
e.printStackTrace();
throw new Exception(e.getMessage());
}
Expand Down Expand Up @@ -3157,6 +3165,7 @@ protected int uploadEnrols(
List<Family.Policy> policies = familyPolicyFromJSONObject(family.getUuid(), policiesArray);
new UpdateFamily().execute(family, policies);
} catch (Exception e) {
Sentry.captureException(e);
e.printStackTrace();
enrolMessages.add(Objects.requireNonNullElse(e.getMessage(), "Something went wrong updating the family"));
return -400;
Expand Down Expand Up @@ -3582,9 +3591,9 @@ protected void onPostExecute(Boolean aBoolean) {
}
}

protected void DeleteUploadedData(final int FamilyId, ArrayList<String> FamilyIDs, int CallerId) {
if (FamilyIDs.size() == 0) {
FamilyIDs = new ArrayList<>() {{
private void DeleteUploadedData(final int FamilyId, ArrayList<String> FamilyIDs, int CallerId) {
if (FamilyIDs.isEmpty()) {
FamilyIDs = new ArrayList<String>() {{
add(String.valueOf(FamilyId));
}};
}
Expand Down Expand Up @@ -3675,6 +3684,7 @@ public void uploadFeedbacks() {
MoveFile(xmlFiles[i], 1);
MoveFile(jsonFiles[i], 1);
} catch (Exception e) {
Sentry.captureException(e);
e.printStackTrace();
if (
e instanceof HttpException &&
Expand Down Expand Up @@ -3913,6 +3923,7 @@ public void downloadMasterData() {
((MainActivity) activity).ShowEnrolmentOfficerDialog();
});
} catch (JSONException e) {
Sentry.captureException(e);
Log.e("MASTERDATA", "Error while parsing master data", e);
} catch (UserException e) {
Log.e("MASTERDATA", "Error while downloading master data", e);
Expand All @@ -3935,6 +3946,7 @@ public void importMasterData(String data) throws JSONException, UserException {
try {
processOldFormat(new JSONArray(data));
} catch (JSONException e) {
Sentry.captureException(e);
try {
processNewFormat(new JSONObject(data));
} catch (JSONException e2) {
Expand All @@ -3949,6 +3961,7 @@ public void startDownloadingMasterData() throws JSONException, UserException, Us
try {
importMasterData(new FetchMasterData().execute());
} catch (Exception e) {
Sentry.captureException(e);
if (e instanceof UserNotAuthenticatedException) {
throw (UserNotAuthenticatedException) e;
}
Expand Down Expand Up @@ -4066,6 +4079,7 @@ private void processOldFormat(@NonNull JSONArray masterData) throws UserExceptio
insertPhoneDefaults(PhoneDefaults);
insertGenders(Genders);
} catch (JSONException e) {
Sentry.captureException(e);
e.printStackTrace();
throw new UserException(activity.getResources().getString(R.string.DownloadMasterDataFailed), e);
}
Expand Down Expand Up @@ -4573,6 +4587,7 @@ public void SaveInsureePolicy(int InsureId, int FamilyId, Boolean Activate, int
ExpiryDate = PolicyObject2.getString("ExpiryDate");
EnrollDate = PolicyObject2.getString("EnrollDate");
} catch (JSONException e) {
Sentry.captureException(e);
e.printStackTrace();
}
values.put("InsureePolicyId", MaxInsureePolicyId);
Expand Down
188 changes: 97 additions & 91 deletions app/src/main/java/org/openimis/imispolicies/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.openimis.imispolicies.network.exception.HttpException;
import org.openimis.imispolicies.network.exception.UserNotAuthenticatedException;
import org.openimis.imispolicies.tools.LanguageManager;
import org.openimis.imispolicies.tools.Log;
Expand All @@ -88,6 +89,8 @@
import java.io.OutputStream;
import java.lang.ref.WeakReference;

import io.sentry.Sentry;

public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

Expand Down Expand Up @@ -161,6 +164,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (f.exists() || f.createNewFile())
new FileOutputStream(f).write(bytes);
} catch (IOException e) {
Sentry.captureException(e);
e.printStackTrace();
}
ShowDialogTex2();
Expand Down Expand Up @@ -230,100 +234,100 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
protected void onCreate(Bundle savedInstanceState) {
global = (Global) getApplicationContext();
super.onCreate(savedInstanceState);
instance = this;
setContentView(R.layout.activity_main);
SQLHandler sqlHandler = new SQLHandler(this);
sqlHandler.isPrivate = true;
//Set the Image folder path
global.setImageFolder(global.getSubdirectory("Images"));
//Check if database exists
File database = global.getDatabasePath(SQLHandler.DBNAME);
if (!database.exists()) {
sqlHandler.getReadableDatabase();
if (copyDatabase(this)) {
Toast.makeText(this, "Copy database success", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Copy database failed", Toast.LENGTH_SHORT).show();
return;
}
} else
sqlHandler.getReadableDatabase();

//Create image folder
createImageFolder();

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show());

DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
//noinspection deprecation
drawer.setDrawerListener(toggle);
toggle.syncState();

navigationView = findViewById(R.id.nav_view);
try {
instance = this;
setContentView(R.layout.activity_main);
SQLHandler sqlHandler = new SQLHandler(this);
sqlHandler.isPrivate = true;
//Set the Image folder path
global.setImageFolder(global.getSubdirectory("Images"));
//Check if database exists
File database = global.getDatabasePath(SQLHandler.DBNAME);
if (!database.exists()) {
sqlHandler.getReadableDatabase();
if (copyDatabase(this)) {
Toast.makeText(this, "Copy database success", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Copy database failed", Toast.LENGTH_SHORT).show();
return;
}
} else
sqlHandler.getReadableDatabase();

//Create image folder
createImageFolder();

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show());

DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
//noinspection deprecation
drawer.setDrawerListener(toggle);
toggle.syncState();

navigationView = findViewById(R.id.nav_view);

navigationView.setNavigationItemSelectedListener(this);
wv = findViewById(R.id.webview);
WebSettings settings = wv.getSettings();
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
settings.setJavaScriptEnabled(true);
//noinspection deprecation
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setDomStorageEnabled(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
settings.setUseWideViewPort(true);
settings.setSaveFormData(true);
settings.setAllowFileAccess(true);
//noinspection deprecation
settings.setEnableSmoothTransition(true);
settings.setLoadWithOverviewMode(true);
wv.addJavascriptInterface(new ClientAndroidInterface(this), "Android");

//Register for context acquire_menu
registerForContextMenu(wv);

navigationView.setNavigationItemSelectedListener(this);
wv = findViewById(R.id.webview);
WebSettings settings = wv.getSettings();
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
settings.setJavaScriptEnabled(true);
//noinspection deprecation
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setDomStorageEnabled(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
settings.setUseWideViewPort(true);
settings.setSaveFormData(true);
settings.setAllowFileAccess(true);
//noinspection deprecation
settings.setEnableSmoothTransition(true);
settings.setLoadWithOverviewMode(true);
wv.addJavascriptInterface(new ClientAndroidInterface(this), "Android");

//Register for context acquire_menu
registerForContextMenu(wv);

wv.loadUrl("file:///android_asset/pages/Home.html");
wv.setWebViewClient(new MyWebViewClient(MainActivity.this));

wv.setWebChromeClient(new WebChromeClient() {
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
//noinspection ConstantConditions
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
getSupportActionBar().setSubtitle(title);
wv.loadUrl("file:///android_asset/pages/Home.html");
wv.setWebViewClient(new MyWebViewClient(MainActivity.this));

wv.setWebChromeClient(new WebChromeClient() {
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
//noinspection ConstantConditions
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
getSupportActionBar().setSubtitle(title);
}
});
NavigationView navigationView = findViewById(R.id.nav_view);
View headerview = navigationView.getHeaderView(0);
Login = headerview.findViewById(R.id.tvLogin);
OfficerName = headerview.findViewById(R.id.tvOfficerName);

Login.setOnClickListener(v -> {
wv.loadUrl("file:///android_asset/pages/Login.html?s=3");
drawer.closeDrawer(GravityCompat.START);
SetLoggedIn();
});
ca = new ClientAndroidInterface(this);
if (ca.isMasterDataAvailable() > 0) {
loadLanguages();
}
});
NavigationView navigationView = findViewById(R.id.nav_view);
View headerview = navigationView.getHeaderView(0);
Login = headerview.findViewById(R.id.tvLogin);
OfficerName = headerview.findViewById(R.id.tvOfficerName);

Login.setOnClickListener(v -> {
wv.loadUrl("file:///android_asset/pages/Login.html?s=3");
drawer.closeDrawer(GravityCompat.START);
SetLoggedIn();
});
ca = new ClientAndroidInterface(this);
if (ca.isMasterDataAvailable() > 0) {
loadLanguages();
}


navigationView.setCheckedItem(R.id.nav_home);

if (checkRequirements()) {
onAllRequirementsMet();
navigationView.setCheckedItem(R.id.nav_home);
if (checkRequirements()) {
onAllRequirementsMet();
}
setVisibilityOfPaymentMenu();
} catch (Exception e) {
Sentry.captureException(e);
}

setVisibilityOfPaymentMenu();
}

private void setVisibilityOfPaymentMenu() {
Expand Down Expand Up @@ -508,6 +512,7 @@ public void ShowEnrolmentOfficerDialog() {
//ShowDialogTex();
}
} catch (JSONException e) {
Sentry.captureException(e);
e.printStackTrace();
}
})
Expand Down Expand Up @@ -567,6 +572,7 @@ public void ShowDialogTex2() {
ConfirmDialogPage((f.getName()));
}
} catch (Exception e) {
Sentry.captureException(e);
e.getMessage();
}
})
Expand Down
Loading