Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Commit

Permalink
Resolves pmd errorprone violation (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
konishon committed Oct 15, 2019
1 parent a2644ba commit 8fc4183
Show file tree
Hide file tree
Showing 29 changed files with 108 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* separately check the option to navigate with either swipes or buttons:
*
* <code>
* String navigation = (String) GeneralSharedPreferences.getInstance().get(GeneralKeys.KEY_NAVIGATION);
* String navigation = (String) GeneralSharedPreferences.newInstance().get(GeneralKeys.KEY_NAVIGATION);
* showNavigationButtons = navigation.contains(GeneralKeys.NAVIGATION_BUTTONS);
* </code>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@ public LongSparseArray(int initialCapacity) {

@Override
@SuppressWarnings("unchecked")
public LongSparseArray<E> clone() {
public LongSparseArray<E> clone() throws CloneNotSupportedException {
LongSparseArray<E> clone = null;
try {
clone = (LongSparseArray<E>) super.clone();
clone.mKeys = mKeys.clone();
clone.mValues = mValues.clone();
} catch (CloneNotSupportedException cnse) {
/* ignore */
}

clone = (LongSparseArray<E>) super.clone();
clone.mKeys = mKeys.clone();
clone.mValues = mValues.clone();

return clone;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -35,8 +30,6 @@

public class EducationalMaterialRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

private static final String TAG = "Education Material";
// The items to display in your RecyclerView
private final List<Object> items;

private static final int TEXT_VIEW = 0, IMAGE = 1, VIDEO = 2, PDF = 3;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 += "}";
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import static org.fieldsight.naxa.common.AnimationUtils.getRotationAnimation;

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public SyncableItem apply(Integer integer) {
// public ObservableSource<SyncableItem> 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);
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void fetchGeneralForms() {
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
// ProjectSitesRemoteSource
// .getInstance()
// .newInstance()
// .fetchProjecSites()
.flatMap((Function<List<Project>, SingleSource<?>>) projects -> {
/*note:
Expand Down Expand Up @@ -106,7 +106,7 @@ public void fetchScheduledForms() {
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
// ProjectSitesRemoteSource
// .getInstance()
// .newInstance()
// .fetchProjecSites()
.flatMap((Function<List<Project>, Single<List<DownloadProgress>>>) projects -> {
/*note:
Expand Down Expand Up @@ -150,7 +150,7 @@ public void onError(Throwable e) {
public void fetchStagedForms() {

// ProjectSitesRemoteSource
// .getInstance()
// .newInstance()
// .fetchProjecSites()
ProjectLocalSource.getInstance()
.getProjectsMaybe()
Expand Down Expand Up @@ -241,7 +241,7 @@ public void fetchAllForms() {
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
// ProjectSitesRemoteSource
// .getInstance()
// .newInstance()
// .fetchProjecSites()
.flatMap((Function<List<Project>, SingleSource<List<DownloadProgress>>>) projects -> {
/*note:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
//
// private ArrayList<GeoPoint> 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);
Expand All @@ -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;
// }
Expand Down Expand Up @@ -144,7 +144,7 @@
//
//
//
// SiteLocalSource.getInstance().getByIdAsSingle(loadedProject.getId())
// SiteLocalSource.newInstance().getByIdAsSingle(loadedProject.getId())
// .toObservable()
// .flatMapIterable((Function<List<Site>, Iterable<Site>>) sites -> sites)
// .flatMap((Function<Site, ObservableSource<GeoPoint>>) site -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import okhttp3.ResponseBody;
import timber.log.Timber;

@SuppressWarnings({"PMD.SingleMethodSingleton"})
public class ProjectRepository implements BaseRepository<Project> {

private static ProjectRepository projectRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import static org.fieldsight.naxa.common.AnimationUtils.getRotationAnimation;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,10 @@ private void setViewpager() {


ArrayList<Fragment> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public DownloadableItem apply(Integer integer) {
// public ObservableSource<SyncableItem> 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);
// }
Expand Down
Loading

0 comments on commit 8fc4183

Please sign in to comment.