add not completely functional headline thumbnails for compact mode
This commit is contained in:
parent
d7677ec893
commit
49f820110d
@ -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,12 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
|
||||
|
||||
m_needRestart = Arrays.asList(filter).indexOf(key) != -1;
|
||||
}
|
||||
|
||||
public int dpToPx(int dp) {
|
||||
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
|
||||
int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
|
||||
return px;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
@ -341,7 +342,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 +683,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);
|
||||
@ -728,11 +735,13 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
||||
String tmp = item.title.length() > 0 ? item.title.substring(0, 1) : "?";
|
||||
|
||||
if (item.selected) {
|
||||
holder.textImage.setImageDrawable(m_drawableBuilder.build(" ", 0xff616161));
|
||||
if (item.flavorImage == null)
|
||||
holder.textImage.setImageDrawable(m_drawableBuilder.build(" ", 0xff616161));
|
||||
|
||||
holder.textChecked.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.textImage.setImageDrawable(m_drawableBuilder.build(tmp, m_colorGenerator.getColor(item.title)));
|
||||
if (item.flavorImage == null)
|
||||
holder.textImage.setImageDrawable(m_drawableBuilder.build(tmp, m_colorGenerator.getColor(item.title)));
|
||||
|
||||
holder.textChecked.setVisibility(View.GONE);
|
||||
}
|
||||
@ -800,7 +809,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 +827,64 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
||||
});
|
||||
}
|
||||
|
||||
if (showFlavorImage && 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 (holder.textImage != null) {
|
||||
updateTextCheckedState(holder, article);
|
||||
|
||||
holder.textImage.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.d(TAG, "textImage : onclicked");
|
||||
if (article.flavorImage != null) {
|
||||
String imgSrc = article.flavorImage.attr("src");
|
||||
final String imgSrcFirst = imgSrc;
|
||||
|
||||
article.selected = !article.selected;
|
||||
// retarded schema-less urls
|
||||
if (imgSrc.indexOf("//") == 0)
|
||||
imgSrc = "http:" + imgSrc;
|
||||
|
||||
updateTextCheckedState(holder, article);
|
||||
if (!imgSrc.equals(holder.textImage.getTag())) {
|
||||
ImageAware imageAware = new ImageViewAware(holder.textImage, false);
|
||||
m_imageLoader.displayImage(imgSrc, imageAware, displayImageOptions);
|
||||
holder.textImage.setTag(imgSrc);
|
||||
}
|
||||
|
||||
m_listener.onArticleListSelectionChange(getSelectedArticles());
|
||||
holder.textImage.getLayoutParams().width = m_activity.dpToPx(64);
|
||||
holder.textImage.getLayoutParams().height = m_activity.dpToPx(64);
|
||||
|
||||
Log.d(TAG, "num selected: " + getSelectedArticles().size());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
holder.textImage.getLayoutParams().width = m_activity.dpToPx(48);
|
||||
holder.textImage.getLayoutParams().height = m_activity.dpToPx(48);
|
||||
}
|
||||
|
||||
holder.textImage.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.d(TAG, "textImage : onclicked");
|
||||
|
||||
article.selected = !article.selected;
|
||||
|
||||
updateTextCheckedState(holder, article);
|
||||
|
||||
m_listener.onArticleListSelectionChange(getSelectedArticles());
|
||||
|
||||
Log.d(TAG, "num selected: " + getSelectedArticles().size());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@ -898,14 +956,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 +980,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 +988,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 +1087,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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
@ -601,6 +603,9 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
||||
if (holder.textImage != null) {
|
||||
updateTextCheckedState(holder, article);
|
||||
|
||||
holder.textImage.getLayoutParams().width = m_activity.dpToPx(48);
|
||||
holder.textImage.getLayoutParams().height = m_activity.dpToPx(48);
|
||||
|
||||
holder.textImage.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -10,22 +10,24 @@
|
||||
tools:ignore="HardcodedText" >
|
||||
|
||||
<FrameLayout
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_gravity="center_vertical|left"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:clickable="true"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
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>
|
||||
|
||||
|
@ -11,22 +11,24 @@
|
||||
tools:ignore="HardcodedText" >
|
||||
|
||||
<FrameLayout
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_gravity="center_vertical|left"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp">
|
||||
|
||||
<ImageView
|
||||
android:clickable="true"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
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>
|
||||
|
||||
|
@ -11,22 +11,24 @@
|
||||
tools:ignore="HardcodedText" >
|
||||
|
||||
<FrameLayout
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_gravity="center_vertical|left"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp">
|
||||
|
||||
<ImageView
|
||||
android:clickable="true"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
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>
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user