more experimental stuff

This commit is contained in:
Andrew Dolgov 2012-09-16 19:25:47 +04:00
parent ced80be1ae
commit c52ea94c44
8 changed files with 249 additions and 73 deletions

View File

@ -19,7 +19,7 @@
</LinearLayout>
<FrameLayout
android:id="@+id/fragment_container"
android:id="@+id/headlines_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>

View File

@ -2,6 +2,41 @@
<group android:id="@+id/menu_group_logged_in" >
<group android:id="@+id/menu_group_feeds" >
<!--
<item
android:id="@+id/back_to_categories"
android:icon="@android:drawable/ic_menu_close_clear_cancel"
android:showAsAction=""
android:title="@string/back_to_categories"/>
-->
<item
android:id="@+id/show_feeds"
android:icon="@android:drawable/ic_menu_agenda"
android:showAsAction=""
android:title="@string/menu_all_feeds"/>
<item
android:id="@+id/update_feeds"
android:icon="@android:drawable/ic_menu_rotate"
android:showAsAction="ifRoom"
android:title="@string/update_feeds"/>
<item
android:id="@+id/go_offline"
android:icon="@drawable/ic_menu_cloud"
android:showAsAction=""
android:title="@string/go_offline"/>
<item
android:id="@+id/logout"
android:icon="@drawable/ic_menu_exit"
android:showAsAction=""
android:title="@string/logout"/>
</group>
<group android:id="@+id/menu_group_headlines" >
<item
@ -28,11 +63,11 @@
android:showAsAction="ifRoom"
android:title="@string/headlines_select"/>
<item
<!-- <item
android:id="@+id/close_feed"
android:icon="@android:drawable/ic_menu_close_clear_cancel"
android:showAsAction=""
android:title="@string/close_feed"/>
android:title="@string/close_feed"/> -->
</group>
@ -105,11 +140,11 @@
android:showAsAction=""
android:title="@string/article_set_note"/>
<item
<!-- <item
android:id="@+id/close_article"
android:icon="@android:drawable/ic_menu_close_clear_cancel"
android:showAsAction=""
android:title="@string/close_article"/>
android:title="@string/close_article"/> -->
</group>
</group>

View File

@ -1,29 +0,0 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<group android:id="@+id/menu_group_logged_in" >
<item
android:id="@+id/logout"
android:icon="@drawable/ic_menu_exit"
android:showAsAction=""
android:title="@string/logout"/>
</group>
<group android:id="@+id/menu_group_logged_out" >
<item
android:id="@+id/login"
android:icon="@android:drawable/ic_menu_rotate"
android:showAsAction="ifRoom|withText"
android:title="@string/login_login"/>
</group>
<item
android:id="@+id/preferences"
android:icon="@android:drawable/ic_menu_preferences"
android:showAsAction=""
android:title="@string/preferences"/>
</menu>

View File

@ -1,6 +1,7 @@
package org.fox.ttrss;
import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.ArticleList;
import android.app.Activity;
import android.os.Bundle;
@ -17,8 +18,8 @@ public class ArticlePager extends Fragment {
private final String TAG = "ArticlePager";
private PagerAdapter m_adapter;
private HeadlinesEventListener m_onlineServices;
private HeadlinesFragment m_hf;
private Article m_article;
private ArticleList m_articles;
private class PagerAdapter extends FragmentStatePagerAdapter {
@ -28,7 +29,7 @@ public class ArticlePager extends Fragment {
@Override
public Fragment getItem(int position) {
Article article = m_hf.getArticleAtPosition(position);
Article article = m_articles.get(position);
if (article != null) {
ArticleFragment af = new ArticleFragment(article);
@ -39,7 +40,7 @@ public class ArticlePager extends Fragment {
@Override
public int getCount() {
return m_hf.getAllArticles().size();
return m_articles.size();
}
}
@ -48,21 +49,27 @@ public class ArticlePager extends Fragment {
super();
}
public ArticlePager(Article article) {
public ArticlePager(Article article, ArticleList articles) {
super();
m_article = article;
m_articles = articles;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.article_pager, container, false);
if (savedInstanceState != null) {
m_articles = savedInstanceState.getParcelable("articles");
m_article = savedInstanceState.getParcelable("article");
}
m_adapter = new PagerAdapter(getActivity().getSupportFragmentManager());
ViewPager pager = (ViewPager) view.findViewById(R.id.article_pager);
int position = m_hf.getArticlePosition(m_article);
int position = m_articles.indexOf(m_article);
pager.setAdapter(m_adapter);
pager.setCurrentItem(position);
@ -78,7 +85,7 @@ public class ArticlePager extends Fragment {
@Override
public void onPageSelected(int position) {
Article article = m_hf.getArticleAtPosition(position);
Article article = m_articles.get(position);
if (article != null) {
if (article.unread) {
@ -90,7 +97,8 @@ public class ArticlePager extends Fragment {
//Log.d(TAG, "Page #" + position + "/" + m_adapter.getCount());
if (position == m_adapter.getCount() - 5) {
m_hf.refresh(true);
// FIXME load more articles somehow
//m_hf.refresh(true);
m_adapter.notifyDataSetChanged();
}
}
@ -100,12 +108,21 @@ public class ArticlePager extends Fragment {
return view;
}
@Override
public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
out.putParcelable("articles", m_articles);
out.putParcelable("article", m_article);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
m_hf = (HeadlinesFragment) getActivity().getSupportFragmentManager().findFragmentByTag(CommonActivity.FRAG_HEADLINES);
m_onlineServices = (HeadlinesEventListener)activity;
((OnlineActivity)getActivity()).initMenu();
}
}

View File

@ -25,9 +25,6 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
protected SharedPreferences m_prefs;
private boolean m_unreadOnly = true;
private boolean m_unreadArticlesOnly = true;
@Override
public void onCreate(Bundle savedInstanceState) {
m_prefs = PreferenceManager
@ -55,36 +52,46 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
}
ft.commit();
} else if (isSmallScreen()) {
} /* else if (isSmallScreen()) {
Fragment frag = getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
if (frag != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.remove(frag);
ft.commit();
}
}
}
public boolean getUnreadOnly() {
return m_unreadOnly;
}
} */
}
@Override
protected void initMenu() {
super.initMenu();
if (m_menu != null) {
Log.d(TAG, "initMenu: " + m_menu);
if (m_menu != null && m_sessionId != null) {
Fragment ff = getSupportFragmentManager().findFragmentByTag(FRAG_FEEDS);
Fragment cf = getSupportFragmentManager().findFragmentByTag(FRAG_CATS);
Fragment af = getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
Log.d(TAG, "ff/cf/af/hf " + ff + " " + cf + " " + af + " " + hf);
m_menu.setGroupVisible(R.id.menu_group_feeds, ff != null || cf != null);
m_menu.setGroupVisible(R.id.menu_group_article, af != null);
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
m_menu.setGroupVisible(R.id.menu_group_headlines, hf != null && hf.getSelectedArticles().size() == 0);
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, hf != null && hf.getSelectedArticles().size() != 0);
MenuItem item = m_menu.findItem(R.id.show_feeds);
if (getUnreadOnly()) {
item.setTitle(R.string.menu_all_feeds);
} else {
item.setTitle(R.string.menu_unread_feeds);
}
}
}
@ -127,9 +134,37 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
onCatSelected(cat, m_prefs.getBoolean("browse_cats_like_feeds", false));
}
private void refresh() {
FeedCategoriesFragment cf = (FeedCategoriesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_CATS);
if (cf != null) {
cf.refresh(false);
}
FeedsFragment ff = (FeedsFragment) getSupportFragmentManager().findFragmentByTag(FRAG_FEEDS);
if (ff != null) {
ff.refresh(false);
}
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) {
hf.refresh(false);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.show_feeds:
m_unreadOnly = !m_unreadOnly;
initMenu();
refresh();
return true;
case R.id.update_feeds:
refresh();
return true;
default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
return super.onOptionsItemSelected(item);
@ -140,7 +175,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
protected void loginSuccess() {
setLoadingStatus(R.string.blank, false);
findViewById(R.id.loading_container).setVisibility(View.GONE);
initMenu();
}
@Override
@ -154,11 +189,6 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
super.onResume();
}
@Override
public boolean getUnreadArticlesOnly() {
return m_unreadArticlesOnly;
}
@Override
public void onArticleListSelectionChange(ArticleList m_selectedArticles) {
initMenu();
@ -175,10 +205,11 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
Fragment frag = new ArticlePager(article);
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
Fragment frag = new ArticlePager(article, hf.getAllArticles());
ft.hide(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES));
ft.add(R.id.feeds_fragment, frag, FRAG_ARTICLE);
ft.replace(R.id.feeds_fragment, frag, FRAG_ARTICLE);
ft.addToBackStack(null);
ft.commit();
@ -199,8 +230,8 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
startActivityForResult(intent, 0);
}
} else {
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) hf.setActiveArticle(article);
/* HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) hf.setActiveArticle(article); */
}
}

View File

@ -64,7 +64,7 @@ private final String TAG = this.getClass().getSimpleName();
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
ArticlePager af = new ArticlePager(article);
ArticlePager af = new ArticlePager(article, hf.getAllArticles());
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
}
@ -80,6 +80,7 @@ private final String TAG = this.getClass().getSimpleName();
setLoadingStatus(R.string.blank, false);
findViewById(R.id.loading_container).setVisibility(View.GONE);
initMenu();
}
@Override
@ -114,7 +115,7 @@ private final String TAG = this.getClass().getSimpleName();
protected void initMenu() {
super.initMenu();
if (m_menu != null) {
if (m_menu != null && m_sessionId != null) {
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
@ -145,7 +146,9 @@ private final String TAG = this.getClass().getSimpleName();
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
Fragment frag = new ArticlePager(article);
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
Fragment frag = new ArticlePager(article, hf.getAllArticles());
ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE);
//ft.addToBackStack(null);

View File

@ -9,6 +9,6 @@ public interface HeadlinesEventListener {
void onArticleListSelectionChange(ArticleList m_selectedArticles);
void onArticleSelected(Article article);
void saveArticleUnread(Article article);
void onArticleSelected(Article article, boolean b);
void onArticleSelected(Article article, boolean open);
}

View File

@ -15,6 +15,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentTransaction;
@ -24,6 +25,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.SearchView;
public class OnlineActivity extends CommonActivity {
@ -33,6 +35,9 @@ public class OnlineActivity extends CommonActivity {
protected SharedPreferences m_prefs;
protected int m_apiLevel = 0;
protected Menu m_menu;
protected boolean m_unreadOnly = true;
protected boolean m_unreadArticlesOnly = true;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -61,6 +66,9 @@ public class OnlineActivity extends CommonActivity {
if (savedInstanceState != null) {
m_sessionId = savedInstanceState.getString("sessionId");
m_apiLevel = savedInstanceState.getInt("apiLevel");
m_unreadOnly = savedInstanceState.getBoolean("unreadOnly");
m_unreadArticlesOnly = savedInstanceState.getBoolean("unreadArticlesOnly");
}
Log.d(TAG, "m_sessionId=" + m_sessionId);
@ -130,6 +138,8 @@ public class OnlineActivity extends CommonActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
switch (item.getItemId()) {
case R.id.logout:
logout();
@ -137,11 +147,113 @@ public class OnlineActivity extends CommonActivity {
case R.id.login:
login();
return true;
case R.id.go_offline:
// FIXME go offline
return true;
case R.id.preferences:
Intent intent = new Intent(OnlineActivity.this,
PreferencesActivity.class);
startActivityForResult(intent, 0);
return true;
case R.id.search:
if (hf != null && isCompatMode()) {
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.headlines_mark_as_read:
if (hf != null) {
ArticleList articles = hf.getUnreadArticles();
for (Article a : articles)
a.unread = false;
ApiRequest req = new ApiRequest(getApplicationContext()) {
protected void onPostExecute(JsonElement result) {
hf.refresh(false);
}
};
final String articleIds = articlesToIdString(articles);
@SuppressWarnings("serial")
HashMap<String, String> map = new HashMap<String, String>() {
{
put("sid", m_sessionId);
put("op", "updateArticle");
put("article_ids", articleIds);
put("mode", "0");
put("field", "2");
}
};
req.execute(map);
}
return true;
case R.id.headlines_select:
if (hf != null) {
Dialog dialog = new Dialog(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(R.string.headlines_select_dialog)
.setSingleChoiceItems(
new String[] {
getString(R.string.headlines_select_all),
getString(R.string.headlines_select_unread),
getString(R.string.headlines_select_none) },
0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
switch (which) {
case 0:
hf.setSelection(HeadlinesFragment.ArticlesSelection.ALL);
break;
case 1:
hf.setSelection(HeadlinesFragment.ArticlesSelection.UNREAD);
break;
case 2:
hf.setSelection(HeadlinesFragment.ArticlesSelection.NONE);
break;
}
dialog.cancel();
initMenu();
}
});
dialog = builder.create();
dialog.show();
}
return true;
default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
return super.onOptionsItemSelected(item);
@ -161,6 +273,14 @@ public class OnlineActivity extends CommonActivity {
m_sessionId = null;
initMenu();
}
public boolean getUnreadArticlesOnly() {
return m_unreadArticlesOnly;
}
public boolean getUnreadOnly() {
return m_unreadOnly;
}
@Override
public void onSaveInstanceState(Bundle out) {
@ -168,6 +288,8 @@ public class OnlineActivity extends CommonActivity {
out.putString("sessionId", m_sessionId);
out.putInt("apiLevel", m_apiLevel);
out.putBoolean("unreadOnly", m_unreadOnly);
out.putBoolean("unreadArticlesOnly", m_unreadArticlesOnly);
}
@Override
@ -415,9 +537,6 @@ public class OnlineActivity extends CommonActivity {
m_menu.findItem(R.id.set_labels).setEnabled(m_apiLevel >= 1);
m_menu.findItem(R.id.article_set_note).setEnabled(m_apiLevel >= 1);
m_menu.findItem(R.id.close_feed).setVisible(!isSmallScreen());
m_menu.findItem(R.id.close_article).setVisible(!isSmallScreen());
MenuItem search = m_menu.findItem(R.id.search);
search.setEnabled(m_apiLevel >= 2);