Merge pull request #1573 from seannemann21/show-block-status

Show Block Status if use is blocked
This commit is contained in:
neslihanturan 2018-07-22 15:29:05 +03:00 committed by GitHub
commit b4d556a648
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 145 additions and 0 deletions

View file

@ -4,8 +4,13 @@ import android.os.Bundle;
import javax.inject.Inject;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.theme.NavigationBaseActivity;
import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static fr.free.nrw.commons.auth.AccountUtil.AUTH_COOKIE;
@ -34,6 +39,8 @@ public abstract class AuthenticatedActivity extends NavigationBaseActivity {
if (savedInstanceState != null) {
authCookie = savedInstanceState.getString(AUTH_COOKIE);
}
showBlockStatus();
}
@Override
@ -45,4 +52,20 @@ public abstract class AuthenticatedActivity extends NavigationBaseActivity {
protected abstract void onAuthCookieAcquired(String authCookie);
protected abstract void onAuthFailure();
/**
* Makes API call to check if user is blocked from Commons. If the user is blocked, a snackbar
* is created to notify the user
*/
protected void showBlockStatus()
{
Observable.fromCallable(() -> mediaWikiApi.isUserBlockedFromCommons())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.filter(result -> result)
.subscribe(result -> {
ViewUtil.showSnackbar(findViewById(android.R.id.content), R.string.block_notification);
}
);
}
}

View file

@ -166,6 +166,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
if (sessionManager.getCurrentAccount() != null
&& sessionManager.isUserLoggedIn()
&& sessionManager.getCachedAuthCookie() != null) {
sessionManager.revalidateAuthToken();
startMainActivity();
}
}