Search in sources :

Example 1 with MiniTemplator

use of biz.source_code.miniTemplator.MiniTemplator in project ForPDA by RadiationX.

the class QmsChatFragment method onLoadChat.

private void onLoadChat(QmsChatModel loadedChat) {
    App.get().subscribeQms(notification);
    progressBar.setVisibility(View.GONE);
    currentChat.setThemeId(loadedChat.getThemeId());
    currentChat.setTitle(loadedChat.getTitle());
    currentChat.setUserId(loadedChat.getUserId());
    currentChat.setNick(loadedChat.getNick());
    currentChat.getMessages().addAll(loadedChat.getMessages());
    tryShowAvatar();
    MiniTemplator t = App.get().getTemplate(App.TEMPLATE_QMS_CHAT_MESS);
    App.setTemplateResStrings(t);
    int end = currentChat.getMessages().size();
    int start = Math.max(end - 30, 0);
    QmsRx.generateMess(t, currentChat.getMessages(), start, end);
    String messagesSrc = t.generateOutput();
    t.reset();
    currentChat.setShowedMessIndex(start);
    messagesSrc = QmsRx.transformMessageSrc(messagesSrc);
    Log.d(LOG_TAG, "showNewMess");
    webView.evalJs("showNewMess('".concat(messagesSrc).concat("', true)"));
    refreshToolbarMenuItems(true);
    if (currentChat.getNick() != null) {
        setSubtitle(currentChat.getNick());
    }
    if (currentChat.getTitle() != null) {
        setTitle(currentChat.getTitle());
        setTabTitle(String.format(getString(R.string.fragment_tab_title_chat), currentChat.getTitle(), currentChat.getNick()));
    }
}
Also used : MiniTemplator(biz.source_code.miniTemplator.MiniTemplator) SuppressLint(android.annotation.SuppressLint)

Example 2 with MiniTemplator

use of biz.source_code.miniTemplator.MiniTemplator in project ForPDA by RadiationX.

the class QmsRx method transform.

public static QmsChatModel transform(QmsChatModel chatModel, boolean withHtml) throws Exception {
    if (withHtml) {
        MiniTemplator t = App.get().getTemplate(App.TEMPLATE_QMS_CHAT);
        App.setTemplateResStrings(t);
        t.setVariableOpt("style_type", App.get().getCssStyleType());
        t.setVariableOpt("chat_title", ApiUtils.htmlEncode(chatModel.getTitle()));
        t.setVariableOpt("chatId", chatModel.getThemeId());
        t.setVariableOpt("userId", chatModel.getUserId());
        t.setVariableOpt("nick", chatModel.getNick());
        t.setVariableOpt("avatarUrl", chatModel.getAvatarUrl());
        int endIndex = chatModel.getMessages().size();
        int startIndex = Math.max(endIndex - 30, 0);
        chatModel.setShowedMessIndex(startIndex);
        MiniTemplator messTemp = App.get().getTemplate(App.TEMPLATE_QMS_CHAT_MESS);
        App.setTemplateResStrings(t);
        generateMess(messTemp, chatModel.getMessages(), startIndex, endIndex);
        t.setVariableOpt("messages", messTemp.generateOutput());
        messTemp.reset();
        chatModel.setHtml(t.generateOutput());
        t.reset();
    }
    return chatModel;
}
Also used : MiniTemplator(biz.source_code.miniTemplator.MiniTemplator)

Example 3 with MiniTemplator

use of biz.source_code.miniTemplator.MiniTemplator in project ForPDA by RadiationX.

the class SearchRx method transform.

