add drawer stuff to offline headlines activity

This commit is contained in:
Andrew Dolgov 2014-10-31 14:21:50 +03:00
parent acdcf759a0
commit 04366e58f1
3 changed files with 68 additions and 10 deletions

View File

@ -240,7 +240,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
.beginTransaction();
OfflineHeadlinesFragment hf = new OfflineHeadlinesFragment();
hf.initialize(feedId, isCat);
hf.initialize(feedId, isCat, false);
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
ft.commit();

View File

@ -10,8 +10,11 @@ import android.preference.PreferenceManager;
import android.provider.BaseColumns;
import android.support.v4.app.Fragment;
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;
import org.fox.ttrss.GlobalState;
import org.fox.ttrss.R;
@ -21,6 +24,9 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
protected SharedPreferences m_prefs;
private ActionBarDrawerToggle m_drawerToggle;
private DrawerLayout m_drawerLayout;
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
@ -33,7 +39,33 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
setContentView(R.layout.headlines_articles);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
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);
@ -52,7 +84,7 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
String searchQuery = i.getStringExtra("searchQuery");
OfflineHeadlinesFragment hf = new OfflineHeadlinesFragment();
hf.initialize(feedId, isCat);
hf.initialize(feedId, isCat, true);
OfflineArticlePager af = new OfflineArticlePager();
af.initialize(articleId, feedId, isCat);
@ -88,9 +120,19 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
initMenu();
}
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
if (m_drawerToggle != null) m_drawerToggle.syncState();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
if (m_drawerToggle != null && m_drawerToggle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
case android.R.id.home:
finish();
overridePendingTransition(0, R.anim.right_slide_out);
@ -115,7 +157,11 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
}
if (open) {
OfflineArticlePager af = (OfflineArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
if (m_drawerLayout != null) {
m_drawerLayout.closeDrawers();
}
OfflineArticlePager af = (OfflineArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
af.setArticleId(articleId);
} else {

View File

@ -67,9 +67,12 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
private OfflineActivity m_activity;
private SwipeRefreshLayout m_swipeLayout;
public void initialize(int feedId, boolean isCat) {
private boolean m_compactLayoutMode = false;
public void initialize(int feedId, boolean isCat, boolean compactMode) {
m_feedId = feedId;
m_feedIsCat = isCat;
m_compactLayoutMode = compactMode;
}
@Override
@ -276,6 +279,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
//m_selectedArticles = savedInstanceState.getParcelableArrayList("selectedArticles");
m_searchQuery = (String) savedInstanceState.getCharSequence("searchQuery");
m_feedIsCat = savedInstanceState.getBoolean("feedIsCat");
m_compactLayoutMode = savedInstanceState.getBoolean("compactLayoutMode");
} else {
m_activity.getWritableDb().execSQL("UPDATE articles SET selected = 0 ");
}
@ -405,6 +409,8 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
//out.putParcelableArrayList("selectedArticles", m_selectedArticles);
out.putCharSequence("searchQuery", m_searchQuery);
out.putBoolean("feedIsCat", m_feedIsCat);
out.putBoolean("compactLayoutMode", m_compactLayoutMode);
}
/* public void setLoadingStatus(int status, boolean showProgress) {
@ -586,7 +592,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
TextView te = (TextView)v.findViewById(R.id.excerpt);
if (te != null) {
if (!m_prefs.getBoolean("headlines_show_content", true)) {
if ((m_compactLayoutMode && m_activity.isSmallScreen()) || !m_prefs.getBoolean("headlines_show_content", true)) {
te.setVisibility(View.GONE);
} else {
String excerpt = Jsoup.parse(article.getString(article.getColumnIndex("content"))).text();
@ -664,7 +670,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
flavorImageHolder.setVisibility(View.GONE);
}
ImageView ib = (ImageView) v.findViewById(R.id.article_menu_button);
ImageView ib = (ImageView) v.findViewById(R.id.article_menu_button);
if (ib != null) {
//if (m_activity.isDarkTheme())
@ -678,7 +684,13 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
});
}
return v;
View headlineFooter = v.findViewById(R.id.headline_footer);
if (headlineFooter != null && m_compactLayoutMode && m_activity.isSmallScreen()) {
headlineFooter.setVisibility(View.GONE);
}
return v;
}
private void adjustTitleTextView(int score, TextView tv, int position) {