Performance Update

This commit is contained in:
David Development 2014-04-21 16:56:16 +02:00
parent a34806c6d7
commit cc5a5695da
19 changed files with 566 additions and 390 deletions

View file

@ -72,6 +72,7 @@
<orderEntry type="library" exported="" name="extra-abs-0.9.3" level="project" />
<orderEntry type="library" exported="" name="library-0.2.0" level="project" />
<orderEntry type="library" exported="" name="library-0.9.3" level="project" />
<orderEntry type="library" exported="" name="picasso-2.2.0" level="project" />
<orderEntry type="library" exported="" name="gson-2.2.4" level="project" />
<orderEntry type="library" exported="" name="butterknife-4.0.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-19.1.0" level="project" />

View file

@ -35,9 +35,9 @@ android {
dependencies {
compile 'com.android.support:support-v4:19.0.+'
compile 'com.jakewharton:butterknife:4.0.+'
compile 'com.squareup.picasso:picasso:2.2.0@jar'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abs:+'
// You must install or update the Google Repository through the SDK manager to use this dependency.
// The Google Repository (separate from the corresponding library) can be found in the Extras category.
// compile 'com.google.android.gms:play-services:4.2.42'

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.luhmer.owncloudnewsreader"
android:versionCode="43"
android:versionName="0.5.8" >
android:versionCode="44"
android:versionName="0.5.9" >
<uses-sdk
android:minSdkVersion="7"

View file

@ -27,7 +27,7 @@ public class DownloadImagesActivity extends Activity {
.setCancelable(true)
.setPositiveButton(getString(android.R.string.yes) ,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
AsyncTask_GetItems.StartDownloadingImages(DownloadImagesActivity.this, highestItemIdBeforeSync);
AsyncTask_GetItems.StartDownloadingImages(DownloadImagesActivity.this, highestItemIdBeforeSync, false);
DownloadImagesActivity.this.finish();
}
})

View file

@ -40,9 +40,13 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashMap;
import com.squareup.picasso.Picasso;
import java.io.File;
import java.util.ArrayList;
import butterknife.ButterKnife;
import butterknife.InjectView;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.async_tasks.FillTextForTextViewAsyncTask;
@ -51,14 +55,14 @@ import de.luhmer.owncloudnewsreader.data.AbstractItem;
import de.luhmer.owncloudnewsreader.data.ConcreteFeedItem;
import de.luhmer.owncloudnewsreader.data.FolderSubscribtionItem;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.helper.BitmapDrawableLruCache;
import de.luhmer.owncloudnewsreader.helper.FavIconHandler;
import de.luhmer.owncloudnewsreader.helper.FontHelper;
import de.luhmer.owncloudnewsreader.helper.ImageHandler;
import de.luhmer.owncloudnewsreader.interfaces.ExpListTextClicked;
public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter {
BitmapDrawableLruCache favIconCache = null;
//BitmapDrawableLruCache favIconCache = null;
private Context mContext;
private DatabaseConnection dbConn;
@ -76,18 +80,22 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
public static final String ITEMS_WITHOUT_FOLDER = "-22";
//private static final String TAG = "SubscriptionExpandableListAdapter";
LayoutInflater inflater;
private final String favIconPath;
public SubscriptionExpandableListAdapter(Context mContext, DatabaseConnection dbConn)
{
//Picasso.with(mContext).setDebugging(true);
this.favIconPath = ImageHandler.getPathFavIcons(mContext);
this.inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.mContext = mContext;
this.dbConn = dbConn;
int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
//int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
//Use 1/8 of the available memory for this memory cache
int cachSize = maxMemory / 8;
favIconCache = new BitmapDrawableLruCache(cachSize);
//int cachSize = maxMemory / 8;
//favIconCache = new BitmapDrawableLruCache(cachSize);
fHelper = new FontHelper(mContext);
@ -151,41 +159,38 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
LinearLayout view;
ChildHolder viewHolder;
ConcreteFeedItem item = (ConcreteFeedItem)getChild(groupPosition, childPosition);
final ConcreteFeedItem item = (ConcreteFeedItem)getChild(groupPosition, childPosition);
final ChildHolder viewHolder;
if (convertView == null) {
view = new LinearLayout(mContext);
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi = (LayoutInflater) mContext.getSystemService(inflater);
vi.inflate(R.layout.subscription_list_sub_item, view, true);
if(item != null)
view.setTag(item.id_database);
FontHelper fHelper = new FontHelper(mContext);
fHelper.setFontForAllChildren(view, fHelper.getFont());
viewHolder = new ChildHolder();
viewHolder.tV_HeaderText = (TextView) view.findViewById(R.id.summary);
viewHolder.tV_UnreadCount = (TextView) view.findViewById(R.id.tv_unreadCount);
viewHolder.imgView_FavIcon = (ImageView) view.findViewById(R.id.iVFavicon);
view.setTag(viewHolder);
if (convertView != null) {
viewHolder = (ChildHolder) convertView.getTag();
} else {
view = (LinearLayout) convertView;
viewHolder = (ChildHolder) convertView.getTag();
LinearLayout view = new LinearLayout(mContext);
convertView = inflater.inflate(R.layout.subscription_list_sub_item, view, true);
viewHolder = new ChildHolder(convertView, mContext);
convertView.setTag(viewHolder);
/*
if(item != null)
convertView.setTag(item.id_database);
*/
}
if(item != null)
{
String headerText = (item.header != null) ? item.header : "";
viewHolder.tV_HeaderText.setText(headerText);
boolean execludeStarredItems = (item.folder_id.equals(ALL_STARRED_ITEMS)) ? false : true;
SetUnreadCountForFeed(viewHolder.tV_UnreadCount, String.valueOf(item.id_database), execludeStarredItems);
GetFavIconForFeed(item.favIcon, viewHolder.imgView_FavIcon, String.valueOf(item.id_database));
String unreadCount = unreadCountFeeds.get((int) item.id_database);
if(unreadCount != null)
viewHolder.tV_UnreadCount.setText(unreadCount);
else {
boolean execludeStarredItems = (item.folder_id.equals(ALL_STARRED_ITEMS)) ? false : true;
SetUnreadCountForFeed(viewHolder.tV_UnreadCount, String.valueOf(item.id_database), execludeStarredItems);
}
loadFavIconForFeed(item.favIcon, viewHolder.imgView_FavIcon);
}
else
{
@ -194,13 +199,20 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
viewHolder.imgView_FavIcon.setImageDrawable(null);
}
return view;
return convertView;
}
static class ChildHolder {
public TextView tV_HeaderText;
public TextView tV_UnreadCount;
public ImageView imgView_FavIcon;
@InjectView(R.id.summary) TextView tV_HeaderText;
@InjectView(R.id.tv_unreadCount) TextView tV_UnreadCount;
@InjectView(R.id.iVFavicon) ImageView imgView_FavIcon;
public ChildHolder(View view, Context mContext) {
ButterKnife.inject(this, view);
FontHelper fHelper = new FontHelper(mContext);
fHelper.setFontForAllChildren(view, fHelper.getFont());
}
}
@Override
@ -236,30 +248,17 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
LinearLayout view;
GroupHolder viewHolder;
GroupHolder viewHolder;
final FolderSubscribtionItem group = (FolderSubscribtionItem)getGroup(groupPosition);
if (convertView == null) {
view = new LinearLayout(mContext);
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi = (LayoutInflater) mContext.getSystemService(inflater);
vi.inflate(R.layout.subscription_list_item, view, true);
fHelper.setFontForAllChildren(view, fHelper.getFont());
viewHolder = new GroupHolder();
viewHolder.imgView = (ImageView) view.findViewById(R.id.img_View_expandable_indicator);
viewHolder.txt_Summary = (TextView) view.findViewById(R.id.summary);
viewHolder.txt_UnreadCount = (TextView) view.findViewById(R.id.tV_feedsCount);
viewHolder.txt_Summary.setClickable(true);
LinearLayout view = new LinearLayout(mContext);
convertView = inflater.inflate(R.layout.subscription_list_item, view, true);
viewHolder = new GroupHolder(convertView, mContext);
view.setTag(viewHolder);
} else {
view = (LinearLayout) convertView;
viewHolder = (GroupHolder) convertView.getTag();
}
@ -297,8 +296,8 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
if(unreadCount != null)
viewHolder.txt_UnreadCount.setText(unreadCount);
//else
//SetUnreadCountForFeed(viewHolder.txt_UnreadCount, String.valueOf(group.id_database), true);
else
SetUnreadCountForFeed(viewHolder.txt_UnreadCount, String.valueOf(group.id_database), true);
skipGetUnread = true;
}
@ -326,17 +325,7 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
{
String favIconURL = urlsToFavIcons.get((int) group.id_database);
viewHolder.imgView.setImageDrawable(null);
String feedID = String.valueOf(group.id_database);
if(favIconURL != null) {
if(favIconCache != null && favIconCache.get(feedID) != null) {
viewHolder.imgView.setImageDrawable(favIconCache.get(feedID));
} else {
GetFavIconForFeed(favIconURL, viewHolder.imgView, String.valueOf(group.id_database));
}
}
loadFavIconForFeed(favIconURL, viewHolder.imgView);
}
} else {
if(String.valueOf(group.id_database).equals(ALL_STARRED_ITEMS)) {
@ -360,9 +349,26 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
}
}
return view;
return convertView;
}
private void loadFavIconForFeed(String favIconUrl, ImageView imgView) {
File cacheFile = ImageHandler.getFullPathOfCacheFileSafe(favIconUrl, favIconPath);
if(cacheFile != null && cacheFile.exists()) {
Picasso.with(mContext)
.load(cacheFile)
.placeholder(FavIconHandler.getResourceIdForRightDefaultFeedIcon(mContext))
.into(imgView, null);
} else {
Picasso.with(mContext)
.load(favIconUrl)
.placeholder(FavIconHandler.getResourceIdForRightDefaultFeedIcon(mContext))
.into(imgView, null);
}
}
Drawable ic_find_next_holo_dark;
Drawable ic_find_previous_holo_dark;
Drawable btn_rating_star_off_normal_holo_light;
@ -386,6 +392,7 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void SetUnreadCountForFeed(TextView textView, String idDatabase, boolean execludeStarredItems)
{
@ -410,31 +417,23 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
}
private void GetFavIconForFeed(String favIconURL, ImageView imgView, String feedID)
{
try
{
if(favIconURL != null)
{
if(favIconURL.trim().length() > 0)
new FavIconHandler().GetImageAsync(imgView, favIconURL, mContext, feedID, favIconCache);
else
imgView.setImageResource(FavIconHandler.getResourceIdForRightDefaultFeedIcon(mContext));
}
else
imgView.setImageResource(FavIconHandler.getResourceIdForRightDefaultFeedIcon(mContext));
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
static class GroupHolder
{
TextView txt_Summary;
TextView txt_UnreadCount;
ImageView imgView;
@InjectView(R.id.summary) TextView txt_Summary;
@InjectView(R.id.tV_feedsCount) TextView txt_UnreadCount;
@InjectView(R.id.img_View_expandable_indicator) ImageView imgView;
public GroupHolder(View view, Context mContext) {
ButterKnife.inject(this, view);
txt_Summary.setClickable(true);
FontHelper fHelper = new FontHelper(mContext);
fHelper.setFontForAllChildren(view, fHelper.getFont());
}
}

View file

@ -3,47 +3,30 @@ package de.luhmer.owncloudnewsreader;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.ContentResolver;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build.VERSION;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.v4.app.NavUtils;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuItem;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import butterknife.ButterKnife;
import butterknife.InjectView;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.reader.GoogleReaderApi.HttpHelper;
import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest;
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;

View file

@ -45,7 +45,6 @@ import com.devspark.robototextview.widget.RobotoCheckBox;
import java.util.ArrayList;
import de.luhmer.owncloudnewsreader.ListView.BlockingExpandableListView;
import de.luhmer.owncloudnewsreader.ListView.BlockingListView;
import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
import de.luhmer.owncloudnewsreader.cursor.IOnStayUnread;
@ -70,12 +69,12 @@ public class NewsReaderDetailFragment extends SherlockListFragment implements IO
protected static final String TAG = "NewsReaderDetailFragment";
//private DatabaseConnection dbConn;
//private boolean DialogShowedToMarkLastItemsAsRead = false;
//private boolean DialogShowedToMarkLastItemsAsRead = false;
/*
private NewsListCursorAdapter lvAdapter;
public NewsListCursorAdapter getLvAdapter() {
return lvAdapter;
}*/
@ -97,7 +96,7 @@ public class NewsReaderDetailFragment extends SherlockListFragment implements IO
}
String titel;
/**
* @return the titel
*/
@ -115,11 +114,11 @@ public class NewsReaderDetailFragment extends SherlockListFragment implements IO
//private static ArrayList<Integer> databaseIdsOfItems;
ArrayList<RobotoCheckBox> stayUnreadCheckboxes;
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
*/
public NewsReaderDetailFragment() {
//databaseIdsOfItems = new ArrayList<Integer>();
stayUnreadCheckboxes = new ArrayList<RobotoCheckBox>();
@ -128,23 +127,23 @@ public class NewsReaderDetailFragment extends SherlockListFragment implements IO
public void setUpdateListViewOnStartUp(boolean reloadCursorOnStartUp) {
this.reloadCursorOnStartUp = reloadCursorOnStartUp;
}
public void setActivatedPosition(int position) {
mActivatedPosition = position;
}
public void setMarginFromTop(int margin) {
marginFromTop = margin;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setRetainInstance(true);
//dbConn = new DatabaseConnection(getActivity());
if(getArguments() != null) {
if (getArguments().containsKey(NewsReaderListActivity.SUBSCRIPTION_ID)) {
idFeed = getArguments().getString(NewsReaderListActivity.SUBSCRIPTION_ID);
@ -155,13 +154,13 @@ public class NewsReaderDetailFragment extends SherlockListFragment implements IO
if (getArguments().containsKey(NewsReaderListActivity.FOLDER_ID)) {
idFolder = getArguments().getString(NewsReaderListActivity.FOLDER_ID);
}
((SherlockFragmentActivity) getActivity()).getSupportActionBar().setTitle(titel);
UpdateMenuItemsState();//Is called on Tablets and Smartphones but on Smartphones the menuItemDownloadMoreItems is null. So it will be ignored
//getListView().setLayerType(View.LAYER_TYPE_SOFTWARE, null);
//lvAdapter = null;
getActivity().getSupportLoaderManager().destroyLoader(0);
@ -172,10 +171,10 @@ public class NewsReaderDetailFragment extends SherlockListFragment implements IO
UpdateCursor();
}
}
public void UpdateMenuItemsState()
{
{
if(MenuUtilsSherlockFragmentActivity.getMenuItemDownloadMoreItems() != null)
{
if(idFolder != null) {
@ -187,45 +186,45 @@ public class NewsReaderDetailFragment extends SherlockListFragment implements IO
MenuUtilsSherlockFragmentActivity.getMenuItemDownloadMoreItems().setEnabled(false);
}
}
/* (non-Javadoc)
* @see android.support.v4.app.ListFragment#onViewCreated(android.view.View, android.os.Bundle)
*/
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
if(mPrefs.getBoolean(SettingsActivity.CB_MARK_AS_READ_WHILE_SCROLLING_STRING, false))
{
{
getListView().setOnScrollListener(new AbsListView.OnScrollListener() {
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
RobotoCheckBox lastViewedArticleCheckbox = null;
public void onScroll(final AbsListView view, final int firstVisibleItem, final int visibleItemCount, int totalItemCount) {
if(lastViewedArticleCheckbox == null)
lastViewedArticleCheckbox = getCheckBoxAtPosition(0, view);
lastViewedArticleCheckbox = getCheckBoxAtPosition(0, view);
RobotoCheckBox cb = getCheckBoxAtPosition(0, view);
if(lastViewedArticleCheckbox != cb) {
if(! (lastViewedArticleCheckbox.isChecked() && stayUnreadCheckboxes.contains(lastViewedArticleCheckbox)));
NewsListCursorAdapter.ChangeCheckBoxState(lastViewedArticleCheckbox, true, getActivity());
lastViewedArticleCheckbox = cb;
}
}
});
}
super.onViewCreated(view, savedInstanceState);
}
private RobotoCheckBox getCheckBoxAtPosition(int pos, AbsListView viewLV)
{
ListView lv = (ListView) viewLV;
@ -250,7 +249,7 @@ public class NewsReaderDetailFragment extends SherlockListFragment implements IO
public void UpdateCursor()
{
try
{
{
LoaderManager loader = getActivity().getSupportLoaderManager();
loader.initLoader(0, null, loaderCallbacks);
}
@ -270,7 +269,6 @@ public class NewsReaderDetailFragment extends SherlockListFragment implements IO
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
NewsListCursorAdapter nca = (NewsListCursorAdapter) getListAdapter();
// Block children layout for now
BlockingListView bView = ((BlockingListView) getListView());
@ -360,7 +358,7 @@ public class NewsReaderDetailFragment extends SherlockListFragment implements IO
DatabaseConnection dbConn = new DatabaseConnection(context);
return dbConn.getCurrentSelectedRssItems(getSortDirection(context));
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -369,23 +367,23 @@ public class NewsReaderDetailFragment extends SherlockListFragment implements IO
}
public static class NewsDetailCursorLoader extends SimpleCursorLoader {
String idFolder;
String idFeed;
public NewsDetailCursorLoader(Context context, String idFolder, String idFeed) {
super(context);
super(context);
this.idFolder = idFolder;
this.idFeed = idFeed;
}
@Override
@Override
public Cursor loadInBackground() {
return getRightCusor(getContext() /*, idFolder, idFeed */);
}
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {

View file

@ -28,9 +28,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.provider.Settings;
@ -508,6 +505,7 @@ public class NewsReaderListActivity extends MenuUtilsSherlockFragmentActivity im
long highestItemId = dbConn.getLowestItemIdUnread();
Intent service = new Intent(this, DownloadImagesService.class);
service.putExtra(DownloadImagesService.LAST_ITEM_ID, highestItemId);
//service.putExtra(DownloadImagesService.DOWNLOAD_FAVICONS_EXCLUSIVE, true);
startService(service);
} finally {
dbConn.closeDatabase();

View file

@ -14,7 +14,6 @@ import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;

View file

@ -26,6 +26,7 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v4.widget.CursorAdapter;
@ -37,6 +38,9 @@ import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.webkit.WebView;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
@ -47,6 +51,10 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.devspark.robototextview.widget.RobotoCheckBox;
import com.devspark.robototextview.widget.RobotoTextView;
import java.lang.ref.WeakReference;
import butterknife.ButterKnife;
import butterknife.InjectView;
import de.luhmer.owncloudnewsreader.NewsDetailFragment;
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
import de.luhmer.owncloudnewsreader.R;
@ -66,26 +74,26 @@ public class NewsListCursorAdapter extends CursorAdapter {
final int LengthBody = 300;
ForegroundColorSpan bodyForegroundColor;
IOnStayUnread onStayUnread;
PostDelayHandler pDelayHandler;
int selectedDesign = 0;
@SuppressLint("SimpleDateFormat")
@SuppressWarnings("deprecation")
public NewsListCursorAdapter(Context context, Cursor c, IOnStayUnread onStayUnread) {
super(context, c);
this.onStayUnread = onStayUnread;
pDelayHandler = new PostDelayHandler(context);
//simpleDateFormat = new SimpleDateFormat("EEE, d. MMM HH:mm:ss");
bodyForegroundColor = new ForegroundColorSpan(context.getResources().getColor(android.R.color.secondary_text_dark));
_Reader = new OwnCloud_Reader();
dbConn = new DatabaseConnection(context);
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
selectedDesign = Integer.valueOf(mPrefs.getString(SettingsActivity.SP_FEED_LIST_LAYOUT, "0"));
}
@ -93,27 +101,27 @@ public class NewsListCursorAdapter extends CursorAdapter {
@Override
public void bindView(final View view, final Context context, Cursor cursor) {
final String idItemDb = cursor.getString(0);
switch (selectedDesign) {
case 0:
setSimpleLayout(view, cursor);
break;
case 1:
setExtendedLayout(view, cursor);
break;
case 2:
setExtendedLayoutWebView(view, cursor);
break;
default:
break;
}
FontHelper fHelper = new FontHelper(context);
fHelper.setFontForAllChildren(view, fHelper.getFont());
RobotoCheckBox cbStarred = (RobotoCheckBox) view.findViewById(R.id.cb_lv_item_starred);
if(ThemeChooser.isDarkTheme(mContext))
cbStarred.setBackgroundResource(R.drawable.checkbox_background_holo_dark);
@ -129,14 +137,14 @@ public class NewsListCursorAdapter extends CursorAdapter {
cbStarred.setChecked(isStarred);
cbStarred.setClickable(true);
cbStarred.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
dbConn.updateIsStarredOfItem(idItemDb, isChecked);
if(isChecked)
UpdateIsReadCheckBox(buttonView, idItemDb);
pDelayHandler.DelayTimer();
}
});
@ -163,17 +171,17 @@ public class NewsListCursorAdapter extends CursorAdapter {
fHelper.setFontStyleForSingleView(textView, fHelper.getFontUnreadStyle());
}
cbRead.setClickable(true);
cbRead.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
ChangeReadStateOfItem((RobotoCheckBox) buttonView, view, isChecked, context);
}
});
String colorString = dbConn.getAvgColourOfFeedByDbId(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_SUBSCRIPTION_ID)));
View viewColor = view.findViewById(R.id.color_line_feed);
if(colorString != null)
@ -207,58 +215,80 @@ public class NewsListCursorAdapter extends CursorAdapter {
public void setSimpleLayout(View view, Cursor cursor)
{
TextView textViewSummary = (TextView) view.findViewById(R.id.summary);
textViewSummary.setText(Html.fromHtml(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_TITLE))).toString());
SimpleLayout simpleLayout = new SimpleLayout(view);
simpleLayout.textViewSummary.setText(Html.fromHtml(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_TITLE))).toString());
TextView textViewItemDate = (TextView) view.findViewById(R.id.tv_item_date);
long pubDate = cursor.getLong(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_PUBDATE));
//textViewItemDate.setText(simpleDateFormat.format(new Date(pubDate)));
String dateString = (String) DateUtils.getRelativeTimeSpanString(pubDate);
textViewItemDate.setText(dateString);
TextView textViewTitle = (TextView) view.findViewById(R.id.tv_subscription);
textViewTitle.setText(dbConn.getTitleOfSubscriptionByRowID(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_SUBSCRIPTION_ID))));
textViewSummary.setTag(cursor.getString(0));
simpleLayout.textViewItemDate.setText(dateString);
simpleLayout.textViewTitle.setText(dbConn.getTitleOfSubscriptionByRowID(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_SUBSCRIPTION_ID))));
simpleLayout.textViewSummary.setTag(cursor.getString(0));
}
static class SimpleLayout {
@InjectView(R.id.summary) TextView textViewSummary;
@InjectView(R.id.tv_item_date) TextView textViewItemDate;
@InjectView(R.id.tv_subscription) TextView textViewTitle;
SimpleLayout(View view) {
ButterKnife.inject(this, view);
}
}
public void setExtendedLayout(View view, Cursor cursor)
{
TextView textViewSummary = (TextView) view.findViewById(R.id.summary);
textViewSummary.setText(Html.fromHtml(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_TITLE))).toString());
ExtendedLayout extendedLayout = new ExtendedLayout(view);
extendedLayout.textViewSummary.setText(Html.fromHtml(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_TITLE))).toString());
TextView textViewItemDate = (TextView) view.findViewById(R.id.tv_item_date);
long pubDate = cursor.getLong(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_PUBDATE));
//textViewItemDate.setText(simpleDateFormat.format(new Date(pubDate)));
String dateString = (String) DateUtils.getRelativeTimeSpanString(pubDate);
textViewItemDate.setText(dateString);
extendedLayout.textViewItemDate.setText(dateString);
TextView textViewItemBody = (TextView) view.findViewById(R.id.body);
String body = cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_BODY));
textViewItemBody.setText(getBodyText(body));
extendedLayout.textViewItemBody.setVisibility(View.INVISIBLE);
String idItemDb = cursor.getString(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
// Execute in parallel
new DescriptionTextLoaderTask(extendedLayout.textViewItemBody, idItemDb).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ((Void) null));
else
new DescriptionTextLoaderTask(extendedLayout.textViewItemBody, idItemDb).execute((Void) null);
TextView textViewTitle = (TextView) view.findViewById(R.id.tv_subscription);
textViewTitle.setText(dbConn.getTitleOfSubscriptionByRowID(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_SUBSCRIPTION_ID))));
textViewSummary.setTag(cursor.getString(0));
extendedLayout.textViewTitle.setText(dbConn.getTitleOfSubscriptionByRowID(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_SUBSCRIPTION_ID))));
extendedLayout.textViewSummary.setTag(cursor.getString(0));
}
static class ExtendedLayout {
@InjectView(R.id.summary) TextView textViewSummary;
@InjectView(R.id.tv_item_date) TextView textViewItemDate;
@InjectView(R.id.body) TextView textViewItemBody;
@InjectView(R.id.tv_subscription) TextView textViewTitle;
ExtendedLayout(View view) {
ButterKnife.inject(this, view);
}
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void setExtendedLayoutWebView(View view, Cursor cursor)
{
{
WebView webViewContent = (WebView) view.findViewById(R.id.webView_body);
webViewContent.setClickable(false);
webViewContent.setFocusable(false);
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
// webViewContent.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
webViewContent.loadDataWithBaseURL("", NewsDetailFragment.getHtmlPage(mContext, dbConn , cursor.getInt(0)), "text/html", "UTF-8", "");
}
public void CloseDatabaseConnection()
{
if(dbConn != null)
dbConn.closeDatabase();
}
private void UpdateIsReadCheckBox(View view, String idItemDb)
{
LinearLayout lLayout = (LinearLayout) view.getParent();
@ -270,13 +300,13 @@ public class NewsListCursorAdapter extends CursorAdapter {
}
cbRead.setChecked(isChecked);
}
public static void ChangeCheckBoxState(RobotoCheckBox cb, boolean state, Context context)
{
if(cb != null && cb.isChecked() != state)
cb.setChecked(state);
}
public static void UpdateListCursor(Context context)
{
SherlockFragmentActivity sfa = (SherlockFragmentActivity) context;
@ -284,7 +314,7 @@ public class NewsListCursorAdapter extends CursorAdapter {
if(sfa instanceof NewsReaderListActivity && ((NewsReaderListActivity) sfa).isSlidingPaneOpen())
((NewsReaderListActivity) sfa).updateAdapter();
}
private String getBodyText(String body)
{
@ -292,13 +322,13 @@ public class NewsListCursorAdapter extends CursorAdapter {
// body = body.substring(0, LengthBody);
body = body.replaceAll("<img[^>]*>", "");
body = body.replaceAll("<video[^>]*>", "");
body = body.replaceAll("<video[^>]*>", "");
SpannableString bodyStringSpannable = new SpannableString(Html.fromHtml(body));
bodyStringSpannable.setSpan(bodyForegroundColor, 0, bodyStringSpannable.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
String bodyString = bodyStringSpannable.toString().trim();
if(bodyString.length() > LengthBody)
bodyString = bodyString.substring(0, LengthBody);
@ -309,9 +339,9 @@ public class NewsListCursorAdapter extends CursorAdapter {
public View newView(Context cont, Cursor cursor, ViewGroup parent) {
// when the view will be created for first time,
// we need to tell the adapters, how each item will look
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View retView = null;
switch (selectedDesign) {
case 0:
retView = inflater.inflate(R.layout.subscription_detail_list_item_simple, parent, false);
@ -321,13 +351,85 @@ public class NewsListCursorAdapter extends CursorAdapter {
break;
case 2:
retView = inflater.inflate(R.layout.subscription_detail_list_item_extended_webview, parent, false);
break;
break;
}
if(retView != null)
retView.setTag(cursor.getString(0));
return retView;
}
class DescriptionTextLoaderTask extends AsyncTask<Void, Void, String> {
private String idItemDb;
private final WeakReference<TextView> textViewWeakReference;
public DescriptionTextLoaderTask(TextView textView, String idItemDb) {
textViewWeakReference = new WeakReference<TextView>(textView);
this.idItemDb = idItemDb;
}
@Override
// Actual download method, run in the task thread
protected String doInBackground(Void... params) {
DatabaseConnection dbConn = new DatabaseConnection(mContext);
Cursor cursor = dbConn.getItemByDbID(idItemDb);
cursor.moveToFirst();
String body = cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_BODY));
String result = getBodyText(body);
cursor.close();
return result;
}
@Override
// Once the image is downloaded, associates it to the imageView
protected void onPostExecute(String text) {
if (isCancelled()) {
text = null;
}
if (textViewWeakReference != null) {
TextView textView = textViewWeakReference.get();
if (textView != null) {
textView.setText(text);
fadeInTextView(textView);
}
}
}
private void fadeInTextView(final TextView textView)
{
Animation fadeOut = new AlphaAnimation(0, 1);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setDuration(300);
fadeOut.setAnimationListener(new Animation.AnimationListener()
{
public void onAnimationEnd(Animation animation)
{
textView.setVisibility(View.VISIBLE);
}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationStart(Animation animation) {}
});
textView.startAnimation(fadeOut);
}
}
}

View file

@ -52,7 +52,7 @@ public class DatabaseConnection {
}
public SparseArray<String> getUnreadItemCountForFeed() {
String buildSQL = "SELECT " + RSS_ITEM_SUBSCRIPTION_ID + ", COUNT(" + RSS_ITEM_RSSITEM_ID + ")" +
String buildSQL = "SELECT " + RSS_ITEM_SUBSCRIPTION_ID + ", COUNT(" + RSS_ITEM_RSSITEM_ID + ")" + // rowid as _id,
" FROM " + RSS_ITEM_TABLE +
" GROUP BY " + RSS_ITEM_SUBSCRIPTION_ID;
@ -330,7 +330,7 @@ public class DatabaseConnection {
public long getLowestItemIdStarred()
{
String buildSQL = "SELECT MIN(" + RSS_ITEM_RSSITEM_ID + ") FROM " + RSS_ITEM_TABLE + " WHERE " + RSS_ITEM_STARRED_TEMP + " == 1";
String buildSQL = "SELECT MIN(" + RSS_ITEM_RSSITEM_ID + ") FROM " + RSS_ITEM_TABLE + " WHERE " + RSS_ITEM_STARRED_TEMP + " = 1";
return getLongValueBySQL(buildSQL);
}
@ -351,6 +351,24 @@ public class DatabaseConnection {
return database.delete(RSS_ITEM_TABLE, "rowid < ?", new String[] { id_db });
}
public void removeXLatestItems(int limit, String execludeFeed) {
String sql = "DELETE FROM " + RSS_ITEM_TABLE + " WHERE rowid IN (SELECT rowid FROM " + RSS_ITEM_TABLE + " WHERE " + RSS_ITEM_READ + " != 0 " +
" AND " + RSS_ITEM_READ_TEMP + " != 0 XX ORDER BY " + RSS_ITEM_PUBDATE + " desc LIMIT " + limit + ")";
if(execludeFeed != null)
sql = sql.replace("XX", "AND " + RSS_ITEM_SUBSCRIPTION_ID +" != " + execludeFeed);
else
sql = sql.replace("XX", "");
database.execSQL(sql);
}
public void removeReadItems(int limit) {
String sql = "DELETE FROM " + RSS_ITEM_TABLE + " WHERE rowid IN (SELECT rowid FROM " + RSS_ITEM_TABLE + " WHERE " + RSS_ITEM_READ_TEMP + " = 1 " +
" AND " + RSS_ITEM_READ + " = 1 ORDER BY " + RSS_ITEM_PUBDATE + " desc LIMIT " + limit + ")";
database.execSQL(sql);
}
/*
public Cursor getAllData(String TABLE_NAME) {
String buildSQL = "SELECT rowid as _id, * FROM " + TABLE_NAME;
@ -429,6 +447,14 @@ public class DatabaseConnection {
return database.rawQuery(buildSQL, null);
}
public Cursor getItemByDbID(String ID_ITEM_DB) {//Feeds
String buildSQL = "SELECT rowid as _id, * FROM " + RSS_ITEM_TABLE + " WHERE rowid = '" + ID_ITEM_DB + "'";
if(DATABASE_DEBUG_MODE)
Log.d("DB_HELPER", "getSubSubscriptionsByID SQL: " + buildSQL);
return database.rawQuery(buildSQL, null);
}
public Cursor getFeedByDbID(String ID_FEED_DB) {//Feeds
String buildSQL = "SELECT rowid as _id, * FROM " + SUBSCRIPTION_TABLE + " WHERE rowid = '" + ID_FEED_DB + "'";

View file

@ -43,20 +43,20 @@ public class FavIconHandler {
public static Drawable GetFavIconFromCache(String URL_TO_PAGE, Context context, String feedID)
{
try
{
File favIconFile = ImageHandler.getFullPathOfCacheFile(URL_TO_PAGE, ImageHandler.getPathFavIcons(context));
{
File favIconFile = ImageHandler.getFullPathOfCacheFile(URL_TO_PAGE, ImageHandler.getPathFavIcons(context));
if(favIconFile.isFile() && favIconFile.length() > 0)
{
/*
InputStream fs = new FileInputStream(favIconFile);
BufferedInputStream is = new BufferedInputStream(fs, 32*1024);
BufferedInputStream is = new BufferedInputStream(fs, 32*1024);
Bitmap bitmap = GetScaledImage(is, 50, 50);
if(bitmap != null)
return new BitmapDrawable(context.getResources(), bitmap);
else
return null;
*/
if(feedID != null) {
DatabaseConnection dbConn = new DatabaseConnection(context);
try {
@ -69,7 +69,7 @@ public class FavIconHandler {
dbConn.closeDatabase();
}
}
return Drawable.createFromPath(favIconFile.getPath());
}
}
@ -79,16 +79,16 @@ public class FavIconHandler {
}
return null;
}
public static int getResourceIdForRightDefaultFeedIcon(Context context)
{
if(ThemeChooser.isDarkTheme(context))
return R.drawable.default_feed_icon_light;
else
return R.drawable.default_feed_icon_dark;
}
/*
private static Bitmap GetScaledImage(BufferedInputStream is, int minimumDesiredBitmapWidth, int minimumDesiredBitmapHeight)
{
@ -110,7 +110,7 @@ public class FavIconHandler {
// inSampleSize prefers multiples of 2, but we prefer to prioritize memory savings
decodeBitmapOptions.inSampleSize= Math.max(1,Math.min(originalWidth / minimumDesiredBitmapWidth, originalHeight / minimumDesiredBitmapHeight));
}
return BitmapFactory.decodeStream(is,null,decodeBitmapOptions);
} catch( IOException e ) {
@ -121,16 +121,50 @@ public class FavIconHandler {
} catch( IOException ignored ) {}
}
}*/
static SparseArray<FavIconCache> imageViewReferences = new SparseArray<FavIconCache>();
String feedID;
static SparseArray<FavIconCache> favIconToFeedId = new SparseArray<FavIconCache>();
public static void PreCacheFavIcon(String WEB_URL_TO_FILE, Context context, String feedID) {
FavIconCache favIconCache = new FavIconCache();
favIconCache.context = context;
favIconCache.WEB_URL_TO_FILE = WEB_URL_TO_FILE;
int key = Integer.parseInt(feedID);
favIconToFeedId.put(key, favIconCache);
GetImageAsyncTask giAsync = new GetImageAsyncTask(WEB_URL_TO_FILE, favIconDownloadFinished, key, ImageHandler.getPathFavIcons(context), context, null);
giAsync.scaleImage = true;
giAsync.dstHeight = 2*32;
giAsync.dstWidth = 2*32;
giAsync.feedID = feedID;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
// Execute in parallel
giAsync.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ((Void)null));
else
giAsync.execute((Void)null);
}
static ImageDownloadFinished favIconDownloadFinished = new ImageDownloadFinished() {
@Override
public void DownloadFinished(int AsynkTaskId, String fileCachePath, BitmapDrawableLruCache lruCache) {
FavIconCache favIconCache = favIconToFeedId.get(AsynkTaskId);
FavIconHandler.GetFavIconFromCache(favIconCache.WEB_URL_TO_FILE, favIconCache.context, String.valueOf(AsynkTaskId));
imageViewReferences.remove(AsynkTaskId);
}
};
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void GetImageAsync(ImageView imageView, String WEB_URL_TO_FILE, Context context, String feedID, BitmapDrawableLruCache lruCache)
{
{
this.feedID = feedID;
boolean setImageAlready = false;
if(lruCache != null) {
if(lruCache.get(feedID) != null) {
@ -146,13 +180,13 @@ public class FavIconHandler {
favIconCache.context = context;
favIconCache.WEB_URL_TO_FILE = WEB_URL_TO_FILE;
favIconCache.imageViewReference = imageViewReference;
int key = 0;
if(imageViewReferences.size() > 0)
key = imageViewReferences.keyAt(imageViewReferences.size() -1) + 1;
imageViewReferences.append(key, favIconCache);
imageView.setImageDrawable(null);
GetImageAsyncTask giAsync = new GetImageAsyncTask(WEB_URL_TO_FILE, imgDownloadFinished, key, ImageHandler.getPathFavIcons(context), context/*, imageView*/, lruCache);
giAsync.scaleImage = true;
@ -168,30 +202,30 @@ public class FavIconHandler {
giAsync.execute((Void)null);
}
}
ImageDownloadFinished imgDownloadFinished = new ImageDownloadFinished() {
@Override
public void DownloadFinished(int AsynkTaskId, String fileCachePath, BitmapDrawableLruCache lruCache) {
//WeakReference<ImageView> imageViewRef = imageViewReferences.get(AsynkTaskId);
//WeakReference<ImageView> imageViewRef = imageViewReferences.get(AsynkTaskId);
FavIconCache favIconCache = imageViewReferences.get(AsynkTaskId);
WeakReference<ImageView> imageViewRef = favIconCache.imageViewReference;
if(imageViewRef != null)
{
{
ImageView imageView = imageViewRef.get();
if (imageView != null) {
BitmapDrawable bd = (BitmapDrawable) FavIconHandler.GetFavIconFromCache(favIconCache.WEB_URL_TO_FILE, favIconCache.context, feedID);
if(lruCache != null && feedID != null && bd != null)
if(lruCache != null && feedID != null && bd != null)
lruCache.put(feedID, bd);
imageView.setImageDrawable(bd);
}
}
imageViewReferences.remove(AsynkTaskId);
imageViewReferences.remove(AsynkTaskId);
}
};
static class FavIconCache
{
public WeakReference<ImageView> imageViewReference;

View file

@ -39,9 +39,9 @@ import java.util.regex.Pattern;
public class ImageHandler {
//private static final String TAG = "DownloadImagesFromWeb";
public static Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
@ -52,19 +52,19 @@ public class ImageHandler {
return null;
}
}
public static List<File> getFilesFromDir(File dir) {
List<File> files = new ArrayList<File>();
if(dir.isDirectory())
for (File file : dir.listFiles())
for (File file : dir.listFiles())
if (file.isFile())
files.add(file);
return files;
}
public static long getFolderSize(File dir) {
long size = 0;
if(dir.isDirectory())
@ -79,18 +79,26 @@ public class ImageHandler {
}
return size;
}
public static File getFullPathOfCacheFileSafe(String WEB_URL_TO_FILE, String rootPath) {
try {
return getFullPathOfCacheFile(WEB_URL_TO_FILE, rootPath);
} catch (Exception ex) {
return null;
}
}
public static File getFullPathOfCacheFile(String WEB_URL_TO_FILE, String rootPath) throws Exception
{
URL url = new URL(WEB_URL_TO_FILE.trim());
MessageDigest m = MessageDigest.getInstance("MD5");
m.reset();
m.update(url.toString().getBytes());
byte[] digest = m.digest();
BigInteger bigInt = new BigInteger(1,digest);
String hashtext = bigInt.toString(16);
String fileEnding = "";
try
{
@ -102,22 +110,22 @@ public class ImageHandler {
fileEnding = ".png";
//ex.printStackTrace();
}
return new File(rootPath + "/" + hashtext + fileEnding);
}
public static String getPathFavIcons(Context context)
{
return getPath(context) + "/favIcons";
}
public static String getPathImageCache(Context context)
{
return getPath(context) + "/imgCache";
}
public static String getPath(Context context) {
String url;
Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
@ -132,11 +140,11 @@ public class ImageHandler {
}
else
url = context.getCacheDir().getAbsolutePath();
return url;
}
public static List<String> getImageLinksFromText(String text)
{
List<String> links = new ArrayList<String>();
@ -148,16 +156,16 @@ public class ImageHandler {
//System.out.print("Start index: " + matcher.start());
//System.out.print(" End index: " + matcher.end() + " ");
//System.out.println(matcher.group());
Matcher matcherSrcLink = patternSrcLink.matcher(matcher.group());
if(matcherSrcLink.find()) {
links.add(matcherSrcLink.group(1));
links.add(matcherSrcLink.group(1));
}
}
return links;
}
public static boolean clearCache(Context context)
{
String path = getPath(context);
@ -180,7 +188,7 @@ public class ImageHandler {
ex.printStackTrace();
}
}
// Deletes all files and subdirectories under dir.
// Returns true if all deletions were successful.
// If a deletion fails, the method stops attempting to delete and returns
@ -199,11 +207,11 @@ public class ImageHandler {
// The directory is now empty so delete it
return dir.delete();
}
/*
public static Bitmap loadBitmap(String url) {

View file

@ -26,7 +26,6 @@ import android.os.AsyncTask;
import android.os.Build;
import android.util.SparseArray;
import de.luhmer.owncloudnewsreader.async_tasks.FillTextForTextViewAsyncTask;
import de.luhmer.owncloudnewsreader.async_tasks.GetImageAsyncTask;
import de.luhmer.owncloudnewsreader.helper.BitmapDrawableLruCache;
import de.luhmer.owncloudnewsreader.helper.ImageDownloadFinished;
@ -35,32 +34,32 @@ import de.luhmer.owncloudnewsreader.helper.ImageHandler;
public class DownloadItemsToCache {
SparseArray<String> URLs;
Context context;
public DownloadItemsToCache(Context context) {
URLs = new SparseArray<String>();
this.context = context;
}
public void StartDownloadOfImage(String URL_TO_IMAGE)
{
int key = 0;
if(URLs.size() > 0)
key = URLs.keyAt(URLs.size() -1) + 1;
URLs.append(key, URL_TO_IMAGE);
GetImageAsyncTask getImageAsync = new GetImageAsyncTask(URL_TO_IMAGE, imgDownloadFinished, key, ImageHandler.getPathImageCache(context), context, null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
getImageAsync.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ((Void) null));// Execute in parallel
else
getImageAsync.execute((Void)null);
}
}
ImageDownloadFinished imgDownloadFinished = new ImageDownloadFinished() {
@Override
public void DownloadFinished(int AsynkTaskId, String fileCachePath, BitmapDrawableLruCache lruCache) {
}
}
};
}

View file

@ -31,6 +31,7 @@ import android.content.SharedPreferences;
import android.database.Cursor;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.util.SparseArray;
import java.io.File;
import java.util.ArrayList;
@ -47,31 +48,33 @@ import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.async_tasks.GetImageAsyncTask;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.helper.BitmapDrawableLruCache;
import de.luhmer.owncloudnewsreader.helper.FavIconHandler;
import de.luhmer.owncloudnewsreader.helper.ImageDownloadFinished;
import de.luhmer.owncloudnewsreader.helper.ImageHandler;
public class DownloadImagesService extends IntentService {
public static final String LAST_ITEM_ID = "LAST_ITEM_ID";
public static final String DOWNLOAD_FAVICONS_EXCLUSIVE = "DOWNLOAD_FAVICONS_EXCLUSIVE";
private static Random random;
private int NOTIFICATION_ID = 1;
private NotificationManager notificationManager;
private NotificationCompat.Builder NotificationDownloadImages;
private int count;
private int maxCount;
//private int total_size = 0;
public DownloadImagesService() {
super(null);
initService();
}
public DownloadImagesService(String name) {
super(name);
initService();
}
private void initService()
{
count = 0;
@ -100,50 +103,70 @@ public class DownloadImagesService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
String lastId = String.valueOf(intent.getLongExtra(LAST_ITEM_ID, 0));
DatabaseConnection dbConn = new DatabaseConnection(this);
Cursor cursor = dbConn.getAllItemsWithIdHigher(lastId);
List<String> links = new ArrayList<String>();
try
{
if(cursor != null)
{
while(cursor.moveToNext())
{
String body = cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_BODY));
links.addAll(ImageHandler.getImageLinksFromText(body));
}
}
} catch(Exception ex) {
ex.printStackTrace();
} finally {
cursor.close();
dbConn.closeDatabase();
}
maxCount = links.size();
Intent intentNewsReader = new Intent(this, NewsReaderListActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intentNewsReader, 0);
notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
NotificationDownloadImages = new NotificationCompat.Builder(this)
.setContentTitle("ownCloud News Reader")
.setContentText("Downloading Images for offline usage")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent);
Notification notify = NotificationDownloadImages.build();
//Hide the notification after its selected
notify.flags |= Notification.FLAG_AUTO_CANCEL;
//notify.flags |= Notification.FLAG_NO_CLEAR;
if(maxCount > 0)
notificationManager.notify(NOTIFICATION_ID, notify);
for(String link : links)
new GetImageAsyncTask(link, imgDownloadFinished, 999, ImageHandler.getPathImageCache(this), this, null).execute();
boolean downloadFavIconsExclusive = intent.getBooleanExtra(DOWNLOAD_FAVICONS_EXCLUSIVE, false);
DatabaseConnection dbConn = new DatabaseConnection(this);
Notification notify = BuildNotification();
SparseArray<String> linksFavIcons = dbConn.getUrlsToFavIcons();
if(linksFavIcons.size() > 0)
notificationManager.notify(NOTIFICATION_ID, notify);
for(int i = 0; i < linksFavIcons.size(); i++) {
int key = linksFavIcons.keyAt(i);
String link = linksFavIcons.get(i);
FavIconHandler.PreCacheFavIcon(link, this, String.valueOf(key));
}
if(!downloadFavIconsExclusive) {
String lastId = String.valueOf(intent.getLongExtra(LAST_ITEM_ID, 0));
Cursor cursor = dbConn.getAllItemsWithIdHigher(lastId);
List<String> links = new ArrayList<String>();
try {
if (cursor != null) {
while (cursor.moveToNext()) {
String body = cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_BODY));
links.addAll(ImageHandler.getImageLinksFromText(body));
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
cursor.close();
dbConn.closeDatabase();
}
maxCount = links.size();
if (maxCount > 0)
notificationManager.notify(NOTIFICATION_ID, notify);
for (String link : links)
new GetImageAsyncTask(link, imgDownloadFinished, 999, ImageHandler.getPathImageCache(this), this, null).execute();
}
}
private Notification BuildNotification() {
Intent intentNewsReader = new Intent(this, NewsReaderListActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intentNewsReader, 0);
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationDownloadImages = new NotificationCompat.Builder(this)
.setContentTitle("ownCloud News Reader")
.setContentText("Downloading Images for offline usage")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent);
Notification notify = NotificationDownloadImages.build();
//Hide the notification after its selected
notify.flags |= Notification.FLAG_AUTO_CANCEL;
//notify.flags |= Notification.FLAG_NO_CLEAR;
return notify;
}
private void RemoveOldImages(Context context) {
HashMap<File, Long> files;
long size = ImageHandler.getFolderSize(new File(ImageHandler.getPath(context)));
@ -199,9 +222,9 @@ public class DownloadImagesService extends IntentService {
}
return sortedMap;
}
ImageDownloadFinished imgDownloadFinished = new ImageDownloadFinished() {
@Override
public void DownloadFinished(int AsynkTaskId, String fileCachePath, BitmapDrawableLruCache lruCache) {
@ -222,7 +245,7 @@ public class DownloadImagesService extends IntentService {
NotificationDownloadImages.setContentText("Downloading Images for offline usage - " + count + "/" + maxCount);
// Displays the progress bar for the first time.
notificationManager.notify(NOTIFICATION_ID, NotificationDownloadImages.build());
if(maxCount == count) {
notificationManager.cancel(NOTIFICATION_ID);
if(DownloadImagesService.this != null)

View file

@ -6,22 +6,22 @@
<!--
android:background="@drawable/checkbox_background"
android:button="@drawable/checkbox"
android:button="@drawable/checkbox"
-->
<View
android:id="@+id/color_line_feed"
android:layout_width="@dimen/color_bar_of_feeds"
android:layout_height="match_parent"
android:background="@color/abs__background_holo_dark"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -29,7 +29,7 @@
android:layout_marginRight="@dimen/listview_row_margin_right"
android:layout_marginTop="@dimen/listview_row_margin_top"
android:orientation="horizontal" >
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/tv_subscription"
android:layout_width="0dp"
@ -41,7 +41,7 @@
android:text="Hdfsa"
android:layout_weight="1"
android:textSize="14sp" />
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/tv_item_date"
android:layout_width="wrap_content"
@ -52,21 +52,21 @@
android:singleLine="true"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/listview_row_margin_left"
android:layout_marginBottom="@dimen/listview_row_margin_bottom"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginRight="@dimen/listview_row_margin_right"
android:layout_weight="1" >
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/summary"
android:layout_width="match_parent"
@ -77,7 +77,7 @@
android:textSize="17sp"
android:text="Hi\nfds"
android:textStyle="bold" />
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/body"
android:layout_marginTop="5dp"
@ -85,14 +85,14 @@
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="4"
android:text="Hi\nfsddfs\nfdsfs\nfsfdsds"
android:textColor="#858585"
android:text="Test"
android:textColor="@color/extended_listview_body_text_color"
android:textSize="14sp"
android:autoLink="none" />
<!-- android:gravity="center_vertical" -->
</LinearLayout>
<LinearLayout
android:layout_width="50dp"
android:layout_height="match_parent"
@ -109,16 +109,23 @@
android:layout_gravity="center_horizontal"
android:button="@drawable/checkbox_background_empty"
android:background="@drawable/checkbox_background_holo_light" />
<com.devspark.robototextview.widget.RobotoCheckBox
android:id="@+id/cb_lv_item_read"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:layout_marginTop="-2.0dp"
android:background="@color/divider_row_color" />
</LinearLayout>
</LinearLayout>

View file

@ -3,27 +3,26 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="65dp"
android:orientation="horizontal"
android:background="@drawable/row_divider_line" >
android:layout_height="72dp"
android:orientation="horizontal" >
<View
android:id="@+id/color_line_feed"
android:layout_width="@dimen/color_bar_of_feeds"
android:layout_height="match_parent"
android:background="@color/abs__background_holo_dark"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="65dp"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/ll_cb_starred_wrapper"
@ -48,28 +47,28 @@
android:layout_marginTop="@dimen/listview_row_margin_top"
android:layout_weight="1"
android:orientation="vertical" >
<!--
android:background="@drawable/checkbox_background"
android:button="@drawable/checkbox"
android:button="@drawable/checkbox"
-->
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/summary"
android:layout_width="match_parent"
android:layout_height="0dip"
android:ellipsize="end"
android:ellipsize="end"
android:lines="2"
android:textSize="17sp"
android:text="hidsaf afdaljkök"
android:text="Test"
android:layout_weight="1"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/tv_subscription"
android:layout_width="0dp"
@ -78,10 +77,10 @@
android:gravity="center_vertical"
android:layout_gravity="left"
android:singleLine="true"
android:text="Hif dsajfdjasklfds"
android:text="Test"
android:layout_weight="1"
android:textSize="13sp" />
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/tv_item_date"
android:layout_width="wrap_content"
@ -92,25 +91,23 @@
android:text="Hi"
android:singleLine="true"
android:textSize="13sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<com.devspark.robototextview.widget.RobotoCheckBox
android:id="@+id/cb_lv_item_read"
android:layout_width="50dp"
android:layout_height="match_parent"
<com.devspark.robototextview.widget.RobotoCheckBox
android:id="@+id/cb_lv_item_read"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/listview_row_margin_left"
android:clickable="false"
android:focusable="false" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/divider_row_color" />
</LinearLayout>
android:clickable="false"
android:focusable="false" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:layout_marginTop="5.5dp"
android:background="@color/divider_row_color" />
</LinearLayout>
</LinearLayout>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="@dimen/exp_listview_row_height"
android:layout_marginLeft="10dp"
@ -8,11 +8,11 @@
<ImageView
android:id="@+id/img_View_expandable_indicator"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical|center_horizontal"
android:src="@drawable/ic_find_next_holo_dark" />
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/summary"
android:layout_width="0dp"
@ -22,20 +22,20 @@
android:singleLine="true"
android:textSize="20sp"
android:textStyle="bold"
android:layout_weight="1"
android:layout_weight="1"
android:textIsSelectable="false"
android:textColor="@color/slider_listview_text_color" />
<!--app:typeface="roboto_thin" -->
<com.devspark.robototextview.widget.RobotoTextView
android:id="@+id/tV_feedsCount"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical|right"
android:gravity="center_vertical|right"
android:singleLine="true"
android:textIsSelectable="false"
android:layout_marginRight="20dp"
android:textColor="@color/slider_listview_text_color" />
</LinearLayout>

View file

@ -2,6 +2,8 @@
<resources>
<!-- <color name="slider_listview_background_color">#525252</color> -->
<color name="slider_listview_background_color">#383d43</color>
<color name="slider_listview_text_color">#F0F0F0</color>
<color name="slider_listview_text_color">#F0F0F0</color>
<color name="divider_row_color">#292929</color>
<color name="extended_listview_body_text_color">#ff9e9e9e</color>
</resources>