package com.optimalorange.cooltechnologies.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

/**
 * Created by WANGZHENGZE on 2014/11/20.
 */
public class Utils {

    /**
     * 将string存入SharedPreferences
     *
     * @param context context
     * @param key     key
     * @param value   value
     */
    public static void saveString(Context context, String key, String value) {
        SharedPreferences.Editor editor =
                PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putString(key, value);
        editor.commit();
    }

    /**
     * 从SharedPreferences中取出string
     *
     * @param context  context
     * @param key      key
     * @param defValue defValue
     * @return string
     */
    public static String getString(Context context, String key, String defValue) {
        SharedPreferences sharedPreferences =
                PreferenceManager.getDefaultSharedPreferences(context);
        return sharedPreferences.getString(key, defValue);
    }

    /**
     * 视频播放时长（秒）转换为（yy-mm-ss)
     *
     * @param duration int
     * @return String
     */
    public static String getDurationString(int duration) {
        int hours = duration / (60 * 60);
        int minutes = (duration - hours * (60 * 60)) / 60;
        int seconds = duration - hours * (60 * 60) - minutes * 60;
        if (hours == 0) {
            return minutes + ":" + seconds;
        } else {
            return hours + ":" + minutes + ":" + seconds;
        }
    }
}

@@ -1407,24 +1407,379 @@
 nutes * 60;%0A
+        String minutesStr = %22%22, secondsStr = %22%22;%0A        String hoursStr = %22%22 + hours;%0A        if (minutes %3C 10) %7B%0A            minutesStr = %220%22 + minutes;%0A        %7D else %7B%0A            minutesStr = %22%22 + mimutes;%0A        %7D%0A        if (seconds %3C 10) %7B%0A            secondsStr = %220%22 + seconds;%0A        %7D else %7B%0A            secondsStr = %22%22 + seconds;%0A        %7D%0A
         if (
@@ -1810,32 +1810,35 @@
   return minutes
+Str
  + %22:%22 + seconds
@@ -1829,32 +1829,35 @@
  + %22:%22 + seconds
+Str
 ;%0A        %7D else
@@ -1883,16 +1883,19 @@
 rn hours
+Str
  + %22:%22 +
@@ -1902,16 +1902,19 @@
  minutes
+Str
  + %22:%22 +
@@ -1913,32 +1913,35 @@
  + %22:%22 + seconds
+Str
 ;%0A        %7D%0A    

更新 Utils.java中的getDurationString