From aa16c7ff17e22eff8e082eba48ad1f09f5acfde4 Mon Sep 17 00:00:00 2001 From: Nishon Tandukar Date: Tue, 15 Oct 2019 12:15:43 +0545 Subject: [PATCH] Removes printstacktrace usage (#403) --- .../naxa/common/FieldSightUserSession.java | 6 +- .../naxa/common/SharedPreferenceUtils.java | 6 +- .../naxa/common/utilities/ZipUtils.java | 4 +- .../FieldSightNotificationLocalSource.java | 4 +- .../EducationalMaterialActivity.java | 3 +- .../FieldSightFirebaseMessagingService.java | 4 +- .../data/local/FieldsightFormDetailsv3.java | 6 +- .../ui/EducationalMaterialListActivity.java | 2 +- .../data/GeneralFormLocalSource.java | 2 +- .../naxa/helpers/FSInstancesDao.java | 2 +- .../fieldsight/naxa/login/APIErrorUtils.java | 26 ------- .../naxa/login/BaseLoginActivity.java | 4 +- .../naxa/onboarding/DownloadActivity.java | 2 +- .../naxa/onboarding/DownloadModelImpl.java | 2 +- .../onboarding/XMLFormDownloadService.java | 2 +- .../fieldsight/naxa/profile/UserActivity.java | 3 +- .../naxa/report/ReportActivity.java | 3 +- .../data/ScheduledFormsLocalSource.java | 5 +- .../naxa/site/CreateSiteActivity.java | 2 +- .../naxa/site/SiteListFragment.java | 4 +- .../naxa/submissions/PaginationAdapter.java | 4 +- .../PreviousSubmissionListActivity.java | 4 +- .../substages/data/SubStageLocalSource.java | 3 +- .../naxa/survey/SurveyFormsActivity.java | 2 +- .../naxa/sync/ContentDownloadActivity.java | 10 +-- .../naxa/sync/DownloadViewModel.java | 2 +- .../fieldsight/naxa/sync/SyncRepository.java | 3 +- .../naxa/v3/ProjectListActivityV3.java | 51 ++++++------ .../naxa/v3/adapter/SyncAdapterv3.java | 13 ++-- .../v3/forms/FieldSightFormDownloader.java | 4 +- .../naxa/v3/network/SyncActivity.java | 12 +-- .../naxa/v3/network/SyncServiceV3.java | 7 +- .../odk/collect/android/TestingActivity.java | 3 +- .../android/utilities/DateTimeUtils.java | 21 +++-- .../collect/android/utilities/FileUtils.java | 77 +++++++++++++------ 35 files changed, 168 insertions(+), 140 deletions(-) delete mode 100644 collect_app/src/main/java/org/fieldsight/naxa/login/APIErrorUtils.java diff --git a/collect_app/src/main/java/org/fieldsight/naxa/common/FieldSightUserSession.java b/collect_app/src/main/java/org/fieldsight/naxa/common/FieldSightUserSession.java index 3e5aa7551..adb82d37c 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/common/FieldSightUserSession.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/common/FieldSightUserSession.java @@ -139,7 +139,7 @@ protected Void doInBackground(Void... voids) { try { FirebaseInstanceId.getInstance().deleteInstanceId(); } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); } return null; } @@ -361,7 +361,7 @@ private static Long[] getAllFormsIds() { } } } catch (NumberFormatException e) { - e.printStackTrace();//should never happen + Timber.e(e);//should never happen } finally { if (results != null) { results.close(); @@ -387,7 +387,7 @@ private static Long[] getAllInstancedsIds() { } } } catch (NumberFormatException e) { - e.printStackTrace();//should never happen + Timber.e(e);//should never happen } finally { if (results != null) { results.close(); diff --git a/collect_app/src/main/java/org/fieldsight/naxa/common/SharedPreferenceUtils.java b/collect_app/src/main/java/org/fieldsight/naxa/common/SharedPreferenceUtils.java index d3ce8e8a8..877d76489 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/common/SharedPreferenceUtils.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/common/SharedPreferenceUtils.java @@ -6,6 +6,8 @@ import org.odk.collect.android.application.Collect; +import timber.log.Timber; + public class SharedPreferenceUtils { public static class PREF_KEY { @@ -80,7 +82,7 @@ public static String getFromPrefs(Context context, String key, String defaultVal try { return sharedPrefs.getString(key, defaultValue); } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); return defaultValue; } } @@ -91,7 +93,7 @@ public static Boolean getBooleanFromPrefs(Context context, String key, Boolean d try { return sharedPrefs.getBoolean(key, defaultValue); } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); return defaultValue; } } diff --git a/collect_app/src/main/java/org/fieldsight/naxa/common/utilities/ZipUtils.java b/collect_app/src/main/java/org/fieldsight/naxa/common/utilities/ZipUtils.java index 1d3c5a5a2..fc4d27c86 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/common/utilities/ZipUtils.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/common/utilities/ZipUtils.java @@ -10,6 +10,8 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import timber.log.Timber; + public class ZipUtils { /* * @@ -90,7 +92,7 @@ public boolean zipFileAtPath(String sourcePath, String toLocation) { listener.onComplete(); } } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); return false; } return true; diff --git a/collect_app/src/main/java/org/fieldsight/naxa/data/source/local/FieldSightNotificationLocalSource.java b/collect_app/src/main/java/org/fieldsight/naxa/data/source/local/FieldSightNotificationLocalSource.java index 4ae8d9f9a..c6a2e5365 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/data/source/local/FieldSightNotificationLocalSource.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/data/source/local/FieldSightNotificationLocalSource.java @@ -362,7 +362,7 @@ public FieldSightNotification parseNotificationData(JSONObject jsonObject) { siteIdentifier = siteData.getString("identifier"); } } catch (JSONException e) { - e.printStackTrace(); + Timber.e(e); } } @@ -377,7 +377,7 @@ public FieldSightNotification parseNotificationData(JSONObject jsonObject) { projectId = siteData.getString("id"); } } catch (JSONException e) { - e.printStackTrace(); + Timber.e(e); } } diff --git a/collect_app/src/main/java/org/fieldsight/naxa/educational/EducationalMaterialActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/educational/EducationalMaterialActivity.java index ed5eacb8b..93a10ed2a 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/educational/EducationalMaterialActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/educational/EducationalMaterialActivity.java @@ -41,6 +41,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; +import timber.log.Timber; import static org.fieldsight.naxa.common.Constant.EXTRA_MESSAGE; import static org.fieldsight.naxa.common.Constant.EXTRA_OBJECT; @@ -270,7 +271,7 @@ public void onSuccess(List dynamicFragments) { @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); if (e instanceof EmptyResultSetException) { ToastUtils.showLongToast("No education materials present for this form"); } else { diff --git a/collect_app/src/main/java/org/fieldsight/naxa/firebase/FieldSightFirebaseMessagingService.java b/collect_app/src/main/java/org/fieldsight/naxa/firebase/FieldSightFirebaseMessagingService.java index c6e5aa974..2231e4551 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/firebase/FieldSightFirebaseMessagingService.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/firebase/FieldSightFirebaseMessagingService.java @@ -196,7 +196,7 @@ private void parseNotificationData(Map notificationData) { siteIdentifier = siteData.getString("identifier"); } } catch (JSONException e) { - e.printStackTrace(); + Timber.e(e); } } @@ -211,7 +211,7 @@ private void parseNotificationData(Map notificationData) { projectId = siteData.getString("id"); } } catch (JSONException e) { - e.printStackTrace(); + Timber.e(e); } } diff --git a/collect_app/src/main/java/org/fieldsight/naxa/forms/data/local/FieldsightFormDetailsv3.java b/collect_app/src/main/java/org/fieldsight/naxa/forms/data/local/FieldsightFormDetailsv3.java index 194232041..829c2f9d3 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/forms/data/local/FieldsightFormDetailsv3.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/forms/data/local/FieldsightFormDetailsv3.java @@ -173,7 +173,7 @@ public static FieldsightFormDetailsv3 parseFromJSON(JSONObject jsonObject, Strin } fieldsightFormDetailsv3.setMetaAttributes(metaJSON.toString()); } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); } return fieldsightFormDetailsv3; } @@ -193,7 +193,7 @@ public static void getMetaJSON(String prefix, JSONObject fromJSON, JSONObject at atJSON.put(prefix + "_regions", fromJSON.optJSONArray("regions")); } } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); } } @@ -233,7 +233,7 @@ public static List fieldsightFormDetailsV3FromJSON(JSON } } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); } } return fieldsightFormDetailsNewArrayList; diff --git a/collect_app/src/main/java/org/fieldsight/naxa/forms/ui/EducationalMaterialListActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/forms/ui/EducationalMaterialListActivity.java index 519b9f081..274c533a5 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/forms/ui/EducationalMaterialListActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/forms/ui/EducationalMaterialListActivity.java @@ -190,7 +190,7 @@ public void onSuccess(List dynamicFragments) { @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); if (e instanceof EmptyResultSetException) { ToastUtils.showLongToast("No education materials present for this form"); } else { diff --git a/collect_app/src/main/java/org/fieldsight/naxa/generalforms/data/GeneralFormLocalSource.java b/collect_app/src/main/java/org/fieldsight/naxa/generalforms/data/GeneralFormLocalSource.java index 668bdcfc3..5fafc70da 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/generalforms/data/GeneralFormLocalSource.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/generalforms/data/GeneralFormLocalSource.java @@ -116,7 +116,7 @@ public void onSuccess(List generalFormAndSubmissions) @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); generalFormMediator.removeSource(source); } }); diff --git a/collect_app/src/main/java/org/fieldsight/naxa/helpers/FSInstancesDao.java b/collect_app/src/main/java/org/fieldsight/naxa/helpers/FSInstancesDao.java index 3098c53a6..bf3292407 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/helpers/FSInstancesDao.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/helpers/FSInstancesDao.java @@ -218,7 +218,7 @@ private String fixUploadUrl(String url) { url = generateSubmissionUrl(deployedFrom, siteId, fsFormId); } } catch (NullPointerException e) { - e.printStackTrace(); + Timber.e(e); Timber.e("Failed to fix url"); } return url; diff --git a/collect_app/src/main/java/org/fieldsight/naxa/login/APIErrorUtils.java b/collect_app/src/main/java/org/fieldsight/naxa/login/APIErrorUtils.java deleted file mode 100644 index 2a785ec1c..000000000 --- a/collect_app/src/main/java/org/fieldsight/naxa/login/APIErrorUtils.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.fieldsight.naxa.login; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.IOException; - -import retrofit2.HttpException; - -public class APIErrorUtils { - public static String getNonFieldError(HttpException responseBody) { - String errorMessage = "An unknown error occurred"; - - try { - String errorBody = responseBody.response().errorBody().string(); - JSONObject jsonObject = new JSONObject(errorBody); - errorMessage = String.valueOf(jsonObject.getJSONArray("non_field_errors").get(0)); - } catch (IOException | NullPointerException e) { - e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); - } - - return errorMessage; - } -} diff --git a/collect_app/src/main/java/org/fieldsight/naxa/login/BaseLoginActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/login/BaseLoginActivity.java index 21c541b23..92d03ab04 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/login/BaseLoginActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/login/BaseLoginActivity.java @@ -84,7 +84,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { handleSignInResult(task); } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); } } @@ -98,7 +98,7 @@ protected void handleSignInResult(@NonNull Task completedTa Timber.d("handleSignInResult: suthCode " + authCode); updateUI(account); } catch (ApiException e) { - e.printStackTrace(); + Timber.e(e); gmailLoginFailed(e.getMessage()); Log.w(TAG, "signInResult:failed code=" + e.getStatusCode()); updateUI(null); diff --git a/collect_app/src/main/java/org/fieldsight/naxa/onboarding/DownloadActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/onboarding/DownloadActivity.java index fefc58259..35202c9b1 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/onboarding/DownloadActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/onboarding/DownloadActivity.java @@ -241,7 +241,7 @@ public void onSuccess(List syncableItems) { @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); } }); diff --git a/collect_app/src/main/java/org/fieldsight/naxa/onboarding/DownloadModelImpl.java b/collect_app/src/main/java/org/fieldsight/naxa/onboarding/DownloadModelImpl.java index 970d752fe..2afb5e3c0 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/onboarding/DownloadModelImpl.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/onboarding/DownloadModelImpl.java @@ -92,7 +92,7 @@ public void onSuccess(Object o) { @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); SyncRepository.getInstance().setError(Constant.DownloadUID.GENERAL_FORMS); } }); diff --git a/collect_app/src/main/java/org/fieldsight/naxa/onboarding/XMLFormDownloadService.java b/collect_app/src/main/java/org/fieldsight/naxa/onboarding/XMLFormDownloadService.java index 334321ebb..8c92aa3da 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/onboarding/XMLFormDownloadService.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/onboarding/XMLFormDownloadService.java @@ -195,7 +195,7 @@ public void onNext(List projects) { @Override public void onError(Throwable e) { Timber.i("onError"); - e.printStackTrace(); + Timber.e(e); broadcastDownloadError(e.getMessage()); } diff --git a/collect_app/src/main/java/org/fieldsight/naxa/profile/UserActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/profile/UserActivity.java index 6f75f994f..cd40baa4b 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/profile/UserActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/profile/UserActivity.java @@ -37,6 +37,7 @@ import butterknife.ButterKnife; import butterknife.OnClick; import io.reactivex.observers.DisposableObserver; +import timber.log.Timber; public class UserActivity extends CollectAbstractActivity { @@ -315,7 +316,7 @@ public void onNext(User user) { @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); userProfileViewModel.setProgressBar(false); userProfileViewModel.setSyncLiveData(false); mUser.setSync(false); diff --git a/collect_app/src/main/java/org/fieldsight/naxa/report/ReportActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/report/ReportActivity.java index 79a10f304..34ab58e0e 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/report/ReportActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/report/ReportActivity.java @@ -44,6 +44,7 @@ import io.reactivex.observers.DisposableObserver; import io.reactivex.schedulers.Schedulers; import okhttp3.ResponseBody; +import timber.log.Timber; public class ReportActivity extends CollectAbstractActivity { @BindView(R.id.tv_device_id) @@ -170,7 +171,7 @@ public void onNext(ResponseBody response) { hideProgressDialog(); } } catch (IOException | JSONException e) { - e.printStackTrace(); + Timber.e(e); isSubmitting = false; hideProgressDialog(); Toast.makeText(getApplicationContext(), "Unknown error in sending report, Please try again", Toast.LENGTH_SHORT).show(); diff --git a/collect_app/src/main/java/org/fieldsight/naxa/scheduled/data/ScheduledFormsLocalSource.java b/collect_app/src/main/java/org/fieldsight/naxa/scheduled/data/ScheduledFormsLocalSource.java index fed65bcd8..a27b656af 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/scheduled/data/ScheduledFormsLocalSource.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/scheduled/data/ScheduledFormsLocalSource.java @@ -25,6 +25,7 @@ import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; import io.reactivex.schedulers.Schedulers; +import timber.log.Timber; import static org.fieldsight.naxa.common.Constant.FormDeploymentFrom.SITE; @@ -148,7 +149,7 @@ public void onSuccess(List generalFormAndSubmissions @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); generalFormMediator.removeSource(source); } }); @@ -213,7 +214,7 @@ public void onSuccess(List generalFormAndSubmissions @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); generalFormMediator.removeSource(source); } }); diff --git a/collect_app/src/main/java/org/fieldsight/naxa/site/CreateSiteActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/site/CreateSiteActivity.java index 18f2cf46c..adba265a8 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/site/CreateSiteActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/site/CreateSiteActivity.java @@ -908,7 +908,7 @@ public String getAnswerFormMetaAttrs(String submissionTag) { } } catch (JSONException e) { Timber.e(e); - e.printStackTrace(); + Timber.e(e); } } diff --git a/collect_app/src/main/java/org/fieldsight/naxa/site/SiteListFragment.java b/collect_app/src/main/java/org/fieldsight/naxa/site/SiteListFragment.java index 98c767430..e60be392f 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/site/SiteListFragment.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/site/SiteListFragment.java @@ -159,7 +159,7 @@ private TermsLabels getTermsAndLabels() { JSONObject tlJson = new JSONObject(loadedProject.getTerms_and_labels()); return TermsLabels.fromJSON(tlJson); } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); return null; } } else { @@ -511,7 +511,7 @@ public void onSuccess(List instanceIDs) { @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); Timber.e(e); String message; if (e instanceof RetrofitException && ((RetrofitException) e).getResponse().errorBody() == null) { diff --git a/collect_app/src/main/java/org/fieldsight/naxa/submissions/PaginationAdapter.java b/collect_app/src/main/java/org/fieldsight/naxa/submissions/PaginationAdapter.java index c22acc960..169749583 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/submissions/PaginationAdapter.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/submissions/PaginationAdapter.java @@ -18,6 +18,8 @@ import java.util.ArrayList; import java.util.List; +import timber.log.Timber; + public class PaginationAdapter extends RecyclerView.Adapter { @@ -114,7 +116,7 @@ private String formatSubmissionDateTime(String dateTime) { } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); msg = "Cannot load date time"; } diff --git a/collect_app/src/main/java/org/fieldsight/naxa/submissions/PreviousSubmissionListActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/submissions/PreviousSubmissionListActivity.java index 7f2d39a7c..55f6c1cf9 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/submissions/PreviousSubmissionListActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/submissions/PreviousSubmissionListActivity.java @@ -203,7 +203,7 @@ public void onNext(FormHistoryResponse response) { public void onError(Throwable e) { progressBar.setVisibility(View.GONE); ToastUtils.showLongToast(e.getMessage()); - e.printStackTrace(); + Timber.e(e); } @Override @@ -321,7 +321,7 @@ public void onNext(FormHistoryResponse response) { public void onError(Throwable e) { progressBar.setVisibility(View.GONE); ToastUtils.showLongToast(e.getMessage()); - e.printStackTrace(); + Timber.e(e); } @Override diff --git a/collect_app/src/main/java/org/fieldsight/naxa/substages/data/SubStageLocalSource.java b/collect_app/src/main/java/org/fieldsight/naxa/substages/data/SubStageLocalSource.java index 7e57147d3..30654753f 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/substages/data/SubStageLocalSource.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/substages/data/SubStageLocalSource.java @@ -27,6 +27,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; +import timber.log.Timber; import static org.fieldsight.naxa.common.Constant.FormDeploymentFrom.SITE; @@ -119,7 +120,7 @@ public void onSuccess(List subStageAndSubmissions) { @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); mediatorLiveData.removeSource(source); } }); diff --git a/collect_app/src/main/java/org/fieldsight/naxa/survey/SurveyFormsActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/survey/SurveyFormsActivity.java index 2651a3093..fb05b366d 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/survey/SurveyFormsActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/survey/SurveyFormsActivity.java @@ -173,7 +173,7 @@ protected void fillODKForm(String idString) { } } catch (NullPointerException | NumberFormatException e) { - e.printStackTrace(); + Timber.e(e); DialogFactory.createGenericErrorDialog(this, e.getMessage()).show(); Timber.e("Failed to load xml form %s", e.getMessage()); } catch (CursorIndexOutOfBoundsException e) { diff --git a/collect_app/src/main/java/org/fieldsight/naxa/sync/ContentDownloadActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/sync/ContentDownloadActivity.java index 98fefb2d7..1b19c23d5 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/sync/ContentDownloadActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/sync/ContentDownloadActivity.java @@ -113,7 +113,7 @@ public void onComplete() { @Override public void onError(Throwable e) { Timber.e("Insert failed on sync table reason: %s", e.getMessage()); - e.printStackTrace(); + Timber.e(e); } }); @@ -202,7 +202,7 @@ public void onChanged(@Nullable List downloadableItems) { viewModel.downloadOneItem(outOfSyncId); } catch (NullPointerException e) { - e.printStackTrace(); + Timber.e(e); } adapter.setOnItemClickListener(this); } @@ -326,7 +326,7 @@ public void onComplete() { @Override public void onError(Throwable e) { Timber.e("Update failed on sync table reason: %s", e.getMessage()); - e.printStackTrace(); + Timber.e(e); } }); break; @@ -366,7 +366,7 @@ public void onSuccess(List downloadableItems) { @Override public void onError(Throwable e) { Timber.e("Select failed on sync table reason: %s", e.getMessage()); - e.printStackTrace(); + Timber.e(e); } }); } @@ -451,7 +451,7 @@ public void onComplete() { @Override public void onError(Throwable e) { Timber.e("Update failed on sync table reason: %s", e.getMessage()); - e.printStackTrace(); + Timber.e(e); } }) ; diff --git a/collect_app/src/main/java/org/fieldsight/naxa/sync/DownloadViewModel.java b/collect_app/src/main/java/org/fieldsight/naxa/sync/DownloadViewModel.java index 161e8a232..d72cb78c8 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/sync/DownloadViewModel.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/sync/DownloadViewModel.java @@ -119,7 +119,7 @@ public void onSuccess(Object o) { @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); DownloadableItemLocalSource.getINSTANCE().markAsFailed(GENERAL_FORMS); if (e instanceof RetrofitException) { String message = e.getMessage(); diff --git a/collect_app/src/main/java/org/fieldsight/naxa/sync/SyncRepository.java b/collect_app/src/main/java/org/fieldsight/naxa/sync/SyncRepository.java index 274767d16..fab8fb5e9 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/sync/SyncRepository.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/sync/SyncRepository.java @@ -20,6 +20,7 @@ import io.reactivex.Single; import io.reactivex.observers.DisposableObserver; import io.reactivex.schedulers.Schedulers; +import timber.log.Timber; import static org.fieldsight.naxa.common.Constant.DownloadStatus.PENDING; @@ -132,7 +133,7 @@ public void onNext(Integer integer) { @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); } @Override diff --git a/collect_app/src/main/java/org/fieldsight/naxa/v3/ProjectListActivityV3.java b/collect_app/src/main/java/org/fieldsight/naxa/v3/ProjectListActivityV3.java index 2727c7561..ce7bbf3ec 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/v3/ProjectListActivityV3.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/v3/ProjectListActivityV3.java @@ -47,13 +47,13 @@ public class ProjectListActivityV3 extends CollectAbstractActivity { @BindView(R.id.rv_projectlist) - RecyclerView rv_projectlist; + RecyclerView rvProjectlist; @BindView(R.id.ll_nodata) - LinearLayout ll_nodata; + LinearLayout llNodata; @BindView(R.id.tv_nodata) - TextView tv_nodata; + TextView tvNodata; @BindView(R.id.prgbar) ProgressBar prgbar; @@ -62,10 +62,10 @@ public class ProjectListActivityV3 extends CollectAbstractActivity { Toolbar toolbar; @BindView(R.id.tv_sync_project) - TextView tv_sync_project; + TextView tvSyncProject; @BindView(R.id.cv_resync) - CardView cv_resync; + CardView cvResync; ProjectListAdapter adapter = null; List projectList = new ArrayList<>(); @@ -90,16 +90,17 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { public void onChanged() { int selected = 0; for (int i = 0; i < projectList.size(); i++) { - if (projectList.get(i).isChecked()) + if (projectList.get(i).isChecked()) { selected++; + } } Timber.d("project list counter is %d", selected); if (selected > 0) { - tv_sync_project.setVisibility(View.VISIBLE); - tv_sync_project.setBackgroundColor(getResources().getColor(R.color.secondaryColor)); - tv_sync_project.setText(String.format(Locale.getDefault(), "Sync %d projects", selected)); + tvSyncProject.setVisibility(View.VISIBLE); + tvSyncProject.setBackgroundColor(getResources().getColor(R.color.secondaryColor)); + tvSyncProject.setText(String.format(Locale.getDefault(), "Sync %d projects", selected)); } else { - tv_sync_project.setVisibility(View.GONE); + tvSyncProject.setVisibility(View.GONE); allSelected = false; invalidateOptionsMenu(); } @@ -108,11 +109,11 @@ public void onChanged() { }; adapter.registerAdapterDataObserver(observer); - rv_projectlist.setLayoutManager(new LinearLayoutManager(this)); - rv_projectlist.setAdapter(adapter); + rvProjectlist.setLayoutManager(new LinearLayoutManager(this)); + rvProjectlist.setAdapter(adapter); getDataFromServer(); manageNodata(true); - tv_sync_project.setOnClickListener(v -> openDownloadAActivity()); + tvSyncProject.setOnClickListener(v -> openDownloadAActivity()); projectObserver = projectNameList -> { Timber.i("list live data = %d", projectNameList.size()); adapter.notifyProjectisSynced(projectNameList); @@ -126,14 +127,14 @@ public void onChanged() { protected void onResume() { super.onResume(); Timber.i("ProjectListActivityv3 :: anyProject checked = " + adapter.anyProjectSelectedForSync()); - if(tv_sync_project.getVisibility() == View.VISIBLE && !adapter.anyProjectSelectedForSync()) { - tv_sync_project.setVisibility(View.GONE); + if (tvSyncProject.getVisibility() == View.VISIBLE && !adapter.anyProjectSelectedForSync()) { + tvSyncProject.setVisibility(View.GONE); } } @OnClick(R.id.cv_resync) void resyncProject() { - if(NetworkUtils.isNetworkConnected()) { + if (NetworkUtils.isNetworkConnected()) { getDataFromServer(); manageNodata(true); } else { @@ -144,21 +145,23 @@ void resyncProject() { @Override protected void onDestroy() { super.onDestroy(); - if (observer != null) + if (observer != null) { adapter.unregisterAdapterDataObserver(observer); - if (projectIds != null && projectIds.hasObservers() && projectObserver != null) + } + if (projectIds != null && projectIds.hasObservers() && projectObserver != null) { projectIds.removeObserver(projectObserver); + } } void manageNodata(boolean loading) { if (adapter.getItemCount() == 0) { - ll_nodata.setVisibility(View.VISIBLE); - cv_resync.setVisibility(loading ? View.GONE : View.VISIBLE); + llNodata.setVisibility(View.VISIBLE); + cvResync.setVisibility(loading ? View.GONE : View.VISIBLE); } else { - ll_nodata.setVisibility(View.GONE); + llNodata.setVisibility(View.GONE); } prgbar.setVisibility(loading ? View.VISIBLE : View.GONE); - tv_nodata.setText(loading ? "Loading data ... " : "Error in syncing the project"); + tvNodata.setText(loading ? "Loading data ... " : "Error in syncing the project"); } void getDataFromServer() { @@ -216,7 +219,7 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onPrepareOptionsMenu(Menu menu) { // menu.findItem(R.id.action_refresh).setVisible(showSyncMenu); - if(showSyncMenu) { + if (showSyncMenu) { menu.findItem(R.id.action_refresh).setIcon(allSelected ? R.drawable.ic_cancel_white_24dp : R.drawable.ic_action_sync @@ -238,7 +241,7 @@ public boolean onOptionsItemSelected(MenuItem item) { allSelected = !allSelected; for (Project project : projectList) { // if (!project.isSynced()) { - project.setChecked(allSelected); + project.setChecked(allSelected); // } else { // project.setChecked(false); // } diff --git a/collect_app/src/main/java/org/fieldsight/naxa/v3/adapter/SyncAdapterv3.java b/collect_app/src/main/java/org/fieldsight/naxa/v3/adapter/SyncAdapterv3.java index 1dd76491a..33cad899f 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/v3/adapter/SyncAdapterv3.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/v3/adapter/SyncAdapterv3.java @@ -81,9 +81,9 @@ public void notifyBySyncStat(List syncStatList) { if (syncableMap.containsKey(syncStat.getProjectId())) { List list = syncableMap.get(syncStat.getProjectId()); int syncType = Integer.parseInt(syncStat.getType()); - boolean isValidList = syncStat.getFailedUrl().contains("[") ; + boolean isValidList = syncStat.getFailedUrl().contains("["); - if(syncStat.isProgressBarEnabled()){ + if (syncStat.isProgressBarEnabled()) { Syncable syncable = list.get(syncType); syncable.setProgress(syncStat.getProgress()); syncable.setTotal(syncStat.getTotal()); @@ -117,15 +117,16 @@ private void notifyProgressBar() { int totalSynced = 0; int totalSize = 0; for (Syncable syncable : syncableList) { - if (!syncable.getSync()) + if (!syncable.getSync()) { continue; + } if (syncable.getStatus() == Constant.DownloadStatus.COMPLETED) { totalSynced++; } totalSize++; } - if(totalSize > 0) { + if (totalSize > 0) { progressMap.put(key, totalSynced * 100 / totalSize); } } @@ -148,8 +149,8 @@ public void downloadListItemClicked(int parentPos, int pos) { @Override public void retryButtonClicked(Project project, String[] failedUrls) { - if(callback != null){ - callback.onRetryButtonClicked(project,failedUrls); + if (callback != null) { + callback.onRetryButtonClicked(project, failedUrls); } } }; diff --git a/collect_app/src/main/java/org/fieldsight/naxa/v3/forms/FieldSightFormDownloader.java b/collect_app/src/main/java/org/fieldsight/naxa/v3/forms/FieldSightFormDownloader.java index e89b34f83..2e4cf1ee9 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/v3/forms/FieldSightFormDownloader.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/v3/forms/FieldSightFormDownloader.java @@ -79,7 +79,7 @@ public Pair downloadSingleFieldSightForm(Fields pair = Pair.create(fieldsightFormDetailsv3, message); Timber.d("form downloading starts for project = " + fieldsightFormDetailsv3.getSite_project_id() + " or " + fieldsightFormDetailsv3.getProject() + " for = " + fd.getFormName()); } catch (TaskCancelledException e) { - e.printStackTrace(); + Timber.e(e); pair = Pair.create(fieldsightFormDetailsv3, "Failed to create form download request"); } return pair; @@ -104,7 +104,7 @@ public Pair downloadSingleFieldSightForm(FieldSig pair = Pair.create(fd, message.isEmpty() ? Collect.getInstance().getString(R.string.success) : message); } catch (TaskCancelledException e) { - e.printStackTrace(); + Timber.e(e); } return pair; diff --git a/collect_app/src/main/java/org/fieldsight/naxa/v3/network/SyncActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/v3/network/SyncActivity.java index 352a6518d..502939292 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/v3/network/SyncActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/v3/network/SyncActivity.java @@ -49,7 +49,7 @@ public class SyncActivity extends CollectAbstractActivity implements SyncAdapter Button downloadButton; @BindView(R.id.toolbar_message) - TextView toolbar_message; + TextView toolbarMessage; SyncAdapterv3 adapterv3; boolean auto = true; @@ -88,14 +88,15 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { Timber.i("SyncActivity, isSyncing = " + syncing); // clear the sync stat table if it is not syncing when opened - if(!syncing) { + if (!syncing) { SyncLocalSource3.getInstance().delete(); } setTitle(String.format(Locale.getDefault(), "Projects (%d)", projectList.size())); /// create the map of the syncing - if (syncableMap == null) + if (syncableMap == null) { createSyncableList(projectList); + } adapterv3 = new SyncAdapterv3(auto, projectList, syncableMap); adapterv3.setAdapterCallback(this); @@ -185,10 +186,11 @@ public void onRequestInterrupt(int pos, Project project) { .setPositiveButton("Yes", (dialog, which) -> { syncableMap.remove(project.getId()); adapterv3.removeAndNotify(pos); - if (adapterv3.getItemCount() > 0) + if (adapterv3.getItemCount() > 0) { setTitle("Projects (" + adapterv3.getItemCount() + ")"); - else + } else { setTitle("Projects"); + } }) .setNegativeButton("Cancel", null) .create() diff --git a/collect_app/src/main/java/org/fieldsight/naxa/v3/network/SyncServiceV3.java b/collect_app/src/main/java/org/fieldsight/naxa/v3/network/SyncServiceV3.java index 15cbe6c5e..c23a44d23 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/v3/network/SyncServiceV3.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/v3/network/SyncServiceV3.java @@ -162,8 +162,9 @@ public List apply(Project project) throws Exception { for (FieldsightFormDetailsv3 fieldsightFormDetailsv3 : educationMaterial) { String em = fieldsightFormDetailsv3.getEm(); Timber.i("SyncServicev3, em = %s", em); - if (TextUtils.isEmpty(em) || TextUtils.equals(em, "null")) + if (TextUtils.isEmpty(em) || TextUtils.equals(em, "null")) { continue; + } JSONObject jsonObject = new JSONObject(em); // add image @@ -193,7 +194,7 @@ public List apply(Project project) throws Exception { } } } - if(educationMaterialUrls.size() == 0) { + if (educationMaterialUrls.size() == 0) { markAsCompleted(project.getId(), 2); } else { markAsRunning(project.getId(), 2); @@ -215,7 +216,7 @@ public ObservableSource apply(String url) throws Exception { public void accept(Object o) throws Exception { Timber.i("SyncService: educationMaterials finalized = %s, currentWorkingIndex = %s, currentWorkingProject = %s", o.toString(), currentWorkingProjectIndex, projectidList.get(currentWorkingProjectIndex)); String projectId = projectidList.get(currentWorkingProjectIndex); - if(eduMaterialsMap.containsKey(projectId)) { + if (eduMaterialsMap.containsKey(projectId)) { eduMaterialsMap.put(projectId, eduMaterialsMap.get(projectId) - 1); if (eduMaterialsMap.get(projectId) <= 0) { markAsCompleted(projectId, 2); diff --git a/collect_app/src/main/java/org/odk/collect/android/TestingActivity.java b/collect_app/src/main/java/org/odk/collect/android/TestingActivity.java index 5b99283e1..9ce9d17e1 100644 --- a/collect_app/src/main/java/org/odk/collect/android/TestingActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/TestingActivity.java @@ -23,6 +23,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.DisposableObserver; import io.reactivex.schedulers.Schedulers; +import timber.log.Timber; import static org.fieldsight.naxa.common.Constant.FormDeploymentFrom.PROJECT; @@ -81,7 +82,7 @@ public void onNext(Site site) { @Override public void onError(Throwable e) { - e.printStackTrace(); + Timber.e(e); ToastUtils.showLongToast(e.getMessage()); } diff --git a/collect_app/src/main/java/org/odk/collect/android/utilities/DateTimeUtils.java b/collect_app/src/main/java/org/odk/collect/android/utilities/DateTimeUtils.java index 091e18295..0c27ade7d 100644 --- a/collect_app/src/main/java/org/odk/collect/android/utilities/DateTimeUtils.java +++ b/collect_app/src/main/java/org/odk/collect/android/utilities/DateTimeUtils.java @@ -209,13 +209,15 @@ public static DatePickerDetails getDatePickerDetails(String appearance) { } public static long tsToSec8601(String timestamp) { - if (timestamp == null) return 0; + if (timestamp == null) { + return 0; + } try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); - long epoch = sdf.parse(timestamp).getTime(); + long epoch = sdf.parse(timestamp).getTime(); return ((epoch / 1000)); } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); return 0; } } @@ -225,7 +227,9 @@ public static String getRelativeTime(String dateTime, Boolean dateTimeFromServer String relativeTime; - if(dateTime == null)return ""; + if (dateTime == null) { + return ""; + } try { SimpleDateFormat sdf; @@ -244,12 +248,12 @@ public static String getRelativeTime(String dateTime, Boolean dateTimeFromServer CharSequence ago = DateUtils.getRelativeTimeSpanString(time, now, DateUtils.MINUTE_IN_MILLIS); relativeTime = ago.toString(); - if("0 minutes ago".equals(relativeTime)){ + if ("0 minutes ago".equals(relativeTime)) { relativeTime = "just now"; } } catch (ParseException e) { - e.printStackTrace(); + Timber.e(e); relativeTime = dateTime; } @@ -261,8 +265,9 @@ public static String getFormattedDate(String format, long time) { Date date = new Date(); date.setTime(time); return new SimpleDateFormat(format).format(date); - }catch (Exception e) {e.printStackTrace(); - return time+""; + } catch (Exception e) { + Timber.e(e); + return time + ""; } } diff --git a/collect_app/src/main/java/org/odk/collect/android/utilities/FileUtils.java b/collect_app/src/main/java/org/odk/collect/android/utilities/FileUtils.java index 28506f59f..a6fd6c857 100644 --- a/collect_app/src/main/java/org/odk/collect/android/utilities/FileUtils.java +++ b/collect_app/src/main/java/org/odk/collect/android/utilities/FileUtils.java @@ -78,19 +78,29 @@ public class FileUtils { public static final String AUTO_DELETE = "autoDelete"; public static final String AUTO_SEND = "autoSend"; - /** Suffix for the form media directory. */ + /** + * Suffix for the form media directory. + */ public static final String MEDIA_SUFFIX = "-media"; - /** Filename of the last-saved instance data. */ + /** + * Filename of the last-saved instance data. + */ public static final String LAST_SAVED_FILENAME = "last-saved.xml"; - /** Valid XML stub that can be parsed without error. */ + /** + * Valid XML stub that can be parsed without error. + */ private static final String STUB_XML = ""; - /** True if we have checked whether /sdcard points to getExternalStorageDirectory(). */ + /** + * True if we have checked whether /sdcard points to getExternalStorageDirectory(). + */ private static boolean isSdcardSymlinkChecked; - /** The result of checking whether /sdcard points to getExternalStorageDirectory(). */ + /** + * The result of checking whether /sdcard points to getExternalStorageDirectory(). + */ private static boolean isSdcardSymlinkSameAsExternalStorageDirectory; static int bufSize = 16 * 1024; // May be set by unit test @@ -547,11 +557,11 @@ public static String getFileExtension(String fileName) { /** * Grants read and write permissions to a content URI added to the specified intent. - * + *

* For Android > 4.4, the permissions expire when the receiving app's stack is finished. For * Android <= 4.4, the permissions are granted to all applications that can respond to the * intent. - * + *

* For true security, the permissions for Android <= 4.4 should be revoked manually but we don't * revoke them because we don't have many users on lower API levels and prior to targeting API * 24+, all apps always had access to the files anyway. @@ -577,7 +587,7 @@ public static void grantFilePermissions(Intent intent, Uri uri, Context context) /** * Grants read permissions to a content URI added to the specified Intent. - * + *

* See {@link #grantFileReadPermissions(Intent, Uri, Context)} for details. */ public static void grantFileReadPermissions(Intent intent, Uri uri, Context context) { @@ -610,7 +620,9 @@ public static File getFileByPath(String filePath) { } private static boolean isSpace(String s) { - if (s == null) return true; + if (s == null) { + return true; + } for (int i = 0, len = s.length(); i < len; ++i) { if (!Character.isWhitespace(s.charAt(i))) { return false; @@ -645,7 +657,6 @@ public static boolean deleteDir(final File dir) { } - /** * Copy the directory. * @@ -719,11 +730,17 @@ private static boolean copyOrMoveFile(final File srcFile, final File destFile, final OnReplaceListener listener, final boolean isMove) { - if (srcFile == null || destFile == null) return false; + if (srcFile == null || destFile == null){ + return false; + } // srcFile equals destFile then return false - if (srcFile.equals(destFile)) return false; + if (srcFile.equals(destFile)) { + return false; + } // srcFile doesn't exist or isn't a file then return false - if (!srcFile.exists() || !srcFile.isFile()) return false; + if (!srcFile.exists() || !srcFile.isFile()){ + return false; + } if (destFile.exists()) { if (listener == null || listener.onReplace()) {// require delete the old file if (!destFile.delete()) {// unsuccessfully delete then return false @@ -733,12 +750,14 @@ private static boolean copyOrMoveFile(final File srcFile, return true; } } - if (!createOrExistsDir(destFile.getParentFile())) return false; + if (!createOrExistsDir(destFile.getParentFile())) { + return false; + } try { return writeFileFromIS(destFile, new FileInputStream(srcFile)) && !(isMove && !deleteFile(srcFile)); } catch (FileNotFoundException e) { - e.printStackTrace(); + Timber.e(e); return false; } } @@ -775,20 +794,20 @@ private static boolean writeFileFromIS(final File file, } return true; } catch (IOException e) { - e.printStackTrace(); + Timber.e(e); return false; } finally { try { is.close(); } catch (IOException e) { - e.printStackTrace(); + Timber.e(e); } try { if (os != null) { os.close(); } } catch (IOException e) { - e.printStackTrace(); + Timber.e(e); } } } @@ -837,7 +856,9 @@ public static boolean deleteFilesInDirWithFilter(final File dir, final FileFilte return true; } - /** Uses the /sdcard symlink to shorten a path, if it's valid to do so. */ + /** + * Uses the /sdcard symlink to shorten a path, if it's valid to do so. + */ @SuppressWarnings("PMD.DoNotHardCodeSDCard") public static File simplifyPath(File file) { // The symlink at /sdcard points to the same location as the storage @@ -861,7 +882,9 @@ public static File simplifyPath(File file) { } - /** Checks whether /sdcard points to the same place as getExternalStorageDirectory(). */ + /** + * Checks whether /sdcard points to the same place as getExternalStorageDirectory(). + */ @SuppressWarnings("PMD.DoNotHardCodeSDCard") @SuppressFBWarnings( value = "DMI_HARDCODED_ABSOLUTE_FILENAME", @@ -892,12 +915,16 @@ private static void checkIfSdcardSymlinkSameAsExternalStorageDirectory() { } - /** Iterates over all directories and files under a root path. */ + /** + * Iterates over all directories and files under a root path. + */ public static Iterable walk(File root) { return () -> new Walker(root, true); } - /** An iterator that walks over all the directories and files under a given path. */ + /** + * An iterator that walks over all the directories and files under a given path. + */ private static class Walker implements Iterator { private final List queue = new ArrayList<>(); private final boolean depthFirst; @@ -907,11 +934,13 @@ private static class Walker implements Iterator { this.depthFirst = depthFirst; } - @Override public boolean hasNext() { + @Override + public boolean hasNext() { return !queue.isEmpty(); } - @Override public File next() { + @Override + public File next() { if (queue.isEmpty()) { throw new NoSuchElementException(); }