Skip to content

Commit 9f58c51

Browse files
authored
Merge pull request #592 from commons-app/prehackMainActivityIsLoginActivity
Switch the main activity to be the LoginActivity
2 parents 364199d + 367228d commit 9f58c51

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

app/src/main/AndroidManifest.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
<activity
3232
android:name=".auth.LoginActivity"
3333
>
34+
<intent-filter>
35+
<category android:name="android.intent.category.LAUNCHER"/>
36+
<action android:name="android.intent.action.MAIN"/>
37+
</intent-filter>
3438
</activity>
3539
<activity
3640
android:name=".WelcomeActivity"
@@ -66,10 +70,6 @@
6670
android:icon="@drawable/ic_launcher"
6771
android:label="@string/app_name"
6872
>
69-
<intent-filter>
70-
<category android:name="android.intent.category.LAUNCHER"/>
71-
<action android:name="android.intent.action.MAIN"/>
72-
</intent-filter>
7373
</activity>
7474
<activity
7575
android:name=".settings.SettingsActivity"

app/src/main/java/fr/free/nrw/commons/CommonsApplication.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ public void putBitmap(String key, Bitmap bitmap) {
166166
public MWApi getApi() {
167167
return api;
168168
}
169-
169+
170+
/**
171+
* @return Accout|null
172+
*/
170173
public Account getCurrentAccount() {
171174
if(currentAccount == null) {
172175
AccountManager accountManager = AccountManager.get(this);

app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
import android.widget.TextView;
1818

1919
import android.widget.Toast;
20-
import fr.free.nrw.commons.BuildConfig;
21-
import fr.free.nrw.commons.R;
22-
import fr.free.nrw.commons.Utils;
23-
import fr.free.nrw.commons.WelcomeActivity;
20+
import fr.free.nrw.commons.*;
21+
import fr.free.nrw.commons.contributions.ContributionsActivity;
2422
import timber.log.Timber;
2523

2624

@@ -36,10 +34,14 @@ public class LoginActivity extends AccountAuthenticatorActivity {
3634
EditText twoFactorEdit;
3735
ProgressDialog progressDialog;
3836

37+
private CommonsApplication app;
38+
3939
@Override
4040
public void onCreate(Bundle savedInstanceState) {
4141
super.onCreate(savedInstanceState);
4242

43+
app = (CommonsApplication) getApplicationContext();
44+
4345
setContentView(R.layout.activity_login);
4446
final LoginActivity that = this;
4547

@@ -116,6 +118,9 @@ protected void onResume() {
116118
this.startWelcomeIntent();
117119
prefs.edit().putBoolean("firstrun", false).apply();
118120
}
121+
if (app.getCurrentAccount() != null) {
122+
startMainActivity();
123+
}
119124
}
120125

121126
private void startWelcomeIntent() {
@@ -208,4 +213,10 @@ public void emptySensitiveEditFields() {
208213
twoFactorEdit.setText("");
209214
}
210215

216+
public void startMainActivity() {
217+
Intent intent = new Intent(this, ContributionsActivity.class);
218+
startActivity(intent);
219+
finish();
220+
}
221+
211222
}

app/src/main/java/fr/free/nrw/commons/auth/LoginTask.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import fr.free.nrw.commons.CommonsApplication;
1010
import fr.free.nrw.commons.EventLog;
1111
import fr.free.nrw.commons.R;
12-
import fr.free.nrw.commons.contributions.ContributionsActivity;
1312
import timber.log.Timber;
1413

1514
import java.io.IOException;
@@ -90,10 +89,7 @@ private void handlePassResult() {
9089
}
9190

9291
AccountUtil.createAccount( response, username, password );
93-
94-
Intent intent = new Intent(loginActivity, ContributionsActivity.class);
95-
loginActivity.startActivity(intent);
96-
loginActivity.finish();
92+
loginActivity.startMainActivity();
9793
}
9894

9995
/**

0 commit comments

Comments
 (0)