mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Blog Fragment in Navigation Drawer with Tabs
This replaces the custom layouts in the navigation drawer with a `NavigationView` and adds a menu entry for Blogs. A Main Blogs fragment is added that holds a `TabLayout` and a `ViewPager`. Five tabs are already added, but they just have a single placeholder fragment that is to be replaced by the actual fragments. Closes #409
This commit is contained in:
@@ -70,6 +70,12 @@ public interface ActivityComponent {
|
||||
@Named("ForumListFragment")
|
||||
BaseFragment newForumListFragment();
|
||||
|
||||
@Named("BlogsFragment")
|
||||
BaseFragment newBlogsFragment();
|
||||
|
||||
@Named("MyBlogsFragment")
|
||||
BaseFragment newMyBlogsFragment();
|
||||
|
||||
@Named("ChooseIdentityFragment")
|
||||
BaseFragment newChooseIdentityFragment();
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.briarproject.android.blogs.BlogsFragment;
|
||||
import org.briarproject.android.blogs.MyBlogsFragment;
|
||||
import org.briarproject.android.contact.ContactListFragment;
|
||||
import org.briarproject.android.controller.BriarController;
|
||||
import org.briarproject.android.controller.BriarControllerImpl;
|
||||
@@ -149,6 +151,20 @@ public class ActivityModule {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("BlogsFragment")
|
||||
BaseFragment provideBlogsFragment(BlogsFragment fragment) {
|
||||
fragment.setArguments(new Bundle());
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("MyBlogsFragment")
|
||||
BaseFragment provideMyBlogsFragment(MyBlogsFragment fragment) {
|
||||
fragment.setArguments(new Bundle());
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("ChooseIdentityFragment")
|
||||
BaseFragment provideChooseIdentityFragment(
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.blogs.BlogsFragment;
|
||||
import org.briarproject.android.contact.ContactListFragment;
|
||||
import org.briarproject.android.forum.ForumListFragment;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
@@ -26,6 +27,8 @@ public abstract class BriarFragmentActivity extends BriarActivity {
|
||||
actionBar.setTitle(R.string.contacts_toolbar_header);
|
||||
} else if (fragmentTag.equals(ForumListFragment.TAG)) {
|
||||
actionBar.setTitle(R.string.forums_toolbar_header);
|
||||
} else if (fragmentTag.equals(BlogsFragment.TAG)) {
|
||||
actionBar.setTitle(R.string.blogs_button);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,13 @@ import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
@@ -38,7 +41,8 @@ import static android.support.v4.widget.DrawerLayout.LOCK_MODE_UNLOCKED;
|
||||
import static android.view.View.INVISIBLE;
|
||||
|
||||
public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
BaseFragment.BaseFragmentListener, TransportStateListener {
|
||||
BaseFragment.BaseFragmentListener, TransportStateListener,
|
||||
OnNavigationItemSelectedListener {
|
||||
|
||||
public final static String PREF_SEEN_WELCOME_MESSAGE = "welcome_message";
|
||||
|
||||
@@ -90,6 +94,8 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
NavigationView navigation =
|
||||
(NavigationView) findViewById(R.id.navigation);
|
||||
GridView transportsView = (GridView) findViewById(R.id.transportsView);
|
||||
progressTitle = (TextView) findViewById(R.id.title_progress_bar);
|
||||
progressViewGroup = (ViewGroup) findViewById(R.id.container_progress);
|
||||
@@ -101,12 +107,11 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
|
||||
R.string.nav_drawer_open_description,
|
||||
R.string.nav_drawer_close_description);
|
||||
drawerLayout.setDrawerListener(drawerToggle);
|
||||
drawerLayout.addDrawerListener(drawerToggle);
|
||||
navigation.setNavigationItemSelectedListener(this);
|
||||
if (state == null) {
|
||||
navigation.setCheckedItem(R.id.nav_btn_contacts);
|
||||
startFragment(activityComponent.newContactListFragment());
|
||||
} else {
|
||||
currentFragmentId = state.getInt(KEY_CURRENT_FRAGMENT_ID);
|
||||
loadCurrentFragment();
|
||||
}
|
||||
checkAuthorHandle(getIntent());
|
||||
|
||||
@@ -174,6 +179,9 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
case R.id.nav_btn_forums:
|
||||
startFragment(activityComponent.newForumListFragment());
|
||||
break;
|
||||
case R.id.nav_btn_blogs:
|
||||
startFragment(activityComponent.newBlogsFragment());
|
||||
break;
|
||||
case R.id.nav_btn_settings:
|
||||
startActivity(new Intent(this, SettingsActivity.class));
|
||||
break;
|
||||
@@ -183,11 +191,13 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
public void onNavigationClick(View view) {
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem item) {
|
||||
drawerLayout.closeDrawer(START);
|
||||
clearBackStack();
|
||||
currentFragmentId = view.getId();
|
||||
currentFragmentId = item.getItemId();
|
||||
loadCurrentFragment();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package org.briarproject.android.blogs;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.TabLayout;
|
||||
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;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class BlogsFragment extends BaseFragment {
|
||||
|
||||
public final static String TAG = BlogsFragment.class.getName();
|
||||
|
||||
// TODO add your first fragment here
|
||||
//@Inject
|
||||
//Lazy<MyBlogsFragment> myBlogsFragment;
|
||||
|
||||
private static final String SELECTED_TAB = "selectedTab";
|
||||
private TabLayout tabLayout;
|
||||
|
||||
@Inject
|
||||
public BlogsFragment() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_blogs, container,
|
||||
false);
|
||||
|
||||
tabLayout = (TabLayout) v.findViewById(R.id.tabLayout);
|
||||
ViewPager viewPager = (ViewPager) v.findViewById(R.id.pager);
|
||||
|
||||
String[] titles = {
|
||||
getString(R.string.blogs_feed),
|
||||
getString(R.string.blogs_my_blogs),
|
||||
getString(R.string.blogs_blog_list),
|
||||
getString(R.string.blogs_available_blogs),
|
||||
getString(R.string.blogs_drafts)
|
||||
};
|
||||
TabAdapter tabAdapter =
|
||||
new TabAdapter(getChildFragmentManager(), titles);
|
||||
viewPager.setAdapter(tabAdapter);
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
int position = savedInstanceState.getInt(SELECTED_TAB, 0);
|
||||
viewPager.setCurrentItem(position);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(SELECTED_TAB, tabLayout.getSelectedTabPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
|
||||
private static class TabAdapter extends FragmentStatePagerAdapter {
|
||||
private String[] titles;
|
||||
|
||||
TabAdapter(FragmentManager fm, String[] titles) {
|
||||
super(fm);
|
||||
this.titles = titles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return titles.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
switch (position) {
|
||||
// TODO add your fragments here
|
||||
default:
|
||||
return MyBlogsFragment.newInstance(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return titles[position];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.briarproject.android.blogs;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class MyBlogsFragment extends BaseFragment {
|
||||
|
||||
public final static String TAG = MyBlogsFragment.class.getName();
|
||||
|
||||
@Inject
|
||||
public MyBlogsFragment() {
|
||||
}
|
||||
|
||||
static MyBlogsFragment newInstance(int num) {
|
||||
MyBlogsFragment f = new MyBlogsFragment();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("num", num);
|
||||
f.setArguments(args);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_blogs_my, container,
|
||||
false);
|
||||
|
||||
TextView numView = (TextView) v.findViewById(R.id.num);
|
||||
String num = String.valueOf(getArguments().getInt("num"));
|
||||
numView.setText(num);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user