Skip to content

Commit

Permalink
alterações
Browse files Browse the repository at this point in the history
  • Loading branch information
felixsoares committed Dec 7, 2017
1 parent 23964de commit 2e8911e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bottomnavygation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

compile 'com.mikhaellopez:circularimageview:3.0.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void deselectAll() {
public void updateImageProfile(String path) {
for (ItemNav itemNav : this.itens) {
if (itemNav.isProfile()) {
itemNav.updatePathImageProfile(path);
itemNav.updatePathImageProfile(path, "", "");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
Expand All @@ -13,13 +14,20 @@
import android.widget.TextView;

import com.felix.bottomnavygation.Util.Util;
import com.jakewharton.picasso.OkHttp3Downloader;
import com.mikhaellopez.circularimageview.CircularImageView;
import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.Picasso;

import java.io.File;
import java.io.IOException;
import java.util.Random;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
* Created by user on 07/11/2017.
*/
Expand All @@ -32,10 +40,13 @@ public class ItemNav extends LinearLayout {
private int imageIconActive;
private String titulo;
private String pathImageProfile;
private String apiKey;
private String authorization;

private int colorInactive;
private int colorActive;

private Boolean isError = false;
private Boolean isProfile = false;
private Boolean isActive;

Expand Down Expand Up @@ -143,7 +154,7 @@ private void configureImageView() {

private void fileToImageView() {
if (this.isProfile && this.pathImageProfile != null && !this.pathImageProfile.trim().equals("")) {
updatePathImageProfile(pathImageProfile);
updatePathImageProfile(pathImageProfile, apiKey, authorization);
}
}

Expand All @@ -170,8 +181,10 @@ public ItemNav addBadgeIndicator(BadgeIndicator badgeIndicator) {
return this;
}

public void updatePathImageProfile(String pathImage) {
public void updatePathImageProfile(String pathImage, final String apiKey, final String authorization) {
this.pathImageProfile = pathImage;
this.apiKey = apiKey;
this.authorization = authorization;

if (pathImage != null && !pathImage.equals("")) {
File imgFile = new File(pathImage);
Expand Down Expand Up @@ -209,8 +222,34 @@ public void updatePathImageProfile(String pathImage) {
}
}

Picasso
.with(getContext())
OkHttpClient clientHttp = new OkHttpClient.Builder()
.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request();

Request compressedRequest = originalRequest.newBuilder()
.addHeader("api-key", apiKey)
.addHeader("Authorization", authorization)
.addHeader("Content-Type", "application/json")
.build();

return chain.proceed(compressedRequest);
}
})
.build();

Picasso picasso = new Picasso.Builder(getContext())
.downloader(new OkHttp3Downloader(clientHttp))
.listener(new Picasso.Listener() {
@Override
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
isError = true;
}
})
.build();

picasso
.load(pathImage)
.placeholder(ContextCompat.getDrawable(getContext(), imageIcon))
.error(ContextCompat.getDrawable(getContext(), imageIcon))
Expand Down Expand Up @@ -305,7 +344,7 @@ public void run() {
public void select() {
this.isActive = true;

if (isProfile() && pathImageProfile != null && !pathImageProfile.trim().equals("")) {
if (isProfile() && pathImageProfile != null && !pathImageProfile.trim().equals("") && !isError) {
selectActiveColorProfile();
} else {
if (this.imageIconActive != 0) {
Expand Down

0 comments on commit 2e8911e

Please sign in to comment.