@Override
 protected void fitSystemWindows(Rect insets) {
   if (mRecyclerView != null) {
     mRecyclerView.setClipToPadding(false);
     mRecyclerView.setPadding(insets.left, insets.top, insets.right, insets.bottom);
   }
 }
Beispiel #2
0
  /**
   * build the MiniDrawer
   *
   * @param ctx
   * @return
   */
  public View build(Context ctx) {
    mContainer = new LinearLayout(ctx);
    if (mInnerShadow) {
      if (!mInRTL) {
        mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_left);
      } else {
        mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_right);
      }
    }

    // create and append recyclerView
    mRecyclerView = new RecyclerView(ctx);
    mContainer.addView(
        mRecyclerView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    // set the itemAnimator
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    // some style improvements on older devices
    mRecyclerView.setFadingEdgeLength(0);
    // set the drawing cache background to the same color as the slider to improve performance
    // mRecyclerView.setDrawingCacheBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity,
    // R.attr.material_drawer_background, R.color.material_drawer_background));
    mRecyclerView.setClipToPadding(false);
    // additional stuff
    mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
    // adapter
    mDrawerAdapter = new DrawerAdapter();
    mRecyclerView.setAdapter(mDrawerAdapter);

    // if the activity with the drawer should be fullscreen add the padding for the statusbar
    if (mDrawer != null
        && mDrawer.mDrawerBuilder != null
        && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentStatusBar)) {
      mRecyclerView.setPadding(
          mRecyclerView.getPaddingLeft(),
          UIUtils.getStatusBarHeight(ctx),
          mRecyclerView.getPaddingRight(),
          mRecyclerView.getPaddingBottom());
    }

    // if the activity with the drawer should be fullscreen add the padding for the navigationBar
    if (mDrawer != null
        && mDrawer.mDrawerBuilder != null
        && (mDrawer.mDrawerBuilder.mFullscreen
            || mDrawer.mDrawerBuilder.mTranslucentNavigationBar)) {
      mRecyclerView.setPadding(
          mRecyclerView.getPaddingLeft(),
          mRecyclerView.getPaddingTop(),
          mRecyclerView.getPaddingRight(),
          UIUtils.getNavigationBarHeight(ctx));
    }

    // set the adapter with the items
    createItems();

    return mContainer;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRecyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_drawer, container, false);
    mRecyclerView.setClipToPadding(false);
    mAdapter =
        new NavigationDrawerAdapter(
            getActivity(),
            new NavigationDrawerAdapter.ClickListener() {
              @Override
              public void onClick(int index) {
                selectItem(index);
              }

              @Override
              public boolean onLongClick(final int index) {
                Pins.Item item = mAdapter.getItem(index);
                Utils.showConfirmDialog(
                    getActivity(),
                    R.string.remove_shortcut,
                    R.string.confirm_remove_shortcut,
                    item.getDisplay(getActivity()),
                    new Utils.ClickListener() {
                      @Override
                      public void onPositive(int which, View view) {
                        Pins.remove(getActivity(), index);
                        mAdapter.reload(getActivity());
                      }
                    });
                return false;
              }
            });
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mRecyclerView.setAdapter(mAdapter);
    mAdapter.setCheckedPos(mCurrentSelectedPosition);
    return mRecyclerView;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);

    userProfileContainer = (ViewGroup) findViewById(R.id.profile_activity_user_container);
    getStartedContainer = (ViewGroup) findViewById(R.id.get_started_container);
    profileImageView = (ImageView) findViewById(R.id.profile_image_view);
    getStartedButton = (Button) findViewById(R.id.get_started);
    signInButton = (Button) findViewById(R.id.profile_activity_toolbar_signin);
    userPhotosRecyclerView = (RecyclerView) findViewById(R.id.user_photos_rec_view);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);

    user = UserContraller.readUserFromFile(this);

    gridLayoutManager = new GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false);
    profileUserPhotosAdapter = new ProfileUserPhotosAdapter(this);

    userPhotosRecyclerView.setHasFixedSize(true);
    userPhotosRecyclerView.setClipToPadding(true);
    userPhotosRecyclerView.setLayoutManager(gridLayoutManager);
    userPhotosRecyclerView.setItemAnimator(new DefaultItemAnimator());

    userPhotosRecyclerView.setAdapter(profileUserPhotosAdapter);
    userPhotosRecyclerView.addItemDecoration(
        new SpacesItemDecoration((int) Utils.dpToPixel(2, this)));

    if (user != null) {
      isSignedIn = true;
      updateUserInfo();
      visibilitySwitcher(isSignedIn);
      if (Utils.haveNetworkConnection(this)) {
        final UserContraller userContraller = new UserContraller(this);
        userContraller.setOnRequestReadyListener(
            new UserContraller.UserRequest() {
              @Override
              public void onRequestReady(int requestNumber, String messege) {
                if (requestNumber == RequestConstants.REQUEST_USER_SUCCESS_CODE) {
                  user = userContraller.getUser();
                  updateUserInfo();
                  userContraller.requestUserPhotos(user.getKey(), photosOffset, photosLimit);
                } else if (requestNumber == RequestConstants.REQUEST_USER_PHOTO_SUCCESS_CODE) {
                  userPhotos = userContraller.getUserPhotos();
                  profileUserPhotosAdapter.addItems(userPhotos);
                } else {
                  AlertDialog alert = UserContraller.setupDialogBuilder(context, messege).create();
                  alert.show();
                }
              }
            });
        userContraller.requestUser(user.getKey());
      } else {
        Toast.makeText(context, getString(R.string.no_internet_connection), Toast.LENGTH_SHORT)
            .show();
      }
    } else {
      isSignedIn = false;
      visibilitySwitcher(isSignedIn);
    }

    userPhotosRecyclerView.addOnItemTouchListener(
        new RecyclerItemClickListener(
            getApplicationContext(),
            new RecyclerItemClickListener.OnItemClickListener() {
              @Override
              public void onItemClick(View view, int position) {
                Intent intent = new Intent(context, EditLocalPhotoActivity.class);
                intent.putExtra(
                    GifsArtConst.INTENT_IMAGE_URL,
                    profileUserPhotosAdapter.getItem(position).getUrl());
                intent.putExtra(
                    GifsArtConst.INTENT_IS_PUBLIC,
                    profileUserPhotosAdapter.getItem(position).getIsPublic());
                intent.putExtra(
                    GifsArtConst.INTENT_PHOTO_ID,
                    profileUserPhotosAdapter.getItem(position).getId());
                startActivityForResult(intent, REQUEST_OPEN_PHOTO_EDIT);
              }
            }));

    signInButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (isSignedIn) {
              isSignedIn = false;
              UserContraller.writeUserToFile(context, null);
              profileUserPhotosAdapter.removeAllItems();
              visibilitySwitcher(isSignedIn);
              Toast.makeText(context, getString(R.string.sign_out_button), Toast.LENGTH_SHORT)
                  .show();
            } else {
              Intent intent = new Intent(context, SignInActivity.class);
              startActivityForResult(intent, REQUEST_SIGNIN_ACTIVITY);
              overridePendingTransition(R.transition.pull_in_right, R.transition.push_out_left);
            }
          }
        });

    getStartedButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(context, SignUpActivity.class);
            startActivityForResult(intent, REQUEST_SIGNUP_ACTIVITY);
            overridePendingTransition(R.transition.pull_in_right, R.transition.push_out_left);
          }
        });

    profileImageView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (Utils.haveNetworkConnection(context)) {
              pickImageFromGallery();
            } else {
              Toast.makeText(
                      context, getString(R.string.no_internet_connection), Toast.LENGTH_SHORT)
                  .show();
            }
          }
        });

    findViewById(R.id.picsart_deeplink)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                deepLinkToPicsart();
              }
            });

    findViewById(R.id.profile_activity_toolbar_create)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                finish();
                overridePendingTransition(R.transition.pull_in_right, R.transition.push_out_left);
              }
            });

    swipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.pink));
    swipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            final UserContraller userContraller = new UserContraller(context);
            userContraller.setOnRequestReadyListener(
                new UserContraller.UserRequest() {
                  @Override
                  public void onRequestReady(int requestNumber, String messege) {
                    if (requestNumber == RequestConstants.REQUEST_USER_PHOTO_SUCCESS_CODE) {
                      profileUserPhotosAdapter.addItems(userContraller.getUserPhotos());
                    } else {
                      AlertDialog alert =
                          UserContraller.setupDialogBuilder(context, messege).create();
                      alert.show();
                    }
                  }
                });
            userContraller.requestUserPhotos(user.getKey(), photosOffset, photosLimit);

            profileUserPhotosAdapter.notifyDataSetChanged();
            ((SwipeRefreshLayout) findViewById(R.id.swipe_container)).setRefreshing(false);
          }
        });
  }