diff --git a/collect_app/src/androidTest/java/org/odk/collect/android/formentry/FormNavigationButtonTest.java b/collect_app/src/androidTest/java/org/odk/collect/android/formentry/FormNavigationButtonTest.java index 2bea08c73..67734b191 100644 --- a/collect_app/src/androidTest/java/org/odk/collect/android/formentry/FormNavigationButtonTest.java +++ b/collect_app/src/androidTest/java/org/odk/collect/android/formentry/FormNavigationButtonTest.java @@ -59,7 +59,7 @@ * separately check the option to navigate with either swipes or buttons: * * - * String navigation = (String) GeneralSharedPreferences.getInstance().get(GeneralKeys.KEY_NAVIGATION); + * String navigation = (String) GeneralSharedPreferences.newInstance().get(GeneralKeys.KEY_NAVIGATION); * showNavigationButtons = navigation.contains(GeneralKeys.NAVIGATION_BUTTONS); * */ diff --git a/collect_app/src/main/java/org/fieldsight/naxa/common/SettingsActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/common/SettingsActivity.java index 7b2403003..acb735fbd 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/common/SettingsActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/common/SettingsActivity.java @@ -17,6 +17,7 @@ import org.fieldsight.naxa.network.ServiceGenerator; import org.odk.collect.android.utilities.ToastUtils; +import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -93,7 +94,7 @@ public void restoreDefault() { private boolean isValidUrl(String url) { Pattern p = Patterns.WEB_URL; - Matcher m = p.matcher(url.toLowerCase()); + Matcher m = p.matcher(url.toLowerCase(Locale.getDefault())); return m.matches(); } diff --git a/collect_app/src/main/java/org/fieldsight/naxa/common/downloader/utils/LongSparseArray.java b/collect_app/src/main/java/org/fieldsight/naxa/common/downloader/utils/LongSparseArray.java index c6bfd597d..5811978f2 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/common/downloader/utils/LongSparseArray.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/common/downloader/utils/LongSparseArray.java @@ -75,15 +75,13 @@ public LongSparseArray(int initialCapacity) { @Override @SuppressWarnings("unchecked") - public LongSparseArray clone() { + public LongSparseArray clone() throws CloneNotSupportedException { LongSparseArray clone = null; - try { - clone = (LongSparseArray) super.clone(); - clone.mKeys = mKeys.clone(); - clone.mValues = mValues.clone(); - } catch (CloneNotSupportedException cnse) { - /* ignore */ - } + + clone = (LongSparseArray) super.clone(); + clone.mKeys = mKeys.clone(); + clone.mValues = mValues.clone(); + return clone; } diff --git a/collect_app/src/main/java/org/fieldsight/naxa/contact/ContactDetailsBottomSheetFragment.java b/collect_app/src/main/java/org/fieldsight/naxa/contact/ContactDetailsBottomSheetFragment.java index 792f5cf2f..c54e1a942 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/contact/ContactDetailsBottomSheetFragment.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/contact/ContactDetailsBottomSheetFragment.java @@ -26,7 +26,7 @@ public class ContactDetailsBottomSheetFragment extends BottomSheetDialogFragment private ImageView profilePicture; private TextView fullname, username, role, address, gender, email, skype, twitter, tango, hike, qq, googletalk, viber, whatsapp, wechat; - public static ContactDetailsBottomSheetFragment getInstance() { + public static ContactDetailsBottomSheetFragment newInstance() { return new ContactDetailsBottomSheetFragment(); } diff --git a/collect_app/src/main/java/org/fieldsight/naxa/contact/ProjectContactsFragment.java b/collect_app/src/main/java/org/fieldsight/naxa/contact/ProjectContactsFragment.java index fa33d0163..7fd102f50 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/contact/ProjectContactsFragment.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/contact/ProjectContactsFragment.java @@ -42,7 +42,7 @@ public class ProjectContactsFragment extends Fragment implements ContactAdapter. @BindView(R.id.recycler_view) RecyclerView recyclerView; - public static ProjectContactsFragment getInstance() { + public static ProjectContactsFragment newInstance() { return new ProjectContactsFragment(); } @@ -96,7 +96,7 @@ public void onClick(View v) { @Override public void onContactClicked(FieldSightContactModel contactModel) { - ContactDetailsBottomSheetFragment contactDetailsBottomSheetFragmentDialog = ContactDetailsBottomSheetFragment.getInstance(); + ContactDetailsBottomSheetFragment contactDetailsBottomSheetFragmentDialog = ContactDetailsBottomSheetFragment.newInstance(); contactDetailsBottomSheetFragmentDialog.setContact(contactModel); contactDetailsBottomSheetFragmentDialog.show(requireFragmentManager(), "Contact Bottom Sheet"); } 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 ea64a90fb..820a9239b 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 @@ -29,7 +29,6 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -import java.util.Vector; import butterknife.BindView; import butterknife.ButterKnife; diff --git a/collect_app/src/main/java/org/fieldsight/naxa/educational/EducationalMaterialRecyclerViewAdapter.java b/collect_app/src/main/java/org/fieldsight/naxa/educational/EducationalMaterialRecyclerViewAdapter.java index 7e9ab59e6..1491ec0a3 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/educational/EducationalMaterialRecyclerViewAdapter.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/educational/EducationalMaterialRecyclerViewAdapter.java @@ -7,7 +7,6 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; - import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -17,12 +16,8 @@ import androidx.core.content.FileProvider; import androidx.recyclerview.widget.RecyclerView; -import com.bumptech.glide.load.engine.DiskCacheStrategy; - import org.fieldsight.collect.android.BuildConfig; import org.fieldsight.collect.android.R; -import org.fieldsight.naxa.common.Connectivity; -import org.fieldsight.naxa.common.GlideApp; import java.io.File; import java.util.List; @@ -35,8 +30,6 @@ public class EducationalMaterialRecyclerViewAdapter extends RecyclerView.Adapter { - private static final String TAG = "Education Material"; - // The items to display in your RecyclerView private final List items; private static final int TEXT_VIEW = 0, IMAGE = 1, VIDEO = 2, PDF = 3; @@ -197,20 +190,10 @@ private void configureViewHolderImage(ViewHolderImage vh2, int position) { final Edu_Image_Model edu_image_model = (Edu_Image_Model) items.get(position); if (edu_image_model != null) { - Log.d(TAG, "configureViewHolderImage: " + edu_image_model.getThumbImageOn()); - - if (edu_image_model.getThumbImageOff() != null || !edu_image_model.getThumbImageOff().equals("")) { - Log.d(TAG, "configureViewHolderImage: " + edu_image_model.getThumbImageOff()); - File f = new File(edu_image_model.getThumbImageOff()); - ViewHolderImage.imageView.setImageURI(FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", f)); - } else { - if (Connectivity.isConnected(context)) { - GlideApp.with(context.getApplicationContext()) - .load(edu_image_model.getThumbImageOn()) - .diskCacheStrategy(DiskCacheStrategy.ALL) - .into(ViewHolderImage.imageView); - } - } + + Timber.d("configureViewHolderImage: %s", edu_image_model.getThumbImageOff()); + File f = new File(edu_image_model.getThumbImageOff()); + ViewHolderImage.imageView.setImageURI(FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", f)); try { @@ -321,7 +304,7 @@ public void onClick(View v) { target.setDataAndType(path, "application/pdf"); target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); -// Uri fileUri = FileProvider.getUriForFile(context, Collect.getInstance().getString(R.string.android_file_provider_fieldsight), file); +// Uri fileUri = FileProvider.getUriForFile(context, Collect.newInstance().getString(R.string.android_file_provider_fieldsight), file); // Log.d(TAG, "PDF_URI: " + fileUri); // target.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // target.setDataAndType(fileUri, "application/pdf"); @@ -367,7 +350,7 @@ public void onClick(View v) { target.setDataAndType(path, "application/pdf"); target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); -// Uri fileUri = FileProvider.getUriForFile(context, Collect.getInstance().getString(R.string.android_file_provider_fieldsight), file); +// Uri fileUri = FileProvider.getUriForFile(context, Collect.newInstance().getString(R.string.android_file_provider_fieldsight), file); // Log.d(TAG, "PDF_URI: " + fileUri); // target.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // target.setDataAndType(fileUri, "application/pdf"); diff --git a/collect_app/src/main/java/org/fieldsight/naxa/educational/EducationalMaterialsRemoteSource.java b/collect_app/src/main/java/org/fieldsight/naxa/educational/EducationalMaterialsRemoteSource.java index f8541d5cc..04e18ab0f 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/educational/EducationalMaterialsRemoteSource.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/educational/EducationalMaterialsRemoteSource.java @@ -27,6 +27,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import io.reactivex.Observable; import io.reactivex.ObservableSource; @@ -174,7 +175,7 @@ private String getSavePath(String url) { //todo bug RxDownloadmanager is adding /storage/emulated so remove it before we send path String savePath = ""; - switch (FileUtils.getFileExtension(url).toLowerCase()) { + switch (FileUtils.getFileExtension(url).toLowerCase(Locale.getDefault())) { case "pdf": savePath = Collect.PDF.replace(Environment.getExternalStorageDirectory().toString(), ""); break; diff --git a/collect_app/src/main/java/org/fieldsight/naxa/forms/data/local/FormDetailsConverter.java b/collect_app/src/main/java/org/fieldsight/naxa/forms/data/local/FormDetailsConverter.java index 1df94974a..58876aa1e 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/forms/data/local/FormDetailsConverter.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/forms/data/local/FormDetailsConverter.java @@ -14,15 +14,16 @@ public class FormDetailsConverter implements Serializable { @TypeConverter public String fromFormDetail(FormDetails formDetails) { String jsonData = "{"; - try{ - jsonData += "\"downloadUrl\": \""+formDetails.getDownloadUrl()+"\",\n" + - " \"manifestUrl\": \""+formDetails.getManifestUrl()+"\",\n" + - " \"name\": \""+formDetails.getFormName()+"\",\n" + - " \"formID\": \""+formDetails.getFormID()+"\",\n" + - " \"version\": \""+formDetails.getFormVersion()+"\",\n" + - " \"hash\": \""+formDetails.getHash()+"\""; - }catch (Exception e){ - Timber.e(e);;} + try { + jsonData += "\"downloadUrl\": \"" + formDetails.getDownloadUrl() + "\",\n" + + " \"manifestUrl\": \"" + formDetails.getManifestUrl() + "\",\n" + + " \"name\": \"" + formDetails.getFormName() + "\",\n" + + " \"formID\": \"" + formDetails.getFormID() + "\",\n" + + " \"version\": \"" + formDetails.getFormVersion() + "\",\n" + + " \"hash\": \"" + formDetails.getHash() + "\""; + } catch (Exception e) { + Timber.e(e); + } return jsonData += "}"; } @@ -32,7 +33,7 @@ public FormDetails fromString(String value) { JSONObject jsonObject = new JSONObject(value); return FieldsightFormDetailsv3.formDetailsfromJSON(jsonObject); } catch (Exception e) { - Timber.e(e);; + Timber.e(e); return null; } diff --git a/collect_app/src/main/java/org/fieldsight/naxa/generalforms/GeneralFormsAdapter.java b/collect_app/src/main/java/org/fieldsight/naxa/generalforms/GeneralFormsAdapter.java index 4c50a27c1..5f43f619c 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/generalforms/GeneralFormsAdapter.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/generalforms/GeneralFormsAdapter.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Locale; import static org.fieldsight.naxa.common.AnimationUtils.getRotationAnimation; @@ -80,7 +81,7 @@ public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) { String relativeDateTime = DateTimeUtils.getRelativeTime(generalForm.getDateCreated(), true); viewHolder.tvDesc.setText(viewHolder.tvFormName.getContext().getString(R.string.form_created_on, relativeDateTime)); if (generalForm.getName() != null) { - viewHolder.tvIconText.setText(generalForm.getName().substring(0, 1).toUpperCase()); + viewHolder.tvIconText.setText(generalForm.getName().substring(0, 1).toUpperCase(Locale.getDefault())); } setSubmissionText(viewHolder, submissionDetail, generalForm); } 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 35113243f..d7c112736 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 @@ -210,7 +210,7 @@ public SyncableItem apply(Integer integer) { // public ObservableSource apply(SyncableItem syncableItem) throws Exception { // boolean hasAPIRunning = ServiceGenerator.getRunningAPICount() > 0; // if(!hasAPIRunning){ -// SyncRepository.getInstance().setError(syncableItem.getUid()); +// SyncRepository.newInstance().setError(syncableItem.getUid()); // } // return Observable.just(syncableItem); // } 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 d78c66691..01ed09a1d 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 @@ -57,7 +57,7 @@ public void fetchGeneralForms() { .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) // ProjectSitesRemoteSource -// .getInstance() +// .newInstance() // .fetchProjecSites() .flatMap((Function, SingleSource>) projects -> { /*note: @@ -106,7 +106,7 @@ public void fetchScheduledForms() { .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) // ProjectSitesRemoteSource -// .getInstance() +// .newInstance() // .fetchProjecSites() .flatMap((Function, Single>>) projects -> { /*note: @@ -150,7 +150,7 @@ public void onError(Throwable e) { public void fetchStagedForms() { // ProjectSitesRemoteSource -// .getInstance() +// .newInstance() // .fetchProjecSites() ProjectLocalSource.getInstance() .getProjectsMaybe() @@ -241,7 +241,7 @@ public void fetchAllForms() { .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) // ProjectSitesRemoteSource -// .getInstance() +// .newInstance() // .fetchProjecSites() .flatMap((Function, SingleSource>>) projects -> { /*note: diff --git a/collect_app/src/main/java/org/fieldsight/naxa/project/MapFragment.java b/collect_app/src/main/java/org/fieldsight/naxa/project/MapFragment.java index 66c9638f8..068dca20d 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/project/MapFragment.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/project/MapFragment.java @@ -65,7 +65,7 @@ // // private ArrayList plottedSites = new ArrayList<>(0); // -// public static MapFragment getInstance(Project loadedProject) { +// public static MapFragment newInstance(Project loadedProject) { // MapFragment frag = new MapFragment(); // Bundle bundle = new Bundle(); // bundle.putParcelable(EXTRA_OBJECT, loadedProject); @@ -78,7 +78,7 @@ // SiteMarker marker = new SiteMarker(map); // marker.setSnippet(snippet); // marker.setTitle(title); -// marker.setIcon(ContextCompat.getDrawable(Collect.getInstance().getApplicationContext(), R.drawable.ic_place_black)); +// marker.setIcon(ContextCompat.getDrawable(Collect.newInstance().getApplicationContext(), R.drawable.ic_place_black)); // marker.setPosition(geoPoint); // return marker; // } @@ -144,7 +144,7 @@ // // // -// SiteLocalSource.getInstance().getByIdAsSingle(loadedProject.getId()) +// SiteLocalSource.newInstance().getByIdAsSingle(loadedProject.getId()) // .toObservable() // .flatMapIterable((Function, Iterable>) sites -> sites) // .flatMap((Function>) site -> { diff --git a/collect_app/src/main/java/org/fieldsight/naxa/project/data/ProjectRepository.java b/collect_app/src/main/java/org/fieldsight/naxa/project/data/ProjectRepository.java index 240a1c71d..0ec9b3973 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/project/data/ProjectRepository.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/project/data/ProjectRepository.java @@ -35,6 +35,7 @@ import okhttp3.ResponseBody; import timber.log.Timber; +@SuppressWarnings({"PMD.SingleMethodSingleton"}) public class ProjectRepository implements BaseRepository { private static ProjectRepository projectRepository; diff --git a/collect_app/src/main/java/org/fieldsight/naxa/scheduled/ScheduledFormsAdapter.java b/collect_app/src/main/java/org/fieldsight/naxa/scheduled/ScheduledFormsAdapter.java index d0dd9eb4c..93b6c9f2b 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/scheduled/ScheduledFormsAdapter.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/scheduled/ScheduledFormsAdapter.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Locale; import static org.fieldsight.naxa.common.AnimationUtils.getRotationAnimation; @@ -63,7 +64,7 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int position) viewHolder.tvFormName.setText(scheduleForm.getFormName()); viewHolder.tvDesc.setText(scheduleForm.getScheduleName()); if(!TextUtils.isEmpty(scheduleForm.getScheduleName())){ - viewHolder.tvIconText.setText(scheduleForm.getScheduleName().substring(0, 1).toUpperCase()); + viewHolder.tvIconText.setText(scheduleForm.getScheduleName().substring(0, 1).toUpperCase(Locale.getDefault())); } setSubmissionText(viewHolder, submissionDetail, scheduleForm); diff --git a/collect_app/src/main/java/org/fieldsight/naxa/site/ProjectDashboardActivity.java b/collect_app/src/main/java/org/fieldsight/naxa/site/ProjectDashboardActivity.java index ed9a27665..2bfdb7bc3 100644 --- a/collect_app/src/main/java/org/fieldsight/naxa/site/ProjectDashboardActivity.java +++ b/collect_app/src/main/java/org/fieldsight/naxa/site/ProjectDashboardActivity.java @@ -485,10 +485,10 @@ private void setViewpager() { ArrayList fragments = new ArrayList<>(); - SiteListFragment siteListFragment = SiteListFragment.getInstance(loadedProject); - ProjectContactsFragment projectContactsFragment = ProjectContactsFragment.getInstance(); + SiteListFragment siteListFragment = SiteListFragment.newInstance(loadedProject); + ProjectContactsFragment projectContactsFragment = ProjectContactsFragment.newInstance(); -// MapFragment mapFragment = MapFragment.getInstance(loadedProject); +// MapFragment mapFragment = MapFragment.newInstance(loadedProject); fragments.add(siteListFragment); fragments.add(projectContactsFragment); // fragments.add(mapFragment); 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 64fac0408..264e1a90f 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 @@ -30,7 +30,6 @@ import com.google.common.primitives.Longs; import org.fieldsight.collect.android.R; -import org.fieldsight.naxa.common.Constant; import org.fieldsight.naxa.common.DialogFactory; import org.fieldsight.naxa.common.FieldSightNotificationUtils; import org.fieldsight.naxa.common.FilterDialogAdapter; @@ -85,7 +84,7 @@ public class SiteListFragment extends Fragment implements SiteListAdapter.SiteLi TermsLabels tl; - public static SiteListFragment getInstance(Project project) { + public static SiteListFragment newInstance(Project project) { Bundle bundle = new Bundle(); bundle.putParcelable(EXTRA_OBJECT, project); SiteListFragment siteListFragment = new SiteListFragment(); @@ -108,7 +107,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c loadedProject = getArguments().getParcelable(EXTRA_OBJECT); setupRecycleView(); allSitesLiveData = SiteLocalSource.getInstance().getAllParentSite(loadedProject.getId()); - offlineSitesLiveData = SiteLocalSource.getInstance().getByIdAndSiteStatus(loadedProject.getId(), Constant.SiteStatus.IS_OFFLINE); collectFilterAndApply(new ArrayList<>()); siteUploadActionModeCallback = new SiteUploadActionModeCallback(); 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 2be0fdb39..d4d2be464 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 @@ -42,7 +42,6 @@ import static org.fieldsight.naxa.common.Constant.FormDeploymentFrom.PROJECT; import static org.fieldsight.naxa.common.SharedPreferenceUtils.isFormSaveCacheSafe; -; public class SurveyFormsActivity extends CollectAbstractActivity implements TitleDescAdapter.OnCardClickListener { 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 5e2dd77e5..451b8b28c 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 @@ -280,7 +280,7 @@ public DownloadableItem apply(Integer integer) { // public ObservableSource apply(SyncableItem syncableItem) throws Exception { // boolean hasAPIRunning = ServiceGenerator.getRunningAPICount() > 0; // if(!hasAPIRunning){ -// SyncRepository.getInstance().setError(syncableItem.getUid()); +// SyncRepository.newInstance().setError(syncableItem.getUid()); // } // return Observable.just(syncableItem); // } 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 54745cafc..5116ed38e 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 @@ -82,7 +82,7 @@ private void fetchGeneralForms() { .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) // ProjectSitesRemoteSource -// .getInstance() +// .newInstance() // .fetchProjecSites() .flatMap((Function, SingleSource>) projects -> { /*note: @@ -135,7 +135,7 @@ private void fetchScheduledForms() { .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) // ProjectSitesRemoteSource -// .getInstance() +// .newInstance() // .fetchProjecSites() .flatMap((Function, Single>>) projects -> { /*note: @@ -184,7 +184,7 @@ public void onError(Throwable e) { private void fetchStagedForms() { // ProjectSitesRemoteSource -// .getInstance() +// .newInstance() // .fetchProjecSites() ProjectLocalSource.getInstance() .getProjectsMaybe() @@ -276,7 +276,7 @@ public void fetchAllForms() { .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) // ProjectSitesRemoteSource -// .getInstance() +// .newInstance() // .fetchProjecSites() .flatMap((Function, SingleSource>>) projects -> { /*note: diff --git a/collect_app/src/main/java/org/fieldsight/naxa/v3/network/SyncManager.java b/collect_app/src/main/java/org/fieldsight/naxa/v3/network/SyncManager.java deleted file mode 100644 index 4bcd36685..000000000 --- a/collect_app/src/main/java/org/fieldsight/naxa/v3/network/SyncManager.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.fieldsight.naxa.v3.network; - -public class SyncManager { - /** - * @Author: Yubaraj Poudel - * @Since: 13/05/2019 - * - * - */ - String projectId; - - private SyncManager(String projectId){ - this.projectId = projectId; - } - - public SyncManager instance(String projectId) { - return new SyncManager(projectId); - } - - public SyncManager fromRegions(String[] regionIds) { - return this; - } - - void syncSites() { - - } - - void syncExams() { - - } - - void syncMaterials() { - - } - - - - - -} 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 5bb358bb6..b221b3d6e 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 @@ -29,6 +29,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Objects; import io.reactivex.Observable; @@ -244,7 +245,7 @@ private String getSavePath(String url) { //todo bug RxDownloadmanager is adding /storage/emulated so remove it before we send path String savePath = ""; - switch (FileUtils.getFileExtension(url).toLowerCase()) { + switch (FileUtils.getFileExtension(url).toLowerCase(Locale.getDefault())) { case "pdf": savePath = Collect.PDF.replace(Environment.getExternalStorageDirectory().toString(), ""); break; diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java index 1a0e20665..6db5184ea 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java @@ -981,7 +981,7 @@ public boolean onPrepareOptionsMenu(Menu menu) { menu.findItem(R.id.menu_languages).setVisible(useability) .setEnabled(useability); - //useability = (boolean) AdminSharedPreferences.getInstance().get(AdminKeys.KEY_ACCESS_SETTINGS); + //useability = (boolean) AdminSharedPreferences.newInstance().get(AdminKeys.KEY_ACCESS_SETTINGS); useability = false; menu.findItem(R.id.menu_preferences).setVisible(useability) diff --git a/collect_app/src/main/java/org/odk/collect/android/geo/MapboxUtils.java b/collect_app/src/main/java/org/odk/collect/android/geo/MapboxUtils.java index cd76e0cf6..70529830e 100644 --- a/collect_app/src/main/java/org/odk/collect/android/geo/MapboxUtils.java +++ b/collect_app/src/main/java/org/odk/collect/android/geo/MapboxUtils.java @@ -31,7 +31,7 @@ static Mapbox initMapbox() { mapbox = null; } - // It's not safe to call Mapbox.getInstance() more than once. It can fail on + // It's not safe to call Mapbox.newInstance() more than once. It can fail on // the first call and then succeed on the second call, returning an invalid, // crashy Mapbox object. We trust only the result of the first attempt. initAttempted = true; diff --git a/collect_app/src/main/java/org/odk/collect/android/preferences/ServerPreferencesFragment.java b/collect_app/src/main/java/org/odk/collect/android/preferences/ServerPreferencesFragment.java index 5150a16fc..8d4ec6758 100644 --- a/collect_app/src/main/java/org/odk/collect/android/preferences/ServerPreferencesFragment.java +++ b/collect_app/src/main/java/org/odk/collect/android/preferences/ServerPreferencesFragment.java @@ -174,7 +174,7 @@ public void setupTransportPreferences() { smsGatewayPreference.getEditText().setFilters( new InputFilter[]{new ControlCharacterFilter()}); - Transport transport = Transport.fromPreference(GeneralSharedPreferences.getInstance().get(KEY_SUBMISSION_TRANSPORT_TYPE)); + Transport transport = Transport.fromPreference(GeneralSharedPreferences.newInstance().get(KEY_SUBMISSION_TRANSPORT_TYPE)); boolean smsEnabled = !transport.equals(Transport.Internet); smsGatewayPreference.setEnabled(smsEnabled); @@ -482,7 +482,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { */ /* private void runSmsPhoneNumberValidation() { - Transport transport = Transport.fromPreference(GeneralSharedPreferences.getInstance().get(KEY_SUBMISSION_TRANSPORT_TYPE)); + Transport transport = Transport.fromPreference(GeneralSharedPreferences.newInstance().get(KEY_SUBMISSION_TRANSPORT_TYPE)); if (!transport.equals(Transport.Internet)) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity()); diff --git a/collect_app/src/main/java/org/odk/collect/android/tasks/InstanceServerUploader.java b/collect_app/src/main/java/org/odk/collect/android/tasks/InstanceServerUploader.java index 47f4e7cdd..56cb5bc8b 100644 --- a/collect_app/src/main/java/org/odk/collect/android/tasks/InstanceServerUploader.java +++ b/collect_app/src/main/java/org/odk/collect/android/tasks/InstanceServerUploader.java @@ -130,7 +130,7 @@ // private boolean uploadOneSubmission(String urlString, String id, String instanceFilePath, // Uri toUpdate, HttpContext localContext, Map uriRemap, Outcome outcome) { // -// Collect.getInstance().getActivityLogger().logAction(this, urlString, instanceFilePath); +// Collect.newInstance().getActivityLogger().logAction(this, urlString, instanceFilePath); // // File instanceFile = new File(instanceFilePath); // ContentValues cv = new ContentValues(); @@ -158,7 +158,7 @@ // Timber.i("Host name may not be null"); // outcome.messagesByInstanceId.put(id, FAIL + "Host name may not be null"); // cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); -// Collect.getInstance().getContentResolver().update(toUpdate, cv, null, null); +// Collect.newInstance().getContentResolver().update(toUpdate, cv, null, null); // return true; // } // @@ -172,7 +172,7 @@ // uri = URI.create(submissionUri.toString()); // } catch (IllegalArgumentException e) { // Timber.i(e); -// outcome.messagesByInstanceId.put(id, Collect.getInstance().getString(R.string.url_error)); +// outcome.messagesByInstanceId.put(id, Collect.newInstance().getString(R.string.url_error)); // return false; // } // @@ -190,7 +190,7 @@ // int statusCode = response.getStatusLine().getStatusCode(); // if (statusCode == HttpStatus.SC_UNAUTHORIZED) { // // clear the cookies -- should not be necessary? -// Collect.getInstance().getCookieStore().clear(); +// Collect.newInstance().getCookieStore().clear(); // // WebUtils.discardEntityBytes(response); // // we need authentication, so stop and return what we've @@ -227,7 +227,7 @@ // + newURI.toString()); // cv.put(InstanceColumns.STATUS, // InstanceProviderAPI.STATUS_SUBMISSION_FAILED); -// Collect.getInstance().getContentResolver() +// Collect.newInstance().getContentResolver() // .update(toUpdate, cv, null, null); // return true; // } @@ -236,7 +236,7 @@ // outcome.messagesByInstanceId.put(id, FAIL + urlString + " " + e.toString()); // cv.put(InstanceColumns.STATUS, // InstanceProviderAPI.STATUS_SUBMISSION_FAILED); -// Collect.getInstance().getContentResolver() +// Collect.newInstance().getContentResolver() // .update(toUpdate, cv, null, null); // return true; // } @@ -255,7 +255,7 @@ // + "web proxy, you may need to login to your network. "); // cv.put(InstanceColumns.STATUS, // InstanceProviderAPI.STATUS_SUBMISSION_FAILED); -// Collect.getInstance().getContentResolver() +// Collect.newInstance().getContentResolver() // .update(toUpdate, cv, null, null); // return true; // } @@ -278,7 +278,7 @@ // Timber.i(e, "Network Connection Refused"); // } // cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); -// Collect.getInstance().getContentResolver().update(toUpdate, cv, null, null); +// Collect.newInstance().getContentResolver().update(toUpdate, cv, null, null); // return true; // } catch (Exception e) { // String msg = e.getMessage(); @@ -288,7 +288,7 @@ // outcome.messagesByInstanceId.put(id, FAIL + "Generic Exception: " + msg); // Timber.e(e); // cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); -// Collect.getInstance().getContentResolver().update(toUpdate, cv, null, null); +// Collect.newInstance().getContentResolver().update(toUpdate, cv, null, null); // return true; // } // } @@ -323,7 +323,7 @@ // if (!instanceFile.exists() && !submissionFile.exists()) { // outcome.messagesByInstanceId.put(id, FAIL + "instance XML file does not exist!"); // cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); -// Collect.getInstance().getContentResolver().update(toUpdate, cv, null, null); +// Collect.newInstance().getContentResolver().update(toUpdate, cv, null, null); // return true; // } // @@ -448,7 +448,7 @@ // outcome.messagesByInstanceId.put(id, FAIL + "Network login failure? Again?"); // } else if (responseCode == HttpStatus.SC_UNAUTHORIZED) { // // clear the cookies -- should not be necessary? -// Collect.getInstance().getCookieStore().clear(); +// Collect.newInstance().getCookieStore().clear(); // outcome.messagesByInstanceId.put(id, FAIL + response.getStatusLine().getReasonPhrase() // + " (" + responseCode + ") at " + urlString); // } else { @@ -463,7 +463,7 @@ // } // cv.put(InstanceColumns.STATUS, // InstanceProviderAPI.STATUS_SUBMISSION_FAILED); -// Collect.getInstance().getContentResolver() +// Collect.newInstance().getContentResolver() // .update(toUpdate, cv, null, null); // return true; // } @@ -481,7 +481,7 @@ // } // outcome.messagesByInstanceId.put(id, FAIL + "Generic Exception: " + msg); // cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); -// Collect.getInstance().getContentResolver().update(toUpdate, cv, null, null); +// Collect.newInstance().getContentResolver().update(toUpdate, cv, null, null); // return true; // } // } @@ -491,11 +491,11 @@ // outcome.messagesByInstanceId.put(id, messageParser.getMessageResponse()); // } else { // // Default messaging -// outcome.messagesByInstanceId.put(id, Collect.getInstance().getString(R.string.success)); +// outcome.messagesByInstanceId.put(id, Collect.newInstance().getString(R.string.success)); // } // // cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMITTED); -// Collect.getInstance().getContentResolver().update(toUpdate, cv, null, null); +// Collect.newInstance().getContentResolver().update(toUpdate, cv, null, null); // return true; // } // @@ -518,11 +518,11 @@ // selectionBuf.append(")"); // String selection = selectionBuf.toString(); // -// String deviceId = new PropertyManager(Collect.getInstance().getApplicationContext()) +// String deviceId = new PropertyManager(Collect.newInstance().getApplicationContext()) // .getSingularProperty(PropertyManager.withUri(PropertyManager.PROPMGR_DEVICE_ID)); // // // get shared HttpContext so that authentication and cookies are retained. -// HttpContext localContext = Collect.getInstance().getHttpContext(); +// HttpContext localContext = Collect.newInstance().getHttpContext(); // // Map uriRemap = new HashMap(); // @@ -590,10 +590,10 @@ // // private String getServerSubmissionURL() { // -// Collect app = Collect.getInstance(); +// Collect app = Collect.newInstance(); // // SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences( -// Collect.getInstance()); +// Collect.newInstance()); // String serverBase = settings.getString(PreferenceKeys.KEY_SERVER_URL, // app.getString(R.string.default_server_url)); // 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 7dc1cc9c3..aa119d276 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 @@ -262,7 +262,7 @@ public static String getFormattedDate(String format, long time) { try { Date date = new Date(); date.setTime(time); - return new SimpleDateFormat(format).format(date); + return new SimpleDateFormat(format,Locale.getDefault()).format(date); } catch (Exception e) { Timber.e(e); return String.valueOf(time); diff --git a/collect_app/src/main/java/org/odk/collect/android/utilities/PRNGFixes.java b/collect_app/src/main/java/org/odk/collect/android/utilities/PRNGFixes.java index a26fa902f..90b1adaa2 100644 --- a/collect_app/src/main/java/org/odk/collect/android/utilities/PRNGFixes.java +++ b/collect_app/src/main/java/org/odk/collect/android/utilities/PRNGFixes.java @@ -116,7 +116,7 @@ private static void installLinuxPRNGSecureRandom() } // Assert that new SecureRandom() and - // SecureRandom.getInstance("SHA1PRNG") return a SecureRandom backed + // SecureRandom.newInstance("SHA1PRNG") return a SecureRandom backed // by the Linux PRNG-based SecureRandom implementation. SecureRandom rng1 = new SecureRandom(); if (!LinuxPRNGSecureRandomProvider.class.equals( @@ -135,7 +135,7 @@ private static void installLinuxPRNGSecureRandom() if (!LinuxPRNGSecureRandomProvider.class.equals( rng2.getProvider().getClass())) { throw new SecurityException( - "SecureRandom.getInstance(\"SHA1PRNG\") backed by wrong" + "SecureRandom.newInstance(\"SHA1PRNG\") backed by wrong" + " Provider: " + rng2.getProvider().getClass()); } } diff --git a/config/pmd-ruleset.xml b/config/pmd-ruleset.xml index 0c2a2e443..d36c3941c 100644 --- a/config/pmd-ruleset.xml +++ b/config/pmd-ruleset.xml @@ -90,31 +90,33 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + +