Added fragment for adding new podcasts

This commit is contained in:
daniel oeh 2014-04-17 20:33:02 +02:00
parent 628103de45
commit 8b6f16b918
12 changed files with 336 additions and 41 deletions

View File

@ -52,16 +52,6 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="de.danoeh.antennapod.activity.AddFeedActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/add_new_feed_label"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="de.danoeh.antennapod.activity.MainActivity"/>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
@ -109,6 +99,18 @@
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<activity
android:name="de.danoeh.antennapod.activity.AddFeedActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/add_new_feed_label"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="de.danoeh.antennapod.activity.MainActivity"/>
</activity>
<activity
android:name="de.danoeh.antennapod.activity.FeedItemlistActivity"

View File

@ -53,28 +53,29 @@
android:textStyle="italic"
android:text="@string/podcastdirectories_label"/>
<TextView
android:id="@+id/txtvPodcastDirectoriesDescr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/podcastdirectories_descr"
android:textSize="@dimen/text_size_medium"
android:layout_below="@id/txtvPodcastDirectories"
android:layout_margin="8dp"/>
<Button
android:id="@+id/butBrowseGpoddernet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtvPodcastDirectories"
android:layout_below="@id/txtvPodcastDirectoriesDescr"
android:layout_margin="8dp"
android:text="@string/gpodnet_main_label"/>
<Button
android:id="@+id/butBrowseMiroguide"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/butBrowseGpoddernet"
android:layout_margin="8dp"
android:text="@string/miro_guide_label"/>
android:text="@string/browse_gpoddernet_label"/>
<TextView
android:id="@+id/txtvOpmlImport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/butBrowseMiroguide"
android:layout_below="@id/butBrowseGpoddernet"
android:layout_margin="8dp"
android:textSize="@dimen/text_size_large"
android:textColor="@color/bright_blue"
@ -87,6 +88,7 @@
android:layout_height="wrap_content"
android:layout_below="@id/txtvOpmlImport"
android:layout_margin="8dp"
android:textSize="@dimen/text_size_medium"
android:text="@string/opml_import_txtv_button_lable"/>
<Button

View File

@ -70,7 +70,9 @@
<!-- 'Add Feed' Activity labels -->
<string name="feedurl_label">Feed URL</string>
<string name="txtvfeedurl_label">Add Podcast by URL</string>
<string name="podcastdirectories_label">Podcast directories</string>
<string name="podcastdirectories_label">Find podcast in directory</string>
<string name="podcastdirectories_descr">You can search for new podcasts by name, category or popularity in the gpodder.net directory.</string>
<string name="browse_gpoddernet_label">Browse gpodder.net</string>
<!-- Actions on feeds -->
<string name="mark_all_read_label">Mark all as read</string>

View File

@ -50,7 +50,6 @@ public class AddFeedActivity extends ActionBarActivity {
etxtFeedurl.setText(getIntent().getDataString());
}
butBrowseMiroGuide = (Button) findViewById(R.id.butBrowseMiroguide);
butBrowserGpoddernet = (Button) findViewById(R.id.butBrowseGpoddernet);
butOpmlImport = (Button) findViewById(R.id.butOpmlImport);
butConfirm = (Button) findViewById(R.id.butConfirm);

View File

