Open MelvinMathew9 opened 6 years ago
@Melvin9, I'd really love it if you could find some small time to send a PR. Would really appreciate that. Looking forward to that.
it is working pretty good but how to stop music???, music is still.
Hello @Prince655, can you kindly send a PR with @Melvin9 's code he has posted? From there, we can look at how to stop music like you are saying.
same error images repeated
Check apk on play store that I have built. Link:http://play.google.com/store/apps/details?id=com.glowrm.status_downloader
Try This Adapter
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.VideoView;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Objects;
public class ListAdapter extends RecyclerView.Adapter<ListAdapter.MyViewHolder> {
final Context context;
final ArrayList<File> modelFeedArrayList;
private static final String DIRECTORY_TO_SAVE_MEDIA_NOW = "/WhatsappStatus/";
public ListAdapter(Context context, final ArrayList<File> modelFeedArrayList) {
this.context = context;
this.modelFeedArrayList = modelFeedArrayList;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_media_row_item, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final MyViewHolder holder, int position) {
File currentFile = modelFeedArrayList.get(position);
if (currentFile.getAbsolutePath().endsWith(".mp4")) {
holder.cardViewImageMedia.setVisibility(View.GONE);
holder.cardViewVideoMedia.setVisibility(View.VISIBLE);
Uri video = Uri.parse(currentFile.getAbsolutePath());
holder.videoViewVideoMedia.setVideoURI(video);
holder.videoViewVideoMedia.setOnPreparedListener(mp -> {
mp.setLooping(true);
holder.videoViewVideoMedia.start();
});
} else {
holder.cardViewImageMedia.setVisibility(View.VISIBLE);
holder.cardViewVideoMedia.setVisibility(View.GONE);
Bitmap myBitmap = BitmapFactory.decodeFile(currentFile.getAbsolutePath());
holder.imageViewImageMedia.setImageBitmap(myBitmap);
}
}
public View.OnClickListener downloadMediaItem(final File sourceFile) {
return v -> ((Runnable) () -> {
try {
copyFile(sourceFile, new File(Environment.getExternalStorageDirectory().toString() + DIRECTORY_TO_SAVE_MEDIA_NOW + sourceFile.getName()));
} catch (Exception e) {
e.printStackTrace();
Log.e("RecyclerV", "onClick: Error:" + e.getMessage());
}
}).run();
}
public static void copyFile(File sourceFile, File destFile) throws IOException {
if (!Objects.requireNonNull(destFile.getParentFile()).exists())
destFile.getParentFile().mkdirs();
if (!destFile.exists()) {
destFile.createNewFile();
}
try (FileChannel source = new FileInputStream(sourceFile).getChannel(); FileChannel destination = new FileOutputStream(destFile).getChannel()) {
destination.transferFrom(source, 0, source.size());
}
}
@Override
public int getItemCount() {
return modelFeedArrayList.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
ImageView imageViewImageMedia;
VideoView videoViewVideoMedia;
CardView cardViewVideoMedia;
CardView cardViewImageMedia;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
imageViewImageMedia = itemView.findViewById(R.id.imageViewImageMedia);
videoViewVideoMedia = itemView.findViewById(R.id.videoViewVideoMedia);
cardViewVideoMedia = itemView.findViewById(R.id.cardViewVideoMedia);
cardViewImageMedia = itemView.findViewById(R.id.cardViewImageMedia);
}
}
}
JUST SET THE VISIBILITY BACK ON ELSE PART IN onBindViewHolder SNIPPET @Override public void onBindViewHolder(@NonNull final RecyclerViewMediaAdapter.FileHolder holder, int position) { File currentFile = filesList.get(position);