various tablet-related improvements

This commit is contained in:
Andrew Dolgov 2012-09-17 23:20:59 +04:00
parent 4c148d0563
commit 1a5017b432
11 changed files with 157 additions and 29 deletions

View File

@ -13,7 +13,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name="TinyApplication"
android:name=".GlobalState"
android:allowBackup="true"
android:backupAgent=".util.PrefsBackupAgent"
android:hardwareAccelerated="true"

View File

@ -132,7 +132,7 @@ public class ArticlePager extends Fragment {
}
};
final Feed feed = TinyApplication.getInstance().m_activeFeed;
final Feed feed = GlobalState.getInstance().m_activeFeed;
final String sessionId = m_activity.getSessionId();
final boolean showUnread = m_activity.getUnreadArticlesOnly();
@ -188,7 +188,7 @@ public class ArticlePager extends Fragment {
m_onlineServices = (HeadlinesEventListener)activity;
m_activity = (OnlineActivity)activity;
m_articles = TinyApplication.getInstance().m_loadedArticles;
m_articles = GlobalState.getInstance().m_loadedArticles;
}
@Override
@ -202,4 +202,14 @@ public class ArticlePager extends Fragment {
return m_article;
}
public void setActiveArticle(Article article) {
m_article = article;
int position = m_articles.indexOf(m_article);
ViewPager pager = (ViewPager) getView().findViewById(R.id.article_pager);
pager.setCurrentItem(position);
}
}

View File

