anilchahal7

BottombarNavigation

Jun 1st, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.14 KB | None | 0 0
  1. package in.hopscotch.android.activity.parent;
  2.  
  3. import android.app.SearchManager;
  4. import android.content.BroadcastReceiver;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.IntentFilter;
  8. import android.graphics.Color;
  9. import android.os.Build;
  10. import android.os.Bundle;
  11. import android.support.v4.app.Fragment;
  12. import android.support.v4.app.FragmentManager;
  13. import android.support.v4.app.FragmentTransaction;
  14. import android.support.v4.content.LocalBroadcastManager;
  15. import android.support.v7.app.ActionBar;
  16. import android.support.v7.widget.SearchView;
  17. import android.support.v7.widget.Toolbar;
  18. import android.text.TextUtils;
  19. import android.util.Log;
  20. import android.util.TypedValue;
  21. import android.view.Gravity;
  22. import android.view.Menu;
  23. import android.view.MenuItem;
  24. import android.view.View;
  25. import android.view.ViewGroup;
  26. import android.widget.FrameLayout;
  27. import android.widget.LinearLayout;
  28. import android.widget.TextView;
  29.  
  30. import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
  31. import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
  32. import com.crashlytics.android.Crashlytics;
  33. import com.shamanland.fonticon.FontIconDrawable;
  34. import com.shamanland.fonticon.FontIconView;
  35.  
  36. import java.util.ArrayList;
  37. import java.util.List;
  38.  
  39. import in.hopscotch.android.R;
  40. import in.hopscotch.android.activity.HomePageActivity;
  41. import in.hopscotch.android.activity.JoinActivity;
  42. import in.hopscotch.android.activity.ProductDetailPageActivity;
  43. import in.hopscotch.android.activity.ProductListPageActivity;
  44. import in.hopscotch.android.activity.SearchResultsShowingBoutiquesActivity;
  45. import in.hopscotch.android.activity.ShoppingCartActivity;
  46. import in.hopscotch.android.activity.base.BaseActivity;
  47. import in.hopscotch.android.application.CartData;
  48. import in.hopscotch.android.application.IntentHelper;
  49. import in.hopscotch.android.fragment.AboutMeFragment;
  50. import in.hopscotch.android.fragment.BoutiquesFragment;
  51. import in.hopscotch.android.fragment.HomeSearchFragment;
  52. import in.hopscotch.android.fragment.RecentlyFragment;
  53. import in.hopscotch.android.fragment.ShopForFragment;
  54. import in.hopscotch.android.fragment.base.SlidingTabsColorsFragment;
  55. import in.hopscotch.android.model.UserStatus;
  56. import in.hopscotch.android.util.AnimationUtil;
  57. import in.hopscotch.android.util.Constants;
  58. import in.hopscotch.android.util.Util;
  59. import in.hopscotch.android.widget.CircleCartButton;
  60. import in.hopscotch.android.widget.CustomTextView;
  61.  
  62. /**
  63. * Created by Anil Chahal on 12/05/2016.
  64. *
  65. * @author Anil Chahal
  66. */
  67. public class BottombarNavigationActivity extends BaseActivity {
  68.  
  69. protected final String BOTTOM_NAVIGATION_ITEM = "bottom_navigation_item";
  70.  
  71. protected Toolbar mToolbar;
  72.  
  73. protected ActionBar actionBar;
  74.  
  75. protected View mContent;
  76.  
  77. protected MenuItem recentItem, searchItemField;
  78.  
  79. protected CircleCartButton mFloatingButton;
  80.  
  81. protected FrameLayout mMainLayout, mBlankLayout, mRecentlyViewLayout, mWholeContainer;
  82.  
  83. protected LinearLayout toolbarContainer;
  84.  
  85. private LinearLayout alertLayout;
  86.  
  87. private TextView alertText;
  88.  
  89. private FontIconView alertClose;
  90.  
  91. private String currentSelectedRowClassName;
  92.  
  93. public SearchView searchView;
  94.  
  95. private Fragment tabFragment;
  96.  
  97. protected ArrayList<AHBottomNavigationItem> bottomNavigationItems = new ArrayList<>();
  98. public AHBottomNavigation bottomNavigation;
  99. protected FragmentManager fragmentManager = getSupportFragmentManager();
  100. protected List<Fragment> mTabsFragments = new ArrayList<>();
  101.  
  102. private BottomNavigationBarClickListener mListener;
  103.  
  104. private final BroadcastReceiver mCartUpdateBroadcastReceiver = new BroadcastReceiver() {
  105. @Override
  106. public void onReceive(Context context, Intent intent) {
  107. if (intent.getAction() != null && intent.getAction()
  108. .equals(CartData.ACTION_CART_QUANTITY)) {
  109. Log.d("TAG", "QTY: " + intent
  110. .getIntExtra(CartData.QUANTITY, CartData.getCartQuantity()));
  111. if (bottomNavigation != null) {
  112. bottomNavigation.setNotification(CartData.getCartQuantity(), Constants.CART_TAB);
  113. }
  114. }
  115. }
  116. };
  117.  
  118. @Override
  119. protected void onCreate(Bundle savedInstanceState) {
  120. super.onCreate(savedInstanceState);
  121. setContentView(R.layout.activity_bottombar_navigation);
  122. currentSelectedRowClassName =
  123. getIntent().getStringExtra(IntentHelper.DRAWER_CURRENT_CLASS_NAME);
  124. if (currentSelectedRowClassName == null) {
  125. currentSelectedRowClassName = "";
  126. }
  127.  
  128. mWholeContainer = (FrameLayout) findViewById(R.id.wholeContainer);
  129. toolbarContainer = (LinearLayout) findViewById(R.id.toolbarContainer);
  130. mToolbar = (Toolbar) findViewById(R.id.toolbar);
  131. if (mToolbar != null) {
  132. setSupportActionBar(mToolbar);
  133. actionBar = getSupportActionBar();
  134. }
  135. IntentFilter myIntentFilter = new IntentFilter();
  136. myIntentFilter.addAction(CartData.ACTION_CART_QUANTITY);
  137. LocalBroadcastManager.getInstance(getApplicationContext())
  138. .registerReceiver(mCartUpdateBroadcastReceiver, myIntentFilter);
  139.  
  140. LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(
  141. ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  142. linearLayoutParams.height = getSupportActionBar().getHeight() - Util.convertDpToPixel(this, 9);
  143. mToolbar.setLayoutParams(linearLayoutParams);
  144. mContent = findViewById(R.id.mainArea);
  145. mMainLayout = (FrameLayout) findViewById(R.id.mainLayout);
  146. mBlankLayout = (FrameLayout) findViewById(R.id.emptyLayout);
  147. mRecentlyViewLayout = (FrameLayout) findViewById(R.id.recently_viewed_container);
  148. alertLayout = (LinearLayout) findViewById(R.id.alertLayout);
  149. alertText = (TextView) findViewById(R.id.alertText);
  150. alertClose = (FontIconView) findViewById(R.id.alertClose);
  151. alertClose.setOnClickListener(new View.OnClickListener() {
  152. @Override
  153. public void onClick(View v) {
  154. AnimationUtil.collapse(alertLayout);
  155. }
  156. });
  157. mFloatingButton = (CircleCartButton) findViewById(R.id.floatingButton);
  158. if (actionBar != null) {
  159. if (!TextUtils.isEmpty(getIntent().getStringExtra(IntentHelper.INTENT_EXTRA_TITLE))) {
  160. actionBar.setTitle(Util.getSpannableWithCustomFont(
  161. this, getIntent().getStringExtra(IntentHelper.INTENT_EXTRA_TITLE)));
  162. } else {
  163. actionBar.setTitle(Util.getSpannableWithCustomFont(
  164. this, getString(R.string.app_name)));
  165. }
  166. }
  167. setUpBottomNavBar();
  168. }
  169.  
  170. public void setUpBottomNavBar() {
  171. bottomNavigation = (AHBottomNavigation) findViewById(R.id.bottom_navigation);
  172. AHBottomNavigationItem discoverBar = new AHBottomNavigationItem("Home",
  173. FontIconDrawable.inflate(this, R.xml.bottom_home_tab),
  174. getResources().getColor(R.color.button_gray));
  175. AHBottomNavigationItem categoryBar = new AHBottomNavigationItem("Category",
  176. FontIconDrawable.inflate(this, R.xml.bottom_category_tab),
  177. getResources().getColor(R.color.button_gray));
  178. AHBottomNavigationItem searchBar = new AHBottomNavigationItem("Search",
  179. FontIconDrawable.inflate(this, R.xml.bottom_search_tab),
  180. getResources().getColor(R.color.button_gray));
  181. AHBottomNavigationItem meBar = new AHBottomNavigationItem("Me",
  182. FontIconDrawable.inflate(this, R.xml.bottom_me_tab),
  183. getResources().getColor(R.color.button_gray));
  184. AHBottomNavigationItem cartBar = new AHBottomNavigationItem("Cart",
  185. FontIconDrawable.inflate(this, R.xml.bottom_cart_tab),
  186. getResources().getColor(R.color.button_gray));
  187.  
  188. bottomNavigationItems.add(discoverBar);
  189. bottomNavigationItems.add(categoryBar);
  190. bottomNavigationItems.add(searchBar);
  191. bottomNavigationItems.add(meBar);
  192. bottomNavigationItems.add(cartBar);
  193.  
  194. bottomNavigation.addItems(bottomNavigationItems);
  195. bottomNavigation.setAccentColor(Color.parseColor("#FF6299"));
  196. bottomNavigation.setInactiveColor(Color.parseColor("#747474"));
  197. bottomNavigation.setNotificationBackgroundColor(Color.parseColor("#FF6299"));
  198. bottomNavigation.setColored(false);
  199. bottomNavigation.setForceTint(true);
  200. bottomNavigation.setUseElevation(false);
  201. bottomNavigation.setForceTitlesDisplay(true);
  202.  
  203. bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
  204. @Override
  205. public void onTabSelected(int position, boolean wasSelected) {
  206. switch (position) {
  207. case Constants.HOME_TAB:
  208. showHideMenuItems(position);
  209. setActionBarTitle(Util.getActionBarTitleName(BottombarNavigationActivity.this,
  210. position));
  211. if (BottombarNavigationActivity.this instanceof
  212. ProductListPageActivity) {
  213. smoothFinishofActivity(position);
  214. }
  215. if (BottombarNavigationActivity.this instanceof
  216. SearchResultsShowingBoutiquesActivity) {
  217. smoothFinishofActivity(position);
  218. }
  219. break;
  220. case Constants.CATEGORY_TAB:
  221. showHideMenuItems(position);
  222. setActionBarTitle(Util.getActionBarTitleName(BottombarNavigationActivity.this,
  223. position));
  224. if (BottombarNavigationActivity.this instanceof
  225. ProductListPageActivity) {
  226. smoothFinishofActivity(position);
  227. }
  228. if (BottombarNavigationActivity.this instanceof
  229. SearchResultsShowingBoutiquesActivity) {
  230. smoothFinishofActivity(position);
  231. }
  232. break;
  233. case Constants.SEARCH_TAB:
  234. showHideMenuItems(position);
  235. if (BottombarNavigationActivity.this instanceof
  236. ProductListPageActivity) {
  237. smoothFinishofActivity(position);
  238. }
  239. if (BottombarNavigationActivity.this instanceof
  240. SearchResultsShowingBoutiquesActivity) {
  241. smoothFinishofActivity(position);
  242. }
  243. break;
  244. case Constants.ME_TAB:
  245. showHideMenuItems(position);
  246. setActionBarTitle(Util.getActionBarTitleName(BottombarNavigationActivity.this,
  247. position));
  248. if (BottombarNavigationActivity.this instanceof
  249. ProductListPageActivity) {
  250. smoothFinishofActivity(position);
  251. }
  252. if (BottombarNavigationActivity.this instanceof
  253. SearchResultsShowingBoutiquesActivity) {
  254. smoothFinishofActivity(position);
  255. }
  256. break;
  257. case Constants.CART_TAB:
  258. showHideMenuItems(position);
  259. Util.inVokeShoppingCart(BottombarNavigationActivity.this,
  260. (BottombarNavigationActivity.this instanceof HomePageActivity));
  261. if (BottombarNavigationActivity.this instanceof
  262. ProductListPageActivity) {
  263. smoothFinishofActivity(position);
  264. }
  265. if (BottombarNavigationActivity.this instanceof
  266. SearchResultsShowingBoutiquesActivity) {
  267. smoothFinishofActivity(position);
  268. }
  269. return;
  270. default:
  271. break;
  272. }
  273.  
  274. Fragment requestedFragment = mTabsFragments.get(position);
  275. if (wasSelected && requestedFragment instanceof AboutMeFragment) {
  276. //((AboutMeFragment) requestedFragment).goOnTop();
  277. return;
  278. } else if (wasSelected && requestedFragment instanceof BoutiquesFragment) {
  279. //((BoutiquesFragment) requestedFragment).goOnTop();
  280. return;
  281. }
  282. setCurrentItem(position);
  283. }
  284. });
  285.  
  286. mTabsFragments.add(new BoutiquesFragment.BoutiqueTab(getString(R.string.Bestsellers),
  287. Color.WHITE).createFragment());
  288. mTabsFragments.add(new ShopForFragment());
  289. mTabsFragments.add(new HomeSearchFragment());
  290. mTabsFragments.add(new AboutMeFragment());
  291. mTabsFragments.add(new Fragment());
  292.  
  293. boolean firstTabToBeAdded = true;
  294. Intent intent = getIntent();
  295. if (intent != null) {
  296. int position = intent.getIntExtra(IntentHelper.HOME_TAB, -1);
  297. if (position != -1 && position > Constants.HOME_TAB) {
  298. firstTabToBeAdded = false;
  299. setCurrentItem(position);
  300. }
  301. }
  302.  
  303. if (this instanceof HomePageActivity && firstTabToBeAdded) {
  304. setActionBarTitle(Util.getActionBarTitleName(
  305. BottombarNavigationActivity.this, Constants.HOME_TAB));
  306. fragmentManager.beginTransaction()
  307. .replace(R.id.wholeContainer, mTabsFragments.get(Constants.HOME_TAB), "" + Constants.HOME_TAB)
  308. .setCustomAnimations(R.anim.bottom_navigation_bar_fade_in,
  309. R.anim.bottom_navigation_bar_fade_out)
  310. .commit();
  311. }
  312. }
  313.  
  314. @Override
  315. public boolean onCreateOptionsMenu(Menu menu) {
  316. getMenuInflater().inflate(R.menu.include_recently_viewed, menu);
  317. recentItem = menu.findItem(R.id.actionbar_recently_viewed);
  318. recentItem.getActionView().setOnClickListener(new View.OnClickListener() {
  319. @Override
  320. public void onClick(View v) {
  321. onOptionsItemSelected(recentItem);
  322. }
  323. });
  324. getMenuInflater().inflate(R.menu.include_search_field, menu);
  325. searchItemField = menu.findItem(R.id.actionbar_search_field);
  326. // Associate searchable configuration with the SearchView
  327. SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  328. searchView = (SearchView) searchItemField.getActionView();
  329. searchView.setIconified(true);
  330. searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  331.  
  332. searchView.setOnSearchClickListener(new View.OnClickListener() {
  333. @Override
  334. public void onClick(View v) {
  335. bottomNavigation.hideBottomNavigation();
  336. }
  337. });
  338. TextView searchText = (TextView) searchView.findViewById(
  339. android.support.v7.appcompat.R.id.search_src_text);
  340. searchText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  341. @Override
  342. public void onFocusChange(View v, boolean hasFocus) {
  343. if (hasFocus) {
  344. bottomNavigation.hideBottomNavigation();
  345. } else {
  346. bottomNavigation.restoreBottomNavigation(true);
  347. }
  348. }
  349. });
  350.  
  351. if (BottombarNavigationActivity.this instanceof ShoppingCartActivity ||
  352. BottombarNavigationActivity.this instanceof ProductListPageActivity ||
  353. BottombarNavigationActivity.this instanceof ProductDetailPageActivity ||
  354. BottombarNavigationActivity.this instanceof JoinActivity) {
  355. showHideMenuItems(Constants.CART_TAB);
  356. } else {
  357. showHideMenuItems(bottomNavigation.getCurrentItem());
  358. }
  359. return super.onCreateOptionsMenu(menu);
  360. }
  361.  
  362. @Override
  363. public boolean onOptionsItemSelected(MenuItem item) {
  364. boolean ret = true;
  365. switch (item.getItemId()) {
  366. case R.id.actionbar_recently_viewed:
  367. if(!UserStatus.getInstance().getLoginStatus()) {
  368. Intent intent = IntentHelper.createIntent(this, JoinActivity.class);
  369. intent.putExtra(IntentHelper.INTENT_EXTRA_FLAG, JoinActivity.LOGIN_FLAG_GO);
  370. intent.putExtra(IntentHelper.INTENT_FLAG_SIGN_ACTION,
  371. Constants.FROM_RECENTLY_VIEWED);
  372. startActivity(intent);
  373. }
  374. else {
  375. if (tabFragment != null && tabFragment.isAdded()) {
  376. return true;
  377. }
  378. showRecentlyView();
  379. }
  380. ret = true;
  381. break;
  382. case R.id.actionbar_search_field:
  383. bottomNavigation.hideBottomNavigation();
  384. break;
  385. default:
  386. ret = super.onOptionsItemSelected(item);
  387. }
  388. return ret;
  389. }
  390.  
  391.  
  392. private void showHideMenuItems(int position){
  393. if (recentItem == null || searchItemField == null) {
  394. return;
  395. }
  396. if (position == Constants.SEARCH_TAB) {
  397. recentItem.setVisible(false);
  398. searchItemField.setVisible(true);
  399. setActionBarTitle("");
  400. } else if (position == Constants.CART_TAB || position == Constants.ME_TAB ||
  401. position == Constants.CATEGORY_TAB){
  402. recentItem.setVisible(false);
  403. searchItemField.setVisible(false);
  404. } else {
  405. recentItem.setVisible(true);
  406. searchItemField.setVisible(false);
  407. setActionBarTitle(Util.getActionBarTitleName(
  408. BottombarNavigationActivity.this, Constants.HOME_TAB));
  409. bottomNavigation.restoreBottomNavigation(true);
  410. }
  411. }
  412.  
  413. @Override
  414. public void onNewIntent(Intent newIntent) {
  415. super.onNewIntent(newIntent);
  416. }
  417.  
  418. @Override
  419. protected void onResume() {
  420. super.onResume();
  421. CartData.resumeCartQuantity(this);
  422. if (BottombarNavigationActivity.this instanceof SearchResultsShowingBoutiquesActivity &&
  423. Util.getKillSearchResultsBoutiquesActivity()) {
  424. BottombarNavigationActivity.this.finish();
  425. Util.setKillSearchResultsBoutiquesActivity(false);
  426. }
  427. }
  428.  
  429. public void setActionBarTitle(String title) {
  430. if (actionBar != null) {
  431. actionBar.setTitle(Util.getSpannableWithCustomFont(this, title));
  432. }
  433. }
  434.  
  435. protected void setActionBarSubTitle(String subTitle) {
  436. if (actionBar != null) {
  437. Util.setSubTitle(this, actionBar, subTitle);
  438. }
  439. }
  440.  
  441. protected String getLoginStatus(){
  442. if (UserStatus.getInstance().getLoginStatus()) {
  443. return UserStatus.getInstance().getFirstName() + " " +
  444. UserStatus.getInstance().getLastName();
  445. } else {
  446. return getResources().getString(R.string.hello_there);
  447. }
  448. }
  449.  
  450. protected String getActionBarTitle() {
  451. return actionBar.getTitle().toString();
  452. }
  453.  
  454. public Toolbar getToolbar() {
  455. return mToolbar;
  456. }
  457.  
  458. public int getToolbarHeight() {
  459. return toolbarContainer.getHeight();
  460. }
  461.  
  462. public LinearLayout getToolbarContainer() {
  463. return toolbarContainer;
  464. }
  465.  
  466. public int getMainContentHeight() {
  467. // mMainLayout' height is variable, so we use the blank layout.
  468. return mBlankLayout.getHeight();
  469. }
  470.  
  471. public int getWholeContentHeight() {
  472. return mWholeContainer.getHeight();
  473. }
  474.  
  475. public void removeContentMargin() {
  476. ((FrameLayout.LayoutParams) mContent.getLayoutParams()).setMargins(0, 0, 0, 0);
  477. }
  478.  
  479. protected void setBottomNavigationBarClickListener(BottomNavigationBarClickListener listener) {
  480. mListener = listener;
  481. }
  482.  
  483. public interface BottomNavigationBarClickListener {
  484.  
  485. }
  486.  
  487. @Override
  488. public void dismissProgress() {
  489. if (mBlankLayout.getVisibility() == View.VISIBLE) {
  490. mBlankLayout.setVisibility(View.GONE);
  491. }
  492. super.dismissProgress();
  493. }
  494.  
  495. public void showAlertWindow(String message) {
  496. final LinearLayout linearLayout = new LinearLayout(this);
  497. linearLayout
  498. .setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
  499. ViewGroup.LayoutParams.WRAP_CONTENT));
  500. linearLayout.setOrientation(LinearLayout.VERTICAL);
  501. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  502. linearLayout.setElevation(getResources().getDimension(R.dimen.standard_padding));
  503. }
  504. linearLayout
  505. .setPadding(getResources().getDimensionPixelSize(R.dimen.alertWindowLeftPadding),
  506. getResources().getDimensionPixelSize(R.dimen.alertWindowTopPadding),
  507. getResources().getDimensionPixelSize(R.dimen.alertWindowLeftPadding),
  508. getResources().getDimensionPixelSize(R.dimen.alertWindowBottomPadding));
  509. linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
  510. linearLayout.setBackgroundColor(getResources().getColor(R.color.red));
  511. FontIconView fontIconView = new FontIconView(this);
  512. fontIconView
  513. .setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
  514. ViewGroup.LayoutParams.WRAP_CONTENT));
  515. fontIconView.setTextColor(getResources().getColor(R.color.white));
  516. fontIconView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources()
  517. .getDimensionPixelSize(R.dimen.title_text_size));
  518. fontIconView.setText(R.string.icon_error);
  519. linearLayout.addView(fontIconView);
  520. CustomTextView textView = new CustomTextView(this);
  521. textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
  522. ViewGroup.LayoutParams.MATCH_PARENT));
  523. textView.setTextColor(getResources().getColor(R.color.white));
  524. textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources()
  525. .getDimensionPixelSize(R.dimen.verificationStatusTextSize));
  526. textView.setPadding(0, getResources().getDimensionPixelSize(R.dimen.standard_padding), 0,
  527. 0);
  528. textView.setText(message);
  529. textView.setGravity(Gravity.CENTER);
  530. textView.setSingleLine(false);
  531. textView.setLines(2);
  532. linearLayout.addView(textView);
  533. linearLayout.setVisibility(View.VISIBLE);
  534. mWholeContainer.addView(linearLayout);
  535. AnimationUtil.expandView(linearLayout);
  536. mWholeContainer.postDelayed(new Runnable() {
  537. @Override
  538. public void run() {
  539. AnimationUtil.collapse(linearLayout);
  540. mWholeContainer.removeView(linearLayout);
  541. }
  542. }, 3000);
  543. }
  544.  
  545. public void showAlertWindowWithCloseBtn(String message, int color) {
  546. alertText.setText(message);
  547. alertLayout.setBackgroundColor(getResources().getColor(color));
  548. AnimationUtil.expandView(alertLayout);
  549. }
  550.  
  551.  
  552. @Override
  553. public void offline() {
  554. showAlertWindowWithCloseBtn(getString(R.string.no_internet_alert), R.color.red);
  555. }
  556.  
  557. @Override
  558. public void online() {
  559. AnimationUtil.collapse(alertLayout);
  560. }
  561.  
  562. protected void setCurrentItem(int position) {
  563. FragmentTransaction ft = fragmentManager.beginTransaction();
  564. Fragment prevFragment = fragmentManager.findFragmentByTag("" + position);
  565.  
  566. if (prevFragment == null) {
  567. ft.add(R.id.wholeContainer, mTabsFragments.get(position), "" + position).commit();
  568. }
  569.  
  570. ft = fragmentManager.beginTransaction();
  571. for (int i = 0; i < mTabsFragments.size(); i++) {
  572. if (i == position) {
  573. ft.show(mTabsFragments.get(i));
  574. } else {
  575. ft.hide(mTabsFragments.get(i));
  576. }
  577. }
  578. ft.commit();
  579. if (bottomNavigation.getCurrentItem() != position) {
  580. bottomNavigation.setCurrentItem(position, false);
  581. }
  582. showHideMenuItems(position);
  583. }
  584.  
  585. @Override
  586. protected void onDestroy() {
  587. LocalBroadcastManager.getInstance(
  588. getApplicationContext()).unregisterReceiver(mCartUpdateBroadcastReceiver);
  589. if (bottomNavigationItems != null) {
  590. bottomNavigationItems.clear();
  591. bottomNavigationItems = null;
  592. }
  593.  
  594. if (mTabsFragments != null) {
  595. for (Fragment fragment : mTabsFragments) {
  596. FragmentTransaction ft = fragmentManager.beginTransaction();
  597. ft.remove(fragment).commitAllowingStateLoss();
  598. }
  599. mTabsFragments.clear();
  600. mTabsFragments = null;
  601. }
  602. super.onDestroy();
  603. }
  604.  
  605. public void hideBottomNavigationBar() {
  606. if (bottomNavigation != null) {
  607. bottomNavigation.hideBottomNavigation();
  608. }
  609. }
  610.  
  611. public void restoreBottomNavigationBar(boolean withAnimation) {
  612. if (bottomNavigation != null) {
  613. bottomNavigation.restoreBottomNavigation(withAnimation);
  614. }
  615. }
  616.  
  617. private void showRecentlyView() {
  618. try {
  619. mRecentlyViewLayout.setVisibility(View.VISIBLE);
  620. FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
  621. ft.setCustomAnimations(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom,
  622. R.anim.abc_slide_in_bottom,
  623. R.anim.abc_slide_out_bottom);
  624. if (tabFragment == null) {
  625. prepareRecentlyView();
  626. ft.add(R.id.recently_viewed_container, tabFragment, SlidingTabsColorsFragment.TAG);
  627. } else {
  628. ft.attach(tabFragment);
  629. }
  630. ft.commit();
  631. getSupportFragmentManager().executePendingTransactions();
  632. toolbarContainer.setVisibility(View.GONE);
  633. Util.setStaueBarColor(this, getResources().getColor(R.color.navy_dark));
  634. } catch (IllegalStateException e) {
  635. e.printStackTrace();
  636. Crashlytics.logException(e);
  637. }
  638. }
  639.  
  640. private void prepareRecentlyView() {
  641. tabFragment = getSupportFragmentManager()
  642. .findFragmentByTag(SlidingTabsColorsFragment.TAG);
  643. if (tabFragment == null) {
  644. ArrayList<RecentlyFragment.RecentlyViewTab> tabs = new ArrayList<>();
  645. tabs.add(new RecentlyFragment.RecentlyViewTab(getString(R.string.boutiques),
  646. getResources().getColor(R.color.white), false));
  647. tabs.add(new RecentlyFragment.RecentlyViewTab(getString(R.string.products),
  648. getResources().getColor(R.color.white), true));
  649. tabFragment = SlidingTabsColorsFragment.newInstance(tabs, R.layout.weight_tab_textview,
  650. R.id.textView3);
  651. }
  652. }
  653.  
  654. private void smoothFinishofActivity(int position) {
  655. setActionBarTitle("");
  656. setActionBarSubTitle("");
  657. actionBar.setDisplayHomeAsUpEnabled(false);
  658. Util.setSelectedBar(position);
  659. BottombarNavigationActivity.this.finish();
  660. overridePendingTransition(0, R.anim.face_out);
  661. Util.setKillSearchResultsBoutiquesActivity(true);
  662. }
  663. }
Add Comment
Please, Sign In to add comment