Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 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", "https://3afee255dd9f4b96b0d1b207b1bb5f1b@glitchtip.s2.openimis.org/3"
}
buildTypes {
release {
Expand Down Expand Up @@ -192,8 +193,8 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

packagingOptions {
Expand Down Expand Up @@ -245,4 +246,5 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
testImplementation 'junit:junit:4.13.2'
implementation 'io.sentry:sentry-android:4.2.0'
}
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 @@ -778,6 +780,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 @@ -1037,6 +1040,7 @@ else if (ExceedThreshold == 0)
);
}
} catch (NumberFormatException | UserException e) {
Sentry.captureException(e);
e.printStackTrace();
throw new Exception(e.getMessage());
}
Expand Down Expand Up @@ -1691,8 +1695,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 @@ -1883,8 +1889,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 @@ -3145,6 +3153,7 @@ private 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 @@ -3571,8 +3580,8 @@ protected void onPostExecute(Boolean aBoolean) {
}

private void DeleteUploadedData(final int FamilyId, ArrayList<String> FamilyIDs, int CallerId) {
if (FamilyIDs.size() == 0) {
FamilyIDs = new ArrayList<>() {{
if (FamilyIDs.isEmpty()) {
FamilyIDs = new ArrayList<String>() {{
add(String.valueOf(FamilyId));
}};
}
Expand Down Expand Up @@ -3663,6 +3672,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 @@ -3901,6 +3911,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 @@ -3923,6 +3934,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 @@ -3937,6 +3949,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 @@ -4054,6 +4067,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 @@ -4561,6 +4575,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