Search in sources :

Example 1 with RequestFactory

use of com.huetoyou.chatexchange.net.RequestFactory in project ChatExchange by HueToYou.

the class SplashActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    new RequestFactory().get("http://google.com", true, new RequestFactory.Listener() {

        @Override
        public void onSucceeded(URL url, String data) {
            Intent intent = new Intent(SplashActivity.this, MainActivity.class);
            intent.putExtras(getIntent());
            startActivity(intent);
            finish();
        }

        @Override
        public void onFailed(String message) {
            Intent intent = new Intent(SplashActivity.this, OfflineActivity.class);
            startActivity(intent);
            finish();
        }
    });
}
Also used : RequestFactory(com.huetoyou.chatexchange.net.RequestFactory) Intent(android.content.Intent) MainActivity(com.huetoyou.chatexchange.ui.activity.main.MainActivity) URL(java.net.URL)

Example 2 with RequestFactory

use of com.huetoyou.chatexchange.net.RequestFactory in project ChatExchange by HueToYou.

the class BackendService method start.

/**
 * Start the service with the current backend
 *
 * @param token account token
 *              <p>
 *              If an existing backend is running, it is stopped.
 */
@SuppressWarnings("SameReturnValue")
private int start(String token) {
    stop();
    mRequestFactory = new RequestFactory(token);
    mBackend = mSharedPreferences.getString("backend", BACKEND_WEBSOCKET);
    switch(mBackend) {
        case BACKEND_WEBSOCKET:
            startWebSocketBackend();
    }
    // TODO: enter foreground
    return START_STICKY;
}
Also used : RequestFactory(com.huetoyou.chatexchange.net.RequestFactory)

Example 3 with RequestFactory

use of com.huetoyou.chatexchange.net.RequestFactory in project ChatExchange by HueToYou.

the class ChatroomsExplorationActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    ThemeHue.setTheme(this);
    super.onCreate(null);
    normalOnCreate();
    new RequestFactory().get("http://www.google.com/", true, new RequestFactory.Listener() {

        @Override
        public void onSucceeded(URL url, String data) {
            ((SE_ChatroomsFrag) mSectionsPagerAdapter.getFragmentForPosition(mViewPager, 0)).proceedToWebpageLoading();
            ((SO_ChatroomsFrag) mSectionsPagerAdapter.getFragmentForPosition(mViewPager, 1)).proceedToWebpageLoading();
            internetConfirmed = true;
        }

        @Override
        public void onFailed(String message) {
            Intent intent = new Intent(ChatroomsExplorationActivity.this, OfflineActivity.class);
            startActivity(intent);
            finish();
        }
    });
}
Also used : RequestFactory(com.huetoyou.chatexchange.net.RequestFactory) Intent(android.content.Intent) URL(java.net.URL)

Example 4 with RequestFactory

use of com.huetoyou.chatexchange.net.RequestFactory in project ChatExchange by HueToYou.

the class BackendService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    // TODO: need the "auth" token to make this work
    // TODO: decide how this works with multiple accounts
    mRequestFactory = new RequestFactory();
}
Also used : RequestFactory(com.huetoyou.chatexchange.net.RequestFactory)

Example 5 with RequestFactory

use of com.huetoyou.chatexchange.net.RequestFactory 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

RequestFactory (com.huetoyou.chatexchange.net.RequestFactory)8 Intent (android.content.Intent)5 URL (java.net.URL)5 IntentFilter (android.content.IntentFilter)2 Bundle (android.os.Bundle)2 View (android.view.View)2 AccountManagerCallback (android.accounts.AccountManagerCallback)1 AccountManagerFuture (android.accounts.AccountManagerFuture)1 ObjectAnimator (android.animation.ObjectAnimator)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 ViewPager (android.support.v4.view.ViewPager)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 ActionBarContainer (android.support.v7.widget.ActionBarContainer)1 ActionBarOverlayLayout (android.support.v7.widget.ActionBarOverlayLayout)1 ActionMenuView (android.support.v7.widget.ActionMenuView)1 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 LinearLayoutCompat (android.support.v7.widget.LinearLayoutCompat)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ScrollingTabContainerView (android.support.v7.widget.ScrollingTabContainerView)1