From fafdd4120ae03da71ea1ee849eb6a8bb8102660e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 22 Jun 2012 15:37:08 +0400 Subject: [PATCH] code cleanup offline: support feed title in vfeeds --- src/org/fox/ttrss/ArticleFragment.java | 27 +------------ src/org/fox/ttrss/ArticlePager.java | 1 - src/org/fox/ttrss/FeedCategoriesFragment.java | 2 - src/org/fox/ttrss/HeadlinesFragment.java | 1 - .../fox/ttrss/offline/OfflineActivity.java | 9 +++++ .../ttrss/offline/OfflineArticleFragment.java | 40 +++++-------------- .../ttrss/offline/OfflineArticlePager.java | 3 -- .../ttrss/offline/OfflineDownloadService.java | 5 --- .../OfflineFeedCategoriesFragment.java | 9 ----- .../ttrss/offline/OfflineFeedsFragment.java | 6 +-- .../offline/OfflineHeadlinesFragment.java | 27 ++++++++----- .../fox/ttrss/offline/OfflineServices.java | 4 +- .../ttrss/offline/OfflineUploadService.java | 6 +-- src/org/fox/ttrss/util/AppRater.java | 1 - src/org/fox/ttrss/util/ImageCacheService.java | 9 ++--- 15 files changed, 46 insertions(+), 104 deletions(-) diff --git a/src/org/fox/ttrss/ArticleFragment.java b/src/org/fox/ttrss/ArticleFragment.java index 8ad8eab0..09bd0680 100644 --- a/src/org/fox/ttrss/ArticleFragment.java +++ b/src/org/fox/ttrss/ArticleFragment.java @@ -1,6 +1,5 @@ package org.fox.ttrss; -import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.text.SimpleDateFormat; @@ -16,7 +15,6 @@ import org.jsoup.select.Elements; import android.annotation.SuppressLint; import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; @@ -25,23 +23,19 @@ import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.text.Html; import android.text.method.LinkMovementMethod; -import android.util.Log; import android.util.TypedValue; import android.view.ContextMenu; +import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.view.ContextMenu.ContextMenuInfo; import android.webkit.WebSettings; import android.webkit.WebView; -import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.Spinner; import android.widget.TextView; -import android.widget.Toast; -import android.widget.AdapterView.AdapterContextMenuInfo; public class ArticleFragment extends Fragment { @SuppressWarnings("unused") @@ -86,25 +80,6 @@ public class ArticleFragment extends Fragment { View view = inflater.inflate(R.layout.article_fragment, container, false); - Activity activity = (Activity)getActivity(); - - /* if (activity != null) { - int orientation = activity.getWindowManager().getDefaultDisplay().getOrientation(); - - if (!m_onlineServices.isSmallScreen()) { - if (orientation % 2 == 0) { - view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE); - } else { - view.findViewById(R.id.splitter_vertical).setVisibility(View.GONE); - } - } else { - view.findViewById(R.id.splitter_vertical).setVisibility(View.GONE); - view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE); - } - } else { - view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE); - } */ - if (m_article != null) { TextView title = (TextView)view.findViewById(R.id.title); diff --git a/src/org/fox/ttrss/ArticlePager.java b/src/org/fox/ttrss/ArticlePager.java index b31a6ae5..3027d61b 100644 --- a/src/org/fox/ttrss/ArticlePager.java +++ b/src/org/fox/ttrss/ArticlePager.java @@ -8,7 +8,6 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/src/org/fox/ttrss/FeedCategoriesFragment.java b/src/org/fox/ttrss/FeedCategoriesFragment.java index 9b105b31..7dc7714e 100644 --- a/src/org/fox/ttrss/FeedCategoriesFragment.java +++ b/src/org/fox/ttrss/FeedCategoriesFragment.java @@ -17,13 +17,11 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; -import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.Window; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index 1bfdeb40..cb6effec 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -1,6 +1,5 @@ package org.fox.ttrss; -import java.io.File; import java.lang.reflect.Type; import java.net.MalformedURLException; import java.net.URL; diff --git a/src/org/fox/ttrss/offline/OfflineActivity.java b/src/org/fox/ttrss/offline/OfflineActivity.java index 6f507da5..62c6d08e 100644 --- a/src/org/fox/ttrss/offline/OfflineActivity.java +++ b/src/org/fox/ttrss/offline/OfflineActivity.java @@ -1187,6 +1187,10 @@ public class OfflineActivity extends FragmentActivity implements } @Override + public void onFeedSelected(int feedId) { + viewFeed(feedId); + } + public void viewFeed(int feedId) { viewFeed(feedId, false); } @@ -1291,4 +1295,9 @@ public class OfflineActivity extends FragmentActivity implements refreshViews(); } + + @Override + public boolean activeFeedIsCat() { + return m_activeFeedIsCat; + } } \ No newline at end of file diff --git a/src/org/fox/ttrss/offline/OfflineArticleFragment.java b/src/org/fox/ttrss/offline/OfflineArticleFragment.java index 790963fb..bfeb094c 100644 --- a/src/org/fox/ttrss/offline/OfflineArticleFragment.java +++ b/src/org/fox/ttrss/offline/OfflineArticleFragment.java @@ -4,10 +4,6 @@ import java.text.SimpleDateFormat; import java.util.Date; import org.fox.ttrss.R; -import org.fox.ttrss.R.attr; -import org.fox.ttrss.R.id; -import org.fox.ttrss.R.layout; -import org.fox.ttrss.R.menu; import org.fox.ttrss.util.ImageCacheService; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -25,10 +21,10 @@ import android.text.Html; import android.text.method.LinkMovementMethod; import android.util.TypedValue; import android.view.ContextMenu; +import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.ContextMenu.ContextMenuInfo; import android.webkit.WebSettings; import android.webkit.WebView; import android.widget.TextView; @@ -71,28 +67,8 @@ public class OfflineArticleFragment extends Fragment { View view = inflater.inflate(R.layout.article_fragment, container, false); - - // TODO change to interface? - Activity activity = getActivity(); - - /* if (activity != null) { - int orientation = activity.getWindowManager().getDefaultDisplay().getOrientation(); - - if (!m_offlineServices.isSmallScreen()) { - if (orientation % 2 == 0) { - view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE); - } else { - view.findViewById(R.id.splitter_vertical).setVisibility(View.GONE); - } - } else { - view.findViewById(R.id.splitter_vertical).setVisibility(View.GONE); - view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE); - } - } else { - view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE); - } */ - - m_cursor = m_offlineServices.getReadableDb().query("articles", null, BaseColumns._ID + "=?", + m_cursor = m_offlineServices.getReadableDb().query("articles LEFT JOIN feeds ON (feed_id = feeds."+BaseColumns._ID+")", + new String[] { "articles.*", "feeds.title AS feed_title" }, "articles." + BaseColumns._ID + "=?", new String[] { String.valueOf(m_articleId) }, null, null, null); m_cursor.moveToFirst(); @@ -220,8 +196,14 @@ public class OfflineArticleFragment extends Fragment { TextView tagv = (TextView)view.findViewById(R.id.tags); if (tagv != null) { - String tagsStr = m_cursor.getString(m_cursor.getColumnIndex("tags")); - tagv.setText(tagsStr); + int feedTitleIndex = m_cursor.getColumnIndex("feed_title"); + + if (feedTitleIndex != -1 && m_offlineServices.activeFeedIsCat()) { + tagv.setText(m_cursor.getString(feedTitleIndex)); + } else { + String tagsStr = m_cursor.getString(m_cursor.getColumnIndex("tags")); + tagv.setText(tagsStr); + } } } diff --git a/src/org/fox/ttrss/offline/OfflineArticlePager.java b/src/org/fox/ttrss/offline/OfflineArticlePager.java index ec3b86c1..104d9f4f 100644 --- a/src/org/fox/ttrss/offline/OfflineArticlePager.java +++ b/src/org/fox/ttrss/offline/OfflineArticlePager.java @@ -1,11 +1,8 @@ package org.fox.ttrss.offline; import org.fox.ttrss.R; -import org.fox.ttrss.R.id; -import org.fox.ttrss.R.layout; import android.app.Activity; -import android.database.Cursor; import android.database.sqlite.SQLiteStatement; import android.os.Bundle; import android.provider.BaseColumns; diff --git a/src/org/fox/ttrss/offline/OfflineDownloadService.java b/src/org/fox/ttrss/offline/OfflineDownloadService.java index 15477033..b757082f 100644 --- a/src/org/fox/ttrss/offline/OfflineDownloadService.java +++ b/src/org/fox/ttrss/offline/OfflineDownloadService.java @@ -7,8 +7,6 @@ import java.util.List; import org.fox.ttrss.ApiRequest; import org.fox.ttrss.MainActivity; import org.fox.ttrss.R; -import org.fox.ttrss.R.drawable; -import org.fox.ttrss.R.string; import org.fox.ttrss.types.Article; import org.fox.ttrss.types.Feed; import org.fox.ttrss.types.FeedCategory; @@ -21,7 +19,6 @@ import org.jsoup.select.Elements; import android.app.ActivityManager; import android.app.ActivityManager.RunningServiceInfo; -import android.app.IntentService; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; @@ -32,8 +29,6 @@ import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteStatement; import android.os.Binder; -import android.os.Bundle; -import android.os.Environment; import android.os.IBinder; import android.preference.PreferenceManager; import android.provider.BaseColumns; diff --git a/src/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java b/src/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java index 13b28f53..6fc1adf1 100644 --- a/src/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java +++ b/src/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java @@ -1,22 +1,13 @@ package org.fox.ttrss.offline; -import java.io.File; - import org.fox.ttrss.R; -import org.fox.ttrss.R.drawable; -import org.fox.ttrss.R.id; -import org.fox.ttrss.R.layout; -import org.fox.ttrss.R.menu; import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.database.Cursor; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.os.Bundle; -import android.os.Environment; import android.preference.PreferenceManager; import android.provider.BaseColumns; import android.support.v4.app.Fragment; diff --git a/src/org/fox/ttrss/offline/OfflineFeedsFragment.java b/src/org/fox/ttrss/offline/OfflineFeedsFragment.java index ee91eb5b..762e1081 100644 --- a/src/org/fox/ttrss/offline/OfflineFeedsFragment.java +++ b/src/org/fox/ttrss/offline/OfflineFeedsFragment.java @@ -3,10 +3,6 @@ package org.fox.ttrss.offline; import java.io.File; import org.fox.ttrss.R; -import org.fox.ttrss.R.drawable; -import org.fox.ttrss.R.id; -import org.fox.ttrss.R.layout; -import org.fox.ttrss.R.menu; import android.app.Activity; import android.content.Context; @@ -159,7 +155,7 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene int feedId = (int) cursor.getLong(0); Log.d(TAG, "clicked on feed " + feedId); - m_offlineServices.viewFeed(feedId); + m_offlineServices.onFeedSelected(feedId); if (!m_offlineServices.isSmallScreen()) m_selectedFeedId = feedId; diff --git a/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java b/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java index d25c7b65..6dc9b94d 100644 --- a/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java +++ b/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java @@ -6,11 +6,6 @@ import java.util.Date; import java.util.TimeZone; import org.fox.ttrss.R; -import org.fox.ttrss.R.drawable; -import org.fox.ttrss.R.id; -import org.fox.ttrss.R.layout; -import org.fox.ttrss.R.menu; -import org.fox.ttrss.R.string; import org.jsoup.Jsoup; import android.app.Activity; @@ -172,11 +167,13 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis } if (m_searchQuery.equals("")) { - return m_offlineServices.getReadableDb().query("articles", - null, feedClause, new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC"); + return m_offlineServices.getReadableDb().query("articles LEFT JOIN feeds ON (feed_id = feeds."+BaseColumns._ID+")", + new String[] { "articles.*", "feeds.title AS feed_title" }, feedClause, + new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC"); } else { - return m_offlineServices.getReadableDb().query("articles", - null, feedClause + " AND (title LIKE '%' || ? || '%' OR content LIKE '%' || ? || '%')", + return m_offlineServices.getReadableDb().query("articles LEFT JOIN feeds ON (feed_id = feeds."+BaseColumns._ID+")", + new String[] { "articles.*", "feeds.title AS feed_title" }, + feedClause + " AND (articles.title LIKE '%' || ? || '%' OR content LIKE '%' || ? || '%')", new String[] { String.valueOf(m_feedId), m_searchQuery, m_searchQuery }, null, null, "updated DESC"); } } @@ -318,7 +315,17 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis TextView ft = (TextView)v.findViewById(R.id.feed_title); - if (ft != null) { + int feedTitleIndex = article.getColumnIndex("feed_title"); + + if (ft != null && feedTitleIndex != -1 && m_feedIsCat) { + String feedTitle = article.getString(feedTitleIndex); + + if (feedTitle != null) { + ft.setText(feedTitle); + } else { + ft.setVisibility(View.GONE); + } + } else { ft.setVisibility(View.GONE); } diff --git a/src/org/fox/ttrss/offline/OfflineServices.java b/src/org/fox/ttrss/offline/OfflineServices.java index b75d75a4..993fb250 100644 --- a/src/org/fox/ttrss/offline/OfflineServices.java +++ b/src/org/fox/ttrss/offline/OfflineServices.java @@ -1,7 +1,6 @@ package org.fox.ttrss.offline; import org.fox.ttrss.OnlineServices; -import org.fox.ttrss.OnlineServices.RelativeArticle; import android.database.sqlite.SQLiteDatabase; @@ -10,7 +9,7 @@ public interface OfflineServices { public SQLiteDatabase getReadableDb(); public SQLiteDatabase getWritableDb(); public int getRelativeArticleId(int baseId, int feedId, OnlineServices.RelativeArticle mode); - public void viewFeed(int feedId); + public void onFeedSelected(int feedId); public void onCatSelected(int catId); public void openArticle(int articleId, int compatAnimation); public boolean getUnreadOnly(); @@ -18,4 +17,5 @@ public interface OfflineServices { public void initMainMenu(); public boolean isSmallScreen(); public void setSelectedArticleId(int articleId); + public boolean activeFeedIsCat(); } diff --git a/src/org/fox/ttrss/offline/OfflineUploadService.java b/src/org/fox/ttrss/offline/OfflineUploadService.java index 54446669..84a7fc92 100644 --- a/src/org/fox/ttrss/offline/OfflineUploadService.java +++ b/src/org/fox/ttrss/offline/OfflineUploadService.java @@ -5,12 +5,8 @@ import java.util.HashMap; import org.fox.ttrss.ApiRequest; import org.fox.ttrss.MainActivity; import org.fox.ttrss.R; -import org.fox.ttrss.R.drawable; -import org.fox.ttrss.R.string; import org.fox.ttrss.util.DatabaseHelper; -import com.google.gson.JsonElement; - import android.app.IntentService; import android.app.Notification; import android.app.NotificationManager; @@ -20,6 +16,8 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.util.Log; +import com.google.gson.JsonElement; + public class OfflineUploadService extends IntentService { private final String TAG = this.getClass().getSimpleName(); diff --git a/src/org/fox/ttrss/util/AppRater.java b/src/org/fox/ttrss/util/AppRater.java index a50cc9d9..5b410b69 100644 --- a/src/org/fox/ttrss/util/AppRater.java +++ b/src/org/fox/ttrss/util/AppRater.java @@ -7,7 +7,6 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; -import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; diff --git a/src/org/fox/ttrss/util/ImageCacheService.java b/src/org/fox/ttrss/util/ImageCacheService.java index 1541c249..25c4aff0 100644 --- a/src/org/fox/ttrss/util/ImageCacheService.java +++ b/src/org/fox/ttrss/util/ImageCacheService.java @@ -12,19 +12,16 @@ import java.util.Date; import org.fox.ttrss.MainActivity; import org.fox.ttrss.R; -import org.fox.ttrss.R.drawable; -import org.fox.ttrss.R.string; import org.fox.ttrss.offline.OfflineDownloadService; import android.app.ActivityManager; +import android.app.ActivityManager.RunningServiceInfo; import android.app.IntentService; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; -import android.app.ActivityManager.RunningServiceInfo; import android.content.Intent; import android.os.Environment; -import android.util.Log; public class ImageCacheService extends IntentService { @@ -141,9 +138,9 @@ public class ImageCacheService extends IntentService { m_nmgr.notify(NOTIFY_DOWNLOADING, notification); } - private void updateNotification(int msgResId) { + /* private void updateNotification(int msgResId) { updateNotification(getString(msgResId)); - } + } */ @Override protected void onHandleIntent(Intent intent) {