@ -31,7 +31,7 @@ import de.danoeh.antennapod.fragment.*;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.storage.DBReader;
import de.danoeh.antennapod.util.StorageUtils;
import de.danoeh.antennapod.util.ThemeUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
@ -96,7 +96,6 @@ public class MainActivity extends ActionBarActivity {
transaction.replace(R.id.playerFragment, externalPlayerFragment);
transaction.commit();
Fragment mainFragment = fm.findFragmentByTag("main");
@ -105,7 +104,7 @@ public class MainActivity extends ActionBarActivity {
transaction.replace(R.id.main_view, mainFragment);
transaction.commit();
} else {
loadFragment(NavListAdapter.VIEW_TYPE_NAV, 0);
loadFragment(NavListAdapter.VIEW_TYPE_NAV, NavListAdapter.POS_NEW, null);
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -123,24 +122,33 @@ public class MainActivity extends ActionBarActivity {
return getSupportActionBar();
}
private void loadFragment(int viewType, int relPos) {
private void loadFragment(int viewType, int relPos, Bundle args) {
FragmentManager fragmentManager = getSupportFragmentManager();
// clear back stack
for (int i = 0; i < fragmentManager.getBackStackEntryCount(); i++) {
fragmentManager.popBackStack();
}
FragmentTransaction fT = fragmentManager.beginTransaction();
Fragment fragment = null;
if (viewType == NavListAdapter.VIEW_TYPE_NAV) {
switch (relPos) {
case 0:
case NavListAdapter.POS_NEW:
fragment = new NewEpisodesFragment();
break;
case 1:
case NavListAdapter.POS_QUEUE:
fragment = new QueueFragment();
break;
case 2:
case NavListAdapter.POS_DOWNLOADS:
fragment = new DownloadsFragment();
break;
case 3:
case NavListAdapter.POS_HISTORY:
fragment = new PlaybackHistoryFragment();
break;
case NavListAdapter.POS_ADD:
fragment = new AddFeedFragment();
break;
}
currentTitle = getString(NavListAdapter.NAV_TITLES[relPos]);
@ -151,18 +159,30 @@ public class MainActivity extends ActionBarActivity {
}
if (fragment != null) {
fT.replace(R.id.main_view, fragment, "main");
if (args != null) {
fragment.setArguments(args);
}
fT.replace(R.id.main_view, fragment, "main");fragmentManager.popBackStack();
}
fT.commit();
}
public void loadChildFragment(Fragment fragment) {
if (fragment == null) throw new IllegalArgumentException("fragment = null");
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction()
.replace(R.id.main_view, fragment, "main")
.addToBackStack(null)
.commit();
}
private AdapterView.OnItemClickListener navListClickListener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int viewType = parent.getAdapter().getItemViewType(position);
if (viewType != NavListAdapter.VIEW_TYPE_SECTION_DIVIDER && position != selectedNavListIndex) {
int relPos = (viewType == NavListAdapter.VIEW_TYPE_NAV) ? position : position - NavListAdapter.SUBSCRIPTION_OFFSET;
loadFragment(viewType, relPos);
loadFragment(viewType, relPos, null);
selectedNavListIndex = position;
navAdapter.notifyDataSetChanged();
}
@ -207,6 +227,18 @@ public class MainActivity extends ActionBarActivity {
super.onResume();
StorageUtils.checkStorageAvailability(this);
EventDistributor.getInstance().register(contentUpdate);
Intent intent = getIntent();
if (StringUtils.equals(intent.getAction(), Intent.ACTION_SEND)) {
String extra = intent.getStringExtra(Intent.EXTRA_TEXT);
if (extra != null) {
Bundle args = new Bundle();
args.putString(AddFeedFragment.ARG_FEED_URL, extra);
loadFragment(NavListAdapter.VIEW_TYPE_NAV, NavListAdapter.POS_ADD, args);
selectedNavListIndex = NavListAdapter.POS_ADD;
navAdapter.notifyDataSetChanged();
}
}
}
@Override
@ -335,6 +367,12 @@ public class MainActivity extends ActionBarActivity {
static final int VIEW_TYPE_SECTION_DIVIDER = 1;
static final int VIEW_TYPE_SUBSCRIPTION = 2;
static final int POS_NEW = 0,
POS_QUEUE = 1,
POS_DOWNLOADS = 2,
POS_HISTORY = 3,
POS_ADD = 4;
static final int[] NAV_TITLES = {R.string.new_episodes_label, R.string.queue_label, R.string.downloads_label, R.string.playback_history_label, R.string.add_feed_label};

View File

@ -0,0 +1,76 @@
package de.danoeh.antennapod.fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.DefaultOnlineFeedViewActivity;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.OnlineFeedViewActivity;
import de.danoeh.antennapod.activity.OpmlImportFromPathActivity;
import de.danoeh.antennapod.fragment.gpodnet.GpodnetMainFragment;
/**
* Provides actions for adding new podcast subscriptions
*/
public class AddFeedFragment extends Fragment {
private static final String TAG = "AddFeedFragment";
/**
* Preset value for url text field.
*/
public static final String ARG_FEED_URL = "feedurl";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View root = inflater.inflate(R.layout.addfeed, container, false);
final EditText etxtFeedurl = (EditText) root.findViewById(R.id.etxtFeedurl);
Bundle args = getArguments();
if (args != null && args.getString(ARG_FEED_URL) != null) {
etxtFeedurl.setText(args.getString(ARG_FEED_URL));
}
Button butBrowserGpoddernet = (Button) root.findViewById(R.id.butBrowseGpoddernet);
Button butOpmlImport = (Button) root.findViewById(R.id.butOpmlImport);
Button butConfirm = (Button) root.findViewById(R.id.butConfirm);
final MainActivity activity = (MainActivity) getActivity();
activity.getMainActivtyActionBar().setTitle(R.string.add_feed_label);
butBrowserGpoddernet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.loadChildFragment(new GpodnetMainFragment());
}
});
butOpmlImport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(),
OpmlImportFromPathActivity.class));
}
});
butConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), DefaultOnlineFeedViewActivity.class);
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, etxtFeedurl.getText().toString());
intent.putExtra(OnlineFeedViewActivity.ARG_TITLE, getString(R.string.add_feed_label));
startActivity(intent);
}
});
return root;
}
}

View File

