use of org.mazhuang.guanggoo.base.BaseFragment in project guanggoo-android by mzlogin.
the class FragmentFactory method getFragmentByPageType.
public static BaseFragment getFragmentByPageType(PageType type) {
BaseFragment fragment;
switch(type) {
case HOME:
fragment = new HomeFragment();
break;
case HOME_TOPIC_LIST:
fragment = new TopicListFragment();
new TopicListPresenter((TopicListFragment) fragment);
break;
case NODE_TOPIC_LIST:
fragment = new TopicListFragment();
new TopicListPresenter((TopicListFragment) fragment);
break;
case USER_FAVORS:
if (AuthInfoManager.getInstance().isLoginIn()) {
fragment = new TopicListFragment();
new TopicListPresenter((TopicListFragment) fragment);
} else {
fragment = new LoginFragment();
new LoginPresenter((LoginFragment) fragment);
}
break;
case USER_TOPICS:
fragment = new TopicListFragment();
new TopicListPresenter((TopicListFragment) fragment);
break;
case TOPIC_DETAIL:
if (AuthInfoManager.getInstance().isLoginIn()) {
fragment = new TopicDetailFragment();
new TopicDetailPresenter((TopicDetailFragment) fragment);
} else {
fragment = new LoginFragment();
new LoginPresenter((LoginFragment) fragment);
}
break;
case NODES_CLOUD:
fragment = new NodesCloudFragment();
new NodesCloudPresenter((NodesCloudFragment) fragment);
break;
case SELECT_NODE:
fragment = new SelectNodeFragment();
new NodesCloudPresenter((SelectNodeFragment) fragment);
break;
case LOGIN:
fragment = new LoginFragment();
new LoginPresenter((LoginFragment) fragment);
break;
case USER_PROFILE:
if (AuthInfoManager.getInstance().isLoginIn()) {
fragment = new UserProfileFragment();
new UserProfilePresenter((UserProfileFragment) fragment);
} else {
fragment = new LoginFragment();
new LoginPresenter((LoginFragment) fragment);
}
break;
case USER_REPLIES:
if (AuthInfoManager.getInstance().isLoginIn()) {
fragment = new ReplyListFragment();
new ReplyListPresenter((ReplyListFragment) fragment);
} else {
fragment = new LoginFragment();
new LoginPresenter((LoginFragment) fragment);
}
break;
case NEW_TOPIC:
if (AuthInfoManager.getInstance().isLoginIn()) {
fragment = new NewTopicFragment();
new NewTopicPresenter((NewTopicFragment) fragment);
} else {
fragment = new LoginFragment();
new LoginPresenter((LoginFragment) fragment);
}
break;
case VIEW_IMAGE:
fragment = new ViewImageFragment();
new ViewImagePresenter((ViewImageFragment) fragment);
break;
case ABOUT:
fragment = new AboutFragment();
break;
default:
fragment = null;
break;
}
if (fragment != null) {
fragment.setPageType(type);
}
return fragment;
}
use of org.mazhuang.guanggoo.base.BaseFragment in project guanggoo-android by mzlogin.
the class MainActivity method openPage.
@Override
public void openPage(String url, String title) {
if (!TextUtils.isEmpty(url)) {
Fragment fragment = getCurrentFragment();
if (fragment instanceof BaseFragment) {
if (url.equals(((BaseFragment) fragment).getUrl())) {
return;
}
if (fragment.getClass().isAnnotationPresent(FinishWhenCovered.class)) {
getSupportFragmentManager().popBackStack();
}
}
}
BaseFragment fragment = FragmentFactory.getFragmentByUrl(url);
if (fragment == null) {
Toast.makeText(this, getString(R.string.error_happened), Toast.LENGTH_SHORT).show();
return;
}
Bundle bundle = new Bundle();
bundle.putString(BaseFragment.KEY_URL, url);
bundle.putString(BaseFragment.KEY_TITLE, title);
fragment.setArguments(bundle);
if (fragment.getClass().isAnnotationPresent(ClearTop.class)) {
setOnlyFragmentToStack(getSupportFragmentManager(), fragment);
} else {
addFragmentToStack(getSupportFragmentManager(), fragment);
}
}
use of org.mazhuang.guanggoo.base.BaseFragment in project guanggoo-android by mzlogin.
the class HomePagerAdapter method getItem.
@Override
public Fragment getItem(int position) {
BaseFragment fragment = null;
String url = null;
switch(position) {
case 0:
url = ConstantUtil.BASE_URL;
break;
case 1:
url = ConstantUtil.LATEST_URL;
break;
case 2:
url = ConstantUtil.ELITE_URL;
break;
case 3:
url = ConstantUtil.FOLLOWS_URL;
break;
default:
break;
}
if (!TextUtils.isEmpty(url)) {
fragment = FragmentFactory.getFragmentByUrl(url);
Bundle bundle = new Bundle();
bundle.putString(BaseFragment.KEY_URL, url);
bundle.putString(BaseFragment.KEY_TITLE, getPageTitle(position).toString());
fragment.setArguments(bundle);
}
return fragment;
}
use of org.mazhuang.guanggoo.base.BaseFragment in project guanggoo-android by mzlogin.
the class MainActivity method onBackPressed.
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
if (isLoading()) {
stopLoading();
return;
}
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
if (fragment instanceof BaseFragment) {
if (((BaseFragment) fragment).onBackPressed()) {
return;
}
}
if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
long backPressTime = System.nanoTime();
long oneSecondNano = 1000 * 1000 * 1000L;
if (backPressTime - mLastBackPressTime > oneSecondNano) {
Toast.makeText(this, getString(R.string.back_to_quit), Toast.LENGTH_SHORT).show();
} else {
finish();
}
mLastBackPressTime = backPressTime;
return;
}
super.onBackPressed();
}
}
use of org.mazhuang.guanggoo.base.BaseFragment in project guanggoo-android by mzlogin.
the class MainActivity method initViews.
private void initViews() {
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
// 设置抽屉菜单图标为图片原色
navigationView.setItemIconTintList(null);
mAvatarImageView = navigationView.getHeaderView(0).findViewById(R.id.avatar);
mUsernameTextView = navigationView.getHeaderView(0).findViewById(R.id.username);
mSearchImageView = navigationView.getHeaderView(0).findViewById(R.id.search);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
switch(view.getId()) {
case R.id.avatar:
case R.id.username:
openUserProfile();
break;
case R.id.search:
openPage(ConstantUtil.SEARCH_URL, null);
break;
default:
break;
}
}
};
mAvatarImageView.setOnClickListener(listener);
mUsernameTextView.setOnClickListener(listener);
mSearchImageView.setOnClickListener(listener);
openPage(ConstantUtil.HOME_URL, getString(R.string.app_name));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean canGoBack = (getSupportFragmentManager().getBackStackEntryCount() > 1);
if (canGoBack) {
onBackPressed();
} else {
drawer.openDrawer(GravityCompat.START);
}
}
});
getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
@Override
public void onBackStackChanged() {
Fragment fragment = getCurrentFragment();
if (fragment instanceof BaseFragment) {
BaseFragment baseFragment = (BaseFragment) fragment;
setTitle(baseFragment.getTitle());
boolean canGoBack = (getSupportFragmentManager().getBackStackEntryCount() > 1);
if (canGoBack) {
toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
} else {
toolbar.setNavigationIcon(R.drawable.ic_menu);
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
StateListAnimator stateListAnimator = new StateListAnimator();
float elevation = 0;
if (!baseFragment.getClass().isAnnotationPresent(StartsWithAppBar.class)) {
elevation = DimensUtil.getDensity(getWindowManager()) * 5;
}
stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(mMainAppBar, "elevation", elevation));
mMainAppBar.setStateListAnimator(stateListAnimator);
}
}
}
});
}
Aggregations