diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index 81187fa0..27c46108 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -1,13 +1,10 @@ package org.fox.ttrss; -import java.lang.reflect.Type; -import android.app.ActionBar; import java.util.HashMap; import java.util.List; import java.util.Timer; import java.util.TimerTask; -import android.app.ActionBar.Tab; import android.app.AlertDialog; import android.app.Dialog; import android.content.BroadcastReceiver; @@ -21,13 +18,11 @@ import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteStatement; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.os.IBinder; import android.preference.PreferenceManager; -import android.provider.BaseColumns; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTransaction; import android.util.Log; @@ -42,10 +37,8 @@ import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.LinearLayout; import android.widget.TextView; -import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; public class MainActivity extends FragmentActivity implements OnlineServices { private final String TAG = this.getClass().getSimpleName(); @@ -324,7 +317,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { } } - public synchronized void refreshFeeds() { + private synchronized void refreshFeeds() { if (m_sessionId != null) { FeedsFragment frag = (FeedsFragment) getSupportFragmentManager() .findFragmentById(R.id.feeds_fragment); @@ -337,7 +330,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { } } - public synchronized void refreshHeadlines() { + private synchronized void refreshHeadlines() { if (m_sessionId != null) { HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager() .findFragmentById(R.id.headlines_fragment); @@ -350,7 +343,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { } } - public synchronized void refreshCategories() { + private synchronized void refreshCategories() { if (m_sessionId != null) { FeedCategoriesFragment frag = (FeedCategoriesFragment) getSupportFragmentManager() .findFragmentById(R.id.cats_fragment); diff --git a/src/org/fox/ttrss/OfflineArticleFragment.java b/src/org/fox/ttrss/OfflineArticleFragment.java index 77033259..77fae9a0 100644 --- a/src/org/fox/ttrss/OfflineArticleFragment.java +++ b/src/org/fox/ttrss/OfflineArticleFragment.java @@ -38,6 +38,7 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener private GestureDetector m_gestureDetector; private View.OnTouchListener m_gestureListener; private Cursor m_cursor; + private OfflineServices m_offlineServices; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -62,12 +63,12 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener // TODO change to interface? - OfflineActivity activity = (OfflineActivity)getActivity(); + Activity activity = getActivity(); if (activity != null) { int orientation = activity.getWindowManager().getDefaultDisplay().getOrientation(); - if (!activity.isSmallScreen()) { + if (!m_offlineServices.isSmallScreen()) { if (orientation % 2 == 0) { view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE); } else { @@ -81,7 +82,7 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE); } - m_cursor = ((OfflineActivity)getActivity()).getReadableDb().query("articles", null, BaseColumns._ID + "=?", + m_cursor = m_offlineServices.getReadableDb().query("articles", null, BaseColumns._ID + "=?", new String[] { String.valueOf(m_articleId) }, null, null, null); m_cursor.moveToFirst(); @@ -137,7 +138,7 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener web.loadDataWithBaseURL(null, content, "text/html", "utf-8", null); - if (activity.isSmallScreen()) + if (m_offlineServices.isSmallScreen()) web.setOnTouchListener(m_gestureListener); } @@ -210,20 +211,20 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); - OfflineActivity oa = (OfflineActivity)activity; + m_offlineServices = (OfflineServices)activity; - m_articleId = oa.getSelectedArticleId(); + m_articleId = m_offlineServices.getSelectedArticleId(); - m_prevArticleId = oa.getRelativeArticleId(m_articleId, oa.getActiveFeedId(), RelativeArticle.BEFORE); - m_nextArticleId = oa.getRelativeArticleId(m_articleId, oa.getActiveFeedId(), RelativeArticle.AFTER); + m_prevArticleId = m_offlineServices.getRelativeArticleId(m_articleId, m_offlineServices.getActiveFeedId(), RelativeArticle.BEFORE); + m_nextArticleId = m_offlineServices.getRelativeArticleId(m_articleId, m_offlineServices.getActiveFeedId(), RelativeArticle.AFTER); } @Override public void onClick(View v) { if (v.getId() == R.id.next_article) { - ((OfflineActivity)getActivity()).openArticle(m_nextArticleId, 0); + m_offlineServices.openArticle(m_nextArticleId, 0); } else if (v.getId() == R.id.prev_article) { - ((OfflineActivity)getActivity()).openArticle(m_prevArticleId, R.anim.slide_right); + m_offlineServices.openArticle(m_prevArticleId, R.anim.slide_right); } } @@ -244,13 +245,13 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener //Log.d(TAG, "Right swipe"); if (m_prevArticleId != 0) - ((OfflineActivity)getActivity()).openArticle(m_prevArticleId, 0); + m_offlineServices.openArticle(m_prevArticleId, 0); } else { //Log.d(TAG, "Left swipe"); if (m_nextArticleId != 0) - ((OfflineActivity)getActivity()).openArticle(m_nextArticleId, 0); + m_offlineServices.openArticle(m_nextArticleId, 0); } return true; diff --git a/src/org/fox/ttrss/OfflineDownloadService.java b/src/org/fox/ttrss/OfflineDownloadService.java index 4a0550ab..55dacced 100644 --- a/src/org/fox/ttrss/OfflineDownloadService.java +++ b/src/org/fox/ttrss/OfflineDownloadService.java @@ -4,14 +4,11 @@ import java.lang.reflect.Type; import java.util.HashMap; import java.util.List; -import android.app.AlertDialog; -import android.app.Dialog; import android.app.IntentService; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteStatement; @@ -117,6 +114,7 @@ public class OfflineDownloadService extends IntentService { OfflineArticlesRequest req = new OfflineArticlesRequest(this); + @SuppressWarnings("serial") HashMap map = new HashMap() { { put("op", "getHeadlines"); @@ -191,6 +189,7 @@ public class OfflineDownloadService extends IntentService { }; + @SuppressWarnings("serial") HashMap map = new HashMap() { { put("op", "getFeeds"); diff --git a/src/org/fox/ttrss/OfflineFeedsFragment.java b/src/org/fox/ttrss/OfflineFeedsFragment.java index 7c866bfe..34a71b17 100644 --- a/src/org/fox/ttrss/OfflineFeedsFragment.java +++ b/src/org/fox/ttrss/OfflineFeedsFragment.java @@ -36,6 +36,7 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene private int m_selectedFeedId; private boolean m_enableFeedIcons; private Cursor m_cursor; + private OfflineServices m_offlineServices; @Override public void onCreateContextMenu(ContextMenu menu, View v, @@ -54,11 +55,11 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene } public Cursor createCursor() { - String unreadOnly = ((OfflineActivity)getActivity()).getUnreadOnly() ? "unread > 0" : null; + String unreadOnly = m_offlineServices.getUnreadOnly() ? "unread > 0" : null; String order = m_prefs.getBoolean("sort_feeds_by_unread", false) ? "unread DESC, title" : "title"; - return ((OfflineActivity)getActivity()).getReadableDb().query("feeds_unread", + return m_offlineServices.getReadableDb().query("feeds_unread", null, unreadOnly, null, null, null, order); } @@ -110,7 +111,9 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene @Override public void onAttach(Activity activity) { - super.onAttach(activity); + super.onAttach(activity); + + m_offlineServices = (OfflineServices)activity; m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); m_prefs.registerOnSharedPreferenceChangeListener(this); @@ -135,7 +138,7 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene int feedId = (int) cursor.getLong(0); Log.d(TAG, "clicked on feed " + feedId); - ((OfflineActivity)getActivity()).viewFeed(feedId); + m_offlineServices.viewFeed(feedId); m_selectedFeedId = feedId; diff --git a/src/org/fox/ttrss/OfflineHeadlinesFragment.java b/src/org/fox/ttrss/OfflineHeadlinesFragment.java index ed28c320..cf2b6ebd 100644 --- a/src/org/fox/ttrss/OfflineHeadlinesFragment.java +++ b/src/org/fox/ttrss/OfflineHeadlinesFragment.java @@ -51,6 +51,8 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis private Cursor m_cursor; private ArticleListAdapter m_adapter; + private OfflineServices m_offlineServices; + private ImageGetter m_dummyGetter = new ImageGetter() { @Override @@ -68,7 +70,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis } public int getSelectedArticleCount() { - Cursor c = ((OfflineActivity)getActivity()).getReadableDb().query("articles", + Cursor c = m_offlineServices.getReadableDb().query("articles", new String[] { "COUNT(*)" }, "selected = 1", null, null, null, null); c.moveToFirst(); int selected = c.getInt(0); @@ -138,14 +140,16 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis } public Cursor createCursor() { - return ((OfflineActivity)getActivity()).getReadableDb().query("articles", + return m_offlineServices.getReadableDb().query("articles", null, "feed_id = ?", new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC"); } @Override public void onAttach(Activity activity) { super.onAttach(activity); - m_feedId = ((OfflineActivity)activity).getActiveFeedId(); + m_offlineServices = (OfflineServices)activity; + + m_feedId = m_offlineServices.getActiveFeedId(); m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); m_combinedMode = m_prefs.getBoolean("combined_mode", false); } @@ -161,7 +165,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis m_activeArticleId = cursor.getInt(0); - SQLiteStatement stmtUpdate = ((OfflineActivity)getActivity()).getWritableDb().compileStatement("UPDATE articles SET unread = 0 " + + SQLiteStatement stmtUpdate = m_offlineServices.getWritableDb().compileStatement("UPDATE articles SET unread = 0 " + "WHERE " + BaseColumns._ID + " = ?"); stmtUpdate.bindLong(1, m_activeArticleId); @@ -169,7 +173,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis stmtUpdate.close(); if (!m_combinedMode) { - ((OfflineActivity)getActivity()).openArticle(m_activeArticleId, 0); + m_offlineServices.openArticle(m_activeArticleId, 0); } refresh(); @@ -285,7 +289,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis @Override public void onClick(View v) { - SQLiteStatement stmtUpdate = ((OfflineActivity)getActivity()).getWritableDb().compileStatement("UPDATE articles SET marked = NOT marked " + + SQLiteStatement stmtUpdate = m_offlineServices.getWritableDb().compileStatement("UPDATE articles SET marked = NOT marked " + "WHERE " + BaseColumns._ID + " = ?"); stmtUpdate.bindLong(1, articleId); @@ -306,7 +310,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis @Override public void onClick(View v) { - SQLiteStatement stmtUpdate = ((OfflineActivity)getActivity()).getWritableDb().compileStatement("UPDATE articles SET published = NOT published " + + SQLiteStatement stmtUpdate = m_offlineServices.getWritableDb().compileStatement("UPDATE articles SET published = NOT published " + "WHERE " + BaseColumns._ID + " = ?"); stmtUpdate.bindLong(1, articleId); @@ -366,7 +370,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis public void onClick(View view) { CheckBox cb = (CheckBox)view; - SQLiteStatement stmtUpdate = ((OfflineActivity)getActivity()).getWritableDb().compileStatement("UPDATE articles SET selected = ? " + + SQLiteStatement stmtUpdate = m_offlineServices.getWritableDb().compileStatement("UPDATE articles SET selected = ? " + "WHERE " + BaseColumns._ID + " = ?"); stmtUpdate.bindLong(1, cb.isChecked() ? 1 : 0); @@ -376,7 +380,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis refresh(); - ((OfflineActivity)getActivity()).initMainMenu(); + m_offlineServices.initMainMenu(); } });