use of de.danoeh.antennapod.discovery.PodcastSearchResult in project AntennaPod by AntennaPod.
the class DiscoveryFragment method updateData.
/**
* Replace adapter data with provided search results from SearchTask.
* @param result List of Podcast objects containing search results
*/
private void updateData(List<PodcastSearchResult> result) {
this.searchResults = result;
adapter.clear();
if (result != null && result.size() > 0) {
gridView.setVisibility(View.VISIBLE);
txtvEmpty.setVisibility(View.GONE);
for (PodcastSearchResult p : result) {
adapter.add(p);
}
adapter.notifyDataSetInvalidated();
} else {
gridView.setVisibility(View.GONE);
txtvEmpty.setVisibility(View.VISIBLE);
}
}
use of de.danoeh.antennapod.discovery.PodcastSearchResult in project AntennaPod by AntennaPod.
the class DiscoveryFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root = inflater.inflate(R.layout.fragment_itunes_search, container, false);
gridView = root.findViewById(R.id.gridView);
adapter = new ItunesAdapter(getActivity(), new ArrayList<>());
gridView.setAdapter(adapter);
Toolbar toolbar = root.findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack());
// Show information about the podcast when the list item is clicked
gridView.setOnItemClickListener((parent, view1, position, id) -> {
PodcastSearchResult podcast = searchResults.get(position);
if (podcast.feedUrl == null) {
return;
}
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl);
startActivity(intent);
});
List<String> countryCodeArray = new ArrayList<String>(Arrays.asList(Locale.getISOCountries()));
HashMap<String, String> countryCodeNames = new HashMap<String, String>();
for (String code : countryCodeArray) {
Locale locale = new Locale("", code);
String countryName = locale.getDisplayCountry();
if (countryName != null) {
countryCodeNames.put(code, countryName);
}
}
List<String> countryNamesSort = new ArrayList<String>(countryCodeNames.values());
Collections.sort(countryNamesSort);
countryNamesSort.add(0, getResources().getString(R.string.discover_hide));
Spinner countrySpinner = root.findViewById(R.id.spinner_country);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this.getContext(), android.R.layout.simple_spinner_item, countryNamesSort);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
countrySpinner.setAdapter(dataAdapter);
int pos = countryNamesSort.indexOf(countryCodeNames.get(countryCode));
countrySpinner.setSelection(pos);
countrySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> countrySpinner, View view, int position, long id) {
String countryName = (String) countrySpinner.getItemAtPosition(position);
if (countryName.equals(getResources().getString(R.string.discover_hide))) {
countryCode = ItunesTopListLoader.DISCOVER_HIDE_FAKE_COUNTRY_CODE;
} else {
for (Object o : countryCodeNames.keySet()) {
if (countryCodeNames.get(o).equals(countryName)) {
countryCode = o.toString();
break;
}
}
}
prefs.edit().putString(ItunesTopListLoader.PREF_KEY_COUNTRY_CODE, countryCode).apply();
EventBus.getDefault().post(new DiscoveryDefaultUpdateEvent());
loadToplist(countryCode);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
progressBar = root.findViewById(R.id.progressBar);
txtvError = root.findViewById(R.id.txtvError);
butRetry = root.findViewById(R.id.butRetry);
txtvEmpty = root.findViewById(android.R.id.empty);
loadToplist(countryCode);
return root;
}
use of de.danoeh.antennapod.discovery.PodcastSearchResult in project AntennaPod by AntennaPod.
the class OnlineSearchFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root = inflater.inflate(R.layout.fragment_itunes_search, container, false);
root.findViewById(R.id.spinner_country).setVisibility(INVISIBLE);
gridView = root.findViewById(R.id.gridView);
adapter = new ItunesAdapter(getActivity(), new ArrayList<>());
gridView.setAdapter(adapter);
// Show information about the podcast when the list item is clicked
gridView.setOnItemClickListener((parent, view1, position, id) -> {
PodcastSearchResult podcast = searchResults.get(position);
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl);
intent.putExtra(MainActivity.EXTRA_STARTED_FROM_SEARCH, true);
startActivity(intent);
});
progressBar = root.findViewById(R.id.progressBar);
txtvError = root.findViewById(R.id.txtvError);
butRetry = root.findViewById(R.id.butRetry);
txtvEmpty = root.findViewById(android.R.id.empty);
TextView txtvPoweredBy = root.findViewById(R.id.search_powered_by);
txtvPoweredBy.setText(getString(R.string.search_powered_by, searchProvider.getName()));
setupToolbar(root.findViewById(R.id.toolbar));
gridView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == SCROLL_STATE_TOUCH_SCROLL) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
return root;
}
Aggregations