From f66bec3bdcb14c5a7591da6f39191e89c0536b8e Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Sun, 21 Jun 2020 13:24:14 -0300 Subject: [PATCH 01/20] Add Themes button --- .../main/java/dev/lucasnlm/antimine/GameActivity.kt | 8 ++++++++ app/src/main/res/drawable/themes.xml | 10 ++++++++++ app/src/main/res/menu/nav_menu.xml | 10 ++++++++++ build.gradle | 2 +- .../antimine/core/analytics/models/Analytics.kt | 2 ++ gradle/wrapper/gradle-wrapper.properties | 2 +- 6 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/themes.xml diff --git a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt index 18dd50f34..d47a53186 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt @@ -316,6 +316,7 @@ class GameActivity : AppCompatActivity(R.layout.activity_game), DialogInterface. R.id.about -> showAbout() R.id.settings -> showSettings() R.id.rate -> openRateUsLink("Drawer") + R.id.themes -> openThemes() R.id.share_now -> shareCurrentGame() R.id.previous_games -> openSaveHistory() R.id.stats -> openStats() @@ -440,6 +441,13 @@ class GameActivity : AppCompatActivity(R.layout.activity_game), DialogInterface. } } + private fun openThemes() { + analyticsManager.sentEvent(Analytics.OpenThemes) + Intent(this, AboutActivity::class.java).apply { + startActivity(this) + } + } + private fun openSaveHistory() { analyticsManager.sentEvent(Analytics.OpenSaveHistory) Intent(this, HistoryActivity::class.java).apply { diff --git a/app/src/main/res/drawable/themes.xml b/app/src/main/res/drawable/themes.xml new file mode 100644 index 000000000..533274bba --- /dev/null +++ b/app/src/main/res/drawable/themes.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/menu/nav_menu.xml b/app/src/main/res/menu/nav_menu.xml index 304a88948..ffa385015 100644 --- a/app/src/main/res/menu/nav_menu.xml +++ b/app/src/main/res/menu/nav_menu.xml @@ -65,6 +65,16 @@ android:title="@string/settings" /> + + + + + Date: Sun, 21 Jun 2020 14:07:40 -0300 Subject: [PATCH 02/20] Add ThemeActivity --- app/src/main/AndroidManifest.xml | 8 ++++++++ app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt | 3 ++- .../java/dev/lucasnlm/antimine/theme/ThemeActivity.kt | 9 +++++++++ app/src/main/res/layout/activity_theme.xml | 7 +++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt create mode 100644 app/src/main/res/layout/activity_theme.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 06319fdfd..916cf5341 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -148,6 +148,14 @@ android:value="dev.lucasnlm.antimine.GameActivity" /> + + + + + + + \ No newline at end of file From 4c6928f2025da66460a28f9cfe59da0df9992735 Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Fri, 7 Aug 2020 15:15:42 -0300 Subject: [PATCH 03/20] Add basic Theme feature --- app/src/main/AndroidManifest.xml | 1 + .../dev/lucasnlm/antimine/GameActivity.kt | 9 +- .../dev/lucasnlm/antimine/ThematicActivity.kt | 43 +++++++++ .../dev/lucasnlm/antimine/TvGameActivity.kt | 10 +- .../lucasnlm/antimine/about/AboutActivity.kt | 6 +- .../antimine/control/ControlDialogFragment.kt | 4 +- .../custom/CustomLevelDialogFragment.kt | 2 +- .../antimine/history/HistoryActivity.kt | 4 +- .../antimine/history/views/HistoryAdapter.kt | 23 +++-- .../history/views/HistoryViewHolder.kt | 15 --- .../level/view/EndGameDialogFragment.kt | 2 +- .../preferences/PreferencesActivity.kt | 7 +- .../lucasnlm/antimine/share/ShareBuilder.kt | 16 +--- .../lucasnlm/antimine/stats/StatsActivity.kt | 4 +- .../lucasnlm/antimine/text/TextActivity.kt | 3 +- .../lucasnlm/antimine/theme/ThemeActivity.kt | 40 +++++++- .../antimine/theme/view/ThemeAdapter.kt | 96 +++++++++++++++++++ .../theme/viewmodel/ThemeViewModel.kt | 21 ++++ app/src/main/res/layout/activity_stats.xml | 24 ++--- app/src/main/res/layout/activity_theme.xml | 12 ++- app/src/main/res/layout/dialog_end_game.xml | 2 - app/src/main/res/layout/view_control_item.xml | 3 - app/src/main/res/layout/view_history_item.xml | 3 - app/src/main/res/layout/view_theme.xml | 87 +++++++++++++++++ app/src/main/res/menu/nav_menu.xml | 2 +- .../view/common/level/view/AreaScreenshot.kt | 4 +- .../antimine/common/level/di/LevelModule.kt | 7 -- .../common/level/models/AreaPalette.kt | 17 ---- .../antimine/common/level/view/AreaAdapter.kt | 3 +- .../antimine/common/level/view/AreaPainter.kt | 43 +++++---- .../antimine/common/level/view/AreaView.kt | 30 +++--- .../common/level/viewmodel/GameViewModel.kt | 5 + .../lucasnlm/antimine/core/di/CommonModule.kt | 17 ++++ .../core/preferences/PreferencesRepository.kt | 11 +++ .../antimine/core/themes/model/AppTheme.kt | 11 +++ .../core/themes/repository/ThemeRepository.kt | 64 +++++++++++++ .../antimine/core/themes/repository/Themes.kt | 49 ++++++++++ common/src/main/res/values-night/colors.xml | 8 +- common/src/main/res/values-v21/themes.xml | 41 ++++++++ common/src/main/res/values/colors.xml | 10 +- common/src/main/res/values/dimens.xml | 2 + common/src/main/res/values/strings.xml | 1 + 42 files changed, 604 insertions(+), 158 deletions(-) create mode 100644 app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt delete mode 100644 app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryViewHolder.kt create mode 100644 app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt create mode 100644 app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt create mode 100644 app/src/main/res/layout/view_theme.xml create mode 100644 common/src/main/java/dev/lucasnlm/antimine/core/themes/model/AppTheme.kt create mode 100644 common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt create mode 100644 common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/Themes.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 916cf5341..e58b98518 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -149,6 +149,7 @@ Unit) { - AlertDialog.Builder(this, R.style.MyDialog).apply { + AlertDialog.Builder(this).apply { setTitle(R.string.new_game) setMessage(R.string.retry_sure) setPositiveButton(R.string.resume) { _, _ -> action() } @@ -409,7 +410,7 @@ class GameActivity : AppCompatActivity(R.layout.activity_game), DialogInterface. } private fun showQuitConfirmation(action: () -> Unit) { - AlertDialog.Builder(this, R.style.MyDialog) + AlertDialog.Builder(this) .setTitle(R.string.are_you_sure) .setMessage(R.string.quit_confirm) .setPositiveButton(R.string.quit) { _, _ -> action() } diff --git a/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt new file mode 100644 index 000000000..17c1fde23 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt @@ -0,0 +1,43 @@ +package dev.lucasnlm.antimine + +import android.os.Bundle +import androidx.annotation.LayoutRes +import androidx.appcompat.app.AppCompatActivity +import dagger.hilt.android.AndroidEntryPoint +import dev.lucasnlm.antimine.core.themes.repository.IThemeRepository +import javax.inject.Inject + +open class ThematicActivity : AppCompatActivity { + constructor() : super() + constructor(@LayoutRes contentLayoutId: Int) : super(contentLayoutId) + + @Inject + lateinit var themeRepository: IThemeRepository + + protected open val noActionBar: Boolean = false + + protected val usingThemeId: Long by lazy { + currentThemeId() + } + + private fun currentThemeId(): Long = themeRepository.getTheme().id + + override fun onCreate(savedInstanceState: Bundle?) { + themeRepository.getCustomTheme()?.let { + if (noActionBar) { + setTheme(it.themeNoActionBar) + } else { + setTheme(it.theme) + } + } + super.onCreate(savedInstanceState) + } + + override fun onResume() { + super.onResume() + + if (usingThemeId != currentThemeId()) { + recreate() + } + } +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt index fe18b45e7..9418dad83 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt @@ -161,7 +161,7 @@ class TvGameActivity : AppCompatActivity() { } private fun newGameConfirmation(action: () -> Unit) { - AlertDialog.Builder(this, R.style.MyDialog).apply { + AlertDialog.Builder(this).apply { setTitle(R.string.new_game) setMessage(R.string.retry_sure) setPositiveButton(R.string.resume) { _, _ -> action() } @@ -171,7 +171,7 @@ class TvGameActivity : AppCompatActivity() { } private fun showQuitConfirmation(action: () -> Unit) { - AlertDialog.Builder(this, R.style.MyDialog) + AlertDialog.Builder(this) .setTitle(R.string.are_you_sure) .setMessage(R.string.quit_confirm) .setPositiveButton(R.string.quit) { _, _ -> action() } @@ -198,7 +198,7 @@ class TvGameActivity : AppCompatActivity() { } private fun showVictory() { - AlertDialog.Builder(this, R.style.MyDialog).apply { + AlertDialog.Builder(this).apply { setTitle(R.string.you_won) setMessage(R.string.all_mines_disabled) setCancelable(false) @@ -218,7 +218,7 @@ class TvGameActivity : AppCompatActivity() { Handler(), { if (status is Status.Over && !isFinishing) { - AlertDialog.Builder(this, R.style.MyDialog).apply { + AlertDialog.Builder(this).apply { setTitle(R.string.new_game) setMessage(R.string.new_game_request) setPositiveButton(R.string.yes) { _, _ -> @@ -242,7 +242,7 @@ class TvGameActivity : AppCompatActivity() { Handler(), { if (status is Status.Over && !isFinishing) { - AlertDialog.Builder(this, R.style.MyDialog).apply { + AlertDialog.Builder(this).apply { setTitle(R.string.you_lost) setMessage(R.string.new_game_request) setPositiveButton(R.string.yes) { _, _ -> diff --git a/app/src/main/java/dev/lucasnlm/antimine/about/AboutActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/about/AboutActivity.kt index 2a702be7f..bb02fba81 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/about/AboutActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/about/AboutActivity.kt @@ -4,18 +4,20 @@ import android.content.Intent import android.net.Uri import android.os.Bundle import androidx.activity.viewModels -import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentTransaction import androidx.lifecycle.Observer +import dagger.hilt.android.AndroidEntryPoint import dev.lucasnlm.antimine.R +import dev.lucasnlm.antimine.ThematicActivity import dev.lucasnlm.antimine.about.models.AboutEvent import dev.lucasnlm.antimine.about.viewmodel.AboutViewModel import dev.lucasnlm.antimine.about.views.AboutInfoFragment import dev.lucasnlm.antimine.about.views.thirds.ThirdPartyFragment import dev.lucasnlm.antimine.about.views.translators.TranslatorsFragment -class AboutActivity : AppCompatActivity(R.layout.activity_empty) { +@AndroidEntryPoint +class AboutActivity : ThematicActivity(R.layout.activity_empty) { private val aboutViewModel: AboutViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/dev/lucasnlm/antimine/control/ControlDialogFragment.kt b/app/src/main/java/dev/lucasnlm/antimine/control/ControlDialogFragment.kt index b1e24542b..a2845d309 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/control/ControlDialogFragment.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/control/ControlDialogFragment.kt @@ -33,10 +33,10 @@ class ControlDialogFragment : AppCompatDialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val currentControl = preferencesRepository.controlStyle().ordinal - return AlertDialog.Builder(requireContext(), R.style.MyDialog).apply { + return AlertDialog.Builder(requireContext()).apply { setTitle(R.string.control) setSingleChoiceItems(adapter, currentControl, null) - setPositiveButton(R.string.ok, null) // TODO OK + setPositiveButton(R.string.ok, null) }.create() } diff --git a/app/src/main/java/dev/lucasnlm/antimine/custom/CustomLevelDialogFragment.kt b/app/src/main/java/dev/lucasnlm/antimine/custom/CustomLevelDialogFragment.kt index 343b3944c..1a5feac07 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/custom/CustomLevelDialogFragment.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/custom/CustomLevelDialogFragment.kt @@ -46,7 +46,7 @@ class CustomLevelDialogFragment : AppCompatDialogFragment() { } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - return AlertDialog.Builder(requireContext(), R.style.MyDialog).apply { + return AlertDialog.Builder(requireContext()).apply { setTitle(R.string.new_game) setView(R.layout.dialog_custom_game) setNegativeButton(R.string.cancel, null) diff --git a/app/src/main/java/dev/lucasnlm/antimine/history/HistoryActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/history/HistoryActivity.kt index f2fe28646..db8f629e8 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/history/HistoryActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/history/HistoryActivity.kt @@ -1,13 +1,13 @@ package dev.lucasnlm.antimine.history import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity import dagger.hilt.android.AndroidEntryPoint import dev.lucasnlm.antimine.R +import dev.lucasnlm.antimine.ThematicActivity import dev.lucasnlm.antimine.history.views.HistoryFragment @AndroidEntryPoint -class HistoryActivity : AppCompatActivity(R.layout.activity_empty) { +class HistoryActivity : ThematicActivity(R.layout.activity_empty) { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) supportFragmentManager.beginTransaction().apply { diff --git a/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryAdapter.kt b/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryAdapter.kt index 43225ebec..7a831e3db 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryAdapter.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryAdapter.kt @@ -6,6 +6,8 @@ import android.net.Uri import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TextView +import androidx.appcompat.widget.AppCompatImageView import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import dev.lucasnlm.antimine.DeepLink @@ -13,6 +15,7 @@ import dev.lucasnlm.antimine.R import dev.lucasnlm.antimine.common.level.database.models.Save import dev.lucasnlm.antimine.common.level.database.models.SaveStatus import dev.lucasnlm.antimine.common.level.models.Difficulty +import kotlinx.android.synthetic.main.view_history_item.view.* class HistoryAdapter( private val saveHistory: List @@ -38,23 +41,19 @@ class HistoryAdapter( ) val context = holder.itemView.context - holder.flag.setColorFilter( - when (status) { - SaveStatus.VICTORY -> ContextCompat.getColor(context, R.color.victory) - SaveStatus.ON_GOING -> ContextCompat.getColor(context, R.color.ongoing) - SaveStatus.DEFEAT -> ContextCompat.getColor(context, R.color.lose) - }, - PorterDuff.Mode.SRC_IN - ) + holder.flag.setColorFilter(holder.minesCount.currentTextColor) + holder.flag.alpha = if (status == SaveStatus.VICTORY) 1.0f else 0.35f holder.minefieldSize.text = String.format("%d x %d", minefield.width, minefield.height) holder.minesCount.text = context.getString(R.string.mines_remaining, minefield.mines) if (status != SaveStatus.VICTORY) { holder.replay.setImageResource(R.drawable.replay) + holder.replay.setColorFilter(holder.minesCount.currentTextColor) holder.replay.setOnClickListener { replayGame(it, uid) } } else { holder.replay.setImageResource(R.drawable.play) + holder.replay.setColorFilter(holder.minesCount.currentTextColor) holder.replay.setOnClickListener { loadGame(it, uid) } } @@ -85,3 +84,11 @@ class HistoryAdapter( view.context.startActivity(intent) } } + +class HistoryViewHolder(view: View) : RecyclerView.ViewHolder(view) { + val flag: AppCompatImageView = view.badge + val difficulty: TextView = view.difficulty + val minefieldSize: TextView = view.minefieldSize + val minesCount: TextView = view.minesCount + val replay: AppCompatImageView = view.replay +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryViewHolder.kt b/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryViewHolder.kt deleted file mode 100644 index 1e129c3f6..000000000 --- a/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryViewHolder.kt +++ /dev/null @@ -1,15 +0,0 @@ -package dev.lucasnlm.antimine.history.views - -import android.view.View -import android.widget.TextView -import androidx.appcompat.widget.AppCompatImageView -import androidx.recyclerview.widget.RecyclerView -import kotlinx.android.synthetic.main.view_history_item.view.* - -class HistoryViewHolder(view: View) : RecyclerView.ViewHolder(view) { - val flag: AppCompatImageView = view.badge - val difficulty: TextView = view.difficulty - val minefieldSize: TextView = view.minefieldSize - val minesCount: TextView = view.minesCount - val replay: AppCompatImageView = view.replay -} diff --git a/app/src/main/java/dev/lucasnlm/antimine/level/view/EndGameDialogFragment.kt b/app/src/main/java/dev/lucasnlm/antimine/level/view/EndGameDialogFragment.kt index cadb8ac64..afda8b8e9 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/level/view/EndGameDialogFragment.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/level/view/EndGameDialogFragment.kt @@ -50,7 +50,7 @@ class EndGameDialogFragment : AppCompatDialogFragment() { @SuppressLint("InflateParams") override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = - AlertDialog.Builder(requireContext(), R.style.MyDialog).apply { + AlertDialog.Builder(requireContext()).apply { val view = LayoutInflater .from(context) .inflate(R.layout.dialog_end_game, null, false) diff --git a/app/src/main/java/dev/lucasnlm/antimine/preferences/PreferencesActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/preferences/PreferencesActivity.kt index a3cfc8bd5..661b38e7c 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/preferences/PreferencesActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/preferences/PreferencesActivity.kt @@ -1,13 +1,14 @@ package dev.lucasnlm.antimine.preferences import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceManager - +import dagger.hilt.android.AndroidEntryPoint import dev.lucasnlm.antimine.R +import dev.lucasnlm.antimine.ThematicActivity -class PreferencesActivity : AppCompatActivity(R.layout.activity_empty) { +@AndroidEntryPoint +class PreferencesActivity : ThematicActivity(R.layout.activity_empty) { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) PreferenceManager.setDefaultValues(this, R.xml.preferences, false) diff --git a/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt b/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt index 2bf9281c9..4daa6f01f 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt @@ -3,20 +3,15 @@ package dev.lucasnlm.antimine.share import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent -import android.graphics.Bitmap -import android.graphics.Canvas -import android.graphics.Color -import android.graphics.Paint -import android.graphics.RectF -import android.graphics.Typeface +import android.graphics.* import androidx.core.content.FileProvider import dev.lucasnlm.antimine.BuildConfig import dev.lucasnlm.antimine.R import dev.lucasnlm.antimine.common.level.models.Area import dev.lucasnlm.antimine.common.level.models.AreaPaintSettings -import dev.lucasnlm.antimine.common.level.models.AreaPalette import dev.lucasnlm.antimine.common.level.models.Minefield import dev.lucasnlm.antimine.common.level.view.paintOnCanvas +import dev.lucasnlm.antimine.core.themes.repository.Themes.DarkTheme import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.io.File @@ -42,8 +37,6 @@ class ShareBuilder( val padding = 1f val radius = 2f - val areaPalette = AreaPalette.fromLightTheme() - val paintSettings = AreaPaintSettings( Paint().apply { isAntiAlias = true @@ -66,6 +59,7 @@ class ShareBuilder( 0.0f, 0.0f, imageWidth.toFloat(), imageHeight.toFloat(), Paint().apply { color = Color.WHITE + alpha = 0xff style = Paint.Style.FILL } ) @@ -78,13 +72,13 @@ class ShareBuilder( area.paintOnCanvas( context, canvas, + appTheme = DarkTheme, isAmbientMode = false, isLowBitAmbient = false, isFocused = false, paintSettings = paintSettings, markPadding = 6, - minePadding = 1, - areaPalette = areaPalette + minePadding = 1 ) canvas.restore() } diff --git a/app/src/main/java/dev/lucasnlm/antimine/stats/StatsActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/stats/StatsActivity.kt index ea072e070..dd2673191 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/stats/StatsActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/stats/StatsActivity.kt @@ -5,10 +5,10 @@ import android.view.Menu import android.view.MenuItem import androidx.activity.viewModels import androidx.appcompat.app.AlertDialog -import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.Observer import dagger.hilt.android.AndroidEntryPoint import dev.lucasnlm.antimine.R +import dev.lucasnlm.antimine.ThematicActivity import dev.lucasnlm.antimine.common.level.repository.IStatsRepository import dev.lucasnlm.antimine.stats.model.StatsModel import dev.lucasnlm.antimine.stats.viewmodel.StatsViewModel @@ -18,7 +18,7 @@ import kotlinx.coroutines.launch import javax.inject.Inject @AndroidEntryPoint -class StatsActivity : AppCompatActivity(R.layout.activity_stats) { +class StatsActivity : ThematicActivity(R.layout.activity_stats) { @Inject lateinit var statsRepository: IStatsRepository diff --git a/app/src/main/java/dev/lucasnlm/antimine/text/TextActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/text/TextActivity.kt index fece98841..2edfd62eb 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/text/TextActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/text/TextActivity.kt @@ -9,6 +9,7 @@ import androidx.activity.viewModels import androidx.annotation.RawRes import androidx.lifecycle.Observer import dev.lucasnlm.antimine.R +import dev.lucasnlm.antimine.ThematicActivity import dev.lucasnlm.antimine.text.viewmodel.TextViewModel import kotlinx.android.synthetic.main.activity_text.* @@ -17,7 +18,7 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -class TextActivity : AppCompatActivity(R.layout.activity_text) { +class TextActivity : ThematicActivity(R.layout.activity_text) { private val viewModel: TextViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt index 3bc2117c5..cc21af778 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt @@ -1,9 +1,45 @@ package dev.lucasnlm.antimine.theme -import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import androidx.activity.viewModels +import androidx.lifecycle.Observer +import androidx.lifecycle.lifecycleScope +import androidx.recyclerview.widget.GridLayoutManager import dagger.hilt.android.AndroidEntryPoint import dev.lucasnlm.antimine.R +import dev.lucasnlm.antimine.ThematicActivity +import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository +import dev.lucasnlm.antimine.common.level.view.SpaceItemDecoration +import dev.lucasnlm.antimine.theme.view.ThemeAdapter +import dev.lucasnlm.antimine.theme.viewmodel.ThemeViewModel +import kotlinx.android.synthetic.main.activity_theme.* +import javax.inject.Inject @AndroidEntryPoint -class ThemeActivity : AppCompatActivity(R.layout.activity_theme) { +class ThemeActivity : ThematicActivity(R.layout.activity_theme) { + @Inject + lateinit var dimensionRepository: IDimensionRepository + + private val viewModel by viewModels() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + lifecycleScope.launchWhenCreated { + val gaps = resources.getDimension(R.dimen.theme_divider) * 6 + val areaSize = (dimensionRepository.displaySize().width - gaps) / 9f + + recyclerView.apply { + addItemDecoration(SpaceItemDecoration(R.dimen.theme_divider)) + setHasFixedSize(true) + layoutManager = GridLayoutManager(context, 3) + adapter = ThemeAdapter(viewModel, areaSize) + } + + viewModel.theme.observe(this@ThemeActivity, Observer { + if (usingThemeId != it.id) { + recreate() + } + }) + } + } } diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt new file mode 100644 index 000000000..8a580d092 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt @@ -0,0 +1,96 @@ +package dev.lucasnlm.antimine.theme.view + +import android.content.Context +import android.graphics.Paint +import android.graphics.RectF +import android.graphics.Typeface +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import dev.lucasnlm.antimine.R +import dev.lucasnlm.antimine.common.level.models.Area +import dev.lucasnlm.antimine.common.level.models.AreaPaintSettings +import dev.lucasnlm.antimine.common.level.models.Mark +import dev.lucasnlm.antimine.common.level.view.AreaView +import dev.lucasnlm.antimine.core.themes.model.AppTheme +import dev.lucasnlm.antimine.theme.viewmodel.ThemeViewModel +import kotlinx.android.synthetic.main.view_theme.view.* + +class ThemeAdapter( + private val themeViewModel: ThemeViewModel, + private val areaSize: Float +) : RecyclerView.Adapter() { + + private val themes: List = themeViewModel.getThemes() + + private val minefield = listOf( + Area(0, 0, 0, 1, hasMine = false, mistake = false, mark = Mark.None, isCovered = false) + ) + + init { + setHasStableIds(true) + } + + override fun getItemId(position: Int): Long = themes[position].id + + override fun getItemCount(): Int = themes.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ThemeViewHolder { + val view = LayoutInflater + .from(parent.context) + .inflate(R.layout.view_theme, parent, false) + + return ThemeViewHolder(view) + } + + override fun onBindViewHolder(holder: ThemeViewHolder, position: Int) { + val theme = themes[position] + val paintSettings = createAreaPaintSettings(holder.itemView.context, areaSize) + holder.itemView.run { + area0.bindTheme(minefield[0], theme, paintSettings) + area1.bindTheme(minefield[0], theme, paintSettings) + area2.bindTheme(minefield[0], theme, paintSettings) + area3.bindTheme(minefield[0], theme, paintSettings) + area4.bindTheme(minefield[0], theme, paintSettings) + area5.bindTheme(minefield[0], theme, paintSettings) + area6.bindTheme(minefield[0], theme, paintSettings) + area7.bindTheme(minefield[0], theme, paintSettings) + area8.bindTheme(minefield[0], theme, paintSettings) + + clickTheme.setOnClickListener { + themeViewModel.setTheme(theme) + } + } + } + + private fun AreaView.bindTheme(area: Area, appTheme: AppTheme, paintSettings: AreaPaintSettings) { + bindField( + area, + appTheme, + isAmbientMode = false, + isLowBitAmbient = false, + paintSettings = paintSettings + ) + } + + companion object { + fun createAreaPaintSettings(context: Context, size: Float): AreaPaintSettings { + val resources = context.resources + return AreaPaintSettings( + Paint().apply { + isAntiAlias = true + isDither = true + style = Paint.Style.FILL + textSize = 18.0f * context.resources.displayMetrics.density + typeface = Typeface.DEFAULT_BOLD + textAlign = Paint.Align.CENTER + }, + RectF(0.0f, 0.0f, size, size), + resources.getDimension(dev.lucasnlm.antimine.common.R.dimen.field_radius) + ) + } + } +} + +class ThemeViewHolder(view: View) : RecyclerView.ViewHolder(view) diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt new file mode 100644 index 000000000..1ff7a3817 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt @@ -0,0 +1,21 @@ +package dev.lucasnlm.antimine.theme.viewmodel + +import androidx.hilt.lifecycle.ViewModelInject +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import dev.lucasnlm.antimine.core.themes.model.AppTheme +import dev.lucasnlm.antimine.core.themes.repository.IThemeRepository + +class ThemeViewModel @ViewModelInject constructor( + private val themeRepository: IThemeRepository +) : ViewModel() { + val theme = MutableLiveData() + + fun getThemes(): List = themeRepository.getAllThemes() + + fun setTheme(appTheme: AppTheme) { + themeRepository.setTheme(appTheme) + theme.postValue(appTheme) + } +} + diff --git a/app/src/main/res/layout/activity_stats.xml b/app/src/main/res/layout/activity_stats.xml index 53422a75b..ade44ec0e 100644 --- a/app/src/main/res/layout/activity_stats.xml +++ b/app/src/main/res/layout/activity_stats.xml @@ -12,8 +12,7 @@ + android:text="@string/games" /> + android:text="@string/mines" /> + android:text="@string/total_time" /> + android:text="@string/average_time" /> + android:text="@string/open_areas" /> + android:text="@string/performance" /> + android:text="@string/victories" /> + android:text="@string/defeats" /> - + android:layout_height="match_parent" + android:fitsSystemWindows="true"> - \ No newline at end of file + + + diff --git a/app/src/main/res/layout/dialog_end_game.xml b/app/src/main/res/layout/dialog_end_game.xml index 2e83367fe..cc8815d0a 100644 --- a/app/src/main/res/layout/dialog_end_game.xml +++ b/app/src/main/res/layout/dialog_end_game.xml @@ -27,7 +27,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" - android:textColor="@color/text_color" android:textSize="18sp" android:textStyle="bold" android:textAlignment="center" @@ -43,7 +42,6 @@ android:layout_height="wrap_content" android:layout_marginTop="24dp" android:text="@string/you_lost" - android:textColor="@color/text_color" android:textSize="14sp" android:textAlignment="center" android:gravity="center_horizontal" diff --git a/app/src/main/res/layout/view_control_item.xml b/app/src/main/res/layout/view_control_item.xml index e14c2a180..cd8b3a81d 100644 --- a/app/src/main/res/layout/view_control_item.xml +++ b/app/src/main/res/layout/view_control_item.xml @@ -38,7 +38,6 @@ @@ -47,7 +46,6 @@ \ No newline at end of file diff --git a/app/src/main/res/layout/view_theme.xml b/app/src/main/res/layout/view_theme.xml new file mode 100644 index 000000000..1fe0c0120 --- /dev/null +++ b/app/src/main/res/layout/view_theme.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/nav_menu.xml b/app/src/main/res/menu/nav_menu.xml index ffa385015..aa467f79f 100644 --- a/app/src/main/res/menu/nav_menu.xml +++ b/app/src/main/res/menu/nav_menu.xml @@ -72,7 +72,7 @@ android:id="@+id/themes" android:checkable="false" android:icon="@drawable/themes" - android:title="@string/install" /> + android:title="@string/themes" /> 0) { - painter.color = when (minesAround) { - 1 -> areaPalette.minesAround1 - 2 -> areaPalette.minesAround2 - 3 -> areaPalette.minesAround3 - 4 -> areaPalette.minesAround4 - 5 -> areaPalette.minesAround5 - 6 -> areaPalette.minesAround6 - 7 -> areaPalette.minesAround7 - else -> areaPalette.minesAround8 + painter.apply { + color = when (minesAround) { + 1 -> appTheme.palette.minesAround1 + 2 -> appTheme.palette.minesAround2 + 3 -> appTheme.palette.minesAround3 + 4 -> appTheme.palette.minesAround4 + 5 -> appTheme.palette.minesAround5 + 6 -> appTheme.palette.minesAround6 + 7 -> appTheme.palette.minesAround7 + 8 -> appTheme.palette.minesAround8 + else -> 0x00 + } + alpha = 0xff } canvas.drawText(minesAround.toString(), paintSettings, painter) } @@ -134,7 +141,8 @@ fun Area.paintOnCanvas( style = Paint.Style.STROKE strokeWidth = highlightWidth isAntiAlias = !isLowBitAmbient - color = areaPalette.highlight + color = appTheme.palette.highlight + alpha = 0xff val rect = RectF( rectF.left + halfWidth, @@ -156,7 +164,8 @@ fun Area.paintOnCanvas( style = Paint.Style.STROKE strokeWidth = highlightWidth isAntiAlias = !isLowBitAmbient - color = areaPalette.focus + color = appTheme.palette.focus + alpha = 0xff } val rect = RectF( diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt index 9d739e8d7..5e7b3a2b3 100755 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt @@ -15,17 +15,17 @@ import androidx.core.view.ViewCompat import dev.lucasnlm.antimine.common.R import dev.lucasnlm.antimine.common.level.models.Area import dev.lucasnlm.antimine.common.level.models.AreaPaintSettings -import dev.lucasnlm.antimine.common.level.models.AreaPalette import dev.lucasnlm.antimine.common.level.models.Mark +import dev.lucasnlm.antimine.core.themes.model.AppTheme class AreaView : View { // Used on Wear OS - private var isAmbientMode = false - private var isLowBitAmbient = false + private var isAmbientMode: Boolean = false + private var isLowBitAmbient: Boolean = false private var area: Area? = null private lateinit var paintSettings: AreaPaintSettings - private lateinit var palette: AreaPalette + private lateinit var theme: AppTheme private val gestureDetector: GestureDetector by lazy { GestureDetector(context, GestureDetector.SimpleOnGestureListener()) @@ -45,7 +45,13 @@ class AreaView : View { gestureDetector.setOnDoubleTapListener(listener) } - fun bindField(area: Area, isAmbientMode: Boolean, isLowBitAmbient: Boolean, paintSettings: AreaPaintSettings) { + fun bindField( + area: Area, + theme: AppTheme, + isAmbientMode: Boolean, + isLowBitAmbient: Boolean, + paintSettings: AreaPaintSettings + ) { this.paintSettings = paintSettings bindContentDescription(area) @@ -57,15 +63,15 @@ class AreaView : View { ).firstOrNull { it } ?: false if (changed) { - this.palette = if (isAmbientMode) { - AreaPalette.fromContrast(context) - } else { - AreaPalette.fromDefault(context) - } +// this.palette = if (isAmbientMode) { +// AreaPalette.fromContrast(context) +// } else { +// AreaPalette.fromDefault(context) +// } this.isAmbientMode = isAmbientMode this.isLowBitAmbient = isLowBitAmbient - + this.theme = theme this.paintSettings.painter.isAntiAlias = !isAmbientMode || isAmbientMode && !isLowBitAmbient this.area = area.copy() @@ -130,7 +136,7 @@ class AreaView : View { isLowBitAmbient, isFocused, paintSettings, - palette + theme ) } diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt index f21c636e5..5131cff1f 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt @@ -24,6 +24,8 @@ import dev.lucasnlm.antimine.core.control.ActionResponse import dev.lucasnlm.antimine.core.control.GameControl import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository import dev.lucasnlm.antimine.core.sound.ISoundManager +import dev.lucasnlm.antimine.core.themes.model.AppTheme +import dev.lucasnlm.antimine.core.themes.repository.IThemeRepository import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview @@ -40,6 +42,7 @@ class GameViewModel @ViewModelInject constructor( private val dimensionRepository: IDimensionRepository, private val preferencesRepository: IPreferencesRepository, private val hapticFeedbackManager: IHapticFeedbackManager, + private val themeRepository: IThemeRepository, private val soundManager: ISoundManager, private val minefieldRepository: IMinefieldRepository, private val analyticsManager: IAnalyticsManager, @@ -420,6 +423,8 @@ class GameViewModel @ViewModelInject constructor( } } + fun getAppTheme(): AppTheme = themeRepository.getTheme() + private fun getAreaSizeMultiplier() = preferencesRepository.areaSizeMultiplier() private fun refreshIndex(targetIndex: Int, multipleChanges: Boolean = false) { diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/di/CommonModule.kt b/common/src/main/java/dev/lucasnlm/antimine/core/di/CommonModule.kt index 07fe8ba6d..aa17ee084 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/di/CommonModule.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/di/CommonModule.kt @@ -6,6 +6,8 @@ import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.components.ApplicationComponent import dagger.hilt.android.qualifiers.ApplicationContext +import dev.lucasnlm.antimine.common.level.repository.DimensionRepository +import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository import dev.lucasnlm.antimine.core.analytics.IAnalyticsManager import dev.lucasnlm.antimine.core.analytics.DebugAnalyticsManager import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository @@ -13,10 +15,19 @@ import dev.lucasnlm.antimine.core.preferences.PreferencesManager import dev.lucasnlm.antimine.core.preferences.PreferencesRepository import dev.lucasnlm.antimine.core.sound.ISoundManager import dev.lucasnlm.antimine.core.sound.SoundManager +import dev.lucasnlm.antimine.core.themes.repository.IThemeRepository +import dev.lucasnlm.antimine.core.themes.repository.ThemeRepository @Module @InstallIn(ApplicationComponent::class) class CommonModule { + @Provides + fun provideDimensionRepository( + @ApplicationContext context: Context, + preferencesRepository: IPreferencesRepository + ): IDimensionRepository = + DimensionRepository(context, preferencesRepository) + @Provides fun providePreferencesRepository( preferencesManager: PreferencesManager @@ -34,4 +45,10 @@ class CommonModule { fun provideSoundManager( @ApplicationContext context: Context ): ISoundManager = SoundManager(context) + + @Provides + fun provideThemeRepository( + @ApplicationContext context: Context, + preferencesRepository: IPreferencesRepository + ): IThemeRepository = ThemeRepository(context, preferencesRepository) } diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt index 7a13e0f58..c5de3bd98 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt @@ -15,6 +15,9 @@ interface IPreferencesRepository { fun controlStyle(): ControlStyle fun useControlStyle(controlStyle: ControlStyle) + fun themeId(): Long + fun useTheme(themeId: Long) + fun updateStatsBase(statsBase: Int) fun getStatsBase(): Int @@ -86,6 +89,13 @@ class PreferencesRepository( putInt(PREFERENCE_CONTROL_STYLE, controlStyle.ordinal) } + override fun themeId(): Long = + getInt(PREFERENCE_CUSTOM_THEME, 0).toLong() + + override fun useTheme(themeId: Long) { + putInt(PREFERENCE_CUSTOM_THEME, themeId.toInt()) + } + override fun updateStatsBase(statsBase: Int) { putInt(PREFERENCE_STATS_BASE, statsBase) } @@ -115,6 +125,7 @@ class PreferencesRepository( private const val PREFERENCE_AREA_SIZE = "preference_area_size" private const val PREFERENCE_QUESTION_MARK = "preference_use_question_mark" private const val PREFERENCE_CONTROL_STYLE = "preference_control_style" + private const val PREFERENCE_CUSTOM_THEME = "preference_custom_theme" private const val PREFERENCE_OLD_DOUBLE_CLICK = "preference_double_click_open" private const val PREFERENCE_CUSTOM_GAME_WIDTH = "preference_custom_game_width" private const val PREFERENCE_CUSTOM_GAME_HEIGHT = "preference_custom_game_height" diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/themes/model/AppTheme.kt b/common/src/main/java/dev/lucasnlm/antimine/core/themes/model/AppTheme.kt new file mode 100644 index 000000000..8be587e88 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/themes/model/AppTheme.kt @@ -0,0 +1,11 @@ +package dev.lucasnlm.antimine.core.themes.model + +import androidx.annotation.StyleRes +import dev.lucasnlm.antimine.common.level.models.AreaPalette + +data class AppTheme( + val id: Long, + @StyleRes val theme: Int, + @StyleRes val themeNoActionBar: Int, + val palette: AreaPalette +) diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt new file mode 100644 index 000000000..f74627894 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt @@ -0,0 +1,64 @@ +package dev.lucasnlm.antimine.core.themes.repository + +import android.content.Context +import androidx.core.content.ContextCompat +import dev.lucasnlm.antimine.common.R +import dev.lucasnlm.antimine.common.level.models.AreaPalette +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository +import dev.lucasnlm.antimine.core.themes.model.AppTheme +import dev.lucasnlm.antimine.core.themes.repository.Themes.DarkTheme +import dev.lucasnlm.antimine.core.themes.repository.Themes.LightTheme + +interface IThemeRepository { + fun getCustomTheme(): AppTheme? + fun getTheme(): AppTheme + fun getAllThemes(): List + fun setTheme(theme: AppTheme) +} + +class ThemeRepository( + private val context: Context, + private val preferenceRepository: IPreferencesRepository +): IThemeRepository { + override fun getCustomTheme(): AppTheme? { + return getAllThemes().firstOrNull { it.id == preferenceRepository.themeId() } + } + + override fun getTheme(): AppTheme { + return getCustomTheme() ?: buildSystemTheme() + } + + override fun getAllThemes(): List = listOf( + buildSystemTheme(), LightTheme, DarkTheme + ) + + override fun setTheme(theme: AppTheme) { + preferenceRepository.useTheme(theme.id) + } + + private fun buildSystemTheme(): AppTheme { + return AppTheme( + id = 0L, + theme = R.style.AppTheme, + themeNoActionBar = R.style.AppTheme_NoActionBar, + palette = fromDefaultPalette(context) + ) + } + + private fun fromDefaultPalette(context: Context) = + AreaPalette( + border = ContextCompat.getColor(context, R.color.view_cover), + covered = ContextCompat.getColor(context, R.color.view_cover), + uncovered = ContextCompat.getColor(context, R.color.view_clean), + minesAround1 = ContextCompat.getColor(context, R.color.mines_around_1), + minesAround2 = ContextCompat.getColor(context, R.color.mines_around_2), + minesAround3 = ContextCompat.getColor(context, R.color.mines_around_3), + minesAround4 = ContextCompat.getColor(context, R.color.mines_around_4), + minesAround5 = ContextCompat.getColor(context, R.color.mines_around_5), + minesAround6 = ContextCompat.getColor(context, R.color.mines_around_6), + minesAround7 = ContextCompat.getColor(context, R.color.mines_around_7), + minesAround8 = ContextCompat.getColor(context, R.color.mines_around_8), + highlight = ContextCompat.getColor(context, R.color.highlight), + focus = ContextCompat.getColor(context, R.color.accent) + ) +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/Themes.kt b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/Themes.kt new file mode 100644 index 000000000..716df1fca --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/Themes.kt @@ -0,0 +1,49 @@ +package dev.lucasnlm.antimine.core.themes.repository + +import dev.lucasnlm.antimine.common.R +import dev.lucasnlm.antimine.common.level.models.AreaPalette +import dev.lucasnlm.antimine.core.themes.model.AppTheme + +object Themes { + val LightTheme = AppTheme( + id = 1L, + theme = R.style.CustomLightTheme, + themeNoActionBar = R.style.CustomLightTheme_NoActionBar, + palette = AreaPalette( + border = 0x424242, + covered = 0x424242, + uncovered = 0xd5d2cc, + minesAround1 = 0x527F8D, + minesAround2 = 0x2B8D43, + minesAround3 = 0xE65100, + minesAround4 = 0x20A5f7, + minesAround5 = 0xED1C24, + minesAround6 = 0xFFC107, + minesAround7 = 0x66126B, + minesAround8 = 0x000000, + highlight = 0x212121, + focus = 0xD32F2F + ) + ) + + val DarkTheme = AppTheme( + id = 2L, + theme = R.style.CustomDarkTheme, + themeNoActionBar = R.style.CustomDarkTheme_NoActionBar, + palette = AreaPalette( + border = 0x171717, + covered = 0x171717, + uncovered = 0x424242, + minesAround1 = 0xd5d2cc, + minesAround2 = 0xd5d2cc, + minesAround3 = 0xd5d2cc, + minesAround4 = 0xd5d2cc, + minesAround5 = 0xd5d2cc, + minesAround6 = 0xd5d2cc, + minesAround7 = 0xd5d2cc, + minesAround8 = 0xd5d2cc, + highlight = 0xFFFFFF, + focus = 0xFFFFFF + ) + ) +} diff --git a/common/src/main/res/values-night/colors.xml b/common/src/main/res/values-night/colors.xml index 5028a198c..cd478325d 100644 --- a/common/src/main/res/values-night/colors.xml +++ b/common/src/main/res/values-night/colors.xml @@ -6,10 +6,6 @@ #212121 #212121 - #FFFFFF - #616161 - #616161 - #d5d2cc #d5d2cc #d5d2cc @@ -23,10 +19,8 @@ #FFFFFF #E65100 - #FFFFFF #FFFFFF #171717 #ff424242 - - \ No newline at end of file + diff --git a/common/src/main/res/values-v21/themes.xml b/common/src/main/res/values-v21/themes.xml index 95c584774..fe7b86f78 100644 --- a/common/src/main/res/values-v21/themes.xml +++ b/common/src/main/res/values-v21/themes.xml @@ -26,4 +26,45 @@ true true + + + + + + + + diff --git a/common/src/main/res/values/colors.xml b/common/src/main/res/values/colors.xml index dba49adbb..a4ff5ec84 100644 --- a/common/src/main/res/values/colors.xml +++ b/common/src/main/res/values/colors.xml @@ -6,10 +6,6 @@ #FFFFFF #9E9E9E - #4CAF50 - #455a64 - #F44336 - #527F8D #2B8D43 #E65100 @@ -21,12 +17,10 @@ #FCC216 - #D32F2F + #FFD32F2F #00C853 - #212121 #212121 #424242 #d5d2cc - - \ No newline at end of file + diff --git a/common/src/main/res/values/dimens.xml b/common/src/main/res/values/dimens.xml index be4f50262..68aa7527e 100644 --- a/common/src/main/res/values/dimens.xml +++ b/common/src/main/res/values/dimens.xml @@ -9,4 +9,6 @@ 5dp 2dp 18sp + + 5dp diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 6b17b8fee..e67faa8b1 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -88,6 +88,7 @@ Open Menu Close Menu Delete all + Themes Delete all events permanently. All mines were disabled. Covered area From b7b0d66d4cb946feb62e64c6ed018abeaef1d970 Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Fri, 7 Aug 2020 15:17:53 -0300 Subject: [PATCH 04/20] Remove old code --- .../common/level/models/AreaPalette.kt | 50 +------------------ .../antimine/common/level/view/AreaView.kt | 6 --- 2 files changed, 1 insertion(+), 55 deletions(-) diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt index fc4da41a4..ee8505034 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt @@ -1,10 +1,6 @@ package dev.lucasnlm.antimine.common.level.models -import android.content.Context -import android.graphics.Color import androidx.annotation.ColorInt -import androidx.core.content.ContextCompat -import dev.lucasnlm.antimine.common.R data class AreaPalette( @ColorInt val border: Int, @@ -20,48 +16,4 @@ data class AreaPalette( @ColorInt val minesAround8: Int, @ColorInt val highlight: Int, @ColorInt val focus: Int -) { - companion object { - private fun toArgb(color: Int): Int { - return Color.rgb( - Color.red(color), - Color.green(color), - Color.blue(color) - ) - } - - fun fromLightTheme() = - AreaPalette( - border = toArgb(0x424242), - covered = toArgb(0x424242), - uncovered = toArgb(0xd5d2cc), - minesAround1 = toArgb(0x527F8D), - minesAround2 = toArgb(0x2B8D43), - minesAround3 = toArgb(0xE65100), - minesAround4 = toArgb(0x20A5f7), - minesAround5 = toArgb(0xED1C24), - minesAround6 = toArgb(0xFFC107), - minesAround7 = toArgb(0x66126B), - minesAround8 = toArgb(0x000000), - highlight = toArgb(0x212121), - focus = toArgb(0xD32F2F) - ) - - fun fromContrast(context: Context) = - AreaPalette( - border = ContextCompat.getColor(context, android.R.color.white), - covered = ContextCompat.getColor(context, android.R.color.black), - uncovered = ContextCompat.getColor(context, android.R.color.black), - minesAround1 = ContextCompat.getColor(context, R.color.white), - minesAround2 = ContextCompat.getColor(context, R.color.white), - minesAround3 = ContextCompat.getColor(context, R.color.white), - minesAround4 = ContextCompat.getColor(context, R.color.white), - minesAround5 = ContextCompat.getColor(context, R.color.white), - minesAround6 = ContextCompat.getColor(context, R.color.white), - minesAround7 = ContextCompat.getColor(context, R.color.white), - minesAround8 = ContextCompat.getColor(context, R.color.white), - highlight = ContextCompat.getColor(context, R.color.white), - focus = ContextCompat.getColor(context, R.color.white) - ) - } -} +) diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt index 5e7b3a2b3..20f96f778 100755 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt @@ -63,12 +63,6 @@ class AreaView : View { ).firstOrNull { it } ?: false if (changed) { -// this.palette = if (isAmbientMode) { -// AreaPalette.fromContrast(context) -// } else { -// AreaPalette.fromDefault(context) -// } - this.isAmbientMode = isAmbientMode this.isLowBitAmbient = isLowBitAmbient this.theme = theme From 3c7f50d079b61de6ea5e88c3bab3b0dab9f0daea Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Fri, 7 Aug 2020 15:18:03 -0300 Subject: [PATCH 05/20] Revert gradle change --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 015a76b52..be3dd2a4e 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.2.0-alpha07' + classpath 'com.android.tools.build:gradle:4.0.0' classpath 'com.google.dagger:hilt-android-gradle-plugin:2.28.1-alpha' classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72' } From be20ad917297ff43b793628643417f0cd7a59f7b Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Fri, 7 Aug 2020 15:22:18 -0300 Subject: [PATCH 06/20] Rename AppTheme to Theme --- .../lucasnlm/antimine/share/ShareBuilder.kt | 2 +- .../antimine/theme/view/ThemeAdapter.kt | 6 ++-- .../theme/viewmodel/ThemeViewModel.kt | 6 ++-- .../view/common/level/view/AreaScreenshot.kt | 2 +- .../antimine/common/level/view/AreaPainter.kt | 30 +++++++++---------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt b/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt index 4daa6f01f..e1e1c647f 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt @@ -72,7 +72,7 @@ class ShareBuilder( area.paintOnCanvas( context, canvas, - appTheme = DarkTheme, + theme = DarkTheme, isAmbientMode = false, isLowBitAmbient = false, isFocused = false, diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt index 8a580d092..cb0992f14 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt @@ -64,10 +64,10 @@ class ThemeAdapter( } } - private fun AreaView.bindTheme(area: Area, appTheme: AppTheme, paintSettings: AreaPaintSettings) { + private fun AreaView.bindTheme(area: Area, theme: AppTheme, paintSettings: AreaPaintSettings) { bindField( - area, - appTheme, + area = area, + theme = theme, isAmbientMode = false, isLowBitAmbient = false, paintSettings = paintSettings diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt index 1ff7a3817..aa39c067f 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt @@ -13,9 +13,9 @@ class ThemeViewModel @ViewModelInject constructor( fun getThemes(): List = themeRepository.getAllThemes() - fun setTheme(appTheme: AppTheme) { - themeRepository.setTheme(appTheme) - theme.postValue(appTheme) + fun setTheme(theme: AppTheme) { + themeRepository.setTheme(theme) + this.theme.postValue(theme) } } diff --git a/common/src/androidTest/java/dev/lucasnlm/antimine/view/common/level/view/AreaScreenshot.kt b/common/src/androidTest/java/dev/lucasnlm/antimine/view/common/level/view/AreaScreenshot.kt index ede21cf33..053012d81 100644 --- a/common/src/androidTest/java/dev/lucasnlm/antimine/view/common/level/view/AreaScreenshot.kt +++ b/common/src/androidTest/java/dev/lucasnlm/antimine/view/common/level/view/AreaScreenshot.kt @@ -48,7 +48,7 @@ class AreaScreenshot { isLowBitAmbient = false, isFocused = false, paintSettings = paintSettings, - appTheme = LightTheme + theme = LightTheme ) canvas.restore() diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPainter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPainter.kt index b7a6353fd..74d4fd21a 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPainter.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPainter.kt @@ -19,7 +19,7 @@ fun Area.paintOnCanvas( isLowBitAmbient: Boolean, isFocused: Boolean, paintSettings: AreaPaintSettings, - appTheme: AppTheme, + theme: AppTheme, markPadding: Int? = null, minePadding: Int? = null ) { @@ -30,14 +30,14 @@ fun Area.paintOnCanvas( style = Paint.Style.STROKE strokeWidth = 2.0f isAntiAlias = !isLowBitAmbient - color = appTheme.palette.border + color = theme.palette.border alpha = 0xff } } else { painter.apply { style = Paint.Style.FILL isAntiAlias = !isLowBitAmbient - color = appTheme.palette.covered + color = theme.palette.covered alpha = if (highlighted) 155 else 255 } } @@ -83,14 +83,14 @@ fun Area.paintOnCanvas( style = Paint.Style.STROKE strokeWidth = 0.5f isAntiAlias = !isLowBitAmbient - color = appTheme.palette.border + color = theme.palette.border alpha = 0xff } } else { painter.apply { style = Paint.Style.FILL isAntiAlias = !isLowBitAmbient - color = appTheme.palette.uncovered + color = theme.palette.uncovered alpha = 0xff } } @@ -118,14 +118,14 @@ fun Area.paintOnCanvas( } else if (minesAround > 0) { painter.apply { color = when (minesAround) { - 1 -> appTheme.palette.minesAround1 - 2 -> appTheme.palette.minesAround2 - 3 -> appTheme.palette.minesAround3 - 4 -> appTheme.palette.minesAround4 - 5 -> appTheme.palette.minesAround5 - 6 -> appTheme.palette.minesAround6 - 7 -> appTheme.palette.minesAround7 - 8 -> appTheme.palette.minesAround8 + 1 -> theme.palette.minesAround1 + 2 -> theme.palette.minesAround2 + 3 -> theme.palette.minesAround3 + 4 -> theme.palette.minesAround4 + 5 -> theme.palette.minesAround5 + 6 -> theme.palette.minesAround6 + 7 -> theme.palette.minesAround7 + 8 -> theme.palette.minesAround8 else -> 0x00 } alpha = 0xff @@ -141,7 +141,7 @@ fun Area.paintOnCanvas( style = Paint.Style.STROKE strokeWidth = highlightWidth isAntiAlias = !isLowBitAmbient - color = appTheme.palette.highlight + color = theme.palette.highlight alpha = 0xff val rect = RectF( @@ -164,7 +164,7 @@ fun Area.paintOnCanvas( style = Paint.Style.STROKE strokeWidth = highlightWidth isAntiAlias = !isLowBitAmbient - color = appTheme.palette.focus + color = theme.palette.focus alpha = 0xff } From 462b6846b7a7ab73803a07ec7fd37cb0caad7d2b Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Fri, 7 Aug 2020 15:24:11 -0300 Subject: [PATCH 07/20] Fix ktlint --- .../java/dev/lucasnlm/antimine/ThematicActivity.kt | 1 - .../lucasnlm/antimine/history/views/HistoryAdapter.kt | 2 -- .../java/dev/lucasnlm/antimine/share/ShareBuilder.kt | 7 ++++++- .../java/dev/lucasnlm/antimine/text/TextActivity.kt | 1 - .../java/dev/lucasnlm/antimine/theme/ThemeActivity.kt | 11 +++++++---- .../antimine/theme/viewmodel/ThemeViewModel.kt | 1 - .../lucasnlm/antimine/common/level/di/LevelModule.kt | 3 --- .../antimine/common/level/view/AreaAdapter.kt | 1 - .../core/themes/repository/ThemeRepository.kt | 2 +- 9 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt index 17c1fde23..29391bcc8 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt @@ -3,7 +3,6 @@ package dev.lucasnlm.antimine import android.os.Bundle import androidx.annotation.LayoutRes import androidx.appcompat.app.AppCompatActivity -import dagger.hilt.android.AndroidEntryPoint import dev.lucasnlm.antimine.core.themes.repository.IThemeRepository import javax.inject.Inject diff --git a/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryAdapter.kt b/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryAdapter.kt index 7a831e3db..c9f28f12e 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryAdapter.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryAdapter.kt @@ -1,14 +1,12 @@ package dev.lucasnlm.antimine.history.views import android.content.Intent -import android.graphics.PorterDuff import android.net.Uri import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.appcompat.widget.AppCompatImageView -import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import dev.lucasnlm.antimine.DeepLink import dev.lucasnlm.antimine.R diff --git a/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt b/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt index e1e1c647f..d447a38e8 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt @@ -3,7 +3,12 @@ package dev.lucasnlm.antimine.share import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent -import android.graphics.* +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Paint +import android.graphics.RectF +import android.graphics.Typeface import androidx.core.content.FileProvider import dev.lucasnlm.antimine.BuildConfig import dev.lucasnlm.antimine.R diff --git a/app/src/main/java/dev/lucasnlm/antimine/text/TextActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/text/TextActivity.kt index 2edfd62eb..466419046 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/text/TextActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/text/TextActivity.kt @@ -3,7 +3,6 @@ package dev.lucasnlm.antimine.text import android.content.Context import android.content.Intent import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity import android.view.View import androidx.activity.viewModels import androidx.annotation.RawRes diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt index cc21af778..53212d759 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt @@ -35,11 +35,14 @@ class ThemeActivity : ThematicActivity(R.layout.activity_theme) { adapter = ThemeAdapter(viewModel, areaSize) } - viewModel.theme.observe(this@ThemeActivity, Observer { - if (usingThemeId != it.id) { - recreate() + viewModel.theme.observe( + this@ThemeActivity, + Observer { + if (usingThemeId != it.id) { + recreate() + } } - }) + ) } } } diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt index aa39c067f..ebc1ac034 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt @@ -18,4 +18,3 @@ class ThemeViewModel @ViewModelInject constructor( this.theme.postValue(theme) } } - diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/di/LevelModule.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/di/LevelModule.kt index cd58a04ac..2df4ba1fa 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/di/LevelModule.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/di/LevelModule.kt @@ -10,8 +10,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext import dev.lucasnlm.antimine.common.level.database.AppDataBase import dev.lucasnlm.antimine.common.level.database.dao.SaveDao import dev.lucasnlm.antimine.common.level.database.dao.StatsDao -import dev.lucasnlm.antimine.common.level.repository.DimensionRepository -import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository import dev.lucasnlm.antimine.common.level.repository.IMinefieldRepository import dev.lucasnlm.antimine.common.level.repository.ISavesRepository import dev.lucasnlm.antimine.common.level.repository.IStatsRepository @@ -21,7 +19,6 @@ import dev.lucasnlm.antimine.common.level.repository.StatsRepository import dev.lucasnlm.antimine.common.level.utils.Clock import dev.lucasnlm.antimine.common.level.utils.HapticFeedbackManager import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackManager -import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository @Module @InstallIn(ActivityComponent::class) diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt index 8bbdd37a2..2e82cad94 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt @@ -17,7 +17,6 @@ import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel import dev.lucasnlm.antimine.core.control.ControlStyle import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository -import dev.lucasnlm.antimine.core.themes.repository.IThemeRepository import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.GlobalScope diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt index f74627894..8692aefe1 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt @@ -19,7 +19,7 @@ interface IThemeRepository { class ThemeRepository( private val context: Context, private val preferenceRepository: IPreferencesRepository -): IThemeRepository { +) : IThemeRepository { override fun getCustomTheme(): AppTheme? { return getAllThemes().firstOrNull { it.id == preferenceRepository.themeId() } } From db7388db86ed34e38c3665aad45b9ba192d17b85 Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Fri, 7 Aug 2020 15:26:33 -0300 Subject: [PATCH 08/20] Bump version --- app/build.gradle | 4 ++-- common/build.gradle | 4 ++-- foss/build.gradle | 4 ++-- proprietary/build.gradle | 4 ++-- wear/build.gradle | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e5f3c8676..e3be7a71e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { defaultConfig { // versionCode and versionName must be hardcoded to support F-droid - versionCode 703031 - versionName '7.3.3' + versionCode 800001 + versionName '8.0.0' minSdkVersion 16 targetSdkVersion 30 multiDexEnabled true diff --git a/common/build.gradle b/common/build.gradle index 8a96fc65e..f5734f252 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -9,8 +9,8 @@ android { defaultConfig { // versionCode and versionName must be hardcoded to support F-droid - versionCode 703031 - versionName '7.3.3' + versionCode 800001 + versionName '8.0.0' minSdkVersion 16 targetSdkVersion 30 testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' diff --git a/foss/build.gradle b/foss/build.gradle index 9aa410d9a..0df7d0077 100644 --- a/foss/build.gradle +++ b/foss/build.gradle @@ -6,8 +6,8 @@ android { compileSdkVersion 30 defaultConfig { - versionCode 703031 // MMmmPPv - versionName '7.3.3' + versionCode 800001 // MMmmPPv + versionName '8.0.0' minSdkVersion 16 targetSdkVersion 30 } diff --git a/proprietary/build.gradle b/proprietary/build.gradle index d1f27607b..4a9157eea 100644 --- a/proprietary/build.gradle +++ b/proprietary/build.gradle @@ -6,8 +6,8 @@ android { compileSdkVersion 30 defaultConfig { - versionCode 703031 // MMmmPPv - versionName '7.3.3' + versionCode 800001 // MMmmPPv + versionName '8.0.0' minSdkVersion 16 targetSdkVersion 30 } diff --git a/wear/build.gradle b/wear/build.gradle index a4af75531..416ff1d10 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -9,8 +9,8 @@ android { defaultConfig { // versionCode and versionName must be hardcoded to support F-droid - versionCode 703031 - versionName '7.3.3' + versionCode 800001 + versionName '8.0.0' applicationId 'dev.lucasnlm.antimine' minSdkVersion 23 targetSdkVersion 30 From 10de9f9f32e9226ee59f240da04a7b0f6d73ce06 Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Sat, 8 Aug 2020 15:16:00 -0300 Subject: [PATCH 09/20] Add Theme example to adapter --- .../dev/lucasnlm/antimine/GameActivity.kt | 3 +++ .../dev/lucasnlm/antimine/ThematicActivity.kt | 9 ++++--- .../lucasnlm/antimine/theme/ThemeActivity.kt | 2 +- .../antimine/theme/view/ThemeAdapter.kt | 26 ++++++++++++------- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt index febe78133..885a92903 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt @@ -3,6 +3,9 @@ package dev.lucasnlm.antimine import android.content.ActivityNotFoundException import android.content.DialogInterface import android.content.Intent +import android.graphics.BlendModeColorFilter +import android.graphics.ColorFilter +import android.graphics.PorterDuff import android.net.Uri import android.os.Bundle import android.os.Handler diff --git a/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt index 29391bcc8..0726db77a 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt @@ -3,6 +3,7 @@ package dev.lucasnlm.antimine import android.os.Bundle import androidx.annotation.LayoutRes import androidx.appcompat.app.AppCompatActivity +import dev.lucasnlm.antimine.core.themes.model.AppTheme import dev.lucasnlm.antimine.core.themes.repository.IThemeRepository import javax.inject.Inject @@ -15,11 +16,11 @@ open class ThematicActivity : AppCompatActivity { protected open val noActionBar: Boolean = false - protected val usingThemeId: Long by lazy { - currentThemeId() + protected val usingTheme: AppTheme by lazy { + currentTheme() } - private fun currentThemeId(): Long = themeRepository.getTheme().id + private fun currentTheme() = themeRepository.getTheme() override fun onCreate(savedInstanceState: Bundle?) { themeRepository.getCustomTheme()?.let { @@ -35,7 +36,7 @@ open class ThematicActivity : AppCompatActivity { override fun onResume() { super.onResume() - if (usingThemeId != currentThemeId()) { + if (usingTheme.id != currentTheme().id) { recreate() } } diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt index 53212d759..c08930928 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt @@ -38,7 +38,7 @@ class ThemeActivity : ThematicActivity(R.layout.activity_theme) { viewModel.theme.observe( this@ThemeActivity, Observer { - if (usingThemeId != it.id) { + if (usingTheme.id != it.id) { recreate() } } diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt index cb0992f14..fe2fdcc70 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt @@ -25,7 +25,15 @@ class ThemeAdapter( private val themes: List = themeViewModel.getThemes() private val minefield = listOf( - Area(0, 0, 0, 1, hasMine = false, mistake = false, mark = Mark.None, isCovered = false) + Area(0, 0, 0, 1, hasMine = false, mistake = false, mark = Mark.None, isCovered = false), + Area(1, 1, 0, 0, hasMine = true, mistake = false, mark = Mark.None, isCovered = false), + Area(2, 2, 0, 0, hasMine = true, mistake = false, mark = Mark.None, isCovered = true), + Area(3, 0, 1, 2, hasMine = false, mistake = false, mark = Mark.None, isCovered = false), + Area(4, 1, 1, 3, hasMine = false, mistake = false, mark = Mark.None, isCovered = false), + Area(5, 2, 1, 3, hasMine = true, mistake = false, mark = Mark.Flag, isCovered = true), + Area(6, 0, 2, 0, hasMine = true, mistake = false, mark = Mark.Question, isCovered = true), + Area(7, 1, 2, 0, hasMine = false, mistake = false, mark = Mark.None, isCovered = true), + Area(8, 2, 2, 0, hasMine = false, mistake = false, mark = Mark.None, isCovered = true) ) init { @@ -49,14 +57,14 @@ class ThemeAdapter( val paintSettings = createAreaPaintSettings(holder.itemView.context, areaSize) holder.itemView.run { area0.bindTheme(minefield[0], theme, paintSettings) - area1.bindTheme(minefield[0], theme, paintSettings) - area2.bindTheme(minefield[0], theme, paintSettings) - area3.bindTheme(minefield[0], theme, paintSettings) - area4.bindTheme(minefield[0], theme, paintSettings) - area5.bindTheme(minefield[0], theme, paintSettings) - area6.bindTheme(minefield[0], theme, paintSettings) - area7.bindTheme(minefield[0], theme, paintSettings) - area8.bindTheme(minefield[0], theme, paintSettings) + area1.bindTheme(minefield[1], theme, paintSettings) + area2.bindTheme(minefield[2], theme, paintSettings) + area3.bindTheme(minefield[3], theme, paintSettings) + area4.bindTheme(minefield[4], theme, paintSettings) + area5.bindTheme(minefield[5], theme, paintSettings) + area6.bindTheme(minefield[6], theme, paintSettings) + area7.bindTheme(minefield[7], theme, paintSettings) + area8.bindTheme(minefield[8], theme, paintSettings) clickTheme.setOnClickListener { themeViewModel.setTheme(theme) From eb9cc87f2af18caae92efa1be5aa91254a525dc6 Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Sat, 8 Aug 2020 15:40:11 -0300 Subject: [PATCH 10/20] Fix background color --- .../antimine/theme/view/ThemeAdapter.kt | 19 +++++++++---------- app/src/main/res/layout/view_theme.xml | 1 + .../common/level/models/AreaPalette.kt | 1 + .../core/themes/repository/ThemeRepository.kt | 1 + .../antimine/core/themes/repository/Themes.kt | 2 ++ common/src/main/res/values-night/colors.xml | 2 +- common/src/main/res/values-v21/themes.xml | 2 +- common/src/main/res/values/colors.xml | 2 +- 8 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt index fe2fdcc70..024bea21d 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt @@ -1,6 +1,7 @@ package dev.lucasnlm.antimine.theme.view import android.content.Context +import android.graphics.Color import android.graphics.Paint import android.graphics.RectF import android.graphics.Typeface @@ -32,7 +33,7 @@ class ThemeAdapter( Area(4, 1, 1, 3, hasMine = false, mistake = false, mark = Mark.None, isCovered = false), Area(5, 2, 1, 3, hasMine = true, mistake = false, mark = Mark.Flag, isCovered = true), Area(6, 0, 2, 0, hasMine = true, mistake = false, mark = Mark.Question, isCovered = true), - Area(7, 1, 2, 0, hasMine = false, mistake = false, mark = Mark.None, isCovered = true), + Area(7, 1, 2, 4, hasMine = false, mistake = false, mark = Mark.None, isCovered = false), Area(8, 2, 2, 0, hasMine = false, mistake = false, mark = Mark.None, isCovered = true) ) @@ -56,15 +57,13 @@ class ThemeAdapter( val theme = themes[position] val paintSettings = createAreaPaintSettings(holder.itemView.context, areaSize) holder.itemView.run { - area0.bindTheme(minefield[0], theme, paintSettings) - area1.bindTheme(minefield[1], theme, paintSettings) - area2.bindTheme(minefield[2], theme, paintSettings) - area3.bindTheme(minefield[3], theme, paintSettings) - area4.bindTheme(minefield[4], theme, paintSettings) - area5.bindTheme(minefield[5], theme, paintSettings) - area6.bindTheme(minefield[6], theme, paintSettings) - area7.bindTheme(minefield[7], theme, paintSettings) - area8.bindTheme(minefield[8], theme, paintSettings) + arrayOf(area0, area1, area2, area3, area4, area5, area6, area7, area8) + .forEachIndexed { index, areaView -> areaView.bindTheme(minefield[index], theme, paintSettings) } + + val color = with (theme.palette.background) { + Color.rgb(Color.red(this), Color.green(this), Color.blue(this)) + } + parentGrid.setBackgroundColor(color) clickTheme.setOnClickListener { themeViewModel.setTheme(theme) diff --git a/app/src/main/res/layout/view_theme.xml b/app/src/main/res/layout/view_theme.xml index 1fe0c0120..40004c653 100644 --- a/app/src/main/res/layout/view_theme.xml +++ b/app/src/main/res/layout/view_theme.xml @@ -11,6 +11,7 @@ android:layout_height="match_parent" android:layout_gravity="center" android:columnCount="3" + android:background="#FFFF0000" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt index ee8505034..2cff21e40 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt @@ -4,6 +4,7 @@ import androidx.annotation.ColorInt data class AreaPalette( @ColorInt val border: Int, + @ColorInt val background: Int, @ColorInt val covered: Int, @ColorInt val uncovered: Int, @ColorInt val minesAround1: Int, diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt index 8692aefe1..d56640390 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt @@ -48,6 +48,7 @@ class ThemeRepository( private fun fromDefaultPalette(context: Context) = AreaPalette( border = ContextCompat.getColor(context, R.color.view_cover), + background = ContextCompat.getColor(context, R.color.background), covered = ContextCompat.getColor(context, R.color.view_cover), uncovered = ContextCompat.getColor(context, R.color.view_clean), minesAround1 = ContextCompat.getColor(context, R.color.mines_around_1), diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/Themes.kt b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/Themes.kt index 716df1fca..9c2344f37 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/Themes.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/Themes.kt @@ -11,6 +11,7 @@ object Themes { themeNoActionBar = R.style.CustomLightTheme_NoActionBar, palette = AreaPalette( border = 0x424242, + background = 0xFFFFFF, covered = 0x424242, uncovered = 0xd5d2cc, minesAround1 = 0x527F8D, @@ -32,6 +33,7 @@ object Themes { themeNoActionBar = R.style.CustomDarkTheme_NoActionBar, palette = AreaPalette( border = 0x171717, + background = 0x212121, covered = 0x171717, uncovered = 0x424242, minesAround1 = 0xd5d2cc, diff --git a/common/src/main/res/values-night/colors.xml b/common/src/main/res/values-night/colors.xml index cd478325d..e3fc6fd3c 100644 --- a/common/src/main/res/values-night/colors.xml +++ b/common/src/main/res/values-night/colors.xml @@ -1,10 +1,10 @@ - #546E7A #FFFFFF #212121 #212121 + #212121 #d5d2cc #d5d2cc diff --git a/common/src/main/res/values-v21/themes.xml b/common/src/main/res/values-v21/themes.xml index fe7b86f78..1d9da2174 100644 --- a/common/src/main/res/values-v21/themes.xml +++ b/common/src/main/res/values-v21/themes.xml @@ -4,7 +4,7 @@ @color/primary @color/primary_dark @color/accent - @color/primary + @color/background true diff --git a/common/src/main/res/values/colors.xml b/common/src/main/res/values/colors.xml index a4ff5ec84..d6a99b845 100644 --- a/common/src/main/res/values/colors.xml +++ b/common/src/main/res/values/colors.xml @@ -1,10 +1,10 @@ - #000000 #FFFFFF #FFFFFF #9E9E9E + #FFFFFF #527F8D #2B8D43 From dcfea4569598721e89a231de45fb856ff604c66f Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Sun, 9 Aug 2020 20:47:13 -0300 Subject: [PATCH 11/20] Fix ktlint --- app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt | 3 --- .../main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt index 885a92903..febe78133 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt @@ -3,9 +3,6 @@ package dev.lucasnlm.antimine import android.content.ActivityNotFoundException import android.content.DialogInterface import android.content.Intent -import android.graphics.BlendModeColorFilter -import android.graphics.ColorFilter -import android.graphics.PorterDuff import android.net.Uri import android.os.Bundle import android.os.Handler diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt index 024bea21d..93ccfe6c7 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt @@ -60,7 +60,7 @@ class ThemeAdapter( arrayOf(area0, area1, area2, area3, area4, area5, area6, area7, area8) .forEachIndexed { index, areaView -> areaView.bindTheme(minefield[index], theme, paintSettings) } - val color = with (theme.palette.background) { + val color = with(theme.palette.background) { Color.rgb(Color.red(this), Color.green(this), Color.blue(this)) } parentGrid.setBackgroundColor(color) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8655ec783..1b903c1c9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https://services.gradle.org/distributions/gradle-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionSha256Sum=9d94e6e4a28ad328072ef6e56bce79a810494ae756751fdcedffdeaf27c093b1 From 2eb245523030b8b42cfec100abe47b655ed91d71 Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Sun, 9 Aug 2020 21:12:51 -0300 Subject: [PATCH 12/20] Add assets --- .../antimine/common/level/view/AreaPainter.kt | 12 ++++++------ .../antimine/core/themes/model/AppTheme.kt | 2 +- .../themes/model}/AreaPalette.kt | 2 +- .../antimine/core/themes/model/Assets.kt | 12 ++++++++++++ .../core/themes/repository/ThemeRepository.kt | 16 ++++++++++++++-- .../antimine/core/themes/repository/Themes.kt | 19 ++++++++++++++++++- .../main/res/drawable/mine_exploded_red.xml | 14 ++++++++++++++ .../main/res/drawable/mine_exploded_white.xml | 14 ++++++++++++++ 8 files changed, 80 insertions(+), 11 deletions(-) rename common/src/main/java/dev/lucasnlm/antimine/{common/level/models => core/themes/model}/AreaPalette.kt (91%) create mode 100644 common/src/main/java/dev/lucasnlm/antimine/core/themes/model/Assets.kt create mode 100644 common/src/main/res/drawable/mine_exploded_red.xml create mode 100644 common/src/main/res/drawable/mine_exploded_white.xml diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPainter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPainter.kt index 74d4fd21a..490425a9d 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPainter.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPainter.kt @@ -51,9 +51,9 @@ fun Area.paintOnCanvas( val padding = markPadding ?: context.resources.getDimension(R.dimen.mark_padding).toInt() val flag = if (mistake) { - ContextCompat.getDrawable(context, R.drawable.red_flag) + ContextCompat.getDrawable(context, theme.assets.wrongFlag) } else { - ContextCompat.getDrawable(context, R.drawable.flag) + ContextCompat.getDrawable(context, theme.assets.flag) } flag?.setBounds( @@ -65,7 +65,7 @@ fun Area.paintOnCanvas( flag?.draw(canvas) } Mark.Question -> { - val question = ContextCompat.getDrawable(context, R.drawable.question) + val question = ContextCompat.getDrawable(context, theme.assets.questionMark) question?.setBounds( rectF.left.toInt(), @@ -103,9 +103,9 @@ fun Area.paintOnCanvas( val padding = minePadding ?: context.resources.getDimension(R.dimen.mine_padding).toInt() val mine = when { - isAmbientMode -> ContextCompat.getDrawable(context, R.drawable.mine_low) - mistake -> ContextCompat.getDrawable(context, R.drawable.mine_exploded) - else -> ContextCompat.getDrawable(context, R.drawable.mine) + isAmbientMode -> ContextCompat.getDrawable(context, theme.assets.mineLow) + mistake -> ContextCompat.getDrawable(context, theme.assets.mineExploded) + else -> ContextCompat.getDrawable(context, theme.assets.mine) } mine?.setBounds( diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/themes/model/AppTheme.kt b/common/src/main/java/dev/lucasnlm/antimine/core/themes/model/AppTheme.kt index 8be587e88..1dee65ad7 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/themes/model/AppTheme.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/themes/model/AppTheme.kt @@ -1,11 +1,11 @@ package dev.lucasnlm.antimine.core.themes.model import androidx.annotation.StyleRes -import dev.lucasnlm.antimine.common.level.models.AreaPalette data class AppTheme( val id: Long, @StyleRes val theme: Int, @StyleRes val themeNoActionBar: Int, + val assets: Assets, val palette: AreaPalette ) diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt b/common/src/main/java/dev/lucasnlm/antimine/core/themes/model/AreaPalette.kt similarity index 91% rename from common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt rename to common/src/main/java/dev/lucasnlm/antimine/core/themes/model/AreaPalette.kt index 2cff21e40..be7e89ce5 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/themes/model/AreaPalette.kt @@ -1,4 +1,4 @@ -package dev.lucasnlm.antimine.common.level.models +package dev.lucasnlm.antimine.core.themes.model import androidx.annotation.ColorInt diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/themes/model/Assets.kt b/common/src/main/java/dev/lucasnlm/antimine/core/themes/model/Assets.kt new file mode 100644 index 000000000..dde40f329 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/themes/model/Assets.kt @@ -0,0 +1,12 @@ +package dev.lucasnlm.antimine.core.themes.model + +import androidx.annotation.DrawableRes + +data class Assets( + @DrawableRes val wrongFlag: Int, + @DrawableRes val flag: Int, + @DrawableRes val questionMark: Int, + @DrawableRes val mine: Int, + @DrawableRes val mineExploded: Int, + @DrawableRes val mineLow: Int +) diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt index d56640390..4f3b6b66e 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt @@ -3,9 +3,10 @@ package dev.lucasnlm.antimine.core.themes.repository import android.content.Context import androidx.core.content.ContextCompat import dev.lucasnlm.antimine.common.R -import dev.lucasnlm.antimine.common.level.models.AreaPalette +import dev.lucasnlm.antimine.core.themes.model.AreaPalette import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository import dev.lucasnlm.antimine.core.themes.model.AppTheme +import dev.lucasnlm.antimine.core.themes.model.Assets import dev.lucasnlm.antimine.core.themes.repository.Themes.DarkTheme import dev.lucasnlm.antimine.core.themes.repository.Themes.LightTheme @@ -41,10 +42,21 @@ class ThemeRepository( id = 0L, theme = R.style.AppTheme, themeNoActionBar = R.style.AppTheme_NoActionBar, - palette = fromDefaultPalette(context) + palette = fromDefaultPalette(context), + assets = fromDefaultAssets() ) } + private fun fromDefaultAssets() = + Assets( + wrongFlag = R.drawable.red_flag, + flag = R.drawable.flag, + questionMark = R.drawable.question, + mine = R.drawable.mine, + mineExploded = R.drawable.mine_exploded_red, + mineLow = R.drawable.mine_low + ) + private fun fromDefaultPalette(context: Context) = AreaPalette( border = ContextCompat.getColor(context, R.color.view_cover), diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/Themes.kt b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/Themes.kt index 9c2344f37..e89c1b942 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/Themes.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/Themes.kt @@ -1,8 +1,9 @@ package dev.lucasnlm.antimine.core.themes.repository import dev.lucasnlm.antimine.common.R -import dev.lucasnlm.antimine.common.level.models.AreaPalette +import dev.lucasnlm.antimine.core.themes.model.AreaPalette import dev.lucasnlm.antimine.core.themes.model.AppTheme +import dev.lucasnlm.antimine.core.themes.model.Assets object Themes { val LightTheme = AppTheme( @@ -24,6 +25,14 @@ object Themes { minesAround8 = 0x000000, highlight = 0x212121, focus = 0xD32F2F + ), + assets = Assets( + wrongFlag = R.drawable.red_flag, + flag = R.drawable.flag, + questionMark = R.drawable.question, + mine = R.drawable.mine, + mineExploded = R.drawable.mine_exploded_red, + mineLow = R.drawable.mine_low ) ) @@ -46,6 +55,14 @@ object Themes { minesAround8 = 0xd5d2cc, highlight = 0xFFFFFF, focus = 0xFFFFFF + ), + assets = Assets( + wrongFlag = R.drawable.flag, + flag = R.drawable.flag, + questionMark = R.drawable.question, + mine = R.drawable.mine, + mineExploded = R.drawable.mine_exploded_white, + mineLow = R.drawable.mine_low ) ) } diff --git a/common/src/main/res/drawable/mine_exploded_red.xml b/common/src/main/res/drawable/mine_exploded_red.xml new file mode 100644 index 000000000..3637dc923 --- /dev/null +++ b/common/src/main/res/drawable/mine_exploded_red.xml @@ -0,0 +1,14 @@ + + + + diff --git a/common/src/main/res/drawable/mine_exploded_white.xml b/common/src/main/res/drawable/mine_exploded_white.xml new file mode 100644 index 000000000..652db7369 --- /dev/null +++ b/common/src/main/res/drawable/mine_exploded_white.xml @@ -0,0 +1,14 @@ + + + + From d2dcfa480b989b97f2fb6231220674f361c08c86 Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Sun, 9 Aug 2020 21:17:58 -0300 Subject: [PATCH 13/20] Update menu --- app/src/main/res/drawable/control.xml | 10 ---------- app/src/main/res/drawable/controls.xml | 5 +++++ app/src/main/res/menu/nav_menu.xml | 22 ++++++++-------------- 3 files changed, 13 insertions(+), 24 deletions(-) delete mode 100644 app/src/main/res/drawable/control.xml create mode 100644 app/src/main/res/drawable/controls.xml diff --git a/app/src/main/res/drawable/control.xml b/app/src/main/res/drawable/control.xml deleted file mode 100644 index ee0e0f8b4..000000000 --- a/app/src/main/res/drawable/control.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/controls.xml b/app/src/main/res/drawable/controls.xml new file mode 100644 index 000000000..f5cb8f0f8 --- /dev/null +++ b/app/src/main/res/drawable/controls.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/menu/nav_menu.xml b/app/src/main/res/menu/nav_menu.xml index aa467f79f..50658640b 100644 --- a/app/src/main/res/menu/nav_menu.xml +++ b/app/src/main/res/menu/nav_menu.xml @@ -55,24 +55,20 @@ - - - - - + + - + - - Date: Sun, 9 Aug 2020 21:27:51 -0300 Subject: [PATCH 14/20] Fix test --- app/src/test/java/dev/lucasnlm/antimine/di/TestLevelModule.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/test/java/dev/lucasnlm/antimine/di/TestLevelModule.kt b/app/src/test/java/dev/lucasnlm/antimine/di/TestLevelModule.kt index d4c37b66e..09203432f 100644 --- a/app/src/test/java/dev/lucasnlm/antimine/di/TestLevelModule.kt +++ b/app/src/test/java/dev/lucasnlm/antimine/di/TestLevelModule.kt @@ -27,9 +27,6 @@ class TestLevelModule { @Provides fun provideClock(): Clock = Clock() - @Provides - fun provideDimensionRepository(): IDimensionRepository = FixedDimensionRepository() - @Provides fun provideSavesRepository(): ISavesRepository = MemorySavesRepository() From a37d361ccd50305a974396f92c824bf77c603faf Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Sun, 9 Aug 2020 22:46:06 -0300 Subject: [PATCH 15/20] Add system label to default theme --- .../antimine/theme/view/ThemeAdapter.kt | 20 +++++++++++++++++-- app/src/main/res/layout/view_theme.xml | 12 +++++++++++ common/src/main/res/values/strings.xml | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt index 93ccfe6c7..62d822f9b 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/view/ThemeAdapter.kt @@ -57,8 +57,24 @@ class ThemeAdapter( val theme = themes[position] val paintSettings = createAreaPaintSettings(holder.itemView.context, areaSize) holder.itemView.run { - arrayOf(area0, area1, area2, area3, area4, area5, area6, area7, area8) - .forEachIndexed { index, areaView -> areaView.bindTheme(minefield[index], theme, paintSettings) } + val areas = listOf(area0, area1, area2, area3, area4, area5, area6, area7, area8) + + areas.forEachIndexed { index, areaView -> areaView.bindTheme(minefield[index], theme, paintSettings) } + + if (position == 0) { + areas.forEach { it.alpha = 0.35f } + + label.apply { + setTextColor(with(theme.palette.background) { + Color.rgb(255 - Color.red(this), 255 - Color.green(this), 255 - Color.blue(this)) + }) + setBackgroundResource(android.R.color.transparent) + visibility = View.VISIBLE + } + } else { + label.visibility = View.GONE + } + val color = with(theme.palette.background) { Color.rgb(Color.red(this), Color.green(this), Color.blue(this)) diff --git a/app/src/main/res/layout/view_theme.xml b/app/src/main/res/layout/view_theme.xml index 40004c653..72c7b7129 100644 --- a/app/src/main/res/layout/view_theme.xml +++ b/app/src/main/res/layout/view_theme.xml @@ -72,6 +72,18 @@ android:layout_margin="0.5dp" /> + + Accessibility Use Large Areas Size + System Feedback If you like this game, please give us a feedback. It will help us a lot. This game uses the following third parties software: From 598c106f4f47c9fba48c828a763741703f63d90a Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Mon, 10 Aug 2020 01:20:27 -0300 Subject: [PATCH 16/20] Fake menu :( --- .../dev/lucasnlm/antimine/GameActivity.kt | 29 ++- app/src/main/res/drawable/menu.xml | 10 + app/src/main/res/layout/activity_game.xml | 193 +++++++++--------- common/src/main/res/values-v21/themes.xml | 11 +- 4 files changed, 140 insertions(+), 103 deletions(-) create mode 100644 app/src/main/res/drawable/menu.xml diff --git a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt index febe78133..e74a1694b 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt @@ -14,6 +14,7 @@ import android.view.WindowManager import androidx.activity.viewModels import androidx.appcompat.app.ActionBarDrawerToggle import androidx.appcompat.app.AlertDialog +import androidx.appcompat.widget.TooltipCompat import androidx.core.os.HandlerCompat.postDelayed import androidx.core.view.GravityCompat import androidx.drawerlayout.widget.DrawerLayout @@ -34,9 +35,9 @@ import dev.lucasnlm.antimine.control.ControlDialogFragment import dev.lucasnlm.antimine.core.analytics.IAnalyticsManager import dev.lucasnlm.antimine.core.analytics.models.Analytics import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository +import dev.lucasnlm.antimine.custom.CustomLevelDialogFragment import dev.lucasnlm.antimine.history.HistoryActivity import dev.lucasnlm.antimine.instant.InstantAppManager -import dev.lucasnlm.antimine.custom.CustomLevelDialogFragment import dev.lucasnlm.antimine.level.view.EndGameDialogFragment import dev.lucasnlm.antimine.level.view.LevelFragment import dev.lucasnlm.antimine.preferences.PreferencesActivity @@ -44,6 +45,9 @@ import dev.lucasnlm.antimine.share.viewmodel.ShareViewModel import dev.lucasnlm.antimine.stats.StatsActivity import dev.lucasnlm.antimine.theme.ThemeActivity import kotlinx.android.synthetic.main.activity_game.* +import kotlinx.android.synthetic.main.activity_game.minesCount +import kotlinx.android.synthetic.main.activity_game.timer +import kotlinx.android.synthetic.main.activity_tv_game.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview @@ -249,14 +253,25 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O } } + @ExperimentalCoroutinesApi + @FlowPreview private fun bindToolbar() { - setSupportActionBar(toolbar) - toolbar.title = "" + menu.apply { + TooltipCompat.setTooltipText(this, getString(R.string.open_menu)) + setColorFilter(minesCount.currentTextColor) + setOnClickListener { + drawer.openDrawer(GravityCompat.START) + } + } - supportActionBar?.apply { - title = "" - setDisplayHomeAsUpEnabled(true) - setHomeButtonEnabled(true) + retry.apply { + TooltipCompat.setTooltipText(this, getString(R.string.new_game)) + setColorFilter(minesCount.currentTextColor) + setOnClickListener { + lifecycleScope.launch { + viewModel.startNewGame() + } + } } } diff --git a/app/src/main/res/drawable/menu.xml b/app/src/main/res/drawable/menu.xml new file mode 100644 index 000000000..ff67e5566 --- /dev/null +++ b/app/src/main/res/drawable/menu.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_game.xml b/app/src/main/res/layout/activity_game.xml index b7e393c58..cecb7beb4 100644 --- a/app/src/main/res/layout/activity_game.xml +++ b/app/src/main/res/layout/activity_game.xml @@ -1,113 +1,119 @@ - + android:fitsSystemWindows="true"> - - + - + - + - + - + - + - - - - - - - + + ads:menu="@menu/nav_menu" /> diff --git a/common/src/main/res/values-v21/themes.xml b/common/src/main/res/values-v21/themes.xml index 1d9da2174..c4cfa7c03 100644 --- a/common/src/main/res/values-v21/themes.xml +++ b/common/src/main/res/values-v21/themes.xml @@ -5,10 +5,13 @@ @color/primary_dark @color/accent @color/background + true + @android:color/transparent + true true -