diff --git a/.classpath b/.classpath index 05a903b5..3356ec9f 100644 --- a/.classpath +++ b/.classpath @@ -5,7 +5,7 @@ - + diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6bfa76ba..fdab6e89 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,10 +1,10 @@ + android:versionCode="73" + android:versionName="0.6.0" > - + @@ -13,7 +13,7 @@ + android:name=".offline.OfflineActivity" > + android:name=".offline.OfflineDownloadService" /> + android:name=".offline.OfflineUploadService" /> + android:name=".util.ImageCacheService" /> - + - + - + - - \ No newline at end of file + \ No newline at end of file diff --git a/src/org/fox/ttrss/ApiRequest.java b/src/org/fox/ttrss/ApiRequest.java index 6526ca28..496f3b95 100644 --- a/src/org/fox/ttrss/ApiRequest.java +++ b/src/org/fox/ttrss/ApiRequest.java @@ -15,17 +15,12 @@ import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.protocol.ClientContext; -import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; -import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; -import org.apache.http.params.BasicHttpParams; -import org.apache.http.params.HttpParams; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; +import org.fox.ttrss.util.EasySSLSocketFactory; import android.content.Context; import android.content.SharedPreferences; diff --git a/src/org/fox/ttrss/ArticleFragment.java b/src/org/fox/ttrss/ArticleFragment.java index 231fc12d..098ff6f9 100644 --- a/src/org/fox/ttrss/ArticleFragment.java +++ b/src/org/fox/ttrss/ArticleFragment.java @@ -1,12 +1,13 @@ package org.fox.ttrss; -import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import org.fox.ttrss.types.Article; +import org.fox.ttrss.types.Attachment; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -14,32 +15,27 @@ import org.jsoup.select.Elements; import android.annotation.SuppressLint; import android.app.Activity; -import android.content.Context; +import android.app.Fragment; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; 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") diff --git a/src/org/fox/ttrss/ArticleList.java b/src/org/fox/ttrss/ArticleList.java index 77024c74..2ff61e59 100644 --- a/src/org/fox/ttrss/ArticleList.java +++ b/src/org/fox/ttrss/ArticleList.java @@ -2,6 +2,8 @@ package org.fox.ttrss; import java.util.ArrayList; +import org.fox.ttrss.types.Article; + import android.os.Parcel; import android.os.Parcelable; diff --git a/src/org/fox/ttrss/ArticlePager.java b/src/org/fox/ttrss/ArticlePager.java index 4e280f51..6cf62836 100644 --- a/src/org/fox/ttrss/ArticlePager.java +++ b/src/org/fox/ttrss/ArticlePager.java @@ -1,10 +1,12 @@ package org.fox.ttrss; +import org.fox.ttrss.types.Article; +import org.fox.ttrss.util.FragmentStatePagerAdapter; + import android.app.Activity; +import android.app.Fragment; +import android.app.FragmentManager; import android.os.Bundle; -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.view.LayoutInflater; import android.view.View; @@ -55,7 +57,7 @@ public class ArticlePager extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.article_pager, container, false); - m_adapter = new PagerAdapter(getActivity().getSupportFragmentManager()); + m_adapter = new PagerAdapter(getActivity().getFragmentManager()); ViewPager pager = (ViewPager) view.findViewById(R.id.article_pager); @@ -94,7 +96,7 @@ public class ArticlePager extends Fragment { public void onAttach(Activity activity) { super.onAttach(activity); - m_hf = (HeadlinesFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.headlines_fragment); + m_hf = (HeadlinesFragment) getActivity().getFragmentManager().findFragmentById(R.id.headlines_fragment); m_onlineServices = (OnlineServices)activity; } diff --git a/src/org/fox/ttrss/DummyFragment.java b/src/org/fox/ttrss/DummyFragment.java index d23af2aa..d484f398 100644 --- a/src/org/fox/ttrss/DummyFragment.java +++ b/src/org/fox/ttrss/DummyFragment.java @@ -1,7 +1,7 @@ package org.fox.ttrss; +import android.app.Fragment; import android.os.Bundle; -import android.support.v4.app.Fragment; 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 3f17eb60..b2b378bc 100644 --- a/src/org/fox/ttrss/FeedCategoriesFragment.java +++ b/src/org/fox/ttrss/FeedCategoriesFragment.java @@ -7,13 +7,15 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; +import org.fox.ttrss.types.FeedCategory; + import android.app.Activity; +import android.app.Fragment; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.v4.app.Fragment; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; diff --git a/src/org/fox/ttrss/FeedCategoryList.java b/src/org/fox/ttrss/FeedCategoryList.java index e78f8747..71e99161 100644 --- a/src/org/fox/ttrss/FeedCategoryList.java +++ b/src/org/fox/ttrss/FeedCategoryList.java @@ -2,6 +2,9 @@ package org.fox.ttrss; import java.util.ArrayList; +import org.fox.ttrss.types.Feed; +import org.fox.ttrss.types.FeedCategory; + import android.os.Parcel; import android.os.Parcelable; diff --git a/src/org/fox/ttrss/FeedList.java b/src/org/fox/ttrss/FeedList.java index c54ef780..2d3f0933 100644 --- a/src/org/fox/ttrss/FeedList.java +++ b/src/org/fox/ttrss/FeedList.java @@ -2,6 +2,8 @@ package org.fox.ttrss; import java.util.ArrayList; +import org.fox.ttrss.types.Feed; + import android.os.Parcel; import android.os.Parcelable; diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index 02ac2104..92beaf97 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -7,7 +7,6 @@ import java.io.InputStream; import java.lang.reflect.Type; import java.net.MalformedURLException; import java.net.URL; -import java.net.URLConnection; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -21,18 +20,16 @@ import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.protocol.ClientContext; -import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; -import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; -import org.apache.http.params.BasicHttpParams; -import org.apache.http.params.HttpParams; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; +import org.fox.ttrss.types.Feed; +import org.fox.ttrss.types.FeedCategory; +import org.fox.ttrss.util.EasySSLSocketFactory; import android.app.Activity; +import android.app.Fragment; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; @@ -43,7 +40,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; import android.preference.PreferenceManager; -import android.support.v4.app.Fragment; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index 90855aa5..acfeeb27 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; @@ -12,9 +11,13 @@ import java.util.HashMap; import java.util.List; import java.util.TimeZone; +import org.fox.ttrss.types.Article; +import org.fox.ttrss.types.Attachment; +import org.fox.ttrss.types.Feed; import org.jsoup.Jsoup; import android.app.Activity; +import android.app.Fragment; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -23,7 +26,6 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.v4.app.Fragment; import android.text.Html; import android.text.Html.ImageGetter; import android.text.method.LinkMovementMethod; diff --git a/src/org/fox/ttrss/Label.java b/src/org/fox/ttrss/Label.java deleted file mode 100644 index eccc1e66..00000000 --- a/src/org/fox/ttrss/Label.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.fox.ttrss; - -public class Label { - int id; - String caption; - String fg_color; - String bg_color; - boolean checked; -} diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index a86204c2..23e06513 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -6,9 +6,24 @@ import java.util.List; import java.util.Timer; import java.util.TimerTask; +import org.fox.ttrss.billing.BillingHelper; +import org.fox.ttrss.billing.BillingService; +import org.fox.ttrss.offline.OfflineActivity; +import org.fox.ttrss.offline.OfflineDownloadService; +import org.fox.ttrss.offline.OfflineUploadService; +import org.fox.ttrss.types.Article; +import org.fox.ttrss.types.Feed; +import org.fox.ttrss.types.FeedCategory; +import org.fox.ttrss.types.Label; +import org.fox.ttrss.util.AppRater; +import org.fox.ttrss.util.DatabaseHelper; + import android.animation.LayoutTransition; +import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; +import android.app.Fragment; +import android.app.FragmentTransaction; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; @@ -24,9 +39,6 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; -import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.ActionMode; import android.view.KeyEvent; @@ -48,7 +60,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; -public class MainActivity extends FragmentActivity implements OnlineServices { +public class MainActivity extends Activity implements OnlineServices { private final String TAG = this.getClass().getSimpleName(); private SharedPreferences m_prefs; @@ -63,7 +75,6 @@ public class MainActivity extends FragmentActivity implements OnlineServices { private boolean m_smallScreenMode; private boolean m_unreadOnly = true; private boolean m_unreadArticlesOnly = true; - private boolean m_compatMode = false; private boolean m_enableCats = false; private int m_apiLevel = 0; private boolean m_isLoggingIn = false; @@ -133,7 +144,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { }; public void updateHeadlines() { - HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager() + HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); if (frag != null) { frag.notifyUpdated(); @@ -351,7 +362,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { private synchronized void refreshFeeds() { if (m_sessionId != null) { - FeedsFragment frag = (FeedsFragment) getSupportFragmentManager() + FeedsFragment frag = (FeedsFragment) getFragmentManager() .findFragmentById(R.id.feeds_fragment); Log.d(TAG, "Refreshing feeds..."); @@ -364,7 +375,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { private synchronized void refreshHeadlines() { if (m_sessionId != null) { - HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager() + HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); Log.d(TAG, "Refreshing headlines..."); @@ -377,7 +388,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { private synchronized void refreshCategories() { if (m_sessionId != null) { - FeedCategoriesFragment frag = (FeedCategoriesFragment) getSupportFragmentManager() + FeedCategoriesFragment frag = (FeedCategoriesFragment) getFragmentManager() .findFragmentById(R.id.cats_fragment); Log.d(TAG, "Refreshing categories..."); @@ -407,7 +418,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { * = unread; * * HeadlinesFragment frag = - * (HeadlinesFragment)getSupportFragmentManager().findFragmentById + * (HeadlinesFragment)getFragmentManager().findFragmentById * (R.id.headlines_fragment); * * if (frag != null) frag.refresh(false); } @@ -435,8 +446,6 @@ public class MainActivity extends FragmentActivity implements OnlineServices { m_prefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); - m_compatMode = android.os.Build.VERSION.SDK_INT <= 10; - if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) { setTheme(R.style.DarkTheme); } else { @@ -463,7 +472,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { m_enableCats = m_prefs.getBoolean("enable_cats", false); - m_smallScreenMode = m_compatMode || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != + m_smallScreenMode = (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_XLARGE; setContentView(R.layout.main); @@ -481,18 +490,11 @@ public class MainActivity extends FragmentActivity implements OnlineServices { Log.d(TAG, "m_isOffline=" + m_isOffline); Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode); - Log.d(TAG, "m_compatMode=" + m_compatMode); - if (!m_compatMode) { - if (android.os.Build.VERSION.SDK_INT < 14 || android.os.Build.VERSION.SDK_INT == 15) { - if (!m_smallScreenMode) { - LayoutTransition transitioner = new LayoutTransition(); - ((ViewGroup) findViewById(R.id.main)).setLayoutTransition(transitioner); - } - } - - m_headlinesActionModeCallback = new HeadlinesActionModeCallback(); - } + LayoutTransition transitioner = new LayoutTransition(); + ((ViewGroup) findViewById(R.id.main)).setLayoutTransition(transitioner); + + m_headlinesActionModeCallback = new HeadlinesActionModeCallback(); if (m_isOffline) { Intent offline = new Intent(MainActivity.this, @@ -754,7 +756,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { m_activeCategory = null; - FeedCategoriesFragment cf = (FeedCategoriesFragment) getSupportFragmentManager() + FeedCategoriesFragment cf = (FeedCategoriesFragment) getFragmentManager() .findFragmentById(R.id.cats_fragment); if (cf != null) { @@ -767,7 +769,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { } private void deselectAllArticles() { - HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager() + HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); if (hf != null) { @@ -797,11 +799,11 @@ public class MainActivity extends FragmentActivity implements OnlineServices { findViewById(R.id.cats_fragment) .setVisibility(View.VISIBLE); - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.headlines_fragment, new HeadlinesFragment()); ft.commit(); - FeedCategoriesFragment cf = (FeedCategoriesFragment) getSupportFragmentManager() + FeedCategoriesFragment cf = (FeedCategoriesFragment) getFragmentManager() .findFragmentById(R.id.cats_fragment); if (cf != null) { @@ -816,14 +818,14 @@ public class MainActivity extends FragmentActivity implements OnlineServices { findViewById(R.id.feeds_fragment).setVisibility( View.VISIBLE); - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.headlines_fragment, new HeadlinesFragment()); ft.commit(); refreshFeeds(); } - FeedsFragment ff = (FeedsFragment) getSupportFragmentManager() + FeedsFragment ff = (FeedsFragment) getFragmentManager() .findFragmentById(R.id.feeds_fragment); if (ff != null) { @@ -855,7 +857,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { findViewById(R.id.headlines_fragment).setVisibility( View.INVISIBLE); - FeedsFragment ff = (FeedsFragment) getSupportFragmentManager() + FeedsFragment ff = (FeedsFragment) getFragmentManager() .findFragmentById(R.id.feeds_fragment); if (ff != null) { @@ -864,7 +866,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { m_activeFeed = null; - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.headlines_fragment, new HeadlinesFragment()); ft.commit(); @@ -880,7 +882,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { @SuppressWarnings("unchecked") @Override public boolean onOptionsItemSelected(MenuItem item) { - final HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager() + final HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); switch (item.getItemId()) { @@ -925,44 +927,6 @@ public class MainActivity extends FragmentActivity implements OnlineServices { return true; case android.R.id.home: goBack(false); - return true; - case R.id.search: - if (hf != null && m_compatMode) { - Dialog dialog = new Dialog(this); - - final EditText edit = new EditText(this); - - AlertDialog.Builder builder = new AlertDialog.Builder(this) - .setTitle(R.string.search) - .setPositiveButton(getString(R.string.search), - new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which) { - - String query = edit.getText().toString().trim(); - - hf.setSearchQuery(query); - - } - }) - .setNegativeButton(getString(R.string.cancel), - new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which) { - - // - - } - }).setView(edit); - - dialog = builder.create(); - dialog.show(); - } - return true; case R.id.preferences: Intent intent = new Intent(MainActivity.this, @@ -1276,7 +1240,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { m_selectedArticle = null; - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.article_fragment, new DummyFragment()); ft.commit(); @@ -1303,7 +1267,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { m_menu.setGroupVisible(R.id.menu_group_logged_in, true); m_menu.setGroupVisible(R.id.menu_group_logged_out, false); - HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager() + HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); int numSelected = 0; @@ -1312,12 +1276,8 @@ public class MainActivity extends FragmentActivity implements OnlineServices { numSelected = hf.getSelectedArticles().size(); if (numSelected != 0) { - if (m_compatMode) { - m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true); - } else { - if (m_headlinesActionMode == null) - m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback); - } + if (m_headlinesActionMode == null) + m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback); } else if (m_selectedArticle != null) { m_menu.setGroupVisible(R.id.menu_group_article, true); @@ -1328,40 +1288,38 @@ public class MainActivity extends FragmentActivity implements OnlineServices { search.setEnabled(m_apiLevel >= 2); - if (!m_compatMode) { - SearchView searchView = (SearchView) search.getActionView(); - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - private String query = ""; + SearchView searchView = (SearchView) search.getActionView(); + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + private String query = ""; + + @Override + public boolean onQueryTextSubmit(String query) { + HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager() + .findFragmentById(R.id.headlines_fragment); - @Override - public boolean onQueryTextSubmit(String query) { - HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager() + if (frag != null) { + frag.setSearchQuery(query); + this.query = query; + } + + return false; + } + + @Override + public boolean onQueryTextChange(String newText) { + if (newText.equals("") && !newText.equals(this.query)) { + HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); if (frag != null) { - frag.setSearchQuery(query); - this.query = query; + frag.setSearchQuery(newText); + this.query = newText; } - - return false; } - @Override - public boolean onQueryTextChange(String newText) { - if (newText.equals("") && !newText.equals(this.query)) { - HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager() - .findFragmentById(R.id.headlines_fragment); - - if (frag != null) { - frag.setSearchQuery(newText); - this.query = newText; - } - } - - return false; - } + return false; + } }); - } } else { m_menu.setGroupVisible(R.id.menu_group_feeds, true); @@ -1371,33 +1329,29 @@ public class MainActivity extends FragmentActivity implements OnlineServices { m_headlinesActionMode.finish(); } - if (!m_compatMode) { - - if (m_activeFeed != null) { - getActionBar().setTitle(m_activeFeed.title); - } else if (m_activeCategory != null) { - getActionBar().setTitle(m_activeCategory.title); - } else { - getActionBar().setTitle(R.string.app_name); - } - - if (!m_smallScreenMode) { - getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeCategory != null); - } else { - getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeFeed != null || m_activeCategory != null); - } - - if (android.os.Build.VERSION.SDK_INT >= 14) { - ShareActionProvider shareProvider = (ShareActionProvider) m_menu.findItem(R.id.share_article).getActionProvider(); - - if (m_selectedArticle != null) { - Log.d(TAG, "setting up share provider"); - shareProvider.setShareIntent(getShareIntent(m_selectedArticle)); - } - } - + if (m_activeFeed != null) { + getActionBar().setTitle(m_activeFeed.title); + } else if (m_activeCategory != null) { + getActionBar().setTitle(m_activeCategory.title); + } else { + getActionBar().setTitle(R.string.app_name); } + if (!m_smallScreenMode) { + getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeCategory != null); + } else { + getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeFeed != null || m_activeCategory != null); + } + + if (android.os.Build.VERSION.SDK_INT >= 14) { + ShareActionProvider shareProvider = (ShareActionProvider) m_menu.findItem(R.id.share_article).getActionProvider(); + + if (m_selectedArticle != null) { + Log.d(TAG, "setting up share provider"); + shareProvider.setShareIntent(getShareIntent(m_selectedArticle)); + } + } + m_menu.findItem(R.id.set_labels).setEnabled(m_apiLevel >= 1); m_menu.findItem(R.id.donate).setVisible(BillingHelper.isBillingSupported()); @@ -1509,7 +1463,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { if (hasPendingOfflineData()) syncOfflineData(); - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + FragmentTransaction ft = getFragmentManager().beginTransaction(); if (m_enableCats) { FeedCategoriesFragment frag = new FeedCategoriesFragment(); @@ -1615,7 +1569,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { if (m_menu != null) { MenuItem search = m_menu.findItem(R.id.search); - if (search != null && !m_compatMode) { + if (search != null) { SearchView sv = (SearchView) search.getActionView(); sv.setQuery("", false); } @@ -1623,12 +1577,12 @@ public class MainActivity extends FragmentActivity implements OnlineServices { HeadlinesFragment hf = new HeadlinesFragment(); - FragmentTransaction ft = getSupportFragmentManager() + FragmentTransaction ft = getFragmentManager() .beginTransaction(); ft.replace(R.id.headlines_fragment, hf); ft.commit(); } else { - HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager() + HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); if (hf != null) { hf.refresh(true); @@ -1648,7 +1602,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { FeedsFragment frag = new FeedsFragment(); - FragmentTransaction ft = getSupportFragmentManager() + FragmentTransaction ft = getFragmentManager() .beginTransaction(); ft.replace(R.id.feeds_fragment, frag); ft.commit(); @@ -1663,7 +1617,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { if (m_menu != null) { MenuItem search = m_menu.findItem(R.id.search); - if (search != null && !m_compatMode) { + if (search != null) { SearchView sv = (SearchView) search.getActionView(); sv.setQuery("", false); } @@ -1671,7 +1625,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { HeadlinesFragment frag = new HeadlinesFragment(); - FragmentTransaction ft = getSupportFragmentManager() + FragmentTransaction ft = getFragmentManager() .beginTransaction(); ft.replace(R.id.headlines_fragment, frag); ft.commit(); @@ -1691,7 +1645,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { initMainMenu(); - HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager() + HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); if (hf != null) { @@ -1715,7 +1669,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { frag = new ArticleFragment(article); } - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.article_fragment, frag); ft.commit(); @@ -1810,11 +1764,11 @@ public class MainActivity extends FragmentActivity implements OnlineServices { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item .getMenuInfo(); - HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager() + HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); - FeedsFragment ff = (FeedsFragment) getSupportFragmentManager() + FeedsFragment ff = (FeedsFragment) getFragmentManager() .findFragmentById(R.id.feeds_fragment); - FeedCategoriesFragment cf = (FeedCategoriesFragment) getSupportFragmentManager() + FeedCategoriesFragment cf = (FeedCategoriesFragment) getFragmentManager() .findFragmentById(R.id.cats_fragment); switch (item.getItemId()) { @@ -1972,7 +1926,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { @Override public Article getRelativeArticle(Article article, RelativeArticle ra) { - HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager() + HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); if (frag != null) { ArticleList articles = frag.getAllArticles(); @@ -2006,7 +1960,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { - HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager() + HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); if (hf != null && m_activeFeed != null) { @@ -2033,7 +1987,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { return true; case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_UP) { - HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager() + HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); if (hf != null && m_activeFeed != null) { diff --git a/src/org/fox/ttrss/OnlineServices.java b/src/org/fox/ttrss/OnlineServices.java index a4a10f08..3f61276a 100644 --- a/src/org/fox/ttrss/OnlineServices.java +++ b/src/org/fox/ttrss/OnlineServices.java @@ -1,5 +1,9 @@ package org.fox.ttrss; +import org.fox.ttrss.types.Article; +import org.fox.ttrss.types.Feed; +import org.fox.ttrss.types.FeedCategory; + public interface OnlineServices { public enum RelativeArticle { BEFORE, AFTER }; diff --git a/src/org/fox/ttrss/BillingConstants.java b/src/org/fox/ttrss/billing/BillingConstants.java similarity index 96% rename from src/org/fox/ttrss/BillingConstants.java rename to src/org/fox/ttrss/billing/BillingConstants.java index ea8b454c..eb440219 100644 --- a/src/org/fox/ttrss/BillingConstants.java +++ b/src/org/fox/ttrss/billing/BillingConstants.java @@ -1,4 +1,4 @@ -package org.fox.ttrss; +package org.fox.ttrss.billing; public class BillingConstants { diff --git a/src/org/fox/ttrss/BillingHelper.java b/src/org/fox/ttrss/billing/BillingHelper.java similarity index 95% rename from src/org/fox/ttrss/BillingHelper.java rename to src/org/fox/ttrss/billing/BillingHelper.java index e29fd2f7..dcf29322 100644 --- a/src/org/fox/ttrss/BillingHelper.java +++ b/src/org/fox/ttrss/billing/BillingHelper.java @@ -1,4 +1,4 @@ -package org.fox.ttrss; +package org.fox.ttrss.billing; import java.util.ArrayList; @@ -12,8 +12,9 @@ import android.os.RemoteException; import android.util.Log; import com.android.vending.billing.IMarketBillingService; -import org.fox.ttrss.BillingSecurity.VerifiedPurchase; -import org.fox.ttrss.BillingConstants.ResponseCode; + +import org.fox.ttrss.billing.BillingConstants.ResponseCode; +import org.fox.ttrss.billing.BillingSecurity.VerifiedPurchase; public class BillingHelper { @@ -34,7 +35,7 @@ public class BillingHelper { mCompletedHandler = handler; } - protected static boolean isBillingSupported() { + public static boolean isBillingSupported() { if (amIDead()) { return false; } @@ -67,7 +68,7 @@ public class BillingHelper { * @param activityContext * @param itemId */ - protected static void requestPurchase(Context activityContext, String itemId){ + public static void requestPurchase(Context activityContext, String itemId){ if (amIDead()) { return; } diff --git a/src/org/fox/ttrss/BillingReceiver.java b/src/org/fox/ttrss/billing/BillingReceiver.java similarity index 74% rename from src/org/fox/ttrss/BillingReceiver.java rename to src/org/fox/ttrss/billing/BillingReceiver.java index 42cd5df6..9b772054 100644 --- a/src/org/fox/ttrss/BillingReceiver.java +++ b/src/org/fox/ttrss/billing/BillingReceiver.java @@ -1,18 +1,18 @@ -package org.fox.ttrss; - -import static org.fox.ttrss.BillingConstants.*; - -import java.util.ArrayList; +package org.fox.ttrss.billing; +import static org.fox.ttrss.billing.BillingConstants.ACTION_NOTIFY; +import static org.fox.ttrss.billing.BillingConstants.ACTION_PURCHASE_STATE_CHANGED; +import static org.fox.ttrss.billing.BillingConstants.ACTION_RESPONSE_CODE; +import static org.fox.ttrss.billing.BillingConstants.INAPP_REQUEST_ID; +import static org.fox.ttrss.billing.BillingConstants.INAPP_RESPONSE_CODE; +import static org.fox.ttrss.billing.BillingConstants.INAPP_SIGNATURE; +import static org.fox.ttrss.billing.BillingConstants.INAPP_SIGNED_DATA; +import static org.fox.ttrss.billing.BillingConstants.NOTIFICATION_ID; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.os.Message; import android.util.Log; -import org.fox.ttrss.BillingConstants; -import org.fox.ttrss.BillingSecurity.VerifiedPurchase; - public class BillingReceiver extends BroadcastReceiver { private static final String TAG = "BillingService"; diff --git a/src/org/fox/ttrss/BillingSecurity.java b/src/org/fox/ttrss/billing/BillingSecurity.java similarity index 99% rename from src/org/fox/ttrss/BillingSecurity.java rename to src/org/fox/ttrss/billing/BillingSecurity.java index 26e19b3e..513d6f34 100644 --- a/src/org/fox/ttrss/BillingSecurity.java +++ b/src/org/fox/ttrss/billing/BillingSecurity.java @@ -1,6 +1,6 @@ // Copyright 2010 Google Inc. All Rights Reserved. -package org.fox.ttrss; +package org.fox.ttrss.billing; import java.security.InvalidKeyException; import java.security.KeyFactory; @@ -21,7 +21,7 @@ import org.json.JSONObject; import android.text.TextUtils; import android.util.Log; -import org.fox.ttrss.BillingConstants.PurchaseState; +import org.fox.ttrss.billing.BillingConstants.PurchaseState; import org.fox.ttrss.util.Base64; import org.fox.ttrss.util.Base64DecoderException; diff --git a/src/org/fox/ttrss/BillingService.java b/src/org/fox/ttrss/billing/BillingService.java similarity index 94% rename from src/org/fox/ttrss/BillingService.java rename to src/org/fox/ttrss/billing/BillingService.java index e003df32..2ae53234 100644 --- a/src/org/fox/ttrss/BillingService.java +++ b/src/org/fox/ttrss/billing/BillingService.java @@ -1,4 +1,4 @@ -package org.fox.ttrss; +package org.fox.ttrss.billing; import android.app.Service; import android.content.ComponentName; diff --git a/src/org/fox/ttrss/OfflineActivity.java b/src/org/fox/ttrss/offline/OfflineActivity.java similarity index 87% rename from src/org/fox/ttrss/OfflineActivity.java rename to src/org/fox/ttrss/offline/OfflineActivity.java index 96e82bba..8849d67e 100644 --- a/src/org/fox/ttrss/OfflineActivity.java +++ b/src/org/fox/ttrss/offline/OfflineActivity.java @@ -1,10 +1,25 @@ -package org.fox.ttrss; +package org.fox.ttrss.offline; +import org.fox.ttrss.DummyFragment; +import org.fox.ttrss.MainActivity; +import org.fox.ttrss.OnlineServices; +import org.fox.ttrss.PreferencesActivity; +import org.fox.ttrss.R; import org.fox.ttrss.OnlineServices.RelativeArticle; +import org.fox.ttrss.R.anim; +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.fox.ttrss.R.style; +import org.fox.ttrss.util.DatabaseHelper; import android.animation.LayoutTransition; +import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; +import android.app.Fragment; +import android.app.FragmentTransaction; import android.app.NotificationManager; import android.content.Context; import android.content.DialogInterface; @@ -18,9 +33,6 @@ import android.database.sqlite.SQLiteStatement; import android.os.Bundle; import android.preference.PreferenceManager; import android.provider.BaseColumns; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; -import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.ActionMode; import android.view.KeyEvent; @@ -36,7 +48,7 @@ import android.widget.SearchView; import android.widget.TextView; import android.widget.Toast; -public class OfflineActivity extends FragmentActivity implements +public class OfflineActivity extends Activity implements OfflineServices { private final String TAG = this.getClass().getSimpleName(); @@ -46,7 +58,6 @@ public class OfflineActivity extends FragmentActivity implements private boolean m_smallScreenMode; private boolean m_unreadOnly = true; private boolean m_unreadArticlesOnly = true; - private boolean m_compatMode = false; private boolean m_enableCats = false; private int m_activeFeedId = 0; @@ -99,8 +110,6 @@ public class OfflineActivity extends FragmentActivity implements m_prefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); - m_compatMode = android.os.Build.VERSION.SDK_INT <= 10; - if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) { setTheme(R.style.DarkTheme); } else { @@ -124,24 +133,21 @@ public class OfflineActivity extends FragmentActivity implements m_enableCats = m_prefs.getBoolean("enable_cats", false); - m_smallScreenMode = m_compatMode || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != + m_smallScreenMode = (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_XLARGE; setContentView(R.layout.main); Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode); - Log.d(TAG, "m_compatMode=" + m_compatMode); - if (!m_compatMode) { - if (android.os.Build.VERSION.SDK_INT < 14 /* || android.os.Build.VERSION.SDK_INT == 15 */) { - if (!m_smallScreenMode) { - LayoutTransition transitioner = new LayoutTransition(); - ((ViewGroup) findViewById(R.id.main)).setLayoutTransition(transitioner); - } + if (android.os.Build.VERSION.SDK_INT < 14 /* || android.os.Build.VERSION.SDK_INT == 15 */) { + if (!m_smallScreenMode) { + LayoutTransition transitioner = new LayoutTransition(); + ((ViewGroup) findViewById(R.id.main)).setLayoutTransition(transitioner); } - - m_headlinesActionModeCallback = new HeadlinesActionModeCallback(); } + + m_headlinesActionModeCallback = new HeadlinesActionModeCallback(); initMainMenu(); @@ -190,7 +196,7 @@ public class OfflineActivity extends FragmentActivity implements } if (m_activeFeedId == 0) { - FragmentTransaction ft = getSupportFragmentManager() + FragmentTransaction ft = getFragmentManager() .beginTransaction(); OfflineFeedsFragment frag = new OfflineFeedsFragment(); ft.replace(R.id.feeds_fragment, frag); @@ -337,14 +343,14 @@ public class OfflineActivity extends FragmentActivity implements // } m_activeFeedId = 0; - OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager() + OfflineFeedsFragment ff = (OfflineFeedsFragment) getFragmentManager() .findFragmentById(R.id.feeds_fragment); if (ff != null) { ff.setSelectedFeedId(0); } - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.headlines_fragment, new OfflineHeadlinesFragment()); ft.commit(); @@ -361,14 +367,14 @@ public class OfflineActivity extends FragmentActivity implements findViewById(R.id.headlines_fragment).setVisibility(View.INVISIBLE); m_activeFeedId = 0; - OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager() + OfflineFeedsFragment ff = (OfflineFeedsFragment) getFragmentManager() .findFragmentById(R.id.feeds_fragment); if (ff != null) { ff.setSelectedFeedId(0); } - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.headlines_fragment, new OfflineHeadlinesFragment()); ft.commit(); @@ -466,7 +472,7 @@ public class OfflineActivity extends FragmentActivity implements } private void refreshHeadlines() { - OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager() + OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); if (ohf != null) { @@ -476,50 +482,12 @@ public class OfflineActivity extends FragmentActivity implements @Override public boolean onOptionsItemSelected(MenuItem item) { - final OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager() + final OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); switch (item.getItemId()) { case android.R.id.home: goBack(false); - return true; - case R.id.search: - if (ohf != null && m_compatMode) { - Dialog dialog = new Dialog(this); - - final EditText edit = new EditText(this); - - AlertDialog.Builder builder = new AlertDialog.Builder(this) - .setTitle(R.string.search) - .setPositiveButton(getString(R.string.search), - new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which) { - - String query = edit.getText().toString().trim(); - - ohf.setSearchQuery(query); - - } - }) - .setNegativeButton(getString(R.string.cancel), - new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which) { - - // - - } - }).setView(edit); - - dialog = builder.create(); - dialog.show(); - } - return true; case R.id.preferences: Intent intent = new Intent(this, PreferencesActivity.class); @@ -689,7 +657,7 @@ public class OfflineActivity extends FragmentActivity implements } private void refreshFeeds() { - OfflineFeedsFragment frag = (OfflineFeedsFragment) getSupportFragmentManager() + OfflineFeedsFragment frag = (OfflineFeedsFragment) getFragmentManager() .findFragmentById(R.id.feeds_fragment); if (frag != null) { @@ -717,7 +685,7 @@ public class OfflineActivity extends FragmentActivity implements m_selectedArticleId = 0; - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.article_fragment, new DummyFragment()); ft.commit(); @@ -746,12 +714,8 @@ public class OfflineActivity extends FragmentActivity implements m_menu.setGroupVisible(R.id.menu_group_article, false); if (numSelected != 0) { - if (m_compatMode) { - m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true); - } else { - if (m_headlinesActionMode == null) - m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback); - } + if (m_headlinesActionMode == null) + m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback); } else if (m_selectedArticleId != 0) { m_menu.setGroupVisible(R.id.menu_group_article, true); } else if (m_activeFeedId != 0) { @@ -759,40 +723,38 @@ public class OfflineActivity extends FragmentActivity implements MenuItem search = m_menu.findItem(R.id.search); - if (!m_compatMode) { - SearchView searchView = (SearchView) search.getActionView(); - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - private String query = ""; + SearchView searchView = (SearchView) search.getActionView(); + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + private String query = ""; + + @Override + public boolean onQueryTextSubmit(String query) { + OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getFragmentManager() + .findFragmentById(R.id.headlines_fragment); - @Override - public boolean onQueryTextSubmit(String query) { - OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getSupportFragmentManager() + if (frag != null) { + frag.setSearchQuery(query); + this.query = query; + } + + return false; + } + + @Override + public boolean onQueryTextChange(String newText) { + if (newText.equals("") && !newText.equals(this.query)) { + OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); if (frag != null) { - frag.setSearchQuery(query); - this.query = query; + frag.setSearchQuery(newText); + this.query = newText; } - - return false; } - @Override - public boolean onQueryTextChange(String newText) { - if (newText.equals("") && !newText.equals(this.query)) { - OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getSupportFragmentManager() - .findFragmentById(R.id.headlines_fragment); - - if (frag != null) { - frag.setSearchQuery(newText); - this.query = newText; - } - } - - return false; - } - }); - } + return false; + } + }); } else { m_menu.setGroupVisible(R.id.menu_group_feeds, true); @@ -802,23 +764,20 @@ public class OfflineActivity extends FragmentActivity implements m_headlinesActionMode.finish(); } - if (!m_compatMode) { + if (m_activeFeedId != 0) { + Cursor feed = getFeedById(m_activeFeedId); - if (m_activeFeedId != 0) { - Cursor feed = getFeedById(m_activeFeedId); - - if (feed != null) { - getActionBar().setTitle(feed.getString(feed.getColumnIndex("title"))); - } - } else { - getActionBar().setTitle(R.string.app_name); - } - - if (!m_smallScreenMode) { - getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0); - } else { - getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0 || m_activeFeedId != 0); + if (feed != null) { + getActionBar().setTitle(feed.getString(feed.getColumnIndex("title"))); } + } else { + getActionBar().setTitle(R.string.app_name); + } + + if (!m_smallScreenMode) { + getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0); + } else { + getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0 || m_activeFeedId != 0); } } } @@ -848,9 +807,9 @@ public class OfflineActivity extends FragmentActivity implements AdapterContextMenuInfo info = (AdapterContextMenuInfo) item .getMenuInfo(); - OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager() + OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); - OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager() + OfflineFeedsFragment ff = (OfflineFeedsFragment) getFragmentManager() .findFragmentById(R.id.feeds_fragment); switch (item.getItemId()) { @@ -1013,7 +972,7 @@ public class OfflineActivity extends FragmentActivity implements case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { - OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager() + OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); int nextId = getRelativeArticleId(m_selectedArticleId, @@ -1042,7 +1001,7 @@ public class OfflineActivity extends FragmentActivity implements case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_UP) { - OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager() + OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); int prevId = getRelativeArticleId(m_selectedArticleId, @@ -1145,13 +1104,13 @@ public class OfflineActivity extends FragmentActivity implements if (m_menu != null) { MenuItem search = m_menu.findItem(R.id.search); - if (search != null && !m_compatMode) { + if (search != null) { SearchView sv = (SearchView) search.getActionView(); sv.setQuery("", false); } } - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + FragmentTransaction ft = getFragmentManager().beginTransaction(); OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment(); ft.replace(R.id.headlines_fragment, frag); ft.commit(); @@ -1164,7 +1123,7 @@ public class OfflineActivity extends FragmentActivity implements initMainMenu(); - OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager() + OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getFragmentManager() .findFragmentById(R.id.headlines_fragment); if (hf != null) { @@ -1187,7 +1146,7 @@ public class OfflineActivity extends FragmentActivity implements frag = new OfflineArticleFragment(articleId); } - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.article_fragment, frag); ft.commit(); diff --git a/src/org/fox/ttrss/OfflineArticleFragment.java b/src/org/fox/ttrss/offline/OfflineArticleFragment.java similarity index 93% rename from src/org/fox/ttrss/OfflineArticleFragment.java rename to src/org/fox/ttrss/offline/OfflineArticleFragment.java index 4cd1267d..893a7d28 100644 --- a/src/org/fox/ttrss/OfflineArticleFragment.java +++ b/src/org/fox/ttrss/offline/OfflineArticleFragment.java @@ -1,28 +1,34 @@ -package org.fox.ttrss; +package org.fox.ttrss.offline; 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; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import android.app.Activity; +import android.app.Fragment; import android.content.SharedPreferences; import android.database.Cursor; import android.os.Bundle; import android.preference.PreferenceManager; import android.provider.BaseColumns; -import android.support.v4.app.Fragment; 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; diff --git a/src/org/fox/ttrss/OfflineArticlePager.java b/src/org/fox/ttrss/offline/OfflineArticlePager.java similarity index 81% rename from src/org/fox/ttrss/OfflineArticlePager.java rename to src/org/fox/ttrss/offline/OfflineArticlePager.java index 6ba11c32..0e3d87ee 100644 --- a/src/org/fox/ttrss/OfflineArticlePager.java +++ b/src/org/fox/ttrss/offline/OfflineArticlePager.java @@ -1,13 +1,16 @@ -package org.fox.ttrss; +package org.fox.ttrss.offline; + +import org.fox.ttrss.R; +import org.fox.ttrss.R.id; +import org.fox.ttrss.R.layout; +import org.fox.ttrss.util.FragmentStatePagerAdapter; import android.app.Activity; -import android.database.Cursor; +import android.app.Fragment; +import android.app.FragmentManager; import android.database.sqlite.SQLiteStatement; import android.os.Bundle; import android.provider.BaseColumns; -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.view.LayoutInflater; import android.view.View; @@ -58,7 +61,7 @@ public class OfflineArticlePager extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.article_pager, container, false); - m_adapter = new PagerAdapter(getActivity().getSupportFragmentManager()); + m_adapter = new PagerAdapter(getActivity().getFragmentManager()); ViewPager pager = (ViewPager) view.findViewById(R.id.article_pager); @@ -101,7 +104,7 @@ public class OfflineArticlePager extends Fragment { public void onAttach(Activity activity) { super.onAttach(activity); - m_hf = (OfflineHeadlinesFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.headlines_fragment); + m_hf = (OfflineHeadlinesFragment) getActivity().getFragmentManager().findFragmentById(R.id.headlines_fragment); m_offlineServices = (OfflineServices)activity; } diff --git a/src/org/fox/ttrss/OfflineDownloadService.java b/src/org/fox/ttrss/offline/OfflineDownloadService.java similarity index 93% rename from src/org/fox/ttrss/OfflineDownloadService.java rename to src/org/fox/ttrss/offline/OfflineDownloadService.java index ba5aba1f..f9dc0bc1 100644 --- a/src/org/fox/ttrss/OfflineDownloadService.java +++ b/src/org/fox/ttrss/offline/OfflineDownloadService.java @@ -1,9 +1,18 @@ -package org.fox.ttrss; +package org.fox.ttrss.offline; import java.lang.reflect.Type; import java.util.HashMap; 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.util.DatabaseHelper; +import org.fox.ttrss.util.ImageCacheService; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; diff --git a/src/org/fox/ttrss/OfflineFeedsFragment.java b/src/org/fox/ttrss/offline/OfflineFeedsFragment.java similarity index 93% rename from src/org/fox/ttrss/OfflineFeedsFragment.java rename to src/org/fox/ttrss/offline/OfflineFeedsFragment.java index 01744efe..abdfe756 100644 --- a/src/org/fox/ttrss/OfflineFeedsFragment.java +++ b/src/org/fox/ttrss/offline/OfflineFeedsFragment.java @@ -1,8 +1,15 @@ -package org.fox.ttrss; +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.app.Fragment; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; @@ -13,8 +20,6 @@ import android.os.Bundle; import android.os.Environment; import android.preference.PreferenceManager; import android.provider.BaseColumns; -import android.support.v4.app.Fragment; -import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -26,6 +31,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; import android.widget.ImageView; import android.widget.ListView; +import android.widget.SimpleCursorAdapter; import android.widget.TextView; public class OfflineFeedsFragment extends Fragment implements OnItemClickListener, OnSharedPreferenceChangeListener { diff --git a/src/org/fox/ttrss/OfflineHeadlinesFragment.java b/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java similarity index 94% rename from src/org/fox/ttrss/OfflineHeadlinesFragment.java rename to src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java index 46ebca76..59dc7046 100644 --- a/src/org/fox/ttrss/OfflineHeadlinesFragment.java +++ b/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java @@ -1,13 +1,20 @@ -package org.fox.ttrss; +package org.fox.ttrss.offline; import java.text.DateFormat; import java.text.SimpleDateFormat; 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; +import android.app.Fragment; import android.content.Context; import android.content.SharedPreferences; import android.database.Cursor; @@ -17,8 +24,6 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.preference.PreferenceManager; import android.provider.BaseColumns; -import android.support.v4.app.Fragment; -import android.support.v4.widget.SimpleCursorAdapter; import android.text.Html; import android.text.Html.ImageGetter; import android.text.method.LinkMovementMethod; @@ -35,6 +40,7 @@ import android.widget.AdapterView.OnItemClickListener; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.ListView; +import android.widget.SimpleCursorAdapter; import android.widget.TextView; public class OfflineHeadlinesFragment extends Fragment implements OnItemClickListener { diff --git a/src/org/fox/ttrss/OfflineServices.java b/src/org/fox/ttrss/offline/OfflineServices.java similarity index 80% rename from src/org/fox/ttrss/OfflineServices.java rename to src/org/fox/ttrss/offline/OfflineServices.java index e5fdb92e..0ad6bd8c 100644 --- a/src/org/fox/ttrss/OfflineServices.java +++ b/src/org/fox/ttrss/offline/OfflineServices.java @@ -1,4 +1,7 @@ -package org.fox.ttrss; +package org.fox.ttrss.offline; + +import org.fox.ttrss.OnlineServices; +import org.fox.ttrss.OnlineServices.RelativeArticle; import android.database.sqlite.SQLiteDatabase; diff --git a/src/org/fox/ttrss/OfflineUploadService.java b/src/org/fox/ttrss/offline/OfflineUploadService.java similarity index 92% rename from src/org/fox/ttrss/OfflineUploadService.java rename to src/org/fox/ttrss/offline/OfflineUploadService.java index 9eb028ac..54446669 100644 --- a/src/org/fox/ttrss/OfflineUploadService.java +++ b/src/org/fox/ttrss/offline/OfflineUploadService.java @@ -1,7 +1,14 @@ -package org.fox.ttrss; +package org.fox.ttrss.offline; 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; diff --git a/src/org/fox/ttrss/Article.java b/src/org/fox/ttrss/types/Article.java similarity index 78% rename from src/org/fox/ttrss/Article.java rename to src/org/fox/ttrss/types/Article.java index 05ddcb49..28e54d51 100644 --- a/src/org/fox/ttrss/Article.java +++ b/src/org/fox/ttrss/types/Article.java @@ -1,25 +1,26 @@ -package org.fox.ttrss; +package org.fox.ttrss.types; import java.util.ArrayList; import java.util.List; + import android.os.Parcel; import android.os.Parcelable; // TODO: serialize Labels public class Article implements Parcelable { - int id; - boolean unread; - boolean marked; - boolean published; - int updated; - boolean is_updated; - String title; - String link; - int feed_id; - List tags; - List attachments; - String content; - List> labels; + public int id; + public boolean unread; + public boolean marked; + public boolean published; + public int updated; + public boolean is_updated; + public String title; + public String link; + public int feed_id; + public List tags; + public List attachments; + public String content; + public List> labels; public Article(Parcel in) { readFromParcel(in); diff --git a/src/org/fox/ttrss/Attachment.java b/src/org/fox/ttrss/types/Attachment.java similarity index 85% rename from src/org/fox/ttrss/Attachment.java rename to src/org/fox/ttrss/types/Attachment.java index 37c4a08a..7b77d5db 100644 --- a/src/org/fox/ttrss/Attachment.java +++ b/src/org/fox/ttrss/types/Attachment.java @@ -1,4 +1,4 @@ -package org.fox.ttrss; +package org.fox.ttrss.types; import java.io.File; import java.net.MalformedURLException; @@ -8,12 +8,12 @@ import android.os.Parcel; import android.os.Parcelable; public class Attachment implements Parcelable { - int id; - String content_url; - String content_type; - String title; - String duration; - int post_id; + public int id; + public String content_url; + public String content_type; + public String title; + public String duration; + public int post_id; public Attachment(Parcel in) { readFromParcel(in); diff --git a/src/org/fox/ttrss/Feed.java b/src/org/fox/ttrss/types/Feed.java similarity index 82% rename from src/org/fox/ttrss/Feed.java rename to src/org/fox/ttrss/types/Feed.java index 1f0af4cc..25077686 100644 --- a/src/org/fox/ttrss/Feed.java +++ b/src/org/fox/ttrss/types/Feed.java @@ -1,18 +1,18 @@ -package org.fox.ttrss; +package org.fox.ttrss.types; import android.os.Parcel; import android.os.Parcelable; public class Feed implements Comparable, Parcelable { - String feed_url; - String title; - int id; - int unread; - boolean has_icon; - int cat_id; - int last_updated; - int order_id; - boolean is_cat; + public String feed_url; + public String title; + public int id; + public int unread; + public boolean has_icon; + public int cat_id; + public int last_updated; + public int order_id; + public boolean is_cat; public Feed(int id, String title, boolean is_cat) { this.id = id; diff --git a/src/org/fox/ttrss/FeedCategory.java b/src/org/fox/ttrss/types/FeedCategory.java similarity index 86% rename from src/org/fox/ttrss/FeedCategory.java rename to src/org/fox/ttrss/types/FeedCategory.java index 48c3b554..d4f68bfb 100644 --- a/src/org/fox/ttrss/FeedCategory.java +++ b/src/org/fox/ttrss/types/FeedCategory.java @@ -1,13 +1,13 @@ -package org.fox.ttrss; +package org.fox.ttrss.types; import android.os.Parcel; import android.os.Parcelable; public class FeedCategory implements Parcelable { - int id; - String title; - int unread; - int order_id; + public int id; + public String title; + public int unread; + public int order_id; public FeedCategory(Parcel in) { readFromParcel(in); diff --git a/src/org/fox/ttrss/types/Label.java b/src/org/fox/ttrss/types/Label.java new file mode 100644 index 00000000..fd4ce930 --- /dev/null +++ b/src/org/fox/ttrss/types/Label.java @@ -0,0 +1,9 @@ +package org.fox.ttrss.types; + +public class Label { + public int id; + public String caption; + public String fg_color; + public String bg_color; + public boolean checked; +} diff --git a/src/org/fox/ttrss/AppRater.java b/src/org/fox/ttrss/util/AppRater.java similarity index 96% rename from src/org/fox/ttrss/AppRater.java rename to src/org/fox/ttrss/util/AppRater.java index 2bce4248..a50cc9d9 100644 --- a/src/org/fox/ttrss/AppRater.java +++ b/src/org/fox/ttrss/util/AppRater.java @@ -1,4 +1,4 @@ -package org.fox.ttrss; +package org.fox.ttrss.util; // From http://androidsnippets.com/prompt-engaged-users-to-rate-your-app-in-the-android-market-appirater diff --git a/src/org/fox/ttrss/DatabaseHelper.java b/src/org/fox/ttrss/util/DatabaseHelper.java similarity index 96% rename from src/org/fox/ttrss/DatabaseHelper.java rename to src/org/fox/ttrss/util/DatabaseHelper.java index 71020078..b8560589 100644 --- a/src/org/fox/ttrss/DatabaseHelper.java +++ b/src/org/fox/ttrss/util/DatabaseHelper.java @@ -1,4 +1,4 @@ -package org.fox.ttrss; +package org.fox.ttrss.util; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; diff --git a/src/org/fox/ttrss/EasySSLSocketFactory.java b/src/org/fox/ttrss/util/EasySSLSocketFactory.java similarity index 96% rename from src/org/fox/ttrss/EasySSLSocketFactory.java rename to src/org/fox/ttrss/util/EasySSLSocketFactory.java index 2bb6ea14..f0c2d3ad 100644 --- a/src/org/fox/ttrss/EasySSLSocketFactory.java +++ b/src/org/fox/ttrss/util/EasySSLSocketFactory.java @@ -1,4 +1,4 @@ -package org.fox.ttrss; +package org.fox.ttrss.util; import java.io.IOException; import java.net.InetAddress; diff --git a/src/org/fox/ttrss/EasyX509TrustManager.java b/src/org/fox/ttrss/util/EasyX509TrustManager.java similarity index 93% rename from src/org/fox/ttrss/EasyX509TrustManager.java rename to src/org/fox/ttrss/util/EasyX509TrustManager.java index 6842a1a6..5ffc19bb 100644 --- a/src/org/fox/ttrss/EasyX509TrustManager.java +++ b/src/org/fox/ttrss/util/EasyX509TrustManager.java @@ -1,5 +1,5 @@ -package org.fox.ttrss; +package org.fox.ttrss.util; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; diff --git a/src/org/fox/ttrss/util/FragmentStatePagerAdapter.java b/src/org/fox/ttrss/util/FragmentStatePagerAdapter.java new file mode 100644 index 00000000..26494fdc --- /dev/null +++ b/src/org/fox/ttrss/util/FragmentStatePagerAdapter.java @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.fox.ttrss.util; + +import android.app.Fragment; +import android.app.FragmentManager; +import android.app.FragmentTransaction; +import android.os.Bundle; +import android.os.Parcelable; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.PagerAdapter; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; + +import java.util.ArrayList; + +/** + * Implementation of {@link android.support.v4.view.PagerAdapter} that + * uses a {@link Fragment} to manage each page. This class also handles + * saving and restoring of fragment's state. + * + *