public static SearchResult transform(SearchResult page, boolean withHtml) throws Exception {
    if (withHtml) {
        List<ForumUser> forumUsers = new ArrayList<>();
        for (SearchItem post : page.getItems()) {
            ForumUser forumUser = new ForumUser();
            forumUser.setId(post.getUserId());
            forumUser.setNick(post.getNick());
            forumUser.setAvatar(post.getAvatar());
        }
        ForumUsersCache.saveUsers(forumUsers);
        int memberId = ClientHelper.getUserId();
        MiniTemplator t = App.get().getTemplate(App.TEMPLATE_SEARCH);
        App.setTemplateResStrings(t);
        boolean authorized = ClientHelper.getAuthState();
        boolean prevDisabled = page.getPagination().getCurrent() <= 1;
        boolean nextDisabled = page.getPagination().getCurrent() == page.getPagination().getAll();
        t.setVariableOpt("style_type", App.get().getCssStyleType());
        t.setVariableOpt("all_pages_int", page.getPagination().getAll());
        t.setVariableOpt("posts_on_page_int", page.getPagination().getPerPage());
        t.setVariableOpt("current_page_int", page.getPagination().getCurrent());
        t.setVariableOpt("authorized_bool", Boolean.toString(authorized));
        t.setVariableOpt("member_id_int", ClientHelper.getUserId());
        t.setVariableOpt("body_type", "search");
        t.setVariableOpt("navigation_disable", ThemeRx.getDisableStr(prevDisabled && nextDisabled));
        t.setVariableOpt("first_disable", ThemeRx.getDisableStr(prevDisabled));
        t.setVariableOpt("prev_disable", ThemeRx.getDisableStr(prevDisabled));
        t.setVariableOpt("next_disable", ThemeRx.getDisableStr(nextDisabled));
        t.setVariableOpt("last_disable", ThemeRx.getDisableStr(nextDisabled));
        boolean isEnableAvatars = Preferences.Theme.isShowAvatars(null);
        t.setVariableOpt("enable_avatars_bool", Boolean.toString(isEnableAvatars));
        t.setVariableOpt("enable_avatars", isEnableAvatars ? "show_avatar" : "hide_avatar");
        t.setVariableOpt("avatar_type", Preferences.Theme.isCircleAvatars(null) ? "circle_avatar" : "square_avatar");
        Matcher letterMatcher = null;
        for (SearchItem post : page.getItems()) {
            t.setVariableOpt("topic_id", post.getTopicId());
            t.setVariableOpt("post_title", post.getTitle());
            t.setVariableOpt("user_online", post.isOnline() ? "online" : "");
            t.setVariableOpt("post_id", post.getId());
            t.setVariableOpt("user_id", post.getUserId());
            // Post header
            t.setVariableOpt("avatar", post.getAvatar());
            t.setVariableOpt("none_avatar", post.getAvatar().isEmpty() ? "none_avatar" : "");
            if (letterMatcher != null) {
                letterMatcher = letterMatcher.reset(post.getNick());
            } else {
                letterMatcher = firstLetter.matcher(post.getNick());
            }
            String letter = null;
            if (letterMatcher.find()) {
                letter = letterMatcher.group(1);
            } else {
                letter = post.getNick().substring(0, 1);
            }
            t.setVariableOpt("nick_letter", letter);
            t.setVariableOpt("nick", ApiUtils.htmlEncode(post.getNick()));
            // t.setVariableOpt("curator", false ? "curator" : "");
            t.setVariableOpt("group_color", post.getGroupColor());
            t.setVariableOpt("group", post.getGroup());
            t.setVariableOpt("reputation", post.getReputation());
            t.setVariableOpt("date", post.getDate());
            // t.setVariableOpt("number", post.getNumber());
            // Post body
            t.setVariableOpt("body", post.getBody());
            // Post footer
            /*if (post.canReport() && authorized)
                    t.addBlockOpt("report_block");
                if (page.canQuote() && authorized && post.getUserId() != memberId)
                    t.addBlockOpt("reply_block");
                if (authorized && post.getUserId() != memberId)
                    t.addBlockOpt("vote_block");
                if (post.canDelete() && authorized)
                    t.addBlockOpt("delete_block");
                if (post.canEdit() && authorized)
                    t.addBlockOpt("edit_block");*/
            t.addBlockOpt("post");
        }
        page.setHtml(t.generateOutput());
        t.reset();
    }
    return page;
}
Also used : ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) MiniTemplator(biz.source_code.miniTemplator.MiniTemplator) SearchItem(forpdateam.ru.forpda.api.search.models.SearchItem)

Example 4 with MiniTemplator

use of biz.source_code.miniTemplator.MiniTemplator in project ForPDA by RadiationX.

the class ThemeRx method transform.

public static ThemePage transform(ThemePage page, boolean withHtml) throws Exception {
    if (withHtml) {
        List<ForumUser> forumUsers = new ArrayList<>();
        for (ThemePost post : page.getPosts()) {
            ForumUser forumUser = new ForumUser();
            forumUser.setId(post.getUserId());
            forumUser.setNick(post.getNick());
            forumUser.setAvatar(post.getAvatar());
        }
        ForumUsersCache.saveUsers(forumUsers);
        int memberId = ClientHelper.getUserId();
        MiniTemplator t = App.get().getTemplate(App.TEMPLATE_THEME);
        App.setTemplateResStrings(t);
        boolean authorized = ClientHelper.getAuthState();
        boolean prevDisabled = page.getPagination().getCurrent() <= 1;
        boolean nextDisabled = page.getPagination().getCurrent() == page.getPagination().getAll();
        t.setVariableOpt("style_type", App.get().getCssStyleType());
        t.setVariableOpt("topic_title", ApiUtils.htmlEncode(page.getTitle()));
        t.setVariableOpt("topic_description", ApiUtils.htmlEncode(page.getDesc()));
        t.setVariableOpt("topic_url", page.getUrl());
        t.setVariableOpt("all_pages_int", page.getPagination().getAll());
        t.setVariableOpt("posts_on_page_int", page.getPagination().getPerPage());
        t.setVariableOpt("current_page_int", page.getPagination().getCurrent());
        t.setVariableOpt("authorized_bool", Boolean.toString(authorized));
        t.setVariableOpt("is_curator_bool", Boolean.toString(page.isCurator()));
        t.setVariableOpt("member_id_int", ClientHelper.getUserId());
        t.setVariableOpt("elem_to_scroll", page.getAnchor());
        t.setVariableOpt("body_type", "topic");
        t.setVariableOpt("navigation_disable", getDisableStr(prevDisabled && nextDisabled));
        t.setVariableOpt("first_disable", getDisableStr(prevDisabled));
        t.setVariableOpt("prev_disable", getDisableStr(prevDisabled));
        t.setVariableOpt("next_disable", getDisableStr(nextDisabled));
        t.setVariableOpt("last_disable", getDisableStr(nextDisabled));
        t.setVariableOpt("in_favorite_bool", Boolean.toString(page.isInFavorite()));
        boolean isEnableAvatars = Preferences.Theme.isShowAvatars(null);
        t.setVariableOpt("enable_avatars_bool", Boolean.toString(isEnableAvatars));
        t.setVariableOpt("enable_avatars", isEnableAvatars ? "show_avatar" : "hide_avatar");
        t.setVariableOpt("avatar_type", Preferences.Theme.isCircleAvatars(null) ? "circle_avatar" : "square_avatar");
        int hatPostId = 0;
        if (!page.getPosts().isEmpty()) {
            hatPostId = page.getPosts().get(0).getId();
        }
        Matcher letterMatcher = null;
        for (ThemePost post : page.getPosts()) {
            t.setVariableOpt("user_online", post.isOnline() ? "online" : "");
            t.setVariableOpt("post_id", post.getId());
            t.setVariableOpt("user_id", post.getUserId());
            // Post header
            // t.setVariableOpt("avatar", post.getAvatar().isEmpty() ? "file:///android_asset/av.png" : "https://s.4pda.to/forum/uploads/".concat(post.getAvatar()));
            t.setVariableOpt("avatar", post.getAvatar());
            t.setVariableOpt("none_avatar", post.getAvatar().isEmpty() ? "none_avatar" : "");
            if (letterMatcher != null) {
                letterMatcher = letterMatcher.reset(post.getNick());
            } else {
                letterMatcher = firstLetter.matcher(post.getNick());
            }
            String letter = null;
            if (letterMatcher.find()) {
                letter = letterMatcher.group(1);
            } else {
                letter = post.getNick().substring(0, 1);
            }
            t.setVariableOpt("nick_letter", letter);
            t.setVariableOpt("nick", ApiUtils.htmlEncode(post.getNick()));
            t.setVariableOpt("curator", post.isCurator() ? "curator" : "");
            t.setVariableOpt("group_color", post.getGroupColor());
            t.setVariableOpt("group", post.getGroup());
            t.setVariableOpt("reputation", post.getReputation());
            t.setVariableOpt("date", post.getDate());
            t.setVariableOpt("number", post.getNumber());
            // Post body
            if (page.getPosts().size() > 1 && hatPostId == post.getId()) {
                boolean hatOpened = prevDisabled || page.isHatOpen();
                t.setVariableOpt("hat_state_class", prevDisabled || page.isHatOpen() ? "open" : "close");
                // t.setVariableOpt("hat_body_state", prevDisabled || page.isHatOpen() ? "" : "hidden");
                t.addBlockOpt("hat_button");
                t.addBlockOpt("hat_content_start");
                t.addBlockOpt("hat_content_end");
            } else {
                t.setVariableOpt("hat_state_class", "");
            }
            t.setVariableOpt("body", post.getBody());
            if (post.canReport() && authorized)
                t.addBlockOpt("report_block");
            if (page.canQuote() && authorized && post.getUserId() != memberId)
                t.addBlockOpt("reply_block");
            if (authorized && post.getUserId() != memberId)
                t.addBlockOpt("vote_block");
            if (post.canDelete() && authorized)
                t.addBlockOpt("delete_block");
            if (post.canEdit() && authorized)
                t.addBlockOpt("edit_block");
            t.addBlockOpt("post");
        }
        // Poll block
        if (page.getPoll() != null) {
            t.setVariableOpt("poll_state_class", page.isPollOpen() ? "open" : "close");
            // t.setVariableOpt("poll_body_state", page.isPollOpen() ? "" : "hidden");
            Poll poll = page.getPoll();
            boolean isResult = poll.isResult();
            t.setVariableOpt("poll_type", isResult ? "result" : "default");
            t.setVariableOpt("poll_title", poll.getTitle().isEmpty() || poll.getTitle().equals("-") ? App.get().getString(R.string.poll) : poll.getTitle());
            for (PollQuestion question : poll.getQuestions()) {
                t.setVariableOpt("question_title", question.getTitle());
                for (PollQuestionItem questionItem : question.getQuestionItems()) {
                    t.setVariableOpt("question_item_title", questionItem.getTitle());
                    if (isResult) {
                        t.setVariableOpt("question_item_votes", questionItem.getVotes());
                        t.setVariableOpt("question_item_percent", Float.toString(questionItem.getPercent()));
                        t.addBlockOpt("poll_result_item");
                    } else {
                        t.setVariableOpt("question_item_type", questionItem.getType());
                        t.setVariableOpt("question_item_name", questionItem.getName());
                        t.setVariableOpt("question_item_value", questionItem.getValue());
                        t.addBlockOpt("poll_default_item");
                    }
                }
                t.addBlockOpt("poll_question_block");
            }
            t.setVariableOpt("poll_votes_count", poll.getVotesCount());
            if (poll.haveButtons()) {
                if (poll.haveVoteButton())
                    t.addBlockOpt("poll_vote_button");
                if (poll.haveShowResultsButton())
                    t.addBlockOpt("poll_show_results_button");
                if (poll.haveShowPollButton())
                    t.addBlockOpt("poll_show_poll_button");
                t.addBlockOpt("poll_buttons");
            }
            t.addBlockOpt("poll_block");
        }
        page.setHtml(t.generateOutput());
        t.reset();
    }
    return page;
}
Also used : ThemePost(forpdateam.ru.forpda.api.theme.models.ThemePost) PollQuestion(forpdateam.ru.forpda.api.theme.models.PollQuestion) ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Poll(forpdateam.ru.forpda.api.theme.models.Poll) PollQuestionItem(forpdateam.ru.forpda.api.theme.models.PollQuestionItem) MiniTemplator(biz.source_code.miniTemplator.MiniTemplator)

Example 5 with MiniTemplator

use of biz.source_code.miniTemplator.MiniTemplator in project ForPDA by RadiationX.

the class NewsRx method transform.

public static DetailsPage transform(DetailsPage page) throws Exception {
    MiniTemplator t = App.get().getTemplate(App.TEMPLATE_NEWS);
    App.setTemplateResStrings(t);
    t.setVariableOpt("style_type", App.get().getCssStyleType());
    t.setVariableOpt("details_title", ApiUtils.htmlEncode(page.getTitle()));
    t.setVariableOpt("details_content", page.getHtml());
    for (Material material : page.getMaterials()) {
        t.setVariableOpt("material_id", material.getId());
        t.setVariableOpt("material_image", material.getImageUrl());
        t.setVariableOpt("material_title", material.getTitle());
        t.addBlockOpt("material");
    }
    page.setHtml(t.generateOutput());
    t.reset();
    return page;
}
Also used : Material(forpdateam.ru.forpda.api.news.models.Material) MiniTemplator(biz.source_code.miniTemplator.MiniTemplator)

Aggregations

MiniTemplator (biz.source_code.miniTemplator.MiniTemplator)10 SuppressLint (android.annotation.SuppressLint)3 ForumUser (forpdateam.ru.forpda.api.others.user.ForumUser)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 JavascriptInterface (android.webkit.JavascriptInterface)1 ForumRules (forpdateam.ru.forpda.api.forum.models.ForumRules)1 Material (forpdateam.ru.forpda.api.news.models.Material)1 QmsMessage (forpdateam.ru.forpda.api.qms.models.QmsMessage)1 SearchItem (forpdateam.ru.forpda.api.search.models.SearchItem)1 Poll (forpdateam.ru.forpda.api.theme.models.Poll)1 PollQuestion (forpdateam.ru.forpda.api.theme.models.PollQuestion)1 PollQuestionItem (forpdateam.ru.forpda.api.theme.models.PollQuestionItem)1 ThemePost (forpdateam.ru.forpda.api.theme.models.ThemePost)1