Remove dead code

Remove unused class de.luhmer.owncloudnewsreader.database.DatabaseConnection
and all unused code that still reference it
This commit is contained in:
Olivier Trichet 2015-03-29 13:11:51 +02:00
parent b06ce65f89
commit a4d6284957
14 changed files with 17 additions and 2169 deletions

View file

@ -13,7 +13,6 @@ import org.robolectric.annotation.Config;
import java.util.List;
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.DatabaseHelperOrm;
import de.luhmer.owncloudnewsreader.database.model.DaoSession;

View file

@ -457,26 +457,6 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
}
/*
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void SetUnreadCountForFeed(TextView textView, String idDatabase, boolean execludeStarredItems)
{
IGetTextForTextViewAsyncTask iGetter = new UnreadFeedCount(mContext, idDatabase, execludeStarredItems);
FillTextForTextViewHelper.FillTextForTextView(textView, iGetter, !mIsTwoPane);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void SetUnreadCountForFolder(TextView textView, String idDatabase)
{
IGetTextForTextViewAsyncTask iGetter = new UnreadFolderCount(mContext, idDatabase);
FillTextForTextViewHelper.FillTextForTextView(textView, iGetter, !mIsTwoPane);
}
*/
static class GroupHolder
{
@InjectView(R.id.summary) TextView txt_Summary;

View file

@ -1,55 +0,0 @@
/**
* Android ownCloud News
*
* @author David Luhmer
* @copyright 2013 David Luhmer david-dev@live.de
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.luhmer.owncloudnewsreader.ListView;
import android.content.Context;
import de.luhmer.owncloudnewsreader.async_tasks.IGetTextForTextViewAsyncTask;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
@Deprecated
public class UnreadFeedCount implements IGetTextForTextViewAsyncTask {
Context context;
String idDatabase;
boolean execludeStarredItems;
public UnreadFeedCount(Context context, String idDatabase, boolean execludeStarredItems) {
this.context = context;
this.idDatabase = idDatabase;
this.execludeStarredItems = execludeStarredItems;
}
@Override
public String getText() {
DatabaseConnection dbConn = new DatabaseConnection(context);
int unread = 0;
try
{
unread = dbConn.getCountItemsForSubscription(idDatabase, true, execludeStarredItems);
} finally {
dbConn.closeDatabase();
}
return String.valueOf(unread);
}
}

View file

@ -1,53 +0,0 @@
/**
* Android ownCloud News
*
* @author David Luhmer
* @copyright 2013 David Luhmer david-dev@live.de
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.luhmer.owncloudnewsreader.ListView;
import android.content.Context;
import de.luhmer.owncloudnewsreader.async_tasks.IGetTextForTextViewAsyncTask;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
@Deprecated
public class UnreadFolderCount implements IGetTextForTextViewAsyncTask {
Context context;
String idDatabase;
public UnreadFolderCount(Context context, String idDatabase) {
this.context = context;
this.idDatabase = idDatabase;
}
@Override
public String getText() {
DatabaseConnection dbConn = new DatabaseConnection(context);
int unread = 0;
try
{
unread = dbConn.getCountFeedsForFolder(idDatabase, true);
} finally {
dbConn.closeDatabase();
}
return String.valueOf(unread);
}
}

View file

@ -21,7 +21,6 @@
package de.luhmer.owncloudnewsreader;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -38,7 +37,6 @@ import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
@ -47,8 +45,8 @@ import android.view.MenuItem;
import butterknife.ButterKnife;
import butterknife.InjectView;
import de.greenrobot.dao.query.LazyList;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection.SORT_DIRECTION;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm.SORT_DIRECTION;
import de.luhmer.owncloudnewsreader.database.model.RssItem;
import de.luhmer.owncloudnewsreader.helper.PostDelayHandler;
import de.luhmer.owncloudnewsreader.helper.ThemeChooser;

View file

@ -29,10 +29,8 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.ListFragment;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -53,8 +51,8 @@ import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
import de.luhmer.owncloudnewsreader.adapter.NewsListArrayAdapter;
import de.luhmer.owncloudnewsreader.cursor.IOnStayUnread;
import de.luhmer.owncloudnewsreader.cursor.NewsListCursorAdapter;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection.SORT_DIRECTION;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm.SORT_DIRECTION;
import de.luhmer.owncloudnewsreader.database.model.RssItem;
import de.luhmer.owncloudnewsreader.services.PodcastDownloadService;
@ -75,13 +73,6 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr
//private boolean DialogShowedToMarkLastItemsAsRead = false;
/*
private NewsListCursorAdapter lvAdapter;
public NewsListCursorAdapter getLvAdapter() {
return lvAdapter;
}*/
Long idFeed;
/**
* @return the idFeed
@ -293,10 +284,6 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr
NewsListArrayAdapter nca = (NewsListArrayAdapter) getListAdapter();
if(nca != null)
nca.notifyDataSetChanged();
//NewsListCursorAdapter nca = (NewsListCursorAdapter) getListAdapter();
//if(nca != null)
//((NewsListCursorAdapter) getListAdapter()).notifyDataSetChanged();
}
/**

View file

@ -27,12 +27,10 @@ import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Build;
import android.os.Bundle;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.SlidingPaneLayout;
@ -57,7 +55,6 @@ import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
import de.luhmer.owncloudnewsreader.LoginDialogFragment.LoginSuccessfullListener;
import de.luhmer.owncloudnewsreader.adapter.NewsListArrayAdapter;
import de.luhmer.owncloudnewsreader.authentication.AccountGeneral;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.DatabaseHelperOrm;
import de.luhmer.owncloudnewsreader.database.model.DaoSession;
@ -249,7 +246,7 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
/* Test 2 */
for (Folder folder : folderList) {
String query = dbConn.getAllItemsIdsForFolderSQL(folder.getId(), true, DatabaseConnection.SORT_DIRECTION.asc);
String query = dbConn.getAllItemsIdsForFolderSQL(folder.getId(), true, DatabaseConnectionOrm.SORT_DIRECTION.asc);
dbConn.insertIntoRssCurrentViewTable(query);
//Log.d(TAG, "Inserting time needed: " + (System.currentTimeMillis() - start) + " ms");

View file

@ -21,422 +21,23 @@
package de.luhmer.owncloudnewsreader.cursor;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.CursorAdapter;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.format.DateUtils;
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.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.async_tasks.IGetTextForTextViewAsyncTask;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.helper.FillTextForTextViewHelper;
import de.luhmer.owncloudnewsreader.helper.FontHelper;
import de.luhmer.owncloudnewsreader.helper.PostDelayHandler;
import de.luhmer.owncloudnewsreader.helper.ThemeChooser;
import de.luhmer.owncloudnewsreader.reader.IReader;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloud_Reader;
@Deprecated
public class NewsListCursorAdapter extends CursorAdapter {
//private static final String TAG = "NewsListCursorAdapter";
DatabaseConnection dbConn;
IReader _Reader;
//SimpleDateFormat simpleDateFormat;
final int LengthBody = 400;
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"));
}
@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());
CheckBox cbStarred = (CheckBox) view.findViewById(R.id.cb_lv_item_starred);
if(ThemeChooser.isDarkTheme(mContext))
cbStarred.setBackgroundResource(R.drawable.checkbox_background_holo_dark);
/*
//The default is white so we don't need to set it here again..
else
cbStarred.setBackgroundResource(R.drawable.checkbox_background_holo_light);*/
cbStarred.setOnCheckedChangeListener(null);
Boolean isStarred = dbConn.isFeedUnreadStarred(cursor.getString(0), false);//false => starred will be checked
//Log.d("ISSTARRED", "" + isStarred + " - Cursor: " + cursor.getString(0));
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();
}
});
LinearLayout ll_cb_starred_wrapper = (LinearLayout) view.findViewById(R.id.ll_cb_starred_wrapper);
if(ll_cb_starred_wrapper != null) {
ll_cb_starred_wrapper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CheckBox cbStarred = (CheckBox) view.findViewById(R.id.cb_lv_item_starred);
cbStarred.setChecked(!cbStarred.isChecked());
}
});
}
CheckBox cbRead = (CheckBox) view.findViewById(R.id.cb_lv_item_read);
cbRead.setTag(idItemDb);
cbRead.setOnCheckedChangeListener(null);
Boolean isChecked = dbConn.isFeedUnreadStarred(cursor.getString(0), true);
//Log.d("ISREAD", "" + isChecked + " - Cursor: " + cursor.getString(0));
cbRead.setChecked(isChecked);
if(!isChecked) {
TextView textView = (TextView) view.findViewById(R.id.summary);
fHelper.setFontStyleForSingleView(textView, fHelper.getFontUnreadStyle());
}
cbRead.setClickable(true);
cbRead.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
ChangeReadStateOfItem((CheckBox) 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)
viewColor.setBackgroundColor(Integer.parseInt(colorString));
}
public void ChangeReadStateOfItem(CheckBox checkBox, View parentView, boolean isChecked, Context context) {
dbConn.updateIsReadOfItem(checkBox.getTag().toString(), isChecked);
UpdateListCursor(mContext);
pDelayHandler.DelayTimer();
TextView textView = (TextView) parentView.findViewById(R.id.summary);
if(textView != null && parentView.getTop() >= 0)
{
FontHelper fHelper = new FontHelper(context);
if(isChecked)
fHelper.setFontStyleForSingleView(textView, fHelper.getFont());
//textView.setTextAppearance(mContext, R.style.RobotoFontStyle);
else {
fHelper.setFontStyleForSingleView(textView, fHelper.getFontUnreadStyle());
onStayUnread.stayUnread(checkBox);
}
//textView.setTextAppearance(mContext, R.style.RobotoFontStyleBold);
textView.invalidate();
}
}
public void setSimpleLayout(View view, Cursor cursor)
{
SimpleLayout simpleLayout = new SimpleLayout(view);
simpleLayout.textViewSummary.setText(Html.fromHtml(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_TITLE))).toString());
long pubDate = cursor.getLong(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_PUBDATE));
String dateString = (String) DateUtils.getRelativeTimeSpanString(pubDate);
simpleLayout.textViewItemDate.setText(dateString);
simpleLayout.textViewTitle.setText(dbConn.getTitleOfSubscriptionByRowID(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_SUBSCRIPTION_ID))));
simpleLayout.textViewSummary.setTag(cursor.getString(0));
if(!ThemeChooser.isDarkTheme(mContext)) {
simpleLayout.viewDivider.setBackgroundColor(mContext.getResources().getColor(R.color.divider_row_color_light_theme));
}
}
static class SimpleLayout {
@InjectView(R.id.divider) View viewDivider;
@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)
{
ExtendedLayout extendedLayout = new ExtendedLayout(view);
extendedLayout.textViewSummary.setText(Html.fromHtml(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_TITLE))).toString());
long pubDate = cursor.getLong(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_PUBDATE));
//textViewItemDate.setText(simpleDateFormat.format(new Date(pubDate)));
String dateString = (String) DateUtils.getRelativeTimeSpanString(pubDate);
extendedLayout.textViewItemDate.setText(dateString);
extendedLayout.textViewItemBody.setVisibility(View.INVISIBLE);
String idItemDb = cursor.getString(0);
IGetTextForTextViewAsyncTask iGetter = new DescriptionTextGetter(idItemDb);
FillTextForTextViewHelper.FillTextForTextView(extendedLayout.textViewItemBody, iGetter, true);
extendedLayout.textViewTitle.setText(dbConn.getTitleOfSubscriptionByRowID(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_SUBSCRIPTION_ID))));
extendedLayout.textViewSummary.setTag(cursor.getString(0));
if(!ThemeChooser.isDarkTheme(mContext)) {
extendedLayout.textViewItemBody.setTextColor(mContext.getResources().getColor(R.color.extended_listview_item_body_text_color_light_theme));
extendedLayout.viewDivider.setBackgroundColor(mContext.getResources().getColor(R.color.divider_row_color_light_theme));
}
}
static class ExtendedLayout {
@InjectView(R.id.divider) View viewDivider;
@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", ""); //This line is needed to run the adapter
}
public void CloseDatabaseConnection()
{
if(dbConn != null)
dbConn.closeDatabase();
}
private void UpdateIsReadCheckBox(View view, String idItemDb)
{
LinearLayout lLayout = (LinearLayout) view.getParent();
Boolean isChecked = dbConn.isFeedUnreadStarred(idItemDb, true);
CheckBox cbRead = (CheckBox) lLayout.findViewById(R.id.cb_lv_item_read);
if(cbRead == null) {//In the default layout the star checkbox is nested two times.
lLayout = (LinearLayout) lLayout.getParent();
cbRead = (CheckBox) lLayout.findViewById(R.id.cb_lv_item_read);
}
cbRead.setChecked(isChecked);
}
public class NewsListCursorAdapter
{
public static void ChangeCheckBoxState(CheckBox cb, boolean state, Context context)
{
if(cb != null && cb.isChecked() != state)
cb.setChecked(state);
}
public static void UpdateListCursor(Context context)
{
FragmentActivity sfa = (FragmentActivity) context;
if(sfa instanceof NewsReaderListActivity && ((NewsReaderListActivity) sfa).isSlidingPaneOpen())
((NewsReaderListActivity) sfa).updateAdapter();
}
private String getBodyText(String body)
{
body = body.replaceAll("<img[^>]*>", "");
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);
return bodyString;
}
@Override
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());
View retView = null;
switch (selectedDesign) {
case 0:
retView = inflater.inflate(R.layout.subscription_detail_list_item_simple, parent, false);
break;
case 1:
retView = inflater.inflate(R.layout.subscription_detail_list_item_extended, parent, false);
break;
case 2:
retView = inflater.inflate(R.layout.subscription_detail_list_item_extended_webview, parent, false);
break;
}
if(retView != null)
retView.setTag(cursor.getString(0));
return retView;
}
class DescriptionTextGetter implements IGetTextForTextViewAsyncTask {
private String idItemDb;
public DescriptionTextGetter(String idItemDb) {
this.idItemDb = idItemDb;
}
@Override
public String getText() {
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;
}
}
/*
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);
}
}
}
}
*/
public static void FadeInTextView(final TextView textView)
{
Animation fadeOut = new AlphaAnimation(0, 1);

View file

@ -49,7 +49,7 @@ public class DatabaseConnectionOrm {
public static final String[] VIDEO_FORMATS = { "youtube" };
public enum SORT_DIRECTION { asc, desc }
DaoSession daoSession;
@ -330,11 +330,11 @@ public class DatabaseConnectionOrm {
}
public LazyList<RssItem> getCurrentRssItemView(DatabaseConnection.SORT_DIRECTION sortDirection) {
public LazyList<RssItem> getCurrentRssItemView(SORT_DIRECTION sortDirection) {
WhereCondition whereCondition = new WhereCondition.StringCondition(RssItemDao.Properties.Id.columnName + " IN " +
"(SELECT " + CurrentRssItemViewDao.Properties.RssItemId.columnName + " FROM " + CurrentRssItemViewDao.TABLENAME + ")");
if(sortDirection.equals(DatabaseConnection.SORT_DIRECTION.asc))
if(sortDirection.equals(SORT_DIRECTION.asc))
return daoSession.getRssItemDao().queryBuilder().where(whereCondition).orderAsc(RssItemDao.Properties.PubDate).listLazy();
else
return daoSession.getRssItemDao().queryBuilder().where(whereCondition).orderDesc(RssItemDao.Properties.PubDate).listLazy();
@ -367,7 +367,7 @@ public class DatabaseConnectionOrm {
}
public String getAllItemsIdsForFeedSQL(long idFeed, boolean onlyUnread, boolean onlyStarredItems, DatabaseConnection.SORT_DIRECTION sortDirection) {
public String getAllItemsIdsForFeedSQL(long idFeed, boolean onlyUnread, boolean onlyStarredItems, SORT_DIRECTION sortDirection) {
String buildSQL = "SELECT " + RssItemDao.Properties.Id.columnName +
" FROM " + RssItemDao.TABLENAME +
@ -394,17 +394,17 @@ public class DatabaseConnectionOrm {
return (rssItem != null) ? rssItem.getId() : 0;
}
public List<RssItem> getListOfAllItemsForFolder(long ID_FOLDER, boolean onlyUnread, DatabaseConnection.SORT_DIRECTION sortDirection, int limit) {
public List<RssItem> getListOfAllItemsForFolder(long ID_FOLDER, boolean onlyUnread, SORT_DIRECTION sortDirection, int limit) {
String whereStatement = getAllItemsIdsForFolderSQL(ID_FOLDER, onlyUnread, sortDirection);
whereStatement = whereStatement.replace("SELECT " + RssItemDao.Properties.Id.columnName + " FROM " + RssItemDao.TABLENAME, "");
whereStatement += " LIMIT " + limit;
return daoSession.getRssItemDao().queryRaw(whereStatement, null);
}
public String getAllItemsIdsForFolderSQL(long ID_FOLDER, boolean onlyUnread, DatabaseConnection.SORT_DIRECTION sortDirection) {
public String getAllItemsIdsForFolderSQL(long ID_FOLDER, boolean onlyUnread, SORT_DIRECTION sortDirection) {
//If all starred items are requested always return them in desc. order
if(ID_FOLDER == ALL_STARRED_ITEMS.getValue())
sortDirection = DatabaseConnection.SORT_DIRECTION.desc;
sortDirection = SORT_DIRECTION.desc;
String buildSQL = "SELECT " + RssItemDao.Properties.Id.columnName +
" FROM " + RssItemDao.TABLENAME;

View file

@ -1,130 +0,0 @@
/**
* Android ownCloud News
*
* @author David Luhmer
* @copyright 2013 David Luhmer david-dev@live.de
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.luhmer.owncloudnewsreader.database;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "OwncloudNewsReader.db";
private static DatabaseHelper instance;
//private Context context;
private boolean shouldResetDatabase = false;
/**
* @return the shouldResetDatabase
*/
public boolean isShouldResetDatabase() {
return shouldResetDatabase;
}
public static synchronized DatabaseHelper getHelper(Context context)
{
if (instance == null)
instance = new DatabaseHelper(context);
return instance;
}
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 6);
//this.context = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
/* OLD */ //db.execSQL("CREATE TABLE folder (label TEXT NOT NULL,label_path TEXT);");
//db.execSQL("CREATE TABLE subscription(header_text TEXT NOT NULL, subscription_id_subscription INTEGER, FOREIGN KEY (subscription_id_subscription) REFERENCES subscription(rowid));");
/* OLD */ //db.execSQL("CREATE TABLE subscription(header_text TEXT NOT NULL, stream_id TEXT NOT NULL , folder_idfolder INTEGER, FOREIGN KEY (folder_idfolder) REFERENCES folder(rowid));");
/* OLD */ //db.execSQL("CREATE TABLE rss_item (title TEXT NOT NULL, link TEXT, description TEXT, read BOOL, starred BOOL, rssitem_id TEXT NOT NULL, timestamp DATETIME NULL, subscription_id_subscription INTEGER,FOREIGN KEY (subscription_id_subscription) REFERENCES subscription(rowid));");
db.execSQL("CREATE TABLE folder (label TEXT NOT NULL, label_id TEXT);");
db.execSQL("CREATE TABLE subscription(header_text TEXT NOT NULL, "
+ "subscription_id TEXT NOT NULL, "
+ "favicon_url TEXT, "
+ "link TEXT, "
+ "avg_colour TEXT, "
+ "folder_idfolder INTEGER, FOREIGN KEY (folder_idfolder) REFERENCES folder(rowid)"
+ ");");
db.execSQL("CREATE TABLE rss_item (title TEXT NOT NULL, "
+ "link TEXT, "
+ "body TEXT, "
+ "read BOOL, "
+ "starred BOOL, "
+ "rssitem_id INT NOT NULL, "
+ "pubdate DATETIME NULL, "
+ "author TEXT, "
+ "guid TEXT, "
+ "guidHash TEXT, "
+ "read_temp BOOL, "
+ "starred_temp BOOL, "
+ "enclosureLink TEXT, "
+ "enclosureMime TEXT, "
+ "lastModified DATETIME NULL, "
+ "subscription_id_subscription INTEGER, FOREIGN KEY (subscription_id_subscription) REFERENCES subscription(rowid));");
createRssCurrentViewTable(db);
/*
ContentValues cv = new ContentValues();
cv.put(TITLE, "Gravity, Death Star I");
cv.put(VALUE, SensorManager.GRAVITY_DEATH_STAR_I);
db.insert("constants", TITLE, cv);
*/
}
public void createRssCurrentViewTable(SQLiteDatabase db) {
db.beginTransaction();
try {
db.execSQL("DROP TABLE IF EXISTS " + DatabaseConnection.RSS_CURRENT_VIEW_TABLE);
db.execSQL("CREATE TABLE " + DatabaseConnection.RSS_CURRENT_VIEW_TABLE
+ " (" + DatabaseConnection.RSS_CURRENT_VIEW_RSS_ITEM_ID + " INT NOT NULL,"
+ " FOREIGN KEY (" + DatabaseConnection.RSS_CURRENT_VIEW_RSS_ITEM_ID + ") REFERENCES rss_item(rssitem_id))");
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
//db.endTransaction();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
android.util.Log.w("Constants", "Upgrading database, which will destroy all old data");
//Toast.makeText(, "Updating Database. All Items are deleted. Please trigger a sync.", Toast.LENGTH_LONG).show();
//shouldResetDatabase = true;
resetDatabase(db);
}
public void resetDatabase(SQLiteDatabase db)
{
db.execSQL("DROP TABLE rss_item;");
db.execSQL("DROP TABLE subscription;");
db.execSQL("DROP TABLE folder;");
onCreate(db);
}
}

View file

@ -27,15 +27,13 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import de.luhmer.owncloudnewsreader.database.DatabaseHelper;
public class DatabaseUtils {
public static final String DATABASE_NAME = "OwncloudNewsReader.db";
public static boolean CopyDatabaseToSdCard(Context context)
{
//context.getPackageCodePath()//Path to apk file..!
//String path = "/data/data/de.luhmer.owncloudnewsreader/databases/" + DatabaseHelper.DATABASE_NAME;
String path = context.getDatabasePath(DatabaseHelper.DATABASE_NAME).getPath();
String path = context.getDatabasePath(DATABASE_NAME).getPath();
File db = new File(path);
File backupDb = GetPath(context);
@ -55,6 +53,6 @@ public class DatabaseUtils {
}
public static File GetPath(Context context) {
return new File(FileUtils.getPath(context) + "/dbBackup/" + DatabaseHelper.DATABASE_NAME);
return new File(FileUtils.getPath(context) + "/dbBackup/" + DATABASE_NAME);
}
}

View file

@ -21,8 +21,6 @@
package de.luhmer.owncloudnewsreader.reader.GoogleReaderApi;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import org.apache.http.HttpResponse;
@ -46,14 +44,10 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.luhmer.owncloudnewsreader.Constants;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.model.FolderSubscribtionItem;
import de.luhmer.owncloudnewsreader.model.RssFile;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
public class GoogleReaderMethods {
@ -139,47 +133,6 @@ public class GoogleReaderMethods {
return _SUBTITLE_ARRAYLIST;
}
public static String[] getStarredList(String _USERNAME, String _PASSWORD) {
Log.d("mygr","METHOD: getStarredList()");
String returnString = null;
String _TAG_LABEL = null;
try {
_TAG_LABEL = "stream/contents/user/" + AuthenticationManager.getGoogleUserID(_USERNAME, _PASSWORD) + "/state/com.google/starred";
}catch(IOException e){
e.printStackTrace();
}
try{
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(GoogleReaderConstants._API_URL + _TAG_LABEL);
request.addHeader("Authorization", GoogleReaderConstants._AUTHPARAMS + AuthenticationManager.getGoogleAuthKey(_USERNAME, _PASSWORD));
HttpResponse response = client.execute(request);
returnString = HttpHelper.request(response);
Pattern pattern = Pattern.compile("\"alternate\":\\[\\{\"href\":\"(.*?)\",");
Matcher matcher = pattern.matcher(returnString);
ArrayList<String> resultList = new ArrayList<String>();
while (matcher.find())
resultList.add(matcher.group(1));
String[] ret = new String[resultList.size()];
resultList.toArray(ret);
return ret;
}catch(IOException e){
e.printStackTrace();
return null;
}
}
@SuppressWarnings("unused")
public static ArrayList<RssFile> getFeeds(String _USERNAME, String _PASSWORD, String _TAG_LABEL) {
@ -360,141 +313,4 @@ public class GoogleReaderMethods {
}
public static void MarkItemAsStarred(Boolean isStarred, Cursor cursor, DatabaseConnection dbConn, Context context, OnAsyncTaskCompletedListener asyncTaskCompletedPerformTagStarred)
{
List<NameValuePair> nameValuePairs = getStarredReadNameValuePairs(dbConn, cursor);
if(isStarred)
nameValuePairs.add(new BasicNameValuePair("a", GoogleReaderConstants._STATE_STARRED));
else
nameValuePairs.add(new BasicNameValuePair("r", GoogleReaderConstants._STATE_STARRED));
ExecuteTagsReadStarred(nameValuePairs, context, asyncTaskCompletedPerformTagStarred);
Log.d("CHECKBOX", "STARRED CHANGED: " + isStarred);
dbConn.updateIsStarredOfItem(cursor.getString(0), isStarred);
}
public static void MarkItemAsRead(Boolean isRead, Cursor cursor, DatabaseConnection dbConn, Context context, OnAsyncTaskCompletedListener asyncTaskCompletedPerformTagRead)
{
List<NameValuePair> nameValuePairs = getStarredReadNameValuePairs(dbConn, cursor);
if(isRead)
nameValuePairs.add(new BasicNameValuePair("a", GoogleReaderConstants._STATE_READ));
else
nameValuePairs.add(new BasicNameValuePair("r", GoogleReaderConstants._STATE_READ));
ExecuteTagsReadStarred(nameValuePairs, context, asyncTaskCompletedPerformTagRead);
Log.d("CHECKBOX", "STATUS CHANGED: " + isRead);
dbConn.updateIsReadOfItem(cursor.getString(0), isRead);
}
private static List<NameValuePair> getStarredReadNameValuePairs(DatabaseConnection dbConn, Cursor cursor)
{
String subscription_id = cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_SUBSCRIPTION_ID));
String rss_item_id = cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_RSSITEM_ID));
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("async", "true"));
nameValuePairs.add(new BasicNameValuePair("s", dbConn.getRowIdBySubscriptionID(subscription_id)));
nameValuePairs.add(new BasicNameValuePair("i", rss_item_id));
return nameValuePairs;
}
private static void ExecuteTagsReadStarred(List<NameValuePair> nameValuePairs, Context context, OnAsyncTaskCompletedListener asyncTaskCompleted)
{
//AsyncTask_PerformTagAction apt = new AsyncTask_PerformTagAction(0, context, asyncTaskCompleted);
//TODO this is needed
/*apt.execute(NewsReaderListFragment.username,
NewsReaderListFragment.password,
nameValuePairs);
*/
}
/*
public static String mark_all_feeds_as_read(String _USERNAME, String _PASSWORD, String FEED_ID) {
Log.d("mygr","METHOD: markAllAsRead");
try{
//String url = GoogleReaderConstants._MARK_ALL_AS_READ + "?s=" + FEED_ID + "&T=" + AuthenticationManager.getGoogleToken(_USERNAME, _PASSWORD);
String url = GoogleReaderConstants._MARK_ALL_AS_READ + "?s=" + FEED_ID;
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
request.addHeader("Authorization", GoogleReaderConstants._AUTHPARAMS + AuthenticationManager.getGoogleAuthKey(_USERNAME, _PASSWORD));
HttpResponse response = client.execute(request);
return HttpHelper.request(response);
}catch(IOException e){
e.printStackTrace();
return null;
}
}
public static String markItemAsStarred(String _USERNAME, String _PASSWORD, String FEED_ID, Boolean markAsStarred) {
Log.d("mygr","METHOD: markItemAsStarred");
try{
String url = GoogleReaderConstants.get_TAG_STARRED(markAsStarred);
url += "&s=" + FEED_ID + "&T=" + AuthenticationManager.getGoogleToken(_USERNAME, _PASSWORD);
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
request.addHeader("Authorization", GoogleReaderConstants._AUTHPARAMS + AuthenticationManager.getGoogleAuthKey(_USERNAME, _PASSWORD));
HttpResponse response = client.execute(request);
return HttpHelper.request(response);
}catch(IOException e){
e.printStackTrace();
return null;
}
}*/
/*
// Get the subscription list of a user
public String[] getSubscriptionList()
{
ArrayList subsList = new ArrayList();
try
{
Document doc = Jsoup.connect(Constants.SUBSCRIPTION_LIST_URL).header("Authorization", Constants.AUTHPARAMS + authkey).get();
Elements links = doc.select("string");
for(Element link : links)
if(link.attr("name").equals("id"))
subsList.add(link.text());
String[] subsArr = new String[subsList.size()];
subsList.toArray(subsArr);
return subsArr;
}
catch(Exception ex)
{
ex.printStackTrace();
return null;
}
}
public boolean addSubscription(String feedurl,String title,boolean recommendation)
{
String source="";
if(recommendation)
source="&source=RECOMMENDATION";
try{
Document doc = Jsoup.connect(Constants.SUBSCRIPTION_EDIT_URL+"?client=PrivateReader-v1"+source)
.header("Authorization", Constants.AUTHPARAMS + authkey)
.data("s","feed/"+feedurl,
"ac","subscribe",
typgetGoogleToken "t",title,
"T",token)
.post();
if(doc.text().equals("OK"))
return true;
else
return false;
}
catch(Exception ex)
{
ex.printStackTrace();
return false;
}
}
*/
}

View file

@ -39,7 +39,7 @@ import java.util.List;
import de.luhmer.owncloudnewsreader.Constants;
import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection.SORT_DIRECTION;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm.SORT_DIRECTION;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.model.RssItem;