This version of the pager is more useful when there are a large number + * of pages, working more like a list view. When pages are not visible to + * the user, their entire fragment may be destroyed, only keeping the saved + * state of that fragment. This allows the pager to hold on to much less + * memory associated with each visited page as compared to + * {@link FragmentPagerAdapter} at the cost of potentially more overhead when + * switching between pages. + * + *

When using FragmentPagerAdapter the host ViewPager must have a + * valid ID set.

+ * + *

Subclasses only need to implement {@link #getItem(int)} + * and {@link #getCount()} to have a working adapter. + * + *

Here is an example implementation of a pager containing fragments of + * lists: + * + * {@sample development/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStatePagerSupport.java + * complete} + * + *

The R.layout.fragment_pager resource of the top-level fragment is: + * + * {@sample development/samples/Support4Demos/res/layout/fragment_pager.xml + * complete} + * + *

The R.layout.fragment_pager_list resource containing each + * individual fragment's layout is: + * + * {@sample development/samples/Support4Demos/res/layout/fragment_pager_list.xml + * complete} + */ +public abstract class FragmentStatePagerAdapter extends PagerAdapter { + private static final String TAG = "FragmentStatePagerAdapter"; + private static final boolean DEBUG = false; + + private final FragmentManager mFragmentManager; + private FragmentTransaction mCurTransaction = null; + + private ArrayList mSavedState = new ArrayList(); + private ArrayList mFragments = new ArrayList(); + private Fragment mCurrentPrimaryItem = null; + + public FragmentStatePagerAdapter(FragmentManager fm) { + mFragmentManager = fm; + } + + /** + * Return the Fragment associated with a specified position. + */ + public abstract Fragment getItem(int position); + + @Override + public void startUpdate(ViewGroup container) { + } + + @Override + public Object instantiateItem(ViewGroup container, int position) { + // If we already have this item instantiated, there is nothing + // to do. This can happen when we are restoring the entire pager + // from its saved state, where the fragment manager has already + // taken care of restoring the fragments we previously had instantiated. + if (mFragments.size() > position) { + Fragment f = mFragments.get(position); + if (f != null) { + return f; + } + } + + if (mCurTransaction == null) { + mCurTransaction = mFragmentManager.beginTransaction(); + } + + Fragment fragment = getItem(position); + if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment); + if (mSavedState.size() > position) { + Fragment.SavedState fss = mSavedState.get(position); + if (fss != null) { + fragment.setInitialSavedState(fss); + } + } + while (mFragments.size() <= position) { + mFragments.add(null); + } + fragment.setMenuVisibility(false); + mFragments.set(position, fragment); + mCurTransaction.add(container.getId(), fragment); + + return fragment; + } + + @Override + public void destroyItem(ViewGroup container, int position, Object object) { + Fragment fragment = (Fragment)object; + + if (mCurTransaction == null) { + mCurTransaction = mFragmentManager.beginTransaction(); + } + if (DEBUG) Log.v(TAG, "Removing item #" + position + ": f=" + object + + " v=" + ((Fragment)object).getView()); + while (mSavedState.size() <= position) { + mSavedState.add(null); + } + mSavedState.set(position, mFragmentManager.saveFragmentInstanceState(fragment)); + mFragments.set(position, null); + + mCurTransaction.remove(fragment); + } + + @Override + public void setPrimaryItem(ViewGroup container, int position, Object object) { + Fragment fragment = (Fragment)object; + if (fragment != mCurrentPrimaryItem) { + if (mCurrentPrimaryItem != null) { + fragment.setMenuVisibility(false); + } + if (fragment != null) { + fragment.setMenuVisibility(true); + } + mCurrentPrimaryItem = fragment; + } + } + + @Override + public void finishUpdate(ViewGroup container) { + if (mCurTransaction != null) { + mCurTransaction.commitAllowingStateLoss(); + mCurTransaction = null; + mFragmentManager.executePendingTransactions(); + } + } + + @Override + public boolean isViewFromObject(View view, Object object) { + return ((Fragment)object).getView() == view; + } + + @Override + public Parcelable saveState() { + Bundle state = null; + if (mSavedState.size() > 0) { + state = new Bundle(); + Fragment.SavedState[] fss = new Fragment.SavedState[mSavedState.size()]; + mSavedState.toArray(fss); + state.putParcelableArray("states", fss); + } + for (int i=0; i keys = bundle.keySet(); + for (String key: keys) { + if (key.startsWith("f")) { + int index = Integer.parseInt(key.substring(1)); + Fragment f = mFragmentManager.getFragment(bundle, key); + if (f != null) { + while (mFragments.size() <= index) { + mFragments.add(null); + } + f.setMenuVisibility(false); + mFragments.set(index, f); + } else { + Log.w(TAG, "Bad fragment at key " + key); + } + } + } + } + } +} diff --git a/src/org/fox/ttrss/ImageCacheService.java b/src/org/fox/ttrss/util/ImageCacheService.java similarity index 90% rename from src/org/fox/ttrss/ImageCacheService.java rename to src/org/fox/ttrss/util/ImageCacheService.java index 6b0dc139..1541c249 100644 --- a/src/org/fox/ttrss/ImageCacheService.java +++ b/src/org/fox/ttrss/util/ImageCacheService.java @@ -1,4 +1,4 @@ -package org.fox.ttrss; +package org.fox.ttrss.util; import java.io.File; import java.io.FileOutputStream; @@ -10,6 +10,12 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; 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.IntentService; import android.app.Notification; @@ -53,7 +59,7 @@ public class ImageCacheService extends IntentService { m_nmgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); } - protected static boolean isUrlCached(String url) { + public static boolean isUrlCached(String url) { String hashedUrl = md5(url); File storage = Environment.getExternalStorageDirectory(); @@ -63,7 +69,7 @@ public class ImageCacheService extends IntentService { return file.exists(); } - protected static String getCacheFileName(String url) { + public static String getCacheFileName(String url) { String hashedUrl = md5(url); File storage = Environment.getExternalStorageDirectory(); @@ -73,7 +79,7 @@ public class ImageCacheService extends IntentService { return file.getAbsolutePath(); } - protected static void cleanupCache(boolean deleteAll) { + public static void cleanupCache(boolean deleteAll) { if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { File storage = Environment.getExternalStorageDirectory(); File cachePath = new File(storage.getAbsolutePath() + CACHE_PATH); diff --git a/src/org/fox/ttrss/PrefsBackupAgent.java b/src/org/fox/ttrss/util/PrefsBackupAgent.java similarity index 92% rename from src/org/fox/ttrss/PrefsBackupAgent.java rename to src/org/fox/ttrss/util/PrefsBackupAgent.java index 0a7e5dec..a786be56 100644 --- a/src/org/fox/ttrss/PrefsBackupAgent.java +++ b/src/org/fox/ttrss/util/PrefsBackupAgent.java @@ -1,4 +1,4 @@ -package org.fox.ttrss; +package org.fox.ttrss.util; import android.app.backup.BackupAgentHelper; import android.app.backup.SharedPreferencesBackupHelper;