Skip to content

Commit

Permalink
Dark Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
briceln committed Nov 19, 2018
1 parent 399aacf commit 4cb26a5
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 14 deletions.
33 changes: 32 additions & 1 deletion app/src/main/java/brice_bastien/epicture/AccountSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import android.widget.RadioButton;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import brice_bastien.epicture.ImgurApi.ImgurApi;
import brice_bastien.epicture.Settings.SettingItem;

public class AccountSetting extends AppCompatActivity {
public class AccountSetting extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {

private String Token = "";
private String Username = "";
Expand All @@ -37,6 +39,18 @@ public class AccountSetting extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Boolean switchPref = sharedPrefs.getBoolean(SettingsActivity.KEY_PREF_EXAMPLE_SWITCH, false);
if (switchPref) {
setTheme(R.style.AppTheme_DARK);
getWindow().setNavigationBarColor(getResources().getColor(R.color.colorAccentDarker));
} else {
setTheme(R.style.AppTheme);
getWindow().setNavigationBarColor(getResources().getColor(R.color.colorPrimary));
}
sharedPrefs.registerOnSharedPreferenceChangeListener(this);

setContentView(R.layout.activity_account_setting);

mature = findViewById(R.id.switch_mature_content);
Expand Down Expand Up @@ -116,4 +130,21 @@ public void initSetting(SettingItem settingItem) {
}
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(SettingsActivity.KEY_PREF_EXAMPLE_SWITCH)) {
if (sharedPreferences.getBoolean(SettingsActivity.KEY_PREF_EXAMPLE_SWITCH, false)) {
setTheme(R.style.AppTheme_DARK);
getWindow().setNavigationBarColor(getResources().getColor(R.color.colorAccentDarker));
} else {
setTheme(R.style.AppTheme);
getWindow().setNavigationBarColor(getResources().getColor(R.color.colorPrimary));
}
recreate();
}

}



}
5 changes: 2 additions & 3 deletions app/src/main/java/brice_bastien/epicture/PostComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class PostComment extends AppCompatActivity implements SharedPreferences.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_comment);

SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Boolean switchPref = sharedPrefs.getBoolean(SettingsActivity.KEY_PREF_EXAMPLE_SWITCH, false);
Expand All @@ -48,6 +47,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
sharedPrefs.registerOnSharedPreferenceChangeListener(this);

setContentView(R.layout.activity_post_comment);

sharedPreferences = getSharedPreferences(getString(R.string.user_info_pref), Context.MODE_PRIVATE);
Token = sharedPreferences.getString("User_Token", null);
Expand All @@ -58,7 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
startActivity(intent);
finish();
}

RecyclerView recyclerView = findViewById(R.id.commentList);

Intent intent = getIntent();
Expand All @@ -72,7 +72,6 @@ protected void onCreate(Bundle savedInstanceState) {
Context context = recyclerView.getContext();
recyclerView.setLayoutManager(new LinearLayoutManager(context));


View loadingView = getLayoutInflater().inflate(R.layout.view_loading, recyclerView, false);
View emptyView = getLayoutInflater().inflate(R.layout.view_empty, recyclerView, false);
View errorView = getLayoutInflater().inflate(R.layout.view_error, recyclerView, false);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/brice_bastien/epicture/PostDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class PostDetails extends AppCompatActivity implements SharedPreferences.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_details);

SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Boolean switchPref = sharedPrefs.getBoolean(SettingsActivity.KEY_PREF_EXAMPLE_SWITCH, false);
Expand All @@ -70,6 +69,8 @@ protected void onCreate(Bundle savedInstanceState) {
}
sharedPrefs.registerOnSharedPreferenceChangeListener(this);

setContentView(R.layout.activity_post_details);

sharedPreferences = getSharedPreferences(getString(R.string.user_info_pref), Context.MODE_PRIVATE);
Token = sharedPreferences.getString("User_Token", null);
Username = sharedPreferences.getString("Username", null);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?iconTint"
android:fillColor="#2196F3"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_post_comment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
android:layout_height="@dimen/bottom_bar_height"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:background="@color/white"
android:gravity="center|start"
android:hint="@string/add_comment_hint"
android:inputType="textMultiLine|textCapSentences"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_bottomsheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:itemIconTint="@color/colorPrimary"
app:itemTextColor="@color/colorPrimaryText"
app:itemTextColor="@color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/layout/fragment_comments.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
android:layout_marginStart="@dimen/basic_margin"
android:layout_marginTop="4dp"
android:layout_marginBottom="@dimen/basic_margin"
android:textColor="@color/colorPrimaryText"
android:padding="0dp" />

</LinearLayout>
Expand All @@ -49,7 +48,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:textColor="@color/colorSecondaryText"
android:textSize="10sp" />

</LinearLayout>
Expand Down
22 changes: 18 additions & 4 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:iconTint">@color/colorIcon</item>
<item name="android:textColorPrimary">#000</item>
<item name="android:navigationBarColor">@color/colorPrimary</item>
<item name="android:windowMinWidthMajor">90%</item>
<item name="android:windowMinWidthMinor">90%</item>
Expand All @@ -18,21 +19,25 @@
<item name="android:windowMinWidthMinor">90%</item>
</style>

<style name="AppTheme.DARK" parent="Theme.MaterialComponents.Light.DarkActionBar">

<style name="AppTheme.DARK" parent="Theme.AppCompat">
<item name="colorPrimary">#000000</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:iconTint">@color/colorAccent</item>
<item name="android:background">@color/colorAccentDarker</item>
<item name="android:actionBarItemBackground">@color/colorAccentDarker</item>
<item name="android:textColor">@color/white</item>
<item name="android:actionBarStyle">@style/MyActionBarTheme</item>
<!--<item name="android:actionBarStyle">@style/MyActionBarTheme</item>-->
<item name="android:actionButtonStyle">@color/white</item>
<item name="actionMenuTextColor">@color/white</item>
<item name="android:actionMenuTextColor">@color/white</item>
<item name="android:itemTextAppearance">@style/MenuItemTextAppearance</item>
<!--<item name="android:itemTextAppearance">@style/MenuItemTextAppearance</item>-->
<item name="searchViewStyle">@style/MySearchViewStyle</item>
<item name="android:editTextColor">@color/white</item>

<!--<item name="navigationViewStyle">@style/MenuItemTextAppearance</item>-->

<item name="android:textColorPrimary">@color/white</item>
<item name="android:textColorSecondary">@color/white</item>
<item name="android:textColorTertiary">@color/white</item>
Expand All @@ -41,10 +46,19 @@
<item name="android:textColorTertiaryInverse">@color/white</item>
<item name="android:windowMinWidthMajor">90%</item>
<item name="android:windowMinWidthMinor">90%</item>
<item name="android:colorBackground">@color/colorPrimaryDarker</item>
</style>

<style name="AppTheme.DARK.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowMinWidthMajor">90%</item>
<item name="android:windowMinWidthMinor">90%</item>
</style>

<style name="MyActionBarTheme">
<item name="android:backgroundTint">?colorPrimary</item>
<item name="android:iconTint">@color/white</item>
</style>

<style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView">
Expand All @@ -64,7 +78,7 @@
<item name="android:icon">@color/white</item>
</style>

<style name="MenuItemTextAppearance">
<style name="MenuItemTextAppearance" parent="Widget.Design.NavigationView">
<item name="textColor">@color/white</item>
<item name="actionMenuTextColor">@color/white</item>
<item name="android:itemBackground">@color/white</item>
Expand Down

0 comments on commit 4cb26a5

Please sign in to comment.