diff --git a/app/build.gradle b/app/build.gradle index 0f62a32e..57253838 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -89,7 +89,6 @@ dependencies { compile 'com.facebook.stetho:stetho:1.3.1' compile 'com.facebook.stetho:stetho-okhttp3:1.3.1' compile 'com.miguelcatalan:materialsearchview:1.4.0' - compile 'com.bilibili:magicasakura:0.1.1@aar' compile 'jp.wasabeef:glide-transformations:2.0.1' compile 'com.jakewharton:butterknife:8.4.0' annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' diff --git a/app/src/main/java/com/hotbitmapgg/bilibili/BilibiliApp.java b/app/src/main/java/com/hotbitmapgg/bilibili/BilibiliApp.java index b8a2936f..cdc89c1f 100644 --- a/app/src/main/java/com/hotbitmapgg/bilibili/BilibiliApp.java +++ b/app/src/main/java/com/hotbitmapgg/bilibili/BilibiliApp.java @@ -1,14 +1,8 @@ package com.hotbitmapgg.bilibili; import android.app.Application; -import android.content.Context; -import android.support.annotation.ColorInt; -import android.support.annotation.ColorRes; -import com.bilibili.magicasakura.utils.ThemeUtils; import com.facebook.stetho.Stetho; -import com.hotbitmapgg.bilibili.utils.ThemeHelper; -import com.hotbitmapgg.ohmybilibili.R; import com.squareup.leakcanary.LeakCanary; /** @@ -17,106 +11,30 @@ *
* 哔哩哔哩动画App */ -public class BilibiliApp extends Application implements ThemeUtils.switchColor { - public static BilibiliApp mInstance; +public class BilibiliApp extends Application { - @Override - public void onCreate() { - super.onCreate(); - mInstance = this; - init(); - } + public static BilibiliApp mInstance; - private void init() { - // 初始化主题切换 - ThemeUtils.setSwitchColor(this); - //初始化Leak内存泄露检测工具 - LeakCanary.install(this); - //初始化Stetho调试工具 - Stetho.initialize( - Stetho.newInitializerBuilder(this) - .enableDumpapp(Stetho.defaultDumperPluginsProvider(this)) - .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this)) - .build()); - } - - public static BilibiliApp getInstance() { - return mInstance; - } - - @Override - public int replaceColorById(Context context, @ColorRes int colorId) { - if (ThemeHelper.isDefaultTheme(context)) { - return context.getResources().getColor(colorId); - } - String theme = getTheme(context); - if (theme != null) { - colorId = getThemeColorId(context, colorId, theme); + @Override + public void onCreate() { + super.onCreate(); + mInstance = this; + init(); } - return context.getResources().getColor(colorId); - } - @Override - public int replaceColor(Context context, @ColorInt int color) { - if (ThemeHelper.isDefaultTheme(context)) { - return color; + private void init() { + //初始化Leak内存泄露检测工具 + LeakCanary.install(this); + //初始化Stetho调试工具 + Stetho.initialize( + Stetho.newInitializerBuilder(this) + .enableDumpapp(Stetho.defaultDumperPluginsProvider(this)) + .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this)) + .build()); } - String theme = getTheme(context); - int colorId = -1; - - if (theme != null) { - colorId = getThemeColor(context, color, theme); - } - return colorId != -1 ? getResources().getColor(colorId) : color; - } - - private String getTheme(Context context) { - if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_STORM) { - return "blue"; - } else if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_HOPE) { - return "purple"; - } else if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_WOOD) { - return "green"; - } else if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_LIGHT) { - return "green_light"; - } else if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_THUNDER) { - return "yellow"; - } else if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_SAND) { - return "orange"; - } else if (ThemeHelper.getTheme(context) == ThemeHelper.CARD_FIREY) { - return "red"; + public static BilibiliApp getInstance() { + return mInstance; } - return null; - } - - private - @ColorRes - int getThemeColorId(Context context, int colorId, String theme) { - switch (colorId) { - case R.color.theme_color_primary: - return context.getResources().getIdentifier(theme, "color", getPackageName()); - case R.color.theme_color_primary_dark: - return context.getResources().getIdentifier(theme + "_dark", "color", getPackageName()); - case R.color.theme_color_primary_trans: - return context.getResources().getIdentifier(theme + "_trans", "color", getPackageName()); - } - return colorId; - } - - - private - @ColorRes - int getThemeColor(Context context, int color, String theme) { - switch (color) { - case 0xfffb7299: - return context.getResources().getIdentifier(theme, "color", getPackageName()); - case 0xffb85671: - return context.getResources().getIdentifier(theme + "_dark", "color", getPackageName()); - case 0x99f0486c: - return context.getResources().getIdentifier(theme + "_trans", "color", getPackageName()); - } - return -1; - } } diff --git a/app/src/main/java/com/hotbitmapgg/bilibili/base/RxBaseActivity.java b/app/src/main/java/com/hotbitmapgg/bilibili/base/RxBaseActivity.java index 617a0858..8b157c27 100644 --- a/app/src/main/java/com/hotbitmapgg/bilibili/base/RxBaseActivity.java +++ b/app/src/main/java/com/hotbitmapgg/bilibili/base/RxBaseActivity.java @@ -1,17 +1,7 @@ package com.hotbitmapgg.bilibili.base; -import android.app.Activity; -import android.app.ActivityManager; import android.os.Bundle; -import android.os.PersistableBundle; -import android.view.View; -import android.view.Window; -import android.view.WindowManager; - -import com.bilibili.magicasakura.utils.ThemeUtils; -import com.hotbitmapgg.bilibili.utils.ThemeHelper; -import com.hotbitmapgg.bilibili.widget.dialog.CardPickerDialog; -import com.hotbitmapgg.ohmybilibili.R; + import com.trello.rxlifecycle.components.support.RxAppCompatActivity; import butterknife.ButterKnife; @@ -23,7 +13,7 @@ * * Activity基类 */ -public abstract class RxBaseActivity extends RxAppCompatActivity implements CardPickerDialog.ClickListener { +public abstract class RxBaseActivity extends RxAppCompatActivity { private Unbinder bind; @Override @@ -95,49 +85,6 @@ public void initRefreshLayout() { public void finishTask() { } - - @Override - public void onConfirm(int currentTheme) { - if (ThemeHelper.getTheme(RxBaseActivity.this) != currentTheme) { - ThemeHelper.setTheme(RxBaseActivity.this, currentTheme); - ThemeUtils.refreshUI(RxBaseActivity.this, new ThemeUtils.ExtraRefreshable() { - @Override - public void refreshGlobal(Activity activity) { - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { - final RxBaseActivity context = RxBaseActivity.this; - ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(null, null, - ThemeUtils.getThemeAttrColor(context, android.R.attr.colorPrimary)); - setTaskDescription(taskDescription); - getWindow().setStatusBarColor(ThemeUtils.getColorById(context, - R.color.theme_color_primary_dark)); - } - } - - - @Override - public void refreshSpecificView(View view) { - } - } - ); - } - } - - - @Override - public void onPostCreate(Bundle savedInstanceState, PersistableBundle persistentState) { - super.onPostCreate(savedInstanceState); - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { - Window window = getWindow(); - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - window.setStatusBarColor(ThemeUtils.getColorById(this, R.color.theme_color_primary_dark)); - ActivityManager.TaskDescription description = new ActivityManager.TaskDescription(null, null, - ThemeUtils.getThemeAttrColor(this, android.R.attr.colorPrimary)); - setTaskDescription(description); - } - } - - @Override protected void onDestroy() { super.onDestroy(); diff --git a/app/src/main/java/com/hotbitmapgg/bilibili/module/common/MainActivity.java b/app/src/main/java/com/hotbitmapgg/bilibili/module/common/MainActivity.java index cafe2835..a1fd3df4 100644 --- a/app/src/main/java/com/hotbitmapgg/bilibili/module/common/MainActivity.java +++ b/app/src/main/java/com/hotbitmapgg/bilibili/module/common/MainActivity.java @@ -28,7 +28,6 @@ import com.hotbitmapgg.bilibili.utils.PreferenceUtil; import com.hotbitmapgg.bilibili.utils.ToastUtil; import com.hotbitmapgg.bilibili.widget.CircleImageView; -import com.hotbitmapgg.bilibili.widget.dialog.CardPickerDialog; import com.hotbitmapgg.ohmybilibili.R; import butterknife.BindView; @@ -170,9 +169,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) { return true; case R.id.item_theme: // 主题选择 - CardPickerDialog dialog = new CardPickerDialog(); - dialog.setClickListener(this); - dialog.show(getSupportFragmentManager(), CardPickerDialog.TAG); return true; case R.id.item_app: // 应用推荐 diff --git a/app/src/main/java/com/hotbitmapgg/bilibili/utils/ThemeHelper.java b/app/src/main/java/com/hotbitmapgg/bilibili/utils/ThemeHelper.java deleted file mode 100755 index c65be2c0..00000000 --- a/app/src/main/java/com/hotbitmapgg/bilibili/utils/ThemeHelper.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.hotbitmapgg.bilibili.utils; - -import android.content.Context; -import android.content.SharedPreferences; - -/** - * Created by hcc on 16/9/16 13:14 - * 100332338@qq.com - * - * 主题切换帮助类 - */ -public class ThemeHelper { - private static final String CURRENT_THEME = "theme_current"; - public static final int CRAD_SAKURA = 0x1; - public static final int CARD_HOPE = 0x2; - public static final int CARD_STORM = 0x3; - public static final int CARD_WOOD = 0x4; - public static final int CARD_LIGHT = 0x5; - public static final int CARD_THUNDER = 0x6; - public static final int CARD_SAND = 0x7; - public static final int CARD_FIREY = 0x8; - - public static SharedPreferences getSharePreference(Context context) { - return context.getSharedPreferences("multiple_theme", Context.MODE_PRIVATE); - } - - public static void setTheme(Context context, int themeId) { - getSharePreference(context).edit().putInt(CURRENT_THEME, themeId).apply(); - } - - public static int getTheme(Context context) { - return getSharePreference(context).getInt(CURRENT_THEME, CRAD_SAKURA); - } - - public static boolean isDefaultTheme(Context context) { - return getTheme(context) == CRAD_SAKURA; - } - - public static String getName(int currentTheme) { - switch (currentTheme) { - case CRAD_SAKURA: - return "THE SAKURA"; - case CARD_STORM: - return "THE STORM"; - case CARD_WOOD: - return "THE WOOD"; - case CARD_LIGHT: - return "THE LIGHT"; - case CARD_HOPE: - return "THE HOPE"; - case CARD_THUNDER: - return "THE THUNDER"; - case CARD_SAND: - return "THE SAND"; - case CARD_FIREY: - return "THE FIREY"; - } - return "THE RETURN"; - } -} diff --git a/app/src/main/java/com/hotbitmapgg/bilibili/widget/dialog/CardPickerDialog.java b/app/src/main/java/com/hotbitmapgg/bilibili/widget/dialog/CardPickerDialog.java deleted file mode 100755 index e2972c71..00000000 --- a/app/src/main/java/com/hotbitmapgg/bilibili/widget/dialog/CardPickerDialog.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.hotbitmapgg.bilibili.widget.dialog; - -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.DialogFragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.ImageView; - -import com.hotbitmapgg.bilibili.utils.ThemeHelper; -import com.hotbitmapgg.ohmybilibili.R; - -/** - * Created by hcc on 16/9/16 13:14 - * 100332338@qq.com - * - * 主题切换选择对话框 - */ -public class CardPickerDialog extends DialogFragment implements View.OnClickListener { - public static final String TAG = "CardPickerDialog"; - ImageView[] mCards = new ImageView[8]; - Button mConfirm; - Button mCancel; - private int mCurrentTheme; - private ClickListener mClickListener; - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setStyle(DialogFragment.STYLE_NO_TITLE, R.style.AppTheme_AppCompat_Dialog_Alert); - mCurrentTheme = ThemeHelper.getTheme(getActivity()); - } - - - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, - @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.dialog_theme_picker, container, false); - } - - - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - mCancel = (Button) view.findViewById(android.R.id.button2); - mConfirm = (Button) view.findViewById(android.R.id.button1); - mCards[0] = (ImageView) view.findViewById(R.id.theme_pink); - mCards[1] = (ImageView) view.findViewById(R.id.theme_purple); - mCards[2] = (ImageView) view.findViewById(R.id.theme_blue); - mCards[3] = (ImageView) view.findViewById(R.id.theme_green); - mCards[4] = (ImageView) view.findViewById(R.id.theme_green_light); - mCards[5] = (ImageView) view.findViewById(R.id.theme_yellow); - mCards[6] = (ImageView) view.findViewById(R.id.theme_orange); - mCards[7] = (ImageView) view.findViewById(R.id.theme_red); - setImageButtons(mCurrentTheme); - for (ImageView card : mCards) { - card.setOnClickListener(this); - } - mCancel.setOnClickListener(this); - mConfirm.setOnClickListener(this); - } - - - @Override - public void onClick(View v) { - switch (v.getId()) { - case android.R.id.button1: - if (mClickListener != null) { - mClickListener.onConfirm(mCurrentTheme); - } - case android.R.id.button2: - dismiss(); - break; - case R.id.theme_pink: - mCurrentTheme = ThemeHelper.CRAD_SAKURA; - setImageButtons(mCurrentTheme); - break; - case R.id.theme_purple: - mCurrentTheme = ThemeHelper.CARD_HOPE; - setImageButtons(mCurrentTheme); - break; - case R.id.theme_blue: - mCurrentTheme = ThemeHelper.CARD_STORM; - setImageButtons(mCurrentTheme); - break; - case R.id.theme_green: - mCurrentTheme = ThemeHelper.CARD_WOOD; - setImageButtons(mCurrentTheme); - break; - case R.id.theme_green_light: - mCurrentTheme = ThemeHelper.CARD_LIGHT; - setImageButtons(mCurrentTheme); - break; - case R.id.theme_yellow: - mCurrentTheme = ThemeHelper.CARD_THUNDER; - setImageButtons(mCurrentTheme); - break; - case R.id.theme_orange: - mCurrentTheme = ThemeHelper.CARD_SAND; - setImageButtons(mCurrentTheme); - break; - case R.id.theme_red: - mCurrentTheme = ThemeHelper.CARD_FIREY; - setImageButtons(mCurrentTheme); - break; - default: - break; - } - } - - - private void setImageButtons(int currentTheme) { - mCards[0].setSelected(currentTheme == ThemeHelper.CRAD_SAKURA); - mCards[1].setSelected(currentTheme == ThemeHelper.CARD_HOPE); - mCards[2].setSelected(currentTheme == ThemeHelper.CARD_STORM); - mCards[3].setSelected(currentTheme == ThemeHelper.CARD_WOOD); - mCards[4].setSelected(currentTheme == ThemeHelper.CARD_LIGHT); - mCards[5].setSelected(currentTheme == ThemeHelper.CARD_THUNDER); - mCards[6].setSelected(currentTheme == ThemeHelper.CARD_SAND); - mCards[7].setSelected(currentTheme == ThemeHelper.CARD_FIREY); - } - - - public void setClickListener(ClickListener clickListener) { - mClickListener = clickListener; - } - - - public interface ClickListener { - void onConfirm(int currentTheme); - } -}