Exemplo n.º 1
0
 public void updateUserInfo() {
   if (Utils.haveNetworkConnection(this)) {
     if (!user.getPhoto().equals(GifsArtConst.EMPTY_PROFILE_IMAGE_PATH)) {
       Glide.with(context)
           .asBitmap()
           .load(user.getPhoto() + GifsArtConst.DOWNLOAD_GIF_POSTFIX_240)
           .into(
               new BitmapImageViewTarget(profileImageView) {
                 @Override
                 protected void setResource(Bitmap resource) {
                   RoundedBitmapDrawable circularBitmapDrawable =
                       RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                   circularBitmapDrawable.setCircular(true);
                   profileImageView.setImageDrawable(circularBitmapDrawable);
                 }
               });
     } else {
       profileImageView.setImageDrawable(
           getResources().getDrawable(R.drawable.profile_pic_personalize));
     }
   } else {
     profileImageView.setImageDrawable(
         getResources().getDrawable(R.drawable.profile_pic_personalize));
   }
   ((TextView) userProfileContainer.findViewById(R.id.username_text_view))
       .setText("@" + user.getName());
 }
Exemplo n.º 2
0
  @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);
          }
        });
  }