diff options
author | Tom Hennen <tom.hennen@gmail.com> | 2016-03-25 12:53:26 -0400 |
---|---|---|
committer | Tom Hennen <tom.hennen@gmail.com> | 2016-03-25 12:53:26 -0400 |
commit | 7ed82bcac3e1a66d21d6f01c2460e84682c82d6f (patch) | |
tree | 42d5f7964c8d5114902f4e15538b39941ce82b4b /app | |
parent | 163af2a6325dec30b75816b2671b5a586d61d865 (diff) | |
parent | 4cd58a9b37899e0c886a930f268b701d29a9a989 (diff) | |
download | AntennaPod-7ed82bcac3e1a66d21d6f01c2460e84682c82d6f.zip |
merge subscriptions view updates
Diffstat (limited to 'app')
-rw-r--r-- | app/build.gradle | 7 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java | 18 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java | 10 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java | 70 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java | 113 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/view/SubscriptionViewItem.java | 83 | ||||
-rw-r--r-- | app/src/main/res/drawable/unread_circle.xml | 10 | ||||
-rw-r--r-- | app/src/main/res/layout/fragment_subscriptions.xml | 16 | ||||
-rw-r--r-- | app/src/main/res/layout/subscription_item.xml | 12 | ||||
-rw-r--r-- | app/src/main/res/layout/subscription_view.xml | 43 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 10 | ||||
-rw-r--r-- | app/src/main/res/xml/preferences.xml | 6 |
12 files changed, 392 insertions, 6 deletions
diff --git a/app/build.gradle b/app/build.gradle index 240fd6f9f..73d751fb4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,7 +19,6 @@ dependencies { compile("org.shredzone.flattr4j:flattr4j-core:$flattr4jVersion") { exclude group: "org.json", module: "json" } - compile "commons-io:commons-io:$commonsioVersion" compile "org.jsoup:jsoup:$jsoupVersion" compile "com.github.bumptech.glide:glide:$glideVersion" @@ -49,14 +48,14 @@ dependencies { def getMyVersionName() { def parsedManifestXml = (new XmlSlurper()) .parse("${projectDir}/src/main/AndroidManifest.xml") - .declareNamespace(android:"http://schemas.android.com/apk/res/android") + .declareNamespace(android: "http://schemas.android.com/apk/res/android") return parsedManifestXml."@android:versionName" } def getMyVersionCode() { def parsedManifestXml = (new XmlSlurper()) .parse("${projectDir}/src/main/AndroidManifest.xml") - .declareNamespace(android:"http://schemas.android.com/apk/res/android") + .declareNamespace(android: "http://schemas.android.com/apk/res/android") return parsedManifestXml."@android:versionCode".toInteger() } @@ -150,7 +149,7 @@ task filterAbout { from "src/main/templates/about.html" into "src/main/assets" filter(ReplaceTokens, tokens: [versionname: android.defaultConfig.versionName, - commit: "git rev-parse --short HEAD".execute().text]) + commit : "git rev-parse --short HEAD".execute().text]) } } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 6c0f0ab4d..3b5168f51 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -43,13 +43,17 @@ import de.danoeh.antennapod.core.event.ProgressEvent; import de.danoeh.antennapod.core.event.QueueEvent; import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.Feed; +import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; +import de.danoeh.antennapod.core.service.playback.PlayerStatus; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.StorageUtils; +import de.danoeh.antennapod.core.util.playback.Playable; +import de.danoeh.antennapod.core.util.playback.PlaybackController; import de.danoeh.antennapod.dialog.RatingDialog; import de.danoeh.antennapod.fragment.AddFeedFragment; import de.danoeh.antennapod.fragment.DownloadsFragment; @@ -58,6 +62,7 @@ import de.danoeh.antennapod.fragment.ExternalPlayerFragment; import de.danoeh.antennapod.fragment.ItemlistFragment; import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; +import de.danoeh.antennapod.fragment.SubscriptionFragment; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; import de.danoeh.antennapod.preferences.PreferenceController; import de.greenrobot.event.EventBus; @@ -94,6 +99,7 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity EpisodesFragment.TAG, DownloadsFragment.TAG, PlaybackHistoryFragment.TAG, + SubscriptionFragment.TAG, AddFeedFragment.TAG }; @@ -269,7 +275,7 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity } public void loadFragment(int index, Bundle args) { - Log.d(TAG, "loadFragment(index: " + index + ", args: " + args +")"); + Log.d(TAG, "loadFragment(index: " + index + ", args: " + args + ")"); if (index < navAdapter.getSubscriptionOffset()) { String tag = navAdapter.getTags().get(index); loadFragment(tag, args); @@ -298,6 +304,11 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity case AddFeedFragment.TAG: fragment = new AddFeedFragment(); break; + case SubscriptionFragment.TAG: + SubscriptionFragment subscriptionFragment = new SubscriptionFragment(); + subscriptionFragment.setItemAccess(itemAccess); + fragment = subscriptionFragment; + break; default: // default to the queue tag = QueueFragment.TAG; @@ -646,6 +657,7 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity public int getFeedCounter(long feedId) { return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0; } + }; private void loadData() { @@ -671,6 +683,10 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity loadData(); } + public void onEvent(SubscriptionFragment.SubscriptionEvent event) { + loadFeedFragmentById(event.feed.getId(), null); + } + public void onEventMainThread(ProgressEvent event) { Log.d(TAG, "onEvent(" + event + ")"); switch(event.action) { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java index c98a2fac7..0227aeee4 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -19,6 +19,7 @@ import com.bumptech.glide.Glide; import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.widget.IconTextView; +import de.danoeh.antennapod.fragment.SubscriptionFragment; import org.apache.commons.lang3.ArrayUtils; import java.util.ArrayList; @@ -108,6 +109,9 @@ public class NavListAdapter extends BaseAdapter case PlaybackHistoryFragment.TAG: icon = R.attr.ic_history; break; + case SubscriptionFragment.TAG: + icon = R.attr.ic_folder; + break; case AddFeedFragment.TAG: icon = R.attr.content_new; break; @@ -127,7 +131,11 @@ public class NavListAdapter extends BaseAdapter @Override public int getCount() { - return getSubscriptionOffset() + itemAccess.getCount(); + int baseCount = getSubscriptionOffset(); + if (UserPreferences.showSubscriptionsInDrawer()) { + baseCount += itemAccess.getCount(); + } + return baseCount; } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java new file mode 100644 index 000000000..de000570b --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java @@ -0,0 +1,70 @@ +package de.danoeh.antennapod.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; + +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.feed.Feed; +import de.danoeh.antennapod.view.SubscriptionViewItem; + +/** + * Adapter for subscriptions + */ +public class SubscriptionsAdapter extends BaseAdapter { + + private NavListAdapter.ItemAccess mItemAccess; + + private Context mContext; + + public SubscriptionsAdapter(Context context, NavListAdapter.ItemAccess itemAccess) { + mItemAccess = itemAccess; + mContext = context; + } + + public void setItemAccess(NavListAdapter.ItemAccess itemAccess) { + mItemAccess = itemAccess; + } + + @Override + public int getCount() { + return mItemAccess.getCount(); + } + + @Override + public Object getItem(int position) { + return mItemAccess.getItem(position); + } + + @Override + public long getItemId(int position) { + return mItemAccess.getItem(position).getId(); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Holder holder; + final Feed item = (Feed) getItem(position); + if (item == null) return null; + + if (convertView == null) { + holder = new Holder(); + LayoutInflater inflater = + (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + convertView = inflater.inflate(R.layout.subscription_item, parent, false); + holder.itemView = (SubscriptionViewItem) convertView.findViewById(R.id.subscription_item); + convertView.setTag(holder); + } else { + holder = (Holder) convertView.getTag(); + } + + holder.itemView.setFeed(item); + return convertView; + } + + static class Holder { + SubscriptionViewItem itemView; + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java new file mode 100644 index 000000000..286212891 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -0,0 +1,113 @@ +package de.danoeh.antennapod.fragment; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.GridView; + +import java.util.ArrayList; +import java.util.List; + +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.adapter.NavListAdapter; +import de.danoeh.antennapod.adapter.SubscriptionsAdapter; +import de.danoeh.antennapod.core.feed.Feed; +import de.danoeh.antennapod.core.storage.DBReader; +import de.greenrobot.event.EventBus; +import rx.Observable; +import rx.android.schedulers.AndroidSchedulers; +import rx.schedulers.Schedulers; + +/** + * Fragment for displaying feed subscriptions + */ +public class SubscriptionFragment extends Fragment { + + public static final String TAG = "SubscriptionFragment"; + + private GridView mSubscriptionGridLayout; + private DBReader.NavDrawerData mDrawerData; + private SubscriptionsAdapter mSubscriptionAdapter; + private NavListAdapter.ItemAccess mItemAccess; + + private List<Feed> mSubscriptionList = new ArrayList<>(); + + + public SubscriptionFragment() { + } + + + public void setItemAccess(NavListAdapter.ItemAccess itemAccess) { + mItemAccess = itemAccess; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setRetainInstance(true); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View root = inflater.inflate(R.layout.fragment_subscriptions, container, false); + mSubscriptionGridLayout = (GridView) root.findViewById(R.id.subscriptions_grid); + return root; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + mSubscriptionAdapter = new SubscriptionsAdapter(getActivity(), mItemAccess); + + mSubscriptionGridLayout.setAdapter(mSubscriptionAdapter); + + Observable.fromCallable(() -> loadData()) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(result -> { + mDrawerData = result; + mSubscriptionList = mDrawerData.feeds; + mSubscriptionAdapter.setItemAccess(mItemAccess); + mSubscriptionAdapter.notifyDataSetChanged(); + }, error -> { + Log.e(TAG, Log.getStackTraceString(error)); + }); + + + mSubscriptionGridLayout.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + EventBus.getDefault().post(new SubscriptionEvent(mSubscriptionList.get(position))); + } + }); + + if (getActivity() instanceof MainActivity) { + ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.my_subscriptions); + } + + } + + @Override + public void onResume() { + super.onResume(); + } + + public class SubscriptionEvent { + public final Feed feed; + + SubscriptionEvent(Feed f) { + feed = f; + } + } + + + private DBReader.NavDrawerData loadData() { + return DBReader.getNavDrawerData(); + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/view/SubscriptionViewItem.java b/app/src/main/java/de/danoeh/antennapod/view/SubscriptionViewItem.java new file mode 100644 index 000000000..67973a7ef --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/view/SubscriptionViewItem.java @@ -0,0 +1,83 @@ +package de.danoeh.antennapod.view; + +import android.content.Context; +import android.net.Uri; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.resource.drawable.GlideDrawable; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.target.Target; + +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.feed.Feed; + +/** + * Custom view for handling feed item. + */ +public class SubscriptionViewItem extends RelativeLayout { + + private ImageView mImageView; + private TextView mTextTime; + private TextView mFeedTitle; + private Context mContext; + + public SubscriptionViewItem(Context context) { + super(context); + init(context); + } + + public SubscriptionViewItem(Context context, AttributeSet attrs) { + super(context, attrs); + init(context); + } + + public SubscriptionViewItem(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(context); + } + + @Override + public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, widthMeasureSpec); + } + + private void init(Context context) { + mContext = context; + LayoutInflater mLayoutInflater = + (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View view = mLayoutInflater.inflate(R.layout.subscription_view, this); + mTextTime = (TextView) view.findViewById(R.id.txtvTime); + mFeedTitle = (TextView) view.findViewById(R.id.txtvTitle); + mImageView = (ImageView) view.findViewById(R.id.imgvCover); + } + + public void setFeed(Feed feed) { + mFeedTitle.setVisibility(VISIBLE); + mFeedTitle.setText(feed.getTitle()); + Glide.with(mContext) + .load(feed.getImageUri()) + .listener(new RequestListener<Uri, GlideDrawable>() { + @Override + public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) { + return false; + } + + @Override + public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { + mFeedTitle.setVisibility(INVISIBLE); + return false; + } + }) + .centerCrop() + .into(mImageView); + + mTextTime.setVisibility(GONE); + } + +} diff --git a/app/src/main/res/drawable/unread_circle.xml b/app/src/main/res/drawable/unread_circle.xml new file mode 100644 index 000000000..c31e753b1 --- /dev/null +++ b/app/src/main/res/drawable/unread_circle.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="oval"> + + + <stroke + android:width="1dp" + android:color="@color/white"/> + +</shape>
\ No newline at end of file diff --git a/app/src/main/res/layout/fragment_subscriptions.xml b/app/src/main/res/layout/fragment_subscriptions.xml new file mode 100644 index 000000000..8a61e5fa5 --- /dev/null +++ b/app/src/main/res/layout/fragment_subscriptions.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <GridView + android:id="@+id/subscriptions_grid" + android:layout_width="match_parent" + android:numColumns="3" + android:horizontalSpacing="2dp" + android:verticalSpacing="2dp" + android:layout_height="match_parent" + android:layout_gravity="center_horizontal"> + </GridView> +</LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/subscription_item.xml b/app/src/main/res/layout/subscription_item.xml new file mode 100644 index 000000000..fc89ab74d --- /dev/null +++ b/app/src/main/res/layout/subscription_item.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + + <de.danoeh.antennapod.view.SubscriptionViewItem + android:layout_width="match_parent" + android:id="@+id/subscription_item" + android:layout_height="match_parent"/> + +</RelativeLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/subscription_view.xml b/app/src/main/res/layout/subscription_view.xml new file mode 100644 index 000000000..84dc00ba5 --- /dev/null +++ b/app/src/main/res/layout/subscription_view.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <ImageView + android:id="@+id/imgvCover" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:layout_centerHorizontal="true" + android:layout_centerVertical="true" + tools:src="@drawable/ic_launcher" /> + + <TextView + android:id="@+id/txtvTitle" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_centerInParent="true" + android:layout_margin="@dimen/widget_margin" + android:ellipsize="end" + android:padding="@dimen/widget_margin" + style="@style/AntennaPod.TextView.Heading" + android:textSize="15sp" + android:textStyle="bold" + tools:text="@string/app_name" /> + + <TextView + android:id="@+id/txtvTime" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentBottom="true" + android:layout_alignParentEnd="true" + android:layout_alignParentRight="true" + android:layout_margin="@dimen/widget_margin" + android:ellipsize="end" + android:maxLines="1" + android:textColor="@color/white" + android:textSize="12sp" + tools:text="@string/app_name" /> + +</RelativeLayout>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 000000000..9c055f887 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="time_just_now">just now</string> + <string name="time_a_min_ago">a min ago</string> + <string name="time_an_hour_ago">an hour ago</string> + <string name="time_min_ago">" min ago"</string> + <string name="time_yesterday">yesterday</string> + <string name="time_hours_ago">" hours ago"</string> + <string name="time_days_ago">" days ago"</string> +</resources>
\ No newline at end of file diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 675687fb8..93df4e3e0 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -36,6 +36,12 @@ android:summary="@string/pref_nav_drawer_feed_counter_sum" android:defaultValue="0" app:useStockLayout="true"/> + <de.danoeh.antennapod.preferences.SwitchCompatPreference + android:defaultValue="true" + android:enabled="true" + android:key="prefShowSubscriptionsInDrawer" + android:summary="@string/pref_show_subscriptions_in_drawer_sum" + android:title="@string/pref_show_subscriptions_in_drawer_title"/> </PreferenceScreen> <de.danoeh.antennapod.preferences.SwitchCompatPreference android:defaultValue="false" |