Search in sources :

Example 6 with ForumUser

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);
    }
}
Also used : JavascriptInterface(android.webkit.JavascriptInterface) Observer(java.util.Observer) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) TabNotification(forpdateam.ru.forpda.data.models.TabNotification) FrameLayout(android.widget.FrameLayout) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Preferences(forpdateam.ru.forpda.common.Preferences) RxApi(forpdateam.ru.forpda.apirx.RxApi) ExtendedWebView(forpdateam.ru.forpda.ui.views.ExtendedWebView) Matcher(java.util.regex.Matcher) MessagePanel(forpdateam.ru.forpda.ui.views.messagepanel.MessagePanel) Locale(java.util.Locale) QmsMessage(forpdateam.ru.forpda.api.qms.models.QmsMessage) View(android.view.View) TabFragment(forpdateam.ru.forpda.ui.fragments.TabFragment) Schedulers(io.reactivex.schedulers.Schedulers) Log(android.util.Log) IntentHandler(forpdateam.ru.forpda.common.IntentHandler) ViewGroup(android.view.ViewGroup) List(java.util.List) FilePickHelper(forpdateam.ru.forpda.common.FilePickHelper) CustomWebChromeClient(forpdateam.ru.forpda.common.webview.CustomWebChromeClient) Pattern(java.util.regex.Pattern) Nullable(android.support.annotation.Nullable) R(forpdateam.ru.forpda.R) MiniTemplator(biz.source_code.miniTemplator.MiniTemplator) NotesAddPopup(forpdateam.ru.forpda.ui.fragments.notes.NotesAddPopup) Intent(android.content.Intent) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) AttachmentsPopup(forpdateam.ru.forpda.ui.views.messagepanel.attachments.AttachmentsPopup) SuppressLint(android.annotation.SuppressLint) Toast(android.widget.Toast) Menu(android.view.Menu) CustomWebViewClient(forpdateam.ru.forpda.common.webview.CustomWebViewClient) QmsThemesFragment(forpdateam.ru.forpda.ui.fragments.qms.QmsThemesFragment) Observable(io.reactivex.Observable) QmsChatModel(forpdateam.ru.forpda.api.qms.models.QmsChatModel) ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser) TabManager(forpdateam.ru.forpda.ui.TabManager) LayoutInflater(android.view.LayoutInflater) ImageLoader(com.nostra13.universalimageloader.core.ImageLoader) ForumUsersCache(forpdateam.ru.forpda.apirx.ForumUsersCache) QmsRx(forpdateam.ru.forpda.apirx.apiclasses.QmsRx) App(forpdateam.ru.forpda.App) Activity(android.app.Activity) RequestFile(forpdateam.ru.forpda.api.RequestFile) ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser)

Example 7 with ForumUser

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;
}
Also used : Bitmap(android.graphics.Bitmap) ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser)

Example 8 with ForumUser

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;
}
Also used : ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser) ForumUserBd(forpdateam.ru.forpda.data.realm.ForumUserBd) Realm(io.realm.Realm)

Example 9 with ForumUser

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;
}
Also used : ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser) Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) ArrayList(java.util.ArrayList)

Example 10 with ForumUser

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);
}
Also used : ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser) Bitmap(android.graphics.Bitmap) WebResourceResponse(android.webkit.WebResourceResponse) Matcher(java.util.regex.Matcher) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

ForumUser (forpdateam.ru.forpda.api.others.user.ForumUser)12 ArrayList (java.util.ArrayList)8 Matcher (java.util.regex.Matcher)5 MiniTemplator (biz.source_code.miniTemplator.MiniTemplator)3 ForumUserBd (forpdateam.ru.forpda.data.realm.ForumUserBd)3 Realm (io.realm.Realm)3 Bitmap (android.graphics.Bitmap)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 JavascriptInterface (android.webkit.JavascriptInterface)1 WebResourceResponse (android.webkit.WebResourceResponse)1