Search in sources :

Example 1 with BaseFragment

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;
}
Also used : NodesCloudFragment(org.mazhuang.guanggoo.nodescloud.NodesCloudFragment) AboutFragment(org.mazhuang.guanggoo.about.AboutFragment) ReplyListFragment(org.mazhuang.guanggoo.userprofile.replies.ReplyListFragment) LoginPresenter(org.mazhuang.guanggoo.login.LoginPresenter) TopicListPresenter(org.mazhuang.guanggoo.topiclist.TopicListPresenter) SelectNodeFragment(org.mazhuang.guanggoo.newtopic.SelectNodeFragment) TopicDetailPresenter(org.mazhuang.guanggoo.topicdetail.TopicDetailPresenter) UserProfileFragment(org.mazhuang.guanggoo.userprofile.UserProfileFragment) HomeFragment(org.mazhuang.guanggoo.home.HomeFragment) LoginFragment(org.mazhuang.guanggoo.login.LoginFragment) BaseFragment(org.mazhuang.guanggoo.base.BaseFragment) NodesCloudPresenter(org.mazhuang.guanggoo.nodescloud.NodesCloudPresenter) NewTopicPresenter(org.mazhuang.guanggoo.newtopic.NewTopicPresenter) TopicDetailFragment(org.mazhuang.guanggoo.topicdetail.TopicDetailFragment) TopicListFragment(org.mazhuang.guanggoo.topiclist.TopicListFragment) UserProfilePresenter(org.mazhuang.guanggoo.userprofile.UserProfilePresenter) ReplyListPresenter(org.mazhuang.guanggoo.userprofile.replies.ReplyListPresenter) ViewImageFragment(org.mazhuang.guanggoo.topicdetail.viewimage.ViewImageFragment) NewTopicFragment(org.mazhuang.guanggoo.newtopic.NewTopicFragment) ViewImagePresenter(org.mazhuang.guanggoo.topicdetail.viewimage.ViewImagePresenter)

Example 2 with BaseFragment

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);
    }
}
Also used : Bundle(android.os.Bundle) BaseFragment(org.mazhuang.guanggoo.base.BaseFragment) Fragment(android.support.v4.app.Fragment) BaseFragment(org.mazhuang.guanggoo.base.BaseFragment)

Example 3 with BaseFragment

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;
}
Also used : Bundle(android.os.Bundle) BaseFragment(org.mazhuang.guanggoo.base.BaseFragment)

Example 4 with BaseFragment

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();
    }
}
Also used : DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) BaseFragment(org.mazhuang.guanggoo.base.BaseFragment) Fragment(androidx.fragment.app.Fragment) BaseFragment(org.mazhuang.guanggoo.base.BaseFragment)

Example 5 with BaseFragment

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);
                }
            }
        }
    });
}
Also used : NavigationView(com.google.android.material.navigation.NavigationView) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) StateListAnimator(android.animation.StateListAnimator) NavigationView(com.google.android.material.navigation.NavigationView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) BaseFragment(org.mazhuang.guanggoo.base.BaseFragment) Fragment(androidx.fragment.app.Fragment) BaseFragment(org.mazhuang.guanggoo.base.BaseFragment) FragmentManager(androidx.fragment.app.FragmentManager) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

BaseFragment (org.mazhuang.guanggoo.base.BaseFragment)6 Bundle (android.os.Bundle)3 Fragment (androidx.fragment.app.Fragment)3 DrawerLayout (androidx.drawerlayout.widget.DrawerLayout)2 StateListAnimator (android.animation.StateListAnimator)1 Fragment (android.support.v4.app.Fragment)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ActionBarDrawerToggle (androidx.appcompat.app.ActionBarDrawerToggle)1 Toolbar (androidx.appcompat.widget.Toolbar)1 FragmentManager (androidx.fragment.app.FragmentManager)1 BindView (butterknife.BindView)1 NavigationView (com.google.android.material.navigation.NavigationView)1 AboutFragment (org.mazhuang.guanggoo.about.AboutFragment)1 HomeFragment (org.mazhuang.guanggoo.home.HomeFragment)1 LoginFragment (org.mazhuang.guanggoo.login.LoginFragment)1 LoginPresenter (org.mazhuang.guanggoo.login.LoginPresenter)1 NewTopicFragment (org.mazhuang.guanggoo.newtopic.NewTopicFragment)1 NewTopicPresenter (org.mazhuang.guanggoo.newtopic.NewTopicPresenter)1