mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Upon creating AuthenticatedActivity, now checking if the user is blocked via api call and notifying the user if they are blocked via snackbar
This commit is contained in:
parent
8cd8baf49c
commit
39096cf30b
5 changed files with 43 additions and 0 deletions
|
|
@ -4,8 +4,13 @@ import android.os.Bundle;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||||
import fr.free.nrw.commons.theme.NavigationBaseActivity;
|
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;
|
import static fr.free.nrw.commons.auth.AccountUtil.AUTH_COOKIE;
|
||||||
|
|
||||||
|
|
@ -34,6 +39,8 @@ public abstract class AuthenticatedActivity extends NavigationBaseActivity {
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
authCookie = savedInstanceState.getString(AUTH_COOKIE);
|
authCookie = savedInstanceState.getString(AUTH_COOKIE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showBlockStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -45,4 +52,16 @@ public abstract class AuthenticatedActivity extends NavigationBaseActivity {
|
||||||
protected abstract void onAuthCookieAcquired(String authCookie);
|
protected abstract void onAuthCookieAcquired(String authCookie);
|
||||||
|
|
||||||
protected abstract void onAuthFailure();
|
protected abstract void onAuthFailure();
|
||||||
|
|
||||||
|
protected void showBlockStatus()
|
||||||
|
{
|
||||||
|
Observable.fromCallable(() -> mediaWikiApi.isUserBlocked())
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.filter(result -> result)
|
||||||
|
.subscribe(result -> {
|
||||||
|
ViewUtil.showSnackbar(findViewById(android.R.id.content), R.string.block_notification);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
||||||
if (sessionManager.getCurrentAccount() != null
|
if (sessionManager.getCurrentAccount() != null
|
||||||
&& sessionManager.isUserLoggedIn()
|
&& sessionManager.isUserLoggedIn()
|
||||||
&& sessionManager.getCachedAuthCookie() != null) {
|
&& sessionManager.getCachedAuthCookie() != null) {
|
||||||
|
sessionManager.revalidateAuthToken();
|
||||||
startMainActivity();
|
startMainActivity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -615,6 +615,26 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUserBlocked() {
|
||||||
|
boolean userBlocked = false;
|
||||||
|
try {
|
||||||
|
ApiResult result = api.action("query")
|
||||||
|
.param("action", "query")
|
||||||
|
.param("format", "xml")
|
||||||
|
.param("meta", "userinfo")
|
||||||
|
.param("uiprop", "blockinfo")
|
||||||
|
.get();
|
||||||
|
if(result != null) {
|
||||||
|
userBlocked = !result.getString("/api/query/userinfo/@blockexpiry").isEmpty();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return userBlocked;
|
||||||
|
}
|
||||||
|
|
||||||
private Date parseMWDate(String mwDate) {
|
private Date parseMWDate(String mwDate) {
|
||||||
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH); // Assuming MW always gives me UTC
|
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH); // Assuming MW always gives me UTC
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,8 @@ public interface MediaWikiApi {
|
||||||
@NonNull
|
@NonNull
|
||||||
Single<Integer> getUploadCount(String userName);
|
Single<Integer> getUploadCount(String userName);
|
||||||
|
|
||||||
|
boolean isUserBlocked();
|
||||||
|
|
||||||
interface ProgressListener {
|
interface ProgressListener {
|
||||||
void onProgress(long transferred, long total);
|
void onProgress(long transferred, long total);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -282,6 +282,7 @@
|
||||||
<string name="share_app_title">Share App</string>
|
<string name="share_app_title">Share App</string>
|
||||||
<string name="share_coordinates_not_present">Coordinates were not specified during image selection</string>
|
<string name="share_coordinates_not_present">Coordinates were not specified during image selection</string>
|
||||||
<string name="error_fetching_nearby_places">Error fetching nearby places.</string>
|
<string name="error_fetching_nearby_places">Error fetching nearby places.</string>
|
||||||
|
<string name="block_notification">You are blocked from editing commons</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>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue