@Override public int getItemViewType(int position) { Util.Lang lang = activity.getTextLang(); if (lang == Util.Lang.BI || itemList.get(position).getText(lang).length() == 0) return BI_LINK_TEXT_VIEW_TYPE; else return MONO_LINK_TEXT_VIEW_TYPE; }
public void initialUpdate(LinkFilter linkFilterAll, Util.Lang lang) { hasBeenInitialized = true; List<LinkFilter> yo = Settings.Link.getLinks(activity.getBook().getTitle(Util.Lang.EN), linkFilterAll); linkSelectorQueue = new LinkedList<>(yo); currLinkCount = null; // initialize to all grayed update(lang); }
// if currLinkCount == null, all linkSelectorBarButtons will be gray public void update(LinkFilter currLinkCount, Util.Lang lang) { this.currLinkCount = currLinkCount; selectorListLayout.removeAllViews(); if (linkSelectorQueue == null) return; ListIterator<LinkFilter> linkIt = linkSelectorQueue.listIterator(linkSelectorQueue.size()); while (linkIt.hasPrevious()) { // add children in reverse order LinkFilter tempLC = linkIt.previous(); LinkSelectorBarButton lssb = new LinkSelectorBarButton(activity, tempLC, activity.getBook(), lang); lssb.setOnClickListener(linkSelectorBarButtonClick); selectorListLayout.addView(lssb); if (!LinkFilter.pseudoEquals(tempLC, currLinkCount)) { lssb.setTextColor(Util.getColor(activity, R.attr.text_chapter_header_color)); } } Settings.Link.setLinks(activity.getBook().getTitle(Util.Lang.EN), linkSelectorQueue); }
private boolean menuClick(View v, boolean longClick) { boolean goToTOC = longClick; longClick = false; MenuButton mb = (MenuButton) v; MenuState newMenuState = menuState.goForward(mb.getNode(), mb.getSectionNode()); Intent intent; if (mb.isBook()) { Book book = null; try { if (!Settings.getUseAPI() && !Database.hasOfflineDB()) { // There's no DB //TODO make it work with API Settings.setUseAPI(true); } book = new Book(newMenuState.getCurrNode().getTitle(Util.Lang.EN)); if (goToTOC) { intent = TOCActivity.getStartTOCActivityIntent(context, book, null); /// intent = new Intent(context, TOCActivity.class); // intent.putExtra("currBook", book); // intent.putExtra("lang", newMenuState.getLang()); context.startActivity(intent); return true; } else { SuperTextActivity.startNewTextActivityIntent(context, book, longClick); } } catch (Book.BookNotFoundException e) { Toast.makeText(context, MyApp.getRString(R.string.sorry_book_not_found), Toast.LENGTH_SHORT) .show(); } } else { intent = new Intent(context, MenuActivity.class); Bundle options = null; if (longClick) { intent = MyApp.startNewTab(intent); options = ActivityOptionsCompat.makeCustomAnimation( context, R.animator.activity_zoom_in, R.animator.activity_zoom_out) .toBundle(); } intent.putExtra("menuState", newMenuState); intent.putExtra("hasSectionBack", mb.getSectionNode() != null); intent.putExtra("hasTabBack", hasTabs); if (longClick) { ActivityCompat.startActivityForResult((Activity) context, intent, 0, options); } else { ((Activity) context).startActivityForResult(intent, 0); } } return false; }
@Override public void onBindViewHolder(LinkTextHolder holder, int position) { Util.Lang lang = activity.getTextLang(); Segment link = itemList.get(position); if (link.getText(lang).length() == 0) lang = Util.Lang.BI; // TODO noah, make this better. holder.title.setVisibility(View.VISIBLE); holder.title.setText(Html.fromHtml(link.getLocationString(Settings.getMenuLang()))); holder.title.setFont(Settings.getMenuLang(), true, activity.getTextSize()); holder.setPosition(position); // itemList might not have updated yet if you switched pesukim. make sure it's up to date if (!holder.getItemList().equals(itemList)) holder.setItemList(itemList); if (holder instanceof LinkMonoTextHolder) { LinkMonoTextHolder monoHolder = (LinkMonoTextHolder) holder; String text; if (link.getText(lang).length() == 0) text = activity.getResources().getString(R.string.no_text); else text = link.getText(lang); monoHolder.monoTv.setText(Html.fromHtml(Util.getBidiString(text, lang))); monoHolder.monoTv.setFont(lang, true, activity.getTextSize()); monoHolder.monoTv.setLangGravity(lang); } else if (holder instanceof LinkBiTextHolder) { LinkBiTextHolder biHolder = (LinkBiTextHolder) holder; biHolder.enTv.setVisibility(View.VISIBLE); biHolder.heTv.setVisibility(View.VISIBLE); String enText = link.getText(Util.Lang.EN); String heText = link.getText(Util.Lang.HE); if (enText.length() == 0) biHolder.enTv.setVisibility(View.GONE); else biHolder.enTv.setText(Html.fromHtml(Util.getBidiString(enText, Util.Lang.EN))); biHolder.enTv.setFont(Util.Lang.EN, true, activity.getTextSize()); if (heText.length() == 0) biHolder.heTv.setVisibility(View.GONE); else biHolder.heTv.setText(Html.fromHtml(Util.getBidiString(heText, Util.Lang.HE))); biHolder.heTv.setFont(Util.Lang.HE, true, activity.getTextSize()); } }