Search in sources :

Example 1 with HomeFragment

use of com.huetoyou.chatexchange.ui.frags.HomeFragment in project ChatExchange by HueToYou.

the class FragStuff method setFragmentByTag.

/**
 * Open a chat using its tag
 *
 * @param tag the chat's fragment tag (should be its URL)
 */
public void setFragmentByTag(String tag) {
    Log.e("TAG", tag);
    if (mainActivity.mFragmentManager.getFragments() != null) {
        for (Fragment fragment : mainActivity.mFragmentManager.getFragments()) {
            if (fragment != null && !fragment.isDetached()) {
                mainActivity.mFragmentManager.beginTransaction().detach(fragment).commit();
            }
        }
        Fragment fragToAttach = mainActivity.mFragmentManager.findFragmentByTag(tag);
        if (fragToAttach != null) {
            if (tag.equals("home")) {
                mainActivity.mFragmentManager.beginTransaction().setCustomAnimations(R.anim.fade_in, R.anim.fade_out).attach(fragToAttach).commit();
                mainActivity.mCurrentUsers_SlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
                ((HomeFragment) fragToAttach).hueTest();
            } else {
                if (mainActivity.mFragmentManager.findFragmentByTag("home").isDetached()) {
                    mainActivity.mFragmentManager.beginTransaction().attach(fragToAttach).commit();
                } else {
                    mainActivity.mFragmentManager.beginTransaction().setCustomAnimations(R.anim.fade_in, R.anim.fade_out).attach(fragToAttach).commit();
                }
                mainActivity.mCurrentUsers_SlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
            }
        } else {
            Log.e("TAG", tag);
        }
    }
}
Also used : Fragment(android.support.v4.app.Fragment) HomeFragment(com.huetoyou.chatexchange.ui.frags.HomeFragment) ChatFragment(com.huetoyou.chatexchange.ui.frags.ChatFragment) HomeFragment(com.huetoyou.chatexchange.ui.frags.HomeFragment)

Example 2 with HomeFragment

use of com.huetoyou.chatexchange.ui.frags.HomeFragment in project ChatExchange by HueToYou.

the class MainActivity method setup.

