Cleanup CommonsApplication Singelton

This commit is contained in:
addshore 2017-05-16 10:39:05 +02:00
parent 45a19620b9
commit bdfbdc7579
29 changed files with 116 additions and 83 deletions

View file

@ -55,7 +55,7 @@ public class AccountUtil {
@NonNull
private static CommonsApplication app() {
return CommonsApplication.app;
return CommonsApplication.getInstance();
}
}

View file

@ -132,7 +132,7 @@ public abstract class AuthenticatedActivity extends NavigationBaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = (CommonsApplication)this.getApplicationContext();
app = CommonsApplication.getInstance();
if(savedInstanceState != null) {
authCookie = savedInstanceState.getString("authCookie");
}

View file

@ -40,7 +40,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = (CommonsApplication) getApplicationContext();
app = CommonsApplication.getInstance();
setContentView(R.layout.activity_login);
final LoginActivity that = this;
@ -199,7 +199,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
}
private void showUserToast( int resId ) {
Toast.makeText(getApplicationContext(), resId, Toast.LENGTH_LONG).show();
Toast.makeText(this, resId, Toast.LENGTH_LONG).show();
}
public void showSuccessToastAndDismissDialog() {

View file

@ -26,7 +26,7 @@ class LoginTask extends AsyncTask<String, String, String> {
this.username = username;
this.password = password;
this.twoFactorCode = twoFactorCode;
app = (CommonsApplication) loginActivity.getApplicationContext();
app = CommonsApplication.getInstance();
}
@Override
@ -44,9 +44,9 @@ class LoginTask extends AsyncTask<String, String, String> {
protected String doInBackground(String... params) {
try {
if (twoFactorCode.isEmpty()) {
return app.getApi().login(username, password);
return app.getMWApi().login(username, password);
} else {
return app.getApi().login(username, password, twoFactorCode);
return app.getMWApi().login(username, password, twoFactorCode);
}
} catch (IOException e) {
// Do something better!

View file

@ -7,6 +7,7 @@ import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.theme.BaseActivity;
import timber.log.Timber;
@ -39,10 +40,10 @@ public class SignupActivity extends BaseActivity {
//Signup success, so clear cookies, notify user, and load LoginActivity again
Timber.d("Overriding URL %s", url);
Toast toast = Toast.makeText(getApplicationContext(), "Account created!", Toast.LENGTH_LONG);
Toast toast = Toast.makeText(CommonsApplication.getInstance(), "Account created!", Toast.LENGTH_LONG);
toast.show();
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
Intent intent = new Intent(CommonsApplication.getInstance(), LoginActivity.class);
startActivity(intent);
return true;
} else {

View file

@ -75,7 +75,7 @@ public class WikiAccountAuthenticator extends AbstractAccountAuthenticator {
}
private String getAuthCookie(String username, String password) throws IOException {
MWApi api = CommonsApplication.createMWApi();
MWApi api = CommonsApplication.getInstance().getMWApi();
//TODO add 2fa support here
String result = api.login(username, password);
if(result.equals("PASS")) {