18
18
import android .util .Log ;
19
19
import android .view .LayoutInflater ;
20
20
import android .view .View ;
21
- import android .widget .Button ;
22
- import android .widget .EditText ;
23
21
import android .widget .ProgressBar ;
24
22
import android .widget .ScrollView ;
25
- import android .widget .TextView ;
26
23
import android .widget .Toast ;
27
24
28
25
import androidx .annotation .NonNull ;
47
44
import com .downloader .PRDownloaderConfig ;
48
45
import com .downloader .Status ;
49
46
import com .google .android .material .bottomsheet .BottomSheetBehavior ;
47
+ import com .google .android .material .button .MaterialButton ;
50
48
import com .google .android .material .snackbar .Snackbar ;
49
+ import com .google .android .material .textfield .TextInputEditText ;
51
50
import com .google .android .material .textfield .TextInputLayout ;
52
51
import com .google .android .material .textview .MaterialTextView ;
53
52
import com .google .firebase .auth .FirebaseAuth ;
@@ -90,19 +89,19 @@ public class MainActivity extends AppCompatActivity implements InternetConnectiv
90
89
@ BindView (R .id .mainLayout )
91
90
CoordinatorLayout mainLayout ;
92
91
@ BindView (R .id .user )
93
- EditText user ;
92
+ TextInputEditText user ;
94
93
@ BindView (R .id .pass )
95
- EditText pass ;
94
+ TextInputEditText pass ;
96
95
@ BindView (R .id .login_button )
97
- Button login ;
96
+ MaterialButton login ;
98
97
@ BindView (R .id .progress_bar )
99
98
ProgressBar progressBar ;
100
99
@ BindView (R .id .passordLayout )
101
100
TextInputLayout passLayout ;
102
101
@ BindView (R .id .bottomSheet_view )
103
102
ScrollView bottomSheetView ;
104
103
@ BindView (R .id .hello )
105
- TextView welcomeMessage ;
104
+ MaterialTextView welcomeMessage ;
106
105
@ BindView (R .id .manual )
107
106
MaterialTextView maual ;
108
107
@ BindView (R .id .manaul_layout )
@@ -185,8 +184,8 @@ protected void onCreate(Bundle savedInstanceState) {
185
184
editor .apply ();
186
185
187
186
login .setOnClickListener (view -> {
188
- String u = user .getText ().toString ().trim ();
189
- String p = pass .getText ().toString ().trim ();
187
+ String u = Objects . requireNonNull ( user .getText () ).toString ().trim ();
188
+ String p = Objects . requireNonNull ( pass .getText () ).toString ().trim ();
190
189
191
190
if (u .equals ("" ) || p .equals ("" )) {
192
191
Snackbar snackbar = Snackbar .make (mainLayout , "Enter your Details" , Snackbar .LENGTH_SHORT );
@@ -218,54 +217,63 @@ protected void onCreate(Bundle savedInstanceState) {
218
217
}
219
218
220
219
public void fetchDetails () {
221
- CollectionReference apiCollection = FirebaseFirestore .getInstance ().collection (DETAILS );
222
- apiCollection .addSnapshotListener ((queryDocumentSnapshots , e ) -> {
223
- if (queryDocumentSnapshots != null ) {
224
- for (DocumentChange documentChange : queryDocumentSnapshots .getDocumentChanges ()) {
225
- api = documentChange .getDocument ().getString (API );
226
- updated_version = Integer .parseInt (Objects .requireNonNull (documentChange .getDocument ().getString ("update_available" )));
227
- int check = Integer .parseInt (Objects .requireNonNull (documentChange .getDocument ().getString ("under_maintenance" )));
228
- fileSize = Long .parseLong (Objects .requireNonNull (documentChange .getDocument ().getString ("update_file_size" )));
229
- appLink = documentChange .getDocument ().getString ("appLink" );
230
- isQueried = true ;
231
- new_message = documentChange .getDocument ().getString ("what's_new" );
232
- updatedAppID = documentChange .getDocument ().getString ("download_id" );
233
- edit = apiUrl .edit ();
234
- edit .putString (API , api );
235
- edit .putInt ("CHECK" , check );
236
- edit .apply ();
237
-
238
- if (check == 1 ) {
239
- Intent intent = new Intent (MainActivity .this , UnderMaintenance .class );
240
- startActivity (intent );
241
- finish ();
242
- return ;
243
- }
244
- if (updated_version > current_version && current_version > 0 && Utils .isNetworkAvailable (MainActivity .this )) {
245
- downloadUpdatedApp (updatedAppID , this .new_message , appLink );
246
- } else {
247
- autoFill ();
248
- try {
249
- if (awolAppUpdateFile .exists () && Utils .isNetworkAvailable (MainActivity .this )) {
250
- if (awolAppUpdateFile .delete ()) {
251
- Log .d ("fileDeleted" , "True" );
252
- } else {
253
- Log .d ("fileDeleted" , "False" );
220
+ try {
221
+ CollectionReference apiCollection = FirebaseFirestore .getInstance ().collection (DETAILS );
222
+ apiCollection .addSnapshotListener ((queryDocumentSnapshots , e ) -> {
223
+ if (queryDocumentSnapshots != null ) {
224
+ for (DocumentChange documentChange : queryDocumentSnapshots .getDocumentChanges ()) {
225
+ api = documentChange .getDocument ().getString (API );
226
+ updated_version = Integer .parseInt (Objects .requireNonNull (documentChange .getDocument ().getString ("update_available" )));
227
+ int check = Integer .parseInt (Objects .requireNonNull (documentChange .getDocument ().getString ("under_maintenance" )));
228
+ fileSize = Long .parseLong (Objects .requireNonNull (documentChange .getDocument ().getString ("update_file_size" )));
229
+ appLink = documentChange .getDocument ().getString ("appLink" );
230
+ isQueried = true ;
231
+ new_message = documentChange .getDocument ().getString ("what's_new" );
232
+ updatedAppID = documentChange .getDocument ().getString ("download_id" );
233
+ edit = apiUrl .edit ();
234
+ edit .putString (API , api );
235
+ edit .putInt ("CHECK" , check );
236
+ edit .apply ();
237
+
238
+ if (check == 1 ) {
239
+ Intent intent = new Intent (MainActivity .this , UnderMaintenance .class );
240
+ startActivity (intent );
241
+ finish ();
242
+ return ;
243
+ }
244
+ if (updated_version > current_version && current_version > 0 && Utils .isNetworkAvailable (MainActivity .this )) {
245
+ downloadUpdatedApp (updatedAppID , this .new_message , appLink );
246
+ } else {
247
+ autoFill ();
248
+ try {
249
+ if (awolAppUpdateFile .exists () && Utils .isNetworkAvailable (MainActivity .this )) {
250
+ if (awolAppUpdateFile .delete ()) {
251
+ Log .d ("fileDeleted" , "True" );
252
+ } else {
253
+ Log .d ("fileDeleted" , "False" );
254
+ }
254
255
}
256
+ } catch (Exception e1 ) {
257
+ Log .d ("fileDeleted" , "False" );
255
258
}
256
- } catch (Exception e1 ) {
257
- Log .d ("fileDeleted" , "False" );
258
259
}
259
- }
260
260
261
+ }
261
262
}
262
- }
263
- });
263
+ });
264
+ } catch (Exception e ) {
265
+
266
+ Snackbar snackbar = Snackbar .make (mainLayout , "Invalid firebase response" , Snackbar .LENGTH_SHORT );
267
+ snackbar .show ();
268
+ }
264
269
}
265
270
266
271
@ Override
267
272
protected void onResume () {
268
273
super .onResume ();
274
+ if (mAuth == null ) {
275
+ mAuth = FirebaseAuth .getInstance ();
276
+ }
269
277
if (mAuth .getCurrentUser () != null ) {
270
278
fetchDetails ();
271
279
} else {
@@ -319,7 +327,7 @@ private void getData(final String... param) {
319
327
} else if (response .equals ("390" )) {
320
328
//Attendance not present
321
329
Intent intent = new Intent (MainActivity .this , AttendanceActivity .class );
322
- intent .putExtra (REGISTRATION_NUMBER , user .getText ().toString ());
330
+ intent .putExtra (REGISTRATION_NUMBER , Objects . requireNonNull ( user .getText () ).toString ());
323
331
intent .putExtra (NO_ATTENDANCE , true );
324
332
intent .putExtra (LOGIN , true );
325
333
intent .putExtra (API , api );
@@ -343,7 +351,7 @@ private void getData(final String... param) {
343
351
Intent intent = new Intent (MainActivity .this , AttendanceActivity .class );
344
352
response += "kkk" + param [1 ];
345
353
intent .putExtra (RESULTS , response );
346
- intent .putExtra (REGISTRATION_NUMBER , user .getText ().toString ());
354
+ intent .putExtra (REGISTRATION_NUMBER , Objects . requireNonNull ( user .getText () ).toString ());
347
355
intent .putExtra (LOGIN , true );
348
356
intent .putExtra (STUDENT_NAME , studentName );
349
357
intent .putExtra (API , api );
@@ -741,7 +749,7 @@ public void FileDownloader(String fileID, String new_message, String appLink) {
741
749
.setOnPauseListener (() -> Toast .makeText (MainActivity .this , "Download Paused" , Toast .LENGTH_SHORT ).show ())
742
750
.setOnCancelListener (() -> Toast .makeText (MainActivity .this , "Download Cancelled" , Toast .LENGTH_SHORT ).show ())
743
751
.setOnProgressListener (progress -> {
744
- long progressPercent = progress .currentBytes * 100 / fileSize ;
752
+ long progressPercent = progress .currentBytes * 100 / progress . totalBytes ;
745
753
update .setText ((int ) progressPercent + "%" );
746
754
update_out_of_100 .setText ((int ) progressPercent + "/100" );
747
755
progressBar .setProgress ((int ) progressPercent );
0 commit comments