Get list of langs in WikivoyageArticleDialogFragment#showInstance
This commit is contained in:
parent
09605ce46b
commit
f1376b069c
2 changed files with 27 additions and 12 deletions
|
@ -22,6 +22,7 @@ import android.widget.TextView;
|
|||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
|
||||
|
@ -260,11 +261,24 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
return normal;
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentManager fm, long cityId, ArrayList<String> langs) {
|
||||
public static boolean showInstance(@NonNull OsmandApplication app,
|
||||
@NonNull FragmentManager fm,
|
||||
long cityId,
|
||||
@Nullable String selectedLang) {
|
||||
ArrayList<String> langs = app.getWikivoyageDbHelper().getArticleLangs(cityId);
|
||||
return showInstance(fm, cityId, langs, selectedLang);
|
||||
}
|
||||
|
||||
public static boolean showInstance(@NonNull FragmentManager fm,
|
||||
long cityId,
|
||||
@NonNull ArrayList<String> langs) {
|
||||
return showInstance(fm, cityId, langs, null);
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentManager fm, long cityId, ArrayList<String> langs, @Nullable String selectedLang) {
|
||||
public static boolean showInstance(@NonNull FragmentManager fm,
|
||||
long cityId,
|
||||
@NonNull ArrayList<String> langs,
|
||||
@Nullable String selectedLang) {
|
||||
try {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong(CITY_ID_KEY, cityId);
|
||||
|
|
|
@ -18,9 +18,10 @@ import android.widget.ImageButton;
|
|||
import android.widget.ProgressBar;
|
||||
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
|
||||
import net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem;
|
||||
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
|
||||
|
@ -47,7 +48,8 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
|
|||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
searchHelper = new WikivoyageSearchHelper(getMyApplication());
|
||||
final OsmandApplication app = getMyApplication();
|
||||
searchHelper = new WikivoyageSearchHelper(app);
|
||||
|
||||
final View mainView = inflate(R.layout.fragment_wikivoyage_search_dialog, container);
|
||||
|
||||
|
@ -93,7 +95,7 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
|
|||
}
|
||||
});
|
||||
|
||||
adapter = new SearchRecyclerViewAdapter(getMyApplication());
|
||||
adapter = new SearchRecyclerViewAdapter(app);
|
||||
final RecyclerView rv = (RecyclerView) mainView.findViewById(R.id.recycler_view);
|
||||
rv.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
rv.setAdapter(adapter);
|
||||
|
@ -101,18 +103,17 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
int pos = rv.getChildAdapterPosition(v);
|
||||
if (pos != RecyclerView.NO_POSITION) {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (pos != RecyclerView.NO_POSITION && fm != null) {
|
||||
Object item = adapter.getItem(pos);
|
||||
if (item instanceof WikivoyageSearchResult) {
|
||||
WikivoyageSearchResult res = (WikivoyageSearchResult) item;
|
||||
WikivoyageArticleDialogFragment.showInstance(getFragmentManager(),
|
||||
res.getCityId(), new ArrayList<>(res.getLangs()));
|
||||
WikivoyageArticleDialogFragment
|
||||
.showInstance(fm, res.getCityId(), new ArrayList<>(res.getLangs()));
|
||||
} else if (item instanceof WikivoyageSearchHistoryItem) {
|
||||
WikivoyageSearchHistoryItem historyItem = (WikivoyageSearchHistoryItem) item;
|
||||
ArrayList<String> langs = getMyApplication().getWikivoyageDbHelper()
|
||||
.getArticleLangs(historyItem.getCityId());
|
||||
WikivoyageArticleDialogFragment.showInstance(getFragmentManager(),
|
||||
historyItem.getCityId(), langs, historyItem.getLang());
|
||||
WikivoyageArticleDialogFragment
|
||||
.showInstance(app, fm, historyItem.getCityId(), historyItem.getLang());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue