MovieMessageUtils.java 2.72 KB
package com.gimi.common.cinema.utils;

import com.gimi.common.cinema.model.Constant;
import com.gimi.common.cinema.model.MovieMessage;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;

import java.io.File;
import java.io.IOException;

/**
 * Created by wugian on 2016/4/27
 */
public class MovieMessageUtils {
    public static final String TAG = MovieMessageUtils.class.getName();

    public static MovieMessage getLocalMovieMessage(String localMoviePath) {
        MovieMessage movieMessage = null;
        File qntFile = new File(localMoviePath + Constant.MOVIE_MESSAGE_NAME_NEW);
        File txtFile = new File(localMoviePath + Constant.MOVIE_MESSAGE_NAME_OLD);
        if (qntFile.exists()) {
            String mm = FileReadUtils.readDate(qntFile.getAbsolutePath());
            try {
                movieMessage = new Gson().fromJson(mm, MovieMessage.class);
            } catch (JsonSyntaxException e) {
                e.printStackTrace();
            }
        } else {
            if (txtFile.exists()) {
                String mm = FileReadUtils.readDate(txtFile.getAbsolutePath());
                try {
                    movieMessage = new Gson().fromJson(mm, MovieMessage.class);
                } catch (JsonSyntaxException e) {
                    e.printStackTrace();
                }
            }
        }
        return movieMessage;
    }

    public static String getLocalMoviePoster(String localMoviePath) {
//        String gif = localMoviePath + Constant.MOVIE_POSTER_GIF;
        String qnj = localMoviePath + Constant.MOVIE_POSTER_NEW;
        String jpg = localMoviePath + Constant.MOVIE_POSTER_OLD;
       /* if (SambaFileCharge.fileExist(gif)) {
            return gif;
        } else */if (SambaFileCharge.fileExist(qnj)) {
            return qnj;
        } else if (SambaFileCharge.fileExist(jpg)) {
            return jpg;
        } else {
            return null;
        }
    }

    public static int getPlayCount(String localMoviePath) {
        int count = 0;
        String path = localMoviePath + Constant.MOVIE_COUNT;
        if (SambaFileCharge.fileExist(path)) {
            count = FileReadUtils.readCount(path);
        }
        return count;
    }

    public static void writePlayCount(String localMoviePath, int count) {
        String path = localMoviePath + Constant.MOVIE_COUNT;
        if (SambaFileCharge.fileExist(path)) {
            FileReadUtils.writeDate(path, "" + count);
        } else {
            try {
                boolean newFile = new File(path).createNewFile();
                if (newFile) {
                    FileReadUtils.writeDate(path, "" + count);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}