mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Lambda usage simplifications (#1928)
* Replace anonymous type with lambda * Use method reference * Replace with expression lambda
This commit is contained in:
parent
1f8063284c
commit
e8f4a286c5
12 changed files with 57 additions and 110 deletions
|
|
@ -155,22 +155,14 @@ public class AboutActivity extends NavigationBaseActivity {
|
|||
builder.setView(spinner);
|
||||
builder.setTitle(R.string.about_translate_title)
|
||||
.setMessage(R.string.about_translate_message)
|
||||
.setPositiveButton(R.string.about_translate_proceed, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String languageSelected = spinner.getSelectedItem().toString();
|
||||
TokensTranslations tokensTranslations = new TokensTranslations();
|
||||
tokensTranslations.initailize();
|
||||
String token = tokensTranslations.getTranslationToken(languageSelected);
|
||||
Utils.handleWebUrl(AboutActivity.this,Uri.parse("https://translatewiki.net/w/i.php?title=Special:Translate&language="+token+"&group=commons-android-strings&filter=%21translated&action=translate ?"));
|
||||
}
|
||||
.setPositiveButton(R.string.about_translate_proceed, (dialog, which) -> {
|
||||
String languageSelected = spinner.getSelectedItem().toString();
|
||||
TokensTranslations tokensTranslations = new TokensTranslations();
|
||||
tokensTranslations.initailize();
|
||||
String token = tokensTranslations.getTranslationToken(languageSelected);
|
||||
Utils.handleWebUrl(AboutActivity.this,Uri.parse("https://translatewiki.net/w/i.php?title=Special:Translate&language="+token+"&group=commons-android-strings&filter=%21translated&action=translate ?"));
|
||||
});
|
||||
builder.setNegativeButton(R.string.about_translate_cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.about_translate_cancel, (dialog, which) -> finish());
|
||||
builder.create().show();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,9 +63,7 @@ public abstract class AuthenticatedActivity extends NavigationBaseActivity {
|
|||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.filter(result -> result)
|
||||
.subscribe(result -> {
|
||||
ViewUtil.showSnackbar(findViewById(android.R.id.content), R.string.block_notification);
|
||||
}
|
||||
.subscribe(result -> ViewUtil.showSnackbar(findViewById(android.R.id.content), R.string.block_notification)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,22 +38,20 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
|
|||
View rootView = inflater.inflate(R.layout.fragment_search_history, container, false);
|
||||
ButterKnife.bind(this, rootView);
|
||||
recentSearches = recentSearchesDao.recentSearches(10);
|
||||
recent_searches_delete_button.setOnClickListener(v -> {
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setMessage(getString(R.string.delete_recent_searches_dialog))
|
||||
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
||||
recentSearchesDao.deleteAll(recentSearches);
|
||||
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);
|
||||
recentSearchesList.setAdapter(adapter);
|
||||
adapter.notifyDataSetChanged();
|
||||
dialog.dismiss();
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.create()
|
||||
.show();
|
||||
});
|
||||
recent_searches_delete_button.setOnClickListener(v -> new AlertDialog.Builder(getContext())
|
||||
.setMessage(getString(R.string.delete_recent_searches_dialog))
|
||||
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
||||
recentSearchesDao.deleteAll(recentSearches);
|
||||
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);
|
||||
recentSearchesList.setAdapter(adapter);
|
||||
adapter.notifyDataSetChanged();
|
||||
dialog.dismiss();
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.create()
|
||||
.show());
|
||||
adapter = new ArrayAdapter<String>(getContext(),R.layout.item_recent_searches, recentSearches);
|
||||
recentSearchesList.setAdapter(adapter);
|
||||
recentSearchesList.setOnItemClickListener((parent, view, position, id) -> (
|
||||
|
|
|
|||
|
|
@ -376,17 +376,13 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
final EditText input = new EditText(getActivity());
|
||||
alert.setView(input);
|
||||
input.requestFocus();
|
||||
alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
String reason = input.getText().toString();
|
||||
DeleteTask deleteTask = new DeleteTask(getActivity(), media, reason);
|
||||
deleteTask.execute();
|
||||
enableDeleteButton(false);
|
||||
}
|
||||
alert.setPositiveButton(R.string.ok, (dialog, whichButton) -> {
|
||||
String reason = input.getText().toString();
|
||||
DeleteTask deleteTask = new DeleteTask(getActivity(), media, reason);
|
||||
deleteTask.execute();
|
||||
enableDeleteButton(false);
|
||||
});
|
||||
alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
}
|
||||
alert.setNegativeButton(R.string.cancel, (dialog, whichButton) -> {
|
||||
});
|
||||
AlertDialog d = alert.create();
|
||||
input.addTextChangedListener(new TextWatcher() {
|
||||
|
|
|
|||
|
|
@ -508,13 +508,10 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
// create map
|
||||
mapView = new MapView(getActivity(), options);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(MapboxMap mapboxMap) {
|
||||
((NearbyActivity)getActivity()).setMapViewTutorialShowCase();
|
||||
NearbyMapFragment.this.mapboxMap = mapboxMap;
|
||||
updateMapSignificantly();
|
||||
}
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
((NearbyActivity)getActivity()).setMapViewTutorialShowCase();
|
||||
NearbyMapFragment.this.mapboxMap = mapboxMap;
|
||||
updateMapSignificantly();
|
||||
});
|
||||
mapView.setStyleUrl("asset://mapstyle.json");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,9 +74,7 @@ public class NotificationActivity extends NavigationBaseActivity {
|
|||
if (!NetworkUtils.isInternetConnectionEstablished(this)) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
Snackbar.make(relativeLayout , R.string.no_internet, Snackbar.LENGTH_INDEFINITE)
|
||||
.setAction(R.string.retry, view -> {
|
||||
refresh();
|
||||
}).show();
|
||||
.setAction(R.string.retry, view -> refresh()).show();
|
||||
}else {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
addNotifications();
|
||||
|
|
|
|||
|
|
@ -57,12 +57,7 @@ public class QuizActivity extends AppCompatActivity {
|
|||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||
alert.setTitle(getResources().getString(R.string.warning));
|
||||
alert.setMessage(getResources().getString(R.string.warning_for_no_answer));
|
||||
alert.setPositiveButton(R.string.continue_message, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
alert.setPositiveButton(R.string.continue_message, (dialog, which) -> dialog.dismiss());
|
||||
AlertDialog dialog = alert.create();
|
||||
dialog.show();
|
||||
}
|
||||
|
|
@ -77,21 +72,13 @@ public class QuizActivity extends AppCompatActivity {
|
|||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||
alert.setTitle(getResources().getString(R.string.warning));
|
||||
alert.setMessage(getResources().getString(R.string.quiz_back_button));
|
||||
alert.setPositiveButton(R.string.continue_message, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent i = new Intent(QuizActivity.this, QuizResultActivity.class);
|
||||
dialog.dismiss();
|
||||
i.putExtra("QuizResult",score);
|
||||
startActivity(i);
|
||||
}
|
||||
});
|
||||
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
dialogInterface.dismiss();
|
||||
}
|
||||
alert.setPositiveButton(R.string.continue_message, (dialog, which) -> {
|
||||
Intent i = new Intent(QuizActivity.this, QuizResultActivity.class);
|
||||
dialog.dismiss();
|
||||
i.putExtra("QuizResult",score);
|
||||
startActivity(i);
|
||||
});
|
||||
alert.setNegativeButton("Cancel", (dialogInterface, i) -> dialogInterface.dismiss());
|
||||
AlertDialog dialog = alert.create();
|
||||
dialog.show();
|
||||
}
|
||||
|
|
@ -138,18 +125,15 @@ public class QuizActivity extends AppCompatActivity {
|
|||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||
alert.setTitle(title);
|
||||
alert.setMessage(Message);
|
||||
alert.setPositiveButton(R.string.continue_message, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
questionIndex++;
|
||||
if(questionIndex == quiz.size()){
|
||||
Intent i = new Intent(QuizActivity.this, QuizResultActivity.class);
|
||||
dialog.dismiss();
|
||||
i.putExtra("QuizResult",score);
|
||||
startActivity(i);
|
||||
}else {
|
||||
displayQuestion();
|
||||
}
|
||||
alert.setPositiveButton(R.string.continue_message, (dialog, which) -> {
|
||||
questionIndex++;
|
||||
if(questionIndex == quiz.size()){
|
||||
Intent i = new Intent(QuizActivity.this, QuizResultActivity.class);
|
||||
dialog.dismiss();
|
||||
i.putExtra("QuizResult",score);
|
||||
startActivity(i);
|
||||
}else {
|
||||
displayQuestion();
|
||||
}
|
||||
});
|
||||
AlertDialog dialog = alert.create();
|
||||
|
|
|
|||
|
|
@ -191,17 +191,8 @@ public class QuizResultActivity extends AppCompatActivity {
|
|||
TextView shareMessage = (TextView) view.findViewById(R.id.alert_text);
|
||||
shareMessage.setText(R.string.quiz_result_share_message);
|
||||
alertadd.setView(view);
|
||||
alertadd.setPositiveButton(R.string.about_translate_proceed, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
shareScreen(screenshot);
|
||||
}
|
||||
});
|
||||
alertadd.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
alertadd.setPositiveButton(R.string.about_translate_proceed, (dialog, which) -> shareScreen(screenshot));
|
||||
alertadd.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.cancel());
|
||||
alertadd.show();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,12 +104,9 @@ public abstract class NavigationBaseActivity extends BaseActivity
|
|||
username.setText(allAccounts[0].name);
|
||||
}
|
||||
ImageView userIcon = navHeaderView.findViewById(R.id.user_icon);
|
||||
userIcon.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
AchievementsActivity.startYourself(NavigationBaseActivity.this);
|
||||
}
|
||||
userIcon.setOnClickListener(v -> {
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
AchievementsActivity.startYourself(NavigationBaseActivity.this);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment {
|
|||
|
||||
private void initRecyclerView() {
|
||||
descriptionsAdapter = new DescriptionsAdapter();
|
||||
descriptionsAdapter.setCallback((mediaDetailDescription, descriptionInfo) -> showInfoAlert(mediaDetailDescription,descriptionInfo));
|
||||
descriptionsAdapter.setCallback(this::showInfoAlert);
|
||||
descriptionsAdapter.setLanguages(getLocaleSupportedByDevice());
|
||||
rvDescriptions.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
rvDescriptions.setAdapter(descriptionsAdapter);
|
||||
|
|
|
|||
|
|
@ -65,9 +65,7 @@ public class PicOfDayAppWidget extends AppWidgetProvider {
|
|||
loadImageFromUrl(response.getImageUrl(), context, views, appWidgetManager, appWidgetId);
|
||||
}
|
||||
},
|
||||
t -> {
|
||||
Timber.e(t, "Fetching picture of the day failed");
|
||||
}
|
||||
t -> Timber.e(t, "Fetching picture of the day failed")
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,9 +110,7 @@ public class WikidataEditService {
|
|||
} else {
|
||||
Timber.d("Wikidata edit couldn't be tagged");
|
||||
}
|
||||
}, throwable -> {
|
||||
Timber.e(throwable, "Error occurred while adding tag to the edit");
|
||||
});
|
||||
}, throwable -> Timber.e(throwable, "Error occurred while adding tag to the edit"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue