|
@@ -3,7 +3,9 @@ package com.sheep.gamegroup.module.skin.util;
|
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
|
|
+import com.kfzs.duanduan.utils.DateFormatUtils;
|
|
|
import com.sheep.gamegroup.absBase.AbsObserver;
|
|
import com.sheep.gamegroup.absBase.AbsObserver;
|
|
|
|
|
+import com.sheep.gamegroup.dateview.DateUtil;
|
|
|
import com.sheep.gamegroup.module.plugin.model.Plugin;
|
|
import com.sheep.gamegroup.module.plugin.model.Plugin;
|
|
|
import com.sheep.gamegroup.module.plugin.util.SheepPluginUtil;
|
|
import com.sheep.gamegroup.module.plugin.util.SheepPluginUtil;
|
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
@@ -29,7 +31,7 @@ import skin.support.utils.SkinPreference;
|
|
|
/**
|
|
/**
|
|
|
* Created by realicing on 2019/1/15.
|
|
* Created by realicing on 2019/1/15.
|
|
|
* realicing@sina.com
|
|
* realicing@sina.com
|
|
|
- *
|
|
|
|
|
|
|
+ * <p>
|
|
|
* 换肤工具类
|
|
* 换肤工具类
|
|
|
*/
|
|
*/
|
|
|
public class SkinUtil {
|
|
public class SkinUtil {
|
|
@@ -53,13 +55,14 @@ public class SkinUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static final String KEY_CUR_SKIN_MD5 = "cur_skin";//当前正在使用的皮肤的key
|
|
public static final String KEY_CUR_SKIN_MD5 = "cur_skin";//当前正在使用的皮肤的key
|
|
|
|
|
+
|
|
|
//切换皮肤
|
|
//切换皮肤
|
|
|
public static void changeSkin(Action1<Object> action1) {
|
|
public static void changeSkin(Action1<Object> action1) {
|
|
|
Plugin willLoadPlugin = getSkinByTime();//需要加载的皮肤
|
|
Plugin willLoadPlugin = getSkinByTime();//需要加载的皮肤
|
|
|
String curSkinMd5 = PreferenceUtils.getPrefString(SheepApp.getInstance(), KEY_CUR_SKIN_MD5, null);
|
|
String curSkinMd5 = PreferenceUtils.getPrefString(SheepApp.getInstance(), KEY_CUR_SKIN_MD5, null);
|
|
|
- if(willLoadPlugin == null){//默认皮肤
|
|
|
|
|
|
|
+ if (willLoadPlugin == null) {//默认皮肤
|
|
|
String curSkinName = SkinPreference.getInstance().getSkinName();
|
|
String curSkinName = SkinPreference.getInstance().getSkinName();
|
|
|
- if(TextUtils.isEmpty(curSkinMd5) || !TextUtils.isEmpty(curSkinName)){
|
|
|
|
|
|
|
+ if (TextUtils.isEmpty(curSkinMd5) || !TextUtils.isEmpty(curSkinName)) {
|
|
|
PreferenceUtils.setPrefString(SheepApp.getInstance(), KEY_CUR_SKIN_MD5, "");
|
|
PreferenceUtils.setPrefString(SheepApp.getInstance(), KEY_CUR_SKIN_MD5, "");
|
|
|
restoreDefaultTheme();
|
|
restoreDefaultTheme();
|
|
|
}
|
|
}
|
|
@@ -74,14 +77,14 @@ public class SkinUtil {
|
|
|
@Override
|
|
@Override
|
|
|
public void onNext(Plugin plugin) {
|
|
public void onNext(Plugin plugin) {
|
|
|
File file = SheepPluginUtil.getFile(plugin);
|
|
File file = SheepPluginUtil.getFile(plugin);
|
|
|
- if(!file.exists()){//检查文件是否存在
|
|
|
|
|
|
|
+ if (!file.exists()) {//检查文件是否存在
|
|
|
action1.call(null);
|
|
action1.call(null);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
String md5 = Md5Util.getFileMD5(file);
|
|
String md5 = Md5Util.getFileMD5(file);
|
|
|
String skinName = SheepPluginUtil.getFileName(willLoadPlugin);
|
|
String skinName = SheepPluginUtil.getFileName(willLoadPlugin);
|
|
|
String curSkinName = SkinPreference.getInstance().getSkinName();
|
|
String curSkinName = SkinPreference.getInstance().getSkinName();
|
|
|
- if(curSkinMd5 != null && TextUtils.equals(md5, curSkinMd5) && TextUtils.equals(skinName, curSkinName)){//已经加载皮肤
|
|
|
|
|
|
|
+ if (curSkinMd5 != null && TextUtils.equals(md5, curSkinMd5) && TextUtils.equals(skinName, curSkinName)) {//已经加载皮肤
|
|
|
action1.call(null);
|
|
action1.call(null);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -110,44 +113,38 @@ public class SkinUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static boolean isUserPlugin = true;
|
|
public static boolean isUserPlugin = true;
|
|
|
|
|
+
|
|
|
//根据时间生成对应的主题
|
|
//根据时间生成对应的主题
|
|
|
public static Plugin getSkinByTime() {
|
|
public static Plugin getSkinByTime() {
|
|
|
- if(!isUserPlugin){
|
|
|
|
|
|
|
+ if (!isUserPlugin) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- java.util.Calendar curCalendar = java.util.Calendar.getInstance();
|
|
|
|
|
- int year = curCalendar.get(java.util.Calendar.YEAR);
|
|
|
|
|
- int month = curCalendar.get(java.util.Calendar.MONTH);
|
|
|
|
|
- int day = curCalendar.get(java.util.Calendar.DAY_OF_MONTH);
|
|
|
|
|
- if(isNewYear(year, month, day)){//春节
|
|
|
|
|
|
|
+ if (isNewYear()) {//春节
|
|
|
return Plugin.skin_new_year;
|
|
return Plugin.skin_new_year;
|
|
|
- } else if(isChristmas(year, month, day)){//元旦
|
|
|
|
|
- return Plugin.skin_christmas;
|
|
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private static boolean isChristmas(int year, int month, int day) {
|
|
|
|
|
- return year == 2019 && month == 1 && day == 1;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private static boolean isNewYear(int year, int month, int day) {
|
|
|
|
|
- return false;//year == 2019 && month < 4 ;//&& day < 20 && day < 3;
|
|
|
|
|
|
|
+ private static boolean isNewYear() {
|
|
|
|
|
+ long time = DateFormatUtils.getTimeZoneMillis("2020-02-11", "yyyy-MM-dd");
|
|
|
|
|
+ return System.currentTimeMillis() < time;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static String getSkinPath(String skinName) {
|
|
public static String getSkinPath(String skinName) {
|
|
|
return SheepPluginUtil.getFileByName(skinName, getSkinByTime()).getAbsolutePath();
|
|
return SheepPluginUtil.getFileByName(skinName, getSkinByTime()).getAbsolutePath();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
//获取应用图标
|
|
//获取应用图标
|
|
|
- public static int getAppIcon(){
|
|
|
|
|
|
|
+ public static int getAppIcon() {
|
|
|
return R.mipmap.icon;
|
|
return R.mipmap.icon;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 是否加载的是春节皮肤
|
|
* 是否加载的是春节皮肤
|
|
|
|
|
+ *
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public static boolean isLoadNewYearSkin(){
|
|
|
|
|
|
|
+ public static boolean isLoadNewYearSkin() {
|
|
|
return getSkinByTime() == Plugin.skin_new_year;
|
|
return getSkinByTime() == Plugin.skin_new_year;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|