implement drawer navigation for headlines activity instead of old hideable sidebar

This commit is contained in:
Andrew Dolgov 2014-10-31 14:11:47 +03:00
parent 8a15540c61
commit acdcf759a0
16 changed files with 222 additions and 191 deletions

View File

@ -291,6 +291,9 @@ public class ArticleImagesPagerActivity extends CommonActivity {
}
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.article_img_open:
if (url != null) {
try {

View File

@ -35,11 +35,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
protected SharedPreferences m_prefs;
protected long m_lastRefresh = 0;
//private boolean m_actionbarUpEnabled = false;
//private int m_actionbarRevertDepth = 0;
//private SlidingMenu m_slidingMenu;
private boolean m_feedIsSelected = false;
//private boolean m_feedWasSelected = false;
private ActionBarDrawerToggle m_drawerToggle;
private DrawerLayout m_drawerLayout;
@ -189,7 +185,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
m_menu.findItem(R.id.update_headlines).setVisible(false);
}
m_menu.findItem(R.id.headlines_toggle_sidebar).setVisible(false);
//m_menu.findItem(R.id.headlines_toggle_sidebar).setVisible(false);
MenuItem item = m_menu.findItem(R.id.show_feeds);
@ -229,15 +225,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
//m_feedWasSelected = true;
if (m_drawerLayout != null) {
/* if (findViewById(R.id.sw600dp_port_anchor) != null) {
m_slidingMenu.setBehindWidth(getScreenWidthInPixel() * 2/3);
} */
m_drawerLayout.closeDrawers();
//getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//m_actionbarUpEnabled = true;
}
}
}, 10);
@ -336,13 +324,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
//out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled);
//out.putInt("actionbarRevertDepth", m_actionbarRevertDepth);
out.putBoolean("feedIsSelected", m_feedIsSelected);
//out.putBoolean("feedWasSelected", m_feedWasSelected);
//if (m_slidingMenu != null )
// out.putBoolean("slidingMenuVisible", m_slidingMenu.isMenuShowing());
GlobalState.getInstance().save(out);
}

View File

@ -7,6 +7,8 @@ import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
@ -20,6 +22,9 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
protected SharedPreferences m_prefs;
private ActionBarDrawerToggle m_drawerToggle;
private DrawerLayout m_drawerLayout;
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
@ -32,16 +37,42 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
setContentView(R.layout.headlines_articles);
m_drawerLayout = (DrawerLayout) findViewById(R.id.headlines_drawer);
if (m_drawerLayout != null) {
m_drawerToggle = new ActionBarDrawerToggle(this, m_drawerLayout, R.string.blank, R.string.blank) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
invalidateOptionsMenu();
}
};
m_drawerLayout.setDrawerListener(m_drawerToggle);
m_drawerToggle.setDrawerIndicatorEnabled(true);
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
setStatusBarTint();
setSmallScreen(findViewById(R.id.sw600dp_anchor) == null);
GlobalState.getInstance().load(savedInstanceState);
if (isPortrait() || m_prefs.getBoolean("headlines_hide_sidebar", false)) {
/* if (isPortrait() || m_prefs.getBoolean("headlines_hide_sidebar", false)) {
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
}
} */
if (savedInstanceState == null) {
Intent i = getIntent();
@ -85,7 +116,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
HeadlinesFragment hf = new HeadlinesFragment();
hf.initialize(feed, article);
hf.initialize(feed, article, true);
hf.setSearchQuery(searchQuery);
ArticlePager af = new ArticlePager();
@ -101,11 +132,12 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
}
}
}
/* if (!isCompatMode()) {
((ViewGroup)findViewById(R.id.headlines_fragment)).setLayoutTransition(new LayoutTransition());
((ViewGroup)findViewById(R.id.article_fragment)).setLayoutTransition(new LayoutTransition());
} */
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
if (m_drawerToggle != null) m_drawerToggle.syncState();
}
@Override
@ -133,6 +165,10 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (m_drawerToggle != null && m_drawerToggle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
case android.R.id.home:
finish();
@ -159,7 +195,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
//HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
m_menu.setGroupVisible(R.id.menu_group_headlines, !isPortrait() && !isSmallScreen());
m_menu.findItem(R.id.headlines_toggle_sidebar).setVisible(!isPortrait() && !isSmallScreen());
//m_menu.findItem(R.id.headlines_toggle_sidebar).setVisible(!isPortrait() && !isSmallScreen());
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
@ -210,6 +246,10 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (m_drawerLayout != null) {
m_drawerLayout.closeDrawers();
}
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
if (af != null) {

View File

@ -91,6 +91,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
private OnlineActivity m_activity;
private SwipeRefreshLayout m_swipeLayout;
private int m_maxImageSize = 0;
private boolean m_compactLayoutMode = false;
public ArticleList getSelectedArticles() {
return m_selectedArticles;
@ -100,8 +101,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
m_feed = feed;
}
public void initialize(Feed feed, Article activeArticle) {
public void initialize(Feed feed, Article activeArticle, boolean compactMode) {
m_feed = feed;
m_compactLayoutMode = compactMode;
if (activeArticle != null) {
m_activeArticle = getArticleById(activeArticle.id);
@ -293,6 +295,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
m_activeArticle = savedInstanceState.getParcelable("activeArticle");
m_selectedArticles = savedInstanceState.getParcelable("selectedArticles");
m_searchQuery = (String) savedInstanceState.getCharSequence("searchQuery");
m_compactLayoutMode = savedInstanceState.getBoolean("compactLayoutMode");
}
DisplayMetrics metrics = new DisplayMetrics();
@ -570,6 +573,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
out.putParcelable("activeArticle", m_activeArticle);
out.putParcelable("selectedArticles", m_selectedArticles);
out.putCharSequence("searchQuery", m_searchQuery);
out.putBoolean("compactLayoutMode", m_compactLayoutMode);
}
static class HeadlineViewHolder {
@ -586,6 +590,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public ViewGroup flavorImageHolder;
public ProgressBar flavorImageLoadingBar;
public View flavorImageArrow;
public View headlineFooter;
}
private class ArticleListAdapter extends ArrayAdapter<Article> {
@ -680,6 +685,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
holder.flavorImageHolder = (ViewGroup) v.findViewById(R.id.flavorImageHolder);
holder.flavorImageLoadingBar = (ProgressBar) v.findViewById(R.id.flavorImageLoadingBar);
holder.flavorImageArrow = v.findViewById(R.id.flavorImageArrow);
holder.headlineFooter = v.findViewById(R.id.headline_footer);
v.setTag(holder);
@ -762,7 +768,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
String articleContent = article.content != null ? article.content : "";
if (holder.excerptView != null) {
if (!m_prefs.getBoolean("headlines_show_content", true)) {
if ((m_compactLayoutMode && m_activity.isSmallScreen()) || !m_prefs.getBoolean("headlines_show_content", true)) {
holder.excerptView.setVisibility(View.GONE);
} else {
String excerpt = Jsoup.parse(articleContent).text();
@ -775,6 +781,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
}
}
if (!m_compactLayoutMode) {
if (holder.flavorImageView != null && m_prefs.getBoolean("headlines_show_flavor_image", true)) {
holder.flavorImageArrow.setVisibility(View.GONE);
@ -897,6 +904,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
}
} else if (holder.flavorImageHolder != null) {
holder.flavorImageHolder.setVisibility(View.GONE);
}
} else {
holder.flavorImageHolder.setVisibility(View.GONE);
}
String articleAuthor = article.author != null ? article.author : "";
@ -956,6 +966,12 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
});
}
if (m_compactLayoutMode && m_activity.isSmallScreen()) {
if (holder.headlineFooter != null) {
holder.headlineFooter.setVisibility(View.GONE);
}
}
return v;
}

View File

@ -651,7 +651,7 @@ public class OnlineActivity extends CommonActivity {
/* case android.R.id.home:
finish();
return true; */
case R.id.headlines_toggle_sidebar:
/* case R.id.headlines_toggle_sidebar:
if (true && !isSmallScreen()) {
View v = findViewById(R.id.headlines_fragment);
@ -663,7 +663,7 @@ public class OnlineActivity extends CommonActivity {
v.setVisibility(m_prefs.getBoolean("headlines_hide_sidebar", false) ? View.GONE : View.VISIBLE);
}
}
return true;
return true; */
case R.id.subscribe_to_feed:
Intent subscribe = new Intent(OnlineActivity.this, SubscribeActivity.class);
startActivityForResult(subscribe, 0);

View File

@ -20,7 +20,6 @@ import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
@ -257,7 +256,7 @@ public class OfflineActivity extends CommonActivity {
/* case android.R.id.home:
finish();
return true; */
case R.id.headlines_toggle_sidebar:
/* case R.id.headlines_toggle_sidebar:
if (true && !isSmallScreen()) {
SharedPreferences.Editor editor = m_prefs.edit();
editor.putBoolean("headlines_hide_sidebar", !m_prefs.getBoolean("headlines_hide_sidebar", false));
@ -267,7 +266,7 @@ public class OfflineActivity extends CommonActivity {
ohf.getView().setVisibility(m_prefs.getBoolean("headlines_hide_sidebar", false) ? View.GONE : View.VISIBLE);
}
}
return true;
return true; */
case R.id.go_online:
switchOnline();
return true;

View File

@ -155,14 +155,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
//out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled);
//out.putInt("actionbarRevertDepth", m_actionbarRevertDepth);
out.putBoolean("feedIsSelected", m_feedIsSelected);
//out.putBoolean("feedWasSelected", m_feedWasSelected);
//if (m_slidingMenu != null )
// out.putBoolean("slidingMenuVisible", m_slidingMenu.isMenuShowing());
GlobalState.getInstance().save(out);
}
@ -185,7 +178,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
m_menu.setGroupVisible(R.id.menu_group_headlines, hf != null && hf.isAdded());
}
m_menu.findItem(R.id.headlines_toggle_sidebar).setVisible(false);
//m_menu.findItem(R.id.headlines_toggle_sidebar).setVisible(false);
MenuItem item = m_menu.findItem(R.id.show_feeds);

View File

@ -12,7 +12,6 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import org.fox.ttrss.GlobalState;
import org.fox.ttrss.R;
@ -39,9 +38,9 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
setStatusBarTint();
setSmallScreen(findViewById(R.id.sw600dp_anchor) == null);
if (isPortrait() || m_prefs.getBoolean("headlines_hide_sidebar", false)) {
/* if (isPortrait() || m_prefs.getBoolean("headlines_hide_sidebar", false)) {
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
}
} */
if (savedInstanceState == null) {
Intent i = getIntent();
@ -141,7 +140,7 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
//OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
m_menu.setGroupVisible(R.id.menu_group_headlines, !isPortrait() && !isSmallScreen());
m_menu.findItem(R.id.headlines_toggle_sidebar).setVisible(!isPortrait() && !isSmallScreen());
//m_menu.findItem(R.id.headlines_toggle_sidebar).setVisible(!isPortrait() && !isSmallScreen());
Fragment af = getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);

View File

@ -12,27 +12,25 @@
android:visibility="gone" >
</FrameLayout>
<LinearLayout
android:id="@+id/fragment_container"
<android.support.v4.widget.DrawerLayout
android:id="@+id/headlines_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/headlines_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:background="?headlinesBackgroundSolid" >
</FrameLayout>
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/article_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
android:background="?articleBackground" >
android:layout_height="match_parent"
android:background="?articleBackground">
</FrameLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/headlines_fragment"
android:layout_height="match_parent"
android:layout_width="300dp"
android:layout_gravity="start"
android:background="?headlinesBackgroundSolid">
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>

View File

@ -4,28 +4,25 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/fragment_container"
<android.support.v4.widget.DrawerLayout
android:id="@+id/headlines_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/headlines_fragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0"
android:background="?feedlistBackground" >
</FrameLayout>
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/article_fragment"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?articleBackground" >
android:background="?articleBackground">
</FrameLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/headlines_fragment"
android:layout_height="match_parent"
android:layout_width="240dp"
android:layout_gravity="start"
android:background="?headlinesBackgroundSolid">
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
</FrameLayout>

View File

@ -125,6 +125,7 @@
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/headline_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"

View File

@ -126,6 +126,7 @@
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/headline_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"

View File

@ -127,6 +127,7 @@
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/headline_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"

View File

@ -126,6 +126,7 @@
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/headline_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"

View File

@ -64,10 +64,10 @@
app:showAsAction=""
android:title="@string/headlines_view_mode"/>
<item
<!-- <item
android:id="@+id/headlines_toggle_sidebar"
app:showAsAction=""
android:title="@string/toggle_sidebar"/>
android:title="@string/toggle_sidebar"/> -->
<!--
<item

View File

@ -33,10 +33,10 @@
app:showAsAction=""
android:title="@string/headlines_view_mode"/>
<item
<!-- <item
android:id="@+id/headlines_toggle_sidebar"
app:showAsAction=""
android:title="@string/toggle_sidebar"/>
android:title="@string/toggle_sidebar"/> -->
</group>
<!--
<group android:id="@+id/menu_group_headlines_selection" >