mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Made a pass through the code to introduce lambdas / method references in the places the Android Studio suggested.
This commit is contained in:
parent
3824f31ef9
commit
4796557fb7
25 changed files with 206 additions and 374 deletions
|
|
@ -197,8 +197,8 @@ public class CommonsApplication extends Application {
|
|||
|
||||
AccountManager accountManager = AccountManager.get(this);
|
||||
Account[] allAccounts = accountManager.getAccountsByType(AccountUtil.accountType());
|
||||
for (int index = 0; index < allAccounts.length; index++) {
|
||||
accountManager.removeAccount(allAccounts[index], null, null);
|
||||
for (Account allAccount : allAccounts) {
|
||||
accountManager.removeAccount(allAccount, null, null);
|
||||
}
|
||||
|
||||
//TODO: fix preference manager
|
||||
|
|
|
|||
|
|
@ -27,12 +27,7 @@ public class WelcomeActivity extends BaseActivity {
|
|||
|
||||
pager.setAdapter(adapter);
|
||||
indicator.setViewPager(pager);
|
||||
adapter.setCallback(new WelcomePagerAdapter.Callback() {
|
||||
@Override
|
||||
public void onYesClicked() {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
adapter.setCallback(this::finish);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ import fr.free.nrw.commons.PageTitle;
|
|||
import fr.free.nrw.commons.contributions.ContributionsActivity;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.view.KeyEvent.KEYCODE_ENTER;
|
||||
import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
|
||||
|
||||
|
||||
public class LoginActivity extends AccountAuthenticatorActivity {
|
||||
|
||||
|
|
@ -63,18 +66,8 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
twoFactorEdit.addTextChangedListener(textWatcher);
|
||||
passwordEdit.setOnEditorActionListener(newLoginInputActionListener());
|
||||
|
||||
loginButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
performLogin();
|
||||
}
|
||||
});
|
||||
signupButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
signUp(v);
|
||||
}
|
||||
});
|
||||
loginButton.setOnClickListener(this::performLogin);
|
||||
signupButton.setOnClickListener(this::signUp);
|
||||
}
|
||||
|
||||
private class LoginTextWatcher implements TextWatcher {
|
||||
|
|
@ -98,20 +91,17 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
}
|
||||
|
||||
private TextView.OnEditorActionListener newLoginInputActionListener() {
|
||||
return new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
|
||||
return (textView, actionId, keyEvent) -> {
|
||||
if (loginButton.isEnabled()) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
performLogin();
|
||||
if (actionId == IME_ACTION_DONE) {
|
||||
performLogin(textView);
|
||||
return true;
|
||||
} else if ((keyEvent != null) && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
|
||||
performLogin();
|
||||
} else if ((keyEvent != null) && keyEvent.getKeyCode() == KEYCODE_ENTER) {
|
||||
performLogin(textView);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +132,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void performLogin() {
|
||||
private void performLogin(View view) {
|
||||
Timber.d("Login to start!");
|
||||
LoginTask task = getLoginTask();
|
||||
task.execute();
|
||||
|
|
|
|||
|
|
@ -409,12 +409,9 @@ public class CategorizationFragment extends Fragment {
|
|||
categoriesNotFoundView = (TextView) rootView.findViewById(R.id.categoriesNotFound);
|
||||
categoriesSkip = (TextView) rootView.findViewById(R.id.categoriesExplanation);
|
||||
|
||||
categoriesSkip.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
categoriesSkip.setOnClickListener(view -> {
|
||||
getActivity().onBackPressed();
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
|
||||
ArrayList<CategoryItem> items;
|
||||
|
|
@ -429,9 +426,7 @@ public class CategorizationFragment extends Fragment {
|
|||
categoriesAdapter = new CategoriesAdapter(getActivity(), items);
|
||||
categoriesList.setAdapter(categoriesAdapter);
|
||||
|
||||
categoriesList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int index, long id) {
|
||||
categoriesList.setOnItemClickListener((adapterView, view, index, id) -> {
|
||||
CheckedTextView checkedView = (CheckedTextView) view;
|
||||
CategoryItem item = (CategoryItem) adapterView.getAdapter().getItem(index);
|
||||
item.selected = !item.selected;
|
||||
|
|
@ -439,7 +434,6 @@ public class CategorizationFragment extends Fragment {
|
|||
if (item.selected) {
|
||||
updateCategoryCount(item.name);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
categoriesFilter.addTextChangedListener(textWatcher);
|
||||
|
|
@ -463,15 +457,12 @@ public class CategorizationFragment extends Fragment {
|
|||
if (rootView != null) {
|
||||
rootView.setFocusableInTouchMode(true);
|
||||
rootView.requestFocus();
|
||||
rootView.setOnKeyListener(new View.OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
rootView.setOnKeyListener((v, keyCode, event) -> {
|
||||
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
backButtonDialog();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -487,18 +478,10 @@ public class CategorizationFragment extends Fragment {
|
|||
|
||||
builder.setMessage("Are you sure you want to go back? The image will not have any categories saved.")
|
||||
.setTitle("Warning");
|
||||
builder.setPositiveButton("No", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
builder.setPositiveButton("No", (dialog, id) -> {
|
||||
//No need to do anything, user remains on categorization screen
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("Yes", (dialog, id) -> getActivity().finish());
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
|
|
@ -537,20 +520,12 @@ public class CategorizationFragment extends Fragment {
|
|||
|
||||
builder.setMessage("Images without categories are rarely usable. Are you sure you want to submit without selecting categories?")
|
||||
.setTitle("No Categories Selected");
|
||||
builder.setPositiveButton("No, go back", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
builder.setPositiveButton("No, go back", (dialog, id) -> {
|
||||
//Exit menuItem so user can select their categories
|
||||
return;
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("Yes, submit", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
builder.setNegativeButton("Yes, submit", (dialog, id) -> {
|
||||
//Proceed to submission
|
||||
onCategoriesSaveHandler.onCategoriesSave(selectedCategories);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
|
|
|
|||
|
|
@ -9,11 +9,8 @@ public class BackgroundPoolExceptionHandler implements ExceptionHandler {
|
|||
public void onException(@NonNull final Throwable t) {
|
||||
//Crash for debug build
|
||||
if (BuildConfig.DEBUG) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread thread = new Thread(() -> {
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,17 +11,13 @@ class ThreadFactoryMaker {
|
|||
private int count = 0;
|
||||
|
||||
@Override
|
||||
public Thread newThread(final Runnable runnable) {
|
||||
public Thread newThread(@NonNull final Runnable runnable) {
|
||||
count++;
|
||||
Runnable wrapperRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Runnable wrapperRunnable = () -> {
|
||||
Process.setThreadPriority(priority);
|
||||
runnable.run();
|
||||
}
|
||||
};
|
||||
Thread t = new Thread(wrapperRunnable, String.format("%s-%s", name, count));
|
||||
return t;
|
||||
return new Thread(wrapperRunnable, String.format("%s-%s", name, count));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import fr.free.nrw.commons.R;
|
|||
import fr.free.nrw.commons.nearby.NearbyActivity;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
public class ContributionsListFragment extends Fragment {
|
||||
|
|
@ -110,11 +111,11 @@ public class ContributionsListFragment extends Fragment {
|
|||
|
||||
// Here, thisActivity is the current activity
|
||||
if (ContextCompat.checkSelfPermission(getActivity(),
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
READ_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
|
||||
// Should we show an explanation?
|
||||
if (shouldShowRequestPermissionRationale(Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
||||
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
|
||||
|
|
@ -122,15 +123,9 @@ public class ContributionsListFragment extends Fragment {
|
|||
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage(getString(R.string.storage_permission_rationale))
|
||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
requestPermissions(
|
||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||
1);
|
||||
.setPositiveButton("OK", (dialog, which) -> {
|
||||
requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, 1);
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", null)
|
||||
.create()
|
||||
|
|
@ -140,7 +135,7 @@ public class ContributionsListFragment extends Fragment {
|
|||
|
||||
// No explanation needed, we can request the permission.
|
||||
|
||||
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||
requestPermissions(new String[]{READ_EXTERNAL_STORAGE},
|
||||
1);
|
||||
|
||||
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ import fr.free.nrw.commons.concurrency.BackgroundPoolExceptionHandler;
|
|||
import fr.free.nrw.commons.concurrency.ThreadPoolExecutorService;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class UploadCountClient {
|
||||
class UploadCountClient {
|
||||
private ThreadPoolExecutorService threadPoolExecutor;
|
||||
|
||||
public UploadCountClient() {
|
||||
UploadCountClient() {
|
||||
threadPoolExecutor = new ThreadPoolExecutorService.Builder("bg-pool")
|
||||
.setPoolSize(Runtime.getRuntime().availableProcessors())
|
||||
.setExceptionHandler(new BackgroundPoolExceptionHandler())
|
||||
|
|
@ -27,11 +27,9 @@ public class UploadCountClient {
|
|||
private static final String UPLOAD_COUNT_URL_TEMPLATE =
|
||||
"https://tools.wmflabs.org/urbanecmbot/uploadsbyuser/uploadsbyuser.py?user=%s";
|
||||
|
||||
public ListenableFuture<Integer> getUploadCount(final String userName) {
|
||||
ListenableFuture<Integer> getUploadCount(final String userName) {
|
||||
final SettableFuture<Integer> future = SettableFuture.create();
|
||||
threadPoolExecutor.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
threadPoolExecutor.schedule(() -> {
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(String.format(Locale.ENGLISH, UPLOAD_COUNT_URL_TEMPLATE,
|
||||
|
|
@ -50,7 +48,6 @@ public class UploadCountClient {
|
|||
Timber.e("Error getting upload count Error", e);
|
||||
future.setException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,12 +119,7 @@ public class MediaDetailFragment extends Fragment {
|
|||
licenseList = new LicenseList(getActivity());
|
||||
|
||||
// Progressively darken the image in the background when we scroll detail pane up
|
||||
scrollListener = new ViewTreeObserver.OnScrollChangedListener() {
|
||||
@Override
|
||||
public void onScrollChanged() {
|
||||
updateTheDarkness();
|
||||
}
|
||||
};
|
||||
scrollListener = this::updateTheDarkness;
|
||||
view.getViewTreeObserver().addOnScrollChangedListener(scrollListener);
|
||||
|
||||
// Layout layoutListener to size the spacer item relative to the available space.
|
||||
|
|
@ -280,15 +275,12 @@ public class MediaDetailFragment extends Fragment {
|
|||
|
||||
textView.setText(catName);
|
||||
if (categoriesLoaded && categoriesPresent) {
|
||||
textView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
textView.setOnClickListener(view -> {
|
||||
String selectedCategoryTitle = "Category:" + catName;
|
||||
Intent viewIntent = new Intent();
|
||||
viewIntent.setAction(Intent.ACTION_VIEW);
|
||||
viewIntent.setData(new PageTitle(selectedCategoryTitle).getCanonicalUri());
|
||||
startActivity(viewIntent);
|
||||
}
|
||||
});
|
||||
}
|
||||
return item;
|
||||
|
|
|
|||
|
|
@ -72,12 +72,7 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
|
|||
public Fragment getItem(int i) {
|
||||
if (i == 0) {
|
||||
// See bug https://code.google.com/p/android/issues/detail?id=27526
|
||||
pager.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getActivity().supportInvalidateOptionsMenu();
|
||||
}
|
||||
}, 5);
|
||||
pager.postDelayed(() -> getActivity().supportInvalidateOptionsMenu(), 5);
|
||||
}
|
||||
return MediaDetailFragment.forMedia(i, editable);
|
||||
}
|
||||
|
|
@ -100,14 +95,11 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
|
|||
final int pageNumber = savedInstanceState.getInt("current-page");
|
||||
// Adapter doesn't seem to be loading immediately.
|
||||
// Dear God, please forgive us for our sins
|
||||
view.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
view.postDelayed(() -> {
|
||||
pager.setAdapter(adapter);
|
||||
pager.setCurrentItem(pageNumber, false);
|
||||
getActivity().supportInvalidateOptionsMenu();
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}, 100);
|
||||
} else {
|
||||
pager.setAdapter(adapter);
|
||||
|
|
@ -196,13 +188,8 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !(ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
|
||||
Snackbar.make(getView(), R.string.storage_permission_rationale,
|
||||
Snackbar.LENGTH_INDEFINITE)
|
||||
.setAction(R.string.ok, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
ActivityCompat.requestPermissions(getActivity(),
|
||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
|
||||
}
|
||||
}).show();
|
||||
.setAction(R.string.ok, view -> ActivityCompat.requestPermissions(getActivity(),
|
||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1)).show();
|
||||
} else {
|
||||
final DownloadManager manager = (DownloadManager)getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
manager.enqueue(req);
|
||||
|
|
|
|||
|
|
@ -351,12 +351,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
@Override
|
||||
@NonNull
|
||||
public UploadResult uploadFile(String filename, InputStream file, long dataLength, String pageContents, String editSummary, final ProgressListener progressListener) throws IOException {
|
||||
ApiResult result = api.upload(filename, file, dataLength, pageContents, editSummary, new in.yuvi.http.fluent.ProgressListener() {
|
||||
@Override
|
||||
public void onProgress(long transferred, long total) {
|
||||
progressListener.onProgress(transferred, total);
|
||||
}
|
||||
});
|
||||
ApiResult result = api.upload(filename, file, dataLength, pageContents, editSummary, progressListener::onProgress);
|
||||
|
||||
Log.e("WTF", "Result: "+result.toString());
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package fr.free.nrw.commons.nearby;
|
|||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.LocationManager;
|
||||
|
|
@ -41,7 +40,8 @@ import timber.log.Timber;
|
|||
|
||||
public class NearbyActivity extends NavigationBaseActivity {
|
||||
|
||||
@BindView(R.id.progressBar) ProgressBar progressBar;
|
||||
@BindView(R.id.progressBar)
|
||||
ProgressBar progressBar;
|
||||
private boolean isMapViewActive = false;
|
||||
private static final int LOCATION_REQUEST = 1;
|
||||
|
||||
|
|
@ -115,15 +115,11 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(getString(R.string.location_permission_rationale))
|
||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
.setPositiveButton("OK", (dialog, which) -> {
|
||||
ActivityCompat.requestPermissions(NearbyActivity.this,
|
||||
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
|
||||
LOCATION_REQUEST);
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", null)
|
||||
.create()
|
||||
|
|
@ -175,26 +171,19 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||
Timber.d("GPS is not enabled");
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
||||
alertDialogBuilder.setMessage(R.string.gps_disabled)
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(R.string.gps_disabled)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.enable_gps,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
(dialog, id) -> {
|
||||
Intent callGPSSettingIntent = new Intent(
|
||||
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||
Timber.d("Loaded settings page");
|
||||
startActivityForResult(callGPSSettingIntent, 1);
|
||||
}
|
||||
});
|
||||
alertDialogBuilder.setNegativeButton(R.string.menu_cancel_upload,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = alertDialogBuilder.create();
|
||||
alert.show();
|
||||
})
|
||||
.setNegativeButton(R.string.menu_cancel_upload, (dialog, id) -> dialog.cancel())
|
||||
.create()
|
||||
.show();
|
||||
} else {
|
||||
Timber.d("GPS is enabled");
|
||||
}
|
||||
|
|
@ -257,7 +246,7 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
|
||||
private final Context mContext;
|
||||
|
||||
private NearbyAsyncTask (Context context) {
|
||||
private NearbyAsyncTask(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,14 +52,11 @@ public class NearbyController {
|
|||
distances.put(place, computeDistanceBetween(place.location, curLatLng));
|
||||
}
|
||||
Collections.sort(places,
|
||||
new Comparator<Place>() {
|
||||
@Override
|
||||
public int compare(Place lhs, Place rhs) {
|
||||
(lhs, rhs) -> {
|
||||
double lhsDistance = distances.get(lhs);
|
||||
double rhsDistance = distances.get(rhs);
|
||||
return (int) (lhsDistance - rhsDistance);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return places;
|
||||
|
|
|
|||
|
|
@ -63,15 +63,10 @@ public class NearbyInfoDialog extends OverlayDialog {
|
|||
|
||||
overflowButton.setVisibility(showMenu() ? View.VISIBLE : View.GONE);
|
||||
|
||||
overflowButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
popupMenuListener();
|
||||
}
|
||||
});
|
||||
overflowButton.setOnClickListener(this::popupMenuListener);
|
||||
}
|
||||
|
||||
private void popupMenuListener() {
|
||||
private void popupMenuListener(View v) {
|
||||
PopupMenu popupMenu = new PopupMenu(getActivity(), overflowButton);
|
||||
popupMenu.inflate(R.menu.nearby_info_dialog_options);
|
||||
|
||||
|
|
|
|||
|
|
@ -48,12 +48,7 @@ public class NearbyListFragment extends Fragment {
|
|||
View view = inflater.inflate(R.layout.fragment_nearby, container, false);
|
||||
recyclerView = (RecyclerView) view.findViewById(R.id.listView);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
adapterFactory = new NearbyAdapterFactory(new PlaceRenderer.PlaceClickedListener() {
|
||||
@Override
|
||||
public void placeClicked(Place place) {
|
||||
NearbyInfoDialog.showYourself(getActivity(), place);
|
||||
}
|
||||
});
|
||||
adapterFactory = new NearbyAdapterFactory(place -> NearbyInfoDialog.showYourself(getActivity(), place));
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,25 +88,19 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
|
|||
// create map
|
||||
mapView = new MapView(getActivity(), options);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(MapboxMap mapboxMap) {
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
mapboxMap.addMarkers(baseMarkerOptions);
|
||||
|
||||
mapboxMap.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {
|
||||
@Override
|
||||
public boolean onMarkerClick(@NonNull Marker marker) {
|
||||
mapboxMap.setOnMarkerClickListener(marker -> {
|
||||
if (marker instanceof NearbyMarker) {
|
||||
NearbyMarker nearbyMarker = (NearbyMarker) marker;
|
||||
Place place = nearbyMarker.getNearbyBaseMarker().getPlace();
|
||||
NearbyInfoDialog.showYourself(getActivity(), place);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
addCurrentLocationMarker(mapboxMap);
|
||||
}
|
||||
});
|
||||
if (PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("theme",true)) {
|
||||
mapView.setStyleUrl(getResources().getString(R.string.map_theme_dark));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
@ -19,7 +20,7 @@ class PlaceRenderer extends Renderer<Place> {
|
|||
@BindView(R.id.icon) ImageView icon;
|
||||
private final PlaceClickedListener listener;
|
||||
|
||||
PlaceRenderer(PlaceClickedListener listener) {
|
||||
PlaceRenderer(@NonNull PlaceClickedListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
|
|
@ -35,14 +36,7 @@ class PlaceRenderer extends Renderer<Place> {
|
|||
|
||||
@Override
|
||||
protected void hookListeners(View view) {
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (listener != null) {
|
||||
listener.placeClicked(getContent());
|
||||
}
|
||||
}
|
||||
});
|
||||
view.setOnClickListener(v -> listener.placeClicked(getContent()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -28,21 +28,15 @@ public class SettingsFragment extends PreferenceFragment {
|
|||
licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue())));
|
||||
|
||||
// Keep summary updated when changing value
|
||||
licensePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
licensePreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
preference.setSummary(getString(Utils.licenseNameFor((String) newValue)));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
CheckBoxPreference themePreference = (CheckBoxPreference) findPreference("theme");
|
||||
themePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
themePreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
getActivity().recreate();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
final EditTextPreference uploadLimit = (EditTextPreference) findPreference("uploads");
|
||||
|
|
@ -51,21 +45,14 @@ public class SettingsFragment extends PreferenceFragment {
|
|||
int uploads = sharedPref.getInt(Prefs.UPLOADS_SHOWING, 100);
|
||||
uploadLimit.setText(uploads + "");
|
||||
uploadLimit.setSummary(uploads + "");
|
||||
uploadLimit.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
uploadLimit.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
int value = Integer.parseInt(newValue.toString());
|
||||
final SharedPreferences.Editor editor = sharedPref.edit();
|
||||
if (value > 500) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.maximum_limit)
|
||||
.setMessage(R.string.maximum_limit_alert)
|
||||
.setPositiveButton(android.R.string.yes,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
})
|
||||
.setPositiveButton(android.R.string.yes, (dialog, which) -> {})
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.show();
|
||||
editor.putInt(Prefs.UPLOADS_SHOWING, 500);
|
||||
|
|
@ -79,8 +66,6 @@ public class SettingsFragment extends PreferenceFragment {
|
|||
}
|
||||
editor.apply();
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -55,12 +55,7 @@ public class NavigationBaseActivity extends BaseActivity
|
|||
public void initBackButton() {
|
||||
int backStackEntryCount = getSupportFragmentManager().getBackStackEntryCount();
|
||||
toggle.setDrawerIndicatorEnabled(backStackEntryCount == 0);
|
||||
toggle.setToolbarNavigationClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onBackPressed();
|
||||
}
|
||||
});
|
||||
toggle.setToolbarNavigationClickListener(v -> onBackPressed());
|
||||
}
|
||||
|
||||
public void initBack() {
|
||||
|
|
@ -118,9 +113,7 @@ public class NavigationBaseActivity extends BaseActivity
|
|||
new AlertDialog.Builder(this)
|
||||
.setMessage(R.string.logout_verification)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
.setPositiveButton(R.string.yes, (dialog, which) -> {
|
||||
((CommonsApplication) getApplicationContext())
|
||||
.clearApplicationData(NavigationBaseActivity.this);
|
||||
Intent nearbyIntent = new Intent(
|
||||
|
|
@ -129,14 +122,8 @@ public class NavigationBaseActivity extends BaseActivity
|
|||
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(nearbyIntent);
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.cancel();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.no, (dialog, which) -> dialog.cancel())
|
||||
.show();
|
||||
return true;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -72,21 +72,13 @@ public class ExistingFileAsync extends AsyncTask<Void, Void, Boolean> {
|
|||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setMessage(R.string.file_exists)
|
||||
.setTitle(R.string.warning);
|
||||
builder.setPositiveButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
builder.setPositiveButton(R.string.no, (dialog, id) -> {
|
||||
//Go back to ContributionsActivity
|
||||
Intent intent = new Intent(context, ContributionsActivity.class);
|
||||
context.startActivity(intent);
|
||||
callback.onResult(Result.DUPLICATE_CANCELLED);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
callback.onResult(Result.DUPLICATE_PROCEED);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.yes, (dialog, id) -> callback.onResult(Result.DUPLICATE_PROCEED));
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
|
|
|
|||
|
|
@ -125,11 +125,9 @@ public class MultipleShareActivity
|
|||
Contribution up = photosList.get(i);
|
||||
final int uploadCount = i + 1; // Goddamn Java
|
||||
|
||||
uploadController.startUpload(up, new UploadController.ContributionUploadProgress() {
|
||||
@Override
|
||||
public void onUploadStarted(Contribution contribution) {
|
||||
uploadController.startUpload(up, contribution -> {
|
||||
dialog.setProgress(uploadCount);
|
||||
if(uploadCount == photosList.size()) {
|
||||
if (uploadCount == photosList.size()) {
|
||||
dialog.dismiss();
|
||||
Toast startingToast = Toast.makeText(
|
||||
CommonsApplication.getInstance(),
|
||||
|
|
@ -138,7 +136,6 @@ public class MultipleShareActivity
|
|||
);
|
||||
startingToast.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class MwVolleyApi {
|
|||
Timber.d("URL: %s", apiUrl);
|
||||
|
||||
JsonRequest<QueryResponse> request = new QueryRequest(apiUrl,
|
||||
new LogResponseListener<QueryResponse>(), new LogResponseErrorListener());
|
||||
new LogResponseListener<>(), new LogResponseErrorListener());
|
||||
getQueue().add(request);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@ import fr.free.nrw.commons.modifications.TemplateRemoveModifier;
|
|||
import fr.free.nrw.commons.mwapi.EventLog;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.DUPLICATE_PROCEED;
|
||||
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.NO_DUPLICATE;
|
||||
|
||||
/**
|
||||
* Activity for the title/desc screen after image is selected. Also starts processing image
|
||||
* GPS coordinates or user location (if enabled in Settings) for category suggestions.
|
||||
|
|
@ -133,12 +136,9 @@ public class ShareActivity
|
|||
Timber.d("Cache the categories found");
|
||||
}
|
||||
|
||||
uploadController.startUpload(title, mediaUri, description, mimeType, source, decimalCoords, new UploadController.ContributionUploadProgress() {
|
||||
@Override
|
||||
public void onUploadStarted(Contribution contribution) {
|
||||
ShareActivity.this.contribution = contribution;
|
||||
uploadController.startUpload(title, mediaUri, description, mimeType, source, decimalCoords, c -> {
|
||||
ShareActivity.this.contribution = c;
|
||||
showPostUpload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -379,14 +379,10 @@ public class ShareActivity
|
|||
Timber.d("File SHA1 is: %s", fileSHA1);
|
||||
|
||||
ExistingFileAsync fileAsyncTask =
|
||||
new ExistingFileAsync(fileSHA1, this, new ExistingFileAsync.Callback() {
|
||||
@Override
|
||||
public void onResult(ExistingFileAsync.Result result) {
|
||||
new ExistingFileAsync(fileSHA1, this, result -> {
|
||||
Timber.d("%s duplicate check: %s", mediaUri.toString(), result);
|
||||
duplicateCheckPassed =
|
||||
result == ExistingFileAsync.Result.DUPLICATE_PROCEED
|
||||
|| result == ExistingFileAsync.Result.NO_DUPLICATE;
|
||||
}
|
||||
duplicateCheckPassed = (result == DUPLICATE_PROCEED
|
||||
|| result == NO_DUPLICATE);
|
||||
});
|
||||
fileAsyncTask.execute();
|
||||
} catch (IOException e) {
|
||||
|
|
@ -401,17 +397,12 @@ public class ShareActivity
|
|||
}
|
||||
}
|
||||
|
||||
private Snackbar requestPermissionUsingSnackBar(
|
||||
String rationale, final String[] perms, final int code) {
|
||||
private Snackbar requestPermissionUsingSnackBar(String rationale,
|
||||
final String[] perms,
|
||||
final int code) {
|
||||
Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), rationale,
|
||||
Snackbar.LENGTH_INDEFINITE)
|
||||
.setAction(R.string.ok, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
ActivityCompat.requestPermissions(ShareActivity.this,
|
||||
perms, code);
|
||||
}
|
||||
});
|
||||
Snackbar.LENGTH_INDEFINITE).setAction(R.string.ok,
|
||||
view -> ActivityCompat.requestPermissions(ShareActivity.this, perms, code));
|
||||
snackbar.show();
|
||||
return snackbar;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,15 +7,12 @@ import java.util.concurrent.Executor;
|
|||
|
||||
public class ExecutorUtils {
|
||||
|
||||
private static final Executor uiExecutor = new Executor() {
|
||||
@Override
|
||||
public void execute(Runnable command) {
|
||||
private static final Executor uiExecutor = command -> {
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
command.run();
|
||||
} else {
|
||||
new Handler(Looper.getMainLooper()).post(command);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static Executor uiExecutor () { return uiExecutor;}
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ public class FileUtils {
|
|||
if (file != null) {
|
||||
if (file.isDirectory()) {
|
||||
String[] children = file.list();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
deletedAll = deleteFile(new File(file, children[i])) && deletedAll;
|
||||
for (String child : children) {
|
||||
deletedAll = deleteFile(new File(file, child)) && deletedAll;
|
||||
}
|
||||
} else {
|
||||
deletedAll = file.delete();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue