code cleanup

offline: support feed title in vfeeds
This commit is contained in:
Andrew Dolgov 2012-06-22 15:37:08 +04:00
parent c1d452a97d
commit fafdd4120a
15 changed files with 46 additions and 104 deletions

View File

@ -1,6 +1,5 @@
package org.fox.ttrss; package org.fox.ttrss;
import java.io.File;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -16,7 +15,6 @@ import org.jsoup.select.Elements;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
@ -25,23 +23,19 @@ import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
public class ArticleFragment extends Fragment { public class ArticleFragment extends Fragment {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -86,25 +80,6 @@ public class ArticleFragment extends Fragment {
View view = inflater.inflate(R.layout.article_fragment, container, false); 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) { if (m_article != null) {
TextView title = (TextView)view.findViewById(R.id.title); TextView title = (TextView)view.findViewById(R.id.title);

View File

@ -8,7 +8,6 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;

View File

@ -17,13 +17,11 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;

View File

@ -1,6 +1,5 @@
package org.fox.ttrss; package org.fox.ttrss;
import java.io.File;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;

View File

@ -1187,6 +1187,10 @@ public class OfflineActivity extends FragmentActivity implements
} }
@Override @Override
public void onFeedSelected(int feedId) {
viewFeed(feedId);
}
public void viewFeed(int feedId) { public void viewFeed(int feedId) {
viewFeed(feedId, false); viewFeed(feedId, false);
} }
@ -1291,4 +1295,9 @@ public class OfflineActivity extends FragmentActivity implements
refreshViews(); refreshViews();
} }
@Override
public boolean activeFeedIsCat() {
return m_activeFeedIsCat;
}
} }

View File

@ -4,10 +4,6 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import org.fox.ttrss.R; 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.fox.ttrss.util.ImageCacheService;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -25,10 +21,10 @@ import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.TextView; import android.widget.TextView;
@ -71,28 +67,8 @@ public class OfflineArticleFragment extends Fragment {
View view = inflater.inflate(R.layout.article_fragment, container, false); View view = inflater.inflate(R.layout.article_fragment, container, false);
m_cursor = m_offlineServices.getReadableDb().query("articles LEFT JOIN feeds ON (feed_id = feeds."+BaseColumns._ID+")",
// TODO change to interface? new String[] { "articles.*", "feeds.title AS feed_title" }, "articles." + BaseColumns._ID + "=?",
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 + "=?",
new String[] { String.valueOf(m_articleId) }, null, null, null); new String[] { String.valueOf(m_articleId) }, null, null, null);
m_cursor.moveToFirst(); m_cursor.moveToFirst();
@ -220,10 +196,16 @@ public class OfflineArticleFragment extends Fragment {
TextView tagv = (TextView)view.findViewById(R.id.tags); TextView tagv = (TextView)view.findViewById(R.id.tags);
if (tagv != null) { if (tagv != null) {
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")); String tagsStr = m_cursor.getString(m_cursor.getColumnIndex("tags"));
tagv.setText(tagsStr); tagv.setText(tagsStr);
} }
} }
}
return view; return view;
} }

View File

@ -1,11 +1,8 @@
package org.fox.ttrss.offline; package org.fox.ttrss.offline;
import org.fox.ttrss.R; import org.fox.ttrss.R;
import org.fox.ttrss.R.id;
import org.fox.ttrss.R.layout;
import android.app.Activity; import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement; import android.database.sqlite.SQLiteStatement;
import android.os.Bundle; import android.os.Bundle;
import android.provider.BaseColumns; import android.provider.BaseColumns;

View File

@ -7,8 +7,6 @@ import java.util.List;
import org.fox.ttrss.ApiRequest; import org.fox.ttrss.ApiRequest;
import org.fox.ttrss.MainActivity; import org.fox.ttrss.MainActivity;
import org.fox.ttrss.R; 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.Article;
import org.fox.ttrss.types.Feed; import org.fox.ttrss.types.Feed;
import org.fox.ttrss.types.FeedCategory; import org.fox.ttrss.types.FeedCategory;
@ -21,7 +19,6 @@ import org.jsoup.select.Elements;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo; import android.app.ActivityManager.RunningServiceInfo;
import android.app.IntentService;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
@ -32,8 +29,6 @@ import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement; import android.database.sqlite.SQLiteStatement;
import android.os.Binder; import android.os.Binder;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder; import android.os.IBinder;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.BaseColumns; import android.provider.BaseColumns;

View File

@ -1,22 +1,13 @@
package org.fox.ttrss.offline; package org.fox.ttrss.offline;
import java.io.File;
import org.fox.ttrss.R; 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.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.BaseColumns; import android.provider.BaseColumns;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;

View File

