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