<commit_before>package scal.io.liger.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.media.Image;
import android.media.MediaPlayer;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import com.fima.cardsui.objects.Card;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import scal.io.liger.Utility;
import scal.io.liger.model.CardModel;
import scal.io.liger.model.PreviewCardModel;
import scal.io.liger.R;
import scal.io.liger.touch.DraggableGridView;


public class PreviewCardView extends Card {

    private PreviewCardModel mCardModel;
    private Context mContext;
    public ArrayList<String> paths = new ArrayList<String>();
    public int videoIndex = 0;

    public PreviewCardView(Context context, CardModel cardModel) {
        Log.d("PreviewCardView", "constructor");
        mContext = context;
        mCardModel = (PreviewCardModel) cardModel;
    }

    @Override
    public View getCardContent(Context context) {
        Log.d("PreviewCardView", "getCardContent");
        if(mCardModel == null) {
            return null;
        }

        View view = LayoutInflater.from(context).inflate(R.layout.card_preview, null);
        final ImageView ivCardPhoto = ((ImageView) view.findViewById(R.id.iv_card_photo));
        final VideoView vvCardVideo = ((VideoView) view.findViewById(R.id.vv_card_media));
        TextView tvText= ((TextView) view.findViewById(R.id.tv_text));
        tvText.setText(mCardModel.getText());

        loadClips(mCardModel.getClipPaths());

        //TODO find better way of checking file is valid
        File mediaFile = new File(paths.get(0));
        if(mediaFile.exists() && !mediaFile.isDirectory()) {
            Uri video = Uri.parse(paths.get(0));
            vvCardVideo.setMediaController(null);
            vvCardVideo.setVideoURI(video);

            //set up image as preview
            Bitmap videoFrame = Utility.getFrameFromVideo(video.getPath());
            if(null != videoFrame) {
                ivCardPhoto.setImageBitmap(videoFrame);
                ivCardPhoto.setVisibility(View.VISIBLE);
            }
        } else {
            System.err.println("INVALID MEDIA FILE: " + mediaFile.getPath());
        }

        ivCardPhoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                vvCardVideo.setVisibility(View.VISIBLE);
                ivCardPhoto.setVisibility(View.GONE);
                vvCardVideo.start();
            }
        });

        vvCardVideo.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer vvCardPlayer) {
                videoIndex++;

                if (videoIndex >= paths.size()) {
                    vvCardVideo.setVisibility(View.GONE);
                    ivCardPhoto.setVisibility(View.VISIBLE);
                    return; // don't loop
                }

                File mediaFile = new File(paths.get(videoIndex));
                if (mediaFile.exists() && !mediaFile.isDirectory()) {
                    Uri video = Uri.parse(paths.get(videoIndex));
                    vvCardVideo.setVideoURI(video);
                    vvCardVideo.start();
                } else {
                    System.err.println("INVALID MEDIA FILE: " + mediaFile.getPath());
                }
            }
        });


        return view;<commit_msg>preview card wasn't starting from the begginning after you wathed through once<commit_after>package scal.io.liger.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.media.Image;
import android.media.MediaPlayer;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import com.fima.cardsui.objects.Card;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import scal.io.liger.Utility;
import scal.io.liger.model.CardModel;
import scal.io.liger.model.PreviewCardModel;
import scal.io.liger.R;
import scal.io.liger.touch.DraggableGridView;


public class PreviewCardView extends Card {

    private PreviewCardModel mCardModel;
    private Context mContext;
    public ArrayList<String> paths = new ArrayList<String>();
    public int videoIndex = 0;

    public PreviewCardView(Context context, CardModel cardModel) {
        Log.d("PreviewCardView", "constructor");
        mContext = context;
        mCardModel = (PreviewCardModel) cardModel;
    }

    @Override
    public View getCardContent(Context context) {
        Log.d("PreviewCardView", "getCardContent");
        if(mCardModel == null) {
            return null;
        }

        View view = LayoutInflater.from(context).inflate(R.layout.card_preview, null);
        final ImageView ivCardPhoto = ((ImageView) view.findViewById(R.id.iv_card_photo));
        final VideoView vvCardVideo = ((VideoView) view.findViewById(R.id.vv_card_media));
        TextView tvText= ((TextView) view.findViewById(R.id.tv_text));
        tvText.setText(mCardModel.getText());

        loadClips(mCardModel.getClipPaths());

        //TODO find better way of checking file is valid
        File mediaFile = new File(paths.get(0));
        if(mediaFile.exists() && !mediaFile.isDirectory()) {
            Uri video = Uri.parse(paths.get(0));
            vvCardVideo.setMediaController(null);
            vvCardVideo.setVideoURI(video);

            //set up image as preview
            Bitmap videoFrame = Utility.getFrameFromVideo(video.getPath());
            if(null != videoFrame) {
                ivCardPhoto.setImageBitmap(videoFrame);
                ivCardPhoto.setVisibility(View.VISIBLE);
            }
        } else {
            System.err.println("INVALID MEDIA FILE: " + mediaFile.getPath());
        }

        ivCardPhoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                vvCardVideo.setVisibility(View.VISIBLE);
                ivCardPhoto.setVisibility(View.GONE);
                Uri video = Uri.parse(paths.get(videoIndex));
                vvCardVideo.setVideoURI(video);
                vvCardVideo.start();
            }
        });

        vvCardVideo.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer vvCardPlayer) {
                videoIndex++;

                if (videoIndex >= paths.size()) {
                    vvCardVideo.setVisibility(View.GONE);
                    ivCardPhoto.setVisibility(View.VISIBLE);
                    videoIndex = 0;
                    return; // don't loop
                }

                File mediaFile = new File(paths.get(videoIndex));
                if (mediaFile.exists() && !mediaFile.isDirectory()) {
                    Uri video = Uri.parse(paths.get(videoIndex));
                    vvCardVideo.setVideoURI(video);
                    vvCardVideo.start();
                } else {
                    System.err.println("INVALID MEDIA FILE: " + mediaFile.getPath());
                }
            }
        });


        return view;
{'fraction_non_alphanumeric': 0.10421868839532133, 'fraction_numerical': 0.0009199632014719411, 'mean_word_length': 2.353900396650507, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7586788', 'n_tokens_mistral': 2145, 'n_tokens_neox': 2001, 'n_words': 398}