@ -50,6 +50,10 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
if (intent.getParcelableExtra("feed") != null || intent.getParcelableExtra("category") != null ||
intent.getParcelableExtra("article") != null) {
if (!isCompatMode()) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
Feed feed = (Feed) intent.getParcelableExtra("feed");
FeedCategory cat = (FeedCategory) intent.getParcelableExtra("category");
Article article = (Article) intent.getParcelableExtra("article");
@ -71,7 +75,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
}
if (article != null) {
Article original = TinyApplication.getInstance().m_loadedArticles.findById(article.id);
Article original = GlobalState.getInstance().m_loadedArticles.findById(article.id);
ArticlePager ap = new ArticlePager(original != null ? original : article);
ft.replace(R.id.feeds_fragment, ap, FRAG_ARTICLE);
@ -126,7 +130,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
public void onFeedSelected(Feed feed) {
TinyApplication.getInstance().m_loadedArticles.clear();
GlobalState.getInstance().m_loadedArticles.clear();
if (isSmallScreen()) {

View File

@ -6,13 +6,16 @@ import org.fox.ttrss.types.Feed;
import android.app.Application;
public class TinyApplication extends Application {
private static TinyApplication m_singleton;
public class GlobalState extends Application {
private static GlobalState m_singleton;
public Article m_activeArticle;
public ArticleList m_loadedArticles = new ArticleList();
public Feed m_activeFeed;
public Article m_selectedArticle;
public int m_selectedArticleId;
public static TinyApplication getInstance(){
public static GlobalState getInstance(){
return m_singleton;
}

View File

@ -144,9 +144,11 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
Fragment frag = new ArticlePager(article);
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE);
af.setActiveArticle(article);
// ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE);
// ft.addToBackStack(null);
hf.notifyUpdated();
@ -155,9 +157,11 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
} else {
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
hf.setActiveArticle(article);
}
GlobalState.getInstance().m_activeArticle = article;
initMenu();
}
}
}

View File

@ -75,7 +75,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
private SharedPreferences m_prefs;
private ArticleListAdapter m_adapter;
private ArticleList m_articles = TinyApplication.getInstance().m_loadedArticles;
private ArticleList m_articles = GlobalState.getInstance().m_loadedArticles;
private ArticleList m_selectedArticles = new ArticleList();
private HeadlinesEventListener m_listener;
private OnlineActivity m_activity;
@ -293,19 +293,18 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public void onResume() {
super.onResume();
if (GlobalState.getInstance().m_activeArticle != null) {
m_activeArticle = GlobalState.getInstance().m_activeArticle;
GlobalState.getInstance().m_activeArticle = null;
}
if (m_activeArticle != null) {
setActiveArticle(m_activeArticle);
}
/* if (TinyApplication.getInstance().m_activeArticle != null) {
m_activeArticle = TinyApplication.getInstance().m_activeArticle;
notifyUpdated();
TinyApplication.getInstance().m_activeArticle = null;
} */
if (m_articles.size() == 0 || !m_feed.equals(TinyApplication.getInstance().m_activeFeed)) {
if (m_articles.size() == 0 || !m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
refresh(false);
TinyApplication.getInstance().m_activeFeed = m_feed;
GlobalState.getInstance().m_activeFeed = m_feed;
} else {
notifyUpdated();
}
@ -366,7 +365,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
final boolean isCat = m_feed.is_cat;
int skip = 0;
if (!m_feed.equals(TinyApplication.getInstance().m_activeFeed)) {
if (!m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
append = false;
}
@ -577,7 +576,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
if (ft != null) {
if (article.feed_title != null && (m_feed.is_cat || m_feed.id < 0)) {
ft.setText(article.feed_title);
ft.setText(article.feed_title.substring(0, 30));
} else {
ft.setVisibility(View.GONE);
}

View File

@ -190,4 +190,25 @@ public class OfflineArticlePager extends Fragment {
public void setSearchQuery(String searchQuery) {
m_searchQuery = searchQuery;
}
public void setArticleId(int articleId) {
m_articleId = articleId;
m_cursor.moveToFirst();
int position = 0;
while (!m_cursor.isLast()) {
if (m_cursor.getInt(m_cursor.getColumnIndex(BaseColumns._ID)) == m_articleId) {
position = m_cursor.getPosition();
break;
}
m_cursor.moveToNext();
}
ViewPager pager = (ViewPager) getView().findViewById(R.id.article_pager);
pager.setCurrentItem(position);
}
}

View File

@ -42,6 +42,10 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
if (intent.getIntExtra("feed", -10000) != -10000 || intent.getIntExtra("category", -10000) != -10000 ||
intent.getIntExtra("article", -10000) != -10000) {
if (!isCompatMode()) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
int feedId = intent.getIntExtra("feed", -10000);
@ -230,7 +234,6 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
intent.putExtra("feed", hf.getFeedId());
intent.putExtra("isCat", hf.getFeedIsCat());
intent.putExtra("article", articleId);
intent.putExtra("title", "FIXME-TITLE");
startActivityForResult(intent, 0);
}

View File

@ -1,11 +1,17 @@
package org.fox.ttrss.offline;
import org.fox.ttrss.GlobalState;
import org.fox.ttrss.HeadlinesFragment;
import org.fox.ttrss.R;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
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.FragmentTransaction;
import android.view.View;
@ -43,7 +49,6 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
boolean isCat = i.getBooleanExtra("isCat", false);
int articleId = i.getIntExtra("article", 0);
String searchQuery = i.getStringExtra("searchQuery");
String title = i.getStringExtra("title");
OfflineHeadlinesFragment hf = new OfflineHeadlinesFragment(feedId, isCat);
OfflineArticlePager af = new OfflineArticlePager(articleId, feedId, isCat);
@ -60,7 +65,19 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
ft.commit();
setTitle(title);
Cursor c;
if (isCat) {
c = getCatById(feedId);
} else {
c = getFeedById(feedId);
}
if (c != null) {
setTitle(c.getString(c.getColumnIndex("title")));
c.close();
}
}
}
@ -72,8 +89,58 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
@Override
public void onArticleSelected(int articleId, boolean open) {
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 " + "WHERE " + BaseColumns._ID
+ " = ?");
stmt.bindLong(1, articleId);
stmt.execute();
stmt.close();
if (open) {
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
/* OfflineArticlePager af = new OfflineArticlePager(articleId, hf.getFeedId(), hf.getFeedIsCat());
af.setSearchQuery(hf.getSearchQuery());
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
ft.commit(); */
OfflineArticlePager af = (OfflineArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
af.setArticleId(articleId);
} else {
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
hf.setActiveArticleId(articleId);
}
GlobalState.getInstance().m_selectedArticleId = articleId;
initMenu();
refresh();
}
@Override
protected void initMenu() {
super.initMenu();
if (m_menu != null) {
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
m_menu.setGroupVisible(R.id.menu_group_headlines, hf != null && hf.getSelectedArticleCount() == 0);
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, hf != null && hf.getSelectedArticleCount() != 0);
Fragment af = getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
m_menu.setGroupVisible(R.id.menu_group_article, af != null);
}
}
@Override

View File

@ -5,6 +5,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import org.fox.ttrss.GlobalState;
import org.fox.ttrss.R;
import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.ArticleList;
@ -235,6 +236,16 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
@Override
public void onResume() {
super.onResume();
if (GlobalState.getInstance().m_selectedArticleId != 0) {
m_activeArticleId = GlobalState.getInstance().m_selectedArticleId;
GlobalState.getInstance().m_selectedArticleId = 0;
}
if (m_activeArticleId != 0) {
setActiveArticleId(m_activeArticleId);
}
refresh();
}
@ -451,7 +462,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
int feedTitleIndex = article.getColumnIndex("feed_title");
if (ft != null && feedTitleIndex != -1 && m_feedIsCat) {
String feedTitle = article.getString(feedTitleIndex);
String feedTitle = article.getString(feedTitleIndex).substring(0, 30);
if (feedTitle != null) {
ft.setText(feedTitle);
@ -613,6 +624,8 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
ListView list = (ListView)getView().findViewById(R.id.headlines);
Log.d(TAG, articleId + " position " + getArticleIdPosition(articleId));
if (list != null) {
list.setSelection(getArticleIdPosition(articleId));
}
@ -667,4 +680,8 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
return m_feedIsCat;
}
public String getSearchQuery() {
return m_searchQuery;
}
}

View File

@ -6,7 +6,7 @@ import java.util.List;
import org.fox.ttrss.ApiRequest;
import org.fox.ttrss.OnlineActivity;
import org.fox.ttrss.R;
import org.fox.ttrss.TinyApplication;
import org.fox.ttrss.GlobalState;
import org.fox.ttrss.ApiRequest.ApiError;
import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.ArticleList;
@ -26,7 +26,7 @@ public class HeadlinesRequest extends ApiRequest {
private int m_offset = 0;
private OnlineActivity m_activity;
private ArticleList m_articles = TinyApplication.getInstance().m_loadedArticles;
private ArticleList m_articles = GlobalState.getInstance().m_loadedArticles;
public HeadlinesRequest(Context context, OnlineActivity activity) {
super(context);