Subscription view for managing feeds and Navigation drawer feed list cleanup

This commit is contained in:
Raghul Jagannathan 2015-05-27 08:31:42 +08:00
parent ba036e1499
commit d0022e053e
28 changed files with 471 additions and 9 deletions

View File

@ -22,6 +22,7 @@ dependencies {
compile 'com.squareup.okio:okio:1.2.0'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.joanzapata.android:android-iconify:1.0.9'
compile 'io.reactivex:rxandroid:0.24.0'
compile project(':core')
compile project(':library:drag-sort-listview')

View File

@ -23,12 +23,6 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.Validate;
import java.util.List;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.NavListAdapter;
import de.danoeh.antennapod.core.feed.EventDistributor;
@ -45,9 +39,13 @@ import de.danoeh.antennapod.fragment.ItemlistFragment;
import de.danoeh.antennapod.fragment.NewEpisodesFragment;
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;
import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.Validate;
/**
* The activity that is shown when the user launches the app.
@ -79,6 +77,7 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
AllEpisodesFragment.TAG,
DownloadsFragment.TAG,
PlaybackHistoryFragment.TAG,
SubscriptionFragment.TAG,
AddFeedFragment.TAG
};
@ -282,6 +281,11 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
case AddFeedFragment.TAG:
fragment = new AddFeedFragment();
break;
case SubscriptionFragment.TAG:
SubscriptionFragment subscriptionFragment = new SubscriptionFragment();
subscriptionFragment.setItemAccess(itemAccess);
fragment = subscriptionFragment;
break;
}
currentTitle = navAdapter.getLabel(tag);
getSupportActionBar().setTitle(currentTitle);
@ -292,6 +296,7 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
loadFragment(fragment);
}
private void loadFeedFragmentByPosition(int relPos, Bundle args) {
if(relPos < 0) {
return;
@ -305,7 +310,15 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
saveLastNavFragment(String.valueOf(feed.getId()));
currentTitle = "";
getSupportActionBar().setTitle(currentTitle);
loadFragment(fragment);
loadChildFragment(fragment);
}
private void loadFeedFragment(Feed feed){
long feedId = feed.getId();
Fragment fragment = ItemlistFragment.newInstance(feedId);
currentTitle = "";
getSupportActionBar().setTitle(currentTitle);
loadChildFragment(fragment);
}
public void loadFeedFragmentById(long feedId) {
@ -537,7 +550,7 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
String lastFragment = getLastNavFragment();
if(!ArrayUtils.contains(NAV_DRAWER_TAGS, lastFragment)) {
long feedId = Long.valueOf(lastFragment);
loadFeedFragmentById(feedId);
//loadFeedFragmentById(feedId);
saveLastNavFragment(null);
}
@ -560,6 +573,10 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
loadData();
}
public void onEvent(SubscriptionFragment.SubscriptionEvent event){
loadFeedFragment(event.feed);
}
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
@Override
@ -593,4 +610,15 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
super.onNewIntent(intent);
setIntent(intent);
}
@Override
public void onBackPressed() {
// Make sure to have consistent behaviour across android apps
// Close the nav drawer if open on the first back button press
if(drawerLayout.isDrawerOpen(navDrawer)){
drawerLayout.closeDrawer(navDrawer);
return;
}
super.onBackPressed();
}
}

View File

@ -16,6 +16,7 @@ import android.widget.TextView;
import com.squareup.picasso.Picasso;
import de.danoeh.antennapod.fragment.SubscriptionFragment;
import org.apache.commons.lang3.ArrayUtils;
import java.util.ArrayList;
@ -100,6 +101,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;
@ -119,7 +123,7 @@ public class NavListAdapter extends BaseAdapter
@Override
public int getCount() {
return getSubscriptionOffset() + itemAccess.getCount();
return getSubscriptionOffset() ;//+ itemAccess.getCount(); //Avoid feed
}
@Override

View File

@ -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 0;
}
@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, mItemAccess.getNumberOfUnreadFeedItems(item.getId()));
return convertView;
}
static class Holder {
SubscriptionViewItem itemView;
}
}

View File

@ -0,0 +1,108 @@
package de.danoeh.antennapod.fragment;
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.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.functions.Action1;
/**
* 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.just(loadData()).subscribe(new Action1<DBReader.NavDrawerData>() {
@Override
public void call(DBReader.NavDrawerData navDrawerData) {
mDrawerData = navDrawerData;
mSubscriptionList = mDrawerData.feeds;
mSubscriptionAdapter.setItemAccess(mItemAccess);
mSubscriptionAdapter.notifyDataSetChanged();
}
});
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(getActivity());
}
}

View File

@ -0,0 +1,64 @@
package de.danoeh.antennapod.utils;
import android.content.Context;
import java.util.Date;
import de.danoeh.antennapod.R;
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//http://stackoverflow.com/questions/13018550/time-since-ago-library-for-android-java
public class TimeUtils {
private static final int SECOND_MILLIS = 1000;
private static final int MINUTE_MILLIS = 60 * SECOND_MILLIS;
private static final int HOUR_MILLIS = 60 * MINUTE_MILLIS;
private static final int DAY_MILLIS = 24 * HOUR_MILLIS;
public static String getTimeAgo(long time, Context ctx) {
if (time < 1000000000000L) {
// if timestamp given in seconds, convert to millis
time *= 1000;
}
long now = new Date().getTime();
if (time > now || time <= 0) {
return null;
}
final long diff = now - time;
if (diff < MINUTE_MILLIS) {
return ctx.getString(R.string.time_just_now);
} else if (diff < 2 * MINUTE_MILLIS) {
return ctx.getString(R.string.time_a_min_ago);
} else if (diff < 50 * MINUTE_MILLIS) {
return diff / MINUTE_MILLIS + ctx.getString(R.string.time_min_ago);
} else if (diff < 90 * MINUTE_MILLIS) {
return ctx.getString(R.string.time_an_hour_ago);
} else if (diff < 24 * HOUR_MILLIS) {
return diff / HOUR_MILLIS + ctx.getString(R.string.time_hours_ago);
} else if (diff < 48 * HOUR_MILLIS) {
return ctx.getString(R.string.time_yesterday);
} else {
return diff / DAY_MILLIS + ctx.getString(R.string.time_days_ago);
}
}
}

View File

@ -0,0 +1,63 @@
package de.danoeh.antennapod.view;
import android.content.Context;
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.squareup.picasso.Picasso;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.utils.TimeUtils;
/**
* Custom view for handling feed item.
*/
public class SubscriptionViewItem extends RelativeLayout {
private ImageView mImageView;
private TextView mTitle;
private TextView mUnreadCountText;
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);
mTitle = (TextView) view.findViewById(R.id.txtvTitle);
mImageView = (ImageView) view.findViewById(R.id.imgvCover);
mUnreadCountText = (TextView) view.findViewById(R.id.unread_count_text);
}
public void setFeed(Feed feed, int unreadCount) {
Picasso.with(mContext).load(feed.getImageUri()).centerCrop().fit().into(mImageView);
mUnreadCountText.setText(unreadCount + "");
mTitle.setText(TimeUtils.getTimeAgo(feed.getLastUpdate().getTime(), mContext));
}
}

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:centerX="69%"
android:startColor="#00000000"
android:centerColor="#59000000"
android:endColor="#FF242424"
android:angle="270"/>
</shape>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:src="@drawable/ic_launcher" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/cover_image_bg">
</RelativeLayout>
<TextView
android:id="@+id/txtvTitle"
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="5dp"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="12sp" />
<RelativeLayout
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_alignParentBottom="true"
android:layout_margin="5dp"
android:background="@drawable/unread_circle">
<TextView
android:id="@+id/unread_count_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="end"
android:maxLines="1"
android:text="3"
android:textColor="@color/white"
android:textSize="11sp" />
</RelativeLayout>
</RelativeLayout>