@ -3,10 +3,6 @@ package org.fox.ttrss.offline;
import java.io.File; import java.io.File;
import org.fox.ttrss.R; 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.app.Activity;
import android.content.Context; import android.content.Context;
@ -159,7 +155,7 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene
int feedId = (int) cursor.getLong(0); int feedId = (int) cursor.getLong(0);
Log.d(TAG, "clicked on feed " + feedId); Log.d(TAG, "clicked on feed " + feedId);
m_offlineServices.viewFeed(feedId); m_offlineServices.onFeedSelected(feedId);
if (!m_offlineServices.isSmallScreen()) if (!m_offlineServices.isSmallScreen())
m_selectedFeedId = feedId; m_selectedFeedId = feedId;

View File

@ -6,11 +6,6 @@ import java.util.Date;
import java.util.TimeZone; import java.util.TimeZone;
import org.fox.ttrss.R; 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 org.jsoup.Jsoup;
import android.app.Activity; import android.app.Activity;
@ -172,11 +167,13 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
} }
if (m_searchQuery.equals("")) { if (m_searchQuery.equals("")) {
return m_offlineServices.getReadableDb().query("articles", return m_offlineServices.getReadableDb().query("articles LEFT JOIN feeds ON (feed_id = feeds."+BaseColumns._ID+")",
null, feedClause, new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC"); new String[] { "articles.*", "feeds.title AS feed_title" }, feedClause,
new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC");
} else { } else {
return m_offlineServices.getReadableDb().query("articles", return m_offlineServices.getReadableDb().query("articles LEFT JOIN feeds ON (feed_id = feeds."+BaseColumns._ID+")",
null, feedClause + " AND (title LIKE '%' || ? || '%' OR content LIKE '%' || ? || '%')", 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"); 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); 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); ft.setVisibility(View.GONE);
} }

View File

@ -1,7 +1,6 @@
package org.fox.ttrss.offline; package org.fox.ttrss.offline;
import org.fox.ttrss.OnlineServices; import org.fox.ttrss.OnlineServices;
import org.fox.ttrss.OnlineServices.RelativeArticle;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
@ -10,7 +9,7 @@ public interface OfflineServices {
public SQLiteDatabase getReadableDb(); public SQLiteDatabase getReadableDb();
public SQLiteDatabase getWritableDb(); public SQLiteDatabase getWritableDb();
public int getRelativeArticleId(int baseId, int feedId, OnlineServices.RelativeArticle mode); 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 onCatSelected(int catId);
public void openArticle(int articleId, int compatAnimation); public void openArticle(int articleId, int compatAnimation);
public boolean getUnreadOnly(); public boolean getUnreadOnly();
@ -18,4 +17,5 @@ public interface OfflineServices {
public void initMainMenu(); public void initMainMenu();
public boolean isSmallScreen(); public boolean isSmallScreen();
public void setSelectedArticleId(int articleId); public void setSelectedArticleId(int articleId);
public boolean activeFeedIsCat();
} }

View File

@ -5,12 +5,8 @@ import java.util.HashMap;
import org.fox.ttrss.ApiRequest; import org.fox.ttrss.ApiRequest;
import org.fox.ttrss.MainActivity; import org.fox.ttrss.MainActivity;
import org.fox.ttrss.R; import org.fox.ttrss.R;
import org.fox.ttrss.R.drawable;
import org.fox.ttrss.R.string;
import org.fox.ttrss.util.DatabaseHelper; import org.fox.ttrss.util.DatabaseHelper;
import com.google.gson.JsonElement;
import android.app.IntentService; import android.app.IntentService;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
@ -20,6 +16,8 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.util.Log; import android.util.Log;
import com.google.gson.JsonElement;
public class OfflineUploadService extends IntentService { public class OfflineUploadService extends IntentService {
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();

View File

@ -7,7 +7,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;

View File

@ -12,19 +12,16 @@ import java.util.Date;
import org.fox.ttrss.MainActivity; import org.fox.ttrss.MainActivity;
import org.fox.ttrss.R; import org.fox.ttrss.R;
import org.fox.ttrss.R.drawable;
import org.fox.ttrss.R.string;
import org.fox.ttrss.offline.OfflineDownloadService; import org.fox.ttrss.offline.OfflineDownloadService;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.IntentService; import android.app.IntentService;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Intent; import android.content.Intent;
import android.os.Environment; import android.os.Environment;
import android.util.Log;
public class ImageCacheService extends IntentService { public class ImageCacheService extends IntentService {
@ -141,9 +138,9 @@ public class ImageCacheService extends IntentService {
m_nmgr.notify(NOTIFY_DOWNLOADING, notification); m_nmgr.notify(NOTIFY_DOWNLOADING, notification);
} }
private void updateNotification(int msgResId) { /* private void updateNotification(int msgResId) {
updateNotification(getString(msgResId)); updateNotification(getString(msgResId));
} } */
@Override @Override
protected void onHandleIntent(Intent intent) { protected void onHandleIntent(Intent intent) {