1 |
efrain |
1 |
package com.cesams.twogetskills.adapter;
|
|
|
2 |
|
|
|
3 |
import android.content.Context;
|
|
|
4 |
import android.view.LayoutInflater;
|
|
|
5 |
import android.view.View;
|
|
|
6 |
import android.view.ViewGroup;
|
|
|
7 |
import android.widget.ImageView;
|
|
|
8 |
import android.widget.TextView;
|
|
|
9 |
|
|
|
10 |
import androidx.recyclerview.widget.RecyclerView;
|
|
|
11 |
|
|
|
12 |
import com.bumptech.glide.Glide;
|
|
|
13 |
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|
|
14 |
import com.bumptech.glide.load.model.GlideUrl;
|
|
|
15 |
import com.bumptech.glide.load.model.LazyHeaders;
|
|
|
16 |
import com.bumptech.glide.request.RequestOptions;
|
|
|
17 |
import com.cesams.twogetskills.Constants;
|
|
|
18 |
import com.cesams.twogetskills.R;
|
|
|
19 |
import com.cesams.twogetskills.library.MD5;
|
|
|
20 |
import com.cesams.twogetskills.viewdata.UserProfileViewData;
|
|
|
21 |
import com.cesams.twogetskills.skeleton.ITwoGetSkills;
|
|
|
22 |
import com.cesams.twogetskills.skeleton.IUserProfileDelegateAdapter;
|
|
|
23 |
|
|
|
24 |
import java.util.Calendar;
|
|
|
25 |
import java.util.List;
|
|
|
26 |
import java.util.Random;
|
|
|
27 |
import java.util.TimeZone;
|
|
|
28 |
|
|
|
29 |
public class UserProfileListViewHeaderAdapter implements IUserProfileDelegateAdapter {
|
|
|
30 |
private final static String TAG = "C2GS - UserProfileListViewHeaderAdapter";
|
|
|
31 |
private List<UserProfileViewData> mData;
|
|
|
32 |
private LayoutInflater mInflater;
|
|
|
33 |
private Context mContext;
|
|
|
34 |
private ITwoGetSkills iTwoGetSkills;
|
|
|
35 |
|
|
|
36 |
public UserProfileListViewHeaderAdapter(Context context)
|
|
|
37 |
{
|
|
|
38 |
this.mContext = context;
|
|
|
39 |
this.mInflater = LayoutInflater.from(context);
|
|
|
40 |
|
|
|
41 |
if(context instanceof ITwoGetSkills) {
|
|
|
42 |
iTwoGetSkills = (ITwoGetSkills) context;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
// inflates the row layout from xml when needed
|
|
|
50 |
@Override
|
|
|
51 |
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
52 |
View view = mInflater.inflate(R.layout.fragment_userprofile_item_header, parent, false);
|
|
|
53 |
return new HeaderViewHolder(view);
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
// binds the data to the TextView in each row
|
|
|
57 |
@Override
|
|
|
58 |
public void onBindViewHolder(RecyclerView.ViewHolder holder, UserProfileViewData userProfileViewData) {
|
|
|
59 |
HeaderViewHolder mHolder = (HeaderViewHolder) holder;
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
mHolder.mItem.setText(userProfileViewData.getLabelOrCompanyName());
|
|
|
63 |
|
|
|
64 |
TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
|
|
65 |
Calendar calendar = Calendar.getInstance(timeZone);
|
|
|
66 |
TimeZone tz = calendar.getTimeZone();
|
|
|
67 |
int created = (int) (calendar.getTimeInMillis() / 1000);
|
|
|
68 |
|
|
|
69 |
Random random = new Random(created);
|
|
|
70 |
int rand = 1000 + random.nextInt(8999);
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
|
|
|
74 |
String password = iTwoGetSkills.getPreference().getPassword();
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
String secret = MD5.generar(password + ':' + created + ':' + rand);
|
|
|
78 |
|
|
|
79 |
GlideUrl url = new GlideUrl(userProfileViewData.getValueOrImage(), new LazyHeaders.Builder()
|
|
|
80 |
.addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
|
|
|
81 |
.addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
|
|
|
82 |
.addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
|
|
|
83 |
.addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
|
|
|
84 |
.addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
|
|
|
85 |
.build());
|
|
|
86 |
|
|
|
87 |
RequestOptions options = new RequestOptions()
|
|
|
88 |
.diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
89 |
|
|
|
90 |
Glide.with(mContext).load(url)
|
|
|
91 |
.thumbnail()
|
|
|
92 |
.apply(options)
|
|
|
93 |
.into(mHolder.mImage);
|
|
|
94 |
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
public class HeaderViewHolder extends RecyclerView.ViewHolder {
|
|
|
98 |
TextView mItem;
|
|
|
99 |
ImageView mImage;
|
|
|
100 |
|
|
|
101 |
HeaderViewHolder(View itemView) {
|
|
|
102 |
super(itemView);
|
|
|
103 |
|
|
|
104 |
mItem = (TextView) itemView.findViewById(R.id.fragment_userprofile_item_header_company_name);
|
|
|
105 |
mImage = (ImageView) itemView.findViewById(R.id.fragment_userprofile_item_header_company_image);
|
|
|
106 |
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
}
|