BearND has uploaded a new change for review. https://gerrit.wikimedia.org/r/174821
Change subject: Display native Read more section ...................................................................... Display native Read more section except on Main page, since that provides strange links. (The layout at the end still needs to be fixed. It overlaps with the attribution links.) Change-Id: Idbe51ef33b24fd35383565b48331ef4461e4137e --- M wikipedia/res/layout/fragment_page.xml M wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java M wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java 3 files changed, 159 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/21/174821/1 diff --git a/wikipedia/res/layout/fragment_page.xml b/wikipedia/res/layout/fragment_page.xml index 182174a..7b2d433 100644 --- a/wikipedia/res/layout/fragment_page.xml +++ b/wikipedia/res/layout/fragment_page.xml @@ -2,10 +2,11 @@ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/page_background_color" - > + tools:context=".page.PageActivity"> <org.wikipedia.views.DisableableDrawerLayout android:id="@+id/page_toc_drawer" android:layout_width="match_parent" @@ -81,6 +82,26 @@ android:background="?attr/subtle_gray_color" android:layout_gravity="bottom" android:visibility="invisible"> + <LinearLayout + android:id="@+id/read_more_container" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + <TextView + style="?android:textAppearanceLarge" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="16dp" + android:fontFamily="serif" + android:textSize="24sp" + android:text="@string/read_more_section" + /> + <ListView + android:id="@+id/read_more_list" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + </ListView> + </LinearLayout> <View android:layout_width="match_parent" android:layout_height="8dp" diff --git a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java index f5eb4bb..5edaf28 100644 --- a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java +++ b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java @@ -467,7 +467,8 @@ // create bottom content for this page... new BottomContentHandler(parentFragment, bridge, webView, linkHandler, - (ViewGroup) parentFragment.getView().findViewById(R.id.bottom_content_container)); + (ViewGroup) parentFragment.getView().findViewById(R.id.bottom_content_container), + title, page.getPageProperties().isMainPage()); } }); diff --git a/wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java b/wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java index 8d594e7..2833b90 100644 --- a/wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java +++ b/wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java @@ -3,28 +3,51 @@ import android.graphics.Point; import android.os.Build; import android.text.Html; +import android.text.TextUtils; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView; +import android.widget.AdapterView; +import android.widget.BaseAdapter; import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.ListView; import android.widget.TextView; + +import com.squareup.picasso.Picasso; import org.json.JSONException; import org.json.JSONObject; +import org.wikipedia.PageTitle; import org.wikipedia.R; import org.wikipedia.Utils; +import org.wikipedia.WikipediaApp; import org.wikipedia.bridge.CommunicationBridge; +import org.wikipedia.history.HistoryEntry; import org.wikipedia.page.LinkHandler; import org.wikipedia.page.LinkMovementMethodExt; import org.wikipedia.page.Page; +import org.wikipedia.page.PageActivity; import org.wikipedia.page.PageViewFragment; +import org.wikipedia.page.SuggestionsTask; +import org.wikipedia.search.FullSearchArticlesTask; +import org.wikipedia.search.FullSearchResult; import org.wikipedia.views.ObservableWebView; +import org.wikipedia.wikidata.WikidataCache; +import org.wikipedia.wikidata.WikidataDescriptionFeeder; + +import java.util.List; +import java.util.Map; public class BottomContentHandler implements ObservableWebView.OnScrollChangeListener { private final PageViewFragment parentFragment; private final CommunicationBridge bridge; private final WebView webView; private final LinkHandler linkHandler; + private final PageTitle pageTitle; + private final PageActivity activity; + private final WikipediaApp app; private int displayHeight; private float displayDensity; @@ -34,11 +57,15 @@ private TextView pageLicenseText; public BottomContentHandler(final PageViewFragment parentFragment, CommunicationBridge bridge, - ObservableWebView webview, LinkHandler linkHandler, ViewGroup hidingView) { + ObservableWebView webview, LinkHandler linkHandler, ViewGroup hidingView, + PageTitle pageTitle, boolean isMainPage) { this.parentFragment = parentFragment; this.bridge = bridge; this.webView = webview; this.linkHandler = linkHandler; + this.pageTitle = pageTitle; + activity = parentFragment.getFragment().getActivity(); + app = (WikipediaApp) activity.getApplicationContext(); displayDensity = parentFragment.getResources().getDisplayMetrics().density; bottomContentContainer = hidingView; @@ -61,6 +88,11 @@ } layoutContent(); + if (isMainPage) { + bottomContentContainer.findViewById(R.id.read_more_container).setVisibility(View.GONE); + } else { + requestReadMoreItems(activity.getLayoutInflater()); + } } @Override @@ -108,4 +140,106 @@ // trigger a manual scroll event to update our position onScrollChanged(webView.getScrollY(), webView.getScrollY()); } + + private void requestReadMoreItems(final LayoutInflater layoutInflater) { + new SuggestionsTask(app.getAPIForSite(pageTitle.getSite()), pageTitle.getSite(), + pageTitle.getPrefixedText()) { + @Override + public void onFinish(FullSearchResults results) { + setupReadMoreSection(bottomContentContainer, layoutInflater, results); + } + + @Override + public void onCatch(Throwable caught) { + super.onCatch(caught); + } + }.execute(); + } + + private ListView list; + private void setupReadMoreSection(View bottomContentContainer, LayoutInflater layoutInflater, + FullSearchArticlesTask.FullSearchResults results) { + list = (ListView)bottomContentContainer.findViewById(R.id.read_more_list); + final ReadMoreAdapter adapter = new ReadMoreAdapter(layoutInflater, results.getResults()); + list.setAdapter(adapter); + list.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + PageTitle title = ((FullSearchResult) list.getAdapter().getItem(position)).getTitle(); + HistoryEntry historyEntry = new HistoryEntry(title, HistoryEntry.SOURCE_INTERNAL_LINK); + activity.displayNewPage(title, historyEntry); + } + }); + + WikidataDescriptionFeeder.retrieveWikidataDescriptions(results.getResults(), app, + new WikidataCache.OnWikidataReceiveListener() { + @Override + public void onWikidataReceived(Map<String, String> result) { + adapter.notifyDataSetChanged(); + } + + @Override + public void onWikidataFailed(Throwable caught) { + // Don't actually do anything. + // Descriptions are expendable + } + }); + } + + private final class ReadMoreAdapter extends BaseAdapter { + private final LayoutInflater inflater; + private final List<FullSearchResult> results; + + private ReadMoreAdapter(LayoutInflater inflater, List<FullSearchResult> results) { + this.inflater = inflater; + this.results = results; + } + + @Override + public int getCount() { + return results == null ? 0 : results.size(); + } + + @Override + public Object getItem(int position) { + return results.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + if (convertView == null) { + convertView = inflater.inflate(R.layout.item_full_search_result, parent, false); + } + TextView pageTitleText = (TextView) convertView.findViewById(R.id.result_title); + FullSearchResult result = (FullSearchResult) getItem(position); + pageTitleText.setText(result.getTitle().getDisplayText()); + + String wikidataId = result.getWikiBaseId(); + if (!TextUtils.isEmpty(wikidataId)) { + TextView descriptionText = (TextView) convertView.findViewById(R.id.result_description); + descriptionText.setText(app.getWikidataCache().get(wikidataId)); + } + + ImageView imageView = (ImageView) convertView.findViewById(R.id.result_image); + String thumbnail = result.getThumbUrl(); + if (thumbnail == null) { + Picasso.with(parent.getContext()) + .load(R.drawable.ic_pageimage_placeholder) + .into(imageView); + } else { + Picasso.with(parent.getContext()) + .load(thumbnail) + .placeholder(R.drawable.ic_pageimage_placeholder) + .error(R.drawable.ic_pageimage_placeholder) + .into(imageView); + } + + return convertView; + } + } } -- To view, visit https://gerrit.wikimedia.org/r/174821 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idbe51ef33b24fd35383565b48331ef4461e4137e Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: BearND <bsitzm...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits