Add the ability to open article from search
This commit is contained in:
parent
69f891c82f
commit
3ff4bb8dbd
4 changed files with 101 additions and 3 deletions
31
OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml
Normal file
31
OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dashboard_map_toolbar"
|
||||
android:minHeight="@dimen/dashboard_map_toolbar"
|
||||
android:theme="?attr/toolbar_theme"
|
||||
osmand:contentInsetLeft="54dp"
|
||||
osmand:contentInsetStart="54dp">
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/content_text_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,61 @@
|
|||
package net.osmand.plus.wikivoyage;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.data.SearchResult;
|
||||
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
|
||||
|
||||
public class WikivoyageArticleDialogFragment extends BaseOsmAndDialogFragment {
|
||||
|
||||
public static final String TAG = "WikivoyageArticleDialogFragment";
|
||||
|
||||
private SearchResult searchResult;
|
||||
|
||||
public void setSearchResult(SearchResult searchResult) {
|
||||
this.searchResult = searchResult;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
final View mainView = inflater.inflate(R.layout.fragment_wikivoyage_article_dialog, container);
|
||||
|
||||
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
|
||||
toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back));
|
||||
toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
TextView contentTv = (TextView) mainView.findViewById(R.id.content_text_view);
|
||||
WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper().getArticle(searchResult);
|
||||
contentTv.setText(new SpannableString(Html.fromHtml(article.getContent())));
|
||||
|
||||
return mainView;
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentManager fm, SearchResult searchResult) {
|
||||
try {
|
||||
WikivoyageArticleDialogFragment fragment = new WikivoyageArticleDialogFragment();
|
||||
fragment.setSearchResult(searchResult);
|
||||
fragment.show(fm, TAG);
|
||||
return true;
|
||||
} catch (RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,8 +7,10 @@ import net.osmand.IndexConstants;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -129,7 +131,11 @@ public class WikivoyageDbHelper {
|
|||
|
||||
res.id = cursor.getString(0);
|
||||
res.title = cursor.getString(1);
|
||||
byte[] contentBlob = cursor.getBlob(2);
|
||||
try {
|
||||
res.content = Algorithms.gzipToString(cursor.getBlob(2));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
res.isPartOf = cursor.getString(3);
|
||||
res.lat = cursor.getDouble(4);
|
||||
res.lon = cursor.getDouble(5);
|
||||
|
|
|
@ -17,7 +17,7 @@ import android.widget.TextView;
|
|||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
|
||||
import net.osmand.plus.wikivoyage.WikivoyageArticleDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper;
|
||||
|
||||
public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment {
|
||||
|
@ -76,7 +76,7 @@ public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment {
|
|||
public void onClick(View v) {
|
||||
int pos = rv.getChildAdapterPosition(v);
|
||||
if (pos != RecyclerView.NO_POSITION) {
|
||||
WikivoyageArticle article = dbHelper.getArticle(adapter.getItem(pos));
|
||||
WikivoyageArticleDialogFragment.showInstance(getFragmentManager(), adapter.getItem(pos));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue