Lint issues (#2114)

* Dangling Javadoc comments

* Replace for loop with foreach

* Explicit type can be replaced with <>

* Anonymous type can be replaced with lambda

* Lambda can be replaced with method reference

* Remove redundant methods

* Use capital L for long literals

* Remove unnecessary StringBuilder
This commit is contained in:
Adam Jones 2018-12-21 11:09:04 +00:00 committed by neslihanturan
parent 8e967a3698
commit f04503bb3e
26 changed files with 214 additions and 295 deletions

View file

@ -143,7 +143,7 @@ public class AboutActivity extends NavigationBaseActivity {
@OnClick(R.id.about_translate)
public void launchTranslate(View view) {
final ArrayAdapter<String> languageAdapter = new ArrayAdapter<String>(AboutActivity.this,
final ArrayAdapter<String> languageAdapter = new ArrayAdapter<>(AboutActivity.this,
android.R.layout.simple_spinner_dropdown_item, language);
final Spinner spinner = new Spinner(AboutActivity.this);
spinner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));

View file

@ -7,7 +7,7 @@ import java.util.HashMap;
*/
public class TokensTranslations {
HashMap<String,String> translationToken = new HashMap<String,String>();
HashMap<String,String> translationToken = new HashMap<>();
public void initailize() {
translationToken.put("Kazakh", "ab");

View file

@ -104,17 +104,14 @@ public class AchievementsActivity extends NavigationBaseActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_achievements);
ButterKnife.bind(this);
/**
* DisplayMetrics used to fetch the size of the screen
*/
// DisplayMetrics used to fetch the size of the screen
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
/**
* Used for the setting the size of imageView at runtime
*/
// Used for the setting the size of imageView at runtime
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)
imageView.getLayoutParams();
params.height = (int) (height * BADGE_IMAGE_HEIGHT_RATIO);
@ -130,7 +127,7 @@ public class AchievementsActivity extends NavigationBaseActivity {
}
/**
* to invoke the AlertDialog on clicking info button
* To invoke the AlertDialog on clicking info button
*/
@OnClick(R.id.achievement_info)
public void showInfoDialog(){
@ -159,7 +156,6 @@ public class AchievementsActivity extends NavigationBaseActivity {
/**
* To take bitmap and store it temporary storage and share it
*
* @param bitmap
*/
void shareScreen(Bitmap bitmap) {

View file

@ -76,14 +76,7 @@ public class BookmarkLocationsFragment extends DaggerFragment {
super.onViewCreated(view, savedInstanceState);
progressBar.setVisibility(View.VISIBLE);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(
adapterFactory.create(
new ArrayList<Place>(),
() -> {
initList();
}
)
);
recyclerView.setAdapter(adapterFactory.create(new ArrayList<>(), this::initList));
}
@Override

View file

@ -32,7 +32,7 @@ public class BookmarkPicturesController {
List<Media> loadBookmarkedPictures() {
List<Bookmark> bookmarks = bookmarkDao.getAllBookmarks();
currentBookmarks = bookmarks;
ArrayList<Media> medias = new ArrayList<Media>();
ArrayList<Media> medias = new ArrayList<>();
for (Bookmark bookmark : bookmarks) {
List<Media> tmpMedias = mediaWikiApi.searchImages(bookmark.getMediaName(), 0);
for (Media m : tmpMedias) {

View file

@ -165,14 +165,10 @@ public class ContributionsFragment
nearbyNoificationCardView = view.findViewById(R.id.card_view_nearby);
checkBoxView = View.inflate(getActivity(), R.layout.nearby_permission_dialog, null);
checkBox = (CheckBox) checkBoxView.findViewById(R.id.never_ask_again);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
// Do not ask for permission on activity start again
prefs.edit().putBoolean("displayLocationPermissionForCardView",false).apply();
}
checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
// Do not ask for permission on activity start again
prefs.edit().putBoolean("displayLocationPermissionForCardView",false).apply();
}
});
@ -388,8 +384,8 @@ public class ContributionsFragment
DialogUtil.showAlertDialog(getActivity(),
getString(R.string.nearby_card_permission_title),
getString(R.string.nearby_card_permission_explanation),
() -> displayYouWontSeeNearbyMessage(),
() -> enableLocationPermission(),
this::displayYouWontSeeNearbyMessage,
this::enableLocationPermission,
checkBoxView,
false);
}
@ -505,11 +501,6 @@ public class ContributionsFragment
((MainActivity)getActivity()).updateNotificationIcon(isThereUnreadNotifications);
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onPause() {
super.onPause();
@ -564,8 +555,8 @@ public class ContributionsFragment
DialogUtil.showAlertDialog(getActivity(),
getString(R.string.nearby_card_permission_title),
getString(R.string.nearby_card_permission_explanation),
() -> displayYouWontSeeNearbyMessage(),
() -> enableGPS(),
this::displayYouWontSeeNearbyMessage,
this::enableGPS,
checkBoxView,
false);
}
@ -588,8 +579,8 @@ public class ContributionsFragment
DialogUtil.showAlertDialog(getActivity(),
getString(R.string.nearby_card_permission_title),
getString(R.string.nearby_card_permission_explanation),
() -> displayYouWontSeeNearbyMessage(),
() -> enableLocationPermission(),
this::displayYouWontSeeNearbyMessage,
this::enableLocationPermission,
checkBoxView,
false);
}

View file

@ -43,6 +43,7 @@ import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static android.app.Activity.RESULT_OK;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.view.View.*;
import static android.view.View.GONE;
import static fr.free.nrw.commons.contributions.ContributionController.SELECT_FROM_GALLERY;
@ -118,7 +119,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment {
}
public void changeEmptyScreen(boolean isEmpty){
this.noDataYet.setVisibility(isEmpty ? View.VISIBLE : View.GONE);
this.noDataYet.setVisibility(isEmpty ? VISIBLE : GONE);
}
private void initializeAnimations() {
@ -131,92 +132,84 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment {
private void setListeners() {
fabPlus.setOnClickListener(view -> animateFAB(isFabOpen));
fabCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean useExtStorage = defaultPrefs.getBoolean("useExternalStorage", true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && useExtStorage) {
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(getActivity(), WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
if (shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
new AlertDialog.Builder(getParentFragment().getActivity())
.setMessage(getString(R.string.write_storage_permission_rationale))
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
getActivity().requestPermissions
(new String[]{WRITE_EXTERNAL_STORAGE}, PermissionUtils.CAMERA_PERMISSION_FROM_CONTRIBUTION_LIST);
dialog.dismiss();
})
.setNegativeButton(android.R.string.cancel, null)
.create()
.show();
} else {
// No explanation needed, we can request the permission.
requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE},
3);
// MY_PERMISSIONS_WRITE_EXTERNAL_STORAGE is an
// app-defined int constant. The callback method gets the
// result of the request.
}
fabCamera.setOnClickListener(view -> {
boolean useExtStorage = defaultPrefs.getBoolean("useExternalStorage", true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && useExtStorage) {
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(getActivity(), WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
if (shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
new AlertDialog.Builder(getParentFragment().getActivity())
.setMessage(getString(R.string.write_storage_permission_rationale))
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
getActivity().requestPermissions
(new String[]{WRITE_EXTERNAL_STORAGE}, PermissionUtils.CAMERA_PERMISSION_FROM_CONTRIBUTION_LIST);
dialog.dismiss();
})
.setNegativeButton(android.R.string.cancel, null)
.create()
.show();
} else {
controller.startCameraCapture();
// No explanation needed, we can request the permission.
requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE},
3);
// MY_PERMISSIONS_WRITE_EXTERNAL_STORAGE is an
// app-defined int constant. The callback method gets the
// result of the request.
}
} else {
controller.startCameraCapture();
}
} else {
controller.startCameraCapture();
}
});
fabGalery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Gallery crashes before reach ShareActivity screen so must implement permissions check here
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
fabGalery.setOnClickListener(view -> {
//Gallery crashes before reach ShareActivity screen so must implement permissions check here
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(getActivity(),
READ_EXTERNAL_STORAGE)
!= PERMISSION_GRANTED) {
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(getActivity(), READ_EXTERNAL_STORAGE)
!= PERMISSION_GRANTED) {
// Should we show an explanation?
if (shouldShowRequestPermissionRationale(READ_EXTERNAL_STORAGE)) {
// Should we show an explanation?
if (shouldShowRequestPermissionRationale(READ_EXTERNAL_STORAGE)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
new AlertDialog.Builder(getParentFragment().getActivity())
.setMessage(getString(R.string.read_storage_permission_rationale))
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
getActivity().requestPermissions
(new String[]{READ_EXTERNAL_STORAGE}, PermissionUtils.GALLERY_PERMISSION_FROM_CONTRIBUTION_LIST);
dialog.dismiss();
})
.setNegativeButton(android.R.string.cancel, null)
.create()
.show();
new AlertDialog.Builder(getParentFragment().getActivity())
.setMessage(getString(R.string.read_storage_permission_rationale))
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
getActivity().requestPermissions
(new String[]{READ_EXTERNAL_STORAGE}, PermissionUtils.GALLERY_PERMISSION_FROM_CONTRIBUTION_LIST);
dialog.dismiss();
})
.setNegativeButton(android.R.string.cancel, null)
.create()
.show();
} else {
// No explanation needed, we can request the permission.
requestPermissions(new String[]{READ_EXTERNAL_STORAGE},
1);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
} else {
controller.startGalleryPick();
}
// No explanation needed, we can request the permission.
requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, 1);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
} else {
controller.startGalleryPick();
}
} else {
controller.startGalleryPick();
}
});
}
@ -309,7 +302,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
&& data.getClipData() != null) {
ClipData mClipData = data.getClipData();
ArrayList<Uri> mArrayUri = new ArrayList<Uri>();
ArrayList<Uri> mArrayUri = new ArrayList<>();
for (int i = 0; i < mClipData.getItemCount(); i++) {
ClipData.Item item = mClipData.getItemAt(i);
@ -329,7 +322,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment {
* @param isVisible True when contributions list should be hidden.
*/
public void changeProgressBarVisibility(boolean isVisible) {
this.progressBar.setVisibility(isVisible ? View.VISIBLE : View.GONE);
this.progressBar.setVisibility(isVisible ? VISIBLE : GONE);
}
/**

View file

@ -123,18 +123,15 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
ImageView nearbyInfo = nearbyTabLinearLayout.findViewById(R.id.nearby_info_image);
tabLayout.getTabAt(1).setCustomView(nearbyTabLinearLayout);
nearbyInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
nearbyInfo.setOnClickListener(view ->
new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.title_activity_nearby)
.setMessage(R.string.showcase_view_whole_nearby_activity)
.setCancelable(true)
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
.create()
.show();
}
});
.setTitle(R.string.title_activity_nearby)
.setMessage(R.string.showcase_view_whole_nearby_activity)
.setCancelable(true)
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
.create()
.show()
);
if (uploadServiceIntent != null) {
// If auth cookie already acquired notify contrib fragmnet so that it san operate auth required actions
@ -378,10 +375,8 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
case 0:
ContributionsFragment retainedContributionsFragment = getContributionsFragment(0);
if (retainedContributionsFragment != null) {
/**
* ContributionsFragment is parent of ContributionsListFragment and
* MediaDetailsFragment. If below decides which child will be visible.
*/
// ContributionsFragment is parent of ContributionsListFragment and
// MediaDetailsFragment. If below decides which child will be visible.
if (isContributionsListFragment) {
retainedContributionsFragment.setContributionsListFragment();
} else {

View file

@ -64,7 +64,7 @@ public class ReasonBuilder {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
jsonObject -> appendArticlesUsed(jsonObject),
this::appendArticlesUsed,
t -> Timber.e(t, "Fetching achievements statistics failed")
));
}

View file

@ -213,10 +213,6 @@ public class SearchActivity extends NavigationBaseActivity implements MediaDetai
mediaDetails.showImage(index);
forceInitBackButton();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
/**
* This method is called on Screen Rotation

View file

@ -59,7 +59,7 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
recent_searches_text_view.setText(R.string.no_recent_searches);
Toast.makeText(getContext(),getString(R.string.search_history_deleted),Toast.LENGTH_SHORT).show();
recentSearches = recentSearchesDao.recentSearches(10);
adapter = new ArrayAdapter<String>(getContext(),R.layout.item_recent_searches, recentSearches);
adapter = new ArrayAdapter<>(getContext(), R.layout.item_recent_searches, recentSearches);
recentSearchesList.setAdapter(adapter);
adapter.notifyDataSetChanged();
dialog.dismiss();

View file

@ -31,15 +31,12 @@ public class CommonsLogSender extends LogsSender {
/**
* Attach any extra meta information about user or device that might help in debugging
* @return
* @return String with extra meta information useful for debugging
*/
@Override
protected String getExtraInfo() {
StringBuilder builder = new StringBuilder();
builder.append("App Version Name: ")
.append(BuildConfig.VERSION_NAME)
.append("\n");
return builder.toString();
return "App Version Name: " +
BuildConfig.VERSION_NAME +
"\n";
}
}

View file

@ -397,7 +397,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
@OnClick(R.id.nominateDeletion)
public void onDeleteButtonClicked(){
final ArrayAdapter<String> languageAdapter = new ArrayAdapter<String>(getActivity(),
final ArrayAdapter<String> languageAdapter = new ArrayAdapter<>(getActivity(),
R.layout.simple_spinner_dropdown_list, reasonList);
final Spinner spinner = new Spinner(getActivity());
spinner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
@ -407,28 +407,20 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(spinner);
builder.setTitle(R.string.nominate_delete)
.setPositiveButton(R.string.about_translate_proceed, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String reason = spinner.getSelectedItem().toString();
ReasonBuilder reasonBuilder = new ReasonBuilder(reason,
getActivity(),
media,
sessionManager,
mwApi);
reason = reasonBuilder.getReason();
DeleteTask deleteTask = new DeleteTask(getActivity(), media, reason);
deleteTask.execute();
isDeleted = true;
enableDeleteButton(false);
}
.setPositiveButton(R.string.about_translate_proceed, (dialog, which) -> {
String reason = spinner.getSelectedItem().toString();
ReasonBuilder reasonBuilder = new ReasonBuilder(reason,
getActivity(),
media,
sessionManager,
mwApi);
reason = reasonBuilder.getReason();
DeleteTask deleteTask = new DeleteTask(getActivity(), media, reason);
deleteTask.execute();
isDeleted = true;
enableDeleteButton(false);
});
builder.setNegativeButton(R.string.about_translate_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setNegativeButton(R.string.about_translate_cancel, (dialog, which) -> dialog.dismiss());
AlertDialog dialog = builder.create();
dialog.show();
if(isDeleted) {

View file

@ -779,7 +779,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
}
if (imageNodes == null) {
return new ArrayList<Media>();
return new ArrayList<>();
}
List<Media> images = new ArrayList<>();
@ -819,7 +819,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
}
if (categoryNodes == null) {
return new ArrayList<String>();
return new ArrayList<>();
}
List<String> categories = new ArrayList<>();

View file

@ -83,7 +83,7 @@ public class CustomApiResult {
public ArrayList<CustomApiResult> getNodes(String xpath) {
try {
ArrayList<CustomApiResult> results = new ArrayList<CustomApiResult>();
ArrayList<CustomApiResult> results = new ArrayList<>();
NodeList nodes = (NodeList) evaluator.evaluate(xpath, doc, XPathConstants.NODESET);
for(int i = 0; i < nodes.getLength(); i++) {
results.add(new CustomApiResult(nodes.item(i)));

View file

@ -21,7 +21,7 @@ public class CustomMwApi {
private CustomMwApi api;
RequestBuilder(CustomMwApi api) {
params = new HashMap<String, Object>();
params = new HashMap<>();
this.api = api;
}

View file

@ -795,11 +795,6 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
wikidataEditListener.setAuthenticationStateListener(null);
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onPause() {
super.onPause();

View file

@ -186,13 +186,6 @@ public class NearbyMapFragment extends DaggerFragment {
setRetainInstance(true);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -328,8 +321,8 @@ public class NearbyMapFragment extends DaggerFragment {
mapboxMap.addPolygon(currentLocationPolygonOptions);
}
// Make camera to follow user on location change
CameraPosition position ;
// Make camera to follow user on location change
CameraPosition position ;
// Do not update camera position is search this area mode on
if (!searchThisAreaModeOn) {
@ -538,13 +531,10 @@ public class NearbyMapFragment extends DaggerFragment {
mapView = new MapView(getParentFragment().getActivity(), options);
// create map
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
NearbyMapFragment.this.mapboxMap = mapboxMap;
addMapMovementListeners();
updateMapSignificantlyForCurrentLocation();
}
mapView.getMapAsync(mapboxMap -> {
NearbyMapFragment.this.mapboxMap = mapboxMap;
addMapMovementListeners();
updateMapSignificantlyForCurrentLocation();
});
mapView.setStyleUrl("asset://mapstyle.json");
}
@ -556,63 +546,53 @@ public class NearbyMapFragment extends DaggerFragment {
*/
private void addMapMovementListeners() {
mapboxMap.addOnCameraMoveListener(new MapboxMap.OnCameraMoveListener() {
mapboxMap.addOnCameraMoveListener(() -> {
@Override
public void onCameraMove() {
if (NearbyController.currentLocation != null) { // If our nearby markers are calculated at least once
if (NearbyController.currentLocation != null) { // If our nearby markers are calculated at least once
if (searchThisAreaButton.getVisibility() == View.GONE) {
searchThisAreaButton.setVisibility(View.VISIBLE);
}
double distance = mapboxMap.getCameraPosition().target
.distanceTo(new LatLng(NearbyController.currentLocation.getLatitude()
, NearbyController.currentLocation.getLongitude()));
if (searchThisAreaButton.getVisibility() == View.GONE) {
searchThisAreaButton.setVisibility(View.VISIBLE);
}
double distance = mapboxMap.getCameraPosition().target
.distanceTo(new LatLng(NearbyController.currentLocation.getLatitude()
, NearbyController.currentLocation.getLongitude()));
if (distance > NearbyController.searchedRadius*1000*3/4) { //Convert to meter, and compare if our distance is bigger than 3/4 or our searched area
checkingAround = true;
if (!searchThisAreaModeOn) { // If we are changing mode, then change click action
if (distance > NearbyController.searchedRadius*1000*3/4) { //Convert to meter, and compare if our distance is bigger than 3/4 or our searched area
checkingAround = true;
if (!searchThisAreaModeOn) { // If we are changing mode, then change click action
searchThisAreaModeOn = true;
searchThisAreaButton.setOnClickListener(view -> {
searchThisAreaModeOn = true;
searchThisAreaButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
searchThisAreaModeOn = true;
// Lock map operations during search this area operation
mapboxMap.getUiSettings().setAllGesturesEnabled(false);
searchThisAreaButtonProgressBar.setVisibility(View.VISIBLE);
searchThisAreaButton.setVisibility(View.GONE);
searchedAroundCurrentLocation = false;
((NearbyFragment)getParentFragment())
.refreshViewForCustomLocation(LocationUtils
.mapBoxLatLngToCommonsLatLng(mapboxMap.getCameraPosition().target), false);
}
});
}
} else {
checkingAround = false;
if (searchThisAreaModeOn) {
searchThisAreaModeOn = false; // This flag will help us to understand should we folor users location or not
searchThisAreaButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
searchThisAreaModeOn = true;
// Lock map operations during search this area operation
mapboxMap.getUiSettings().setAllGesturesEnabled(false);
searchThisAreaButtonProgressBar.setVisibility(View.VISIBLE);
fabRecenter.callOnClick();
searchThisAreaButton.setVisibility(View.GONE);
searchedAroundCurrentLocation = true;
((NearbyFragment)getParentFragment())
.refreshViewForCustomLocation(LocationUtils
.mapBoxLatLngToCommonsLatLng(mapboxMap.getCameraPosition().target), true);
}
});
}
if (searchedAroundCurrentLocation) {
// Lock map operations during search this area operation
mapboxMap.getUiSettings().setAllGesturesEnabled(false);
searchThisAreaButtonProgressBar.setVisibility(View.VISIBLE);
searchThisAreaButton.setVisibility(View.GONE);
}
searchedAroundCurrentLocation = false;
((NearbyFragment)getParentFragment())
.refreshViewForCustomLocation(LocationUtils
.mapBoxLatLngToCommonsLatLng(mapboxMap.getCameraPosition().target), false);
});
}
} else {
checkingAround = false;
if (searchThisAreaModeOn) {
searchThisAreaModeOn = false; // This flag will help us to understand should we folor users location or not
searchThisAreaButton.setOnClickListener(view -> {
searchThisAreaModeOn = true;
// Lock map operations during search this area operation
mapboxMap.getUiSettings().setAllGesturesEnabled(false);
searchThisAreaButtonProgressBar.setVisibility(View.VISIBLE);
fabRecenter.callOnClick();
searchThisAreaButton.setVisibility(View.GONE);
searchedAroundCurrentLocation = true;
((NearbyFragment)getParentFragment())
.refreshViewForCustomLocation(LocationUtils
.mapBoxLatLngToCommonsLatLng(mapboxMap.getCameraPosition().target), true);
});
}
if (searchedAroundCurrentLocation) {
searchThisAreaButton.setVisibility(View.GONE);
}
}
}
@ -785,8 +765,8 @@ public class NearbyMapFragment extends DaggerFragment {
}
/*
* We are not able to hide FABs without removing anchors, this method removes anchors
* */
* We are not able to hide FABs without removing anchors, this method removes anchors
* */
private void removeAnchorFromFABs(FloatingActionButton floatingActionButton) {
//get rid of anchors
//Somehow this was the only way https://stackoverflow.com/questions/32732932
@ -808,12 +788,12 @@ public class NearbyMapFragment extends DaggerFragment {
addAnchorToSmallFABs(fabGallery, ((NearbyFragment)getParentFragment()).view.findViewById(R.id.empty_view).getId());
addAnchorToSmallFABs(fabCamera, ((NearbyFragment)getParentFragment()).view.findViewById(R.id.empty_view1).getId());
}
}
/*
* Add anchors back before making them visible again.
* */
* Add anchors back before making them visible again.
* */
private void addAnchorToBigFABs(FloatingActionButton floatingActionButton, int anchorID) {
CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams
(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
@ -823,9 +803,9 @@ public class NearbyMapFragment extends DaggerFragment {
}
/*
* Add anchors back before making them visible again. Big and small fabs have different anchor
* gravities, therefore the are two methods.
* */
* Add anchors back before making them visible again. Big and small fabs have different anchor
* gravities, therefore the are two methods.
* */
private void addAnchorToSmallFABs(FloatingActionButton floatingActionButton, int anchorID) {
CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams
(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
@ -964,7 +944,7 @@ public class NearbyMapFragment extends DaggerFragment {
* @param isFabOpen state of FAB buttons, open when clicked on fab button, closed on other click
*/
private void animateFAB(boolean isFabOpen) {
this.isFabOpen = !isFabOpen;
this.isFabOpen = !isFabOpen;
if (fabPlus.isShown()){
if (isFabOpen) {
fabPlus.startAnimation(rotate_backward);
@ -1073,4 +1053,3 @@ public class NearbyMapFragment extends DaggerFragment {
}
}
}

View file

@ -146,10 +146,10 @@ public class NearbyNoificationCardView extends SwipableCardView {
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
if (visibility == VISIBLE) {
/**
* Sometimes we need to preserve previous state of notification card view without getting
* any data from user. Ie. wen user came back from Media Details fragment to Contrib List
* fragment, we need to know what was the state of card view, and set it to exact same state.
/*
Sometimes we need to preserve previous state of notification card view without getting
any data from user. Ie. wen user came back from Media Details fragment to Contrib List
fragment, we need to know what was the state of card view, and set it to exact same state.
*/
switch (cardViewVisibilityState) {
case READY:

View file

@ -31,7 +31,7 @@ public class QuizActivity extends AppCompatActivity {
@BindView(R.id.toolbar) Toolbar toolbar;
private QuizController quizController = new QuizController();
private ArrayList<QuizQuestion> quiz = new ArrayList<QuizQuestion>();
private ArrayList<QuizQuestion> quiz = new ArrayList<>();
private int questionIndex = 0;
private int score;

View file

@ -11,7 +11,7 @@ import fr.free.nrw.commons.R;
*/
public class QuizController {
ArrayList<QuizQuestion> quiz = new ArrayList<QuizQuestion>();
ArrayList<QuizQuestion> quiz = new ArrayList<>();
private final String URL_FOR_SELFIE = "https://i.imgur.com/0fMYcpM.jpg";
private final String URL_FOR_TAJ_MAHAL = "https://upload.wikimedia.org/wikipedia/commons/1/15/Taj_Mahal-03.jpg";

View file

@ -93,12 +93,7 @@ public abstract class NavigationBaseActivity extends BaseActivity
public void changeDrawerIconToBakcButton() {
toggle.setDrawerIndicatorEnabled(false);
toggle.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white);
toggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});
toggle.setToolbarNavigationClickListener(view -> onBackPressed());
}
public void changeDrawerIconToDefault() {

View file

@ -34,16 +34,6 @@ public class CustomEditText extends EditText {
super(context, attrs, defStyle);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
}
@Override
public void setCompoundDrawables(Drawable left, Drawable top,
Drawable right, Drawable bottom) {
@ -97,7 +87,7 @@ public class CustomEditText extends EditText {
y = actionY;
if (!bounds.contains(actionX, actionY)) {
/** Gives the +20 area for tapping. */
// Gives the +20 area for tapping.
x = (int) (actionX - extraTapArea);
y = (int) (actionY - extraTapArea);
@ -106,7 +96,7 @@ public class CustomEditText extends EditText {
if (y <= 0)
y = actionY;
/** Creates square from the smallest value */
// Creates square from the smallest value
if (x < y) {
y = x;
}
@ -129,18 +119,19 @@ public class CustomEditText extends EditText {
int x, y;
int extraTapArea = 13;
/**
* IF USER CLICKS JUST OUT SIDE THE RECTANGLE OF THE DRAWABLE
* THAN ADD X AND SUBTRACT THE Y WITH SOME VALUE SO THAT AFTER
* CALCULATING X AND Y CO-ORDINATE LIES INTO THE DRAWBABLE
* BOUND. - this process help to increase the tappable area of
* the rectangle.
/*
IF USER CLICKS JUST OUT SIDE THE RECTANGLE OF THE DRAWABLE
THAN ADD X AND SUBTRACT THE Y WITH SOME VALUE SO THAT AFTER
CALCULATING X AND Y CO-ORDINATE LIES INTO THE DRAWBABLE
BOUND. - this process help to increase the tappable area of
the rectangle.
*/
x = (int) (actionX + extraTapArea);
y = (int) (actionY - extraTapArea);
/**Since this is right drawable subtract the value of x from the width
* of view. so that width - tappedarea will result in x co-ordinate in drawable bound.
/*
Since this is right drawable subtract the value of x from the width
of view. so that width - tappedarea will result in x co-ordinate in drawable bound.
*/
x = getWidth() - x;
@ -156,13 +147,13 @@ public class CustomEditText extends EditText {
/* If result after calculating for extra tappable area is negative.
* assign the original value so that after subtracting
* extratapping area value doesn't go into negative value.
* extra tapping area value doesn't go into negative value.
*/
if (y <= 0)
y = actionY;
/**If drawble bounds contains the x and y points then move ahead.*/
// If drawble bounds contains the x and y points then move ahead.
if (bounds.contains(x, y) && clickListener != null) {
clickListener
.onClick(DrawableClickListener.DrawablePosition.RIGHT);

View file

@ -38,7 +38,14 @@ import timber.log.Timber;
public class UploadModel {
private MediaWikiApi mwApi;
private static UploadItem DUMMY = new UploadItem(Uri.EMPTY, "", "", GPSExtractor.DUMMY, "", null,-1l) {
private static UploadItem DUMMY = new UploadItem(
Uri.EMPTY,
"",
"",
GPSExtractor.DUMMY,
"",
null,
-1L) {
};
private final SharedPreferences prefs;
private final List<String> licenses;
@ -175,12 +182,12 @@ public class UploadModel {
}
//Content provider contracts for opening gallery from the app and that by sharing from gallery from outside are different and we need to handle both the cases
int lastModifiedColumnIndex = cursor.getColumnIndex("last_modified");//If gallery is opened from in app
if(lastModifiedColumnIndex==-1){
lastModifiedColumnIndex=cursor.getColumnIndex("datetaken");
if (lastModifiedColumnIndex == -1) {
lastModifiedColumnIndex = cursor.getColumnIndex("datetaken");
}
//If both the content providers do not give the data, lets leave it to Jesus
if(lastModifiedColumnIndex==-1){
return -1l;
if (lastModifiedColumnIndex == -1) {
return -1L;
}
cursor.moveToFirst();
return cursor.getLong(lastModifiedColumnIndex);
@ -337,7 +344,7 @@ public class UploadModel {
contribution.setTag("mimeType", item.mimeType);
contribution.setSource(item.source);
contribution.setContentProviderUri(item.mediaUri);
if (item.createdTimestamp != -1l) {
if (item.createdTimestamp != -1L) {
contribution.setDateCreated(new Date(item.createdTimestamp));
//Set the date only if you have it, else the upload service is gonna try it the other way
}

View file

@ -8,8 +8,8 @@ import java.util.Set;
*/
public class BiMap<K, V> {
private HashMap<K, V> map = new HashMap<K, V>();
private HashMap<V, K> inversedMap = new HashMap<V, K>();
private HashMap<K, V> map = new HashMap<>();
private HashMap<V, K> inversedMap = new HashMap<>();
public void put(K k, V v) {
map.put(k, v);

View file

@ -88,14 +88,13 @@ public class ContributionUtils {
*/
public static void emptyTemporaryDirectory() {
File dir = new File(TEMP_EXTERNAL_DIRECTORY);
if (dir.isDirectory())
{
if (dir.isDirectory()) {
String[] children = dir.list();
if (children != null && children.length >0) {
for (int i = 0; i < children.length; i++)
{
new File(dir, children[i]).delete();
}
if (children == null) return;
for (String child : children) {
new File(dir, child).delete();
}
}
}