Search in sources :

Example 1 with TabFragment

use of forpdateam.ru.forpda.ui.fragments.TabFragment in project ForPDA by RadiationX.

the class ThemeFragment method updateFavorites.

protected void updateFavorites(ThemePage themePage) {
    if (!ClientHelper.getAuthState() || themePage.getPagination().getCurrent() < themePage.getPagination().getAll())
        return;
    int topicId = themePage.getId();
    TabFragment parentTab = TabManager.get().get(getParentTag());
    if (parentTab == null) {
        parentTab = TabManager.get().getByClass(FavoritesFragment.class);
    }
    if (parentTab == null)
        return;
    if (parentTab instanceof FavoritesFragment) {
        ((FavoritesFragment) parentTab).markRead(topicId);
    } else if (parentTab instanceof TopicsFragment) {
        ((TopicsFragment) parentTab).markRead(topicId);
    }
}
Also used : FavoritesFragment(forpdateam.ru.forpda.ui.fragments.favorites.FavoritesFragment) TopicsFragment(forpdateam.ru.forpda.ui.fragments.topics.TopicsFragment) TabFragment(forpdateam.ru.forpda.ui.fragments.TabFragment) SuppressLint(android.annotation.SuppressLint)

Example 2 with TabFragment

use of forpdateam.ru.forpda.ui.fragments.TabFragment in project ForPDA by RadiationX.

the class Drawers method closeAllTabs.

public void closeAllTabs() {
    new AlertDialog.Builder(activity).setMessage(R.string.ask_close_other_tabs).setPositiveButton(R.string.ok, (dialog, which) -> {
        closeTabs();
        List<TabFragment> fragmentList = new ArrayList<>();
        for (TabFragment fragment : TabManager.get().getFragments()) {
            if (!fragment.getTag().equals(TabManager.getActiveTag())) {
                fragmentList.add(fragment);
            }
        }
        for (TabFragment fragment : fragmentList) {
            TabManager.get().remove(fragment);
        }
    }).setNegativeButton(R.string.no, null).show();
}
Also used : ArrayList(java.util.ArrayList) TabFragment(forpdateam.ru.forpda.ui.fragments.TabFragment)

Example 3 with TabFragment

use of forpdateam.ru.forpda.ui.fragments.TabFragment in project ForPDA by RadiationX.

the class Drawers method firstSelect.

public void firstSelect() {
    if (isFirstSelected)
        return;
    isFirstSelected = true;
    String className = ClientHelper.getAuthState() == ClientHelper.AUTH_STATE_LOGIN ? FavoritesFragment.class.getSimpleName() : AuthFragment.class.getSimpleName();
    String last = App.get().getPreferences().getString("menu_drawer_last", className);
    last = ClientHelper.getAuthState() == ClientHelper.AUTH_STATE_LOGIN && last.equals(AuthFragment.class.getSimpleName()) ? FavoritesFragment.class.getSimpleName() : last;
    Log.d(LOG_TAG, "Last item " + last);
    MenuItems.MenuItem item = null;
    if (this.savedInstanceState != null) {
        TabFragment tabFragment = TabManager.get().get(TabManager.getActiveTag());
        if (tabFragment != null) {
            item = findMenuItem(tabFragment.getClass());
        }
        Log.d(LOG_TAG, "AAAA " + tabFragment + " : " + item);
        if (item != null) {
            item.setAttachedTabTag(tabFragment.getTag());
            item.setActive(true);
            lastActive = item;
        } else {
            item = findMenuItem(last);
        }
    } else {
        item = findMenuItem(last);
    }
    Log.d(LOG_TAG, "Final item " + item);
    if (item == null) {
        item = menuItems.get(0);
    }
    Log.d(LOG_TAG, "FinalFinal item " + item);
    selectMenuItem(item);
/*if (savedInstanceState == null) {
            select(findByClassName(last));
        } else {
            setActive(last);
        }*/
}
Also used : FavoritesFragment(forpdateam.ru.forpda.ui.fragments.favorites.FavoritesFragment) AuthFragment(forpdateam.ru.forpda.ui.fragments.auth.AuthFragment) TabFragment(forpdateam.ru.forpda.ui.fragments.TabFragment)

Example 4 with TabFragment

