Implement dark mode

This commit is contained in:
Billy Brawner 2019-05-17 23:29:15 -07:00 committed by William Brawner
parent 4fa6cc462d
commit 9b6bc58021
12 changed files with 77 additions and 113 deletions

View file

@ -27,13 +27,13 @@ android {
} }
defaultConfig { defaultConfig {
applicationId "com.wbrawner.simplemarkdown" applicationId "com.wbrawner.simplemarkdown"
minSdkVersion 19 minSdkVersion 20
targetSdkVersion 'Q' targetSdkVersion 'Q'
multiDexEnabled true multiDexEnabled true
versionCode 18 versionCode 18
versionName "0.6.0" versionName "0.6.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "boolean", "ENABLE_CUSTOM_CSS", "true" buildConfigField "boolean", "ENABLE_CUSTOM_CSS", "false"
} }
signingConfigs { signingConfigs {
release { release {

View file

@ -67,10 +67,6 @@
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".view.activity.MainActivity" /> android:value=".view.activity.MainActivity" />
</activity> </activity>
<activity
android:name=".view.activity.ExplorerActivity"
android:label="@string/title_activity_explorer"
android:theme="@style/AppTheme.NoActionBar" />
<meta-data <meta-data
android:name="firebase_crashlytics_collection_enabled" android:name="firebase_crashlytics_collection_enabled"

View file

@ -37,11 +37,23 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
window.decorView.apply {
systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
)
// setOnApplyWindowInsetsListener { v, insets ->
// pager.updatePadding(top = insets.systemWindowInsetTop)
// insets
// }
}
(application as MarkdownApplication).component.inject(this) (application as MarkdownApplication).component.inject(this)
pager.adapter = EditPagerAdapter(supportFragmentManager, this@MainActivity) pager.adapter = EditPagerAdapter(supportFragmentManager, this@MainActivity)
pager.pageMargin = 1 pager.pageMargin = 1
pager.setPageMarginDrawable(R.color.colorAccent) pager.setPageMarginDrawable(R.color.colorAccent)
tabLayout.setupWithViewPager(pager)
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
tabLayout!!.visibility = View.GONE tabLayout!!.visibility = View.GONE
} }

View file

@ -76,13 +76,13 @@ class EditFragment : Fragment(), MarkdownEditView {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
presenter!!.setEditView(this) presenter.setEditView(this)
markdown = presenter!!.markdown markdown = presenter.markdown
} }
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
presenter!!.setEditView(null) presenter.setEditView(null)
} }
override fun getMarkdown(): String { override fun getMarkdown(): String {
@ -101,7 +101,7 @@ class EditFragment : Fragment(), MarkdownEditView {
} }
override fun onFileSaved(success: Boolean) { override fun onFileSaved(success: Boolean) {
val location = Utils.getDocsPath(activity) + presenter!!.fileName val location = Utils.getDocsPath(activity) + presenter.fileName
val message: String val message: String
message = if (success) { message = if (success) {
getString(R.string.file_saved, location) getString(R.string.file_saved, location)

View file

@ -1,6 +1,8 @@
package com.wbrawner.simplemarkdown.view.fragment package com.wbrawner.simplemarkdown.view.fragment
import android.content.SharedPreferences import android.content.SharedPreferences
import android.content.res.Configuration.UI_MODE_NIGHT_MASK
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.view.LayoutInflater import android.view.LayoutInflater
@ -15,6 +17,7 @@ import com.wbrawner.simplemarkdown.presentation.MarkdownPresenter
import com.wbrawner.simplemarkdown.view.MarkdownPreviewView import com.wbrawner.simplemarkdown.view.MarkdownPreviewView
import javax.inject.Inject import javax.inject.Inject
class PreviewFragment : Fragment(), MarkdownPreviewView { class PreviewFragment : Fragment(), MarkdownPreviewView {
@Inject @Inject
lateinit var presenter: MarkdownPresenter lateinit var presenter: MarkdownPresenter
@ -48,15 +51,18 @@ class PreviewFragment : Fragment(), MarkdownPreviewView {
return@post return@post
} }
val isNightMode = context!!.resources.configuration.uiMode and UI_MODE_NIGHT_MASK == UI_MODE_NIGHT_YES
val defaultCssId = if (isNightMode) {
R.string.pref_custom_css_default_dark
} else {
R.string.pref_custom_css_default
}
val css: String? = if (!BuildConfig.ENABLE_CUSTOM_CSS) { val css: String? = if (!BuildConfig.ENABLE_CUSTOM_CSS) {
sharedPreferences!!.getString( getString(defaultCssId)
getString(R.string.pref_custom_css_default),
""
)
} else { } else {
sharedPreferences!!.getString( sharedPreferences!!.getString(
getString(R.string.pref_custom_css), getString(R.string.pref_custom_css),
getString(R.string.pref_custom_css_default) getString(defaultCssId)
) )
} }

View file

@ -1,75 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.wbrawner.simplemarkdown.view.activity.ExplorerActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/toolbarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<include
android:id="@+id/file_list_container"
layout="@layout/content_explorer"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/file_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbarContainer" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/file_name"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_input_add" />
<EditText
android:id="@+id/file_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button_save"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/button_save"
style="@style/ButtonRed"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:text="@string/action_save"
android:textAllCaps="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,14 +1,32 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.wbrawner.simplemarkdown.view.DisableableViewPager xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:fitsSystemWindows="true"
android:clipToPadding="false">
<com.wbrawner.simplemarkdown.view.DisableableViewPager
android:id="@+id/pager" android:id="@+id/pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="0dp"
android:clipChildren="false"
android:fitsSystemWindows="true"
android:clipToPadding="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/tabLayout" />
<com.google.android.material.tabs.TabLayout <com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout" android:id="@+id/tabLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="top"> android:background="@color/colorBackground"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/toolbar">
<com.google.android.material.tabs.TabItem <com.google.android.material.tabs.TabItem
android:id="@+id/editTab" android:id="@+id/editTab"
@ -22,4 +40,18 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/action_preview" /> android:text="@string/action_preview" />
</com.google.android.material.tabs.TabLayout> </com.google.android.material.tabs.TabLayout>
</com.wbrawner.simplemarkdown.view.DisableableViewPager>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:background="@color/colorBackground"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:clipChildren="false"
android:fitsSystemWindows="true"
android:clipToPadding="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"> android:fitsSystemWindows="true">
<fragment <fragment
android:id="@+id/fragment_settings" android:id="@+id/fragment_settings"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorBackground">#000000</color>
</resources>

View file

@ -3,4 +3,5 @@
<color name="colorPrimary">#d32f2f</color> <color name="colorPrimary">#d32f2f</color>
<color name="colorPrimaryDark">#b71c1c</color> <color name="colorPrimaryDark">#b71c1c</color>
<color name="colorAccent">#d32f2f</color> <color name="colorAccent">#d32f2f</color>
<color name="colorBackground">#FFFFFF</color>
</resources> </resources>

View file

@ -56,6 +56,8 @@
<string name="pref_title_custom_css">Custom CSS</string> <string name="pref_title_custom_css">Custom CSS</string>
<string name="pref_description_custom_css">Paste or write your own CSS to be used for the preview pane</string> <string name="pref_description_custom_css">Paste or write your own CSS to be used for the preview pane</string>
<string name="pref_custom_css_default" translatable="false">pre {overflow:scroll; padding:15px; background: #F1F1F1;}</string> <string name="pref_custom_css_default" translatable="false">pre {overflow:scroll; padding:15px; background: #F1F1F1;}</string>
<string name="pref_custom_css_default_dark" translatable="false">body{background:
#000000;color: #F1F1F1;}a{color:#7b91ff;}pre{background:#111111;}</string>
<string-array name="pref_entries_default_view"> <string-array name="pref_entries_default_view">
<item>@string/value_edit_view</item> <item>@string/value_edit_view</item>
<item>@string/value_explorer_view</item> <item>@string/value_explorer_view</item>

View file

@ -1,29 +1,15 @@
<resources> <resources>
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
<item name="android:windowTranslucentStatus">true</item>
</style> </style>
<style name="AppTheme.Splash" parent="AppTheme"> <style name="AppTheme.Splash" parent="AppTheme">
<item name="android:windowBackground">@drawable/splash_bg</item> <item name="android:windowBackground">@drawable/splash_bg</item>
</style> </style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="ButtonRed">
<item name="android:background">@color/colorAccent</item>
<item name="android:textColor">#FFFFFF</item>
</style>
</resources> </resources>