diff options
author | Andrew Dolgov <[email protected]> | 2015-07-08 18:06:19 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2015-07-08 18:06:19 +0300 |
commit | 3f7b4a0da6e80d9574529666e695e99f3abf558f (patch) | |
tree | 43e9a14a0c5d7b9f7185b2510b6cda79960cd5d9 /org.fox.ttrss/src | |
parent | 63671190194fb97d3203d87a34c2324dc209cd91 (diff) | |
parent | 49a4128833e2430033ed1ec96813cd27ffacc7ec (diff) |
Merge branch 'headlines-compact-images-wip'
Diffstat (limited to 'org.fox.ttrss/src')
8 files changed, 130 insertions, 49 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java index 326b88f6..c2fe90a1 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java @@ -7,6 +7,7 @@ import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v7.app.ActionBarActivity; +import android.util.DisplayMetrics; import android.util.Log; import android.view.Display; import android.widget.Toast; @@ -170,5 +171,6 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc m_needRestart = Arrays.asList(filter).indexOf(key) != -1; } + } 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 2b031d3c..8f6f583f 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java @@ -7,6 +7,7 @@ import android.content.SharedPreferences; import android.content.res.Resources.Theme; import android.graphics.Bitmap; import android.graphics.Paint; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -52,6 +53,7 @@ import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; +import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer; import com.nostra13.universalimageloader.core.imageaware.ImageAware; import com.nostra13.universalimageloader.core.imageaware.ImageViewAware; import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; @@ -341,7 +343,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, m_compactLayoutMode = savedInstanceState.getBoolean("compactLayoutMode"); } - if ("HL_COMPACT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT"))) + String headlineMode = m_prefs.getString("headline_mode", "HL_DEFAULT"); + + if ("HL_COMPACT".equals(headlineMode) || "HL_COMPACT_NOIMAGES".equals(headlineMode)) m_compactLayoutMode = true; DisplayMetrics metrics = new DisplayMetrics(); @@ -680,11 +684,15 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, private ColorGenerator m_colorGenerator = ColorGenerator.DEFAULT; private TextDrawable.IBuilder m_drawableBuilder = TextDrawable.builder().round(); private final DisplayImageOptions displayImageOptions; + boolean showFlavorImage; public ArticleListAdapter(Context context, int textViewResourceId, ArrayList<Article> items) { super(context, textViewResourceId, items); this.items = items; + String headlineMode = m_prefs.getString("headline_mode", "HL_DEFAULT"); + showFlavorImage = "HL_DEFAULT".equals(headlineMode) || "HL_COMPACT".equals(headlineMode); + Theme theme = context.getTheme(); TypedValue tv = new TypedValue(); theme.resolveAttribute(R.attr.headlineTitleHighScoreUnreadTextColor, tv, true); @@ -696,6 +704,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, .cacheOnDisk(true) .displayer(new FadeInBitmapDisplayer(500)) .build(); + } public int getViewTypeCount() { @@ -725,14 +734,44 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, } private void updateTextCheckedState(HeadlineViewHolder holder, Article item) { - String tmp = item.title.length() > 0 ? item.title.substring(0, 1) : "?"; + String tmp = item.title.length() > 0 ? item.title.substring(0, 1).toUpperCase() : "?"; if (item.selected) { - holder.textImage.setImageDrawable(m_drawableBuilder.build(" ", 0xff616161)); + holder.textImage.setImageDrawable(m_drawableBuilder.build(" ", 0xff616161)); + holder.textImage.setTag(null); holder.textChecked.setVisibility(View.VISIBLE); } else { - holder.textImage.setImageDrawable(m_drawableBuilder.build(tmp, m_colorGenerator.getColor(item.title))); + Drawable textDrawable = m_drawableBuilder.build(tmp, m_colorGenerator.getColor(item.title)); + + if (item.flavorImage == null) { + holder.textImage.setImageDrawable(textDrawable); + holder.textImage.setTag(null); + } else { + String imgSrc = item.flavorImage.attr("src"); + + // retarded schema-less urls + if (imgSrc.indexOf("//") == 0) + imgSrc = "http:" + imgSrc; + + if (!imgSrc.equals(holder.textImage.getTag())) { + ImageAware imageAware = new ImageViewAware(holder.textImage, false); + + DisplayImageOptions options = new DisplayImageOptions.Builder() + .cacheInMemory(true) + .resetViewBeforeLoading(true) + .cacheOnDisk(true) + .showImageOnLoading(textDrawable) + .showImageOnFail(textDrawable) + .showImageForEmptyUri(textDrawable) + .displayer(new RoundedBitmapDisplayer(100)) + .build(); + + + m_imageLoader.displayImage(imgSrc, imageAware, options); + holder.textImage.setTag(imgSrc); + } + } holder.textChecked.setVisibility(View.GONE); } @@ -800,7 +839,15 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, holder = (HeadlineViewHolder) v.getTag(); } - // block footer clicks to make button/selection clicking easier + String articleContent = article.content != null ? article.content : ""; + + String articleContentReduced = articleContent.length() > CommonActivity.EXCERPT_MAX_QUERY_LENGTH ? + articleContent.substring(0, CommonActivity.EXCERPT_MAX_QUERY_LENGTH) : articleContent; + + if (article.articleDoc == null) + article.articleDoc = Jsoup.parse(articleContentReduced); + + // block footer clicks to make button/selection clicking easier if (holder.headlineFooter != null) { holder.headlineFooter.setOnClickListener(new OnClickListener() { @Override @@ -810,23 +857,73 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, }); } + if (showFlavorImage && article.flavorImage == null) { + + Elements imgs = article.articleDoc.select("img"); + + for (Element tmp : imgs) { + try { + if (tmp.attr("src") != null && tmp.attr("src").indexOf("data:") == 0) { + continue; + } + + if (Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_WIDTH && Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_HEIGHT) { + article.flavorImage = tmp; + break; + } + + } catch (NumberFormatException e) { + // + } + } + + if (article.flavorImage == null) + article.flavorImage = imgs.first(); + } + if (holder.textImage != null) { updateTextCheckedState(holder, article); - holder.textImage.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - Log.d(TAG, "textImage : onclicked"); + holder.textImage.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + Log.d(TAG, "textImage : onclicked"); - article.selected = !article.selected; + article.selected = !article.selected; - updateTextCheckedState(holder, article); + updateTextCheckedState(holder, article); - m_listener.onArticleListSelectionChange(getSelectedArticles()); + m_listener.onArticleListSelectionChange(getSelectedArticles()); - Log.d(TAG, "num selected: " + getSelectedArticles().size()); - } - }); + Log.d(TAG, "num selected: " + getSelectedArticles().size()); + } + }); + ViewCompat.setTransitionName(holder.textImage, "TRANSITION:ARTICLE_IMAGES_PAGER"); + + if (article.flavorImage != null) { + final String imgSrcFirst = article.flavorImage.attr("src"); + + holder.textImage.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + + Intent intent = new Intent(m_activity, ArticleImagesPagerActivity.class); + intent.putExtra("firstSrc", imgSrcFirst); + intent.putExtra("title", article.title); + intent.putExtra("content", article.content); + + ActivityOptionsCompat options = + ActivityOptionsCompat.makeSceneTransitionAnimation(m_activity, + holder.textImage, // The view which starts the transition + "TRANSITION:ARTICLE_IMAGES_PAGER" // The transitionName of the view we’re transitioning to + ); + ActivityCompat.startActivity(m_activity, intent, options.toBundle()); + + return true; + } + }); + + } } @@ -898,14 +995,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, }); } - String articleContent = article.content != null ? article.content : ""; - - String articleContentReduced = articleContent.length() > CommonActivity.EXCERPT_MAX_QUERY_LENGTH ? - articleContent.substring(0, CommonActivity.EXCERPT_MAX_QUERY_LENGTH) : articleContent; - - if (article.articleDoc == null) - article.articleDoc = Jsoup.parse(articleContentReduced); - if (holder.excerptView != null) { if (!m_prefs.getBoolean("headlines_show_content", true)) { holder.excerptView.setVisibility(View.GONE); @@ -930,7 +1019,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, } if (!m_compactLayoutMode) { - boolean showFlavorImage = "HL_DEFAULT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT")); if (showFlavorImage && holder.flavorImageView != null) { holder.flavorImageArrow.setVisibility(View.GONE); @@ -939,25 +1027,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, holder.flavorImageHolder.setVisibility(View.GONE); } else if (article.articleDoc != null) { - if (article.flavorImage == null) { - - Elements imgs = article.articleDoc.select("img"); - - for (Element tmp : imgs) { - try { - if (Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_WIDTH && Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_HEIGHT) { - article.flavorImage = tmp; - break; - } - } catch (NumberFormatException e) { - // - } - } - - if (article.flavorImage == null) - article.flavorImage = imgs.first(); - } - if (article.flavorImage != null) { String imgSrc = article.flavorImage.attr("src"); final String imgSrcFirst = imgSrc; @@ -1057,7 +1126,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, String articleAuthor = article.author != null ? article.author : ""; - if (holder.authorView != null) { holder.authorView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineSmallFontSize); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineHeadlinesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineHeadlinesFragment.java index 93e8e8a3..9e12cc94 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineHeadlinesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineHeadlinesFragment.java @@ -292,8 +292,10 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis m_activity.getDatabase().execSQL("UPDATE articles SET selected = 0 "); } - if ("HL_COMPACT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT"))) - m_compactLayoutMode = true; + String headlineMode = m_prefs.getString("headline_mode", "HL_DEFAULT"); + + if ("HL_COMPACT".equals(headlineMode) || "HL_COMPACT_NOIMAGES".equals(headlineMode)) + m_compactLayoutMode = true; View view = inflater.inflate(R.layout.fragment_headlines, container, false); diff --git a/org.fox.ttrss/src/main/res/layout/headlines_row_compact.xml b/org.fox.ttrss/src/main/res/layout/headlines_row_compact.xml index 58b5ed69..8b645529 100755 --- a/org.fox.ttrss/src/main/res/layout/headlines_row_compact.xml +++ b/org.fox.ttrss/src/main/res/layout/headlines_row_compact.xml @@ -19,13 +19,15 @@ android:clickable="true" android:layout_width="48dp" android:layout_height="48dp" + android:layout_gravity="center" android:id="@+id/text_image"/> <ImageView android:layout_width="48dp" android:layout_height="48dp" android:src="@drawable/check_sm" - android:id="@+id/text_checked"/> + android:id="@+id/text_checked" + android:layout_gravity="center" /> </FrameLayout> diff --git a/org.fox.ttrss/src/main/res/layout/headlines_row_selected_compact.xml b/org.fox.ttrss/src/main/res/layout/headlines_row_selected_compact.xml index 2f766960..306f87b4 100755 --- a/org.fox.ttrss/src/main/res/layout/headlines_row_selected_compact.xml +++ b/org.fox.ttrss/src/main/res/layout/headlines_row_selected_compact.xml @@ -20,13 +20,15 @@ android:clickable="true" android:layout_width="48dp" android:layout_height="48dp" + android:layout_gravity="center" android:id="@+id/text_image"/> <ImageView android:layout_width="48dp" android:layout_height="48dp" android:src="@drawable/check_sm" - android:id="@+id/text_checked"/> + android:id="@+id/text_checked" + android:layout_gravity="center" /> </FrameLayout> diff --git a/org.fox.ttrss/src/main/res/layout/headlines_row_unread_compact.xml b/org.fox.ttrss/src/main/res/layout/headlines_row_unread_compact.xml index 68a4537b..e5539b8d 100755 --- a/org.fox.ttrss/src/main/res/layout/headlines_row_unread_compact.xml +++ b/org.fox.ttrss/src/main/res/layout/headlines_row_unread_compact.xml @@ -20,13 +20,15 @@ android:clickable="true" android:layout_width="48dp" android:layout_height="48dp" + android:layout_gravity="center" android:id="@+id/text_image"/> <ImageView android:layout_width="48dp" android:layout_height="48dp" android:src="@drawable/check_sm" - android:id="@+id/text_checked"/> + android:id="@+id/text_checked" + android:layout_gravity="center" /> </FrameLayout> diff --git a/org.fox.ttrss/src/main/res/values/arrays.xml b/org.fox.ttrss/src/main/res/values/arrays.xml index 1ac11814..aa14bd62 100644 --- a/org.fox.ttrss/src/main/res/values/arrays.xml +++ b/org.fox.ttrss/src/main/res/values/arrays.xml @@ -15,11 +15,13 @@ <item>@string/headline_display_mode_default</item> <item>@string/headline_display_mode_no_images</item> <item>@string/headline_display_mode_compact</item> + <item>@string/headline_display_mode_compact_noimages</item> </string-array> <string-array name="headline_mode_values" translatable="false"> <item>HL_DEFAULT</item> <item>HL_NOIMAGES</item> <item>HL_COMPACT</item> + <item>HL_COMPACT_NOIMAGES</item> </string-array> <string-array name="pref_offline_amounts" translatable="false"> <item>150</item> diff --git a/org.fox.ttrss/src/main/res/values/strings.xml b/org.fox.ttrss/src/main/res/values/strings.xml index 1d88f150..746451f8 100755 --- a/org.fox.ttrss/src/main/res/values/strings.xml +++ b/org.fox.ttrss/src/main/res/values/strings.xml @@ -215,6 +215,7 @@ <string name="headline_display_mode_default">Default</string> <string name="headline_display_mode_no_images">No images</string> <string name="headline_display_mode_compact">Compact</string> + <string name="headline_display_mode_compact_noimages">Compact (no images)</string> <string name="prefs_version">%1$s (%2$d)</string> <string name="prefs_version_title">Version</string> <string name="prefs_build_timestamp">%1$s</string> |