private void setup() {
    final FloatingActionMenu fam = findViewById(R.id.chat_slide_menu);
    FloatingActionButton floatingActionButton = findViewById(R.id.add_chat_fab);
    floatingActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mainActivityUtils.showAddTabDialog();
            fam.close(true);
        }
    });
    FloatingActionButton fab = findViewById(R.id.home_fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    Log.e("POS", "DEFL");
                    fragStuff.setFragmentByTag("home");
                }
            }, getResources().getInteger(R.integer.animation_duration_ms));
            // doCloseAnimationForDrawerToggle(mDrawerButton);
            mChatroomSlidingMenu.toggle();
            fam.close(false);
        }
    });
    mRequestFactory = new RequestFactory();
    mAccountManager = AccountManager.get(this);
    AccountManagerCallback<Bundle> accountManagerCallback = new AccountManagerCallback<Bundle>() {

        @Override
        public void run(AccountManagerFuture<Bundle> accountManagerFuture) {
            Log.e("AUtH", "AAA");
            String authToken = "";
            try {
                authToken = accountManagerFuture.getResult().getString(AccountManager.KEY_AUTHTOKEN);
                Log.e("Auth", authToken);
            } catch (Exception e) {
                e.printStackTrace();
                Log.e("RI", "P");
            }
            mRequestFactory = new RequestFactory(authToken);
            mCookieString = authToken;
            Log.e("AUTHTOKEN", authToken);
            CookieSyncManager.createInstance(MainActivity.this);
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(true);
            if (authToken != null) {
                cookieManager.removeSessionCookie();
                cookieManager.setCookie("https://stackexchange.com", authToken);
                CookieSyncManager.getInstance().sync();
            }
            fragStuff.doFragmentStuff();
        }
    };
    Set<String> seChatsTemp = mSharedPrefs.getStringSet("SEChatIDs", new HashSet<String>());
    Set<String> soChatsTemp = mSharedPrefs.getStringSet("SOChatIDs", new HashSet<String>());
    chatDataBundle.mSOChatIDs = new HashSet<>(soChatsTemp);
    chatDataBundle.mSEChatIDs = new HashSet<>(seChatsTemp);
    if (mSharedPrefs.getBoolean("isFirstRun", true)) {
        Intent intent = new Intent(this, IntroActivity.class);
        startActivity(intent);
        finish();
    } else if (mAccountManager.getAccounts().length < 1) {
        startActivity(new Intent(this, AuthenticatorActivity.class));
        finish();
    } else {
        if (mFragmentManager.findFragmentByTag("home") == null) {
            mFragmentManager.beginTransaction().add(R.id.content_main, new HomeFragment(), "home").commit();
        }
        mAccountManager.getAuthToken(mAccountManager.getAccounts()[0], Authenticator.ACCOUNT_TYPE, null, true, accountManagerCallback, null);
    }
    mainActivityUtils.respondToNotificationClick();
    mainActivityUtils.setupACBR();
    mItemClickedListener = new RecyclerAdapter.OnItemClicked() {

        @Override
        public void onClick(View view, int position) {
            Log.e("CLICKED", position + "");
            mCurrentFragment = mWrappedAdapter.getItemAt(position).getUrl();
            // doCloseAnimationForDrawerToggle(mDrawerButton);
            getmChatroomSlidingMenu().toggle();
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    fragStuff.setFragmentByTag(mCurrentFragment);
                }
            }, getResources().getInteger(R.integer.animation_duration_ms));
        }

        @Override
        public void onCloseClick(View view, int position) {
            mainActivityUtils.confirmClose(position);
        }
    };
    chatroomsList = findViewById(R.id.chatroomsListView);
    mSwipeManager = new RecyclerViewSwipeManager();
    mWrappedAdapter = new RecyclerAdapter(this, mItemClickedListener, mSwipeManager);
    mAdapter = mSwipeManager.createWrappedAdapter(mWrappedAdapter);
    chatroomsList.setAdapter(mAdapter);
    // disable change animations
    ((SimpleItemAnimator) chatroomsList.getItemAnimator()).setSupportsChangeAnimations(false);
    mSwipeManager.attachRecyclerView(chatroomsList);
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(chatroomsList.getContext(), DividerItemDecoration.VERTICAL);
    chatroomsList.addItemDecoration(dividerItemDecoration);
    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    drawable = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu_black_24dp, null);
    drawable.setTintList(ColorStateList.valueOf(Color.rgb(255, 255, 255)));
    getSupportActionBar().setHomeAsUpIndicator(drawable);
    fam.hideMenuButton(false);
    mActionBar = (Toolbar) Utils.getActionBar(getWindow().getDecorView());
    assert mActionBar != null;
    Log.e("ACTIONBAR", mActionBar.getClass().toString());
    // mActionBar.removeViewAt(1);
    // mActionBar.addView(newDrawer, 1);
    mDrawerButton = (AppCompatImageButton) mActionBar.getChildAt(1);
    ObjectAnimator closeAnimator = ObjectAnimator.ofFloat(mDrawerButton, "rotation", 180f, 0f);
    mCloseAnimSet.play(closeAnimator);
    mCloseAnimSet.setInterpolator(new AnticipateInterpolator());
    mCloseAnimSet.setDuration((long) Utils.getAnimDuration(getResources().getInteger(R.integer.animation_duration_ms), MainActivity.this));
    ObjectAnimator openAnimator = ObjectAnimator.ofFloat(mDrawerButton, "rotation", -180f, 0f);
    mOpenAnimSet.play(openAnimator);
    mOpenAnimSet.setInterpolator(new OvershootInterpolator());
    mOpenAnimSet.setDuration((long) Utils.getAnimDuration(getResources().getInteger(R.integer.animation_duration_ms), MainActivity.this));
    mDrawerButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Log.e("CLICKED", "CLICKED");
            onSupportNavigateUp();
        }
    });
    mChatroomSlidingMenu.setOnCloseListener(new SlidingMenu.OnCloseListener() {

        @Override
        public void onClose() {
            fam.close(false);
            fam.hideMenuButton(false);
            doCloseAnimationForDrawerToggle(mDrawerButton);
        }
    });
    mChatroomSlidingMenu.setOnOpenListener(new SlidingMenu.OnOpenListener() {

        @Override
        public void onOpen() {
            doOpenAnimationForDrawerToggle(mDrawerButton);
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    fam.showMenuButton(true);
                }
            }, getResources().getInteger(R.integer.animation_duration_ms) - 400);
        }
    });
    mChatroomSlidingMenu.setOnOpenedListener(new SlidingMenu.OnOpenedListener() {

        @Override
        public void onOpened() {
            TutorialStuff.showChatSliderTutorial_MainActivity(MainActivity.this);
        }
    });
    Log.e("FEATURE", String.valueOf(getWindow().hasFeature(Window.FEATURE_OPTIONS_PANEL)));
    mActionMenuView = (ActionMenuView) mActionBar.getChildAt(2);
    oncreatejustcalled = true;
    // forces options menu overflow icon to show on devices with physical menu keys
    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception e) {
    // presumably, not relevant
    }
}
Also used : AccountManagerCallback(android.accounts.AccountManagerCallback) AccountManagerFuture(android.accounts.AccountManagerFuture) HomeFragment(com.huetoyou.chatexchange.ui.frags.HomeFragment) FloatingActionMenu(com.github.clans.fab.FloatingActionMenu) SlidingMenu(com.jeremyfeinstein.slidingmenu.lib.SlidingMenu) ViewConfiguration(android.view.ViewConfiguration) Field(java.lang.reflect.Field) RequestFactory(com.huetoyou.chatexchange.net.RequestFactory) FloatingActionButton(com.github.clans.fab.FloatingActionButton) CookieManager(android.webkit.CookieManager) RecyclerViewSwipeManager(com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager) SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) OvershootInterpolator(android.view.animation.OvershootInterpolator) Bundle(android.os.Bundle) ChatDataBundle(com.huetoyou.chatexchange.ui.misc.ChatDataBundle) ObjectAnimator(android.animation.ObjectAnimator) Intent(android.content.Intent) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) View(android.view.View) CustomRecyclerView(com.huetoyou.chatexchange.ui.misc.CustomRecyclerView) ActionMenuView(android.support.v7.widget.ActionMenuView) RecyclerView(android.support.v7.widget.RecyclerView) AnticipateInterpolator(android.view.animation.AnticipateInterpolator) RecyclerAdapter(com.huetoyou.chatexchange.ui.misc.RecyclerAdapter)

Aggregations

HomeFragment (com.huetoyou.chatexchange.ui.frags.HomeFragment)2 AccountManagerCallback (android.accounts.AccountManagerCallback)1 AccountManagerFuture (android.accounts.AccountManagerFuture)1 ObjectAnimator (android.animation.ObjectAnimator)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Fragment (android.support.v4.app.Fragment)1 ActionMenuView (android.support.v7.widget.ActionMenuView)1 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SimpleItemAnimator (android.support.v7.widget.SimpleItemAnimator)1 View (android.view.View)1 ViewConfiguration (android.view.ViewConfiguration)1 AnticipateInterpolator (android.view.animation.AnticipateInterpolator)1 OvershootInterpolator (android.view.animation.OvershootInterpolator)1 CookieManager (android.webkit.CookieManager)1 FloatingActionButton (com.github.clans.fab.FloatingActionButton)1 FloatingActionMenu (com.github.clans.fab.FloatingActionMenu)1 RecyclerViewSwipeManager (com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager)1 RequestFactory (com.huetoyou.chatexchange.net.RequestFactory)1