Merge branch 'headlines-compact-images-wip'
This commit is contained in:
commit
3f7b4a0da6
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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.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,6 +839,14 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
||||
holder = (HeadlineViewHolder) v.getTag();
|
||||
}
|
||||
|
||||
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() {
|
||||
@ -810,6 +857,30 @@ 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);
|
||||
|
||||
@ -827,6 +898,32 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
||||
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);
|
||||
|
||||
|
@ -292,7 +292,9 @@ 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")))
|
||||
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);
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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…
x
Reference in New Issue
Block a user