Skip to content

Commit

Permalink
Fragment requires theme in styles.xml & icon colour moved
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-stoneuk committed Jun 10, 2017
1 parent 58a3b13 commit 5c7de58
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ExampleMaterialAboutActivity extends MaterialAboutActivity {
public static final int THEME_DARK_LIGHTBAR = 2;
public static final int THEME_DARK_DARKBAR = 3;

protected int colorIcon = R.color.colorIconLight;
protected int colorIcon = R.color.mal_color_icon_light_theme;

@NonNull @Override
protected MaterialAboutList getMaterialAboutList(@NonNull final Context c) {
Expand Down Expand Up @@ -106,19 +106,19 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
switch (getIntent().getIntExtra(THEME_EXTRA, THEME_LIGHT_DARKBAR)) {
case THEME_LIGHT_LIGHTBAR:
setTheme(R.style.AppTheme_MaterialAboutActivity_Light_LightActionBar);
colorIcon = R.color.colorIconLight;
colorIcon = R.color.mal_color_icon_light_theme;
break;
case THEME_DARK_LIGHTBAR:
setTheme(R.style.AppTheme_MaterialAboutActivity_Dark_LightActionBar);
colorIcon = R.color.colorIconDark;
colorIcon = R.color.mal_color_icon_dark_theme;
break;
case THEME_LIGHT_DARKBAR:
setTheme(R.style.AppTheme_MaterialAboutActivity_Light_DarkActionBar);
colorIcon = R.color.colorIconLight;
colorIcon = R.color.mal_color_icon_light_theme;
break;
case THEME_DARK_DARKBAR:
setTheme(R.style.AppTheme_MaterialAboutActivity_Dark_DarkActionBar);
colorIcon = R.color.colorIconDark;
colorIcon = R.color.mal_color_icon_dark_theme;
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class ExampleMaterialAboutFragment extends MaterialAboutFragment {

@Override
protected MaterialAboutList getMaterialAboutList(final Context c) {
return Demo.createMaterialAboutList(c, R.color.colorIconDark, THEME_LIGHT_DARKBAR);
return Demo.createMaterialAboutList(c, R.color.mal_color_icon_dark_theme, THEME_LIGHT_DARKBAR);
}

@Override
protected int getTheme() {
return THEME_DARK;
return R.style.AppTheme_MaterialAboutActivity_Fragment;
}
}
3 changes: 0 additions & 3 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@

<color name="colorLightBar">#FFFFFF</color>
<color name="colorLightStatus">#9E9E9E</color>

<color name="colorIconLight">#616161</color>
<color name="colorIconDark">#E0E0E0</color>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.MaterialAboutActivity.Fragment" parent="Theme.Mal.Dark.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.MaterialAboutActivity.Dark.LightActionBar" parent="Theme.Mal.Dark.LightActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorLightBar</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -19,32 +17,20 @@
import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager;
import com.danielstone.materialaboutlibrary.util.ViewTypeManager;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public abstract class MaterialAboutFragment extends Fragment {

private MaterialAboutList list = new MaterialAboutList.Builder().build();
private RecyclerView recyclerView;
private MaterialAboutListAdapter adapter;

@Retention(RetentionPolicy.SOURCE)
@IntDef({THEME_LIGHT, THEME_DARK})
public @interface FragmentTheme {
}

public static final int THEME_LIGHT = 0;
public static final int THEME_DARK = 1;

public static MaterialAboutFragment newInstance(MaterialAboutFragment fragment) {
return fragment;
}

protected abstract MaterialAboutList getMaterialAboutList(Context activityContext);

@FragmentTheme
protected int getTheme() {
return THEME_LIGHT;
return R.style.Theme_Mal_Light_DarkActionBar;
}

protected boolean shouldAnimate() {
Expand All @@ -54,17 +40,7 @@ protected boolean shouldAnimate() {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
int style = -1;
switch (getTheme()) {
case THEME_LIGHT:
Log.i("test", "onCreateView: light theme");
style = R.style.Theme_Mal_Light_DarkActionBar;
break;
case THEME_DARK:
Log.i("test", "onCreateView: dark theme");
style = R.style.Theme_Mal_Dark_DarkActionBar;
break;
}
int style = getTheme();

// create ContextThemeWrapper from the original Activity Context with the custom theme
final Context contextThemeWrapper = new android.view.ContextThemeWrapper(getActivity(), style);
Expand Down
2 changes: 2 additions & 0 deletions library/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
<color name="mal_text_primary_dark">#FFFFFF</color>
<color name="mal_text_secondary_dark">#b4ffffff</color>

<color name="mal_color_icon_light_theme">#616161</color>
<color name="mal_color_icon_dark_theme">#E0E0E0</color>
</resources>

0 comments on commit 5c7de58

Please sign in to comment.