mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Coding style fixes
This commit is contained in:
parent
ee409a9e8f
commit
3b728ca568
11 changed files with 91 additions and 87 deletions
|
|
@ -61,7 +61,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
usernameEdit.addTextChangedListener(textWatcher);
|
||||
passwordEdit.addTextChangedListener(textWatcher);
|
||||
twoFactorEdit.addTextChangedListener(textWatcher);
|
||||
passwordEdit.setOnEditorActionListener( newLoginInputActionListener() );
|
||||
passwordEdit.setOnEditorActionListener(newLoginInputActionListener());
|
||||
|
||||
loginButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
@ -151,7 +151,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
private LoginTask getLoginTask() {
|
||||
return new LoginTask(
|
||||
this,
|
||||
canonicializeUsername( usernameEdit.getText().toString() ),
|
||||
canonicializeUsername(usernameEdit.getText().toString()),
|
||||
passwordEdit.getText().toString(),
|
||||
twoFactorEdit.getText().toString()
|
||||
);
|
||||
|
|
@ -162,7 +162,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
* @param username String
|
||||
* @return String canonicial username
|
||||
*/
|
||||
private String canonicializeUsername( String username ) {
|
||||
private String canonicializeUsername(String username) {
|
||||
return new PageTitle(username).getText();
|
||||
}
|
||||
|
||||
|
|
@ -186,20 +186,20 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
}
|
||||
|
||||
public void askUserForTwoFactorAuth() {
|
||||
if(BuildConfig.DEBUG) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
twoFactorEdit.setVisibility(View.VISIBLE);
|
||||
showUserToastAndCancelDialog( R.string.login_failed_2fa_needed );
|
||||
}else{
|
||||
showUserToastAndCancelDialog( R.string.login_failed_2fa_not_supported );
|
||||
showUserToastAndCancelDialog(R.string.login_failed_2fa_needed);
|
||||
} else {
|
||||
showUserToastAndCancelDialog(R.string.login_failed_2fa_not_supported);
|
||||
}
|
||||
}
|
||||
|
||||
public void showUserToastAndCancelDialog( int resId ) {
|
||||
showUserToast( resId );
|
||||
public void showUserToastAndCancelDialog(int resId) {
|
||||
showUserToast(resId);
|
||||
progressDialog.cancel();
|
||||
}
|
||||
|
||||
private void showUserToast( int resId ) {
|
||||
private void showUserToast(int resId) {
|
||||
Toast.makeText(this, resId, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class LoginTask extends AsyncTask<String, String, String> {
|
|||
if (result.equals("PASS")) {
|
||||
handlePassResult();
|
||||
} else {
|
||||
handleOtherResults( result );
|
||||
handleOtherResults(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,38 +88,38 @@ class LoginTask extends AsyncTask<String, String, String> {
|
|||
}
|
||||
}
|
||||
|
||||
AccountUtil.createAccount( response, username, password );
|
||||
AccountUtil.createAccount(response, username, password);
|
||||
loginActivity.startMainActivity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Match known failure message codes and provide messages
|
||||
* Match known failure message codes and provide messages.
|
||||
* @param result String
|
||||
*/
|
||||
private void handleOtherResults( String result ) {
|
||||
private void handleOtherResults(String result) {
|
||||
if (result.equals("NetworkFailure")) {
|
||||
// Matches NetworkFailure which is created by the doInBackground method
|
||||
loginActivity.showUserToastAndCancelDialog( R.string.login_failed_network );
|
||||
loginActivity.showUserToastAndCancelDialog(R.string.login_failed_network);
|
||||
} else if (result.toLowerCase().contains("nosuchuser".toLowerCase()) || result.toLowerCase().contains("noname".toLowerCase())) {
|
||||
// Matches nosuchuser, nosuchusershort, noname
|
||||
loginActivity.showUserToastAndCancelDialog( R.string.login_failed_username );
|
||||
loginActivity.showUserToastAndCancelDialog(R.string.login_failed_username);
|
||||
loginActivity.emptySensitiveEditFields();
|
||||
} else if (result.toLowerCase().contains("wrongpassword".toLowerCase())) {
|
||||
// Matches wrongpassword, wrongpasswordempty
|
||||
loginActivity.showUserToastAndCancelDialog( R.string.login_failed_password );
|
||||
loginActivity.showUserToastAndCancelDialog(R.string.login_failed_password);
|
||||
loginActivity.emptySensitiveEditFields();
|
||||
} else if (result.toLowerCase().contains("throttle".toLowerCase())) {
|
||||
// Matches unknown throttle error codes
|
||||
loginActivity.showUserToastAndCancelDialog( R.string.login_failed_throttled );
|
||||
loginActivity.showUserToastAndCancelDialog(R.string.login_failed_throttled);
|
||||
} else if (result.toLowerCase().contains("userblocked".toLowerCase())) {
|
||||
// Matches login-userblocked
|
||||
loginActivity.showUserToastAndCancelDialog( R.string.login_failed_blocked );
|
||||
loginActivity.showUserToastAndCancelDialog(R.string.login_failed_blocked);
|
||||
} else if (result.equals("2FA")) {
|
||||
loginActivity.askUserForTwoFactorAuth();
|
||||
} else {
|
||||
// Occurs with unhandled login failure codes
|
||||
Timber.d("Login failed with reason: %s", result);
|
||||
loginActivity.showUserToastAndCancelDialog( R.string.login_failed_generic );
|
||||
loginActivity.showUserToastAndCancelDialog(R.string.login_failed_generic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import android.app.Service;
|
|||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
|
||||
public class WikiAccountAuthenticatorService extends Service{
|
||||
public class WikiAccountAuthenticatorService extends Service {
|
||||
|
||||
private static WikiAccountAuthenticator wikiAccountAuthenticator = null;
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ public class WikiAccountAuthenticatorService extends Service{
|
|||
return null;
|
||||
}
|
||||
|
||||
if(wikiAccountAuthenticator == null) {
|
||||
if (wikiAccountAuthenticator == null) {
|
||||
wikiAccountAuthenticator = new WikiAccountAuthenticator(this);
|
||||
}
|
||||
return wikiAccountAuthenticator.getIBinder();
|
||||
|
|
|
|||
|
|
@ -74,14 +74,14 @@ public class CacheController {
|
|||
double offset = 100;
|
||||
|
||||
//Coordinate offsets in radians
|
||||
double dLat = offset/EARTH_RADIUS;
|
||||
double dLon = offset/(EARTH_RADIUS*Math.cos(Math.PI*lat/180));
|
||||
double dLat = offset / EARTH_RADIUS;
|
||||
double dLon = offset / (EARTH_RADIUS * Math.cos(Math.PI * lat / 180));
|
||||
|
||||
//OffsetPosition, decimal degrees
|
||||
yPlus = lat + dLat * 180/Math.PI;
|
||||
yMinus = lat - dLat * 180/Math.PI;
|
||||
xPlus = lon + dLon * 180/Math.PI;
|
||||
xMinus = lon - dLon * 180/Math.PI;
|
||||
yPlus = lat + dLat * 180 / Math.PI;
|
||||
yMinus = lat - dLat * 180 / Math.PI;
|
||||
xPlus = lon + dLon * 180 / Math.PI;
|
||||
xMinus = lon - dLon * 180 / Math.PI;
|
||||
Timber.d("Search within: xMinus=%s, yMinus=%s, xPlus=%s, yPlus=%s",
|
||||
xMinus, yMinus, xPlus, yPlus);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,12 +60,12 @@ public class Category {
|
|||
|
||||
public void save() {
|
||||
try {
|
||||
if(contentUri == null) {
|
||||
if (contentUri == null) {
|
||||
contentUri = client.insert(CategoryContentProvider.BASE_URI, this.toContentValues());
|
||||
} else {
|
||||
client.update(contentUri, toContentValues(), null, null);
|
||||
}
|
||||
} catch(RemoteException e) {
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
|
@ -121,23 +121,23 @@ public class Category {
|
|||
}
|
||||
|
||||
public static void onUpdate(SQLiteDatabase db, int from, int to) {
|
||||
if(from == to) {
|
||||
if (from == to) {
|
||||
return;
|
||||
}
|
||||
if(from < 4) {
|
||||
if (from < 4) {
|
||||
// doesn't exist yet
|
||||
from++;
|
||||
onUpdate(db, from, to);
|
||||
return;
|
||||
}
|
||||
if(from == 4) {
|
||||
if (from == 4) {
|
||||
// table added in version 5
|
||||
onCreate(db);
|
||||
from++;
|
||||
onUpdate(db, from, to);
|
||||
return;
|
||||
}
|
||||
if(from == 5) {
|
||||
if (from == 5) {
|
||||
from++;
|
||||
onUpdate(db, from, to);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,19 @@ import fr.free.nrw.commons.contributions.ContributionsActivity;
|
|||
import fr.free.nrw.commons.mwapi.EventLog;
|
||||
|
||||
public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPageChangeListener {
|
||||
|
||||
public interface MediaDetailProvider {
|
||||
Media getMediaAtPosition(int i);
|
||||
|
||||
int getTotalMediaCount();
|
||||
|
||||
void notifyDatasetChanged();
|
||||
|
||||
void registerDataSetObserver(DataSetObserver observer);
|
||||
|
||||
void unregisterDataSetObserver(DataSetObserver observer);
|
||||
}
|
||||
|
||||
private ViewPager pager;
|
||||
private Boolean editable;
|
||||
private CommonsApplication app;
|
||||
|
|
@ -48,14 +61,6 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
|
|||
this.editable = editable;
|
||||
}
|
||||
|
||||
public interface MediaDetailProvider {
|
||||
Media getMediaAtPosition(int i);
|
||||
int getTotalMediaCount();
|
||||
void notifyDatasetChanged();
|
||||
void registerDataSetObserver(DataSetObserver observer);
|
||||
void unregisterDataSetObserver(DataSetObserver observer);
|
||||
}
|
||||
|
||||
//FragmentStatePagerAdapter allows user to swipe across collection of images (no. of images undetermined)
|
||||
private class MediaDetailAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
|
|
@ -65,7 +70,7 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
|
|||
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
if(i == 0) {
|
||||
if (i == 0) {
|
||||
// See bug https://code.google.com/p/android/issues/detail?id=27526
|
||||
pager.postDelayed(new Runnable() {
|
||||
@Override
|
||||
|
|
@ -120,7 +125,7 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if(savedInstanceState != null) {
|
||||
if (savedInstanceState != null) {
|
||||
editable = savedInstanceState.getBoolean("editable");
|
||||
}
|
||||
app = CommonsApplication.getInstance();
|
||||
|
|
@ -206,13 +211,13 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
|
|||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if(!editable) { // Disable menu options for editable views
|
||||
if (!editable) { // Disable menu options for editable views
|
||||
menu.clear(); // see http://stackoverflow.com/a/8495697/17865
|
||||
inflater.inflate(R.menu.fragment_image_detail, menu);
|
||||
if(pager != null) {
|
||||
if (pager != null) {
|
||||
MediaDetailProvider provider = (MediaDetailProvider)getActivity();
|
||||
Media m = provider.getMediaAtPosition(pager.getCurrentItem());
|
||||
if(m != null) {
|
||||
if (m != null) {
|
||||
// Enable default set of actions, then re-enable different set of actions only if it is a failed contrib
|
||||
menu.findItem(R.id.menu_retry_current_image).setEnabled(false).setVisible(false);
|
||||
menu.findItem(R.id.menu_cancel_current_image).setEnabled(false).setVisible(false);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,17 @@ import fr.free.nrw.commons.utils.UriDeserializer;
|
|||
import fr.free.nrw.commons.utils.UriSerializer;
|
||||
|
||||
public class NearbyBaseMarker extends BaseMarkerOptions<NearbyMarker, NearbyBaseMarker> {
|
||||
|
||||
public static final Parcelable.Creator<NearbyBaseMarker> CREATOR = new Parcelable.Creator<NearbyBaseMarker>() {
|
||||
public NearbyBaseMarker createFromParcel(Parcel in) {
|
||||
return new NearbyBaseMarker(in);
|
||||
}
|
||||
|
||||
public NearbyBaseMarker[] newArray(int size) {
|
||||
return new NearbyBaseMarker[size];
|
||||
}
|
||||
};
|
||||
|
||||
private Place place;
|
||||
|
||||
NearbyBaseMarker() {
|
||||
|
|
@ -74,15 +85,4 @@ public class NearbyBaseMarker extends BaseMarkerOptions<NearbyMarker, NearbyBase
|
|||
dest.writeString(title);
|
||||
dest.writeString(gson.toJson(place));
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<NearbyBaseMarker> CREATOR
|
||||
= new Parcelable.Creator<NearbyBaseMarker>() {
|
||||
public NearbyBaseMarker createFromParcel(Parcel in) {
|
||||
return new NearbyBaseMarker(in);
|
||||
}
|
||||
|
||||
public NearbyBaseMarker[] newArray(int size) {
|
||||
return new NearbyBaseMarker[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,12 +86,12 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
@Override
|
||||
public void onProgress(long transferred, long total) {
|
||||
Timber.d("Uploaded %d of %d", transferred, total);
|
||||
if(!notificationTitleChanged) {
|
||||
if (!notificationTitleChanged) {
|
||||
curProgressNotification.setContentTitle(notificationProgressTitle);
|
||||
notificationTitleChanged = true;
|
||||
contribution.setState(Contribution.STATE_IN_PROGRESS);
|
||||
}
|
||||
if(transferred == total) {
|
||||
if (transferred == total) {
|
||||
// Completed!
|
||||
curProgressNotification.setContentTitle(notificationFinishingTitle);
|
||||
curProgressNotification.setProgress(0, 100, true);
|
||||
|
|
@ -124,7 +124,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
|
||||
@Override
|
||||
protected void handle(int what, Contribution contribution) {
|
||||
switch(what) {
|
||||
switch (what) {
|
||||
case ACTION_UPLOAD_FILE:
|
||||
//FIXME: Google Photos bug
|
||||
uploadContribution(contribution);
|
||||
|
|
@ -162,7 +162,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if(intent.getAction().equals(ACTION_START_SERVICE) && freshStart) {
|
||||
if (intent.getAction().equals(ACTION_START_SERVICE) && freshStart) {
|
||||
ContentValues failedValues = new ContentValues();
|
||||
failedValues.put(Contribution.Table.COLUMN_STATE, Contribution.STATE_FAILED);
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
try {
|
||||
//FIXME: Google Photos bug
|
||||
file = this.getContentResolver().openInputStream(contribution.getLocalUri());
|
||||
} catch(FileNotFoundException e) {
|
||||
} catch (FileNotFoundException e) {
|
||||
Timber.d("File not found");
|
||||
Toast fileNotFound = Toast.makeText(this, R.string.upload_failed, Toast.LENGTH_LONG);
|
||||
fileNotFound.show();
|
||||
|
|
@ -220,9 +220,9 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
filename = findUniqueFilename(filename);
|
||||
unfinishedUploads.add(filename);
|
||||
}
|
||||
if(!api.validateLogin()) {
|
||||
if (!api.validateLogin()) {
|
||||
// Need to revalidate!
|
||||
if(app.revalidateAuthToken()) {
|
||||
if (app.revalidateAuthToken()) {
|
||||
Timber.d("Successfully revalidated token!");
|
||||
} else {
|
||||
Timber.d("Unable to revalidate :(");
|
||||
|
|
@ -245,7 +245,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
curProgressNotification = null;
|
||||
|
||||
String resultStatus = uploadResult.getResultStatus();
|
||||
if(!resultStatus.equals("Success")) {
|
||||
if (!resultStatus.equals("Success")) {
|
||||
showFailedNotification(contribution);
|
||||
EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT)
|
||||
.param("username", app.getCurrentAccount().name)
|
||||
|
|
@ -269,15 +269,15 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
.param("result", "success")
|
||||
.log();
|
||||
}
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
Timber.d("I have a network fuckup");
|
||||
showFailedNotification(contribution);
|
||||
} finally {
|
||||
if ( filename != null ) {
|
||||
if (filename != null) {
|
||||
unfinishedUploads.remove(filename);
|
||||
}
|
||||
toUpload--;
|
||||
if(toUpload == 0) {
|
||||
if (toUpload == 0) {
|
||||
// Sync modifications right after all uplaods are processed
|
||||
ContentResolver.requestSync((CommonsApplication.getInstance()).getCurrentAccount(), ModificationsContentProvider.AUTHORITY, new Bundle());
|
||||
stopForeground(true);
|
||||
|
|
@ -304,7 +304,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
private String findUniqueFilename(String fileName) throws IOException {
|
||||
MediaWikiApi api = app.getMWApi();
|
||||
String sequenceFileName;
|
||||
for ( int sequenceNumber = 1; true; sequenceNumber++ ) {
|
||||
for (int sequenceNumber = 1; true; sequenceNumber++) {
|
||||
if (sequenceNumber == 1) {
|
||||
sequenceFileName = fileName;
|
||||
} else {
|
||||
|
|
@ -318,9 +318,8 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
sequenceFileName = regexMatcher.replaceAll("$1 " + sequenceNumber + "$2");
|
||||
}
|
||||
}
|
||||
if ( api.fileExistsWithName(sequenceFileName) || unfinishedUploads.contains(sequenceFileName) ) {
|
||||
continue;
|
||||
} else {
|
||||
if (!api.fileExistsWithName(sequenceFileName)
|
||||
&& !unfinishedUploads.contains(sequenceFileName)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
public class LatLngTests {
|
||||
@Test public void testZeroZero() {
|
||||
LatLng place = new LatLng(0, 0, 0);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.utils.LengthUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
public class LengthUtilsTest {
|
||||
@Test public void testZeroDistance() {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
public class UtilsFixExtensionTest {
|
||||
|
||||
@Test public void jpegResultsInJpg() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue