diff --git a/.gitignore b/.gitignore index c77a34a4..ce14694b 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ local.properties # Eclipse project files .classpath .project +.settings # Android Studio .idea/ diff --git a/.project b/.project deleted file mode 100644 index 3f4b2d10..00000000 --- a/.project +++ /dev/null @@ -1,35 +0,0 @@ - - - OwncloudNewsReader - - - ActionBarSherlock - Android-PullToRefresh - - - - com.android.ide.eclipse.adt.ResourceManagerBuilder - - - - - com.android.ide.eclipse.adt.PreCompilerBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - com.android.ide.eclipse.adt.ApkBuilder - - - - - - com.android.ide.eclipse.adt.AndroidNature - org.eclipse.jdt.core.javanature - - diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index b080d2dd..00000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/.settings/org.eclipse.ltk.core.refactoring.prefs b/.settings/org.eclipse.ltk.core.refactoring.prefs deleted file mode 100644 index b196c64a..00000000 --- a/.settings/org.eclipse.ltk.core.refactoring.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/News-Android-App.iml b/News-Android-App.iml deleted file mode 100644 index 55503402..00000000 --- a/News-Android-App.iml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/News-Android-App/News-Android-App-News-Android-App.iml b/News-Android-App/News-Android-App-News-Android-App.iml deleted file mode 100644 index 437ab4cf..00000000 --- a/News-Android-App/News-Android-App-News-Android-App.iml +++ /dev/null @@ -1,189 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/News-Android-App/src/androidTest/java/de/luhmer/owncloudnewsreader/junit_tests/TestDbTest.java b/News-Android-App/src/androidTest/java/de/luhmer/owncloudnewsreader/junit_tests/TestDbTest.java index 44a0e6fc..5aa68f0b 100644 --- a/News-Android-App/src/androidTest/java/de/luhmer/owncloudnewsreader/junit_tests/TestDbTest.java +++ b/News-Android-App/src/androidTest/java/de/luhmer/owncloudnewsreader/junit_tests/TestDbTest.java @@ -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; diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java index bb6d286f..77289c12 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java @@ -127,11 +127,6 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter mTextColorLightTheme = mContext.getResources().getColor(R.color.slider_listview_text_color_light_theme); - //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); - fHelper = new FontHelper(mContext); unreadCountFeeds = new SparseArray(); @@ -462,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; diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/UnreadFeedCount.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/UnreadFeedCount.java deleted file mode 100644 index 0f16ec7d..00000000 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/UnreadFeedCount.java +++ /dev/null @@ -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 . -* -*/ - -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); - } -} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/UnreadFolderCount.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/UnreadFolderCount.java deleted file mode 100644 index f972bac2..00000000 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/UnreadFolderCount.java +++ /dev/null @@ -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 . -* -*/ - -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); - } -} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java index d9982efb..400d4b4e 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java @@ -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; @@ -48,8 +46,8 @@ import android.widget.ProgressBar; 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; diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderDetailFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderDetailFragment.java index 2faca81b..b92e90df 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderDetailFragment.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderDetailFragment.java @@ -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(); } /** diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index 1a5ea145..a2d0acc6 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -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"); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/GetImageThreaded.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/GetImageThreaded.java index 67c65180..d5b5e781 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/GetImageThreaded.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/GetImageThreaded.java @@ -21,12 +21,9 @@ package de.luhmer.owncloudnewsreader.async_tasks; -import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.graphics.drawable.BitmapDrawable; -import android.os.AsyncTask; import android.util.Log; import org.apache.http.util.ByteArrayBuffer; @@ -41,7 +38,6 @@ import java.net.URLConnection; import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm; import de.luhmer.owncloudnewsreader.database.model.Feed; -import de.luhmer.owncloudnewsreader.helper.BitmapDrawableLruCache; import de.luhmer.owncloudnewsreader.helper.ImageDownloadFinished; import de.luhmer.owncloudnewsreader.helper.ImageHandler; @@ -70,8 +66,7 @@ public class GetImageThreaded extends Thread } catch(Exception ex) { - Log.d(TAG, ex.getLocalizedMessage() + " - URL: " + WEB_URL_TO_FILE); - //ex.printStackTrace(); + Log.d(TAG, "Invalid URL: " + WEB_URL_TO_FILE, ex); } this.cont = cont; diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/cursor/NewsListCursorAdapter.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/cursor/NewsListCursorAdapter.java index cf8b9717..63da53bc 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/cursor/NewsListCursorAdapter.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/cursor/NewsListCursorAdapter.java @@ -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("]*>", ""); - body = body.replaceAll("]*>", ""); - - 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 { - private String idItemDb; - private final WeakReference textViewWeakReference; - - public DescriptionTextLoaderTask(TextView textView, String idItemDb) { - textViewWeakReference = new WeakReference(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); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnection.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnection.java deleted file mode 100644 index b776e36d..00000000 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnection.java +++ /dev/null @@ -1,1290 +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 . -* -*/ - -package de.luhmer.owncloudnewsreader.database; - -import android.content.ContentValues; -import android.content.Context; -import android.database.Cursor; -import android.database.SQLException; -import android.database.sqlite.SQLiteDatabase; -import android.util.Log; -import android.util.SparseArray; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import de.luhmer.owncloudnewsreader.Constants; -import de.luhmer.owncloudnewsreader.ListView.UnreadFolderCount; -import de.luhmer.owncloudnewsreader.model.PodcastFeedItem; -import de.luhmer.owncloudnewsreader.model.PodcastItem; -import de.luhmer.owncloudnewsreader.model.RssFile; -import de.luhmer.owncloudnewsreader.services.PodcastDownloadService; - -import static de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_ITEMS; -import static de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_STARRED_ITEMS; -import static de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_UNREAD_ITEMS; - -public class DatabaseConnection { - private DatabaseHelper openHelper; - private SQLiteDatabase database; - - - public SparseArray getUnreadItemCountForFolder(Context mContext) { - String buildSQL = "SELECT f.rowid, COUNT(" + RSS_ITEM_RSSITEM_ID + ")" + - " FROM " + RSS_ITEM_TABLE + " rss " + - " JOIN " + SUBSCRIPTION_TABLE + " st ON rss." + RSS_ITEM_SUBSCRIPTION_ID + " = st.rowid" + - " JOIN " + FOLDER_TABLE + " f ON st." + SUBSCRIPTION_FOLDER_ID + " = f.rowid" + - " WHERE " + RSS_ITEM_READ_TEMP + " != 1 " + - " GROUP BY f.rowid"; - - SparseArray values = getSparseArrayFromSQL(buildSQL, 0, 1); - - - values.put(ALL_UNREAD_ITEMS.getValue(), new UnreadFolderCount(mContext, ALL_UNREAD_ITEMS.getValueString()).getText()); - values.put(ALL_STARRED_ITEMS.getValue(), new UnreadFolderCount(mContext, ALL_STARRED_ITEMS.getValueString()).getText()); - - - return values; - } - - public SparseArray getUnreadItemCountForFeed() { - String buildSQL = "SELECT " + RSS_ITEM_SUBSCRIPTION_ID + ", COUNT(" + RSS_ITEM_RSSITEM_ID + ")" + // rowid as _id, - " FROM " + RSS_ITEM_TABLE + - " WHERE " + RSS_ITEM_READ_TEMP + " != 1 " + - " GROUP BY " + RSS_ITEM_SUBSCRIPTION_ID; - - return getSparseArrayFromSQL(buildSQL, 0, 1); - } - - public SparseArray getUrlsToFavIcons() { - String buildSQL = "SELECT " + SUBSCRIPTION_ID + ", " + SUBSCRIPTION_FAVICON_URL + - " FROM " + SUBSCRIPTION_TABLE; - return getSparseArrayFromSQL(buildSQL, 0, 1); - } - - - - public static final String FOLDER_TABLE = "folder"; - public static final String FOLDER_LABEL = "label"; - public static final String FOLDER_LABEL_ID = "label_id"; - - public static final String SUBSCRIPTION_TABLE = "subscription"; - public static final String SUBSCRIPTION_HEADERTEXT = "header_text"; - //public static final String SUBSCRIPTION_SUBSCRIPTION_ID = "subscription_id_subscription"; - public static final String SUBSCRIPTION_FOLDER_ID = "folder_idfolder"; - public static final String SUBSCRIPTION_ID = "subscription_id"; - public static final String SUBSCRIPTION_FAVICON_URL = "favicon_url"; - public static final String SUBSCRIPTION_LINK = "link"; - public static final String SUBSCRIPTION_AVG_COLOUR = "avg_colour"; - - public static final String RSS_ITEM_TABLE = "rss_item"; - public static final String RSS_ITEM_SUBSCRIPTION_ID = "subscription_id_subscription"; - public static final String RSS_ITEM_TITLE = "title"; - public static final String RSS_ITEM_LINK = "link"; - public static final String RSS_ITEM_BODY = "body"; - public static final String RSS_ITEM_READ = "read"; - public static final String RSS_ITEM_RSSITEM_ID = "rssitem_id"; - public static final String RSS_ITEM_STARRED = "starred"; - public static final String RSS_ITEM_PUBDATE = "pubdate"; - public static final String RSS_ITEM_AUTHOR = "author"; - public static final String RSS_ITEM_GUID = "guid"; - public static final String RSS_ITEM_GUIDHASH = "guidHash"; - public static final String RSS_ITEM_LAST_MODIFIED = "lastModified"; - - public static final String RSS_ITEM_READ_TEMP = "read_temp"; - public static final String RSS_ITEM_STARRED_TEMP = "starred_temp"; - - - public static final String RSS_CURRENT_VIEW_TABLE = "rss_current_view"; - public static final String RSS_CURRENT_VIEW_RSS_ITEM_ID = "rss_current_view_rss_item_id"; - - public static final String RSS_ITEM_ENC_MIME = "enclosureMime"; - public static final String RSS_ITEM_ENC_LINK = "enclosureLink"; - - - - public enum SORT_DIRECTION { asc, desc } - - - public static final boolean DATABASE_DEBUG_MODE = false; //(false && Constants.DEBUG_MODE) ? true: false; - - - public DatabaseConnection(Context aContext) { - //openHelper = new DatabaseHelper(aContext); - openHelper = DatabaseHelper.getHelper(aContext); - openDatabase(); - } - - public SQLiteDatabase getDatabase() - { - return database; - } - - public DatabaseHelper getHelper() { - return openHelper; - } - - public void getAllItemsIdsForFeedSQL() - { - //If i have 9023 rows in the database, when i run that query it should delete 8023 rows and leave me with 1000 - //database.execSQL("DELETE FROM " + RSS_ITEM_TABLE + " WHERE " + + "ORDER BY rowid DESC LIMIT 1000 * - - //Let's say it said 1005 - you need to delete 5 rows. - //DELETE FROM table ORDER BY dateRegistered ASC LIMIT 5 - - - int max = Constants.maxItemsCount; - int total = (int) getLongValueBySQL("SELECT COUNT(*) FROM rss_item"); - int unread = (int) getLongValueBySQL("SELECT COUNT(*) FROM rss_item WHERE read_temp != 1"); - int read = total - unread; - - if(total > max) - { - int overSize = total - max; - //Soll verhindern, dass ungelesene Artikel gelöscht werden - if(overSize > read) - overSize = read; - database.execSQL("DELETE FROM rss_item WHERE rowid IN (SELECT rowid FROM rss_item WHERE read_temp = 1 AND starred_temp != 1 ORDER BY rssitem_id asc LIMIT " + overSize + ")"); - /* SELECT * FROM rss_item WHERE read_temp = 1 ORDER BY rowid asc LIMIT 3; */ - } - } - - /* - public void markAllItemsAsRead(List itemIds) - { - List items = new ArrayList(); - for(Integer itemId : itemIds) - items.add(String.valueOf(itemId)); - markAllItemsAsReadUnread(items, true); - } - */ - - public void markAllItemsAsReadForCurrentView() - { - String sql = "UPDATE " + RSS_ITEM_TABLE + " SET " + RSS_ITEM_READ_TEMP + " = 1 WHERE " + RSS_ITEM_RSSITEM_ID + - " IN (SELECT " + RSS_CURRENT_VIEW_RSS_ITEM_ID + " FROM " + RSS_CURRENT_VIEW_TABLE + ")"; - database.execSQL(sql); - } - - public void markAllItemsAsReadUnread(List itemIds, boolean markAsRead) - { - if(itemIds != null) - for(String idItem : itemIds) - updateIsReadOfItem(idItem, markAsRead); - } - - /** - * Changes the read unread state of the item. This is NOT the temp value!!! - * @param itemIds - * @param markAsRead - */ - public void change_readUnreadStateOfItem(List itemIds, boolean markAsRead) - { - if(itemIds != null) - for(String idItem : itemIds) - updateIsReadOfItemNotTemp(idItem, markAsRead); - } - - /** - * Changes the starred unstarred state of the item. This is NOT the temp value!!! - * @param itemIds - * @param markAsStarred - */ - public void change_starrUnstarrStateOfItem(List itemIds, boolean markAsStarred) - { - if(itemIds != null) - for(String idItem : itemIds) - updateIsStarredOfFeedNotTemp(idItem, markAsStarred); - } - - public int getCountOfAllItems(boolean execludeStarred) - { - String buildSQL = "SELECT count(*) FROM " + RSS_ITEM_TABLE; - if(execludeStarred) - buildSQL += " WHERE " + RSS_ITEM_STARRED_TEMP + " != 1"; - - int result = 0; - - Cursor cursor = database.rawQuery(buildSQL, null); - try - { - if(cursor != null) - { - cursor.moveToFirst(); - result = cursor.getInt(0); - } - } finally { - cursor.close(); - } - - return result; - } - - public long getLastModified() - { - String buildSQL = "SELECT MAX(" + RSS_ITEM_LAST_MODIFIED + ") FROM " + RSS_ITEM_TABLE; - long result = 0; - - Cursor cursor = database.rawQuery(buildSQL, null); - try - { - if(cursor != null) - { - cursor.moveToFirst(); - result = cursor.getLong(0); - } - } finally { - cursor.close(); - } - - return result; - } - - public long getItemDbIdAtPosition(int positionXRow) - { - String buildSQL = "SELECT rowid FROM " + RSS_ITEM_TABLE; - long result = -1; - - Cursor cursor = database.rawQuery(buildSQL, null); - try - { - if(cursor != null) - { - if(cursor.move(cursor.getCount() - (positionXRow - 1))) - result = cursor.getLong(0); - } - } finally { - cursor.close(); - } - - return result; - } - - public List getAllNewReadItems() - { - String buildSQL = "SELECT " + RSS_ITEM_RSSITEM_ID + " FROM " + RSS_ITEM_TABLE + " WHERE " - + RSS_ITEM_READ_TEMP + " = 1 AND " - + RSS_ITEM_READ + " = 0"; - Cursor cursor = database.rawQuery(buildSQL, null); - return convertCursorToStringArray(cursor, 0); - } - - public List getAllNewUnreadItems() - { - String buildSQL = "SELECT " + RSS_ITEM_RSSITEM_ID + " FROM " + RSS_ITEM_TABLE + " WHERE " - + RSS_ITEM_READ_TEMP + " = 0 AND " - + RSS_ITEM_READ + " = 1"; - Cursor cursor = database.rawQuery(buildSQL, null); - return convertCursorToStringArray(cursor, 0); - } - - public List getAllNewStarredItems() - { - String buildSQL = "SELECT " + RSS_ITEM_RSSITEM_ID + " FROM " + RSS_ITEM_TABLE + " WHERE " - + RSS_ITEM_STARRED_TEMP + " = 1 AND " - + RSS_ITEM_STARRED + " = 0"; - Cursor cursor = database.rawQuery(buildSQL, null); - return convertCursorToStringArray(cursor, 0); - } - - public List getAllNewUnstarredItems() - { - String buildSQL = "SELECT " + RSS_ITEM_RSSITEM_ID + " FROM " + RSS_ITEM_TABLE + " WHERE " - + RSS_ITEM_STARRED_TEMP + " = 0 AND " - + RSS_ITEM_STARRED + " = 1"; - Cursor cursor = database.rawQuery(buildSQL, null); - return convertCursorToStringArray(cursor, 0); - } - - public Cursor getAllItemsWithIdHigher(String id_item) { - //String buildSQL = "SELECT rowid as _id, * FROM " + SUBSCRIPTION_TABLE + " WHERE subscription_id_subscription IS NULL"; - String buildSQL = "SELECT rowid as _id, * FROM " + RSS_ITEM_TABLE + " WHERE " + RSS_ITEM_RSSITEM_ID + " > " + id_item; - - - if(DATABASE_DEBUG_MODE) - Log.d("DB_HELPER", "getAllItemsWithIdHigher SQL: " + buildSQL); - return database.rawQuery(buildSQL, null); - } - - public long getLowestItemId(boolean onlyStarred) - { - String buildSQL = "SELECT MIN(" + RSS_ITEM_RSSITEM_ID + ") FROM " + RSS_ITEM_TABLE; - - if(onlyStarred) - buildSQL += " WHERE " + RSS_ITEM_STARRED_TEMP + " = 1"; - - return getLongValueBySQL(buildSQL); - } - - public long getLowestItemIdByFeed(String id_feed) - { - String buildSQL = "SELECT MIN(" + RSS_ITEM_RSSITEM_ID + ") FROM " + RSS_ITEM_TABLE + " WHERE " + RSS_ITEM_SUBSCRIPTION_ID + " = " + id_feed; - return getLongValueBySQL(buildSQL); - } - - public long getLowestItemIdByFolder(String id_folder) - { - String buildSQL = "SELECT MIN(" + RSS_ITEM_RSSITEM_ID + ") " + - "FROM " + RSS_ITEM_TABLE + " rss " + - "JOIN " + SUBSCRIPTION_TABLE + " sc ON rss." + RSS_ITEM_SUBSCRIPTION_ID + " = sc.rowid " + - "WHERE " + SUBSCRIPTION_FOLDER_ID + " = " + id_folder; - return getLongValueBySQL(buildSQL); - } - - public long getLowestItemIdStarred() - { - String buildSQL = "SELECT MIN(" + RSS_ITEM_RSSITEM_ID + ") FROM " + RSS_ITEM_TABLE + " WHERE " + RSS_ITEM_STARRED_TEMP + " = 1"; - return getLongValueBySQL(buildSQL); - } - - public long getLowestItemIdUnread() - { - String buildSQL = "SELECT MIN(" + RSS_ITEM_RSSITEM_ID + ") FROM " + RSS_ITEM_TABLE + " WHERE " + RSS_ITEM_READ_TEMP + " != 1"; - return getLongValueBySQL(buildSQL); - } - - public long getHighestItemId() - { - String buildSQL = "SELECT MAX(" + RSS_ITEM_RSSITEM_ID + ") FROM " + RSS_ITEM_TABLE; - return getLongValueBySQL(buildSQL); - } - - public int removeAllItemsWithIdLowerThan(String id_db) - { - 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; - Log.d("DB_HELPER", "getAllData SQL: " + buildSQL); - return database.rawQuery(buildSQL, null); - } - */ - - public Cursor getAllTopSubscriptions(boolean onlyUnread) { - //String buildSQL = "SELECT DISTINCT(f.rowid) as _id, * FROM " + FOLDER_TABLE + " f "; - - - String buildSQL = "SELECT DISTINCT(f.rowid) as _id, " + FOLDER_LABEL + - " FROM " + FOLDER_TABLE + " f "; - - if(onlyUnread) - { - buildSQL += " JOIN " + SUBSCRIPTION_TABLE + " sc ON f.rowid = sc." + SUBSCRIPTION_FOLDER_ID + - " JOIN " + RSS_ITEM_TABLE + " rss ON sc.rowid = rss." + RSS_ITEM_SUBSCRIPTION_ID + - " WHERE " + RSS_ITEM_READ_TEMP + " != 1" + - " GROUP BY f.rowid " + - " HAVING COUNT(*) > 0"; - } - - if(DATABASE_DEBUG_MODE) - Log.d("DB_HELPER", "getAllTopSubscriptions SQL: " + buildSQL); - return database.rawQuery(buildSQL, null); - } - - public Cursor getAllTopSubscriptionsWithoutFolder(boolean onlyUnread) { - //String buildSQL = "SELECT DISTINCT(sc.rowid) as _id, * FROM " + SUBSCRIPTION_TABLE + " sc "; - String buildSQL = "SELECT DISTINCT(sc.rowid) as _id, " + SUBSCRIPTION_HEADERTEXT + ", " + SUBSCRIPTION_ID + ", " + SUBSCRIPTION_FAVICON_URL + - " FROM " + SUBSCRIPTION_TABLE + " sc "; - - if(onlyUnread) - { - buildSQL += " JOIN " + RSS_ITEM_TABLE + " rss ON sc.rowid = rss." + RSS_ITEM_SUBSCRIPTION_ID + - " WHERE " + SUBSCRIPTION_FOLDER_ID + " IS NULL" + - " AND " + RSS_ITEM_READ_TEMP + " != 1" + - " GROUP BY sc.rowid " + - " HAVING COUNT(*) > 0"; - } - else - buildSQL += " WHERE " + SUBSCRIPTION_FOLDER_ID + " IS NULL"; - - if(DATABASE_DEBUG_MODE) - Log.d("DB_HELPER", "getAllTopSubscriptions SQL: " + buildSQL); - return database.rawQuery(buildSQL, null); - } - - /* - public Cursor getAllTopSubscriptionsWithUnreadFeeds() { - //String buildSQL = "SELECT rowid as _id, * FROM " + SUBSCRIPTION_TABLE + " WHERE subscription_id_subscription IS NULL"; - String buildSQL = "SELECT f.rowid as _id, * FROM " + FOLDER_TABLE + " f "+ - " JOIN " + SUBSCRIPTION_TABLE + " sc ON f.rowid = sc." + SUBSCRIPTION_FOLDER_ID + - " JOIN " + RSS_ITEM_TABLE + " rss ON sc.rowid = rss." + RSS_ITEM_SUBSCRIPTION_ID + - " GROUP BY f.rowid " + - " HAVING COUNT(*) > 0"; - Log.d("DB_HELPER", "getAllTopData SQL: " + buildSQL); - return database.rawQuery(buildSQL, null); - }*/ - - - public String getAvgColourOfFeedByDbId(String feedId) { - String buildSQL = "SELECT " + SUBSCRIPTION_AVG_COLOUR + " FROM " + SUBSCRIPTION_TABLE + " WHERE rowid = " + feedId; - return getStringValueBySQL(buildSQL); - } - - public int setAvgColourOfFeedByDbId(String feedId, String colour) { - ContentValues args = new ContentValues(); - args.put(SUBSCRIPTION_AVG_COLOUR, colour); - return database.update(SUBSCRIPTION_TABLE, args, "rowid=?", new String[] { feedId }); - } - - public Cursor getAllSubSubscriptions() { - //String buildSQL = "SELECT rowid as _id, * FROM " + SUBSCRIPTION_TABLE + " WHERE subscription_id_subscription IS NOT NULL"; - String buildSQL = "SELECT DISTINCT(rowid) as _id, * FROM " + SUBSCRIPTION_TABLE; - - if(DATABASE_DEBUG_MODE) - Log.d("DB_HELPER", "getAllSubSubscriptions SQL: " + buildSQL); - 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 + "'"; - - if(DATABASE_DEBUG_MODE) - Log.d("DB_HELPER", "getSubSubscriptionsByID SQL: " + buildSQL); - return database.rawQuery(buildSQL, null); - } - - public Cursor getFeedByFeedID(String ID_FEED) {//Feeds - String buildSQL = "SELECT rowid as _id, * FROM " + SUBSCRIPTION_TABLE + " WHERE " + SUBSCRIPTION_ID + " = '" + ID_FEED + "'"; - - if(DATABASE_DEBUG_MODE) - Log.d("DB_HELPER", "getSubSubscriptionsByID SQL: " + buildSQL); - return database.rawQuery(buildSQL, null); - } - - public int getCountItemsForSubscription(String ID_SUBSCRIPTION, boolean onlyUnread, boolean execludeStarredItems) { - - String buildSQL = "SELECT COUNT(*) " + - " FROM " + RSS_ITEM_TABLE + - //" WHERE read != 1" + - " WHERE " + RSS_ITEM_READ_TEMP +" != 1 AND " + RSS_ITEM_STARRED + " != 1" + - " AND subscription_id_subscription IN " + - "(SELECT rowid " + - "FROM subscription " + - "WHERE rowid = " + ID_SUBSCRIPTION + ");"; - - - - if(!onlyUnread) - buildSQL = buildSQL.replace("read_temp != 1 AND", ""); - - if(!execludeStarredItems) - buildSQL = buildSQL.replace(RSS_ITEM_STARRED + " != 1 AND", RSS_ITEM_STARRED_TEMP + " = 1 AND"); - - return (int)getLongValueBySQL(buildSQL); - } - - public Boolean isFeedUnreadStarred(String FEED_ID, Boolean checkUnread) { - String buildSQL; - /* - if(checkUnread) - buildSQL = "SELECT read "; - else//Wenn nicht checkRead auf true steht, soll geprueft werden ob das Feed Markiert ist. - buildSQL = "SELECT starred "; - */ - - if(checkUnread) - buildSQL = "SELECT read_temp "; - else//Wenn nicht checkRead auf true steht, soll geprueft werden ob das Feed Markiert ist. - buildSQL = "SELECT starred_temp "; - - buildSQL += " FROM " + RSS_ITEM_TABLE + - " WHERE rowid = " + FEED_ID; - - return checkSqlForBoolean(buildSQL); - } - - private Boolean checkSqlForBoolean(String buildSQL) - { - Boolean result = false; - Cursor cursor = database.rawQuery(buildSQL, null); - if (cursor != null) - { - if(cursor.moveToFirst()) - { - String val = cursor.getString(0); - if(val != null) - if(val.equals("1")) - result = true; - } - } - cursor.close(); - - return result; - } - - public void updateIsReadOfItem(String ITEM_ID, Boolean isRead) { - ContentValues args = new ContentValues(); - //args.put(RSS_ITEM_READ, isRead); - args.put(RSS_ITEM_READ_TEMP, isRead); - int result = database.update(RSS_ITEM_TABLE, args, "rowid=?", new String[] { ITEM_ID }); - - if(DATABASE_DEBUG_MODE) - Log.d("RESULT UPDATE DATABASE", "RESULT: " + result); - } - - public void updateIsReadOfItemNotTemp(String ITEM_ID, Boolean isRead) { - ContentValues args = new ContentValues(); - //args.put(RSS_ITEM_READ, isRead); - args.put(RSS_ITEM_READ, isRead); - int result = database.update(RSS_ITEM_TABLE, args, RSS_ITEM_RSSITEM_ID + "=?", new String[] { ITEM_ID }); - - if(DATABASE_DEBUG_MODE) - Log.d("RESULT UPDATE DATABASE", "RESULT: " + result); - } - - public void updateIsStarredOfFeedNotTemp(String FEED_ID, Boolean isStarred) { - ContentValues args = new ContentValues(); - //args.put(RSS_ITEM_READ, isRead); - args.put(RSS_ITEM_STARRED, isStarred); - int result = database.update(RSS_ITEM_TABLE, args, RSS_ITEM_RSSITEM_ID + "=?", new String[] { FEED_ID }); - - if(DATABASE_DEBUG_MODE) - Log.d("RESULT UPDATE DATABASE", "RESULT: " + result); - } - - public void updateIsStarredOfItem(String ITEM_ID, Boolean isStarred) { - - if(isStarred)//Wenn ein Feed markiert ist muss es auch als gelesen markiert werden. - updateIsReadOfItem(ITEM_ID, true); - - - ContentValues args = new ContentValues(); - //args.put(RSS_ITEM_STARRED, isStarred); - args.put(RSS_ITEM_STARRED_TEMP, isStarred); - int result = database.update(RSS_ITEM_TABLE, args, "rowid=?", new String[] { ITEM_ID }); - - if(DATABASE_DEBUG_MODE) - Log.d("RESULT UPDATE DATABASE", "RESULT: " + result); - } - - private String getAllFeedsSelectStatement() - { - return "SELECT DISTINCT(rowid) as _id, " + RSS_ITEM_TITLE + ", " + RSS_ITEM_RSSITEM_ID + ", " + RSS_ITEM_LINK + ", " + RSS_ITEM_BODY + ", " + RSS_ITEM_READ + ", " + RSS_ITEM_SUBSCRIPTION_ID + ", " - + RSS_ITEM_PUBDATE + ", " + RSS_ITEM_STARRED + ", " + RSS_ITEM_GUIDHASH + ", " + RSS_ITEM_GUID + ", " + RSS_ITEM_STARRED_TEMP + ", " + RSS_ITEM_READ_TEMP + ", " + RSS_ITEM_AUTHOR; - } - - @Deprecated - public Cursor getAllItemsForFeed(String ID_SUBSCRIPTION, boolean onlyUnread, boolean onlyStarredItems, SORT_DIRECTION sortDirection) { - - String buildSQL = getAllFeedsSelectStatement() + - " FROM " + RSS_ITEM_TABLE + - " WHERE subscription_id_subscription IN " + - "(SELECT rowid " + - "FROM subscription " + - "WHERE rowid = " + ID_SUBSCRIPTION + ")"; - - if(onlyUnread && !onlyStarredItems) - buildSQL += " AND " + RSS_ITEM_READ_TEMP + " != 1"; - else if(onlyStarredItems) - buildSQL += " AND " + RSS_ITEM_STARRED_TEMP + " = 1"; - - buildSQL += " ORDER BY " + RSS_ITEM_PUBDATE + " " + sortDirection.toString(); - - if(DATABASE_DEBUG_MODE) - Log.d("DB_HELPER", "getAllItemsForFeed SQL: " + buildSQL); - return database.rawQuery(buildSQL, null); - } - - public String getAllItemsIdsForFeedSQL(String ID_SUBSCRIPTION, boolean onlyUnread, boolean onlyStarredItems, SORT_DIRECTION sortDirection) { - - String buildSQL = "SELECT " + RSS_ITEM_RSSITEM_ID + - " FROM " + RSS_ITEM_TABLE + - " WHERE subscription_id_subscription IN " + - "(SELECT rowid " + - "FROM subscription " + - "WHERE rowid = " + ID_SUBSCRIPTION + ")"; - - if(onlyUnread && !onlyStarredItems) - buildSQL += " AND " + RSS_ITEM_READ_TEMP + " != 1"; - else if(onlyStarredItems) - buildSQL += " AND " + RSS_ITEM_STARRED_TEMP + " = 1"; - - buildSQL += " ORDER BY " + RSS_ITEM_PUBDATE + " " + sortDirection.toString(); - - return buildSQL; - } - - /* - public String getUrlToArticleByRowid(String article_rowid) { - - String buildSQL = "SELECT " + RSS_ITEM_LINK + - " FROM " + RSS_ITEM_TABLE + - " WHERE rowid =?"; - - return getStringValueBySQL(buildSQL); - } - */ - - - public Cursor getArticleByID(String ID_FEED) { - String buildSQL = getAllFeedsSelectStatement() + - " FROM " + RSS_ITEM_TABLE + - " WHERE rowid = " + ID_FEED; - - if(DATABASE_DEBUG_MODE) - Log.d("DB_HELPER", "getFeedByID SQL: " + buildSQL); - return database.rawQuery(buildSQL, null); - } - - public String getRowIdOfFeedByItemID(String ID_FEED) - { - String buildSQL = "SELECT rowid " + - " FROM " + RSS_ITEM_TABLE + - " WHERE " + RSS_ITEM_RSSITEM_ID + " = " + ID_FEED; - - return getStringValueBySQL(buildSQL); - } - - public void insertIntoRssCurrentViewTable(String SQL_SELECT) { - SQL_SELECT = "INSERT INTO " + RSS_CURRENT_VIEW_TABLE + - " (" + RSS_CURRENT_VIEW_RSS_ITEM_ID + ") " + SQL_SELECT; - openHelper.createRssCurrentViewTable(database); - database.execSQL(SQL_SELECT); - } - - public Cursor getCurrentSelectedRssItems(SORT_DIRECTION sortDirection) { - - String query1 = getAllFeedsSelectStatement() + " FROM " + RSS_ITEM_TABLE; - String query2 = "SELECT " + RSS_CURRENT_VIEW_RSS_ITEM_ID + " FROM " + RSS_CURRENT_VIEW_TABLE; - - String query = query1 + " WHERE " + RSS_ITEM_RSSITEM_ID + " IN (" + query2 + ")"; - //query += " ORDER BY " + RSS_ITEM_PUBDATE + " " + - query += " ORDER BY " + RSS_ITEM_PUBDATE + " " + sortDirection.toString(); - - return database.rawQuery(query, null); - } - - - public int getCountFeedsForFolder(String ID_FOLDER, boolean onlyUnread) { - Cursor cursor = database.rawQuery(getAllItemsIdsForFolderSQL(ID_FOLDER, onlyUnread, SORT_DIRECTION.desc), null); - int count = cursor.getCount(); - cursor.close(); - - return count; - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @Deprecated - public Cursor getAllItemsForFolder(String ID_FOLDER, boolean onlyUnread, SORT_DIRECTION sortDirection) { - String buildSQL = getAllFeedsSelectStatement() + - " FROM " + RSS_ITEM_TABLE; - - if(!(ID_FOLDER.equals(ALL_UNREAD_ITEMS.getValueString()) || ID_FOLDER.equals(ALL_STARRED_ITEMS.getValueString()) || ID_FOLDER.equals(ALL_ITEMS.getValueString())))//Wenn nicht Alle Artikel ausgewaehlt wurde (-10) oder (-11) fuer Starred Feeds - { - buildSQL += " WHERE subscription_id_subscription IN " + - "(SELECT sc.rowid " + - "FROM subscription sc " + - "JOIN folder f ON sc." + SUBSCRIPTION_FOLDER_ID + " = f.rowid " + - "WHERE f.rowid = " + ID_FOLDER + ")"; - - if(onlyUnread) - buildSQL += " AND " + RSS_ITEM_READ_TEMP + " != 1"; - } - //else if(ID_FOLDER.equals(SubscriptionExpandableListAdapter.ALL_UNREAD_ITEMS) && onlyUnread)//only unRead should only be null when testing the size of items - else if(ID_FOLDER.equals(ALL_UNREAD_ITEMS.getValueString())) - buildSQL += " WHERE " + RSS_ITEM_STARRED_TEMP + " != 1 AND " + RSS_ITEM_READ_TEMP + " != 1"; - else if(ID_FOLDER.equals(ALL_STARRED_ITEMS.getValueString())) - buildSQL += " WHERE " + RSS_ITEM_STARRED_TEMP + " = 1"; - - - buildSQL += " ORDER BY " + RSS_ITEM_PUBDATE + " " + sortDirection.toString(); - - // buildSQL += " WHERE starred = 1"; - - if(DATABASE_DEBUG_MODE) - Log.d("DB_HELPER", "getAllFeedData SQL: " + buildSQL); - return database.rawQuery(buildSQL, null); - } - - public String getAllItemsIdsForFolderSQL(String ID_FOLDER, boolean onlyUnread, SORT_DIRECTION sortDirection) { - String buildSQL = "SELECT " + RSS_ITEM_RSSITEM_ID + - " FROM " + RSS_ITEM_TABLE; - - if(!(ID_FOLDER.equals(ALL_UNREAD_ITEMS.getValueString()) || ID_FOLDER.equals(ALL_STARRED_ITEMS.getValueString()) || ID_FOLDER.equals(ALL_ITEMS.getValueString())))//Wenn nicht Alle Artikel ausgewaehlt wurde (-10) oder (-11) fuer Starred Feeds - { - buildSQL += " WHERE subscription_id_subscription IN " + - "(SELECT sc.rowid " + - "FROM subscription sc " + - "JOIN folder f ON sc." + SUBSCRIPTION_FOLDER_ID + " = f.rowid " + - "WHERE f.rowid = " + ID_FOLDER + ")"; - - if(onlyUnread) - buildSQL += " AND " + RSS_ITEM_READ_TEMP + " != 1"; - } - //else if(ID_FOLDER.equals(SubscriptionExpandableListAdapter.ALL_UNREAD_ITEMS) && onlyUnread)//only unRead should only be null when testing the size of items - else if(ID_FOLDER.equals(ALL_UNREAD_ITEMS.getValueString())) - buildSQL += " WHERE " + RSS_ITEM_READ_TEMP + " != 1"; - //buildSQL += " WHERE " + RSS_ITEM_STARRED_TEMP + " != 1 AND " + RSS_ITEM_READ_TEMP + " != 1"; - //else if(ID_FOLDER.equals(SubscriptionExpandableListAdapter.ALL_UNREAD_ITEMS)) - // buildSQL += " WHERE " + RSS_ITEM_STARRED + " != 1"; - //else if(ID_FOLDER.equals(SubscriptionExpandableListAdapter.ALL_STARRED_ITEMS) && onlyUnread) - // buildSQL += " WHERE " + RSS_ITEM_STARRED_TEMP + " = 1 AND " + RSS_ITEM_READ_TEMP + " != 1"; - else if(ID_FOLDER.equals(ALL_STARRED_ITEMS.getValueString())) - buildSQL += " WHERE " + RSS_ITEM_STARRED_TEMP + " = 1"; - - - buildSQL += " ORDER BY " + RSS_ITEM_PUBDATE + " " + sortDirection.toString(); - - // buildSQL += " WHERE starred = 1"; - - if(DATABASE_DEBUG_MODE) - Log.d("DB_HELPER", "getAllFeedData SQL: " + buildSQL); - return buildSQL; - } - - public Cursor getAllSubscriptionForFolder(String ID_FOLDER, boolean onlyUnread) { - //String buildSQL = "SELECT sc.rowid as _id, sc.* " + - String buildSQL = "SELECT sc.rowid as _id, sc." + SUBSCRIPTION_HEADERTEXT + ", sc." + SUBSCRIPTION_ID + ", sc." + SUBSCRIPTION_FAVICON_URL + - " FROM " + SUBSCRIPTION_TABLE + " sc " + - " LEFT OUTER JOIN folder f ON sc.folder_idfolder = f.rowid "; - - if(ID_FOLDER.equals("-11"))//Starred - { - buildSQL += " JOIN " + RSS_ITEM_TABLE + " rss ON sc.rowid = rss." + RSS_ITEM_SUBSCRIPTION_ID + - " WHERE rss." + RSS_ITEM_STARRED_TEMP + " = 1" + - " GROUP BY sc.rowid " + - " HAVING COUNT(*) > 0"; - } - else if(onlyUnread || ID_FOLDER.equals(ALL_UNREAD_ITEMS.getValueString()) /*ID_SUBSCRIPTION.matches("-10|-11")*/) - { - buildSQL += " JOIN " + RSS_ITEM_TABLE + " rss ON sc.rowid = rss." + RSS_ITEM_SUBSCRIPTION_ID + - " WHERE f.rowid = " + ID_FOLDER + " AND rss." + RSS_ITEM_READ_TEMP + " != 1" + - " GROUP BY sc.rowid " + - " HAVING COUNT(*) > 0"; - - if(ID_FOLDER.equals(ALL_UNREAD_ITEMS.getValueString())) - buildSQL = buildSQL.replace("f.rowid = " + ID_FOLDER + " AND", "");//Remove to ID stuff because i want the result of all feeds where are unread items in - } - else - buildSQL += "WHERE f.rowid = " + ID_FOLDER; - - if(DATABASE_DEBUG_MODE) - Log.d("DB_HELPER", "getAllSub_SubscriptionForSubscription SQL: " + buildSQL); - return database.rawQuery(buildSQL, null); - } - - public void insertNewFolder (String label, String label_path) { - ContentValues contentValues = new ContentValues(); - contentValues.put(FOLDER_LABEL, label); - contentValues.put(FOLDER_LABEL_ID, label_path); - database.insert(FOLDER_TABLE, null, contentValues); - } - - public void insertNewFeed (String headerText, String ID_FOLDER, String subscription_id, String FAVICON_URL) { - ContentValues contentValues = new ContentValues(); - contentValues.put(SUBSCRIPTION_HEADERTEXT, headerText); - contentValues.put(SUBSCRIPTION_FOLDER_ID, ID_FOLDER); - contentValues.put(SUBSCRIPTION_ID , subscription_id); - contentValues.put(SUBSCRIPTION_FAVICON_URL, FAVICON_URL); - database.insert(SUBSCRIPTION_TABLE, null, contentValues); - } - - public int updateFeed (String headerText, String ID_FOLDER, String subscription_id, String FAVICON_URL) { - ContentValues contentValues = new ContentValues(); - contentValues.put(SUBSCRIPTION_HEADERTEXT, headerText); - contentValues.put(SUBSCRIPTION_FOLDER_ID, ID_FOLDER); - contentValues.put(SUBSCRIPTION_FAVICON_URL, FAVICON_URL); - return database.update(SUBSCRIPTION_TABLE, contentValues, SUBSCRIPTION_ID + "= ?", new String[] { subscription_id }); - } - - public void insertNewItems(RssFile[] items) { - database.beginTransaction(); - - List rssItems = getRssItemsIds(); - - try { - for(RssFile item : items) { - if(item != null) { - Integer itemId = Integer.parseInt(item.getItem_Id()); - boolean isFeedAlreadyInDatabase = rssItems.contains(itemId); //doesRssItemAlreadyExsists(item.getItem_Id()); - insertNewItem(item, !isFeedAlreadyInDatabase); - } - } - database.setTransactionSuccessful(); - } catch (SQLException e) { - e.printStackTrace(); - } finally { - database.endTransaction(); - } - } - - public void insertNewItem (RssFile item, boolean insertItem) { - ContentValues contentValues = new ContentValues(); - contentValues.put(RSS_ITEM_TITLE, item.getTitle()); - contentValues.put(RSS_ITEM_LINK, item.getLink()); - contentValues.put(RSS_ITEM_BODY, item.getDescription()); - contentValues.put(RSS_ITEM_READ, item.getRead()); - contentValues.put(RSS_ITEM_SUBSCRIPTION_ID, String.valueOf(item.getFeedID_Db())); - contentValues.put(RSS_ITEM_RSSITEM_ID, item.getItem_Id()); - contentValues.put(RSS_ITEM_PUBDATE, item.getDate().getTime()); - contentValues.put(RSS_ITEM_STARRED, item.getStarred()); - contentValues.put(RSS_ITEM_GUID, item.getGuid()); - contentValues.put(RSS_ITEM_GUIDHASH, item.getGuidHash()); - contentValues.put(RSS_ITEM_LAST_MODIFIED, item.getLastModified()); - contentValues.put(RSS_ITEM_AUTHOR, item.getAuthor()); - - contentValues.put(RSS_ITEM_READ_TEMP, item.getRead()); - contentValues.put(RSS_ITEM_STARRED_TEMP, item.getStarred()); - - contentValues.put(RSS_ITEM_ENC_LINK, item.getEnclosureLink()); - contentValues.put(RSS_ITEM_ENC_MIME, item.getEnclosureMime()); - - long result; - if(insertItem) - result = database.insert(RSS_ITEM_TABLE, null, contentValues); - else - result = database.update(RSS_ITEM_TABLE, contentValues, RSS_ITEM_RSSITEM_ID + "=?", new String[] { item.getItem_Id() }); - - //Log.d("DatabaseConnection", "Inserted Rows: " + result); - } - - private static final String ALLOWED_PODCASTS_TYPES = "audio/mp3', 'audio/mpeg', 'audio/ogg', 'audio/opus', 'audio/ogg;codecs=opus', 'youtube"; - - public List getListOfFeedsWithAudioPodcasts() { - - String buildSQL = "SELECT DISTINCT sc.rowid, " + SUBSCRIPTION_HEADERTEXT + ", COUNT(rss.rowid) FROM " + SUBSCRIPTION_TABLE + " sc " + - " JOIN " + RSS_ITEM_TABLE + " rss ON sc.rowid = rss." + RSS_ITEM_SUBSCRIPTION_ID + - " WHERE rss." + RSS_ITEM_ENC_MIME + " IN ('" + ALLOWED_PODCASTS_TYPES + "') GROUP BY sc.rowid"; - - List result = new ArrayList(); - Cursor cursor = database.rawQuery(buildSQL, null); - try - { - if(cursor != null) - { - if(cursor.getCount() > 0) - { - cursor.moveToFirst(); - do { - /* - PodcastFeedItem podcastItem = new PodcastFeedItem(); - podcastItem.itemId = cursor.getString(0); - podcastItem.title = cursor.getString(1); - podcastItem.count = cursor.getInt(2); - result.add(podcastItem); - */ - } while(cursor.moveToNext()); - } - } - } finally { - cursor.close(); - } - - return result; - } - - public PodcastItem getPodcastForItem(Context context, String itemId) { - String buildSQL = "SELECT rowid, " + RSS_ITEM_TITLE + ", " + RSS_ITEM_ENC_LINK + ", " + RSS_ITEM_ENC_MIME + " FROM " + RSS_ITEM_TABLE + - " WHERE " + RSS_ITEM_ENC_MIME + " IN ('" + ALLOWED_PODCASTS_TYPES + "') AND rowid = " + itemId; - - Cursor cursor = database.rawQuery(buildSQL, null); - try - { - if(cursor != null) - { - if(cursor.getCount() > 0) - { - cursor.moveToFirst(); - return ParsePodcastItemFromCursor(context, cursor); - } - } - } finally { - cursor.close(); - } - return null; - } - - public List getListOfAudioPodcastsForFeed(Context context, String feedId) { - - String buildSQL = "SELECT rowid, " + RSS_ITEM_TITLE + ", " + RSS_ITEM_ENC_LINK + ", " + RSS_ITEM_ENC_MIME + " FROM " + RSS_ITEM_TABLE + - " WHERE " + RSS_ITEM_ENC_MIME + " IN ('" + ALLOWED_PODCASTS_TYPES + "') AND " + RSS_ITEM_SUBSCRIPTION_ID + " = " + feedId; - - - List result = new ArrayList(); - Cursor cursor = database.rawQuery(buildSQL, null); - try - { - if(cursor != null) - { - if(cursor.getCount() > 0) - { - cursor.moveToFirst(); - do { - PodcastItem podcastItem = ParsePodcastItemFromCursor(context, cursor); - result.add(podcastItem); - } while(cursor.moveToNext()); - } - } - } finally { - cursor.close(); - } - - return result; - } - - public static PodcastItem ParsePodcastItemFromCursor(Context context, Cursor cursor) { - PodcastItem podcastItem = new PodcastItem(); - podcastItem.itemId = cursor.getLong(0); - podcastItem.title = cursor.getString(cursor.getColumnIndex(RSS_ITEM_TITLE)); //cursor.getString(1); - podcastItem.link = cursor.getString(cursor.getColumnIndex(RSS_ITEM_ENC_LINK)); //cursor.getString(2); - podcastItem.mimeType = cursor.getString(cursor.getColumnIndex(RSS_ITEM_ENC_MIME)); //cursor.getString(3); - - File file = new File(PodcastDownloadService.getUrlToPodcastFile(context, podcastItem.link, false)); - podcastItem.offlineCached = file.exists(); - - return podcastItem; - } - - public HashMap getListOfFolders () { - //String buildSQL = "SELECT rowid as _id FROM " + SUBSCRIPTION_TABLE + " WHERE " + SUBSCRIPTION_HEADERTEXT + " = '" + SubscriptionName + "'"; - String buildSQL = "SELECT label, label_id FROM " + FOLDER_TABLE; - - /* - Cursor cursor = database.rawQuery(buildSQL, null); - List folderNames = convertCursorToStringArray(cursor, 0); - - cursor = database.rawQuery(buildSQL, null); - List folderIds = convertCursorToStringArray(cursor, 1); - - HashMap folders = new HashMap(); - - for(int i = 0; i < folderNames.size(); i++) { - folders.put(folderNames.get(i), folderIds.get(i)); - } - */ - - return getHashMapFromSQL(buildSQL, 0, 1); //folders; - } - - public String getIdOfFolder (String FolderName) { - //String buildSQL = "SELECT rowid as _id FROM " + SUBSCRIPTION_TABLE + " WHERE " + SUBSCRIPTION_HEADERTEXT + " = '" + SubscriptionName + "'"; - String buildSQL = "SELECT rowid as _id FROM " + FOLDER_TABLE + " WHERE " + FOLDER_LABEL + " = '" + FolderName + "'"; - - return getStringValueBySQL(buildSQL); - } - - public String getIdOfFolderByLabelPath (String FolderLabelPath) { - //String buildSQL = "SELECT rowid as _id FROM " + SUBSCRIPTION_TABLE + " WHERE " + SUBSCRIPTION_HEADERTEXT + " = '" + SubscriptionName + "'"; - String buildSQL = "SELECT rowid as _id FROM " + FOLDER_TABLE + " WHERE " + FOLDER_LABEL_ID + " = '" + FolderLabelPath + "'"; - - return getStringValueBySQL(buildSQL); - } - - public SparseArray getFeedIds() { - String buildSQL = "SELECT " + SUBSCRIPTION_ID + ", rowid as _id FROM " + SUBSCRIPTION_TABLE; - return getSparseArrayFromSQL(buildSQL, 0, 1); - } - - public String getRowIdBySubscriptionID (String StreamID) { - //String buildSQL = "SELECT rowid as _id FROM " + SUBSCRIPTION_TABLE + " WHERE " + SUBSCRIPTION_HEADERTEXT + " = '" + SubscriptionName + "'"; - String buildSQL = "SELECT rowid as _id FROM " + SUBSCRIPTION_TABLE + " WHERE " + SUBSCRIPTION_ID + " = '" + StreamID + "'"; - return getStringValueBySQL(buildSQL); - } - - public String getSubscriptionIdByRowID (String ID) { - - String buildSQL = "SELECT " + SUBSCRIPTION_ID + " FROM " + SUBSCRIPTION_TABLE + " WHERE rowid = '" + ID + "'"; - return getStringValueBySQL(buildSQL); - } - - public String getTitleOfFolderByID (String FolderID) { - //String buildSQL = "SELECT " + SUBSCRIPTION_HEADERTEXT + " FROM " + SUBSCRIPTION_TABLE + " WHERE rowid = '" + SubscriptionID + "'"; - String buildSQL = "SELECT " + FOLDER_LABEL + " FROM " + FOLDER_TABLE + " WHERE rowid = '" + FolderID + "'"; - return getStringValueBySQL(buildSQL); - } - - public String getTitleOfSubscriptionByRowID (String SubscriptionID) { - String buildSQL = "SELECT " + SUBSCRIPTION_HEADERTEXT + " FROM " + SUBSCRIPTION_TABLE + " WHERE rowid = '" + SubscriptionID + "'"; - return getStringValueBySQL(buildSQL); - } - - public String getTitleOfSubscriptionByRSSItemID (String RssItemID) { - String buildSQL = "SELECT " + SUBSCRIPTION_HEADERTEXT + " FROM " + SUBSCRIPTION_TABLE + " sc " + - "JOIN " + RSS_ITEM_TABLE + " rss ON sc.rowid = rss." + RSS_ITEM_SUBSCRIPTION_ID + " " + - "WHERE rss.rowid = '" + RssItemID + "'"; - return getStringValueBySQL(buildSQL); - } - - public int removeTopSubscriptionItemByTag(String TAG) - { - return database.delete(SUBSCRIPTION_TABLE, SUBSCRIPTION_HEADERTEXT + " = ?", new String[] { TAG }); - } - - public int removeFolderByFolderLabel(String FolderLabel) - { - return database.delete(FOLDER_TABLE, FOLDER_LABEL + " = ?", new String[] { FolderLabel }); - } - - public int removeItemByItemId(String idRssItem) - { - return database.delete(RSS_ITEM_TABLE, RSS_ITEM_RSSITEM_ID + " = ?", new String[] { idRssItem }); - } - - public boolean doesRssItemAlreadyExsists(String idRssItem)//idRssItem = id aus dem Google Reader Stream - { - String buildSQL = "SELECT " + RSS_ITEM_TITLE + " FROM " + RSS_ITEM_TABLE + " WHERE " + RSS_ITEM_RSSITEM_ID + " = '" + idRssItem + "'"; - Cursor cursor = database.rawQuery(buildSQL, null); - int count = cursor.getCount(); - cursor.close(); - if(count > 0) - return true; - else - return false; - } - - public List getRssItemsIds() { - String buildSQL = "SELECT " + RSS_ITEM_RSSITEM_ID + " FROM " + RSS_ITEM_TABLE; - Cursor cursor = database.rawQuery(buildSQL, null); - return convertCursorToIntArray(cursor, 0); - } - - public List convertCursorToIntArray(Cursor cursor, int column_id) - { - List items = new ArrayList(); - try - { - if(cursor != null) - { - if(cursor.getCount() > 0) - { - cursor.moveToFirst(); - do { - items.add(cursor.getInt(column_id)); - } while(cursor.moveToNext()); - } - } - } finally { - cursor.close(); - } - return items; - } - - public List convertCursorToStringArray(Cursor cursor, int column_id) - { - List items = new ArrayList(); - try - { - if(cursor != null) - { - if(cursor.getCount() > 0) - { - cursor.moveToFirst(); - do { - items.add(cursor.getString(column_id)); - } while(cursor.moveToNext()); - } - } - } finally { - cursor.close(); - } - return items; - } - - private String getStringValueBySQL(String buildSQL) - { - String result = null; - - Cursor cursor = database.rawQuery(buildSQL, null); - try - { - if(cursor != null) - { - if(cursor.moveToFirst()) - result = cursor.getString(0); - } - } finally { - cursor.close(); - } - - return result; - } - - public long getLongValueBySQL(String buildSQL) - { - long result = -1; - - Cursor cursor = database.rawQuery(buildSQL, null); - try - { - if(cursor != null) - { - if(cursor.moveToFirst()) - result = cursor.getLong(0); - } - } finally { - cursor.close(); - } - - return result; - } - - public HashMap getHashMapFromSQL(String buildSQL, int index1, int index2) { - HashMap result = new HashMap(); - - Cursor cursor = database.rawQuery(buildSQL, null); - try - { - if(cursor != null) - { - if(cursor.getCount() > 0) - { - cursor.moveToFirst(); - do { - String key = cursor.getString(index1); - String value = cursor.getString(index2); - result.put(key, value); - } while(cursor.moveToNext()); - } - } - } finally { - cursor.close(); - } - - return result; - } - - public SparseArray getSparseArrayFromSQL(String buildSQL, int index1, int index2) { - SparseArray result = new SparseArray(); - - Cursor cursor = database.rawQuery(buildSQL, null); - try - { - if(cursor != null) - { - if(cursor.getCount() > 0) - { - cursor.moveToFirst(); - do { - int key = cursor.getInt(index1); - String value = cursor.getString(index2); - result.put(key, value); - } while(cursor.moveToNext()); - } - } - } finally { - cursor.close(); - } - - return result; - } - - - - public int resetRssItemsDatabase() - { - int result = database.delete(RSS_ITEM_TABLE, null, null); - return result; - } - - public void resetDatabase() - { - openHelper.resetDatabase(database); - } - - public void openDatabase() - { - if(database == null) - database = openHelper.getWritableDatabase(); - } - - public void closeDatabase() - { - //database.close(); - } -} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java index ab225bd8..870b045c 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java @@ -43,13 +43,14 @@ public class DatabaseConnectionOrm { this.add("audio/ogg"); this.add("audio/opus"); this.add("audio/ogg;codecs=opus"); + this.add("audio/x-m4a"); this.add("youtube"); } }; public static final String[] VIDEO_FORMATS = { "youtube" }; - + public enum SORT_DIRECTION { asc, desc } DaoSession daoSession; @@ -330,11 +331,11 @@ public class DatabaseConnectionOrm { } - public LazyList getCurrentRssItemView(DatabaseConnection.SORT_DIRECTION sortDirection) { + public LazyList 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 +368,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 +395,17 @@ public class DatabaseConnectionOrm { return (rssItem != null) ? rssItem.getId() : 0; } - public List getListOfAllItemsForFolder(long ID_FOLDER, boolean onlyUnread, DatabaseConnection.SORT_DIRECTION sortDirection, int limit) { + public List 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; diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseHelper.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseHelper.java deleted file mode 100644 index c62860ec..00000000 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseHelper.java +++ /dev/null @@ -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 . -* -*/ - -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); - } -} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/BitmapDrawableLruCache.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/BitmapDrawableLruCache.java deleted file mode 100644 index e8de025e..00000000 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/BitmapDrawableLruCache.java +++ /dev/null @@ -1,54 +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 . -* -*/ - -package de.luhmer.owncloudnewsreader.helper; - -import android.annotation.TargetApi; -import android.graphics.drawable.BitmapDrawable; -import android.os.Build; -import android.support.v4.util.LruCache; - - - -public class BitmapDrawableLruCache extends LruCache { - public static int getDefaultLruCacheSize() { - final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); - final int cacheSize = maxMemory / 8; - return cacheSize; - } - - public BitmapDrawableLruCache() { - this(getDefaultLruCacheSize()); - } - - public BitmapDrawableLruCache(int sizeInKiloBytes) { - super(sizeInKiloBytes); - } - - @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) - @Override - protected int sizeOf(Long key, BitmapDrawable bitmap) { - if(Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR1) - return bitmap.getBitmap().getByteCount() / 1024; - else - return bitmap.getBitmap().getRowBytes() * bitmap.getBitmap().getHeight() / 1024; - } -} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/DatabaseUtils.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/DatabaseUtils.java index 8ef35a43..c8d58392 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/DatabaseUtils.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/DatabaseUtils.java @@ -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); } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/FavIconHandler.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/FavIconHandler.java index 9cd5fb04..947f24fb 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/FavIconHandler.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/FavIconHandler.java @@ -89,6 +89,11 @@ public class FavIconHandler { } public void PreCacheFavIcon(Feed feed) { + if(feed.getFaviconUrl() == null) { + Log.v(TAG, "No favicon for "+feed.getFeedTitle()); + return; + } + GetImageThreaded giAsync = new GetImageThreaded(feed.getFaviconUrl(), favIconDownloadFinished, feed.getId(), FileUtils.getPathFavIcons(context), context); giAsync.scaleImage = true; giAsync.dstHeight = 2*32; diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/GoogleReaderApi/GoogleReaderMethods.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/GoogleReaderApi/GoogleReaderMethods.java index e5c75f02..b6a906ff 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/GoogleReaderApi/GoogleReaderMethods.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/GoogleReaderApi/GoogleReaderMethods.java @@ -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 resultList = new ArrayList(); - - 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 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 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 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 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 nameValuePairs = new ArrayList(); - 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 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; - } - } - */ } \ No newline at end of file diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java index 2f9d9843..989fff39 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java @@ -31,7 +31,6 @@ import android.content.SharedPreferences; import android.graphics.Bitmap; import android.preference.PreferenceManager; import android.support.v4.app.NotificationCompat; -import android.util.SparseArray; import android.widget.Toast; import java.io.File; @@ -51,7 +50,6 @@ import de.luhmer.owncloudnewsreader.async_tasks.GetImageThreaded; import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm; import de.luhmer.owncloudnewsreader.database.model.Feed; import de.luhmer.owncloudnewsreader.database.model.RssItem; -import de.luhmer.owncloudnewsreader.helper.BitmapDrawableLruCache; import de.luhmer.owncloudnewsreader.helper.FavIconHandler; import de.luhmer.owncloudnewsreader.helper.FileUtils; import de.luhmer.owncloudnewsreader.helper.ImageDownloadFinished; @@ -196,10 +194,10 @@ public class DownloadImagesService extends IntentService { private void RemoveOldImages(Context context) { HashMap files; long size = ImageHandler.getFolderSize(new File(FileUtils.getPath(context))); - size = (long) (size / 1024d / 1024d); SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context); int max_allowed_size = Integer.parseInt(mPrefs.getString(SettingsActivity.SP_MAX_CACHE_SIZE, "1000"));//Default is 1Gb --> 1000mb + max_allowed_size *= 1024 * 1024; // convert to byte if(size > max_allowed_size) { files = new HashMap<>(); @@ -211,8 +209,8 @@ public class DownloadImagesService extends IntentService { for(Object itemObj : sortHashMapByValuesD(files).keySet()) { File file = (File) itemObj; - file.delete(); size -= file.length(); + file.delete(); if(size < max_allowed_size) break; } @@ -259,8 +257,7 @@ public class DownloadImagesService extends IntentService { if(maxCount == count) { notificationManager.cancel(NOTIFICATION_ID); - if(DownloadImagesService.this != null) - RemoveOldImages(DownloadImagesService.this); + RemoveOldImages(DownloadImagesService.this); } else { NotificationDownloadImages.setProgress(maxCount, count+1, false); NotificationDownloadImages.setContentText("Downloading Images for offline usage - " + (count+1) + "/" + maxCount); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/PodcastPlaybackService.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/PodcastPlaybackService.java index e9b6ea85..c00b0df8 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/PodcastPlaybackService.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/PodcastPlaybackService.java @@ -110,6 +110,7 @@ public class PodcastPlaybackService extends Service implements TextToSpeech.OnIn @Override public void onCompletion(MediaPlayer mediaPlayer) { pause();//Send the over signal + podcastNotification.cancel(); } }); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/view/PodcastNotification.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/view/PodcastNotification.java index a54f3095..1b9ec0b6 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/view/PodcastNotification.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/view/PodcastNotification.java @@ -100,6 +100,8 @@ public class PodcastNotification { //.addAction(android.R.drawable.ic_media_pause, "More", resultPendingIntent) } - - + public void cancel() + { + notificationManager.cancel(NOTIFICATION_ID); + } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetTodoViewsFactory.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetTodoViewsFactory.java index 74bb5792..555462f4 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetTodoViewsFactory.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetTodoViewsFactory.java @@ -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; diff --git a/News-Android-App/src/main/res/values-fr/strings.xml b/News-Android-App/src/main/res/values-fr/strings.xml index 7fb75107..7f0e8a1c 100644 --- a/News-Android-App/src/main/res/values-fr/strings.xml +++ b/News-Android-App/src/main/res/values-fr/strings.xml @@ -5,8 +5,8 @@ Sélecteur d\'intervalle de synchronisation Activité de détail d’article Activité d’abonnement - Lecteur d\'actualités - Détail du lecteur d\'actualités + Lecteur de news + Détail du lecteur de news Information Aucun article Téléchargement d\'articles supplémentaire en cours... Veuillez patienter. diff --git a/News-Android-App/src/main/res/values-sr/strings.xml b/News-Android-App/src/main/res/values-sr/strings.xml index 31721688..7f1b683d 100644 --- a/News-Android-App/src/main/res/values-sr/strings.xml +++ b/News-Android-App/src/main/res/values-sr/strings.xml @@ -3,6 +3,7 @@ Ауто-синхронизација ОунКлауд читач вести Избор размака синхронизације + Активност о детаљима вести Активност претплаћивања Читач новости Детаљи читача diff --git a/News-Android-App/src/main/res/values/colors.xml b/News-Android-App/src/main/res/values/colors.xml index d4818547..d9130069 100644 --- a/News-Android-App/src/main/res/values/colors.xml +++ b/News-Android-App/src/main/res/values/colors.xml @@ -17,6 +17,7 @@ #ff343434 #ffdcdcdc + @drawable/options_menu_item_color #212121 diff --git a/News-Android-App/src/main/res/values/themes.xml b/News-Android-App/src/main/res/values/themes.xml index d08c291e..517f3c6e 100644 --- a/News-Android-App/src/main/res/values/themes.xml +++ b/News-Android-App/src/main/res/values/themes.xml @@ -30,7 +30,7 @@ diff --git a/local.properties b/local.properties deleted file mode 100644 index a0ee113a..00000000 --- a/local.properties +++ /dev/null @@ -1,11 +0,0 @@ -## This file is automatically generated by Android Studio. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# Location of the SDK. This is only used by Gradle. -# For customization when using a Version Control System, please read the -# header note. -#Sat Nov 01 03:37:25 CET 2014 -sdk.dir=C\:\\Program Files\\Android\\android-sdk