|
71 | 71 | import org.json.JSONArray; |
72 | 72 | import org.json.JSONException; |
73 | 73 | import org.json.JSONObject; |
| 74 | +import org.openimis.imispolicies.network.exception.HttpException; |
74 | 75 | import org.openimis.imispolicies.network.exception.UserNotAuthenticatedException; |
75 | 76 | import org.openimis.imispolicies.tools.LanguageManager; |
76 | 77 | import org.openimis.imispolicies.tools.Log; |
|
88 | 89 | import java.io.OutputStream; |
89 | 90 | import java.lang.ref.WeakReference; |
90 | 91 |
|
| 92 | +import io.sentry.Sentry; |
| 93 | + |
91 | 94 | public class MainActivity extends AppCompatActivity |
92 | 95 | implements NavigationView.OnNavigationItemSelectedListener { |
93 | 96 |
|
@@ -161,6 +164,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
161 | 164 | if (f.exists() || f.createNewFile()) |
162 | 165 | new FileOutputStream(f).write(bytes); |
163 | 166 | } catch (IOException e) { |
| 167 | + Sentry.captureException(e); |
164 | 168 | e.printStackTrace(); |
165 | 169 | } |
166 | 170 | ShowDialogTex2(); |
@@ -230,100 +234,100 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis |
230 | 234 | protected void onCreate(Bundle savedInstanceState) { |
231 | 235 | global = (Global) getApplicationContext(); |
232 | 236 | super.onCreate(savedInstanceState); |
233 | | - instance = this; |
234 | | - setContentView(R.layout.activity_main); |
235 | | - SQLHandler sqlHandler = new SQLHandler(this); |
236 | | - sqlHandler.isPrivate = true; |
237 | | - //Set the Image folder path |
238 | | - global.setImageFolder(global.getSubdirectory("Images")); |
239 | | - //Check if database exists |
240 | | - File database = global.getDatabasePath(SQLHandler.DBNAME); |
241 | | - if (!database.exists()) { |
242 | | - sqlHandler.getReadableDatabase(); |
243 | | - if (copyDatabase(this)) { |
244 | | - Toast.makeText(this, "Copy database success", Toast.LENGTH_SHORT).show(); |
245 | | - } else { |
246 | | - Toast.makeText(this, "Copy database failed", Toast.LENGTH_SHORT).show(); |
247 | | - return; |
248 | | - } |
249 | | - } else |
250 | | - sqlHandler.getReadableDatabase(); |
251 | | - |
252 | | - //Create image folder |
253 | | - createImageFolder(); |
254 | | - |
255 | | - Toolbar toolbar = findViewById(R.id.toolbar); |
256 | | - setSupportActionBar(toolbar); |
257 | | - |
258 | | - FloatingActionButton fab = findViewById(R.id.fab); |
259 | | - fab.setOnClickListener(view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) |
260 | | - .setAction("Action", null).show()); |
261 | | - |
262 | | - DrawerLayout drawer = findViewById(R.id.drawer_layout); |
263 | | - ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( |
264 | | - this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); |
265 | | - //noinspection deprecation |
266 | | - drawer.setDrawerListener(toggle); |
267 | | - toggle.syncState(); |
268 | | - |
269 | | - navigationView = findViewById(R.id.nav_view); |
| 237 | + try { |
| 238 | + instance = this; |
| 239 | + setContentView(R.layout.activity_main); |
| 240 | + SQLHandler sqlHandler = new SQLHandler(this); |
| 241 | + sqlHandler.isPrivate = true; |
| 242 | + //Set the Image folder path |
| 243 | + global.setImageFolder(global.getSubdirectory("Images")); |
| 244 | + //Check if database exists |
| 245 | + File database = global.getDatabasePath(SQLHandler.DBNAME); |
| 246 | + if (!database.exists()) { |
| 247 | + sqlHandler.getReadableDatabase(); |
| 248 | + if (copyDatabase(this)) { |
| 249 | + Toast.makeText(this, "Copy database success", Toast.LENGTH_SHORT).show(); |
| 250 | + } else { |
| 251 | + Toast.makeText(this, "Copy database failed", Toast.LENGTH_SHORT).show(); |
| 252 | + return; |
| 253 | + } |
| 254 | + } else |
| 255 | + sqlHandler.getReadableDatabase(); |
| 256 | + |
| 257 | + //Create image folder |
| 258 | + createImageFolder(); |
| 259 | + |
| 260 | + Toolbar toolbar = findViewById(R.id.toolbar); |
| 261 | + setSupportActionBar(toolbar); |
| 262 | + |
| 263 | + FloatingActionButton fab = findViewById(R.id.fab); |
| 264 | + fab.setOnClickListener(view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) |
| 265 | + .setAction("Action", null).show()); |
| 266 | + |
| 267 | + DrawerLayout drawer = findViewById(R.id.drawer_layout); |
| 268 | + ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( |
| 269 | + this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); |
| 270 | + //noinspection deprecation |
| 271 | + drawer.setDrawerListener(toggle); |
| 272 | + toggle.syncState(); |
| 273 | + |
| 274 | + navigationView = findViewById(R.id.nav_view); |
| 275 | + |
| 276 | + navigationView.setNavigationItemSelectedListener(this); |
| 277 | + wv = findViewById(R.id.webview); |
| 278 | + WebSettings settings = wv.getSettings(); |
| 279 | + wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); |
| 280 | + settings.setJavaScriptEnabled(true); |
| 281 | + //noinspection deprecation |
| 282 | + settings.setRenderPriority(WebSettings.RenderPriority.HIGH); |
| 283 | + settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); |
| 284 | + settings.setDomStorageEnabled(true); |
| 285 | + settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); |
| 286 | + settings.setUseWideViewPort(true); |
| 287 | + settings.setSaveFormData(true); |
| 288 | + settings.setAllowFileAccess(true); |
| 289 | + //noinspection deprecation |
| 290 | + settings.setEnableSmoothTransition(true); |
| 291 | + settings.setLoadWithOverviewMode(true); |
| 292 | + wv.addJavascriptInterface(new ClientAndroidInterface(this), "Android"); |
| 293 | + |
| 294 | + //Register for context acquire_menu |
| 295 | + registerForContextMenu(wv); |
270 | 296 |
|
271 | | - navigationView.setNavigationItemSelectedListener(this); |
272 | | - wv = findViewById(R.id.webview); |
273 | | - WebSettings settings = wv.getSettings(); |
274 | | - wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); |
275 | | - settings.setJavaScriptEnabled(true); |
276 | | - //noinspection deprecation |
277 | | - settings.setRenderPriority(WebSettings.RenderPriority.HIGH); |
278 | | - settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); |
279 | | - settings.setDomStorageEnabled(true); |
280 | | - settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); |
281 | | - settings.setUseWideViewPort(true); |
282 | | - settings.setSaveFormData(true); |
283 | | - settings.setAllowFileAccess(true); |
284 | | - //noinspection deprecation |
285 | | - settings.setEnableSmoothTransition(true); |
286 | | - settings.setLoadWithOverviewMode(true); |
287 | | - wv.addJavascriptInterface(new ClientAndroidInterface(this), "Android"); |
288 | | - |
289 | | - //Register for context acquire_menu |
290 | | - registerForContextMenu(wv); |
291 | | - |
292 | | - wv.loadUrl("file:///android_asset/pages/Home.html"); |
293 | | - wv.setWebViewClient(new MyWebViewClient(MainActivity.this)); |
294 | | - |
295 | | - wv.setWebChromeClient(new WebChromeClient() { |
296 | | - @Override |
297 | | - public void onReceivedTitle(WebView view, String title) { |
298 | | - super.onReceivedTitle(view, title); |
299 | | - //noinspection ConstantConditions |
300 | | - getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE); |
301 | | - getSupportActionBar().setSubtitle(title); |
| 297 | + wv.loadUrl("file:///android_asset/pages/Home.html"); |
| 298 | + wv.setWebViewClient(new MyWebViewClient(MainActivity.this)); |
| 299 | + |
| 300 | + wv.setWebChromeClient(new WebChromeClient() { |
| 301 | + @Override |
| 302 | + public void onReceivedTitle(WebView view, String title) { |
| 303 | + super.onReceivedTitle(view, title); |
| 304 | + //noinspection ConstantConditions |
| 305 | + getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE); |
| 306 | + getSupportActionBar().setSubtitle(title); |
| 307 | + } |
| 308 | + }); |
| 309 | + NavigationView navigationView = findViewById(R.id.nav_view); |
| 310 | + View headerview = navigationView.getHeaderView(0); |
| 311 | + Login = headerview.findViewById(R.id.tvLogin); |
| 312 | + OfficerName = headerview.findViewById(R.id.tvOfficerName); |
| 313 | + |
| 314 | + Login.setOnClickListener(v -> { |
| 315 | + wv.loadUrl("file:///android_asset/pages/Login.html?s=3"); |
| 316 | + drawer.closeDrawer(GravityCompat.START); |
| 317 | + SetLoggedIn(); |
| 318 | + }); |
| 319 | + ca = new ClientAndroidInterface(this); |
| 320 | + if (ca.isMasterDataAvailable() > 0) { |
| 321 | + loadLanguages(); |
302 | 322 | } |
303 | | - }); |
304 | | - NavigationView navigationView = findViewById(R.id.nav_view); |
305 | | - View headerview = navigationView.getHeaderView(0); |
306 | | - Login = headerview.findViewById(R.id.tvLogin); |
307 | | - OfficerName = headerview.findViewById(R.id.tvOfficerName); |
308 | | - |
309 | | - Login.setOnClickListener(v -> { |
310 | | - wv.loadUrl("file:///android_asset/pages/Login.html?s=3"); |
311 | | - drawer.closeDrawer(GravityCompat.START); |
312 | | - SetLoggedIn(); |
313 | | - }); |
314 | | - ca = new ClientAndroidInterface(this); |
315 | | - if (ca.isMasterDataAvailable() > 0) { |
316 | | - loadLanguages(); |
317 | | - } |
318 | | - |
319 | | - |
320 | | - navigationView.setCheckedItem(R.id.nav_home); |
321 | | - |
322 | | - if (checkRequirements()) { |
323 | | - onAllRequirementsMet(); |
| 323 | + navigationView.setCheckedItem(R.id.nav_home); |
| 324 | + if (checkRequirements()) { |
| 325 | + onAllRequirementsMet(); |
| 326 | + } |
| 327 | + setVisibilityOfPaymentMenu(); |
| 328 | + } catch (Exception e) { |
| 329 | + Sentry.captureException(e); |
324 | 330 | } |
325 | | - |
326 | | - setVisibilityOfPaymentMenu(); |
327 | 331 | } |
328 | 332 |
|
329 | 333 | private void setVisibilityOfPaymentMenu() { |
@@ -508,6 +512,7 @@ public void ShowEnrolmentOfficerDialog() { |
508 | 512 | //ShowDialogTex(); |
509 | 513 | } |
510 | 514 | } catch (JSONException e) { |
| 515 | + Sentry.captureException(e); |
511 | 516 | e.printStackTrace(); |
512 | 517 | } |
513 | 518 | }) |
@@ -567,6 +572,7 @@ public void ShowDialogTex2() { |
567 | 572 | ConfirmDialogPage((f.getName())); |
568 | 573 | } |
569 | 574 | } catch (Exception e) { |
| 575 | + Sentry.captureException(e); |
570 | 576 | e.getMessage(); |
571 | 577 | } |
572 | 578 | }) |
|
0 commit comments