Merge pull request #1857 from mfietz/issue/1850-subscriptions-counter

Subscription counter
This commit is contained in:
Tom Hennen 2016-04-07 17:02:52 -04:00
commit 9b563c1c87
4 changed files with 45 additions and 1 deletions

View File

@ -537,6 +537,18 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
public int getFeedCounter(long feedId) { public int getFeedCounter(long feedId) {
return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0; return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0;
} }
@Override
public int getFeedCounterSum() {
if(navDrawerData == null) {
return 0;
}
int sum = 0;
for(int counter : navDrawerData.feedCounters.values()) {
sum += counter;
}
return sum;
}
}; };
public interface AudioplayerContentFragment { public interface AudioplayerContentFragment {

View File

@ -654,6 +654,18 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity
return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0; return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0;
} }
@Override
public int getFeedCounterSum() {
if(navDrawerData == null) {
return 0;
}
int sum = 0;
for(int counter : navDrawerData.feedCounters.values()) {
sum += counter;
}
return sum;
}
}; };
private void loadData() { private void loadData() {

View File

@ -19,7 +19,6 @@ import com.bumptech.glide.Glide;
import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.widget.IconTextView; import com.joanzapata.iconify.widget.IconTextView;
import de.danoeh.antennapod.fragment.SubscriptionFragment;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import java.util.ArrayList; import java.util.ArrayList;
@ -39,6 +38,7 @@ import de.danoeh.antennapod.fragment.EpisodesFragment;
import de.danoeh.antennapod.fragment.NewEpisodesFragment; import de.danoeh.antennapod.fragment.NewEpisodesFragment;
import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.fragment.QueueFragment;
import de.danoeh.antennapod.fragment.SubscriptionFragment;
/** /**
* BaseAdapter for the navigation drawer * BaseAdapter for the navigation drawer
@ -253,6 +253,14 @@ public class NavListAdapter extends BaseAdapter
} else { } else {
holder.count.setVisibility(View.GONE); holder.count.setVisibility(View.GONE);
} }
} else if (tag.equals(SubscriptionFragment.TAG)) {
int sum = itemAccess.getFeedCounterSum();
if (sum > 0) {
holder.count.setVisibility(View.VISIBLE);
holder.count.setText(String.valueOf(sum));
} else {
holder.count.setVisibility(View.GONE);
}
} else if(tag.equals(DownloadsFragment.TAG) && UserPreferences.isEnableAutodownload()) { } else if(tag.equals(DownloadsFragment.TAG) && UserPreferences.isEnableAutodownload()) {
int epCacheSize = UserPreferences.getEpisodeCacheSize(); int epCacheSize = UserPreferences.getEpisodeCacheSize();
// don't count episodes that can be reclaimed // don't count episodes that can be reclaimed
@ -372,6 +380,7 @@ public class NavListAdapter extends BaseAdapter
int getNumberOfDownloadedItems(); int getNumberOfDownloadedItems();
int getReclaimableItems(); int getReclaimableItems();
int getFeedCounter(long feedId); int getFeedCounter(long feedId);
int getFeedCounterSum();
} }
} }

View File

@ -1,6 +1,8 @@
package de.danoeh.antennapod.core.util; package de.danoeh.antennapod.core.util;
import java.util.Arrays;
/** /**
* Fast and memory efficient long to long map * Fast and memory efficient long to long map
*/ */
@ -197,6 +199,15 @@ public class LongIntMap {
size = 0; size = 0;
} }
/**
* Returns a copy of the values contained in this map.
*
* @return a copy of the values contained in this map
*/
public int[] values() {
return Arrays.copyOf(values, size);
}
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (other == this) { if (other == this) {