mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Force login when no active session is found while uploading an image (#1684)
* Force login when no active session is found while uploading an image * Updated not logged in message
This commit is contained in:
parent
8859ff91e8
commit
306f23d1e2
3 changed files with 17 additions and 1 deletions
|
|
@ -5,6 +5,8 @@ import android.accounts.AccountManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||||
import io.reactivex.Completable;
|
import io.reactivex.Completable;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
|
|
@ -31,6 +33,7 @@ public class SessionManager {
|
||||||
/**
|
/**
|
||||||
* @return Account|null
|
* @return Account|null
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Account getCurrentAccount() {
|
public Account getCurrentAccount() {
|
||||||
if (currentAccount == null) {
|
if (currentAccount == null) {
|
||||||
AccountManager accountManager = AccountManager.get(context);
|
AccountManager accountManager = AccountManager.get(context);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package fr.free.nrw.commons.upload;
|
package fr.free.nrw.commons.upload;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
@ -13,6 +14,7 @@ import android.os.AsyncTask;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -22,9 +24,11 @@ import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import fr.free.nrw.commons.CommonsApplication;
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
import fr.free.nrw.commons.HandlerService;
|
import fr.free.nrw.commons.HandlerService;
|
||||||
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.auth.SessionManager;
|
import fr.free.nrw.commons.auth.SessionManager;
|
||||||
import fr.free.nrw.commons.contributions.Contribution;
|
import fr.free.nrw.commons.contributions.Contribution;
|
||||||
import fr.free.nrw.commons.settings.Prefs;
|
import fr.free.nrw.commons.settings.Prefs;
|
||||||
|
import fr.free.nrw.commons.utils.ViewUtil;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class UploadController {
|
public class UploadController {
|
||||||
|
|
@ -95,8 +99,15 @@ public class UploadController {
|
||||||
Contribution contribution;
|
Contribution contribution;
|
||||||
|
|
||||||
//TODO: Modify this to include coords
|
//TODO: Modify this to include coords
|
||||||
|
Account currentAccount = sessionManager.getCurrentAccount();
|
||||||
|
if(currentAccount == null) {
|
||||||
|
Timber.d("Current account is null");
|
||||||
|
ViewUtil.showLongToast(context, context.getString(R.string.user_not_logged_in));
|
||||||
|
sessionManager.forceLogin(context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
contribution = new Contribution(mediaUri, null, title, description, -1,
|
contribution = new Contribution(mediaUri, null, title, description, -1,
|
||||||
null, null, sessionManager.getCurrentAccount().name,
|
null, null, currentAccount.name,
|
||||||
CommonsApplication.DEFAULT_EDIT_SUMMARY, decimalCoords);
|
CommonsApplication.DEFAULT_EDIT_SUMMARY, decimalCoords);
|
||||||
|
|
||||||
contribution.setTag("mimeType", mimeType);
|
contribution.setTag("mimeType", mimeType);
|
||||||
|
|
|
||||||
|
|
@ -287,4 +287,6 @@
|
||||||
<string name="wikidata_edit_failure">Failed to update corresponding Wikidata entity!</string>
|
<string name="wikidata_edit_failure">Failed to update corresponding Wikidata entity!</string>
|
||||||
<string name="menu_set_wallpaper">Set wallpaper</string>
|
<string name="menu_set_wallpaper">Set wallpaper</string>
|
||||||
<string name="wallpaper_set_successfully">Wallpaper set successfully!</string>
|
<string name="wallpaper_set_successfully">Wallpaper set successfully!</string>
|
||||||
|
|
||||||
|
<string name="user_not_logged_in">Login session expired, please log in again.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue