use of org.wikipedia.history.HistoryEntry in project apps-android-wikipedia by wikimedia.
the class MainPageReadMoreTopicTask method performTask.
@Override
public HistoryEntry performTask() throws Throwable {
Cursor c = getInterestedHistoryEntry();
try {
if (c.moveToPosition(age)) {
HistoryEntry entry = HistoryEntry.DATABASE_TABLE.fromCursor(c);
entry.getTitle().setThumbUrl(PageImageHistoryContract.Col.IMAGE_NAME.val(c));
return entry.getTitle().isMainPage() ? null : entry;
}
return null;
} finally {
c.close();
}
}
use of org.wikipedia.history.HistoryEntry in project apps-android-wikipedia by wikimedia.
the class SearchFragment method navigateToTitle.
@Override
public void navigateToTitle(@NonNull PageTitle title, boolean inNewTab, int position) {
if (!isAdded()) {
return;
}
funnel.searchClick(position);
HistoryEntry historyEntry = new HistoryEntry(title, HistoryEntry.SOURCE_SEARCH);
Callback callback = callback();
if (callback != null) {
callback.onSearchSelectPage(historyEntry, inNewTab);
}
closeSearch();
}
use of org.wikipedia.history.HistoryEntry in project apps-android-wikipedia by wikimedia.
the class LangLinksActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = WikipediaApp.getInstance();
setStatusBarColor(ResourceUtil.getThemedAttributeId(this, R.attr.page_status_bar_color));
setContentView(R.layout.activity_langlinks);
if (!getIntent().getAction().equals(ACTION_LANGLINKS_FOR_TITLE)) {
throw new RuntimeException("Only ACTION_LANGLINKS_FOR_TITLE is supported");
}
langLinksList = findViewById(R.id.langlinks_list);
langLinksProgress = findViewById(R.id.langlinks_load_progress);
langLinksContainer = findViewById(R.id.langlinks_list_container);
langLinksEmpty = findViewById(R.id.langlinks_empty);
langLinksNoMatch = findViewById(R.id.langlinks_no_match);
langLinksError = findViewById(R.id.langlinks_error);
EditText langLinksFilter = findViewById(R.id.langlinks_filter);
title = getIntent().getParcelableExtra(EXTRA_PAGETITLE);
if (savedInstanceState != null && savedInstanceState.containsKey(LANGUAGE_ENTRIES_BUNDLE_KEY)) {
languageEntries = savedInstanceState.getParcelableArrayList(LANGUAGE_ENTRIES_BUNDLE_KEY);
}
client = new LangLinksClient();
fetchLangLinks();
langLinksError.setRetryClickListener((v) -> {
ViewAnimations.crossFade(langLinksError, langLinksProgress);
fetchLangLinks();
});
langLinksList.setOnItemClickListener((parent, view, position, id) -> {
PageTitle langLink = (PageTitle) parent.getAdapter().getItem(position);
app.setMruLanguageCode(langLink.getWikiSite().languageCode());
HistoryEntry historyEntry = new HistoryEntry(langLink, HistoryEntry.SOURCE_LANGUAGE_LINK);
Intent intent = PageActivity.newIntentForCurrentTab(LangLinksActivity.this, historyEntry, langLink);
setResult(ACTIVITY_RESULT_LANGLINK_SELECT, intent);
hideSoftKeyboard(LangLinksActivity.this);
finish();
});
langLinksFilter.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
// the languages might not be loaded yet...
if (langLinksList.getAdapter() == null) {
return;
}
((LangLinksAdapter) langLinksList.getAdapter()).setFilterText(s.toString());
// Check if there are no languages that match the filter
if (langLinksList.getAdapter().getCount() == 0) {
langLinksNoMatch.setVisibility(View.VISIBLE);
} else {
langLinksNoMatch.setVisibility(View.GONE);
}
}
});
}
use of org.wikipedia.history.HistoryEntry in project apps-android-wikipedia by wikimedia.
the class CompilationDetailFragment method onMainPageClick.
@OnClick(R.id.button_compilation_detail_main_page)
void onMainPageClick() {
try {
PageTitle title = new PageTitle(OfflineManager.instance().getMainPageTitle(compilation), WikipediaApp.getInstance().getWikiSite());
HistoryEntry entry = new HistoryEntry(title, HistoryEntry.SOURCE_MAIN_PAGE);
startActivity(PageActivity.newIntentForNewTab(getContext(), entry, entry.getTitle()));
} catch (IOException e) {
L.e(e);
FeedbackUtil.showError(getActivity(), e);
}
}
use of org.wikipedia.history.HistoryEntry in project apps-android-wikipedia by wikimedia.
the class EditPreviewFragment method displayPreview.
private void displayPreview(final String html) {
if (!isWebViewSetup) {
isWebViewSetup = true;
L10nUtil.setupDirectionality(parentActivity.getPageTitle().getWikiSite().languageCode(), Locale.getDefault().getLanguage(), bridge);
if (!WikipediaApp.getInstance().getCurrentTheme().isDefault()) {
ThemeBridgeAdapter.setTheme(bridge);
}
bridge.addListener("linkClicked", new LinkHandler(getActivity()) {
@Override
public void onPageLinkClicked(@NonNull String href) {
// TODO: also need to handle references, issues, disambig, ... in preview eventually
}
@Override
public void onInternalLinkClicked(@NonNull final PageTitle title) {
showLeavingEditDialogue(() -> startActivity(PageActivity.newIntentForNewTab(getContext(), new HistoryEntry(title, HistoryEntry.SOURCE_INTERNAL_LINK), title)));
}
@Override
public void onExternalLinkClicked(@NonNull final Uri uri) {
showLeavingEditDialogue(() -> handleExternalLink(getContext(), uri));
}
/**
* Shows the user a dialogue asking them if they really meant to leave the edit
* workflow, and warning them that their changes have not yet been saved.
* @param runnable The runnable that is run if the user chooses to leave.
*/
private void showLeavingEditDialogue(final Runnable runnable) {
// Ask the user if they really meant to leave the edit workflow
final AlertDialog leavingEditDialog = new AlertDialog.Builder(getActivity()).setMessage(R.string.dialog_message_leaving_edit).setPositiveButton(R.string.dialog_message_leaving_edit_leave, (dialog, which) -> {
// They meant to leave; close dialogue and run specified action
dialog.dismiss();
runnable.run();
}).setNegativeButton(R.string.dialog_message_leaving_edit_stay, null).create();
leavingEditDialog.show();
}
@Override
public WikiSite getWikiSite() {
return parentActivity.getPageTitle().getWikiSite();
}
});
bridge.addListener("imageClicked", (messageType, messagePayload) -> {
// TODO: do something when an image is clicked in Preview.
});
bridge.addListener("mediaClicked", (messageType, messagePayload) -> {
// TODO: do something when a video is clicked in Preview.
});
bridge.addListener("referenceClicked", (messageType, messagePayload) -> {
// TODO: do something when a reference is clicked in Preview.
});
}
ViewAnimations.fadeIn(previewContainer, () -> parentActivity.supportInvalidateOptionsMenu());
ViewAnimations.fadeOut(getActivity().findViewById(R.id.edit_section_container));
JSONObject payload = new JSONObject();
try {
payload.put("html", html);
payload.put("siteBaseUrl", parentActivity.getPageTitle().getWikiSite().url());
} catch (JSONException e) {
throw new RuntimeException(e);
}
bridge.sendMessage("displayPreviewHTML", payload);
}
Aggregations