diff options
Diffstat (limited to 'app/src/main/java/de/danoeh')
16 files changed, 162 insertions, 50 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java index 014c65e11..50d557735 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -499,6 +499,11 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe } @Override + public int getNumberOfDownloadedItems() { + return (navDrawerData != null) ? navDrawerData.numDownloadedItems : 0; + } + + @Override public int getFeedCounter(long feedId) { return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0; } 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 17cd5ace3..2181e7d2d 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -636,6 +636,11 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity } @Override + public int getNumberOfDownloadedItems() { + return (navDrawerData != null) ? navDrawerData.numDownloadedItems : 0; + } + + @Override public int getFeedCounter(long feedId) { return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0; } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java index f120aa1d5..1fa4b7c48 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java @@ -4,7 +4,6 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; -import android.text.format.DateUtils; import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; @@ -15,7 +14,6 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; @@ -36,6 +34,7 @@ import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.Converter; +import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.NetworkUtils; import de.danoeh.antennapod.fragment.ItemFragment; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; @@ -118,8 +117,8 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR holder.placeholder.setVisibility(View.VISIBLE); holder.placeholder.setText(item.getFeed().getTitle()); holder.title.setText(item.getTitle()); - holder.pubDate.setText(DateUtils.formatDateTime(mainActivityRef.get(), - item.getPubDate().getTime(), DateUtils.FORMAT_ABBREV_ALL)); + String pubDateStr = DateUtils.formatAbbrev(mainActivityRef.get(), item.getPubDate()); + holder.pubDate.setText(pubDateStr); if (showOnlyNewEpisodes || false == item.isNew()) { holder.statusUnread.setVisibility(View.INVISIBLE); } else { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java index 2b1eccea5..ca747b9b0 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java @@ -1,7 +1,6 @@ package de.danoeh.antennapod.adapter; import android.content.Context; -import android.text.format.DateUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -11,12 +10,12 @@ import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; -import com.bumptech.glide.load.engine.DiskCacheStrategy; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.util.Converter; +import de.danoeh.antennapod.core.util.DateUtils; /** * Shows a list of downloaded episodes @@ -75,7 +74,8 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter { } holder.title.setText(item.getTitle()); - holder.pubDate.setText(DateUtils.formatDateTime(context, item.getPubDate().getTime(), DateUtils.FORMAT_ABBREV_ALL)); + String pubDateStr = DateUtils.formatAbbrev(context, item.getPubDate()); + holder.pubDate.setText(pubDateStr); holder.txtvSize.setText(Converter.byteToString(item.getMedia().getSize())); FeedItem.State state = item.getState(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java index e1d158d6a..e483738b4 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java @@ -2,7 +2,6 @@ package de.danoeh.antennapod.adapter; import android.content.Context; import android.content.res.TypedArray; -import android.text.format.DateUtils; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -23,6 +22,7 @@ import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DownloadRequester; +import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.ThemeUtils; /** @@ -143,8 +143,8 @@ public class FeedItemlistAdapter extends BaseAdapter { ViewHelper.setAlpha(convertView, 1.0f); } - holder.published.setText(DateUtils.formatDateTime(context, item.getPubDate().getTime(), DateUtils.FORMAT_ABBREV_ALL)); - + String pubDateStr = DateUtils.formatAbbrev(context, item.getPubDate()); + holder.published.setText(pubDateStr); FeedMedia media = item.getMedia(); if (media == null) { 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 183c1a44e..d43e30d8f 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -6,6 +6,7 @@ import android.content.res.TypedArray; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.preference.PreferenceManager; +import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -15,7 +16,7 @@ import android.widget.RelativeLayout; import android.widget.TextView; import com.bumptech.glide.Glide; -import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.widget.IconTextView; import org.apache.commons.lang3.ArrayUtils; @@ -208,7 +209,8 @@ public class NavListAdapter extends BaseAdapter holder.title.setText(title); - if (tags.get(position).equals(QueueFragment.TAG)) { + String tag = tags.get(position); + if (tag.equals(QueueFragment.TAG)) { int queueSize = itemAccess.getQueueSize(); if (queueSize > 0) { holder.count.setVisibility(View.VISIBLE); @@ -216,7 +218,7 @@ public class NavListAdapter extends BaseAdapter } else { holder.count.setVisibility(View.GONE); } - } else if (tags.get(position).equals(EpisodesFragment.TAG)) { + } else if (tag.equals(EpisodesFragment.TAG)) { int unreadItems = itemAccess.getNumberOfNewItems(); if (unreadItems > 0) { holder.count.setVisibility(View.VISIBLE); @@ -224,6 +226,22 @@ public class NavListAdapter extends BaseAdapter } else { holder.count.setVisibility(View.GONE); } + } else if(tag.equals(DownloadsFragment.TAG) && UserPreferences.isEnableAutodownload()) { + int epCacheSize = UserPreferences.getEpisodeCacheSize(); + if(itemAccess.getNumberOfDownloadedItems() >= epCacheSize) { + holder.count.setText("{md-disc-full 150%}"); + Iconify.addIcons(holder.count); + holder.count.setVisibility(View.VISIBLE); + holder.count.setOnClickListener(v -> { + new AlertDialog.Builder(context) + .setTitle(R.string.episode_cache_full_title) + .setMessage(R.string.episode_cache_full_message) + .setPositiveButton(android.R.string.ok, (dialog, which) -> {}) + .show(); + }); + } else { + holder.count.setVisibility(View.GONE); + } } else { holder.count.setVisibility(View.GONE); } @@ -316,6 +334,7 @@ public class NavListAdapter extends BaseAdapter int getSelectedItemIndex(); int getQueueSize(); int getNumberOfNewItems(); + int getNumberOfDownloadedItems(); int getFeedCounter(long feedId); } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java index 3e4dd4deb..ca1f59e8d 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java @@ -6,7 +6,6 @@ import android.support.annotation.Nullable; import android.support.v4.view.MotionEventCompat; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; -import android.text.format.DateUtils; import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; @@ -28,6 +27,8 @@ import com.bumptech.glide.request.target.GlideDrawableImageViewTarget; import com.joanzapata.iconify.Iconify; import com.nineoldandroids.view.ViewHelper; +import org.apache.commons.lang3.StringUtils; + import java.lang.ref.WeakReference; import de.danoeh.antennapod.R; @@ -38,6 +39,7 @@ import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.Converter; +import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.NetworkUtils; import de.danoeh.antennapod.fragment.ItemFragment; @@ -209,9 +211,21 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap FeedMedia media = item.getMedia(); title.setText(item.getTitle()); - String pubDateStr = DateUtils.formatDateTime(mainActivity.get(), - item.getPubDate().getTime(), DateUtils.FORMAT_ABBREV_ALL); - pubDate.setText(pubDateStr.replace(" ", "\n")); + String pubDateStr = DateUtils.formatAbbrev(mainActivity.get(), item.getPubDate()); + int index = 0; + if(StringUtils.countMatches(pubDateStr, ' ') == 1 || StringUtils.countMatches(pubDateStr, ' ') == 2) { + index = pubDateStr.lastIndexOf(' '); + } else if(StringUtils.countMatches(pubDateStr, '.') == 2) { + index = pubDateStr.lastIndexOf('.'); + } else if(StringUtils.countMatches(pubDateStr, '-') == 2) { + index = pubDateStr.lastIndexOf('-'); + } else if(StringUtils.countMatches(pubDateStr, '/') == 2) { + index = pubDateStr.lastIndexOf('/'); + } + if(index > 0) { + pubDateStr = pubDateStr.substring(0, index+1).trim() + "\n" + pubDateStr.substring(index+1); + } + pubDate.setText(pubDateStr); if (media != null) { final boolean isDownloadingMedia = DownloadRequester.getInstance().isDownloadingFile(media); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index 9ccb0fbe3..2bc4e9ded 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -190,6 +190,9 @@ public class AllEpisodesFragment extends Fragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if(!isAdded()) { + return; + } super.onCreateOptionsMenu(menu, inflater); if (itemsLoaded) { inflater.inflate(R.menu.new_episodes, menu); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java index 47ed9676a..b470d379a 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java @@ -111,6 +111,9 @@ public class DownloadLogFragment extends ListFragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if(!isAdded()) { + return; + } super.onCreateOptionsMenu(menu, inflater); if (itemsLoaded) { MenuItem clearHistory = menu.add(Menu.NONE, R.id.clear_history_item, Menu.CATEGORY_CONTAINER, R.string.clear_history_label); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java index f71b90570..bbffd2dea 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -11,7 +11,6 @@ import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.util.Pair; import android.text.TextUtils; -import android.text.format.DateUtils; import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; @@ -55,6 +54,7 @@ import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.Converter; +import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.ShareUtils; @@ -243,7 +243,7 @@ public class ItemFragment extends Fragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - if(item == null) { + if(!isAdded() || item == null) { return; } inflater.inflate(R.menu.feeditem_options, menu); @@ -297,7 +297,8 @@ public class ItemFragment extends Fragment { txtvTitle.setText(item.getTitle()); if (item.getPubDate() != null) { - txtvPublished.setText(DateUtils.formatDateTime(getActivity(), item.getPubDate().getTime(), DateUtils.FORMAT_ABBREV_ALL)); + String pubDateStr = DateUtils.formatAbbrev(getActivity(), item.getPubDate()); + txtvPublished.setText(pubDateStr); } Glide.with(getActivity()) @@ -331,7 +332,7 @@ public class ItemFragment extends Fragment { butAction1Text = R.string.mark_read_label; } if (item.getLink() != null) { - butAction2Icon = "{ma-web 24sp}"; + butAction2Icon = "{md-web 24sp}"; butAction2Text = R.string.visit_website_label; } } else { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java index bc5024426..97c446fab 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -194,6 +194,9 @@ public class ItemlistFragment extends ListFragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if(!isAdded()) { + return; + } super.onCreateOptionsMenu(menu, inflater); if (itemsLoaded) { @@ -370,6 +373,9 @@ public class ItemlistFragment extends ListFragment { @Override public void onListItemClick(ListView l, View v, int position, long id) { + if(adapter == null) { + return; + } FeedItem selection = adapter.getItem(position - l.getHeaderViewsCount()); if (selection != null) { MainActivity activity = (MainActivity) getActivity(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java index 64e3a7da7..c5b77fae2 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -148,6 +148,9 @@ public class PlaybackHistoryFragment extends ListFragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if(!isAdded()) { + return; + } super.onCreateOptionsMenu(menu, inflater); if (itemsLoaded) { MenuItem clearHistory = menu.add(Menu.NONE, R.id.clear_history_item, Menu.CATEGORY_CONTAINER, R.string.clear_history_label); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index cc6b44f6a..43f22a587 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -68,6 +68,7 @@ public class QueueFragment extends Fragment { public static final String TAG = "QueueFragment"; private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED | + EventDistributor.UNREAD_ITEMS_UPDATE | // sent when playback position is reset EventDistributor.PLAYER_STATUS_UPDATE; private TextView infoBar; @@ -235,6 +236,9 @@ public class QueueFragment extends Fragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if(!isAdded()) { + return; + } super.onCreateOptionsMenu(menu, inflater); if (queue != null) { inflater.inflate(R.menu.queue, menu); @@ -268,10 +272,17 @@ public class QueueFragment extends Fragment { if (!super.onOptionsItemSelected(item)) { switch (item.getItemId()) { case R.id.queue_lock: - boolean locked = !UserPreferences.isQueueLocked(); - UserPreferences.setQueueLocked(locked); + boolean newLockState = !UserPreferences.isQueueLocked(); + UserPreferences.setQueueLocked(newLockState); getActivity().supportInvalidateOptionsMenu(); - recyclerAdapter.setLocked(locked); + recyclerAdapter.setLocked(newLockState); + if (newLockState) { + Snackbar.make(getActivity().findViewById(R.id.content), R.string + .queue_locked, Snackbar.LENGTH_SHORT).show(); + } else { + Snackbar.make(getActivity().findViewById(R.id.content), R.string + .queue_unlocked, Snackbar.LENGTH_SHORT).show(); + } return true; case R.id.refresh_item: List<Feed> feeds = ((MainActivity) getActivity()).getFeeds(); diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java index 06dbe4963..0224d2c7e 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -72,7 +72,10 @@ public class FeedItemMenuHandler { mi.setItemVisibility(R.id.skip_episode_item, false); } - boolean isInQueue = selectedItem.isTagged(FeedItem.TAG_QUEUE); + boolean isInQueue = false; + if(queueAccess != null) { + isInQueue = queueAccess.contains(selectedItem.getId()); + } if(queueAccess == null || queueAccess.size() == 0 || queueAccess.get(0) == selectedItem.getId()) { mi.setItemVisibility(R.id.move_to_top_item, false); } diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/MenuItemUtils.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/MenuItemUtils.java index cfc540fd6..0d2ff8a75 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/MenuItemUtils.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/MenuItemUtils.java @@ -34,10 +34,10 @@ public class MenuItemUtils extends de.danoeh.antennapod.core.menuhandler.MenuIte TypedArray ta = context.obtainStyledAttributes(lockIcons); if (UserPreferences.isQueueLocked()) { queueLock.setTitle(de.danoeh.antennapod.R.string.unlock_queue); - queueLock.setIcon(ta.getDrawable(1)); + queueLock.setIcon(ta.getDrawable(0)); } else { queueLock.setTitle(de.danoeh.antennapod.R.string.lock_queue); - queueLock.setIcon(ta.getDrawable(0)); + queueLock.setIcon(ta.getDrawable(1)); } } diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index a872039f9..083ac5202 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -30,10 +30,15 @@ import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; +import org.apache.commons.lang3.ArrayUtils; + import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; +import java.util.GregorianCalendar; import java.util.List; +import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.CrashReportWriter; import de.danoeh.antennapod.R; @@ -216,17 +221,16 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } }); - ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL) - .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if (newValue instanceof Boolean) { - ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled((Boolean) newValue); - setSelectedNetworksEnabled((Boolean) newValue && UserPreferences.isEnableAutodownloadWifiFilter()); - ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY).setEnabled((Boolean) newValue); - } - return true; + ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL).setOnPreferenceChangeListener( + (preference, newValue) -> { + if (newValue instanceof Boolean) { + boolean enabled = (Boolean) newValue; + ui.findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setEnabled(enabled); + ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY).setEnabled(enabled); + ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled(enabled); + setSelectedNetworksEnabled(enabled && UserPreferences.isEnableAutodownloadWifiFilter()); } + return true; }); ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER) .setOnPreferenceChangeListener( @@ -411,6 +415,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc public void onResume() { checkItemVisibility(); + setUpdateIntervalText(); setParallelDownloadsText(UserPreferences.getParallelDownloads()); setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize()); setDataFolderText(); @@ -503,15 +508,19 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc final Resources res = ui.getActivity().getResources(); ListPreference pref = (ListPreference) ui.findPreference(UserPreferences.PREF_SMART_MARK_AS_PLAYED_SECS); - String[] values = res.getStringArray( - R.array.smart_mark_as_played_values); + String[] values = res.getStringArray(R.array.smart_mark_as_played_values); String[] entries = new String[values.length]; for (int x = 0; x < values.length; x++) { if(x == 0) { entries[x] = res.getString(R.string.pref_smart_mark_as_played_disabled); } else { Integer v = Integer.parseInt(values[x]); - entries[x] = res.getQuantityString(R.plurals.time_seconds_quantified, v, v); + if(v < 60) { + entries[x] = res.getQuantityString(R.plurals.time_seconds_quantified, v, v); + } else { + v /= 60; + entries[x] = res.getQuantityString(R.plurals.time_minutes_quantified, v, v); + } } } pref.setEntries(entries); @@ -527,21 +536,17 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc @SuppressWarnings("deprecation") private void checkItemVisibility() { - boolean hasFlattrToken = FlattrUtils.hasToken(); - ui.findPreference(PreferenceController.PREF_FLATTR_SETTINGS).setEnabled(FlattrUtils.hasAPICredentials()); ui.findPreference(PreferenceController.PREF_FLATTR_AUTH).setEnabled(!hasFlattrToken); ui.findPreference(PreferenceController.PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken); ui.findPreference(PreferenceController.PREF_AUTO_FLATTR_PREFS).setEnabled(hasFlattrToken); - ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER) - .setEnabled(UserPreferences.isEnableAutodownload()); - setSelectedNetworksEnabled(UserPreferences.isEnableAutodownload() - && UserPreferences.isEnableAutodownloadWifiFilter()); - - ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY) - .setEnabled(UserPreferences.isEnableAutodownload()); + boolean autoDownload = UserPreferences.isEnableAutodownload(); + ui.findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setEnabled(autoDownload); + ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY).setEnabled(autoDownload); + ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled(autoDownload); + setSelectedNetworksEnabled(autoDownload && UserPreferences.isEnableAutodownloadWifiFilter()); ui.findPreference("prefSendCrashReport").setEnabled(CrashReportWriter.getFile().exists()); @@ -553,6 +558,32 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } } + private void setUpdateIntervalText() { + Context context = ui.getActivity().getApplicationContext(); + String val; + long interval = UserPreferences.getUpdateInterval(); + if(interval > 0) { + int hours = (int) TimeUnit.MILLISECONDS.toHours(interval); + String hoursStr = context.getResources().getQuantityString(R.plurals.time_hours_quantified, hours, hours); + val = String.format(context.getString(R.string.pref_autoUpdateIntervallOrTime_every), hoursStr); + } else { + int[] timeOfDay = UserPreferences.getUpdateTimeOfDay(); + if(timeOfDay.length == 2) { + Calendar cal = new GregorianCalendar(); + cal.set(Calendar.HOUR_OF_DAY, timeOfDay[0]); + cal.set(Calendar.MINUTE, timeOfDay[1]); + String timeOfDayStr = DateFormat.getTimeFormat(context).format(cal.getTime()); + val = String.format(context.getString(R.string.pref_autoUpdateIntervallOrTime_at), + timeOfDayStr); + } else { + val = context.getString(R.string.pref_smart_mark_as_played_disabled); + } + } + String summary = context.getString(R.string.pref_autoUpdateIntervallOrTime_sum) + "\n" + + String.format(context.getString(R.string.pref_current_value), val); + ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL).setSummary(summary); + } + private void setParallelDownloadsText(int downloads) { final Resources res = ui.getActivity().getResources(); @@ -772,10 +803,17 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc builder.setTitle(context.getString(R.string.pref_autoUpdateIntervallOrTime_Interval)); final String[] values = context.getResources().getStringArray(R.array.update_intervall_values); final String[] entries = getUpdateIntervalEntries(values); - builder.setSingleChoiceItems(entries, -1, (dialog1, which) -> { + long currInterval = UserPreferences.getUpdateInterval(); + int checkedItem = -1; + if(currInterval > 0) { + String currIntervalStr = String.valueOf(TimeUnit.MILLISECONDS.toHours(currInterval)); + checkedItem = ArrayUtils.indexOf(values, currIntervalStr); + } + builder.setSingleChoiceItems(entries, checkedItem, (dialog1, which) -> { int hours = Integer.valueOf(values[which]); UserPreferences.setUpdateInterval(hours); dialog1.dismiss(); + setUpdateIntervalText(); }); builder.setNegativeButton(context.getString(R.string.cancel_label), null); builder.show(); @@ -794,6 +832,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc if (view.getTag() == null) { // onTimeSet() may get called twice! view.setTag("TAGGED"); UserPreferences.setUpdateTimeOfDay(selectedHourOfDay, selectedMinute); + setUpdateIntervalText(); } }, hourOfDay, minute, DateFormat.is24HourFormat(context)); timePickerDialog.setTitle(context.getString(R.string.pref_autoUpdateIntervallOrTime_TimeOfDay)); @@ -803,6 +842,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc @Override public void onNeutral(MaterialDialog dialog) { UserPreferences.setUpdateInterval(0); + setUpdateIntervalText(); } }); builder.forceStacking(true); |