@ -27,7 +27,7 @@ public class DownloadsFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View root = inflater.inflate(R.layout.downloads_fragment, container, false);
View root = inflater.inflate(R.layout.pager_fragment, container, false);
pager = (ViewPager) root.findViewById(R.id.pager);
DownloadsPagerAdapter pagerAdapter = new DownloadsPagerAdapter(getChildFragmentManager(), getResources());
pager.setAdapter(pagerAdapter);

View File

@ -0,0 +1,131 @@
package de.danoeh.antennapod.fragment.gpodnet;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
/**
* Main navigation hub for gpodder.net podcast directory
*/
public class GpodnetMainFragment extends Fragment {
private ViewPager pager;
private MainActivity activity;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View root = inflater.inflate(R.layout.pager_fragment, container, false);
pager = (ViewPager) root.findViewById(R.id.pager);
GpodnetPagerAdapter pagerAdapter = new GpodnetPagerAdapter(getChildFragmentManager(), getResources());
pager.setAdapter(pagerAdapter);
final ActionBar actionBar = activity.getMainActivtyActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
pager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
};
actionBar.removeAllTabs();
actionBar.addTab(actionBar.newTab()
.setText(R.string.gpodnet_taglist_header)
.setTabListener(tabListener));
actionBar.addTab(actionBar.newTab()
.setText(R.string.gpodnet_toplist_header)
.setTabListener(tabListener));
actionBar.setTitle(R.string.gpodnet_main_label);
pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
actionBar.setSelectedNavigationItem(position);
}
});
return root;
}
@Override
public void onDestroyView() {
super.onDestroyView();
activity.getMainActivtyActionBar().removeAllTabs();
activity.getMainActivtyActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.activity = (MainActivity) activity;
}
public class GpodnetPagerAdapter extends FragmentPagerAdapter {
private static final int NUM_PAGES = 2;
private static final int POS_TAGS = 0;
private static final int POS_TOPLIST = 1;
private static final int POS_SUGGESTIONS = 2;
Resources resources;
public GpodnetPagerAdapter(FragmentManager fm, Resources resources) {
super(fm);
this.resources = resources;
}
@Override
public Fragment getItem(int i) {
switch (i) {
case POS_TAGS:
return new TagListFragment();
case POS_TOPLIST:
return new PodcastTopListFragment();
case POS_SUGGESTIONS:
return new SuggestionListFragment();
default:
return null;
}
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case POS_TAGS:
return getString(R.string.gpodnet_taglist_header);
case POS_TOPLIST:
return getString(R.string.gpodnet_toplist_header);
case POS_SUGGESTIONS:
return getString(R.string.gpodnet_suggestions_header);
default:
return super.getPageTitle(position);
}
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
}

View File

@ -34,7 +34,6 @@ public abstract class PodcastListFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setRetainInstance(true);
View root = inflater.inflate(R.layout.gpodnet_podcast_list, container, false);
gridView = (GridView) root.findViewById(R.id.gridView);

View File

@ -0,0 +1,47 @@
package de.danoeh.antennapod.fragment.gpodnet;
import android.os.Bundle;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.gpoddernet.GpodnetService;
import de.danoeh.antennapod.gpoddernet.GpodnetServiceException;
import de.danoeh.antennapod.gpoddernet.model.GpodnetPodcast;
import de.danoeh.antennapod.gpoddernet.model.GpodnetTag;
import java.util.List;
/**
* Shows all podcasts from gpodder.net that belong to a specific tag.
* Use the newInstance method of this class to create a new TagFragment.
*/
public class TagFragment extends PodcastListFragment {
private static final String TAG = "TagFragment";
private static final int PODCAST_COUNT = 50;
private GpodnetTag tag;
public static TagFragment newInstance(String tagName) {
if (tagName == null) throw new IllegalArgumentException("tagName = null");
TagFragment fragment = new TagFragment();
Bundle args = new Bundle();
args.putString("tag", tagName);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
if (args == null || args.getString("tag") == null) throw new IllegalArgumentException("args invalid");
tag = new GpodnetTag(args.getString("tag"));
((MainActivity) getActivity()).getMainActivtyActionBar().setTitle(tag.getName());
}
@Override
protected List<GpodnetPodcast> loadPodcastData(GpodnetService service) throws GpodnetServiceException {
return service.getPodcastsForTag(tag, PODCAST_COUNT);
}
}

View File

@ -9,6 +9,7 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.gpoddernet.GpodnetTagActivity;
import de.danoeh.antennapod.gpoddernet.GpodnetService;
import de.danoeh.antennapod.gpoddernet.GpodnetServiceException;
@ -24,15 +25,13 @@ public class TagListFragment extends ListFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setRetainInstance(true);
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedTag = (String) getListAdapter().getItem(position);
Intent intent = new Intent(getActivity(), GpodnetTagActivity.class);
intent.putExtra(GpodnetTagActivity.ARG_TAGNAME, selectedTag);
startActivity(intent);
MainActivity activity = (MainActivity) getActivity();
activity.loadChildFragment(TagFragment.newInstance(selectedTag));
}
});