diff options
author | Andrew Dolgov <[email protected]> | 2014-10-24 14:15:26 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2014-10-24 14:15:26 +0400 |
commit | 191ce661e7f9624cbe6e088700ba56beb6bb98b6 (patch) | |
tree | aa4a66c0953d8925f5478f0d1cf16d45fe540339 /org.fox.ttrss/src | |
parent | 35acda95af6233eab6e7dfbbd7282792c1e48d8a (diff) |
Revert "initial implementation of recyclerview"
This reverts commit 7783ff3b42551dd54d2e12667a48cc633b4acc20.
Conflicts:
org.fox.ttrss/src/main/res/layout/headlines_fragment.xml
Diffstat (limited to 'org.fox.ttrss/src')
5 files changed, 120 insertions, 295 deletions
diff --git a/org.fox.ttrss/src/main/AndroidManifest.xml b/org.fox.ttrss/src/main/AndroidManifest.xml index dfa5f247..939326af 100644 --- a/org.fox.ttrss/src/main/AndroidManifest.xml +++ b/org.fox.ttrss/src/main/AndroidManifest.xml @@ -37,8 +37,6 @@ android:name=".FeedsActivity" android:label="@string/app_name" android:uiOptions="splitActionBarWhenNarrow" > - <meta-data android:name="android.support.UI_OPTIONS" - android:value="splitActionBarWhenNarrow" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> </intent-filter> @@ -47,8 +45,6 @@ android:name=".HeadlinesActivity" android:label="@string/app_name" android:uiOptions="splitActionBarWhenNarrow" > - <meta-data android:name="android.support.UI_OPTIONS" - android:value="splitActionBarWhenNarrow" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> </intent-filter> @@ -72,17 +68,11 @@ android:name=".offline.OfflineFeedsActivity" android:label="@string/app_name" android:uiOptions="splitActionBarWhenNarrow" > - <meta-data android:name="android.support.UI_OPTIONS" - android:value="splitActionBarWhenNarrow" /> - </activity> <activity android:name=".offline.OfflineHeadlinesActivity" android:label="@string/app_name" android:uiOptions="splitActionBarWhenNarrow" > - <meta-data android:name="android.support.UI_OPTIONS" - android:value="splitActionBarWhenNarrow" /> - </activity> <activity android:name=".share.ShareActivity" diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java index d0e6db40..c14a55ec 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java @@ -13,7 +13,6 @@ import org.fox.ttrss.types.Article; import org.fox.ttrss.types.ArticleList; import org.fox.ttrss.types.Feed; import org.fox.ttrss.util.HeadlinesRequest; -import org.fox.ttrss.util.RecyclerArrayAdapter; import org.fox.ttrss.util.TypefaceCache; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -34,8 +33,6 @@ import android.preference.PreferenceManager; import android.provider.OpenableColumns; import android.support.v4.app.Fragment; import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; import android.text.Html; import android.util.DisplayMetrics; import android.util.Log; @@ -64,7 +61,7 @@ import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; -public class HeadlinesFragment extends Fragment { +public class HeadlinesFragment extends Fragment implements OnItemClickListener, OnScrollListener { public static enum ArticlesSelection { ALL, NONE, UNREAD }; public static final int HEADLINES_REQUEST_SIZE = 30; @@ -317,59 +314,34 @@ public class HeadlinesFragment extends Fragment { } - final RecyclerView list = (RecyclerView)view.findViewById(R.id.headlines); - - m_adapter = new ArticleListAdapter(m_articles); - - list.setLayoutManager(new LinearLayoutManager(getActivity())); + ListView list = (ListView)view.findViewById(R.id.headlines); + m_adapter = new ArticleListAdapter(getActivity(), R.layout.headlines_row, (ArrayList<Article>)m_articles); + + /* if (!m_activity.isCompatMode()) { + AnimationSet set = new AnimationSet(true); + + Animation animation = new AlphaAnimation(0.0f, 1.0f); + animation.setDuration(500); + set.addAnimation(animation); + + animation = new TranslateAnimation( + Animation.RELATIVE_TO_SELF, 50.0f,Animation.RELATIVE_TO_SELF, 0.0f, + Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f + ); + animation.setDuration(1000); + set.addAnimation(animation); + + LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f); + + list.setLayoutAnimation(controller); + } */ + list.setAdapter(m_adapter); + list.setOnItemClickListener(this); + list.setOnScrollListener(this); + //list.setEmptyView(view.findViewById(R.id.no_headlines)); registerForContextMenu(list); - - list.setOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrollStateChanged(RecyclerView recyclerView, int newState) { - super.onScrollStateChanged(recyclerView, newState); - - if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE && m_prefs.getBoolean("headlines_mark_read_scroll", false)) { - Log.d(TAG, "scroll ended!"); - - if (!m_readArticles.isEmpty()) { - m_activity.toggleArticlesUnread(m_readArticles); - m_activity.refresh(false); - m_readArticles.clear(); - } - } - - } - - @Override - public void onScrolled(RecyclerView recyclerView, int dx, int dy) { - super.onScrolled(recyclerView, dx, dy); - - LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); - - int firstVisibleItem = layoutManager.findFirstVisibleItemPosition(); - int visibleItemCount = layoutManager.findLastCompletelyVisibleItemPosition() - layoutManager.findFirstVisibleItemPosition() + 1; - - Log.d(TAG, "fvI= " + firstVisibleItem + " vIC=" + visibleItemCount); - - if (!m_refreshInProgress && m_articles.findById(-1) != null && firstVisibleItem + visibleItemCount == m_articles.size()) { - refresh(true); - } - - if (m_prefs.getBoolean("headlines_mark_read_scroll", false) && firstVisibleItem > 0 && !m_autoCatchupDisabled) { - Article a = m_articles.get(firstVisibleItem - 1); - - if (a != null && a.unread) { - a.unread = false; - m_readArticles.add(a); - m_feed.unread--; - } - } - - } - }); - + //m_activity.m_pullToRefreshAttacher.addRefreshableView(list, this); //if (m_activity.isSmallScreen()) @@ -413,7 +385,7 @@ public class HeadlinesFragment extends Fragment { m_listener = (HeadlinesEventListener) activity; } - /* @Override + @Override public void onItemClick(AdapterView<?> av, View view, int position, long id) { ListView list = (ListView)av; @@ -432,7 +404,7 @@ public class HeadlinesFragment extends Fragment { m_adapter.notifyDataSetChanged(); } } - } */ + } public void refresh(boolean append) { refresh(append, false); @@ -454,11 +426,11 @@ public class HeadlinesFragment extends Fragment { if (!append) { if (getView() != null) { Log.d(TAG, "scroll hack"); - RecyclerView list = (RecyclerView) getView().findViewById(R.id.headlines); + ListView list = (ListView)getView().findViewById(R.id.headlines); m_autoCatchupDisabled = true; - //list.setSelection(0); + list.setSelection(0); m_autoCatchupDisabled = false; - //list.setEmptyView(null); + list.setEmptyView(null); m_adapter.clear(); m_adapter.notifyDataSetChanged(); } @@ -478,13 +450,13 @@ public class HeadlinesFragment extends Fragment { protected void onPostExecute(JsonElement result) { if (isDetached()) return; - /* if (getView() != null) { + if (getView() != null) { ListView list = (ListView)getView().findViewById(R.id.headlines); if (list != null) { list.setEmptyView(getView().findViewById(R.id.no_headlines)); } - } */ + } m_activity.setProgressBarVisibility(false); @@ -679,8 +651,23 @@ public class HeadlinesFragment extends Fragment { } } */ - private class ArticleListAdapter extends RecyclerArrayAdapter<Article, RecyclerView.ViewHolder> { - //private ArrayList<Article> items; + static class HeadlineViewHolder { + public TextView titleView; + public TextView feedTitleView; + public ImageView markedView; + public ImageView publishedView; + public TextView excerptView; + public ImageView flavorImageView; + public TextView authorView; + public TextView dateView; + public CheckBox selectionBoxView; + public ImageView menuButtonView; + public ViewGroup flavorImageHolder; + + } + + private class ArticleListAdapter extends ArrayAdapter<Article> { + private ArrayList<Article> items; public static final int VIEW_NORMAL = 0; public static final int VIEW_UNREAD = 1; @@ -693,7 +680,7 @@ public class HeadlinesFragment extends Fragment { private final Integer[] origTitleColors = new Integer[VIEW_COUNT]; private final int titleHighScoreUnreadColor; - /* public ArticleListAdapter(Context context, int textViewResourceId, ArrayList<Article> items) { + public ArticleListAdapter(Context context, int textViewResourceId, ArrayList<Article> items) { super(context, textViewResourceId, items); this.items = items; @@ -701,106 +688,15 @@ public class HeadlinesFragment extends Fragment { TypedValue tv = new TypedValue(); theme.resolveAttribute(R.attr.headlineTitleHighScoreUnreadTextColor, tv, true); titleHighScoreUnreadColor = tv.data; - } */ - - public class HeadlineViewHolder extends RecyclerView.ViewHolder { - public TextView titleView; - public TextView feedTitleView; - public ImageView markedView; - public ImageView publishedView; - public TextView excerptView; - public ImageView flavorImageView; - public TextView authorView; - public TextView dateView; - public CheckBox selectionBoxView; - public ImageView menuButtonView; - public ViewGroup flavorImageHolder; - public View headlineView; - - public HeadlineViewHolder(View v) { - super(v); - - titleView = (TextView)v.findViewById(R.id.title); - feedTitleView = (TextView)v.findViewById(R.id.feed_title); - markedView = (ImageView)v.findViewById(R.id.marked); - publishedView = (ImageView)v.findViewById(R.id.published); - excerptView = (TextView)v.findViewById(R.id.excerpt); - flavorImageView = (ImageView) v.findViewById(R.id.flavor_image); - authorView = (TextView)v.findViewById(R.id.author); - dateView = (TextView) v.findViewById(R.id.date); - selectionBoxView = (CheckBox) v.findViewById(R.id.selected); - menuButtonView = (ImageView) v.findViewById(R.id.article_menu_button); - flavorImageHolder = (ViewGroup) v.findViewById(R.id.flavorImageHolder); - headlineView = v; - } - } - - - // Create new views (invoked by the layout manager) - @Override - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, - int viewType) { - /* // create a new view - View v = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.my_text_view, parent, false); - // set the view's size, margins, paddings and layout parameters - ... - ViewHolder vh = new ViewHolder(v); - return vh; */ - - int layoutId = R.layout.headlines_row; - - switch (viewType) { - case VIEW_LOADMORE: - layoutId = R.layout.headlines_row_loadmore; - break; - case VIEW_UNREAD: - layoutId = R.layout.headlines_row_unread; - break; - case VIEW_SELECTED: - layoutId = R.layout.headlines_row_selected; - break; - case VIEW_SELECTED_UNREAD: - layoutId = R.layout.headlines_row_selected_unread; - break; - } - - View v = LayoutInflater.from(parent.getContext()) - .inflate(layoutId, parent, false); - - ((ViewGroup)v).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); - - HeadlineViewHolder vh = new HeadlineViewHolder(v); - - return vh; - } - - /* @Override - public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { - HeadlineViewHolder avh = (HeadlineViewHolder) holder; - - // - get element from your dataset at this position - // - replace the contents of the view with that element - //holder.mTextView.setText(mDataset[position]); - - } */ - - public ArticleListAdapter(ArrayList<Article> items) { - super(items); - - Theme theme = getActivity().getTheme(); - TypedValue tv = new TypedValue(); - theme.resolveAttribute(R.attr.headlineTitleHighScoreUnreadTextColor, tv, true); - titleHighScoreUnreadColor = tv.data; - } - + } + public int getViewTypeCount() { return VIEW_COUNT; } @Override public int getItemViewType(int position) { - Article a = m_items.get(position); + Article a = items.get(position); if (a.id == -1) { return VIEW_LOADMORE; @@ -815,32 +711,61 @@ public class HeadlinesFragment extends Fragment { } } + @Override + public View getView(int position, View convertView, ViewGroup parent) { - @Override - public void onBindViewHolder(RecyclerView.ViewHolder h, final int position) { - HeadlineViewHolder holder = (HeadlineViewHolder) h; - final Article article = m_items.get(position); - + View v = convertView; + + final Article article = items.get(position); + HeadlineViewHolder holder; + int headlineFontSize = Integer.parseInt(m_prefs.getString("headlines_font_size_sp", "13")); int headlineSmallFontSize = Math.max(10, Math.min(18, headlineFontSize - 2)); - - holder.headlineView.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - if (article.id >= 0) { - m_listener.onArticleSelected(article); - - // only set active article when it makes sense (in HeadlinesActivity) - if (getActivity().findViewById(R.id.article_fragment) != null) { - m_activeArticle = article; - } - - m_adapter.notifyDataSetChanged(); - } - } - }); - - if (holder.titleView != null) { + + if (v == null) { + int layoutId = R.layout.headlines_row; + + switch (getItemViewType(position)) { + case VIEW_LOADMORE: + layoutId = R.layout.headlines_row_loadmore; + break; + case VIEW_UNREAD: + layoutId = R.layout.headlines_row_unread; + break; + case VIEW_SELECTED: + layoutId = R.layout.headlines_row_selected; + break; + case VIEW_SELECTED_UNREAD: + layoutId = R.layout.headlines_row_selected_unread; + break; + } + + LayoutInflater vi = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + v = vi.inflate(layoutId, null); + + holder = new HeadlineViewHolder(); + holder.titleView = (TextView)v.findViewById(R.id.title); + + holder.feedTitleView = (TextView)v.findViewById(R.id.feed_title); + holder.markedView = (ImageView)v.findViewById(R.id.marked); + holder.publishedView = (ImageView)v.findViewById(R.id.published); + holder.excerptView = (TextView)v.findViewById(R.id.excerpt); + holder.flavorImageView = (ImageView) v.findViewById(R.id.flavor_image); + holder.authorView = (TextView)v.findViewById(R.id.author); + holder.dateView = (TextView) v.findViewById(R.id.date); + holder.selectionBoxView = (CheckBox) v.findViewById(R.id.selected); + holder.menuButtonView = (ImageView) v.findViewById(R.id.article_menu_button); + holder.flavorImageHolder = (ViewGroup) v.findViewById(R.id.flavorImageHolder); + + v.setTag(holder); + + // http://code.google.com/p/android/issues/detail?id=3414 + ((ViewGroup)v).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); + } else { + holder = (HeadlineViewHolder) v.getTag(); + } + + if (holder.titleView != null) { holder.titleView.setText(Html.fromHtml(article.title)); if (m_prefs.getBoolean("enable_condensed_fonts", false)) { @@ -1057,6 +982,8 @@ public class HeadlinesFragment extends Fragment { } }); } + + return v; } private void adjustTitleTextView(int score, TextView tv, int position) { @@ -1140,7 +1067,7 @@ public class HeadlinesFragment extends Fragment { return tmp; } - /* @Override + @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (!m_refreshInProgress && m_articles.findById(-1) != null && firstVisibleItem + visibleItemCount == m_articles.size()) { refresh(true); @@ -1166,7 +1093,7 @@ public class HeadlinesFragment extends Fragment { m_readArticles.clear(); } } - } */ + } public Article getActiveArticle() { return m_activeArticle; diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java index 10cc1c9a..c1adef52 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java @@ -152,11 +152,11 @@ public class OnlineActivity extends CommonActivity { setAppTheme(m_prefs); - if (canUseProgress()) { - requestWindowFeature(Window.FEATURE_PROGRESS); - } + super.onCreate(savedInstanceState); - super.onCreate(savedInstanceState); + if (canUseProgress()) { + requestWindowFeature(Window.FEATURE_PROGRESS); + } //requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/util/RecyclerArrayAdapter.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/util/RecyclerArrayAdapter.java deleted file mode 100644 index 2f6fdd82..00000000 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/util/RecyclerArrayAdapter.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.fox.ttrss.util; - -import android.support.v7.widget.RecyclerView; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -/** - * Created by pascalwelsch on 04.07.14. - */ -public abstract class RecyclerArrayAdapter<T, VH extends RecyclerView.ViewHolder> - extends RecyclerView.Adapter<VH> { - - protected List<T> m_items; - - public RecyclerArrayAdapter(final List<T> objects) { - m_items = objects; - } - - /** - * Adds the specified object at the end of the array. - * - * @param object The object to add at the end of the array. - */ - public void add(final T object) { - m_items.add(object); - notifyItemInserted(getItemCount() - 1); - } - - /** - * Remove all elements from the list. - */ - public void clear() { - final int size = getItemCount(); - m_items.clear(); - notifyItemRangeRemoved(0, size); - } - - @Override - public int getItemCount() { - return m_items.size(); - } - - public T getItem(final int position) { - return m_items.get(position); - } - - public long getItemId(final int position) { - return position; - } - - /** - * Returns the position of the specified item in the array. - * - * @param item The item to retrieve the position of. - * @return The position of the specified item. - */ - public int getPosition(final T item) { - return m_items.indexOf(item); - } - - /** - * Inserts the specified object at the specified index in the array. - * - * @param object The object to insert into the array. - * @param index The index at which the object must be inserted. - */ - public void insert(final T object, int index) { - m_items.add(index, object); - notifyItemInserted(index); - - } - - /** - * Removes the specified object from the array. - * - * @param object The object to remove. - */ - public void remove(T object) { - final int position = getPosition(object); - m_items.remove(object); - notifyItemRemoved(position); - } - - /** - * Sorts the content of this adapter using the specified comparator. - * - * @param comparator The comparator used to sort the objects contained in this adapter. - */ - public void sort(Comparator<? super T> comparator) { - Collections.sort(m_items, comparator); - notifyItemRangeChanged(0, getItemCount()); - } -}
\ No newline at end of file diff --git a/org.fox.ttrss/src/main/res/layout/headlines_fragment.xml b/org.fox.ttrss/src/main/res/layout/headlines_fragment.xml index df44f739..63f7f856 100644 --- a/org.fox.ttrss/src/main/res/layout/headlines_fragment.xml +++ b/org.fox.ttrss/src/main/res/layout/headlines_fragment.xml @@ -9,13 +9,15 @@ android:layout_width="match_parent" android:layout_height="match_parent" > - <android.support.v7.widget.RecyclerView + <ListView android:id="@+id/headlines" - android:scrollbars="vertical" android:layout_width="match_parent" + android:layoutAnimation="@anim/layout_headline" + android:dividerHeight="0dp" + android:divider="@null" android:paddingTop="3dp" android:layout_height="match_parent" > - </android.support.v7.widget.RecyclerView> + </ListView> </android.support.v4.widget.SwipeRefreshLayout> <LinearLayout |