11package org .openimis .imispolicies ;
22
3- import android .app .AlertDialog ;
43import android .app .ProgressDialog ;
54import android .content .Intent ;
65import android .os .Bundle ;
98import android .view .MenuItem ;
109import android .view .View ;
1110import android .widget .ProgressBar ;
12- import android .widget .TextView ;
1311
14- import androidx .activity .EdgeToEdge ;
1512import androidx .annotation .NonNull ;
1613import androidx .appcompat .app .AppCompatActivity ;
17- import androidx .core .graphics .Insets ;
18- import androidx .core .view .ViewCompat ;
19- import androidx .core .view .WindowInsetsCompat ;
2014
2115import com .google .android .material .button .MaterialButton ;
2216import com .google .android .material .textfield .TextInputEditText ;
2317import com .google .android .material .textfield .TextInputLayout ;
2418
2519import org .openimis .imispolicies .util .AndroidUtils ;
2620
21+
2722public class LoginActivity extends AppCompatActivity {
2823
2924 TextInputLayout layoutLoginName , layoutPassword ;
@@ -32,8 +27,6 @@ public class LoginActivity extends AppCompatActivity {
3227 String officerCode ;
3328 ClientAndroidInterface ca ;
3429 int page ;
35- private ProgressDialog progressDialog ;
36- ProgressBar progressBar ;
3730
3831 @ Override
3932 protected void onCreate (Bundle savedInstanceState ) {
@@ -44,60 +37,11 @@ protected void onCreate(Bundle savedInstanceState) {
4437 getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
4538 }
4639 ca = new ClientAndroidInterface (this );
47- progressDialog = new ProgressDialog (this );
4840 officerCode = ca .getOfficerCode ();
4941 page = getIntent ().getIntExtra ("Page" ,0 );
5042 initViews ();
5143 canSave ();
5244 setupListenners ();
53-
54- btnLogin .setOnClickListener (new View .OnClickListener () {
55- @ Override
56- public void onClick (View view ) {
57- String username = txtLoginName .getText ().toString ();
58- String password = txtPassword .getText ().toString ();
59-
60- boolean hasInternet = ca .CheckInternetAvailable ();
61- if (!hasInternet ){
62- ca .ShowDialog (getResources ().getString (R .string .NoInternet ));
63- } else {
64- progressBar .setVisibility (View .VISIBLE );
65- boolean loggedIn = ca .LoginJI (username , password );
66- if (loggedIn ){
67- if (page == 0 ){
68- finish ();
69- } else if (page == 1 ) {
70- progressBar .setVisibility (View .GONE );
71- Intent intent = new Intent (LoginActivity .this , SearchActivity .class );
72- startActivity (intent );
73- finish ();
74- } else if (page == 2 ) {
75- progressBar .setVisibility (View .GONE );
76- Intent intent = new Intent (LoginActivity .this , Enrolment .class );
77- startActivity (intent );
78- finish ();
79- } else if (page == 4 ) {
80- progressBar .setVisibility (View .GONE );
81- ca .launchActivity ("Reports" );
82- finish ();
83- } else if (page == 5 ) {
84- progressBar .setVisibility (View .GONE );
85- ca .launchActivity ("Enquire" );
86- finish ();
87- } else {
88- progressBar .setVisibility (View .GONE );
89- Intent intent = new Intent (LoginActivity .this , MainActivity .class );
90- startActivity (intent );
91- finish ();
92- }
93- } else {
94- progressDialog .dismiss ();
95- ca .ShowDialog (getResources ().getString (R .string .LoginFail ));
96- }
97- }
98-
99- }
100- });
10145 }
10246
10347 @ Override
@@ -115,7 +59,6 @@ private void initViews(){
11559 btnLogin = findViewById (R .id .btnLogin );
11660 txtLoginName = findViewById (R .id .txtLoginName );
11761 txtPassword = findViewById (R .id .txtPassword );
118- progressBar = findViewById (R .id .loginProgressBar );
11962
12063 txtLoginName .setText (officerCode );
12164 }
@@ -164,5 +107,59 @@ public void afterTextChanged(Editable editable) {
164107
165108 }
166109 });
110+
111+ btnLogin .setOnClickListener (v -> {
112+ boolean hasInternet = ca .CheckInternetAvailable ();
113+ if (!hasInternet ){
114+ AndroidUtils .showDialog (LoginActivity .this , getResources ().getString (R .string .NoInternet ));
115+ } else {
116+ try {
117+ String username = txtLoginName .getText ().toString ();
118+ String password = txtPassword .getText ().toString ();
119+ ProgressBar loginProgressBar = findViewById (R .id .loginProgressBar );
120+ loginProgressBar .setVisibility (View .VISIBLE );
121+ new Thread (() ->{
122+ boolean loggedIn = ca .LoginJI (username , password );
123+ runOnUiThread (() -> {
124+ if (loggedIn ) {
125+ if (page == 0 ) {
126+ finish ();
127+ } else if (page == 1 ) {
128+ loginProgressBar .setVisibility (View .GONE );
129+ Intent intent = new Intent (LoginActivity .this , SearchActivity .class );
130+ startActivity (intent );
131+ finish ();
132+ } else if (page == 2 ) {
133+ loginProgressBar .setVisibility (View .GONE );
134+ Intent intent = new Intent (LoginActivity .this , Enrolment .class );
135+ startActivity (intent );
136+ finish ();
137+ } else if (page == 4 ) {
138+ loginProgressBar .setVisibility (View .GONE );
139+ ca .launchActivity ("Reports" );
140+ finish ();
141+ } else if (page == 5 ) {
142+ loginProgressBar .setVisibility (View .GONE );
143+ ca .launchActivity ("Enquire" );
144+ finish ();
145+ } else {
146+ loginProgressBar .setVisibility (View .GONE );
147+ Intent intent = new Intent (LoginActivity .this , MainActivity .class );
148+ startActivity (intent );
149+ finish ();
150+ }
151+ } else {
152+ loginProgressBar .setVisibility (View .GONE );
153+ AndroidUtils .showDialog (LoginActivity .this , getResources ().getString (R .string .LoginFail ));
154+ }
155+ });
156+ }).start ();
157+
158+
159+ } catch (Exception e ) {
160+ throw new RuntimeException (e );
161+ }
162+ }
163+ });
167164 }
168165}
0 commit comments