use of forpdateam.ru.forpda.api.others.user.ForumUser in project ForPDA by RadiationX.
the class QmsChatFragment method tryShowAvatar.
private void tryShowAvatar() {
toolbarImageView.setContentDescription(getString(R.string.user_avatar));
if (currentChat.getUserId() != QmsChatModel.NOT_CREATED) {
toolbarImageView.setOnClickListener(view1 -> IntentHandler.handle("https://4pda.ru/forum/index.php?showuser=" + currentChat.getUserId()));
}
if (currentChat.getAvatarUrl() != null) {
ImageLoader.getInstance().displayImage(currentChat.getAvatarUrl(), toolbarImageView);
toolbarImageView.setVisibility(View.VISIBLE);
} else if (currentChat.getNick() != null) {
Observable.fromCallable(() -> ForumUsersCache.loadUserByNick(currentChat.getNick())).onErrorReturn(throwable -> new ForumUser()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(forumUser -> {
if (forumUser.getAvatar() != null && !forumUser.getAvatar().isEmpty()) {
ImageLoader.getInstance().displayImage(forumUser.getAvatar(), toolbarImageView);
toolbarImageView.setVisibility(View.VISIBLE);
}
});
} else {
toolbarImageView.setVisibility(View.GONE);
}
}
use of forpdateam.ru.forpda.api.others.user.ForumUser in project ForPDA by RadiationX.
the class NotificationsService method loadAvatar.
public Bitmap loadAvatar(NotificationEvent event) throws Exception {
Bitmap bitmap = null;
if (!event.fromSite()) {
ForumUser forumUser = ForumUsersCache.getUserById(event.getUserId());
Log.d(LOG_TAG, "Forum user from cache " + forumUser);
if (forumUser == null) {
forumUser = ForumUsersCache.loadUserByNick(event.getUserNick());
Log.d(LOG_TAG, "Forum user from network " + forumUser);
}
if (forumUser != null) {
bitmap = ImageLoader.getInstance().loadImageSync(forumUser.getAvatar());
Log.d(LOG_TAG, "Loaded avatar bitmap" + bitmap);
if (bitmap != null) {
Log.d(LOG_TAG, "Bitmap h/w: " + bitmap.getHeight() + " : " + bitmap.getWidth());
}
}
}
return bitmap;
}
use of forpdateam.ru.forpda.api.others.user.ForumUser in project ForPDA by RadiationX.
the class ForumUsersCache method loadUserByNick.
public static ForumUser loadUserByNick(String nick) throws Exception {
ForumUser resultUser = null;
Realm realmInstance = Realm.getDefaultInstance();
ForumUserBd realmResult = realmInstance.where(ForumUserBd.class).equalTo("nick", nick).findFirst();
if (realmResult != null) {
resultUser = new ForumUser(realmResult);
}
realmInstance.close();
if (realmResult != null) {
return resultUser;
}
List<ForumUser> loadedForumUsers = Api.Qms().findUser(nick);
for (ForumUser user : loadedForumUsers) {
if (nick.equals(user.getNick())) {
resultUser = user;
break;
}
}
if (resultUser != null) {
loadedForumUsers.clear();
loadedForumUsers.add(resultUser);
saveUsers(loadedForumUsers);
}
return resultUser;
}
use of forpdateam.ru.forpda.api.others.user.ForumUser in project ForPDA by RadiationX.
the class Qms method findUser.
public List<ForumUser> findUser(final String nick) throws Exception {
String encodedNick = URLEncoder.encode(nick, "UTF-8");
NetworkResponse response = Api.getWebClient().get("https://4pda.ru/forum/index.php?act=qms-xhr&action=autocomplete-username&q=" + encodedNick);
List<ForumUser> list = new ArrayList<>();
Matcher m = findUserPattern.matcher(response.getBody());
while (m.find()) {
ForumUser user = new ForumUser();
user.setId(Integer.parseInt(m.group(1)));
user.setNick(ApiUtils.fromHtml(m.group(2)));
String avatar = m.group(3);
if (avatar.substring(0, 2).equals("//")) {
avatar = "https:".concat(avatar);
} else if (avatar.substring(0, 1).equals("/")) {
avatar = "https://4pda.ru".concat(avatar);
}
user.setAvatar(avatar);
list.add(user);
}
return list;
}
use of forpdateam.ru.forpda.api.others.user.ForumUser in project ForPDA by RadiationX.
the class CustomWebViewClient method shouldInterceptRequest.
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
Matcher matcher = cachePattern.matcher(url);
if (matcher.find()) {
try {
Log.d(LOG_TAG, "intercepted " + url);
WebResourceResponse resourceResponse = null;
String type = matcher.group(1);
String value = matcher.group(2);
value = URLDecoder.decode(value, "UTF-8");
String avatarUrl = null;
switch(type) {
case TYPE_NICK:
ForumUser forumUser = ForumUsersCache.loadUserByNick(value);
Log.d(LOG_TAG, "Loaded user " + forumUser.getId() + " : " + forumUser.getNick() + " : " + forumUser.getAvatar());
avatarUrl = forumUser.getAvatar();
break;
case TYPE_URL:
avatarUrl = value;
break;
}
Bitmap bitmap = ImageLoader.getInstance().loadImageSync(avatarUrl);
String base64Bitmap = convert(bitmap);
base64Bitmap = "data:image/png;base64," + base64Bitmap;
resourceResponse = new WebResourceResponse("text/text", null, new ByteArrayInputStream(base64Bitmap.getBytes()));
return resourceResponse;
} catch (Exception e) {
e.printStackTrace();
super.shouldInterceptRequest(view, url);
}
}
return super.shouldInterceptRequest(view, url);
}
Aggregations