From 941154704b8d6576d2868ab216a906469e841ecb Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Thu, 2 Aug 2012 23:00:01 +0200 Subject: Replaced 'miro' in filenames with 'miroguide' --- .../antennapod/activity/MiroGuideMainActivity.java | 12 +- .../activity/MiroGuideSearchActivity.java | 82 +++++++ .../antennapod/activity/MiroSearchActivity.java | 82 ------- .../antennapod/adapter/MiroChannellistAdapter.java | 57 ----- .../adapter/MiroGuideChannelListAdapter.java | 57 +++++ .../fragment/MiroChannellistFragment.java | 247 --------------------- .../fragment/MiroGuideChannellistFragment.java | 247 +++++++++++++++++++++ .../antennapod/miroguide/con/MiroConnector.java | 127 ----------- .../antennapod/miroguide/con/MiroException.java | 23 -- .../miroguide/con/MiroGuideConnector.java | 127 +++++++++++ .../miroguide/con/MiroGuideException.java | 23 ++ .../antennapod/miroguide/con/MiroGuideService.java | 148 ++++++++++++ .../antennapod/miroguide/con/MiroService.java | 148 ------------ 13 files changed, 690 insertions(+), 690 deletions(-) create mode 100644 src/de/danoeh/antennapod/activity/MiroGuideSearchActivity.java delete mode 100644 src/de/danoeh/antennapod/activity/MiroSearchActivity.java delete mode 100644 src/de/danoeh/antennapod/adapter/MiroChannellistAdapter.java create mode 100644 src/de/danoeh/antennapod/adapter/MiroGuideChannelListAdapter.java delete mode 100644 src/de/danoeh/antennapod/fragment/MiroChannellistFragment.java create mode 100644 src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java delete mode 100644 src/de/danoeh/antennapod/miroguide/con/MiroConnector.java delete mode 100644 src/de/danoeh/antennapod/miroguide/con/MiroException.java create mode 100644 src/de/danoeh/antennapod/miroguide/con/MiroGuideConnector.java create mode 100644 src/de/danoeh/antennapod/miroguide/con/MiroGuideException.java create mode 100644 src/de/danoeh/antennapod/miroguide/con/MiroGuideService.java delete mode 100644 src/de/danoeh/antennapod/miroguide/con/MiroService.java (limited to 'src/de/danoeh') diff --git a/src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java b/src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java index 6b794dd46..9331436a5 100644 --- a/src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java +++ b/src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java @@ -13,8 +13,8 @@ import com.actionbarsherlock.view.MenuItem; import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.miroguide.con.MiroException; -import de.danoeh.antennapod.miroguide.con.MiroService; +import de.danoeh.antennapod.miroguide.con.MiroGuideException; +import de.danoeh.antennapod.miroguide.con.MiroGuideService; /** Shows a list of available categories and offers a search button. */ public class MiroGuideMainActivity extends SherlockListActivity { @@ -29,7 +29,7 @@ public class MiroGuideMainActivity extends SherlockListActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - setContentView(R.layout.miro_categorylist); + setContentView(R.layout.miroguide_categorylist); txtvStatus = (TextView) findViewById(android.R.id.empty); } @@ -63,7 +63,7 @@ public class MiroGuideMainActivity extends SherlockListActivity { AsyncTask listLoader = new AsyncTask() { private String[] c; - private MiroException exception; + private MiroGuideException exception; @Override protected void onPostExecute(Void result) { @@ -85,10 +85,10 @@ public class MiroGuideMainActivity extends SherlockListActivity { @Override protected Void doInBackground(Void... params) { - MiroService service = new MiroService(); + MiroGuideService service = new MiroGuideService(); try { c = service.getCategories(); - } catch (MiroException e) { + } catch (MiroGuideException e) { e.printStackTrace(); exception = e; } diff --git a/src/de/danoeh/antennapod/activity/MiroGuideSearchActivity.java b/src/de/danoeh/antennapod/activity/MiroGuideSearchActivity.java new file mode 100644 index 000000000..d5cb4b1e0 --- /dev/null +++ b/src/de/danoeh/antennapod/activity/MiroGuideSearchActivity.java @@ -0,0 +1,82 @@ +package de.danoeh.antennapod.activity; + +import android.app.SearchManager; +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.FragmentTransaction; +import android.util.Log; + +import com.actionbarsherlock.app.SherlockFragmentActivity; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuItem; + +import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.fragment.MiroGuideChannellistFragment; + +/** Displays results when a search for miroguide channels has been performed */ +public class MiroGuideSearchActivity extends SherlockFragmentActivity { + private static final String TAG = "MiroGuideSearchActivity"; + + private MiroGuideChannellistFragment listFragment; + + @Override + protected void onCreate(Bundle arg0) { + super.onCreate(arg0); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + setContentView(R.layout.miroguidesearch); + } + + @Override + protected void onResume() { + super.onResume(); + Intent intent = getIntent(); + if (Intent.ACTION_SEARCH.equals(intent.getAction())) { + String query = intent.getStringExtra(SearchManager.QUERY); + getSupportActionBar() + .setSubtitle( + getString(R.string.search_term_label) + "\"" + + query + "\""); + handleSearchRequest(query); + } + } + + private void handleSearchRequest(String query) { + if (AppConfig.DEBUG) + Log.d(TAG, "Performing search"); + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + listFragment = MiroGuideChannellistFragment.newInstance("name", query, + "name"); + ft.replace(R.id.channellistFragment, listFragment); + ft.commit(); + } + + @Override + protected void onNewIntent(Intent intent) { + setIntent(intent); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label) + .setIcon(R.drawable.action_search) + .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); + + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + case R.id.search_item: + onSearchRequested(); + return true; + default: + return false; + } + } + +} diff --git a/src/de/danoeh/antennapod/activity/MiroSearchActivity.java b/src/de/danoeh/antennapod/activity/MiroSearchActivity.java deleted file mode 100644 index 43177df88..000000000 --- a/src/de/danoeh/antennapod/activity/MiroSearchActivity.java +++ /dev/null @@ -1,82 +0,0 @@ -package de.danoeh.antennapod.activity; - -import android.app.SearchManager; -import android.content.Intent; -import android.os.Bundle; -import android.support.v4.app.FragmentTransaction; -import android.util.Log; - -import com.actionbarsherlock.app.SherlockFragmentActivity; -import com.actionbarsherlock.view.Menu; -import com.actionbarsherlock.view.MenuItem; - -import de.danoeh.antennapod.AppConfig; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.fragment.MiroChannellistFragment; - -/** Displays results when a search for miroguide channels has been performed */ -public class MiroSearchActivity extends SherlockFragmentActivity { - private static final String TAG = "MiroSearchActivity"; - - private MiroChannellistFragment listFragment; - - @Override - protected void onCreate(Bundle arg0) { - super.onCreate(arg0); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - setContentView(R.layout.mirosearch); - } - - @Override - protected void onResume() { - super.onResume(); - Intent intent = getIntent(); - if (Intent.ACTION_SEARCH.equals(intent.getAction())) { - String query = intent.getStringExtra(SearchManager.QUERY); - getSupportActionBar() - .setSubtitle( - getString(R.string.search_term_label) + "\"" - + query + "\""); - handleSearchRequest(query); - } - } - - private void handleSearchRequest(String query) { - if (AppConfig.DEBUG) - Log.d(TAG, "Performing search"); - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); - listFragment = MiroChannellistFragment.newInstance("name", query, - "name"); - ft.replace(R.id.channellistFragment, listFragment); - ft.commit(); - } - - @Override - protected void onNewIntent(Intent intent) { - setIntent(intent); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label) - .setIcon(R.drawable.action_search) - .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); - - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - finish(); - return true; - case R.id.search_item: - onSearchRequested(); - return true; - default: - return false; - } - } - -} diff --git a/src/de/danoeh/antennapod/adapter/MiroChannellistAdapter.java b/src/de/danoeh/antennapod/adapter/MiroChannellistAdapter.java deleted file mode 100644 index b07e2445d..000000000 --- a/src/de/danoeh/antennapod/adapter/MiroChannellistAdapter.java +++ /dev/null @@ -1,57 +0,0 @@ -package de.danoeh.antennapod.adapter; - -import java.util.List; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.TextView; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.miroguide.model.MiroChannel; - -public class MiroChannellistAdapter extends ArrayAdapter { - - public MiroChannellistAdapter(Context context, int textViewResourceId, - List objects) { - super(context, textViewResourceId, objects); - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - Holder holder; - MiroChannel channel = getItem(position); - - // Inflate Layout - if (convertView == null) { - holder = new Holder(); - LayoutInflater inflater = (LayoutInflater) getContext() - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - - convertView = inflater.inflate(R.layout.miro_channellist_item, null); - holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); - holder.cover = (ImageView) convertView - .findViewById(R.id.imgvChannelimage); - - - convertView.setTag(holder); - } else { - holder = (Holder) convertView.getTag(); - } - - holder.cover.setVisibility(View.GONE); - holder.title.setText(channel.getName()); - - return convertView; - } - - static class Holder { - ImageView cover; - TextView title; - } - - - -} diff --git a/src/de/danoeh/antennapod/adapter/MiroGuideChannelListAdapter.java b/src/de/danoeh/antennapod/adapter/MiroGuideChannelListAdapter.java new file mode 100644 index 000000000..1249b7905 --- /dev/null +++ b/src/de/danoeh/antennapod/adapter/MiroGuideChannelListAdapter.java @@ -0,0 +1,57 @@ +package de.danoeh.antennapod.adapter; + +import java.util.List; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.miroguide.model.MiroChannel; + +public class MiroGuideChannelListAdapter extends ArrayAdapter { + + public MiroGuideChannelListAdapter(Context context, int textViewResourceId, + List objects) { + super(context, textViewResourceId, objects); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Holder holder; + MiroChannel channel = getItem(position); + + // Inflate Layout + if (convertView == null) { + holder = new Holder(); + LayoutInflater inflater = (LayoutInflater) getContext() + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + convertView = inflater.inflate(R.layout.miroguide_channellist_item, null); + holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); + holder.cover = (ImageView) convertView + .findViewById(R.id.imgvChannelimage); + + + convertView.setTag(holder); + } else { + holder = (Holder) convertView.getTag(); + } + + holder.cover.setVisibility(View.GONE); + holder.title.setText(channel.getName()); + + return convertView; + } + + static class Holder { + ImageView cover; + TextView title; + } + + + +} diff --git a/src/de/danoeh/antennapod/fragment/MiroChannellistFragment.java b/src/de/danoeh/antennapod/fragment/MiroChannellistFragment.java deleted file mode 100644 index 6a4cf7a86..000000000 --- a/src/de/danoeh/antennapod/fragment/MiroChannellistFragment.java +++ /dev/null @@ -1,247 +0,0 @@ -package de.danoeh.antennapod.fragment; - -import java.util.ArrayList; -import java.util.List; - -import android.annotation.SuppressLint; -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.os.AsyncTask; -import android.os.Bundle; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.AbsListView; -import android.widget.AbsListView.OnScrollListener; - -import com.actionbarsherlock.app.SherlockListFragment; - -import de.danoeh.antennapod.AppConfig; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.adapter.MiroChannellistAdapter; -import de.danoeh.antennapod.miroguide.con.MiroException; -import de.danoeh.antennapod.miroguide.con.MiroService; -import de.danoeh.antennapod.miroguide.model.MiroChannel; - -/** - * Displays a list of MiroChannel objects that were results of a certain - * MiroService query. If the user reaches the bottom of the list, more entries - * will be loaded until all entries have been loaded or the maximum number of - * channels has been reached. - * */ -public class MiroChannellistFragment extends SherlockListFragment { - private static final String TAG = "MiroChannellistFragment"; - - private static final String ARG_FILTER = "filter"; - private static final String ARG_FILTER_VALUE = "filter_value"; - private static final String ARG_SORT = "sort"; - - private static final int MAX_CHANNELS = 200; - private static final int CHANNELS_PER_QUERY = MiroService.DEFAULT_CHANNEL_LIMIT; - - private ArrayList channels; - private MiroChannellistAdapter listAdapter; - private int offset; - - private boolean isLoadingChannels; - /** - * True if there are no more entries to load or if the maximum number of - * channels in the channellist has been reached - */ - private boolean stopLoading; - - private View footer; - - private String filter; - private String filterValue; - private String sort; - - private AsyncTask> channelLoader; - - /** - * Creates a new instance of Channellist fragment. - * - * @throws IllegalArgumentException - * if filter, filterValue or sort is null - * */ - public static MiroChannellistFragment newInstance(String filter, - String filterValue, String sort) { - if (filter == null) { - throw new IllegalArgumentException("filter cannot be null"); - } - if (filterValue == null) { - throw new IllegalArgumentException("filter value cannot be null"); - } - if (sort == null) { - throw new IllegalArgumentException("sort cannot be null"); - } - MiroChannellistFragment cf = new MiroChannellistFragment(); - Bundle args = new Bundle(); - args.putString(ARG_FILTER, filter); - args.putString(ARG_FILTER_VALUE, filterValue); - args.putString(ARG_SORT, sort); - cf.setArguments(args); - return cf; - } - - private MiroChannellistFragment() { - super(); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - offset = 0; - channels = new ArrayList(); - - Bundle args = getArguments(); - filter = args.getString(ARG_FILTER); - filterValue = args.getString(ARG_FILTER_VALUE); - sort = args.getString(ARG_SORT); - - LayoutInflater inflater = (LayoutInflater) getActivity() - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - footer = inflater.inflate(R.layout.loading_footer, null); - listAdapter = new MiroChannellistAdapter(getActivity(), 0, channels); - } - - @Override - public void onResume() { - super.onResume(); - if (channels.isEmpty()) { - setListShown(false); - loadChannels(); - } - } - - @Override - public void onPause() { - super.onPause(); - if (channelLoader != null) { - channelLoader.cancel(true); - } - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - getListView().addFooterView(footer); // footer has to be added before the adapter has been set - getListView().setAdapter(listAdapter); - getListView().removeFooterView(footer); - - getListView().setOnScrollListener(new OnScrollListener() { - - @Override - public void onScroll(AbsListView view, int firstVisibleItem, - int visibleItemCount, int totalItemCount) { - int lastVisibleItem = firstVisibleItem + visibleItemCount; - if (lastVisibleItem == totalItemCount) { - if (AppConfig.DEBUG) - loadChannels(); - } - } - - @Override - public void onScrollStateChanged(AbsListView view, int scrollState) { - } - }); - } - - @SuppressLint("NewApi") - private void loadChannels() { - if (!isLoadingChannels) { - if (!stopLoading) { - isLoadingChannels = true; - channelLoader = new AsyncTask>() { - private MiroException exception; - - @Override - protected void onCancelled() { - if (AppConfig.DEBUG) - Log.d(TAG, "Channel loader was cancelled"); - } - - @Override - protected void onPostExecute(List result) { - if (AppConfig.DEBUG) - Log.d(TAG, "Channel loading finished"); - if (exception == null) { - getListView().removeFooterView(footer); - for (MiroChannel channel : result) { - channels.add(channel); - } - listAdapter.notifyDataSetChanged(); - offset += CHANNELS_PER_QUERY; - // check if fragment should not send any more - // queries - if (result.size() < CHANNELS_PER_QUERY) { - if (AppConfig.DEBUG) - Log.d(TAG, - "Query result was less than requested number of channels. Stopping to send any more queries"); - stopLoading = true; - } - if (offset >= MAX_CHANNELS) { - if (AppConfig.DEBUG) - Log.d(TAG, - "Maximum number of feeds has been reached. Stopping to send any more queries"); - stopLoading = true; - } - - setListShown(true); - } else { - AlertDialog.Builder dialog = new AlertDialog.Builder( - getActivity()); - dialog.setTitle(R.string.error_label); - dialog.setMessage(exception.getMessage()); - dialog.setNeutralButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - - @Override - public void onClick( - DialogInterface dialog, - int which) { - dialog.dismiss(); - } - }); - dialog.create().show(); - } - isLoadingChannels = false; - } - - @Override - protected void onPreExecute() { - getListView().addFooterView(footer); - } - - @Override - protected List doInBackground(Void... params) { - if (AppConfig.DEBUG) - Log.d(TAG, "Background channel loader started"); - MiroService service = new MiroService(); - try { - return service.getChannelList(filter, filterValue, - sort, CHANNELS_PER_QUERY, offset); - } catch (MiroException e) { - exception = e; - e.printStackTrace(); - } - return null; - } - }; - - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - channelLoader - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - channelLoader.execute(); - } - } - } else { - if (AppConfig.DEBUG) - Log.d(TAG, "Channels are already being loaded"); - } - } -} diff --git a/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java b/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java new file mode 100644 index 000000000..6817ab4d8 --- /dev/null +++ b/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java @@ -0,0 +1,247 @@ +package de.danoeh.antennapod.fragment; + +import java.util.ArrayList; +import java.util.List; + +import android.annotation.SuppressLint; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.AsyncTask; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.AbsListView; +import android.widget.AbsListView.OnScrollListener; + +import com.actionbarsherlock.app.SherlockListFragment; + +import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.adapter.MiroGuideChannelListAdapter; +import de.danoeh.antennapod.miroguide.con.MiroGuideException; +import de.danoeh.antennapod.miroguide.con.MiroGuideService; +import de.danoeh.antennapod.miroguide.model.MiroChannel; + +/** + * Displays a list of MiroChannel objects that were results of a certain + * MiroGuideService query. If the user reaches the bottom of the list, more entries + * will be loaded until all entries have been loaded or the maximum number of + * channels has been reached. + * */ +public class MiroGuideChannellistFragment extends SherlockListFragment { + private static final String TAG = "MiroGuideChannellistFragment"; + + private static final String ARG_FILTER = "filter"; + private static final String ARG_FILTER_VALUE = "filter_value"; + private static final String ARG_SORT = "sort"; + + private static final int MAX_CHANNELS = 200; + private static final int CHANNELS_PER_QUERY = MiroGuideService.DEFAULT_CHANNEL_LIMIT; + + private ArrayList channels; + private MiroGuideChannelListAdapter listAdapter; + private int offset; + + private boolean isLoadingChannels; + /** + * True if there are no more entries to load or if the maximum number of + * channels in the channellist has been reached + */ + private boolean stopLoading; + + private View footer; + + private String filter; + private String filterValue; + private String sort; + + private AsyncTask> channelLoader; + + /** + * Creates a new instance of Channellist fragment. + * + * @throws IllegalArgumentException + * if filter, filterValue or sort is null + * */ + public static MiroGuideChannellistFragment newInstance(String filter, + String filterValue, String sort) { + if (filter == null) { + throw new IllegalArgumentException("filter cannot be null"); + } + if (filterValue == null) { + throw new IllegalArgumentException("filter value cannot be null"); + } + if (sort == null) { + throw new IllegalArgumentException("sort cannot be null"); + } + MiroGuideChannellistFragment cf = new MiroGuideChannellistFragment(); + Bundle args = new Bundle(); + args.putString(ARG_FILTER, filter); + args.putString(ARG_FILTER_VALUE, filterValue); + args.putString(ARG_SORT, sort); + cf.setArguments(args); + return cf; + } + + private MiroGuideChannellistFragment() { + super(); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + offset = 0; + channels = new ArrayList(); + + Bundle args = getArguments(); + filter = args.getString(ARG_FILTER); + filterValue = args.getString(ARG_FILTER_VALUE); + sort = args.getString(ARG_SORT); + + LayoutInflater inflater = (LayoutInflater) getActivity() + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + footer = inflater.inflate(R.layout.loading_footer, null); + listAdapter = new MiroGuideChannelListAdapter(getActivity(), 0, channels); + } + + @Override + public void onResume() { + super.onResume(); + if (channels.isEmpty()) { + setListShown(false); + loadChannels(); + } + } + + @Override + public void onPause() { + super.onPause(); + if (channelLoader != null) { + channelLoader.cancel(true); + } + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + getListView().addFooterView(footer); // footer has to be added before the adapter has been set + getListView().setAdapter(listAdapter); + getListView().removeFooterView(footer); + + getListView().setOnScrollListener(new OnScrollListener() { + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, + int visibleItemCount, int totalItemCount) { + int lastVisibleItem = firstVisibleItem + visibleItemCount; + if (lastVisibleItem == totalItemCount) { + if (AppConfig.DEBUG) + loadChannels(); + } + } + + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) { + } + }); + } + + @SuppressLint("NewApi") + private void loadChannels() { + if (!isLoadingChannels) { + if (!stopLoading) { + isLoadingChannels = true; + channelLoader = new AsyncTask>() { + private MiroGuideException exception; + + @Override + protected void onCancelled() { + if (AppConfig.DEBUG) + Log.d(TAG, "Channel loader was cancelled"); + } + + @Override + protected void onPostExecute(List result) { + if (AppConfig.DEBUG) + Log.d(TAG, "Channel loading finished"); + if (exception == null) { + getListView().removeFooterView(footer); + for (MiroChannel channel : result) { + channels.add(channel); + } + listAdapter.notifyDataSetChanged(); + offset += CHANNELS_PER_QUERY; + // check if fragment should not send any more + // queries + if (result.size() < CHANNELS_PER_QUERY) { + if (AppConfig.DEBUG) + Log.d(TAG, + "Query result was less than requested number of channels. Stopping to send any more queries"); + stopLoading = true; + } + if (offset >= MAX_CHANNELS) { + if (AppConfig.DEBUG) + Log.d(TAG, + "Maximum number of feeds has been reached. Stopping to send any more queries"); + stopLoading = true; + } + + setListShown(true); + } else { + AlertDialog.Builder dialog = new AlertDialog.Builder( + getActivity()); + dialog.setTitle(R.string.error_label); + dialog.setMessage(exception.getMessage()); + dialog.setNeutralButton(android.R.string.ok, + new DialogInterface.OnClickListener() { + + @Override + public void onClick( + DialogInterface dialog, + int which) { + dialog.dismiss(); + } + }); + dialog.create().show(); + } + isLoadingChannels = false; + } + + @Override + protected void onPreExecute() { + getListView().addFooterView(footer); + } + + @Override + protected List doInBackground(Void... params) { + if (AppConfig.DEBUG) + Log.d(TAG, "Background channel loader started"); + MiroGuideService service = new MiroGuideService(); + try { + return service.getChannelList(filter, filterValue, + sort, CHANNELS_PER_QUERY, offset); + } catch (MiroGuideException e) { + exception = e; + e.printStackTrace(); + } + return null; + } + }; + + if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { + channelLoader + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + channelLoader.execute(); + } + } + } else { + if (AppConfig.DEBUG) + Log.d(TAG, "Channels are already being loaded"); + } + } +} diff --git a/src/de/danoeh/antennapod/miroguide/con/MiroConnector.java b/src/de/danoeh/antennapod/miroguide/con/MiroConnector.java deleted file mode 100644 index d6bcb93c9..000000000 --- a/src/de/danoeh/antennapod/miroguide/con/MiroConnector.java +++ /dev/null @@ -1,127 +0,0 @@ -package de.danoeh.antennapod.miroguide.con; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.DefaultHttpClient; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import android.net.Uri; - -/** Executes HTTP requests and returns the results. */ -public class MiroConnector { - private HttpClient httpClient; - - private static final String HOST_URL = "https://www.miroguide.com/api/"; - private static final String PATH_GET_CHANNELS = "get_channels"; - private static final String PATH_LIST_CATEGORIES = "list_categories"; - private static final String PATH_GET_CHANNEL = "get_channel"; - - public MiroConnector() { - httpClient = new DefaultHttpClient(); - } - - public void shutdown() { - httpClient.getConnectionManager().shutdown(); - } - - private Uri.Builder getBaseURIBuilder(String path) { - Uri.Builder builder = Uri.parse(HOST_URL).buildUpon(); - builder.appendPath(path).appendQueryParameter("datatype", "json"); - return builder; - } - - public JSONArray getArrayResponse(Uri uri) throws MiroException { - try { - JSONArray result = new JSONArray(executeRequest(uri)); - return result; - } catch (JSONException e) { - e.printStackTrace(); - throw new MiroException(); - } - } - - public JSONObject getSingleObjectResponse(Uri uri) throws MiroException { - try { - JSONObject result = new JSONObject(executeRequest(uri)); - return result; - } catch (JSONException e) { - e.printStackTrace(); - throw new MiroException(); - } - } - - /** - * Executes a HTTP GET request with the given URI and returns the content of - * the return value. - * - * @throws MiroException - */ - private String executeRequest(Uri uri) throws MiroException { - HttpGet httpGet = new HttpGet(uri.toString()); - String result = null; - try { - HttpResponse response = httpClient.execute(httpGet); - if (response.getStatusLine().getStatusCode() == 200) { - HttpEntity entity = response.getEntity(); - if (entity != null) { - InputStream in = entity.getContent(); - - BufferedReader reader = new BufferedReader( - new InputStreamReader(in)); - result = reader.readLine(); - } - } else { - throw new MiroException(response.getStatusLine() - .getReasonPhrase()); - } - } catch (IOException e) { - e.printStackTrace(); - throw new MiroException(e.getMessage()); - } - return result; - - } - - public Uri createGetChannelsUri(String filter, String filterValue, - String sort, String limit, String offset) throws MiroException { - Uri.Builder resultBuilder = getBaseURIBuilder(PATH_GET_CHANNELS); - resultBuilder.appendQueryParameter("filter", filter) - .appendQueryParameter("filter_value", filterValue); - - if (sort != null) { - resultBuilder.appendQueryParameter("sort", sort); - } - if (limit != null) { - resultBuilder.appendQueryParameter("limit", limit); - } - if (offset != null) { - resultBuilder.appendQueryParameter("offset", offset); - } - Uri result = resultBuilder.build(); - return result; - } - - public Uri createListCategoriesURI() throws MiroException { - Uri.Builder resultBuilder = getBaseURIBuilder(PATH_LIST_CATEGORIES); - Uri result = resultBuilder.build(); - - return result; - } - - public Uri createGetChannelUri(String id) throws MiroException { - Uri.Builder resultBuilder = getBaseURIBuilder(PATH_GET_CHANNEL) - .appendQueryParameter("id", id); - Uri result = resultBuilder.build(); - return result; - } - -} diff --git a/src/de/danoeh/antennapod/miroguide/con/MiroException.java b/src/de/danoeh/antennapod/miroguide/con/MiroException.java deleted file mode 100644 index 7b4ee1651..000000000 --- a/src/de/danoeh/antennapod/miroguide/con/MiroException.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.danoeh.antennapod.miroguide.con; - -public class MiroException extends Exception { - private static final long serialVersionUID = -8834656185748713194L; - - public MiroException() { - super(); - } - - public MiroException(String arg0, Throwable arg1) { - super(arg0, arg1); - } - - public MiroException(String arg0) { - super(arg0); - } - - public MiroException(Throwable arg0) { - super(arg0); - } - - -} diff --git a/src/de/danoeh/antennapod/miroguide/con/MiroGuideConnector.java b/src/de/danoeh/antennapod/miroguide/con/MiroGuideConnector.java new file mode 100644 index 000000000..cccfff4d5 --- /dev/null +++ b/src/de/danoeh/antennapod/miroguide/con/MiroGuideConnector.java @@ -0,0 +1,127 @@ +package de.danoeh.antennapod.miroguide.con; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import android.net.Uri; + +/** Executes HTTP requests and returns the results. */ +public class MiroGuideConnector { + private HttpClient httpClient; + + private static final String HOST_URL = "https://www.miroguide.com/api/"; + private static final String PATH_GET_CHANNELS = "get_channels"; + private static final String PATH_LIST_CATEGORIES = "list_categories"; + private static final String PATH_GET_CHANNEL = "get_channel"; + + public MiroGuideConnector() { + httpClient = new DefaultHttpClient(); + } + + public void shutdown() { + httpClient.getConnectionManager().shutdown(); + } + + private Uri.Builder getBaseURIBuilder(String path) { + Uri.Builder builder = Uri.parse(HOST_URL).buildUpon(); + builder.appendPath(path).appendQueryParameter("datatype", "json"); + return builder; + } + + public JSONArray getArrayResponse(Uri uri) throws MiroGuideException { + try { + JSONArray result = new JSONArray(executeRequest(uri)); + return result; + } catch (JSONException e) { + e.printStackTrace(); + throw new MiroGuideException(); + } + } + + public JSONObject getSingleObjectResponse(Uri uri) throws MiroGuideException { + try { + JSONObject result = new JSONObject(executeRequest(uri)); + return result; + } catch (JSONException e) { + e.printStackTrace(); + throw new MiroGuideException(); + } + } + + /** + * Executes a HTTP GET request with the given URI and returns the content of + * the return value. + * + * @throws MiroGuideException + */ + private String executeRequest(Uri uri) throws MiroGuideException { + HttpGet httpGet = new HttpGet(uri.toString()); + String result = null; + try { + HttpResponse response = httpClient.execute(httpGet); + if (response.getStatusLine().getStatusCode() == 200) { + HttpEntity entity = response.getEntity(); + if (entity != null) { + InputStream in = entity.getContent(); + + BufferedReader reader = new BufferedReader( + new InputStreamReader(in)); + result = reader.readLine(); + } + } else { + throw new MiroGuideException(response.getStatusLine() + .getReasonPhrase()); + } + } catch (IOException e) { + e.printStackTrace(); + throw new MiroGuideException(e.getMessage()); + } + return result; + + } + + public Uri createGetChannelsUri(String filter, String filterValue, + String sort, String limit, String offset) throws MiroGuideException { + Uri.Builder resultBuilder = getBaseURIBuilder(PATH_GET_CHANNELS); + resultBuilder.appendQueryParameter("filter", filter) + .appendQueryParameter("filter_value", filterValue); + + if (sort != null) { + resultBuilder.appendQueryParameter("sort", sort); + } + if (limit != null) { + resultBuilder.appendQueryParameter("limit", limit); + } + if (offset != null) { + resultBuilder.appendQueryParameter("offset", offset); + } + Uri result = resultBuilder.build(); + return result; + } + + public Uri createListCategoriesURI() throws MiroGuideException { + Uri.Builder resultBuilder = getBaseURIBuilder(PATH_LIST_CATEGORIES); + Uri result = resultBuilder.build(); + + return result; + } + + public Uri createGetChannelUri(String id) throws MiroGuideException { + Uri.Builder resultBuilder = getBaseURIBuilder(PATH_GET_CHANNEL) + .appendQueryParameter("id", id); + Uri result = resultBuilder.build(); + return result; + } + +} diff --git a/src/de/danoeh/antennapod/miroguide/con/MiroGuideException.java b/src/de/danoeh/antennapod/miroguide/con/MiroGuideException.java new file mode 100644 index 000000000..074fc3d3c --- /dev/null +++ b/src/de/danoeh/antennapod/miroguide/con/MiroGuideException.java @@ -0,0 +1,23 @@ +package de.danoeh.antennapod.miroguide.con; + +public class MiroGuideException extends Exception { + private static final long serialVersionUID = -8834656185748713194L; + + public MiroGuideException() { + super(); + } + + public MiroGuideException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + + public MiroGuideException(String arg0) { + super(arg0); + } + + public MiroGuideException(Throwable arg0) { + super(arg0); + } + + +} diff --git a/src/de/danoeh/antennapod/miroguide/con/MiroGuideService.java b/src/de/danoeh/antennapod/miroguide/con/MiroGuideService.java new file mode 100644 index 000000000..a3ecf6e06 --- /dev/null +++ b/src/de/danoeh/antennapod/miroguide/con/MiroGuideService.java @@ -0,0 +1,148 @@ +package de.danoeh.antennapod.miroguide.con; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import de.danoeh.antennapod.miroguide.model.MiroChannel; +import de.danoeh.antennapod.miroguide.model.MiroItem; + + +/** Provides methods to communicate with the Miroguide API on an abstract level. */ +public class MiroGuideService { + public static final int DEFAULT_CHANNEL_LIMIT = 20; + + public static final String FILTER_CATEGORY = "category"; + public static final String FILTER_NAME = "name"; + public static final String SORT_NAME = "name"; + public static final String SORT_POPULAR = "popular"; + public static final String SORT_RATING = "rating"; + + public static final String JSON_DATE_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss"; + + private MiroGuideConnector connector; + + private static ThreadLocal jSONDateFormat = new ThreadLocal() { + @Override + protected SimpleDateFormat initialValue() { + return new SimpleDateFormat(JSON_DATE_FORMAT_STRING, Locale.US); + } + + }; + + public MiroGuideService() { + connector = new MiroGuideConnector(); + } + + public String[] getCategories() throws MiroGuideException { + JSONArray resultArray = connector.getArrayResponse(connector + .createListCategoriesURI()); + String[] result = new String[resultArray.length()]; + for (int i = 0; i < resultArray.length(); i++) { + try { + result[i] = resultArray.getJSONObject(i).getString("name"); + } catch (JSONException e) { + e.printStackTrace(); + throw new MiroGuideException(); + } + } + return result; + } + + /** Get a list of MiroChannel objects without their items. */ + public List getChannelList(String filter, String filterValue, + String sort, int limit, int offset) throws MiroGuideException { + JSONArray resultArray = connector.getArrayResponse(connector + .createGetChannelsUri(filter, filterValue, sort, + Integer.toString(limit), Integer.toString(offset))); + int resultLen = resultArray.length(); + List channels = new ArrayList(resultLen); + for (int i = 0; i < resultLen; i++) { + JSONObject content = null; + try { + content = resultArray.getJSONObject(i); + MiroChannel channel = extractMiroChannel(content, false); + channels.add(channel); + } catch (JSONException e) { + e.printStackTrace(); + throw new MiroGuideException(); + } + } + + return channels; + } + + /** + * Get a single channel with its items. + * + * @throws MiroGuideException + */ + public MiroChannel getChannel(long id) throws MiroGuideException { + JSONObject resultObject = connector.getSingleObjectResponse(connector + .createGetChannelUri(Long.toString(id))); + MiroChannel result = null; + try { + result = extractMiroChannel(resultObject, true); + } catch (JSONException e) { + e.printStackTrace(); + throw new MiroGuideException(); + } + return result; + } + + /** + * Get a MiroChannel object from it's JSON source. The itemlist of the + * channel can be included or excluded + * + * @throws JSONException + */ + private MiroChannel extractMiroChannel(JSONObject content, boolean withItems) + throws JSONException { + long id = content.getLong("id"); + String name = content.getString("name"); + String description = content.getString("description"); + String thumbnailUrl = content.optString("thumbnail_url"); + String downloadUrl = content.getString("url"); + String websiteUrl = content.getString("website_url"); + if (!withItems) { + return new MiroChannel(id, name, thumbnailUrl, downloadUrl, + websiteUrl, description); + } else { + JSONArray itemData = content.getJSONArray("item"); + int numItems = itemData.length(); + ArrayList items = new ArrayList(numItems); + for (int i = 0; i < numItems; i++) { + items.add(extractMiroItem(itemData.getJSONObject(i))); + } + + return new MiroChannel(id, name, thumbnailUrl, downloadUrl, + websiteUrl, description, items); + } + } + + /** Get a MiroItem from its JSON source. */ + private MiroItem extractMiroItem(JSONObject content) throws JSONException { + Date date = parseMiroItemDate(content.getString("date")); + String description = content.getString("description"); + String name = content.getString("name"); + String url = content.getString("url"); + return new MiroItem(name, description, date, url); + } + + private Date parseMiroItemDate(String s) { + try { + return jSONDateFormat.get().parse(s); + } catch (ParseException e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/src/de/danoeh/antennapod/miroguide/con/MiroService.java b/src/de/danoeh/antennapod/miroguide/con/MiroService.java deleted file mode 100644 index 3c077e071..000000000 --- a/src/de/danoeh/antennapod/miroguide/con/MiroService.java +++ /dev/null @@ -1,148 +0,0 @@ -package de.danoeh.antennapod.miroguide.con; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import de.danoeh.antennapod.miroguide.model.MiroChannel; -import de.danoeh.antennapod.miroguide.model.MiroItem; - - -/** Provides methods to communicate with the Miroguide API on an abstract level. */ -public class MiroService { - public static final int DEFAULT_CHANNEL_LIMIT = 20; - - public static final String FILTER_CATEGORY = "category"; - public static final String FILTER_NAME = "name"; - public static final String SORT_NAME = "name"; - public static final String SORT_POPULAR = "popular"; - public static final String SORT_RATING = "rating"; - - public static final String JSON_DATE_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss"; - - private MiroConnector connector; - - private static ThreadLocal jSONDateFormat = new ThreadLocal() { - @Override - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat(JSON_DATE_FORMAT_STRING, Locale.US); - } - - }; - - public MiroService() { - connector = new MiroConnector(); - } - - public String[] getCategories() throws MiroException { - JSONArray resultArray = connector.getArrayResponse(connector - .createListCategoriesURI()); - String[] result = new String[resultArray.length()]; - for (int i = 0; i < resultArray.length(); i++) { - try { - result[i] = resultArray.getJSONObject(i).getString("name"); - } catch (JSONException e) { - e.printStackTrace(); - throw new MiroException(); - } - } - return result; - } - - /** Get a list of MiroChannel objects without their items. */ - public List getChannelList(String filter, String filterValue, - String sort, int limit, int offset) throws MiroException { - JSONArray resultArray = connector.getArrayResponse(connector - .createGetChannelsUri(filter, filterValue, sort, - Integer.toString(limit), Integer.toString(offset))); - int resultLen = resultArray.length(); - List channels = new ArrayList(resultLen); - for (int i = 0; i < resultLen; i++) { - JSONObject content = null; - try { - content = resultArray.getJSONObject(i); - MiroChannel channel = extractMiroChannel(content, false); - channels.add(channel); - } catch (JSONException e) { - e.printStackTrace(); - throw new MiroException(); - } - } - - return channels; - } - - /** - * Get a single channel with its items. - * - * @throws MiroException - */ - public MiroChannel getChannel(long id) throws MiroException { - JSONObject resultObject = connector.getSingleObjectResponse(connector - .createGetChannelUri(Long.toString(id))); - MiroChannel result = null; - try { - result = extractMiroChannel(resultObject, true); - } catch (JSONException e) { - e.printStackTrace(); - throw new MiroException(); - } - return result; - } - - /** - * Get a MiroChannel object from it's JSON source. The itemlist of the - * channel can be included or excluded - * - * @throws JSONException - */ - private MiroChannel extractMiroChannel(JSONObject content, boolean withItems) - throws JSONException { - long id = content.getLong("id"); - String name = content.getString("name"); - String description = content.getString("description"); - String thumbnailUrl = content.optString("thumbnail_url"); - String downloadUrl = content.getString("url"); - String websiteUrl = content.getString("website_url"); - if (!withItems) { - return new MiroChannel(id, name, thumbnailUrl, downloadUrl, - websiteUrl, description); - } else { - JSONArray itemData = content.getJSONArray("item"); - int numItems = itemData.length(); - ArrayList items = new ArrayList(numItems); - for (int i = 0; i < numItems; i++) { - items.add(extractMiroItem(itemData.getJSONObject(i))); - } - - return new MiroChannel(id, name, thumbnailUrl, downloadUrl, - websiteUrl, description, items); - } - } - - /** Get a MiroItem from its JSON source. */ - private MiroItem extractMiroItem(JSONObject content) throws JSONException { - Date date = parseMiroItemDate(content.getString("date")); - String description = content.getString("description"); - String name = content.getString("name"); - String url = content.getString("url"); - return new MiroItem(name, description, date, url); - } - - private Date parseMiroItemDate(String s) { - try { - return jSONDateFormat.get().parse(s); - } catch (ParseException e) { - e.printStackTrace(); - } - return null; - } - -} -- cgit v1.2.3