7171import org .json .JSONArray ;
7272import org .json .JSONException ;
7373import org .json .JSONObject ;
74- import org .openimis .imispolicies .network .exception .HttpException ;
7574import org .openimis .imispolicies .network .exception .UserNotAuthenticatedException ;
7675import org .openimis .imispolicies .tools .LanguageManager ;
7776import org .openimis .imispolicies .tools .Log ;
8988import java .io .OutputStream ;
9089import java .lang .ref .WeakReference ;
9190
92- import io .sentry .Sentry ;
93-
9491public class MainActivity extends AppCompatActivity
9592 implements NavigationView .OnNavigationItemSelectedListener {
9693
@@ -164,7 +161,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
164161 if (f .exists () || f .createNewFile ())
165162 new FileOutputStream (f ).write (bytes );
166163 } catch (IOException e ) {
167- Sentry .captureException (e );
168164 e .printStackTrace ();
169165 }
170166 ShowDialogTex2 ();
@@ -234,100 +230,101 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
234230 protected void onCreate (Bundle savedInstanceState ) {
235231 global = (Global ) getApplicationContext ();
236232 super .onCreate (savedInstanceState );
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 );
296-
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 ();
233+ new LanguageManager (this ).restoreLanguage (false );
234+ instance = this ;
235+ setContentView (R .layout .activity_main );
236+ SQLHandler sqlHandler = new SQLHandler (this );
237+ sqlHandler .isPrivate = true ;
238+ //Set the Image folder path
239+ global .setImageFolder (global .getSubdirectory ("Images" ));
240+ //Check if database exists
241+ File database = global .getDatabasePath (SQLHandler .DBNAME );
242+ if (!database .exists ()) {
243+ sqlHandler .getReadableDatabase ();
244+ if (copyDatabase (this )) {
245+ Toast .makeText (this , "Copy database success" , Toast .LENGTH_SHORT ).show ();
246+ } else {
247+ Toast .makeText (this , "Copy database failed" , Toast .LENGTH_SHORT ).show ();
248+ return ;
322249 }
323- navigationView .setCheckedItem (R .id .nav_home );
324- if (checkRequirements ()) {
325- onAllRequirementsMet ();
250+ } else
251+ sqlHandler .getReadableDatabase ();
252+
253+ //Create image folder
254+ createImageFolder ();
255+
256+ Toolbar toolbar = findViewById (R .id .toolbar );
257+ setSupportActionBar (toolbar );
258+
259+ FloatingActionButton fab = findViewById (R .id .fab );
260+ fab .setOnClickListener (view -> Snackbar .make (view , "Replace with your own action" , Snackbar .LENGTH_LONG )
261+ .setAction ("Action" , null ).show ());
262+
263+ DrawerLayout drawer = findViewById (R .id .drawer_layout );
264+ ActionBarDrawerToggle toggle = new ActionBarDrawerToggle (
265+ this , drawer , toolbar , R .string .navigation_drawer_open , R .string .navigation_drawer_close );
266+ //noinspection deprecation
267+ drawer .setDrawerListener (toggle );
268+ toggle .syncState ();
269+
270+ navigationView = findViewById (R .id .nav_view );
271+
272+ navigationView .setNavigationItemSelectedListener (this );
273+ wv = findViewById (R .id .webview );
274+ WebSettings settings = wv .getSettings ();
275+ wv .setScrollBarStyle (View .SCROLLBARS_INSIDE_OVERLAY );
276+ settings .setJavaScriptEnabled (true );
277+ //noinspection deprecation
278+ settings .setRenderPriority (WebSettings .RenderPriority .HIGH );
279+ settings .setCacheMode (WebSettings .LOAD_CACHE_ELSE_NETWORK );
280+ settings .setDomStorageEnabled (true );
281+ settings .setLayoutAlgorithm (WebSettings .LayoutAlgorithm .SINGLE_COLUMN );
282+ settings .setUseWideViewPort (true );
283+ settings .setSaveFormData (true );
284+ settings .setAllowFileAccess (true );
285+ //noinspection deprecation
286+ settings .setEnableSmoothTransition (true );
287+ settings .setLoadWithOverviewMode (true );
288+ wv .addJavascriptInterface (new ClientAndroidInterface (this ), "Android" );
289+
290+ //Register for context acquire_menu
291+ registerForContextMenu (wv );
292+
293+ wv .loadUrl ("file:///android_asset/pages/Home.html" );
294+ wv .setWebViewClient (new MyWebViewClient (MainActivity .this ));
295+
296+ wv .setWebChromeClient (new WebChromeClient () {
297+ @ Override
298+ public void onReceivedTitle (WebView view , String title ) {
299+ super .onReceivedTitle (view , title );
300+ //noinspection ConstantConditions
301+ getSupportActionBar ().setDisplayOptions (ActionBar .DISPLAY_SHOW_TITLE );
302+ getSupportActionBar ().setSubtitle (title );
326303 }
327- setVisibilityOfPaymentMenu ();
328- } catch (Exception e ) {
329- Sentry .captureException (e );
304+ });
305+ NavigationView navigationView = findViewById (R .id .nav_view );
306+ View headerview = navigationView .getHeaderView (0 );
307+ Login = headerview .findViewById (R .id .tvLogin );
308+ OfficerName = headerview .findViewById (R .id .tvOfficerName );
309+
310+ Login .setOnClickListener (v -> {
311+ wv .loadUrl ("file:///android_asset/pages/Login.html?s=3" );
312+ drawer .closeDrawer (GravityCompat .START );
313+ SetLoggedIn ();
314+ });
315+ ca = new ClientAndroidInterface (this );
316+ if (ca .isMasterDataAvailable () > 0 ) {
317+ loadLanguages ();
330318 }
319+
320+
321+ navigationView .setCheckedItem (R .id .nav_home );
322+
323+ if (checkRequirements ()) {
324+ onAllRequirementsMet ();
325+ }
326+
327+ setVisibilityOfPaymentMenu ();
331328 }
332329
333330 private void setVisibilityOfPaymentMenu () {
@@ -512,7 +509,6 @@ public void ShowEnrolmentOfficerDialog() {
512509 //ShowDialogTex();
513510 }
514511 } catch (JSONException e ) {
515- Sentry .captureException (e );
516512 e .printStackTrace ();
517513 }
518514 })
@@ -572,7 +568,6 @@ public void ShowDialogTex2() {
572568 ConfirmDialogPage ((f .getName ()));
573569 }
574570 } catch (Exception e ) {
575- Sentry .captureException (e );
576571 e .getMessage ();
577572 }
578573 })
@@ -723,10 +718,10 @@ public boolean onNavigationItemSelected(MenuItem item) {
723718 } else {
724719 wv .loadUrl ("file:///android_asset/pages/Login.html?s=4" );
725720 }
726- } else if (id == R .id .nav_feedback ) {
721+ }/* else if (id == R.id.nav_feedback) {
727722 Intent intent = new Intent(this, FeedbackList.class);
728723 startActivity(intent);
729- } else if (id == R .id .nav_sync ) {
724+ }*/ else if (id == R .id .nav_sync ) {
730725 wv .loadUrl ("file:///android_asset/pages/Sync.html" );
731726 } else if (id == R .id .nav_about ) {
732727 wv .loadUrl ("file:///android_asset/pages/About.html" );
@@ -824,7 +819,7 @@ protected void onPostExecute(Throwable exception) {
824819 return ;
825820 }
826821 if (exception instanceof UserNotAuthenticatedException ) {
827- new ClientAndroidInterface (context ).forceLoginDialogBox (() -> startDownloading ( ));
822+ new ClientAndroidInterface (context ).forceLoginDialogBox (() -> restart ( context ));
828823 return ;
829824 }
830825 restart (context );
@@ -835,10 +830,6 @@ private void restart(@NonNull Activity activity) {
835830 activity .startActivity (refresh );
836831 activity .finish ();
837832 }
838-
839- private void startDownloading (){
840- new MasterDataAsync (activity .get ()).execute ();
841- }
842833 }
843834
844835 public static class MasterDataLocalAsync extends AsyncTask <String , Void , Void > {
@@ -867,7 +858,7 @@ protected Void doInBackground(String... buffers) {
867858 }
868859 ClientAndroidInterface ca = new ClientAndroidInterface (context );
869860 try {
870- ca .importMasterData (buffers [0 ]);
861+ ca .importMasterData (new JSONObject ( buffers [0 ]) );
871862 } catch (JSONException | UserException e ) {
872863 e .printStackTrace ();
873864 }
0 commit comments