mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Java 5 / Java 8 language suggestions plus general cleanup.
This commit is contained in:
parent
13e84a82b8
commit
8cbf56fa7b
6 changed files with 62 additions and 76 deletions
|
|
@ -31,16 +31,13 @@ class CategoriesRenderer extends Renderer<CategoryItem> {
|
|||
|
||||
@Override
|
||||
protected void hookListeners(View view) {
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
view.setOnClickListener(v -> {
|
||||
CategoryItem item = getContent();
|
||||
item.setSelected(!item.isSelected());
|
||||
checkedView.setChecked(item.isSelected());
|
||||
if (listener != null) {
|
||||
listener.categoryClicked(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public class Contribution extends Media {
|
|||
}
|
||||
|
||||
public String getPageContents() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
|
||||
|
||||
buffer
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class CategoryModifier extends PageModifier {
|
|||
JSONArray categories;
|
||||
categories = params.optJSONArray(PARAM_CATEGORIES);
|
||||
|
||||
StringBuffer categoriesString = new StringBuffer();
|
||||
StringBuilder categoriesString = new StringBuilder();
|
||||
for(int i=0; i < categories.length(); i++) {
|
||||
String category = categories.optString(i);
|
||||
categoriesString.append("\n[[Category:").append(category).append("]]");
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class ModifierSequence {
|
|||
}
|
||||
|
||||
public String getEditSummary() {
|
||||
StringBuffer editSummary = new StringBuffer();
|
||||
StringBuilder editSummary = new StringBuilder();
|
||||
for(PageModifier modifier: modifiers) {
|
||||
editSummary.append(modifier.getEditSumary()).append(" ");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package fr.free.nrw.commons.upload;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
|
|
@ -39,13 +38,10 @@ import fr.free.nrw.commons.Utils;
|
|||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class SingleUploadFragment extends Fragment {
|
||||
private SharedPreferences prefs;
|
||||
private String license;
|
||||
import static android.view.MotionEvent.ACTION_DOWN;
|
||||
import static android.view.MotionEvent.ACTION_UP;
|
||||
|
||||
public interface OnUploadActionInitiated {
|
||||
void uploadActionInitiated(String title, String description);
|
||||
}
|
||||
public class SingleUploadFragment extends Fragment {
|
||||
|
||||
@BindView(R.id.titleEdit) EditText titleEdit;
|
||||
@BindView(R.id.descEdit) EditText descEdit;
|
||||
|
|
@ -53,13 +49,15 @@ public class SingleUploadFragment extends Fragment {
|
|||
@BindView(R.id.share_license_summary) TextView licenseSummaryView;
|
||||
@BindView(R.id.licenseSpinner) Spinner licenseSpinner;
|
||||
|
||||
private SharedPreferences prefs;
|
||||
private String license;
|
||||
private OnUploadActionInitiated uploadActionInitiatedHandler;
|
||||
private TitleTextWatcher textWatcher = new TitleTextWatcher();
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.activity_share, menu);
|
||||
if(titleEdit != null) {
|
||||
if (titleEdit != null) {
|
||||
menu.findItem(R.id.menu_upload_single).setEnabled(titleEdit.getText().length() != 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -89,7 +87,7 @@ public class SingleUploadFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_single_upload, null);
|
||||
View rootView = inflater.inflate(R.layout.fragment_single_upload, container, false);
|
||||
ButterKnife.bind(this, rootView);
|
||||
|
||||
|
||||
|
|
@ -112,10 +110,10 @@ public class SingleUploadFragment extends Fragment {
|
|||
Timber.d(license);
|
||||
|
||||
ArrayAdapter<String> adapter;
|
||||
if (PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("theme",false)) {
|
||||
if (PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("theme", false)) {
|
||||
// dark theme
|
||||
adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, licenseItems);
|
||||
}else {
|
||||
} else {
|
||||
// light theme
|
||||
adapter = new ArrayAdapter<>(getActivity(), R.layout.light_simple_spinner_dropdown_item, licenseItems);
|
||||
}
|
||||
|
|
@ -146,26 +144,27 @@ public class SingleUploadFragment extends Fragment {
|
|||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@OnItemSelected(R.id.licenseSpinner) void onLicenseSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
@OnItemSelected(R.id.licenseSpinner)
|
||||
void onLicenseSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
String licenseName = parent.getItemAtPosition(position).toString();
|
||||
|
||||
// Set selected color to white because it should be readable on random images.
|
||||
TextView selectedText = (TextView) licenseSpinner.getChildAt(0);
|
||||
if (selectedText != null ) {
|
||||
if (selectedText != null) {
|
||||
selectedText.setTextColor(Color.WHITE);
|
||||
selectedText.setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
String license;
|
||||
if(getString(R.string.license_name_cc0).equals(licenseName)) {
|
||||
if (getString(R.string.license_name_cc0).equals(licenseName)) {
|
||||
license = Prefs.Licenses.CC0;
|
||||
} else if(getString(R.string.license_name_cc_by).equals(licenseName)) {
|
||||
} else if (getString(R.string.license_name_cc_by).equals(licenseName)) {
|
||||
license = Prefs.Licenses.CC_BY_3;
|
||||
} else if(getString(R.string.license_name_cc_by_sa).equals(licenseName)) {
|
||||
} else if (getString(R.string.license_name_cc_by_sa).equals(licenseName)) {
|
||||
license = Prefs.Licenses.CC_BY_SA_3;
|
||||
} else if(getString(R.string.license_name_cc_by_four).equals(licenseName)) {
|
||||
} else if (getString(R.string.license_name_cc_by_four).equals(licenseName)) {
|
||||
license = Prefs.Licenses.CC_BY_4;
|
||||
} else if(getString(R.string.license_name_cc_by_sa_four).equals(licenseName)) {
|
||||
} else if (getString(R.string.license_name_cc_by_sa_four).equals(licenseName)) {
|
||||
license = Prefs.Licenses.CC_BY_SA_4;
|
||||
} else {
|
||||
throw new IllegalStateException("Unknown licenseName: " + licenseName);
|
||||
|
|
@ -177,10 +176,9 @@ public class SingleUploadFragment extends Fragment {
|
|||
editor.commit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@OnTouch(R.id.share_license_summary) boolean showLicence(View view, MotionEvent motionEvent) {
|
||||
if (motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
||||
@OnTouch(R.id.share_license_summary)
|
||||
boolean showLicence(View view, MotionEvent motionEvent) {
|
||||
if (motionEvent.getActionMasked() == ACTION_DOWN) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(Utils.licenseUrlFor(license)));
|
||||
|
|
@ -191,7 +189,8 @@ public class SingleUploadFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.titleDescButton) void setTitleDescButton() {
|
||||
@OnClick(R.id.titleDescButton)
|
||||
void setTitleDescButton() {
|
||||
//Retrieve last title and desc entered
|
||||
SharedPreferences titleDesc = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
String title = titleDesc.getString("Title", "");
|
||||
|
|
@ -205,57 +204,41 @@ public class SingleUploadFragment extends Fragment {
|
|||
/**
|
||||
* Copied from https://stackoverflow.com/a/26269435/8065933
|
||||
*/
|
||||
@OnTouch
|
||||
(R.id.titleEdit) boolean titleInfo(View view, MotionEvent motionEvent) {
|
||||
@OnTouch(R.id.titleEdit)
|
||||
boolean titleInfo(View view, MotionEvent motionEvent) {
|
||||
//Should replace right with end to support different right-to-left languages as well
|
||||
final int value = titleEdit.getRight() - titleEdit.getCompoundDrawables()[2].getBounds().width();
|
||||
|
||||
if (motionEvent.getAction() == motionEvent.ACTION_UP && motionEvent.getRawX() >= value) {
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle(R.string.media_detail_title);
|
||||
builder.setMessage(R.string.title_info);
|
||||
builder.setCancelable(true);
|
||||
builder.setNeutralButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) {
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.media_detail_title)
|
||||
.setMessage(R.string.title_info)
|
||||
.setCancelable(true)
|
||||
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
|
||||
.create()
|
||||
.show();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@OnTouch
|
||||
(R.id.descEdit) boolean descriptionInfo(View view, MotionEvent motionEvent) {
|
||||
@OnTouch(R.id.descEdit)
|
||||
boolean descriptionInfo(View view, MotionEvent motionEvent) {
|
||||
final int value = descEdit.getRight() - descEdit.getCompoundDrawables()[2].getBounds().width();
|
||||
|
||||
if (motionEvent.getAction() == motionEvent.ACTION_UP && motionEvent.getRawX() >= value) {
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle(R.string.media_detail_description);
|
||||
builder.setMessage(R.string.description_info);
|
||||
builder.setCancelable(true);
|
||||
builder.setNeutralButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) {
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.media_detail_description)
|
||||
.setMessage(R.string.description_info)
|
||||
.setCancelable(true)
|
||||
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
|
||||
.create()
|
||||
.show();
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void setLicenseSummary(String license) {
|
||||
licenseSummaryView.setText(getString(R.string.share_license_summary, getString(Utils.licenseNameFor(license))));
|
||||
}
|
||||
|
|
@ -279,16 +262,22 @@ public class SingleUploadFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
public interface OnUploadActionInitiated {
|
||||
void uploadActionInitiated(String title, String description);
|
||||
}
|
||||
|
||||
private class TitleTextWatcher implements TextWatcher {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { }
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { }
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if(getActivity() != null) {
|
||||
if (getActivity() != null) {
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class FileUtils {
|
|||
* @return the content of the file
|
||||
*/
|
||||
public static String readFromResource(String fileName) throws IOException {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue