我正在创建聊天应用程序,但工作正常,但是我需要显示类似whatsapp的上传进度。
我正在使用Firebase并从Firebase存储中获取上传状态
storageReference.putFile(Uri.fromFile(file)).addOnSuccessListener(getActivity(),new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
Map<String, Object> map = new HashMap<>();
map.put("Image", uri.toString());
String Temp_Key = databaseReference.push().getKey();
Map<String, Object> RoomKey = new HashMap<>();
databaseReference.updateChildren(RoomKey);
DatabaseReference message_Root = databaseReference.child(Temp_Key);
message_Root.updateChildren(map);
}
});
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = 100.0 * taskSnapshot.getBytesTransferred() / (double) taskSnapshot.getTotalByteCount();
Log.d(TAG, "Upload is " + progress + "% done");
int currentprogress = (int) Math.round(progress);
if (currentprogress<100){
App_Functions.showProgressNotification(getActivity(),"Uploading Video",currentprogress+"% Uploaded",android.R.drawable.stat_sys_upload);
}else {
App_Functions.showProgressNotification(getActivity(),"Video Uploaded ", String.valueOf(taskSnapshot.getBytesTransferred())+" Kb Uploaded",android.R.drawable.stat_sys_upload_done);
}
}
});
在recyclerview片段中,我正在通过Firebase Storage
获取上载百分比,并且在状态栏中显示了上载百分比,但是我没有任何线索如何显示在whatsapp等recyclerview项中的imageview上根据进度显示进度圈从Firebase Storage
接收。
Recyclerview适配器
public class Chat_Adapter extends RecyclerView.Adapter<Chat_Adapter.ViewHolder> {
Chat_Wrapper chat_wrapper;
String ImagePath;
List<Chat_Wrapper> arrayList_message;
public Chat_Adapter(Context context, List<Chat_Wrapper> message) {
this.context = context;
this.arrayList_message = message;
}
@Override
public Chat_Adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View Layout;
Log.d(TAG,"On Create View Holder Calling ");
if (viewType==1){
Log.d(TAG,"View Tyoe Is "+viewType);
Layout=LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_screen_message_item,parent,false);
// ImagePath=Session.getUserImage();
}
else {
Log.d(TAG,"View Type Is "+viewType);
Layout=LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_screen_message_item_other,parent,false);
// ImagePath=chat_wrapper.getImageView();
}
return new ViewHolder(Layout);
}
@Override
public void onBindViewHolder(final Chat_Adapter.ViewHolder holder, final int position) {
chat_wrapper=arrayList_message.get(position);
if (valueofImage){
holder.Message.setVisibility(View.GONE);
holder.TimeStamp.setVisibility(View.GONE);
holder.Sent_Video.setVisibility(View.GONE);
holder.videoView.setVisibility(View.GONE);
holder.User_Image.setVisibility(View.VISIBLE);
holder.Sent_Image.setVisibility(View.VISIBLE);
holder.TimeStampImage.setText(chat_wrapper.getTimestamp());
holder.TimeStampImage.setVisibility(View.VISIBLE);
// Showing Sent User Image in thumbnail
Glide.with(context).load(chat_wrapper.getImageSent()).apply(new RequestOptions()
.fitCenter()
.skipMemoryCache(true))
.thumbnail(0.1f)
.into(holder.Sent_Image);
}
}
@Override
public int getItemCount() {
Log.d(TAG,"GET ITEM COUNT--Array Message List Size "+arrayList_message.size());
return arrayList_message.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
ImageView ,Sent_Image;
public ViewHolder(View itemView) {
super(itemView);
Log.d(TAG,"View Holder Constructor Calling. Now Inflating Layout Items");
Sent_Image= itemView.findViewById(R.id.Single_Item_Chat_User_Posted_Image);
}
}
}