Merge branch 'headlines-compact-images-wip'

This commit is contained in:
Andrew Dolgov 2015-07-08 18:06:19 +03:00
commit 3f7b4a0da6
8 changed files with 130 additions and 49 deletions

View File

@ -7,6 +7,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.Display; import android.view.Display;
import android.widget.Toast; import android.widget.Toast;
@ -170,5 +171,6 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
m_needRestart = Arrays.asList(filter).indexOf(key) != -1; m_needRestart = Arrays.asList(filter).indexOf(key) != -1;
} }
} }

View File

@ -7,6 +7,7 @@ import android.content.SharedPreferences;
import android.content.res.Resources.Theme; import android.content.res.Resources.Theme;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; 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.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; 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.ImageAware;
import com.nostra13.universalimageloader.core.imageaware.ImageViewAware; import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
@ -341,7 +343,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
m_compactLayoutMode = savedInstanceState.getBoolean("compactLayoutMode"); 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; m_compactLayoutMode = true;
DisplayMetrics metrics = new DisplayMetrics(); DisplayMetrics metrics = new DisplayMetrics();
@ -680,11 +684,15 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
private ColorGenerator m_colorGenerator = ColorGenerator.DEFAULT; private ColorGenerator m_colorGenerator = ColorGenerator.DEFAULT;
private TextDrawable.IBuilder m_drawableBuilder = TextDrawable.builder().round(); private TextDrawable.IBuilder m_drawableBuilder = TextDrawable.builder().round();
private final DisplayImageOptions displayImageOptions; private final DisplayImageOptions displayImageOptions;
boolean showFlavorImage;
public ArticleListAdapter(Context context, int textViewResourceId, ArrayList<Article> items) { public ArticleListAdapter(Context context, int textViewResourceId, ArrayList<Article> items) {
super(context, textViewResourceId, items); super(context, textViewResourceId, items);
this.items = 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(); Theme theme = context.getTheme();
TypedValue tv = new TypedValue(); TypedValue tv = new TypedValue();
theme.resolveAttribute(R.attr.headlineTitleHighScoreUnreadTextColor, tv, true); theme.resolveAttribute(R.attr.headlineTitleHighScoreUnreadTextColor, tv, true);
@ -696,6 +704,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
.cacheOnDisk(true) .cacheOnDisk(true)
.displayer(new FadeInBitmapDisplayer(500)) .displayer(new FadeInBitmapDisplayer(500))
.build(); .build();
} }
public int getViewTypeCount() { public int getViewTypeCount() {
@ -725,14 +734,44 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
private void updateTextCheckedState(HeadlineViewHolder holder, Article item) { 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) { 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); holder.textChecked.setVisibility(View.VISIBLE);
} else { } 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); holder.textChecked.setVisibility(View.GONE);
} }
@ -800,7 +839,15 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
holder = (HeadlineViewHolder) v.getTag(); 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) { if (holder.headlineFooter != null) {
holder.headlineFooter.setOnClickListener(new OnClickListener() { holder.headlineFooter.setOnClickListener(new OnClickListener() {
@Override @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) { if (holder.textImage != null) {
updateTextCheckedState(holder, article); updateTextCheckedState(holder, article);
holder.textImage.setOnClickListener(new OnClickListener() { holder.textImage.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Log.d(TAG, "textImage : onclicked"); 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 were 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 (holder.excerptView != null) {
if (!m_prefs.getBoolean("headlines_show_content", true)) { if (!m_prefs.getBoolean("headlines_show_content", true)) {
holder.excerptView.setVisibility(View.GONE); holder.excerptView.setVisibility(View.GONE);
@ -930,7 +1019,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
if (!m_compactLayoutMode) { if (!m_compactLayoutMode) {
boolean showFlavorImage = "HL_DEFAULT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT"));
if (showFlavorImage && holder.flavorImageView != null) { if (showFlavorImage && holder.flavorImageView != null) {
holder.flavorImageArrow.setVisibility(View.GONE); holder.flavorImageArrow.setVisibility(View.GONE);
@ -939,25 +1027,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
holder.flavorImageHolder.setVisibility(View.GONE); holder.flavorImageHolder.setVisibility(View.GONE);
} else if (article.articleDoc != null) { } 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) { if (article.flavorImage != null) {
String imgSrc = article.flavorImage.attr("src"); String imgSrc = article.flavorImage.attr("src");
final String imgSrcFirst = imgSrc; final String imgSrcFirst = imgSrc;
@ -1057,7 +1126,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
String articleAuthor = article.author != null ? article.author : ""; String articleAuthor = article.author != null ? article.author : "";
if (holder.authorView != null) { if (holder.authorView != null) {
holder.authorView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineSmallFontSize); holder.authorView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineSmallFontSize);

View File

@ -292,8 +292,10 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
m_activity.getDatabase().execSQL("UPDATE articles SET selected = 0 "); m_activity.getDatabase().execSQL("UPDATE articles SET selected = 0 ");
} }
if ("HL_COMPACT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT"))) String headlineMode = m_prefs.getString("headline_mode", "HL_DEFAULT");
m_compactLayoutMode = true;
if ("HL_COMPACT".equals(headlineMode) || "HL_COMPACT_NOIMAGES".equals(headlineMode))
m_compactLayoutMode = true;
View view = inflater.inflate(R.layout.fragment_headlines, container, false); View view = inflater.inflate(R.layout.fragment_headlines, container, false);

View File

@ -19,13 +19,15 @@
android:clickable="true" android:clickable="true"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_gravity="center"
android:id="@+id/text_image"/> android:id="@+id/text_image"/>
<ImageView <ImageView
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:src="@drawable/check_sm" android:src="@drawable/check_sm"
android:id="@+id/text_checked"/> android:id="@+id/text_checked"
android:layout_gravity="center" />
</FrameLayout> </FrameLayout>

View File

@ -20,13 +20,15 @@
android:clickable="true" android:clickable="true"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_gravity="center"
android:id="@+id/text_image"/> android:id="@+id/text_image"/>
<ImageView <ImageView
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:src="@drawable/check_sm" android:src="@drawable/check_sm"
android:id="@+id/text_checked"/> android:id="@+id/text_checked"
android:layout_gravity="center" />
</FrameLayout> </FrameLayout>

View File

@ -20,13 +20,15 @@
android:clickable="true" android:clickable="true"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_gravity="center"
android:id="@+id/text_image"/> android:id="@+id/text_image"/>
<ImageView <ImageView
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:src="@drawable/check_sm" android:src="@drawable/check_sm"
android:id="@+id/text_checked"/> android:id="@+id/text_checked"
android:layout_gravity="center" />
</FrameLayout> </FrameLayout>

View File

@ -15,11 +15,13 @@
<item>@string/headline_display_mode_default</item> <item>@string/headline_display_mode_default</item>
<item>@string/headline_display_mode_no_images</item> <item>@string/headline_display_mode_no_images</item>
<item>@string/headline_display_mode_compact</item> <item>@string/headline_display_mode_compact</item>
<item>@string/headline_display_mode_compact_noimages</item>
</string-array> </string-array>
<string-array name="headline_mode_values" translatable="false"> <string-array name="headline_mode_values" translatable="false">
<item>HL_DEFAULT</item> <item>HL_DEFAULT</item>
<item>HL_NOIMAGES</item> <item>HL_NOIMAGES</item>
<item>HL_COMPACT</item> <item>HL_COMPACT</item>
<item>HL_COMPACT_NOIMAGES</item>
</string-array> </string-array>
<string-array name="pref_offline_amounts" translatable="false"> <string-array name="pref_offline_amounts" translatable="false">
<item>150</item> <item>150</item>

View File

@ -215,6 +215,7 @@
<string name="headline_display_mode_default">Default</string> <string name="headline_display_mode_default">Default</string>
<string name="headline_display_mode_no_images">No images</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">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">%1$s (%2$d)</string>
<string name="prefs_version_title">Version</string> <string name="prefs_version_title">Version</string>
<string name="prefs_build_timestamp">%1$s</string> <string name="prefs_build_timestamp">%1$s</string>