View File

@ -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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 B

View File

@ -134,6 +134,7 @@
<item>@string/all_episodes_label</item>
<item>@string/downloads_label</item>
<item>@string/playback_history_label</item>
<item>@string/my_subscriptions</item>
<item>@string/add_feed_label</item>
</string-array>

View File

@ -23,6 +23,7 @@
<attr name="navigation_chapters" format="reference"/>
<attr name="social_share" format="reference"/>
<attr name="stat_playlist" format="reference"/>
<attr name="ic_folder" format="reference"/>
<attr name="type_audio" format="reference"/>
<attr name="type_video" format="reference"/>
<attr name="borderless_button" format="reference"/>

View File

@ -22,6 +22,7 @@
<string name="downloads_log_label">Log</string>
<string name="cancel_download_label">Cancel Download</string>
<string name="playback_history_label">Playback history</string>
<string name="my_subscriptions">Subscriptions</string>
<string name="gpodnet_main_label">gpodder.net</string>
<string name="gpodnet_auth_label">gpodder.net login</string>

View File

@ -37,6 +37,7 @@
<item name="attr/ic_action_overflow">@drawable/ic_more_vert_grey600_24dp</item>
<item name="attr/ic_new">@drawable/ic_new_releases_grey600_24dp</item>
<item name="attr/ic_history">@drawable/ic_history_grey600_24dp</item>
<item name="attr/ic_folder">@drawable/ic_folder_grey600_24dp</item>
<item name="attr/av_play_big">@drawable/ic_play_arrow_grey600_36dp</item>
<item name="attr/av_pause_big">@drawable/ic_pause_grey600_36dp</item>
<item name="attr/av_ff_big">@drawable/ic_fast_forward_grey600_36dp</item>
@ -82,6 +83,7 @@
<item name="attr/ic_action_overflow">@drawable/ic_more_vert_white_24dp</item>
<item name="attr/ic_new">@drawable/ic_new_releases_white_24dp</item>
<item name="attr/ic_history">@drawable/ic_history_white_24dp</item>
<item name="attr/ic_folder">@drawable/ic_folder_white_24dp</item>
<item name="attr/av_play_big">@drawable/ic_play_arrow_white_36dp</item>
<item name="attr/av_pause_big">@drawable/ic_pause_white_36dp</item>
<item name="attr/av_ff_big">@drawable/ic_fast_forward_white_36dp</item>
@ -130,6 +132,7 @@
<item name="attr/ic_action_overflow">@drawable/ic_more_vert_grey600_24dp</item>
<item name="attr/ic_new">@drawable/ic_new_releases_grey600_24dp</item>
<item name="attr/ic_history">@drawable/ic_history_grey600_24dp</item>
<item name="attr/ic_folder">@drawable/ic_folder_grey600_24dp</item>
<item name="attr/av_play_big">@drawable/ic_play_arrow_grey600_36dp</item>
<item name="attr/av_pause_big">@drawable/ic_pause_grey600_36dp</item>
<item name="attr/av_ff_big">@drawable/ic_fast_forward_grey600_36dp</item>
@ -177,6 +180,7 @@
<item name="attr/ic_action_overflow">@drawable/ic_more_vert_white_24dp</item>
<item name="attr/ic_new">@drawable/ic_new_releases_white_24dp</item>
<item name="attr/ic_history">@drawable/ic_history_white_24dp</item>
<item name="attr/ic_folder">@drawable/ic_folder_white_24dp</item>
<item name="attr/av_play_big">@drawable/ic_play_arrow_white_36dp</item>
<item name="attr/av_pause_big">@drawable/ic_pause_white_36dp</item>
<item name="attr/av_ff_big">@drawable/ic_fast_forward_white_36dp</item>

1
submodules/dslv Submodule

@ -0,0 +1 @@
Subproject commit 5f58dff340f705b4dc7f920f81c33d382919c3ad