use of forpdateam.ru.forpda.ui.fragments.TabFragment in project ForPDA by RadiationX.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (EmptyActivity.empty(App.get().getPreferences().getString("auth.user.nick", ""))) {
        startActivity(new Intent(this, EmptyActivity.class));
        finish();
        return;
    }
    Intent intent = getIntent();
    if (intent != null) {
        checkWebView = intent.getBooleanExtra(CHECK_WEBVIEW, checkWebView);
    }
    if (checkWebView) {
        Observable.fromCallable(() -> App.get().isWebViewFound(this)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(aBoolean -> {
            if (!aBoolean) {
                startActivity(new Intent(App.getContext(), WebVewNotFoundActivity.class));
                finish();
            }
        });
    }
    currentThemeIsDark = App.get().isDarkTheme();
    setTheme(currentThemeIsDark ? R.style.DarkAppTheme_NoActionBar : R.style.LightAppTheme_NoActionBar);
    setContentView(R.layout.activity_main);
    DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawerLayout.addDrawerListener(toggle);
    toggle.syncState();
    /*
        * Т.к. 2 вьюхи, делаю цвет в 2 раза прозрачнее, чтобы компенсировать это.
        * P.S. Чем больше вьюх в DrawerLayout находятся до NavigationView, тем сильнее будет затенение
        * P.S.S. Первая вьюха - контейнер фрагментов, вторая - view_for_measure
        * */
    drawerLayout.setScrimColor(0x4C000000);
    drawers = new Drawers(this, drawerLayout);
    drawers.init(savedInstanceState);
    drawerHeader = new DrawerHeader(this, drawerLayout);
    drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            if (drawerView.getId() == R.id.menu_drawer) {
                if (App.get().getPreferences().getBoolean("drawers.tooltip.link_open", true)) {
                    SimpleTooltip tooltip = new SimpleTooltip.Builder(MainActivity.this).anchorView(drawerView.findViewById(R.id.drawer_header_open_link)).text(R.string.tooltip_link).gravity(Gravity.BOTTOM).animated(false).modal(true).transparentOverlay(false).backgroundColor(Color.BLACK).textColor(Color.WHITE).padding((float) App.px16).onDismissListener(simpleTooltip -> tooltips.remove(simpleTooltip)).build();
                    tooltip.show();
                    tooltips.add(tooltip);
                    App.get().getPreferences().edit().putBoolean("drawers.tooltip.link_open", false).apply();
                }
            }
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            if (drawerView.getId() == R.id.menu_drawer) {
                if (App.get().getPreferences().getBoolean("drawers.tooltip.tabs_drawer", true)) {
                    SimpleTooltip tooltip = new SimpleTooltip.Builder(MainActivity.this).anchorView(drawers.getTabDrawer()).text(R.string.tooltip_tabs).gravity(Gravity.START).animated(false).modal(true).transparentOverlay(false).backgroundColor(Color.BLACK).textColor(Color.WHITE).padding((float) App.px16).onDismissListener(simpleTooltip -> tooltips.remove(simpleTooltip)).build();
                    tooltip.show();
                    tooltips.add(tooltip);
                    App.get().getPreferences().edit().putBoolean("drawers.tooltip.tabs_drawer", false).apply();
                }
            }
        }

        @Override
        public void onDrawerStateChanged(int newState) {
            if (newState == DrawerLayout.STATE_DRAGGING) {
                TabFragment fragment = TabManager.get().getActive();
                if (fragment != null) {
                    fragment.hidePopupWindows();
                }
            }
        }
    });
    receiver = new NetworkStateReceiver();
    receiver.registerReceiver();
    KeyboardUtil keyboardUtil = new KeyboardUtil(this, findViewById(R.id.fragments_container));
    keyboardUtil.enable();
    final View viewDiff = findViewById(R.id.view_for_measure);
    viewDiff.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> measureView(v));
    if (Preferences.Notifications.Update.isEnabled(getApplicationContext())) {
        new SimpleUpdateChecker().checkFromGitHub(this);
    }
    checkIntent(getIntent());
}
Also used : SimpleTooltip(io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip) SimpleUpdateChecker(forpdateam.ru.forpda.ui.activities.updatechecker.SimpleUpdateChecker) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) TabFragment(forpdateam.ru.forpda.ui.fragments.TabFragment) View(android.view.View) KeyboardUtil(forpdateam.ru.forpda.ui.views.KeyboardUtil) DrawerLayout(android.support.v4.widget.DrawerLayout) Drawers(forpdateam.ru.forpda.ui.views.drawers.Drawers) NetworkStateReceiver(forpdateam.ru.forpda.common.receivers.NetworkStateReceiver) DrawerHeader(forpdateam.ru.forpda.ui.views.drawers.DrawerHeader)

Example 5 with TabFragment

use of forpdateam.ru.forpda.ui.fragments.TabFragment in project ForPDA by RadiationX.

the class MainActivity method backHandler.

public void backHandler(boolean fromToolbar) {
    /*if (TabManager.get().getSize() <= 1) {
            super.onBackPressed();
        } else {
            if (fromToolbar || !TabManager.get().getActive().onBackPressed()) {
                hideKeyboard();
                TabManager.get().remove(TabManager.get().getActive());
            }
        }*/
    TabFragment active = TabManager.get().getActive();
    if (active == null) {
        finish();
        return;
    }
    if (fromToolbar || !active.onBackPressed()) {
        hideKeyboard();
        TabManager.get().remove(active);
        if (TabManager.get().getSize() < 1) {
            finish();
        }
    }
}
Also used : TabFragment(forpdateam.ru.forpda.ui.fragments.TabFragment)

Aggregations

TabFragment (forpdateam.ru.forpda.ui.fragments.TabFragment)11 Intent (android.content.Intent)2 FavoritesFragment (forpdateam.ru.forpda.ui.fragments.favorites.FavoritesFragment)2 ThemeFragment (forpdateam.ru.forpda.ui.fragments.theme.ThemeFragment)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Handler (android.os.Handler)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 View (android.view.View)1 AttachmentItem (forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)1 ThemePage (forpdateam.ru.forpda.api.theme.models.ThemePage)1 ErrorHandler (forpdateam.ru.forpda.common.ErrorHandler)1 NetworkStateReceiver (forpdateam.ru.forpda.common.receivers.NetworkStateReceiver)1 SimpleUpdateChecker (forpdateam.ru.forpda.ui.activities.updatechecker.SimpleUpdateChecker)1 AuthFragment (forpdateam.ru.forpda.ui.fragments.auth.AuthFragment)1 TopicsFragment (forpdateam.ru.forpda.ui.fragments.topics.TopicsFragment)1 KeyboardUtil (forpdateam.ru.forpda.ui.views.KeyboardUtil)1 DrawerHeader (forpdateam.ru.forpda.ui.views.drawers.DrawerHeader)1 Drawers (forpdateam.ru.forpda.ui.views.drawers.Drawers)1