diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..25e345c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.idea/ +app/local.properties +*.apk +app/release/ +app/standalone/ diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 00000000..918681ce --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,62 @@ +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' +apply plugin: 'io.fabric' +apply plugin: 'kotlin-kapt' + +android { + compileSdkVersion 29 + + defaultConfig { + applicationId 'dev.lucasnlm.antimine' + minSdkVersion 16 + targetSdkVersion 29 + versionCode 40 + versionName '6.0' + + resConfigs 'en', 'pt', 'es', 'zh' + } + + buildTypes { + debug { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + kapt { + generateStubs true + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation project(':common') + + // Android + implementation 'com.google.android.material:material:1.0.0' + implementation 'com.google.android.play:core:1.6.4' + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.preference:preference:1.1.0' + implementation 'androidx.recyclerview:recyclerview:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + + // Dagger + def dagger_version='2.21' + api "com.google.dagger:dagger-android:$dagger_version" + api "com.google.dagger:dagger-android-support:$dagger_version" + kapt "com.google.dagger:dagger-android-processor:$dagger_version" + kapt "com.google.dagger:dagger-compiler:$dagger_version" + + implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') { + transitive = true + } + + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0' + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50' +} diff --git a/app/fabric.properties b/app/fabric.properties new file mode 100644 index 00000000..23b563a9 --- /dev/null +++ b/app/fabric.properties @@ -0,0 +1 @@ +apiKey=18aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa diff --git a/app/gradle/wrapper/gradle-wrapper.jar b/app/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..7a3265ee Binary files /dev/null and b/app/gradle/wrapper/gradle-wrapper.jar differ diff --git a/app/gradle/wrapper/gradle-wrapper.properties b/app/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..541abfe5 --- /dev/null +++ b/app/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon May 21 22:33:16 BRT 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/app/gradlew b/app/gradlew new file mode 100644 index 00000000..cccdd3d5 --- /dev/null +++ b/app/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/app/gradlew.bat b/app/gradlew.bat new file mode 100644 index 00000000..e95643d6 --- /dev/null +++ b/app/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 00000000..19a93f16 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,43 @@ +# Project specific ProGuard rules + +# Crashlytics 2.+ +-keep class com.crashlytics.** { *; } +-keep class com.crashlytics.android.** +-keepattributes SourceFile, LineNumberTable, *Annotation* + +# For Fabric to properly de-obfuscate your crash reports, you need to remove this line from your ProGuard config: +-printmapping mapping.txt + +# support design +-dontwarn android.support.design.** +-keep class android.support.design.** { *; } +-keep interface android.support.design.** { *; } +-keep public class android.support.design.R$* { *; } + +# support v7 +-keep public class android.support.v7.widget.** { *; } +-keep public class android.support.v7.internal.widget.** { *; } +-keep public class android.support.v7.internal.view.menu.** { *; } + +-keep public class * extends android.support.v4.view.ActionProvider { + public (android.content.Context); +} + +# support v4 +-keep class android.support.v4.** { *; } +-keep interface android.support.v4.** { *; } + +# build config +-keep class com.example.BuildConfig { *; } + +# firebase +-keep class com.firebase.** { *; } + +# google gms +-keep class com.google.android.gms.** { *; } +-dontwarn com.google.android.gms.** + +# recycler view +-keep public class * extends android.support.v7.widget.RecyclerView$LayoutManager { + public (...); +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..920b6850 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt new file mode 100644 index 00000000..b1386ccc --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt @@ -0,0 +1,504 @@ +package dev.lucasnlm.antimine + +import android.content.ActivityNotFoundException +import android.content.Intent +import android.content.IntentSender +import android.net.Uri +import android.os.Build +import android.os.Bundle +import android.os.Handler +import android.text.format.DateUtils +import android.util.Log +import android.view.Menu +import android.view.MenuItem +import android.view.View +import androidx.appcompat.app.ActionBarDrawerToggle +import androidx.appcompat.app.AlertDialog +import androidx.core.content.ContextCompat +import androidx.core.os.HandlerCompat.postDelayed +import androidx.core.view.GravityCompat +import androidx.drawerlayout.widget.DrawerLayout +import androidx.fragment.app.FragmentTransaction +import androidx.lifecycle.Observer +import androidx.lifecycle.ViewModelProviders +import androidx.preference.PreferenceManager +import com.google.android.play.core.appupdate.AppUpdateManagerFactory +import com.google.android.play.core.install.model.AppUpdateType +import com.google.android.play.core.install.model.UpdateAvailability +import dev.lucasnlm.antimine.about.AboutActivity +import dev.lucasnlm.antimine.preferences.PreferencesActivity +import dagger.android.support.DaggerAppCompatActivity +import dev.lucasnlm.antimine.common.level.data.DifficultyPreset +import dev.lucasnlm.antimine.common.level.data.GameEvent +import dev.lucasnlm.antimine.common.level.data.GameStatus + +import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel +import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory +import dev.lucasnlm.antimine.core.analytics.AnalyticsManager +import dev.lucasnlm.antimine.core.analytics.Event +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository +import dev.lucasnlm.antimine.core.utils.isDarkModeEnabled +import dev.lucasnlm.antimine.level.view.CustomLevelDialogFragment +import dev.lucasnlm.antimine.level.view.LevelFragment +import kotlinx.android.synthetic.main.activity_game.* +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import javax.inject.Inject + +class GameActivity : DaggerAppCompatActivity() { + + @Inject + lateinit var viewModelFactory: GameViewModelFactory + + @Inject + lateinit var preferencesRepository: IPreferencesRepository + + @Inject + lateinit var analyticsManager: AnalyticsManager + + private lateinit var viewModel: GameViewModel + + private var gameStatus: GameStatus = GameStatus.PreGame + private var keepConfirmingNewGame = true + private val usingLargeArea by lazy { preferencesRepository.useLargeAreas() } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_game) + viewModel = ViewModelProviders.of(this, viewModelFactory).get(GameViewModel::class.java) + bindViewModel() + + PreferenceManager.setDefaultValues(this, R.xml.preferences, false) + + bindToolbarAndDrawer() + + loadGameFragment() + + if (Build.VERSION.SDK_INT >= 21) { + checkUpdate() + } + + checkUseCount() + } + + private fun bindViewModel() = viewModel.apply { + eventObserver.observe(this@GameActivity, Observer { + onGameEvent(it) + }) + elapsedTimeSeconds.observe(this@GameActivity, Observer { + timer.apply { + visibility = if (it == 0L) View.GONE else View.VISIBLE + text = DateUtils.formatElapsedTime(it) + } + }) + mineCount.observe(this@GameActivity, Observer { + minesCount.apply { + visibility = View.VISIBLE + text = it.toString() + } + }) + difficulty.observe(this@GameActivity, Observer { + onChangeDifficulty(it) + }) + } + + override fun onBackPressed() { + when { + drawer.isDrawerOpen(GravityCompat.START) -> { + drawer.closeDrawer(GravityCompat.START) + viewModel.resumeGame() + } + gameStatus == GameStatus.Running -> showQuitConfirmation { + super.onBackPressed() + } + else -> super.onBackPressed() + } + } + + override fun onResume() { + super.onResume() + if (gameStatus == GameStatus.Running) { + viewModel.resumeGame() + analyticsManager.sentEvent(Event.Resume()) + } + + restartIfNeed() + } + + override fun onPause() { + super.onPause() + + if (gameStatus == GameStatus.Running) { + viewModel.pauseGame() + } + + analyticsManager.sentEvent(Event.Quit()) + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean = + when (gameStatus) { + GameStatus.Over, GameStatus.Running -> { + menuInflater.inflate(R.menu.top_menu_over, menu) + true + } + else -> true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return if (item.itemId == R.id.reset) { + + val confirmResign = gameStatus == GameStatus.Running + analyticsManager.sentEvent(Event.TapGameReset(confirmResign)) + + if (confirmResign) { + newGameConfirmation { + GlobalScope.launch { + viewModel.startNewGame() + } + } + } else { + GlobalScope.launch { + viewModel.startNewGame() + } + } + true + } else { + super.onOptionsItemSelected(item) + } + } + + private fun bindToolbarAndDrawer() { + setSupportActionBar(toolbar) + toolbar.title = "" + + supportActionBar?.apply { + title = "" + setDisplayHomeAsUpEnabled(true) + setHomeButtonEnabled(true) + } + + drawer.apply { + addDrawerListener( + ActionBarDrawerToggle(this@GameActivity, drawer, toolbar, R.string.open_menu, R.string.close_menu).apply { + if (!isDarkModeEnabled(applicationContext)) { + drawerArrowDrawable.color = ContextCompat.getColor(applicationContext, R.color.primary) + } + + syncState() + } + ) + + addDrawerListener(object : DrawerLayout.DrawerListener { + override fun onDrawerSlide(drawerView: View, slideOffset: Float) { + // Empty + } + + override fun onDrawerOpened(drawerView: View) { + if (gameStatus != GameStatus.Over) { + viewModel.pauseGame() + } + analyticsManager.sentEvent(Event.OpenDrawer()) + } + + override fun onDrawerClosed(drawerView: View) { + if (gameStatus != GameStatus.Over) { + viewModel.resumeGame() + } + analyticsManager.sentEvent(Event.CloseDrawer()) + } + + override fun onDrawerStateChanged(newState: Int) { + // Empty + } + }) + } + + navigationView.setNavigationItemSelectedListener { item -> + var handled = true + + when (item.itemId) { + R.id.standard -> changeDifficulty(DifficultyPreset.Standard) + R.id.beginner -> changeDifficulty(DifficultyPreset.Beginner) + R.id.intermediate -> changeDifficulty(DifficultyPreset.Intermediate) + R.id.expert -> changeDifficulty(DifficultyPreset.Expert) + R.id.custom -> showCustomLevelDialog() + R.id.about -> showAbout() + R.id.settings -> showSettings() + R.id.rate -> openRateUsLink("Drawer") + else -> handled = false + } + + if (handled) { + drawer.closeDrawer(GravityCompat.START) + } + + handled + } + + if (preferencesRepository.getBoolean(PREFERENCE_FIRST_USE, false)) { + drawer.openDrawer(GravityCompat.START) + preferencesRepository.putBoolean(PREFERENCE_FIRST_USE, true) + } + } + + private fun checkUseCount() { + val current = preferencesRepository.getInt(PREFERENCE_USE_COUNT, 0) + val shouldRequestRating = preferencesRepository.getBoolean(PREFERENCE_REQUEST_RATING, true) + + if (current >= 4 && shouldRequestRating) { + analyticsManager.sentEvent(Event.ShowRatingRequest(current)) + showRequestRating() + } + + preferencesRepository.putInt(PREFERENCE_USE_COUNT, current + 1) + } + + private fun onChangeDifficulty(difficulty: DifficultyPreset) { + navigationView.menu.apply { + arrayOf( + DifficultyPreset.Standard to findItem(R.id.standard), + DifficultyPreset.Beginner to findItem(R.id.beginner), + DifficultyPreset.Intermediate to findItem(R.id.intermediate), + DifficultyPreset.Expert to findItem(R.id.expert), + DifficultyPreset.Custom to findItem(R.id.custom) + ).map { + it.second to (if (it.first == difficulty) R.drawable.checked else R.drawable.unchecked) + }.forEach { (menuItem, icon) -> + menuItem.setIcon(icon) + } + } + } + + private fun loadGameFragment() { + val fragmentManager = supportFragmentManager + + fragmentManager.popBackStack() + + fragmentManager.findFragmentById(R.id.levelContainer)?.let { it -> + fragmentManager.beginTransaction().apply { + remove(it) + commitAllowingStateLoss() + } + } + + fragmentManager.beginTransaction().apply { + replace(R.id.levelContainer, LevelFragment()) + setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) + commitAllowingStateLoss() + } + } + + private fun showRequestRating() { + if (getString(R.string.rating_message).isNotEmpty()) { + + AlertDialog.Builder(this) + .setMessage(R.string.rating_message) + .setPositiveButton(R.string.rating_button) { _, _ -> + openRateUsLink("Dialog") + } + .setNegativeButton(R.string.rating_button_no) { _, _ -> + preferencesRepository.putBoolean(PREFERENCE_REQUEST_RATING, false) + } + .show() + } + } + + private fun newGameConfirmation(action: () -> Unit) { + AlertDialog.Builder(this, R.style.MyDialog).apply { + setTitle(R.string.start_over) + setMessage(R.string.retry_sure) + setPositiveButton(R.string.resume) { _, _ -> action() } + setNegativeButton(R.string.cancel, null) + show() + } + } + + private fun showQuitConfirmation(action: () -> Unit) { + AlertDialog.Builder(this, R.style.MyDialog) + .setTitle(R.string.are_you_sure) + .setMessage(R.string.sure_quit_desc) + .setPositiveButton(R.string.quit) { _, _ -> action() } + .setNegativeButton(R.string.cancel, null) + .show() + } + + private fun showCustomLevelDialog() { + CustomLevelDialogFragment().apply { + show(supportFragmentManager, "custom_level_fragment") + } + } + + private fun showAbout() { + analyticsManager.sentEvent(Event.OpenAbout()) + Intent(this, AboutActivity::class.java).apply { + startActivity(this) + } + } + + private fun showSettings() { + analyticsManager.sentEvent(Event.OpenSettings()) + Intent(this, PreferencesActivity::class.java).apply { + startActivity(this) + } + } + + private fun showVictory() { + AlertDialog.Builder(this, R.style.MyDialog).apply { + setTitle(R.string.you_won) + setMessage(R.string.all_mines_disabled) + setCancelable(false) + setPositiveButton(R.string.new_game) { _, _ -> + GlobalScope.launch { + viewModel.startNewGame() + } + } + setNegativeButton(R.string.cancel, null) + show() + } + } + + private fun waitAndShowConfirmNewGame() { + if (keepConfirmingNewGame) { + postDelayed(Handler(), { + if (this.gameStatus == GameStatus.Over && !isFinishing) { + AlertDialog.Builder(this, R.style.MyDialog).apply { + setTitle(R.string.new_game) + setMessage(R.string.new_game_request) + setPositiveButton(R.string.yes) { _, _ -> + GlobalScope.launch { + viewModel.startNewGame() + } + } + setNegativeButton(R.string.cancel, null) + }.show() + + keepConfirmingNewGame = false + } + }, null, DateUtils.SECOND_IN_MILLIS) + } + } + + private fun waitAndShowGameOverConfirmNewGame() { + postDelayed(Handler(), { + if (this.gameStatus == GameStatus.Over && !isFinishing) { + AlertDialog.Builder(this, R.style.MyDialog).apply { + setTitle(R.string.you_lost) + setMessage(R.string.new_game_request) + setPositiveButton(R.string.yes) { _, _ -> + GlobalScope.launch { + viewModel.startNewGame() + } + } + setNegativeButton(R.string.cancel, null) + }.show() + } + }, null, DateUtils.SECOND_IN_MILLIS) + } + + private fun changeDifficulty(newDifficulty: DifficultyPreset) { + if (gameStatus == GameStatus.PreGame) { + GlobalScope.launch { + viewModel.startNewGame(newDifficulty) + } + } else { + newGameConfirmation { + GlobalScope.launch { + viewModel.startNewGame(newDifficulty) + } + } + } + } + + private fun onGameEvent(event: GameEvent) { + when (event) { + GameEvent.ResumeGame -> { + invalidateOptionsMenu() + } + GameEvent.StartNewGame -> { + gameStatus = GameStatus.PreGame + invalidateOptionsMenu() + } + GameEvent.Resume, GameEvent.Running -> { + gameStatus = GameStatus.Running + viewModel.runClock() + invalidateOptionsMenu() + } + GameEvent.Victory -> { + gameStatus = GameStatus.Over + viewModel.stopClock() + viewModel.revealAllEmptyAreas() + viewModel.victory() + invalidateOptionsMenu() + showVictory() + } + GameEvent.GameOver -> { + gameStatus = GameStatus.Over + invalidateOptionsMenu() + viewModel.stopClock() + viewModel.gameOver() + + waitAndShowGameOverConfirmNewGame() + } + GameEvent.ResumeVictory, GameEvent.ResumeGameOver -> { + gameStatus = GameStatus.Over + invalidateOptionsMenu() + viewModel.stopClock() + + waitAndShowConfirmNewGame() + } + else -> { + + } + } + } + + /** + * Call Google API to request update. + */ + private fun checkUpdate() { + val appUpdateManager = AppUpdateManagerFactory.create(this) + val appUpdateInfoTask = appUpdateManager.appUpdateInfo + + appUpdateInfoTask.addOnSuccessListener { info -> + if (info.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE + && info.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) { + try { + appUpdateManager.startUpdateFlowForResult( + info, AppUpdateType.FLEXIBLE, this, 1) + } catch (e: IntentSender.SendIntentException) { + Log.e(TAG, "Fail to request update.") + } + } + } + + } + + /** + * If user change any accessibility preference, the game will restart the activity to + * apply these changes. + */ + private fun restartIfNeed() { + if (usingLargeArea != preferencesRepository.useLargeAreas()) { + finish() + Intent(this, GameActivity::class.java).run { startActivity(this) } + } + } + + private fun openRateUsLink(from: String) { + try { + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName"))) + } catch (e: ActivityNotFoundException) { + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageName"))) + } + + analyticsManager.sentEvent(Event.TapRatingRequest(from)) + preferencesRepository.putBoolean(PREFERENCE_REQUEST_RATING, false) + } + + companion object { + const val TAG = "GameActivity" + const val PREFERENCE_FIRST_USE = "preference_first_use" + const val PREFERENCE_USE_COUNT = "preference_use_count" + const val PREFERENCE_REQUEST_RATING = "preference_request_rating" + } +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/MainApplication.kt b/app/src/main/java/dev/lucasnlm/antimine/MainApplication.kt new file mode 100644 index 00000000..7097a1e3 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/MainApplication.kt @@ -0,0 +1,27 @@ +package dev.lucasnlm.antimine + +import dagger.android.AndroidInjector +import dagger.android.support.DaggerApplication +import dev.lucasnlm.antimine.core.analytics.AnalyticsManager +import dev.lucasnlm.antimine.core.analytics.Event +import dev.lucasnlm.antimine.di.AppModule +import dev.lucasnlm.antimine.di.DaggerAppComponent +import javax.inject.Inject + +class MainApplication : DaggerApplication() { + + @Inject + lateinit var analyticsManager: AnalyticsManager + + override fun applicationInjector(): AndroidInjector = + DaggerAppComponent.builder() + .application(this) + .appModule(AppModule(this)) + .build() + + override fun onCreate() { + super.onCreate() + analyticsManager.setup(applicationContext, mapOf()) + analyticsManager.sentEvent(Event.Open()) + } +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt new file mode 100644 index 00000000..3948c170 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt @@ -0,0 +1,318 @@ +package dev.lucasnlm.antimine + +import android.content.Intent +import android.content.IntentSender +import android.os.Build +import android.os.Bundle +import android.os.Handler +import android.text.format.DateUtils +import android.util.Log +import android.view.Menu +import android.view.MenuItem +import android.view.View +import androidx.appcompat.app.AlertDialog +import androidx.core.os.HandlerCompat +import androidx.fragment.app.FragmentTransaction +import androidx.lifecycle.Observer +import androidx.lifecycle.ViewModelProviders +import androidx.preference.PreferenceManager +import com.google.android.play.core.appupdate.AppUpdateManagerFactory +import com.google.android.play.core.install.model.AppUpdateType +import com.google.android.play.core.install.model.UpdateAvailability +import dagger.android.support.DaggerAppCompatActivity +import dev.lucasnlm.antimine.about.AboutActivity +import dev.lucasnlm.antimine.common.level.data.DifficultyPreset +import dev.lucasnlm.antimine.common.level.data.GameEvent +import dev.lucasnlm.antimine.common.level.data.GameStatus +import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel +import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository +import dev.lucasnlm.antimine.level.view.CustomLevelDialogFragment +import dev.lucasnlm.antimine.level.view.LevelFragment +import dev.lucasnlm.antimine.preferences.PreferencesActivity +import kotlinx.android.synthetic.main.activity_tv_game.* +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import javax.inject.Inject + +class TvGameActivity : DaggerAppCompatActivity() { + + @Inject + lateinit var viewModelFactory: GameViewModelFactory + + @Inject + lateinit var preferencesRepository: IPreferencesRepository + + private lateinit var viewModel: GameViewModel + + private var gameStatus: GameStatus = GameStatus.PreGame + + private var keepConfirmingNewGame = true + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_tv_game) + viewModel = ViewModelProviders.of(this, viewModelFactory).get(GameViewModel::class.java) + bindViewModel() + + PreferenceManager.setDefaultValues(this, R.xml.preferences, false) + + loadGameFragment() + + if (Build.VERSION.SDK_INT >= 21) { + checkUpdate() + } + } + + private fun bindViewModel() = viewModel.apply { + eventObserver.observe(this@TvGameActivity, Observer { + onGameEvent(it) + }) + elapsedTimeSeconds.observe(this@TvGameActivity, Observer { + timer.apply { + visibility = if (it == 0L) View.GONE else View.VISIBLE + text = DateUtils.formatElapsedTime(it) + } + }) + mineCount.observe(this@TvGameActivity, Observer { + minesCount.apply { + visibility = View.VISIBLE + text = it.toString() + } + }) + difficulty.observe(this@TvGameActivity, Observer { + //onChangeDifficulty(it) + }) + } + + override fun onResume() { + super.onResume() + if (gameStatus == GameStatus.Running) { + viewModel.resumeGame() + } + } + + override fun onPause() { + super.onPause() + + if (gameStatus == GameStatus.Running) { + viewModel.pauseGame() + } + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean = + when (gameStatus) { + GameStatus.Over, GameStatus.Running -> { + menuInflater.inflate(R.menu.top_menu_over, menu) + true + } + else -> true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return if (item.itemId == R.id.reset) { + if (gameStatus == GameStatus.Running) { + newGameConfirmation { + GlobalScope.launch { + viewModel.startNewGame() + } + } + } else { + GlobalScope.launch { + viewModel.startNewGame() + } + } + true + } else { + super.onOptionsItemSelected(item) + } + } + + private fun loadGameFragment() { + val fragmentManager = supportFragmentManager + + fragmentManager.popBackStack() + + fragmentManager.findFragmentById(R.id.levelContainer)?.let { it -> + fragmentManager.beginTransaction().apply { + remove(it) + commitAllowingStateLoss() + } + } + + fragmentManager.beginTransaction().apply { + replace(R.id.levelContainer, LevelFragment()) + setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) + commitAllowingStateLoss() + } + } + + private fun newGameConfirmation(action: () -> Unit) { + AlertDialog.Builder(this, R.style.MyDialog).apply { + setTitle(R.string.start_over) + setMessage(R.string.retry_sure) + setPositiveButton(R.string.resume) { _, _ -> action() } + setNegativeButton(R.string.cancel, null) + show() + } + } + + private fun showQuitConfirmation(action: () -> Unit) { + AlertDialog.Builder(this, R.style.MyDialog) + .setTitle(R.string.are_you_sure) + .setMessage(R.string.sure_quit_desc) + .setPositiveButton(R.string.quit) { _, _ -> action() } + .setNegativeButton(R.string.cancel, null) + .show() + } + + private fun showCustomLevelDialog() { + CustomLevelDialogFragment().apply { + show(supportFragmentManager, "custom_level_fragment") + } + } + + private fun showAbout() { + Intent(this, AboutActivity::class.java).apply { + startActivity(this) + } + } + + private fun showSettings() { + Intent(this, PreferencesActivity::class.java).apply { + startActivity(this) + } + } + + private fun showVictory() { + AlertDialog.Builder(this, R.style.MyDialog).apply { + setTitle(R.string.you_won) + setMessage(R.string.all_mines_disabled) + setCancelable(false) + setPositiveButton(R.string.new_game) { _, _ -> + GlobalScope.launch { + viewModel.startNewGame() + } + } + setNegativeButton(R.string.cancel, null) + show() + } + } + + private fun waitAndShowConfirmNewGame() { + if (keepConfirmingNewGame) { + HandlerCompat.postDelayed(Handler(), { + if (this.gameStatus == GameStatus.Over && !isFinishing) { + AlertDialog.Builder(this, R.style.MyDialog).apply { + setTitle(R.string.new_game) + setMessage(R.string.new_game_request) + setPositiveButton(R.string.yes) { _, _ -> + GlobalScope.launch { + viewModel.startNewGame() + } + } + setNegativeButton(R.string.cancel, null) + }.show() + + keepConfirmingNewGame = false + } + }, null, DateUtils.SECOND_IN_MILLIS) + } + } + + private fun waitAndShowGameOverConfirmNewGame() { + HandlerCompat.postDelayed(Handler(), { + if (this.gameStatus == GameStatus.Over && !isFinishing) { + AlertDialog.Builder(this, R.style.MyDialog).apply { + setTitle(R.string.you_lost) + setMessage(R.string.new_game_request) + setPositiveButton(R.string.yes) { _, _ -> + GlobalScope.launch { + viewModel.startNewGame() + } + } + setNegativeButton(R.string.cancel, null) + }.show() + } + }, null, DateUtils.SECOND_IN_MILLIS) + } + + private fun changeDifficulty(newDifficulty: DifficultyPreset) { + if (gameStatus == GameStatus.PreGame) { + GlobalScope.launch { + viewModel.startNewGame(newDifficulty) + } + } else { + newGameConfirmation { + GlobalScope.launch { + viewModel.startNewGame(newDifficulty) + } + } + } + } + + private fun onGameEvent(event: GameEvent) { + when (event) { + GameEvent.ResumeGame -> { + invalidateOptionsMenu() + } + GameEvent.StartNewGame -> { + gameStatus = GameStatus.PreGame + invalidateOptionsMenu() + } + GameEvent.Resume, GameEvent.Running -> { + gameStatus = GameStatus.Running + viewModel.runClock() + invalidateOptionsMenu() + } + GameEvent.Victory -> { + gameStatus = GameStatus.Over + viewModel.stopClock() + viewModel.revealAllEmptyAreas() + invalidateOptionsMenu() + showVictory() + } + GameEvent.GameOver -> { + gameStatus = GameStatus.Over + invalidateOptionsMenu() + viewModel.stopClock() + viewModel.gameOver() + + waitAndShowGameOverConfirmNewGame() + } + GameEvent.ResumeVictory, GameEvent.ResumeGameOver -> { + gameStatus = GameStatus.Over + invalidateOptionsMenu() + viewModel.stopClock() + + waitAndShowConfirmNewGame() + } + else -> { + + } + } + } + + private fun checkUpdate() { + val appUpdateManager = AppUpdateManagerFactory.create(this) + val appUpdateInfoTask = appUpdateManager.appUpdateInfo + + appUpdateInfoTask.addOnSuccessListener { info -> + if (info.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE + && info.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) { + try { + appUpdateManager.startUpdateFlowForResult( + info, AppUpdateType.FLEXIBLE, this, 1) + } catch (e: IntentSender.SendIntentException) { + Log.e(TAG, "Fail to request update.") + } + } + } + + } + + companion object { + const val TAG = "GameActivity" + const val PREFERENCE_FIRST_USE = "preference_first_use" + } +} \ No newline at end of file diff --git a/app/src/main/java/dev/lucasnlm/antimine/about/AboutActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/about/AboutActivity.kt new file mode 100644 index 00000000..a983e4b8 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/about/AboutActivity.kt @@ -0,0 +1,47 @@ +package dev.lucasnlm.antimine.about + +import android.content.Intent +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import android.view.MenuItem +import dev.lucasnlm.antimine.BuildConfig +import dev.lucasnlm.antimine.R + +import dev.lucasnlm.antimine.about.thirds.ThirdPartiesActivity +import kotlinx.android.synthetic.main.activity_about.* + +class AboutActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_about) + bindToolbar() + + version.text = getString( + R.string.version_s, + getString(R.string.app_name), BuildConfig.VERSION_NAME + ) + + thirdsParties.setOnClickListener { openThirdParties() } + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean = + when (item.itemId) { + android.R.id.home -> { + onBackPressed() + true + } + else -> super.onOptionsItemSelected(item) + } + + private fun bindToolbar() { + supportActionBar?.let { actionBar -> + actionBar.setTitle(R.string.about) + actionBar.setDisplayHomeAsUpEnabled(true) + actionBar.setHomeButtonEnabled(true) + } + } + + private fun openThirdParties() { + startActivity(Intent(this, ThirdPartiesActivity::class.java)) + } +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/about/Constants.kt b/app/src/main/java/dev/lucasnlm/antimine/about/Constants.kt new file mode 100644 index 00000000..d3dad9a5 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/about/Constants.kt @@ -0,0 +1,6 @@ +package dev.lucasnlm.antimine.about + +object Constants { + const val TEXT_TITLE = "third_title" + const val TEXT_PATH = "third_path" +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/about/TextActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/about/TextActivity.kt new file mode 100644 index 00000000..11bf0a7e --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/about/TextActivity.kt @@ -0,0 +1,97 @@ +package dev.lucasnlm.antimine.about + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import android.util.Log +import android.view.MenuItem +import android.view.View +import dev.lucasnlm.antimine.R + +import kotlinx.android.synthetic.main.activity_text.* +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + +import java.io.ByteArrayOutputStream +import java.io.IOException +import java.io.InputStream + +class TextActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_text) + bindToolbar() + + progressBar.isIndeterminate = true + + GlobalScope.launch { + withContext(Dispatchers.Main) { + progressBar.visibility = View.VISIBLE + } + + withContext(Dispatchers.IO) { + val rawPath = intent.getIntExtra(Constants.TEXT_PATH, -1) + var result: String? = null + + if (rawPath > 0) { + resources.openRawResource(rawPath).use { inputStream -> + + result = readTextFile(inputStream) + } + } + + withContext(Dispatchers.Main) { + textView.text = result + progressBar.visibility = View.GONE + } + } + } + } + + private fun readTextFile(inputStream: InputStream): String { + var result = "" + ByteArrayOutputStream().use { outputStream -> + val buf = ByteArray(4096) + var len: Int + try { + while (true) { + len = inputStream.read(buf) + if (len != -1) { + outputStream.write(buf, 0, len) + } else { + break + } + } + } catch (e: IOException) { + Log.e(TAG, "Fail to read file.", e) + } + result = outputStream.toString() + } + return result + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + var handled = false + + if (item.itemId == android.R.id.home) { + onBackPressed() + handled = true + } + + return handled || super.onOptionsItemSelected(item) + } + + private fun bindToolbar() { + supportActionBar?.apply { + title = intent.getStringExtra(Constants.TEXT_TITLE) + setDisplayHomeAsUpEnabled(true) + setHomeButtonEnabled(true) + } + } + + companion object { + private const val TAG = "TextActivity" + } +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/about/thirds/ThirdPartiesActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/about/thirds/ThirdPartiesActivity.kt new file mode 100644 index 00000000..ff348710 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/about/thirds/ThirdPartiesActivity.kt @@ -0,0 +1,78 @@ +package dev.lucasnlm.antimine.about.thirds + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import android.view.MenuItem +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager + +import dev.lucasnlm.antimine.R +import dev.lucasnlm.antimine.about.thirds.data.ThirdParty +import dev.lucasnlm.antimine.about.thirds.view.ThirdPartyAdapter +import kotlinx.android.synthetic.main.activity_third_party.* + +class ThirdPartiesActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_third_party) + bindToolbar() + + licenses.apply { + setHasFixedSize(true) + addItemDecoration( + DividerItemDecoration(context, DividerItemDecoration.VERTICAL) + ) + layoutManager = LinearLayoutManager(context) + } + + loadLicenses() + } + + private fun loadLicenses() { + licenses.adapter = ThirdPartyAdapter( + listOf( + ThirdParty( + "Android SDK License", + R.raw.android_sdk + ), + ThirdParty( + "Material Design Icons", + R.raw.apache2 + ), + ThirdParty( + "Dagger", + R.raw.apache2 + ), + ThirdParty( + "Moshi", + R.raw.apache2 + ), + ThirdParty( + "Mockito", + R.raw.mockito + ), + ThirdParty( + "Sounds", + R.raw.sounds + ) + ) + ) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean = + when (item.itemId) { + android.R.id.home -> { + onBackPressed() + true + } + else -> super.onOptionsItemSelected(item) + } + + private fun bindToolbar() { + supportActionBar?.apply { + setTitle(R.string.licenses) + setDisplayHomeAsUpEnabled(true) + setHomeButtonEnabled(true) + } + } +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/about/thirds/data/ThirdParty.kt b/app/src/main/java/dev/lucasnlm/antimine/about/thirds/data/ThirdParty.kt new file mode 100644 index 00000000..9cd03818 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/about/thirds/data/ThirdParty.kt @@ -0,0 +1,8 @@ +package dev.lucasnlm.antimine.about.thirds.data + +import androidx.annotation.RawRes + +internal data class ThirdParty( + val name: String, + @RawRes val license: Int +) diff --git a/app/src/main/java/dev/lucasnlm/antimine/about/thirds/view/ThirdPartyAdapter.kt b/app/src/main/java/dev/lucasnlm/antimine/about/thirds/view/ThirdPartyAdapter.kt new file mode 100644 index 00000000..3bb7fd77 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/about/thirds/view/ThirdPartyAdapter.kt @@ -0,0 +1,37 @@ +package dev.lucasnlm.antimine.about.thirds.view + +import android.content.Intent +import androidx.recyclerview.widget.RecyclerView +import android.view.LayoutInflater +import android.view.ViewGroup +import dev.lucasnlm.antimine.R + +import dev.lucasnlm.antimine.about.Constants +import dev.lucasnlm.antimine.about.TextActivity +import dev.lucasnlm.antimine.about.thirds.data.ThirdParty + +internal class ThirdPartyAdapter( + private val thirdParties: List +) : RecyclerView.Adapter() { + + override fun getItemCount(): Int = thirdParties.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ThirdPartyItemHolder { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.view_third_party, parent, false) + return ThirdPartyItemHolder(view) + } + + override fun onBindViewHolder(holder: ThirdPartyItemHolder, position: Int) { + val thirdParty = thirdParties[position] + holder.title.text = thirdParty.name + holder.itemView.setOnClickListener { view -> + val intent = Intent(view.context, TextActivity::class.java).apply { + putExtra(Constants.TEXT_TITLE, thirdParty.name) + putExtra(Constants.TEXT_PATH, thirdParty.license) + } + + view.context.startActivity(intent) + } + } +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/about/thirds/view/ThirdPartyItemHolder.kt b/app/src/main/java/dev/lucasnlm/antimine/about/thirds/view/ThirdPartyItemHolder.kt new file mode 100644 index 00000000..47769e2b --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/about/thirds/view/ThirdPartyItemHolder.kt @@ -0,0 +1,11 @@ +package dev.lucasnlm.antimine.about.thirds.view + +import androidx.recyclerview.widget.RecyclerView +import android.view.View +import android.widget.TextView + +import dev.lucasnlm.antimine.R + +internal class ThirdPartyItemHolder(view: View) : RecyclerView.ViewHolder(view) { + val title: TextView = view.findViewById(R.id.third_name) +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/di/ActivityModule.kt b/app/src/main/java/dev/lucasnlm/antimine/di/ActivityModule.kt new file mode 100644 index 00000000..5eb4c98a --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/di/ActivityModule.kt @@ -0,0 +1,18 @@ +package dev.lucasnlm.antimine.di + +import dev.lucasnlm.antimine.GameActivity +import dagger.Module +import dagger.android.ContributesAndroidInjector +import dev.lucasnlm.antimine.TvGameActivity +import dev.lucasnlm.antimine.core.scope.ActivityScope + +@Module +interface ActivityModule { + @ActivityScope + @ContributesAndroidInjector + fun contributeGameActivityInjector(): GameActivity + + @ActivityScope + @ContributesAndroidInjector + fun contributeTvGameActivityInjector(): TvGameActivity +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/di/AppComponent.kt b/app/src/main/java/dev/lucasnlm/antimine/di/AppComponent.kt new file mode 100644 index 00000000..cceaaeaa --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/di/AppComponent.kt @@ -0,0 +1,35 @@ +package dev.lucasnlm.antimine.di + +import android.app.Application +import dagger.BindsInstance +import dagger.Component +import dagger.android.AndroidInjector +import dagger.android.support.AndroidSupportInjectionModule +import dev.lucasnlm.antimine.MainApplication +import dev.lucasnlm.antimine.common.level.di.LevelModule +import dev.lucasnlm.antimine.core.di.CommonModule +import javax.inject.Singleton + +@Component( + modules = [ + AndroidSupportInjectionModule::class, + AppModule::class, + LevelModule::class, + ActivityModule::class, + FragmentModule::class, + CommonModule::class + ] +) +@Singleton +interface AppComponent : AndroidInjector { + + @Component.Builder + interface Builder { + @BindsInstance + fun application(application: Application): Builder + + fun appModule(module: AppModule): Builder + + fun build(): AppComponent + } +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/di/AppModule.kt b/app/src/main/java/dev/lucasnlm/antimine/di/AppModule.kt new file mode 100644 index 00000000..4c46d22e --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/di/AppModule.kt @@ -0,0 +1,14 @@ +package dev.lucasnlm.antimine.di + +import android.app.Application +import android.content.Context +import dagger.Module +import dagger.Provides + +@Module +class AppModule( + private val application: Application +) { + @Provides + fun provideContext(): Context = application.applicationContext +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/di/FragmentModule.kt b/app/src/main/java/dev/lucasnlm/antimine/di/FragmentModule.kt new file mode 100644 index 00000000..73d48312 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/di/FragmentModule.kt @@ -0,0 +1,18 @@ +package dev.lucasnlm.antimine.di + +import dev.lucasnlm.antimine.level.view.CustomLevelDialogFragment +import dagger.Module +import dagger.android.ContributesAndroidInjector +import dev.lucasnlm.antimine.core.scope.ActivityScope +import dev.lucasnlm.antimine.level.view.LevelFragment + +@Module +interface FragmentModule { + @ActivityScope + @ContributesAndroidInjector + fun contributeLevelFragmentInjector(): LevelFragment + + @ActivityScope + @ContributesAndroidInjector + fun contributeCustomLevelDialogFragmentInjector(): CustomLevelDialogFragment +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/level/view/CustomLevelDialogFragment.kt b/app/src/main/java/dev/lucasnlm/antimine/level/view/CustomLevelDialogFragment.kt new file mode 100644 index 00000000..61833f85 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/level/view/CustomLevelDialogFragment.kt @@ -0,0 +1,88 @@ +package dev.lucasnlm.antimine.level.view + +import android.app.Dialog +import android.os.Bundle +import androidx.appcompat.app.AlertDialog +import android.widget.TextView +import androidx.lifecycle.ViewModelProviders + +import dagger.android.support.DaggerAppCompatDialogFragment +import dev.lucasnlm.antimine.R +import dev.lucasnlm.antimine.common.level.data.DifficultyPreset +import dev.lucasnlm.antimine.common.level.data.LevelSetup +import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel +import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import javax.inject.Inject + +class CustomLevelDialogFragment : DaggerAppCompatDialogFragment() { + @Inject + lateinit var viewModelFactory: GameViewModelFactory + + @Inject + lateinit var preferencesRepository: IPreferencesRepository + + private lateinit var viewModel: GameViewModel + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + activity?.let { + viewModel = ViewModelProviders.of(it, viewModelFactory).get(GameViewModel::class.java) + } + } + + private fun filterInput(target: String, min: Int): Int { + var result = min + + try { + result = Integer.valueOf(target) + } catch (e: NumberFormatException) { + result = min + } finally { + result = result.coerceAtLeast(min) + } + + return result + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + return AlertDialog.Builder(context!!, R.style.MyDialog).apply { + setTitle(R.string.new_game) + setView(R.layout.dialog_custom_game) + setNegativeButton(R.string.cancel, null) + setPositiveButton(R.string.start) { _, _ -> + val mapWidth: TextView? = dialog?.findViewById(R.id.map_width) + val mapHeight: TextView? = dialog?.findViewById(R.id.map_height) + val mapMines: TextView? = dialog?.findViewById(R.id.map_mines) + + var width = filterInput(mapWidth?.text.toString(), MIN_WIDTH) + var height = filterInput(mapHeight?.text.toString(), MIN_HEIGHT) + var mines = filterInput(mapMines?.text.toString(), MIN_MINES) + + if (width * height - 1 < mines) { + mines = width * height - 1 + } + + width = width.coerceAtMost(50) + height = height.coerceAtMost(50) + mines = mines.coerceAtLeast(1) + + preferencesRepository.updateCustomGameMode(LevelSetup(width, height, mines)) + + GlobalScope.launch(Dispatchers.IO) { + viewModel.startNewGame(DifficultyPreset.Custom) + } + } + }.create() + } + + companion object { + const val MIN_WIDTH = 5 + const val MIN_HEIGHT = 5 + const val MIN_MINES = 3 + } +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/level/view/LevelFragment.kt b/app/src/main/java/dev/lucasnlm/antimine/level/view/LevelFragment.kt new file mode 100644 index 00000000..2c1c0df9 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/level/view/LevelFragment.kt @@ -0,0 +1,126 @@ +package dev.lucasnlm.antimine.level.view + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.lifecycle.Observer +import androidx.lifecycle.ViewModelProviders +import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.RecyclerView +import dev.lucasnlm.antimine.common.R +import dev.lucasnlm.antimine.common.level.view.UnlockedHorizontalScrollView +import dagger.android.support.DaggerFragment +import dev.lucasnlm.antimine.common.level.data.DifficultyPreset +import dev.lucasnlm.antimine.common.level.view.AreaAdapter +import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel +import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import javax.inject.Inject + +open class LevelFragment : DaggerFragment() { + @Inject + lateinit var viewModelFactory: GameViewModelFactory + + private lateinit var viewModel: GameViewModel + private lateinit var recyclerGrid: RecyclerView + private lateinit var bidirectionalScroll: UnlockedHorizontalScrollView + private lateinit var areaAdapter: AreaAdapter + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? = + inflater.inflate(R.layout.fragment_level, container, false) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + activity?.let { + viewModel = ViewModelProviders.of(it, viewModelFactory).get(GameViewModel::class.java) + areaAdapter = AreaAdapter(it.applicationContext, viewModel) + } + } + + override fun onPause() { + super.onPause() + + GlobalScope.launch { + viewModel.saveGame() + } + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + recyclerGrid = view.findViewById(R.id.recyclerGrid) + recyclerGrid.apply { + setHasFixedSize(true) + isNestedScrollingEnabled = false + adapter = areaAdapter + alpha = 0.0f + } + + bidirectionalScroll = view.findViewById(R.id.bidirectionalScroll) + bidirectionalScroll.setTarget(recyclerGrid) + + GlobalScope.launch { + val levelSetup = viewModel.onCreate(handleNewGameDeeplink()) + + val width = levelSetup.width + + withContext(Dispatchers.Main) { + recyclerGrid.layoutManager = + GridLayoutManager(activity, width, RecyclerView.VERTICAL, false) + + view.post { + recyclerGrid.scrollBy(0, recyclerGrid.height / 2) + bidirectionalScroll.scrollBy(recyclerGrid.width / 4, 0) + recyclerGrid.animate().apply { + alpha(1.0f) + duration = 1000 + }.start() + } + } + } + + viewModel.run { + field.observe(viewLifecycleOwner, Observer { + areaAdapter.bindField(it) + }) + levelSetup.observe(viewLifecycleOwner, Observer { + recyclerGrid.layoutManager = + GridLayoutManager(activity, it.width, RecyclerView.VERTICAL, false) + }) + fieldRefresh.observe(viewLifecycleOwner, Observer { + areaAdapter.notifyItemChanged(it) + }) + } + } + + private fun handleNewGameDeeplink(): DifficultyPreset? { + var result: DifficultyPreset? = null + + activity?.intent?.data?.let { uri -> + if (uri.scheme == DEFAULT_SCHEME) { + result = when (uri.schemeSpecificPart.removePrefix("//new-game/")) { + "beginner" -> DifficultyPreset.Beginner + "intermediate" -> DifficultyPreset.Intermediate + "expert" -> DifficultyPreset.Expert + "standard" -> DifficultyPreset.Standard + else -> null + } + } + } + + return result + } + + companion object { + const val DEFAULT_SCHEME = "antimine" + } +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/preferences/PreferencesActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/preferences/PreferencesActivity.kt new file mode 100644 index 00000000..6ec4e812 --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/preferences/PreferencesActivity.kt @@ -0,0 +1,29 @@ +package dev.lucasnlm.antimine.preferences + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import androidx.preference.PreferenceFragmentCompat +import androidx.preference.PreferenceManager + +import dev.lucasnlm.antimine.R + +class PreferencesActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + PreferenceManager.setDefaultValues(this, R.xml.preferences, false) + + // Load the preferences from an XML resource + supportFragmentManager + .beginTransaction() + .replace(android.R.id.content, PrefsFragment()) + .commitAllowingStateLoss() + } + + class PrefsFragment : PreferenceFragmentCompat() { + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.preferences) + } + } +} diff --git a/app/src/main/java/dev/lucasnlm/antimine/splash/SplashActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/splash/SplashActivity.kt new file mode 100644 index 00000000..bd56b95c --- /dev/null +++ b/app/src/main/java/dev/lucasnlm/antimine/splash/SplashActivity.kt @@ -0,0 +1,24 @@ +package dev.lucasnlm.antimine.splash + +import android.app.UiModeManager +import android.content.Intent +import android.content.res.Configuration +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import dev.lucasnlm.antimine.GameActivity +import dev.lucasnlm.antimine.TvGameActivity + +class SplashActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + val uiModeManager: UiModeManager = getSystemService(UI_MODE_SERVICE) as UiModeManager + if (uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) { + Intent(this, TvGameActivity::class.java).run { startActivity(this) } + } else { + Intent(this, GameActivity::class.java).run { startActivity(this) } + } + + finish() + } +} diff --git a/app/src/main/res/drawable/mine_white.xml b/app/src/main/res/drawable/mine_white.xml new file mode 100644 index 00000000..134dcbe0 --- /dev/null +++ b/app/src/main/res/drawable/mine_white.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml new file mode 100644 index 00000000..95783eab --- /dev/null +++ b/app/src/main/res/layout/activity_about.xml @@ -0,0 +1,59 @@ + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_game.xml b/app/src/main/res/layout/activity_game.xml new file mode 100644 index 00000000..0efdb71c --- /dev/null +++ b/app/src/main/res/layout/activity_game.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_text.xml b/app/src/main/res/layout/activity_text.xml new file mode 100644 index 00000000..fc15d49c --- /dev/null +++ b/app/src/main/res/layout/activity_text.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_third_party.xml b/app/src/main/res/layout/activity_third_party.xml new file mode 100644 index 00000000..24502a09 --- /dev/null +++ b/app/src/main/res/layout/activity_third_party.xml @@ -0,0 +1,31 @@ + + + + + + + + diff --git a/app/src/main/res/layout/activity_tv_game.xml b/app/src/main/res/layout/activity_tv_game.xml new file mode 100644 index 00000000..0a28d7a6 --- /dev/null +++ b/app/src/main/res/layout/activity_tv_game.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/dialog_custom_game.xml b/app/src/main/res/layout/dialog_custom_game.xml new file mode 100644 index 00000000..471c2c05 --- /dev/null +++ b/app/src/main/res/layout/dialog_custom_game.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/view_third_party.xml b/app/src/main/res/layout/view_third_party.xml new file mode 100644 index 00000000..70e1c29d --- /dev/null +++ b/app/src/main/res/layout/view_third_party.xml @@ -0,0 +1,21 @@ + + + + + + diff --git a/app/src/main/res/menu/top_menu_over.xml b/app/src/main/res/menu/top_menu_over.xml new file mode 100644 index 00000000..139eef97 --- /dev/null +++ b/app/src/main/res/menu/top_menu_over.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 00000000..31e31f84 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + 00:00 + \ No newline at end of file diff --git a/app/src/main/res/xml/backup_rules.xml b/app/src/main/res/xml/backup_rules.xml new file mode 100644 index 00000000..ff836a11 --- /dev/null +++ b/app/src/main/res/xml/backup_rules.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/xml/shortcuts.xml b/app/src/main/res/xml/shortcuts.xml new file mode 100644 index 00000000..b1c70720 --- /dev/null +++ b/app/src/main/res/xml/shortcuts.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..4b5d57ba --- /dev/null +++ b/build.gradle @@ -0,0 +1,40 @@ +buildscript { + ext.kotlin_version = '1.3.50' + + repositories { + mavenCentral() + jcenter() + google() + + maven { + url 'https://maven.fabric.io/public' + name 'Fabric' + } + } + + dependencies { + classpath 'com.android.tools.build:gradle:3.5.3' + + // noinspection GradleDynamicVersion + classpath 'io.fabric.tools:gradle:1.+' + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } +} + +allprojects { + repositories { + google() + jcenter() + + maven { + url 'https://jitpack.io' + } + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/common/.gitignore b/common/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/common/.gitignore @@ -0,0 +1 @@ +/build diff --git a/common/build.gradle b/common/build.gradle new file mode 100644 index 00000000..057e92a3 --- /dev/null +++ b/common/build.gradle @@ -0,0 +1,68 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-kapt' + +android { + compileSdkVersion 29 + + defaultConfig { + minSdkVersion 14 + targetSdkVersion 29 + versionCode 19 + versionName '3.0' + } + + kapt { + generateStubs true + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + // AndroidX + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.preference:preference:1.1.0' + implementation 'androidx.recyclerview:recyclerview:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + + // Lifecycle + api 'android.arch.lifecycle:extensions:1.1.1' + implementation "android.arch.lifecycle:viewmodel:1.1.1" + + // Amplitude + implementation 'com.amplitude:android-sdk:2.23.2' + + // Dagger + def dagger_version='2.21' + api "com.google.dagger:dagger-android:$dagger_version" + api "com.google.dagger:dagger-android-support:$dagger_version" + kapt "com.google.dagger:dagger-android-processor:$dagger_version" + kapt "com.google.dagger:dagger-compiler:$dagger_version" + + // Room + def room_version = '2.2.3' + api "androidx.room:room-runtime:$room_version" + api "androidx.room:room-ktx:$room_version" + kapt "androidx.room:room-compiler:$room_version" + testImplementation "androidx.room:room-testing:$room_version" + + // Moshi - Json + def moshi_version = '1.9.1' + api "com.squareup.moshi:moshi:$moshi_version" + api "com.squareup.moshi:moshi-kotlin:$moshi_version" + kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshi_version" + + // Coroutines + def coroutines_version = '1.3.0' + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" + + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50' + + testImplementation 'junit:junit:4.12' + testImplementation 'org.mockito:mockito-core:2.24.0' + testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0' + +} diff --git a/common/gradle/wrapper/gradle-wrapper.jar b/common/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..7a3265ee Binary files /dev/null and b/common/gradle/wrapper/gradle-wrapper.jar differ diff --git a/common/gradle/wrapper/gradle-wrapper.properties b/common/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..905919ca --- /dev/null +++ b/common/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon May 21 23:30:42 BRT 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/common/gradlew b/common/gradlew new file mode 100644 index 00000000..cccdd3d5 --- /dev/null +++ b/common/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/common/gradlew.bat b/common/gradlew.bat new file mode 100644 index 00000000..e95643d6 --- /dev/null +++ b/common/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/common/proguard-rules.pro b/common/proguard-rules.pro new file mode 100644 index 00000000..550dae22 --- /dev/null +++ b/common/proguard-rules.pro @@ -0,0 +1,47 @@ +# Project specific ProGuard rules + +# Crashlytics 2.+ +-keep class com.crashlytics.** { *; } +-keep class com.crashlytics.android.** +-keepattributes SourceFile, LineNumberTable, *Annotation* + +# For Fabric to properly de-obfuscate your crash reports, you need to remove this line from your ProGuard config: +-printmapping mapping.txt + +# support design +-dontwarn android.support.design.** +-keep class android.support.design.** { *; } +-keep interface android.support.design.** { *; } +-keep public class android.support.design.R$* { *; } + +# support v7 +-keep public class android.support.v7.widget.** { *; } +-keep public class android.support.v7.internal.widget.** { *; } +-keep public class android.support.v7.internal.view.menu.** { *; } + +-keep public class * extends android.support.v4.view.ActionProvider { + public (android.content.Context); +} + +# support v4 +-keep class android.support.v4.** { *; } +-keep interface android.support.v4.** { *; } + +# build config +-keep class com.example.BuildConfig { *; } + +# firebase +-keep class com.firebase.** { *; } + +# google gms +-keep class com.google.android.gms.** { *; } +-dontwarn com.google.android.gms.** + +# amplitude +-keep class com.google.android.gms.ads.** { *; } +-dontwarn okio.** + +# recycler view +-keep public class * extends android.support.v7.widget.RecyclerView$LayoutManager { + public (...); +} \ No newline at end of file diff --git a/common/src/main/AndroidManifest.xml b/common/src/main/AndroidManifest.xml new file mode 100644 index 00000000..7086a2af --- /dev/null +++ b/common/src/main/AndroidManifest.xml @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/GameModeFactory.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/GameModeFactory.kt new file mode 100644 index 00000000..72d05a82 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/GameModeFactory.kt @@ -0,0 +1,41 @@ +package dev.lucasnlm.antimine.common.level + +import dev.lucasnlm.antimine.common.level.data.DifficultyPreset +import dev.lucasnlm.antimine.common.level.data.LevelSetup +import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository + +object GameModeFactory { + fun fromDifficultyPreset( + difficulty: DifficultyPreset, + dimensionRepository: IDimensionRepository, + preferencesRepository: IPreferencesRepository + ): LevelSetup = + when (difficulty) { + DifficultyPreset.Standard -> calculateStandardMode(dimensionRepository) + DifficultyPreset.Beginner -> LevelSetup(9, 9, 10, difficulty) + DifficultyPreset.Intermediate -> LevelSetup(16, 16, 40, difficulty) + DifficultyPreset.Expert -> LevelSetup(24, 24, 99, difficulty) + DifficultyPreset.Custom -> preferencesRepository.customGameMode() + } + + private fun calculateStandardMode( + dimensionRepository: IDimensionRepository + ): LevelSetup { + val fieldSize = dimensionRepository.areaSize() + + val display = dimensionRepository.displaySize() + val width = display.widthPixels + val height = display.heightPixels + + val finalWidth = ((width / fieldSize).toInt() - 1).coerceAtLeast(6) + val finalHeight = ((height / fieldSize).toInt() - 3).coerceAtLeast(9) + + return LevelSetup( + finalWidth, + finalHeight, + (finalWidth * finalHeight * 0.2).toInt(), + DifficultyPreset.Standard + ) + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/LevelFacade.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/LevelFacade.kt new file mode 100644 index 00000000..7277b5e5 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/LevelFacade.kt @@ -0,0 +1,264 @@ +package dev.lucasnlm.antimine.common.level + +import dev.lucasnlm.antimine.common.level.data.LevelSetup +import dev.lucasnlm.antimine.common.level.data.Area +import dev.lucasnlm.antimine.common.level.data.GameStats +import dev.lucasnlm.antimine.common.level.data.Mark +import dev.lucasnlm.antimine.common.level.database.data.Save +import dev.lucasnlm.antimine.common.level.database.data.SaveStatus +import java.util.* +import kotlin.math.floor + +class LevelFacade { + private val levelSetup: LevelSetup + private val randomGenerator: Random + private var saveId = 0 + private val startTime = System.currentTimeMillis() + + var hasMines = false + private set + + var seed = 0L + private set + + lateinit var field: Sequence + private set + + private var mines: Sequence = sequenceOf() + + constructor(gameId: Int, levelSetup: LevelSetup, seed: Long = randomSeed()) { + this.saveId = gameId + this.levelSetup = levelSetup + this.randomGenerator = Random().apply { setSeed(seed) } + this.seed = seed + createEmptyField() + } + + constructor(save: Save) { + this.saveId = save.uid + this.levelSetup = save.levelSetup + this.randomGenerator = Random().apply { setSeed(save.seed) } + this.field = save.field.asSequence() + this.hasMines = this.field.firstOrNull { it.hasMine }?.hasMine ?: false + this.mines = this.field.filter { it.hasMine }.asSequence() + } + + private fun createEmptyField() { + val width = levelSetup.width + val height = levelSetup.height + val fieldSize = width * height + this.field = (0 until fieldSize).map { index -> + val yPosition = floor((index / width).toDouble()).toInt() + val xPosition = (index % width) + Area(index, xPosition, yPosition) + }.asSequence() + } + + private fun getArea(id: Int) = field.first { it.id == id } + + fun switchMarkAt(index: Int): Boolean { + val changed: Boolean + getArea(index).apply { + changed = isCovered + if (isCovered) { + mark = when (mark) { + Mark.None -> Mark.Flag + Mark.Flag -> Mark.Question + Mark.Question -> Mark.None + } + } + } + return changed + } + + fun removeMark(index: Int) { + getArea(index).apply { + mark = Mark.None + } + } + + fun hasCoverOn(index: Int): Boolean = getArea(index).isCovered + + fun hasMarkOn(index: Int): Boolean = getArea(index).mark != Mark.None + + fun hasMineOn(index: Int): Boolean = getArea(index).hasMine + + fun plantMinesExcept(index: Int, includeSafeArea: Boolean = false) { + plantRandomMines(index, includeSafeArea) + putMinesTips() + hasMines = true + } + + private fun plantRandomMines(ignoreIndex: Int, includeSafeArea: Boolean) { + getArea(ignoreIndex).run { + safeZone = true + + if (includeSafeArea) { + findNeighbors().forEach { + it.safeZone = true + } + } + } + + field.filterNot { it.safeZone } + .toSet() + .shuffled(randomGenerator) + .take(levelSetup.mines) + .forEach { it.hasMine = true } + mines = field.filter { it.hasMine }.asSequence() + } + + private fun putMinesTips() { + field.forEach { + it.minesAround = if (it.hasMine) 0 else it.findNeighbors().filter { neighbor -> + neighbor.hasMine + }.count() + } + } + + /** + * Run "Flood Fill algorithm" to open all empty neighbors of a target area. + */ + fun openField(target: Area): Boolean { + val result: Boolean = target.isCovered + + if (target.isCovered) { + target.isCovered = false + target.mark = Mark.None + + if (target.minesAround == 0 && !target.hasMine) { + target.findNeighbors().forEach { openField(it) } + } + + if (target.hasMine) { + target.mistake = true + } + } + + return result + } + + fun turnOffAllHighlighted() { + field.forEach { + it.highlighted = false + } + } + + private fun toggleHighlight(target: Area) { + target.highlighted = !target.highlighted + target.findNeighbors() + .filter { it.mark == Mark.None && it.isCovered } + .forEach { + it.highlighted = !it.highlighted + } + } + + fun clickArea(index: Int): Boolean = getArea(index).let { + when { + it.isCovered -> { + openField(getArea(index)) + } + it.minesAround != 0 -> { + toggleHighlight(it) + true + } + else -> { + false + } + } + } + + fun openNeighbors(index: Int): List = + getArea(index) + .findNeighbors() + .filter { + it.mark == Mark.None + } + .map{ + openField(it) + it.id + } + + fun runFlagAssistant() { + mines.filter { it.mark == Mark.None }.forEach { field -> + val neighbors = field.findNeighbors() + val neighborsCount = neighbors.count() + val revealedNeighborsCount = neighbors.filter { neighbor -> + !neighbor.isCovered || (neighbor.hasMine && neighbor.mark == Mark.Flag) + }.count() + + field.mark = if (revealedNeighborsCount == neighborsCount) Mark.Flag else Mark.None + } + } + + fun getStats() = GameStats( + mines.filter { !it.mistake && it.mark == Mark.Flag }.count(), + mines.count(), + field.count() + ) + + fun showAllMines() { + mines.filter { it.mark != Mark.Flag }.forEach { it.isCovered = false } + } + + fun showWrongFlags() { + field.filter { it.mark != Mark.None && !it.hasMine }.forEach { it.mistake = true } + } + + fun revealAllEmptyAreas() { + field.filter { !it.hasMine }.forEach { it.isCovered = false } + } + + fun hasAnyMineExploded(): Boolean = mines.firstOrNull { it.mistake } != null + + fun hasFlaggedAllMines(): Boolean = rightFlags() == levelSetup.mines + + fun hasIsolatedAllMines() = + mines.map { + val neighbors = it.findNeighbors() + val neighborsCount = neighbors.count() + val isolatedNeighborsCount = neighbors.filter { neighbor -> + !neighbor.isCovered || neighbor.hasMine + }.count() + neighborsCount == isolatedNeighborsCount + }.filterNot { it }.count() == 0 + + private fun rightFlags() = mines.count { it.mark == Mark.Flag } + + fun checkVictory(): Boolean = + hasFlaggedAllMines() && hasIsolatedAllMines() && !hasAnyMineExploded() + + fun remainingMines(): Int { + val flagsCount = field.count { it.mark == Mark.Flag } + val minesCount = mines.count() + return (minesCount - flagsCount).coerceAtLeast(0) + } + + private fun Area.findNeighbors() = arrayOf( + getNeighbor(1, 0), + getNeighbor(1, 1), + getNeighbor(0, 1), + getNeighbor(-1, 1), + getNeighbor(-1, 0), + getNeighbor(-1, -1), + getNeighbor(0, -1), + getNeighbor(1, -1) + ).filterNotNull() + + private fun Area.getNeighbor(x: Int, y: Int) = field.firstOrNull { + (it.posX == this.posX + x) && (it.posY == this.posY + y) + } + + fun getSaveState(): Save { + val saveStatus: SaveStatus = when { + checkVictory() -> SaveStatus.VICTORY + hasAnyMineExploded() -> SaveStatus.DEFEAT + else -> SaveStatus.ON_GOING + } + return Save(saveId, seed, startTime, 0L, levelSetup, saveStatus, field.toList()) + } + + companion object { + fun randomSeed(): Long = Random().nextLong() + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/AmbientSettings.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/AmbientSettings.kt new file mode 100644 index 00000000..b06d2a17 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/AmbientSettings.kt @@ -0,0 +1,6 @@ +package dev.lucasnlm.antimine.common.level.data + +data class AmbientSettings( + val isAmbientMode: Boolean = false, + val isLowBitAmbient: Boolean = false +) diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Area.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Area.kt new file mode 100644 index 00000000..8fe1f7b9 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Area.kt @@ -0,0 +1,14 @@ +package dev.lucasnlm.antimine.common.level.data + +data class Area( + val id: Int, + val posX: Int, + val posY: Int, + var minesAround: Int = 0, + var safeZone: Boolean = false, + var hasMine: Boolean = false, + var mistake: Boolean = false, + var isCovered: Boolean = true, + var mark: Mark = Mark.None, + var highlighted: Boolean = false +) diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/DifficultyPreset.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/DifficultyPreset.kt new file mode 100644 index 00000000..d05801c8 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/DifficultyPreset.kt @@ -0,0 +1,9 @@ +package dev.lucasnlm.antimine.common.level.data + +enum class DifficultyPreset(val text: String) { + Standard("STANDARD"), + Beginner("BEGINNER"), + Intermediate("INTERMEDIATE"), + Expert("EXPERT"), + Custom("CUSTOM") +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/GameEvent.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/GameEvent.kt new file mode 100644 index 00000000..1df3ae37 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/GameEvent.kt @@ -0,0 +1,13 @@ +package dev.lucasnlm.antimine.common.level.data + +enum class GameEvent { + StartNewGame, + ResumeGame, + ResumeGameOver, + ResumeVictory, + Pause, + Resume, + Running, + Victory, + GameOver +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/GameStats.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/GameStats.kt new file mode 100644 index 00000000..b5182a9b --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/GameStats.kt @@ -0,0 +1,7 @@ +package dev.lucasnlm.antimine.common.level.data + +data class GameStats( + val rightMines: Int, + val totalMines: Int, + val totalArea: Int +) diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/GameStatus.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/GameStatus.kt new file mode 100644 index 00000000..8c163ef5 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/GameStatus.kt @@ -0,0 +1,7 @@ +package dev.lucasnlm.antimine.common.level.data + +enum class GameStatus { + PreGame, + Running, + Over +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/LevelSetup.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/LevelSetup.kt new file mode 100644 index 00000000..73bc0dc2 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/LevelSetup.kt @@ -0,0 +1,8 @@ +package dev.lucasnlm.antimine.common.level.data + +data class LevelSetup( + val width: Int, + val height: Int, + val mines: Int, + val preset: DifficultyPreset = DifficultyPreset.Custom +) diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Mark.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Mark.kt new file mode 100644 index 00000000..51eea9ec --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Mark.kt @@ -0,0 +1,11 @@ +package dev.lucasnlm.antimine.common.level.data + +enum class Mark { + None, + Flag, + Question +} + +fun Mark.isFlag(): Boolean = this == Mark.Flag + +fun Mark.isQuestion(): Boolean = this == Mark.Question \ No newline at end of file diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/AppDataBase.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/AppDataBase.kt new file mode 100644 index 00000000..070767a1 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/AppDataBase.kt @@ -0,0 +1,24 @@ +package dev.lucasnlm.antimine.common.level.database + +import androidx.room.Database +import androidx.room.RoomDatabase +import androidx.room.TypeConverters +import dev.lucasnlm.antimine.common.level.database.converters.FieldConverter +import dev.lucasnlm.antimine.common.level.database.converters.LevelSetupConverter +import dev.lucasnlm.antimine.common.level.database.converters.SaveStatusConverter +import dev.lucasnlm.antimine.common.level.database.dao.SaveDao +import dev.lucasnlm.antimine.common.level.database.data.Save + +@Database( + entities = [ + Save::class + ], version = 1, exportSchema = false +) +@TypeConverters( + FieldConverter::class, + SaveStatusConverter::class, + LevelSetupConverter::class +) +abstract class AppDataBase : RoomDatabase() { + abstract fun userDao(): SaveDao +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/FieldConverter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/FieldConverter.kt new file mode 100644 index 00000000..b7b94867 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/FieldConverter.kt @@ -0,0 +1,25 @@ +package dev.lucasnlm.antimine.common.level.database.converters + +import androidx.room.TypeConverter +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import com.squareup.moshi.Types +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory +import dev.lucasnlm.antimine.common.level.data.Area +import java.lang.reflect.Type + +class FieldConverter { + private val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build() + private val jsonAdapter: JsonAdapter> + + init { + val type: Type = Types.newParameterizedType(List::class.java, Area::class.java) + this.jsonAdapter = moshi.adapter(type) + } + + @TypeConverter + fun toAreaList(jsonInput: String): List = jsonAdapter.fromJson(jsonInput) ?: listOf() + + @TypeConverter + fun toJsonString(field: List): String = jsonAdapter.toJson(field) +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/LevelSetupConverter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/LevelSetupConverter.kt new file mode 100644 index 00000000..39ef8e30 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/LevelSetupConverter.kt @@ -0,0 +1,24 @@ +package dev.lucasnlm.antimine.common.level.database.converters + +import androidx.room.TypeConverter +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory +import dev.lucasnlm.antimine.common.level.data.DifficultyPreset +import dev.lucasnlm.antimine.common.level.data.LevelSetup + +class LevelSetupConverter { + private val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build() + private val jsonAdapter: JsonAdapter + + init { + this.jsonAdapter = moshi.adapter(LevelSetup::class.java) + } + + @TypeConverter + fun toLevelSetup(jsonInput: String): LevelSetup = + jsonAdapter.fromJson(jsonInput) ?: LevelSetup(9, 9, 10, DifficultyPreset.Beginner) + + @TypeConverter + fun toJsonString(field: LevelSetup): String = jsonAdapter.toJson(field) +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/SaveStatusConverter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/SaveStatusConverter.kt new file mode 100644 index 00000000..f847b023 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/SaveStatusConverter.kt @@ -0,0 +1,19 @@ +package dev.lucasnlm.antimine.common.level.database.converters + +import androidx.room.TypeConverter +import dev.lucasnlm.antimine.common.level.database.data.SaveStatus + +class SaveStatusConverter { + + @TypeConverter + fun toSaveStatus(status: Int): SaveStatus = + when (status) { + 0 -> SaveStatus.ON_GOING + 1 -> SaveStatus.VICTORY + 2 -> SaveStatus.DEFEAT + else -> throw IllegalArgumentException("Could not recognize SaveStatus") + } + + @TypeConverter + fun toInteger(status: SaveStatus): Int = status.code +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/dao/SaveDao.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/dao/SaveDao.kt new file mode 100644 index 00000000..7743a8ba --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/dao/SaveDao.kt @@ -0,0 +1,28 @@ +package dev.lucasnlm.antimine.common.level.database.dao + +import androidx.room.* +import dev.lucasnlm.antimine.common.level.database.data.Save + +@Dao +interface SaveDao { + @Query("SELECT * FROM save") + fun getAll(): List + + @Query("SELECT * FROM save WHERE uid IN (:gameIds)") + fun loadAllByIds(gameIds: IntArray): List + + @Query("SELECT * FROM save WHERE uid = :gameId LIMIT 1") + fun loadById(gameId: Int): Save + + @Query("SELECT * FROM save ORDER BY uid DESC LIMIT 1") + fun loadCurrent(): Save? + + @Query("SELECT count(uid) FROM save") + fun getSaveCounts(): Int + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insertAll(vararg saves: Save): Array + + @Delete + fun delete(save: Save) +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/data/Save.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/data/Save.kt new file mode 100644 index 00000000..01ffcdb6 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/data/Save.kt @@ -0,0 +1,36 @@ +package dev.lucasnlm.antimine.common.level.database.data + +import androidx.room.* +import dev.lucasnlm.antimine.common.level.data.Area +import dev.lucasnlm.antimine.common.level.data.LevelSetup +import dev.lucasnlm.antimine.common.level.database.converters.FieldConverter +import dev.lucasnlm.antimine.common.level.database.converters.SaveStatusConverter + +@Entity +data class Save( + @PrimaryKey(autoGenerate = true) + val uid: Int, + + @ColumnInfo(name = "seed") + val seed: Long, + + @ColumnInfo(name = "date") + val startDate: Long, + + @ColumnInfo(name = "duration") + val duration: Long, + + @ColumnInfo(name = "width") + val levelSetup: LevelSetup, + + @TypeConverters(SaveStatusConverter::class) + @ColumnInfo(name = "status") + val status: SaveStatus, + + @TypeConverters(FieldConverter::class) + @ColumnInfo(name = "field") + val field: List +) + + + diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/data/SaveStatus.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/data/SaveStatus.kt new file mode 100644 index 00000000..d8af3be6 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/data/SaveStatus.kt @@ -0,0 +1,11 @@ +package dev.lucasnlm.antimine.common.level.database.data + +import androidx.room.TypeConverters +import dev.lucasnlm.antimine.common.level.database.converters.SaveStatusConverter + +@TypeConverters(SaveStatusConverter::class) +enum class SaveStatus constructor(val code: Int) { + ON_GOING(0), + VICTORY(1), + DEFEAT(2) +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/di/LevelComponent.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/di/LevelComponent.kt new file mode 100644 index 00000000..2f336859 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/di/LevelComponent.kt @@ -0,0 +1,18 @@ +package dev.lucasnlm.antimine.common.level.di + +import dagger.Component +import dagger.android.support.AndroidSupportInjectionModule + +@Component( + modules = [ + AndroidSupportInjectionModule::class, + LevelModule::class + ] +) +abstract class LevelComponent { + @Component.Builder + interface Builder { + fun levelModule(levelModule: LevelModule): Builder + fun build(): LevelComponent + } +} 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 new file mode 100644 index 00000000..9c40baa0 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/di/LevelModule.kt @@ -0,0 +1,73 @@ +package dev.lucasnlm.antimine.common.level.di + +import android.app.Application +import android.content.Context +import androidx.lifecycle.MutableLiveData +import androidx.room.Room +import dagger.Module +import dagger.Provides +import dev.lucasnlm.antimine.common.level.data.GameEvent +import dev.lucasnlm.antimine.common.level.database.AppDataBase +import dev.lucasnlm.antimine.common.level.database.dao.SaveDao +import dev.lucasnlm.antimine.common.level.repository.DimensionRepository +import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository +import dev.lucasnlm.antimine.common.level.repository.ISavesRepository +import dev.lucasnlm.antimine.common.level.repository.SavesRepository +import dev.lucasnlm.antimine.common.level.utils.Clock +import dev.lucasnlm.antimine.common.level.utils.HapticFeedbackInteractor +import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackInteractor +import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory +import dev.lucasnlm.antimine.core.analytics.AnalyticsManager +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository + +@Module +class LevelModule { + @Provides + fun provideGameEventObserver(): MutableLiveData = MutableLiveData() + + @Provides + fun provideClock(): Clock = Clock() + + @Provides + fun provideGameViewModelFactory( + application: Application, + gameEventObserver: MutableLiveData, + savesRepository: ISavesRepository, + dimensionRepository: IDimensionRepository, + preferencesRepository: IPreferencesRepository, + hapticFeedbackInteractor: IHapticFeedbackInteractor, + analyticsManager: AnalyticsManager, + clock: Clock + ) = GameViewModelFactory( + application, gameEventObserver, savesRepository, + dimensionRepository, preferencesRepository, hapticFeedbackInteractor, analyticsManager, clock + ) + + @Provides + fun provideDimensionRepository( + context: Context, + preferencesRepository: IPreferencesRepository + ): IDimensionRepository = + DimensionRepository(context, preferencesRepository) + + @Provides + fun provideDataBase(application: Application): AppDataBase = + Room.databaseBuilder(application, AppDataBase::class.java, DATA_BASE_NAME).build() + + @Provides + fun provideSaveDao(appDataBase: AppDataBase): SaveDao = appDataBase.userDao() + + @Provides + fun provideSavesRepository(saveDao: SaveDao): ISavesRepository = SavesRepository(saveDao) + + @Provides + fun provideHapticFeedbackInteractor( + application: Application, + preferencesRepository: IPreferencesRepository + ): IHapticFeedbackInteractor = + HapticFeedbackInteractor(application, preferencesRepository) + + companion object { + const val DATA_BASE_NAME = "saves-db" + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/DimensionRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/DimensionRepository.kt new file mode 100644 index 00000000..66c053a0 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/DimensionRepository.kt @@ -0,0 +1,38 @@ +package dev.lucasnlm.antimine.common.level.repository + +import android.content.Context +import android.content.res.Resources +import android.content.res.TypedArray +import android.util.DisplayMetrics +import dev.lucasnlm.antimine.common.R +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository + +interface IDimensionRepository { + fun areaSize(): Float + fun displaySize(): DisplayMetrics + fun actionBarSize(): Int +} + +class DimensionRepository( + private val context: Context, + private val preferencesRepository: IPreferencesRepository +) : IDimensionRepository { + + override fun areaSize(): Float = if (preferencesRepository.useLargeAreas()) { + context.resources.getDimension(R.dimen.accessible_field_size) + } else { + context.resources.getDimension(R.dimen.field_size) + } + + override fun displaySize(): DisplayMetrics = Resources.getSystem().displayMetrics + + override fun actionBarSize(): Int { + val styledAttributes: TypedArray = + context.theme.obtainStyledAttributes( + IntArray(1) { android.R.attr.actionBarSize } + ) + val actionBarSize: Int = styledAttributes.getDimension(0, 0.0f).toInt() + styledAttributes.recycle() + return actionBarSize + } +} \ No newline at end of file diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/DrawableRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/DrawableRepository.kt new file mode 100644 index 00000000..c6f709d9 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/DrawableRepository.kt @@ -0,0 +1,44 @@ +package dev.lucasnlm.antimine.common.level.repository + +import android.content.Context +import android.graphics.drawable.Drawable +import androidx.core.content.ContextCompat +import dev.lucasnlm.antimine.common.R + +class DrawableRepository { + private var flag: Drawable? = null + private var redFlag: Drawable? = null + private var mineExploded: Drawable? = null + private var mine: Drawable? = null + private var mineLow: Drawable? = null + private var question: Drawable? = null + + fun provideFlagDrawable(context: Context) = + flag ?: ContextCompat.getDrawable(context, R.drawable.flag).also { flag = it } + + fun provideRedFlagDrawable(context: Context) = + redFlag ?: ContextCompat.getDrawable(context, R.drawable.red_flag).also { redFlag = it } + + fun provideQuestionDrawable(context: Context) = + question ?: ContextCompat.getDrawable(context, R.drawable.question).also { question = it } + + fun provideMineExploded(context: Context) = + mineExploded ?: ContextCompat.getDrawable( + context, + R.drawable.mine_exploded + ).also { mineExploded = it } + + fun provideMine(context: Context) = + mine ?: ContextCompat.getDrawable(context, R.drawable.mine).also { mine = it } + + fun provideMineLow(context: Context) = + mineLow ?: ContextCompat.getDrawable(context, R.drawable.mine_low).also { mineLow = it } + + fun free() { + flag = null + mineExploded = null + mine = null + mineLow = null + question = null + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/SavesRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/SavesRepository.kt new file mode 100644 index 00000000..e276c9d9 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/repository/SavesRepository.kt @@ -0,0 +1,22 @@ +package dev.lucasnlm.antimine.common.level.repository + +import dev.lucasnlm.antimine.common.level.database.dao.SaveDao +import dev.lucasnlm.antimine.common.level.database.data.Save +import javax.inject.Inject + +interface ISavesRepository { + suspend fun getNewSaveId(): Int + suspend fun fetchCurrentSave(): Save? + suspend fun saveGame(save: Save): Long? +} + +class SavesRepository @Inject constructor( + private val savesDao: SaveDao +) : ISavesRepository { + + override suspend fun getNewSaveId(): Int = savesDao.getSaveCounts() + 1 + + override suspend fun fetchCurrentSave(): Save? = savesDao.loadCurrent() + + override suspend fun saveGame(save: Save) = savesDao.insertAll(save).firstOrNull() +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/utils/Clock.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/utils/Clock.kt new file mode 100644 index 00000000..079df170 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/utils/Clock.kt @@ -0,0 +1,39 @@ +package dev.lucasnlm.antimine.common.level.utils + +import java.util.Timer +import java.util.TimerTask + +class Clock { + private var elapsedTimeSeconds: Long = 0 + private var timer: Timer? = null + + val isStopped: Boolean + get() = (timer == null) + + fun reset(initialValue: Long = 0L) { + stop() + this.elapsedTimeSeconds = initialValue + } + + fun time() = elapsedTimeSeconds + + fun stop() { + timer?.apply { + cancel() + purge() + } + timer = null + } + + fun start(onTick: (seconds: Long) -> Unit) { + stop() + timer = Timer().apply { + scheduleAtFixedRate(object : TimerTask() { + override fun run() { + elapsedTimeSeconds++ + onTick(elapsedTimeSeconds) + } + }, 1000L, 1000L) + } + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/utils/HapticFeedbackInteractor.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/utils/HapticFeedbackInteractor.kt new file mode 100644 index 00000000..b24255ce --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/utils/HapticFeedbackInteractor.kt @@ -0,0 +1,44 @@ +package dev.lucasnlm.antimine.common.level.utils + +import android.app.Application +import android.content.Context.VIBRATOR_SERVICE +import android.os.Build +import android.os.VibrationEffect +import android.os.Vibrator +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository + +interface IHapticFeedbackInteractor { + fun toggleFlagFeedback() + fun explosionFeedback() +} + +class HapticFeedbackInteractor( + application: Application, + private val preferencesRepository: IPreferencesRepository +) : IHapticFeedbackInteractor { + private val vibrator: Vibrator = application.getSystemService(VIBRATOR_SERVICE) as Vibrator + + override fun toggleFlagFeedback() { + if (preferencesRepository.useHapticFeedback()) { + vibrateTo(70, 240) + vibrateTo(10, 100) + } + } + + override fun explosionFeedback() { + if (preferencesRepository.useHapticFeedback()) { + vibrateTo(400, -1) + } + } + + private fun vibrateTo(time: Long, amplitude: Int) { + if (Build.VERSION.SDK_INT >= 26) { + vibrator.vibrate( + VibrationEffect.createOneShot(time, amplitude) + ) + } else { + @Suppress("DEPRECATION") + vibrator.vibrate(time) + } + } +} 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 new file mode 100644 index 00000000..4142247a --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt @@ -0,0 +1,109 @@ +package dev.lucasnlm.antimine.common.level.view + +import android.content.Context +import android.graphics.Paint +import android.graphics.RectF +import android.graphics.Typeface +import android.util.Log +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import dev.lucasnlm.antimine.common.R +import dev.lucasnlm.antimine.common.level.data.Area +import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel + +class AreaAdapter( + context: Context, + private val viewModel: GameViewModel +) : RecyclerView.Adapter() { + + private var field = listOf() + private var isLowBitAmbient = false + private var isAmbientMode = false + private val paintSettings: AreaPaintSettings + + private val clickEnabled: Boolean + get() = viewModel.isGameActive() + + init { + setHasStableIds(true) + paintSettings = createAreaPaintSettings(context, viewModel.useAccessibilityMode()) + } + + fun setAmbientMode(isAmbientMode: Boolean, isLowBitAmbient: Boolean) { + this.isLowBitAmbient = isLowBitAmbient + this.isAmbientMode = isAmbientMode + } + + fun bindField(area: List) { + this.field = area + notifyDataSetChanged() + } + + override fun getItemCount() = field.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FieldViewHolder { + val layout = if (viewModel.useAccessibilityMode()) { R.layout.view_accessibility_field } else { R.layout.view_field } + val view = LayoutInflater.from(parent.context).inflate(layout, parent, false) + val holder = FieldViewHolder(view) + + holder.itemView.setOnLongClickListener { target -> + target.requestFocus() + + val position = holder.adapterPosition + if (position == RecyclerView.NO_POSITION) { + Log.d(TAG, "Item no longer exists.") + } else if (clickEnabled) { + viewModel.onLongClick(position) + } + + true + } + + holder.itemView.setOnClickListener { + val position = holder.adapterPosition + if (position == RecyclerView.NO_POSITION) { + Log.d(TAG, "Item no longer exists.") + } else if (clickEnabled) { + viewModel.onClickArea(position) + } + } + + return holder + } + + private fun getItem(position: Int) = field[position] + + override fun getItemId(position: Int): Long = getItem(position).id.toLong() + + override fun onBindViewHolder(holder: FieldViewHolder, position: Int) { + val field = getItem(position) + holder.areaView.bindField(field, isAmbientMode, isLowBitAmbient, paintSettings) + } + + companion object { + private const val TAG = "AreaAdapter" + + private fun createAreaPaintSettings(context: Context, useLargeArea: Boolean): AreaPaintSettings { + val resources = context.resources + val padding = resources.getDimension(R.dimen.field_padding) + val size = if (useLargeArea) { + resources.getDimension(R.dimen.accessible_field_size).toInt() + } else { + resources.getDimension(R.dimen.field_size).toInt() + } + 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(padding, padding, size - padding, size - padding), + resources.getDimension(R.dimen.field_radius) + ) + } + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPaintSettings.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPaintSettings.kt new file mode 100644 index 00000000..340f1e39 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPaintSettings.kt @@ -0,0 +1,11 @@ +package dev.lucasnlm.antimine.common.level.view + +import android.graphics.Paint +import android.graphics.RectF + +data class AreaPaintSettings( + val painter: Paint, + val rectF: RectF, + val radius: Float +) + 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 new file mode 100755 index 00000000..65b9d172 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt @@ -0,0 +1,273 @@ +package dev.lucasnlm.antimine.common.level.view + +import android.annotation.SuppressLint +import android.content.Context +import android.graphics.* +import androidx.core.content.ContextCompat +import android.util.AttributeSet +import android.view.View +import dev.lucasnlm.antimine.common.level.data.Area +import android.graphics.RectF +import dev.lucasnlm.antimine.common.level.repository.DrawableRepository +import android.util.TypedValue +import android.graphics.drawable.Drawable +import android.os.Build +import androidx.core.view.ViewCompat +import dev.lucasnlm.antimine.common.R +import dev.lucasnlm.antimine.common.level.data.Mark + +class AreaView : View { + private var covered = true + private var minesAround: Int = -1 + private var mark = Mark.None + private var hasMine = false + private var mistake = false + private var isAmbientMode = false + private var isLowBitAmbient = false + private var highlighted = false + + private lateinit var paintSettings: AreaPaintSettings + private val drawableRepository = DrawableRepository() + + constructor(context: Context) + : super(context) + + constructor(context: Context, attrs: AttributeSet?) + : super(context, attrs) + + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) + : super(context, attrs, defStyleAttr) + + fun bindField(area: Area, isAmbientMode: Boolean, isLowBitAmbient: Boolean, paintSettings: AreaPaintSettings) { + this.paintSettings = paintSettings + minesAround = if (covered) -1 else area.minesAround + + bindContentDescription(area) + + val changed = arrayOf( + this.isAmbientMode != isAmbientMode, + covered != area.isCovered, + minesAround != area.minesAround, + mark != area.mark, + hasMine != area.hasMine, + mistake != area.mistake, + minesAround != area.minesAround, + highlighted != area.highlighted + ).find { it } ?: false + + // Used on Wear OS + this.isAmbientMode = isAmbientMode + this.isLowBitAmbient = isLowBitAmbient + + paintSettings.painter.isAntiAlias = !isAmbientMode || isAmbientMode && !isLowBitAmbient + + covered = area.isCovered + mark = area.mark + hasMine = area.hasMine + mistake = area.mistake + minesAround = area.minesAround + highlighted = area.highlighted + if (Build.VERSION.SDK_INT >= 23) { + this.foreground = when { + !isAmbientMode && covered -> getRippleEffect(context) + else -> null + } + } + + if (changed) { + invalidate() + } + } + + @SuppressLint("InlinedApi") + private fun bindContentDescription(area: Area) { + contentDescription = when { + area.mark == Mark.Flag -> { + context.getString(if (area.mistake) R.string.desc_wrongly_marked_area else R.string.desc_marked_area) + } + area.mark == Mark.Question -> context.getString(R.string.desc_marked_area) + area.isCovered -> context.getString(R.string.desc_convered_area) + !area.isCovered && area.minesAround > 0 -> area.minesAround.toString() + !area.isCovered && area.hasMine -> context.getString(R.string.exploded_mine) + else -> "" + } + + ViewCompat.setImportantForAccessibility( + this, + when { + area.minesAround != 0 -> IMPORTANT_FOR_ACCESSIBILITY_YES + area.hasMine -> IMPORTANT_FOR_ACCESSIBILITY_YES + area.mistake -> IMPORTANT_FOR_ACCESSIBILITY_YES + area.mark != Mark.None -> IMPORTANT_FOR_ACCESSIBILITY_YES + !area.isCovered -> IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS + else -> IMPORTANT_FOR_ACCESSIBILITY_YES + } + ) + } + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + + paintSettings.run { + if (isAmbientMode) { + setBackgroundResource(android.R.color.black) + } else { + setBackgroundResource(android.R.color.transparent) + } + + if (covered) { + if (isAmbientMode) { + painter.apply { + style = Paint.Style.STROKE + strokeWidth = 2.0f + isAntiAlias = !isLowBitAmbient + color = ContextCompat.getColor(context, android.R.color.white) + } + } else { + painter.apply { + style = Paint.Style.FILL + isAntiAlias = !isLowBitAmbient + color = ContextCompat.getColor(context, R.color.view_cover) + alpha = if(highlighted) 155 else 255 + } + } + + painter.run { + canvas.drawRoundRect(rectF, radius, radius, this) + } + + when (mark) { + Mark.Flag -> { + val padding = resources.getDimension(R.dimen.mark_padding).toInt() + + val flag = if (mistake) { + drawableRepository.provideRedFlagDrawable(context) + } else { + drawableRepository.provideFlagDrawable(context) + } + + flag?.setBounds( + rectF.left.toInt() + padding, + rectF.top.toInt() + padding, + rectF.right.toInt() - padding, + rectF.bottom.toInt() - padding + ) + flag?.draw(canvas) + } + Mark.Question -> { + val question = drawableRepository.provideQuestionDrawable(context) + + question?.setBounds( + rectF.left.toInt(), + rectF.top.toInt(), + rectF.right.toInt(), + rectF.bottom.toInt() + ) + question?.draw(canvas) + } + else -> {} + } + } else { + if (isAmbientMode) { + painter.apply { + style = Paint.Style.STROKE + strokeWidth = 0.5f + isAntiAlias = !isLowBitAmbient + color = ContextCompat.getColor(context, android.R.color.white) + } + } else { + painter.apply { + style = Paint.Style.FILL + isAntiAlias = !isLowBitAmbient + color = ContextCompat.getColor(context, R.color.view_clean) + } + } + + painter.run { + canvas.drawRoundRect(rectF, radius, radius, this) + } + + if (hasMine) { + val mine = when { + isAmbientMode -> drawableRepository.provideMineLow(context) + mistake -> drawableRepository.provideMineExploded(context) + else -> drawableRepository.provideMine(context) + } + + mine?.setBounds( + rectF.left.toInt(), + rectF.top.toInt(), + rectF.right.toInt(), + rectF.bottom.toInt() + ) + mine?.draw(canvas) + } else if (minesAround > 0) { + val color = if (isAmbientMode) { + R.color.ambient_color_white + } else { + when (minesAround) { + 1 -> R.color.mines_arround_1 + 2 -> R.color.mines_arround_2 + 3 -> R.color.mines_arround_3 + 4 -> R.color.mines_arround_4 + 5 -> R.color.mines_arround_5 + 6 -> R.color.mines_arround_6 + 7 -> R.color.mines_arround_7 + else -> R.color.mines_arround_8 + } + } + + painter.color = ContextCompat.getColor(context, color) + drawText(canvas, painter, minesAround.toString()) + } + + if (highlighted) { + painter.apply { + style = Paint.Style.STROKE + strokeWidth = 2.0f + isAntiAlias = !isLowBitAmbient + color = if (isAmbientMode) { + ContextCompat.getColor(context, R.color.white) + } else { + ContextCompat.getColor(context, R.color.highlight) + } + + canvas.drawRoundRect(rectF, radius, radius, this) + } + } + } + + if (isFocused) { + painter.apply { + style = Paint.Style.STROKE + strokeWidth = 4f + isAntiAlias = !isLowBitAmbient + color = ContextCompat.getColor(context, android.R.color.holo_orange_dark) + } + + canvas.drawRoundRect(rectF, radius, radius, painter) + } + } + } + + private fun getRippleEffect(context: Context): Drawable? { + val outValue = TypedValue() + context.theme.resolveAttribute( + android.R.attr.selectableItemBackground, outValue, true + ) + return ContextCompat.getDrawable(context, outValue.resourceId) + } + + private fun drawText(canvas: Canvas, paint: Paint, text: String) { + paintSettings.run { + val bounds = RectF(rectF).apply { + right = paint.measureText(text, 0, text.length) + bottom = paint.descent() - paint.ascent() + left += (rectF.width() - right) / 2.0f + top += (rectF.height() - bottom) / 2.0f + } + + canvas.drawText(text, rectF.width() * 0.5f, bounds.top - paint.ascent(), paint) + } + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/FieldViewHolder.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/FieldViewHolder.kt new file mode 100644 index 00000000..7a4c4758 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/FieldViewHolder.kt @@ -0,0 +1,46 @@ +package dev.lucasnlm.antimine.common.level.view + +import android.os.Build +import android.view.KeyEvent +import android.view.View +import androidx.recyclerview.widget.RecyclerView +import dev.lucasnlm.antimine.common.R + +class FieldViewHolder(view: View) : RecyclerView.ViewHolder(view) { + val areaView: AreaView = view.findViewById(R.id.area) + + init { + view.isFocusable = false + areaView.isFocusable = true + areaView.setOnKeyListener { _, keyCode, keyEvent -> + var handled = false + + if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { + when (keyEvent.action) { + KeyEvent.ACTION_DOWN -> { + longPressAt = System.currentTimeMillis() + handled = true + } + KeyEvent.ACTION_UP -> { + if (System.currentTimeMillis() - longPressAt > 300L) { + view.performLongClick() + } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { + view.callOnClick() + } else { + view.performClick() + } + } + handled = true + } + } + } + + handled + } + } + + companion object { + var longPressAt: Long = 0L + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/UnlockedHorizontalScrollView.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/UnlockedHorizontalScrollView.kt new file mode 100644 index 00000000..20cb8797 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/UnlockedHorizontalScrollView.kt @@ -0,0 +1,31 @@ +package dev.lucasnlm.antimine.common.level.view + +import android.annotation.SuppressLint +import android.content.Context +import android.util.AttributeSet +import android.view.MotionEvent +import android.widget.HorizontalScrollView +import androidx.recyclerview.widget.RecyclerView + +class UnlockedHorizontalScrollView : HorizontalScrollView { + private var recyclerView: RecyclerView? = null + + constructor(context: Context) : super(context) + + constructor(context: Context, attrs: AttributeSet) + : super(context, attrs) + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) + : super(context, attrs, defStyleAttr) + + fun setTarget(recyclerView: RecyclerView) { + this.recyclerView = recyclerView + } + + @SuppressLint("ClickableViewAccessibility") + override fun onTouchEvent(event: MotionEvent): Boolean = + super.onTouchEvent(event) or recyclerView!!.onTouchEvent(event) + + override fun onInterceptTouchEvent(event: MotionEvent): Boolean = + super.onInterceptTouchEvent(event) or recyclerView!!.onInterceptTouchEvent(event) +} 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 new file mode 100644 index 00000000..4b5d04c2 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt @@ -0,0 +1,257 @@ +package dev.lucasnlm.antimine.common.level.viewmodel + +import android.app.Application +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import dev.lucasnlm.antimine.common.level.GameModeFactory +import dev.lucasnlm.antimine.common.level.LevelFacade +import dev.lucasnlm.antimine.common.level.data.* +import dev.lucasnlm.antimine.common.level.database.data.Save +import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository +import dev.lucasnlm.antimine.common.level.repository.ISavesRepository +import dev.lucasnlm.antimine.common.level.utils.Clock +import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackInteractor +import dev.lucasnlm.antimine.core.analytics.AnalyticsManager +import dev.lucasnlm.antimine.core.analytics.Event +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + +class GameViewModel( + val application: Application, + val eventObserver: MutableLiveData, + private val savesRepository: ISavesRepository, + private val dimensionRepository: IDimensionRepository, + private val preferencesRepository: IPreferencesRepository, + private val hapticFeedbackInteractor: IHapticFeedbackInteractor, + private val analyticsManager: AnalyticsManager, + private val clock: Clock +) : ViewModel() { + private lateinit var levelFacade: LevelFacade + private var currentDifficulty: DifficultyPreset = DifficultyPreset.Standard + private var initialized = false + + val field = MutableLiveData>() + val fieldRefresh = MutableLiveData() + val elapsedTimeSeconds = MutableLiveData() + val mineCount = MutableLiveData() + val difficulty = MutableLiveData() + val levelSetup = MutableLiveData() + + private fun startNewGame(gameId: Int, difficultyPreset: DifficultyPreset): LevelSetup { + clock.reset() + elapsedTimeSeconds.postValue(0L) + currentDifficulty = difficultyPreset + + val setup = GameModeFactory.fromDifficultyPreset( + difficultyPreset, dimensionRepository, preferencesRepository + ) + + levelFacade = LevelFacade(gameId, setup) + + mineCount.postValue(setup.mines) + difficulty.postValue(difficultyPreset) + levelSetup.postValue(setup) + field.postValue(levelFacade.field.toList()) + + eventObserver.postValue(GameEvent.StartNewGame) + + analyticsManager.sentEvent(Event.NewGame(setup, levelFacade.seed, useAccessibilityMode())) + + return setup + } + + private fun resumeGameFromSave(save: Save): LevelSetup { + clock.reset(save.duration) + elapsedTimeSeconds.postValue(save.duration) + + val setup = save.levelSetup + levelFacade = LevelFacade(save) + + mineCount.postValue(setup.mines) + difficulty.postValue(save.levelSetup.preset) + levelSetup.postValue(setup) + field.postValue(levelFacade.field.toList()) + + when { + levelFacade.hasAnyMineExploded() -> eventObserver.postValue(GameEvent.ResumeGameOver) + levelFacade.checkVictory() -> eventObserver.postValue(GameEvent.ResumeVictory) + else -> eventObserver.postValue(GameEvent.ResumeGame) + } + + analyticsManager.sentEvent(Event.ResumePreviousGame()) + + return setup + } + + suspend fun startNewGame(difficultyPreset: DifficultyPreset = currentDifficulty): LevelSetup = + withContext(Dispatchers.IO) { + val newGameId = savesRepository.getNewSaveId() + startNewGame(newGameId, difficultyPreset) + } + + suspend fun onCreate(newGame: DifficultyPreset? = null): LevelSetup = withContext(Dispatchers.IO) { + val lastGame = if (newGame == null) savesRepository.fetchCurrentSave() else null + + if (lastGame != null) { + currentDifficulty = lastGame.levelSetup.preset + } else if (newGame != null) { + currentDifficulty = newGame + } + + if (lastGame == null) { + val newGameId = savesRepository.getNewSaveId() + startNewGame(newGameId, currentDifficulty) + } else { + resumeGameFromSave(lastGame) + }.also { + initialized = true + } + } + + fun pauseGame() { + if (initialized) { + if (levelFacade.hasMines) { + eventObserver.postValue(GameEvent.Pause) + } + clock.stop() + } + } + + suspend fun saveGame() { + if (initialized) { + if (levelFacade.hasMines) { + savesRepository.saveGame( + levelFacade.getSaveState().copy(duration = elapsedTimeSeconds.value ?: 0L) + ) + } + } + } + + fun resumeGame() { + if (initialized) { + if (levelFacade.hasMines) { + eventObserver.postValue(GameEvent.Resume) + } + } + } + + fun onLongClick(index: Int) { + levelFacade.turnOffAllHighlighted() + + if (levelFacade.hasCoverOn(index)) { + if (levelFacade.switchMarkAt(index)) { + refreshField(index) + hapticFeedbackInteractor.toggleFlagFeedback() + } + + analyticsManager.sentEvent(Event.LongPressArea(index)) + } else { + levelFacade.openNeighbors(index) + refreshGameStatus() + + analyticsManager.sentEvent(Event.LongPressMultipleArea(index)) + } + + field.postValue(levelFacade.field.toList()) + + if (levelFacade.hasMines) { + mineCount.postValue(levelFacade.remainingMines()) + } + } + + fun onClickArea(index: Int) { + levelFacade.turnOffAllHighlighted() + + if (levelFacade.hasMarkOn(index)) { + levelFacade.removeMark(index) + hapticFeedbackInteractor.toggleFlagFeedback() + refreshField(index) + } else { + if (!levelFacade.hasMines) { + levelFacade.plantMinesExcept(index, true) + } + + levelFacade.clickArea(index) + + field.postValue(levelFacade.field.toList()) + } + + refreshGameStatus() + analyticsManager.sentEvent(Event.PressArea(index)) + } + + private fun refreshMineCount() = mineCount.postValue(levelFacade.remainingMines()) + + private fun refreshGameStatus() { + refreshMineCount() + + when { + levelFacade.hasAnyMineExploded() -> { + hapticFeedbackInteractor.explosionFeedback() + eventObserver.postValue(GameEvent.GameOver) + } + levelFacade.checkVictory() -> eventObserver.postValue(GameEvent.Victory) + else -> { + if (preferencesRepository.useFlagAssistant()){ + levelFacade.runFlagAssistant() + } + eventObserver.postValue(GameEvent.Running) + } + } + } + + fun runClock() { + if (isGameActive()) { + clock.run { + if (isStopped) start { + elapsedTimeSeconds.postValue(it) + } + } + } + } + + fun stopClock() { + clock.stop() + } + + fun revealAllEmptyAreas() { + levelFacade.revealAllEmptyAreas() + } + + fun gameOver() { + levelFacade.run { + analyticsManager.sentEvent(Event.GameOver(clock.time(), getStats())) + + showAllMines() + showWrongFlags() + } + + GlobalScope.launch { + saveGame() + } + } + + fun victory() { + levelFacade.run { + analyticsManager.sentEvent(Event.Victory(clock.time(), getStats(), currentDifficulty)) + + showAllMines() + showWrongFlags() + } + + GlobalScope.launch { + saveGame() + } + } + + fun isGameActive() = (levelFacade.checkVictory() || levelFacade.hasAnyMineExploded()).not() + + fun useAccessibilityMode() = preferencesRepository.useLargeAreas() + + private fun refreshField(index: Int) { + fieldRefresh.postValue(index) + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModelFactory.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModelFactory.kt new file mode 100644 index 00000000..4d6fc791 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModelFactory.kt @@ -0,0 +1,38 @@ +package dev.lucasnlm.antimine.common.level.viewmodel + +import android.app.Application +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import dev.lucasnlm.antimine.common.level.data.GameEvent +import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository +import dev.lucasnlm.antimine.common.level.repository.ISavesRepository +import dev.lucasnlm.antimine.common.level.utils.Clock +import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackInteractor +import dev.lucasnlm.antimine.core.analytics.AnalyticsManager +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository +import javax.inject.Inject + +class GameViewModelFactory @Inject constructor( + private val application: Application, + private val gameEventObserver: MutableLiveData, + private val savesRepository: ISavesRepository, + private val dimensionRepository: IDimensionRepository, + private val preferencesRepository: IPreferencesRepository, + private val hapticFeedbackInteractor: IHapticFeedbackInteractor, + private val analyticsManager: AnalyticsManager, + private val clock: Clock +) : ViewModelProvider.Factory { + + override fun create(modelClass: Class): T = + if (modelClass.isAssignableFrom(GameViewModel::class.java)) { + @Suppress("UNCHECKED_CAST") + GameViewModel( + application, gameEventObserver, savesRepository, + dimensionRepository, preferencesRepository, hapticFeedbackInteractor, + analyticsManager, clock + ) as T + } else { + throw IllegalArgumentException("ViewModel Not Found") + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/analytics/AmplitudeAnalyticsManager.kt b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/AmplitudeAnalyticsManager.kt new file mode 100644 index 00000000..b3bc2451 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/AmplitudeAnalyticsManager.kt @@ -0,0 +1,27 @@ +package dev.lucasnlm.antimine.core.analytics + +import android.app.Application +import android.content.Context +import com.amplitude.api.Amplitude +import com.amplitude.api.AmplitudeClient +import dev.lucasnlm.antimine.common.R +import org.json.JSONObject + +class AmplitudeAnalyticsManager( + private val application: Application +) : AnalyticsManager { + + private var amplitudeClient: AmplitudeClient? = null + + override fun setup(context: Context, userProperties: Map) { + val key = context.getString(R.string.amplitude_key) + amplitudeClient = Amplitude.getInstance().initialize(application, key).apply { + setUserProperties(JSONObject(userProperties)) + enableForegroundTracking(application) + } + } + + override fun sentEvent(event: Event) { + amplitudeClient?.logEvent(event.title, JSONObject(event.extra)) + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/analytics/AnalyticsManager.kt b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/AnalyticsManager.kt new file mode 100644 index 00000000..90610d3f --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/AnalyticsManager.kt @@ -0,0 +1,8 @@ +package dev.lucasnlm.antimine.core.analytics + +import android.content.Context + +interface AnalyticsManager { + fun setup(context: Context, userProperties: Map) + fun sentEvent(event: Event) +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/analytics/DebugAnalyticsManager.kt b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/DebugAnalyticsManager.kt new file mode 100644 index 00000000..967f7eea --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/DebugAnalyticsManager.kt @@ -0,0 +1,18 @@ +package dev.lucasnlm.antimine.core.analytics + +import android.content.Context +import android.util.Log + +class DebugAnalyticsManager : AnalyticsManager { + override fun setup(context: Context, userProperties: Map) { + Log.d(TAG, "Setup Analytics using $userProperties") + } + + override fun sentEvent(event: Event) { + Log.d(TAG, "Sent event: '${event.title}' with ${event.extra}") + } + + companion object { + const val TAG = "DebugAnalyticsManager" + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/analytics/Event.kt b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/Event.kt new file mode 100644 index 00000000..6641edb4 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/Event.kt @@ -0,0 +1,82 @@ +package dev.lucasnlm.antimine.core.analytics + +import dev.lucasnlm.antimine.common.level.data.DifficultyPreset +import dev.lucasnlm.antimine.common.level.data.GameStats +import dev.lucasnlm.antimine.common.level.data.LevelSetup + +sealed class Event( + val title: String, val extra: Map = mapOf() +) { + class Open : Event("Open game") + + class NewGame(levelSetup: LevelSetup, seed: Long, useAccessibilityMode: Boolean) : + Event("New Game", mapOf( + "Seed" to seed.toString(), + "Difficulty Preset" to levelSetup.preset.text, + "Width" to levelSetup.width.toString(), + "Height" to levelSetup.height.toString(), + "Mines" to levelSetup.mines.toString(), + "Accessibility" to useAccessibilityMode.toString() + ) + ) + + class ResumePreviousGame : Event("Resume previous game") + + class LongPressArea(index: Int) : Event("Long press area", + mapOf("Index" to index.toString()) + ) + + class LongPressMultipleArea(index: Int) : Event("Long press to open multiple", + mapOf("Index" to index.toString()) + ) + + class PressArea(index: Int) : Event("Press area", + mapOf("Index" to index.toString()) + ) + + class GameOver(time: Long, gameStats: GameStats) : Event("Game Over", + mapOf( + "Time" to time.toString(), + "Right Mines" to gameStats.rightMines.toString(), + "Total Mines" to gameStats.totalMines.toString(), + "Total Area" to gameStats.totalArea.toString() + ) + ) + + class Victory(time: Long, gameStats: GameStats, difficultyPreset: DifficultyPreset) : Event( + "Victory", + mapOf( + "Time" to time.toString(), + "Difficulty" to difficultyPreset.text, + "Right Mines" to gameStats.rightMines.toString(), + "Total Mines" to gameStats.totalMines.toString(), + "Total Area" to gameStats.totalArea.toString() + ) + ) + + class Resume : Event("Back to the game") + + class Quit : Event("Quit game") + + class OpenDrawer : Event("Opened Drawer") + + class CloseDrawer : Event("Closed Drawer") + + class OpenAbout : Event("Open About") + + class OpenSettings : Event("Open Settings") + + class ShowRatingRequest(usages: Int) : Event("Shown Rating Request", + mapOf( + "Usages" to usages.toString() + )) + + class TapRatingRequest(from: String) : Event("Rating Request", + mapOf( + "From" to from + )) + + class TapGameReset(resign: Boolean) : Event("Game reset", + mapOf("Resign" to resign.toString()) + ) +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/di/CommonComponent.kt b/common/src/main/java/dev/lucasnlm/antimine/core/di/CommonComponent.kt new file mode 100644 index 00000000..d292d639 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/di/CommonComponent.kt @@ -0,0 +1,18 @@ +package dev.lucasnlm.antimine.core.di + +import dagger.Component +import dagger.android.support.AndroidSupportInjectionModule + +@Component( + modules = [ + AndroidSupportInjectionModule::class, + CommonModule::class + ] +) +abstract class LevelComponent { + @Component.Builder + interface Builder { + fun levelModule(levelModule: CommonModule): Builder + fun build(): LevelComponent + } +} 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 new file mode 100644 index 00000000..75a23ba5 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/di/CommonModule.kt @@ -0,0 +1,38 @@ +package dev.lucasnlm.antimine.core.di + +import android.app.Application +import dagger.Module +import dagger.Provides +import dev.lucasnlm.antimine.common.BuildConfig +import dev.lucasnlm.antimine.core.analytics.AmplitudeAnalyticsManager +import dev.lucasnlm.antimine.core.analytics.AnalyticsManager +import dev.lucasnlm.antimine.core.analytics.DebugAnalyticsManager +import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository +import dev.lucasnlm.antimine.core.preferences.PreferencesInteractor +import dev.lucasnlm.antimine.core.preferences.PreferencesRepository +import javax.inject.Singleton + +@Module +class CommonModule { + @Singleton + @Provides + fun providePreferencesRepository( + preferencesInteractor: PreferencesInteractor + ): IPreferencesRepository = PreferencesRepository(preferencesInteractor) + + @Singleton + @Provides + fun providePreferencesInteractor( + application: Application + ): PreferencesInteractor = PreferencesInteractor(application) + + @Singleton + @Provides + fun provideAnalyticsManager( + application: Application + ): AnalyticsManager = if (BuildConfig.DEBUG) { + DebugAnalyticsManager() + } else { + AmplitudeAnalyticsManager(application) + } +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesInteractor.kt b/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesInteractor.kt new file mode 100644 index 00000000..e429d64b --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesInteractor.kt @@ -0,0 +1,42 @@ +package dev.lucasnlm.antimine.core.preferences + +import android.app.Application +import androidx.preference.PreferenceManager +import dev.lucasnlm.antimine.common.level.data.LevelSetup +import javax.inject.Inject + +class PreferencesInteractor @Inject constructor( + private val application: Application +) { + private val preferences by lazy { + PreferenceManager.getDefaultSharedPreferences(application) + } + + fun getCustomMode() = LevelSetup( + preferences.getInt(PREFERENCE_CUSTOM_GAME_WIDTH, 9), + preferences.getInt(PREFERENCE_CUSTOM_GAME_HEIGHT, 9), + preferences.getInt(PREFERENCE_CUSTOM_GAME_MINES, 9) + ) + + fun updateCustomMode(customLevelSetup: LevelSetup) { + preferences.edit().apply { + putInt(PREFERENCE_CUSTOM_GAME_WIDTH, customLevelSetup.width) + putInt(PREFERENCE_CUSTOM_GAME_HEIGHT, customLevelSetup.height) + putInt(PREFERENCE_CUSTOM_GAME_MINES, customLevelSetup.mines) + }.apply() + } + + fun getBoolean(key: String, defaultValue: Boolean) = preferences.getBoolean(key, defaultValue) + + fun putBoolean(key: String, value: Boolean) = preferences.edit().putBoolean(key, value).apply() + + fun getInt(key: String, defaultValue: Int) = preferences.getInt(key, defaultValue) + + fun putInt(key: String, value: Int) = preferences.edit().putInt(key, value).apply() + + companion object { + private const val PREFERENCE_CUSTOM_GAME_WIDTH = "preference_custom_game_width" + private const val PREFERENCE_CUSTOM_GAME_HEIGHT = "preference_custom_game_height" + private const val PREFERENCE_CUSTOM_GAME_MINES = "preference_custom_game_mines" + } +} 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 new file mode 100644 index 00000000..8e1b03ef --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt @@ -0,0 +1,49 @@ +package dev.lucasnlm.antimine.core.preferences + +import dev.lucasnlm.antimine.common.level.data.LevelSetup + +interface IPreferencesRepository { + fun customGameMode(): LevelSetup + fun updateCustomGameMode(levelSetup: LevelSetup) + fun getBoolean(key: String, defaultValue: Boolean): Boolean + fun getInt(key: String, defaultValue: Int): Int + fun putBoolean(key: String, value: Boolean) + fun putInt(key: String, value: Int) + + fun useFlagAssistant(): Boolean + fun useHapticFeedback(): Boolean + fun useLargeAreas(): Boolean +} + +class PreferencesRepository( + private val preferencesInteractor: PreferencesInteractor +) : IPreferencesRepository { + + override fun customGameMode(): LevelSetup = + preferencesInteractor.getCustomMode() + + override fun updateCustomGameMode(levelSetup: LevelSetup) = + preferencesInteractor.updateCustomMode(levelSetup) + + override fun getBoolean(key: String, defaultValue: Boolean): Boolean = + preferencesInteractor.getBoolean(key, defaultValue) + + override fun putBoolean(key: String, value: Boolean) = + preferencesInteractor.putBoolean(key, value) + + override fun getInt(key: String, defaultValue: Int): Int = + preferencesInteractor.getInt(key, defaultValue) + + override fun putInt(key: String, value: Int) = + preferencesInteractor.putInt(key, value) + + override fun useFlagAssistant(): Boolean = + getBoolean("preference_assistant", true) + + override fun useHapticFeedback(): Boolean = + getBoolean("preference_vibration", true) + + override fun useLargeAreas(): Boolean = + getBoolean("preference_large_area", false) + +} diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/scope/ActivityScope.kt b/common/src/main/java/dev/lucasnlm/antimine/core/scope/ActivityScope.kt new file mode 100644 index 00000000..82f84270 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/scope/ActivityScope.kt @@ -0,0 +1,7 @@ +package dev.lucasnlm.antimine.core.scope + +import javax.inject.Scope + +@Scope +@Retention(AnnotationRetention.RUNTIME) +annotation class ActivityScope diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/scope/FragmentScope.kt b/common/src/main/java/dev/lucasnlm/antimine/core/scope/FragmentScope.kt new file mode 100644 index 00000000..8f476192 --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/scope/FragmentScope.kt @@ -0,0 +1,7 @@ +package dev.lucasnlm.antimine.core.scope + +import javax.inject.Scope + +@Scope +@Retention(AnnotationRetention.RUNTIME) +annotation class FragmentScope diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/utils/DarkModeUtils.kt b/common/src/main/java/dev/lucasnlm/antimine/core/utils/DarkModeUtils.kt new file mode 100644 index 00000000..19f24d4a --- /dev/null +++ b/common/src/main/java/dev/lucasnlm/antimine/core/utils/DarkModeUtils.kt @@ -0,0 +1,12 @@ +package dev.lucasnlm.antimine.core.utils + +import android.content.Context +import android.content.res.Configuration.UI_MODE_NIGHT_YES +import android.content.res.Configuration.UI_MODE_NIGHT_MASK + +fun isDarkModeEnabled(context: Context): Boolean { + return when (context.resources.configuration.uiMode and UI_MODE_NIGHT_MASK) { + UI_MODE_NIGHT_YES -> true + else -> false + } +} diff --git a/common/src/main/res/drawable-night/mine_exploded.xml b/common/src/main/res/drawable-night/mine_exploded.xml new file mode 100644 index 00000000..652db736 --- /dev/null +++ b/common/src/main/res/drawable-night/mine_exploded.xml @@ -0,0 +1,14 @@ + + + + diff --git a/common/src/main/res/drawable-night/red_flag.xml b/common/src/main/res/drawable-night/red_flag.xml new file mode 100644 index 00000000..8a2c2f71 --- /dev/null +++ b/common/src/main/res/drawable-night/red_flag.xml @@ -0,0 +1,10 @@ + + + diff --git a/common/src/main/res/drawable-night/replay.xml b/common/src/main/res/drawable-night/replay.xml new file mode 100644 index 00000000..2f8e48c8 --- /dev/null +++ b/common/src/main/res/drawable-night/replay.xml @@ -0,0 +1,9 @@ + + + diff --git a/common/src/main/res/drawable-night/splash.xml b/common/src/main/res/drawable-night/splash.xml new file mode 100644 index 00000000..75613ea0 --- /dev/null +++ b/common/src/main/res/drawable-night/splash.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/common/src/main/res/drawable-night/splash_image.png b/common/src/main/res/drawable-night/splash_image.png new file mode 100644 index 00000000..df6009ff Binary files /dev/null and b/common/src/main/res/drawable-night/splash_image.png differ diff --git a/common/src/main/res/drawable/checked.xml b/common/src/main/res/drawable/checked.xml new file mode 100644 index 00000000..ebb8c9d8 --- /dev/null +++ b/common/src/main/res/drawable/checked.xml @@ -0,0 +1,9 @@ + + + diff --git a/common/src/main/res/drawable/close.xml b/common/src/main/res/drawable/close.xml new file mode 100644 index 00000000..fd8599cf --- /dev/null +++ b/common/src/main/res/drawable/close.xml @@ -0,0 +1,9 @@ + + + diff --git a/common/src/main/res/drawable/done.xml b/common/src/main/res/drawable/done.xml new file mode 100644 index 00000000..436553a0 --- /dev/null +++ b/common/src/main/res/drawable/done.xml @@ -0,0 +1,9 @@ + + + diff --git a/common/src/main/res/drawable/flag.xml b/common/src/main/res/drawable/flag.xml new file mode 100755 index 00000000..f8abb7b2 --- /dev/null +++ b/common/src/main/res/drawable/flag.xml @@ -0,0 +1,10 @@ + + + diff --git a/common/src/main/res/drawable/main_logo.xml b/common/src/main/res/drawable/main_logo.xml new file mode 100644 index 00000000..a61170fb --- /dev/null +++ b/common/src/main/res/drawable/main_logo.xml @@ -0,0 +1,18 @@ + + + + diff --git a/common/src/main/res/drawable/mine.xml b/common/src/main/res/drawable/mine.xml new file mode 100755 index 00000000..2b38bcd4 --- /dev/null +++ b/common/src/main/res/drawable/mine.xml @@ -0,0 +1,14 @@ + + + + diff --git a/common/src/main/res/drawable/mine_exploded.xml b/common/src/main/res/drawable/mine_exploded.xml new file mode 100644 index 00000000..3637dc92 --- /dev/null +++ b/common/src/main/res/drawable/mine_exploded.xml @@ -0,0 +1,14 @@ + + + + diff --git a/common/src/main/res/drawable/mine_icon.xml b/common/src/main/res/drawable/mine_icon.xml new file mode 100755 index 00000000..a9af31dc --- /dev/null +++ b/common/src/main/res/drawable/mine_icon.xml @@ -0,0 +1,10 @@ + + + diff --git a/common/src/main/res/drawable/mine_low.xml b/common/src/main/res/drawable/mine_low.xml new file mode 100644 index 00000000..395f69a0 --- /dev/null +++ b/common/src/main/res/drawable/mine_low.xml @@ -0,0 +1,10 @@ + + + diff --git a/common/src/main/res/drawable/question.xml b/common/src/main/res/drawable/question.xml new file mode 100644 index 00000000..ab6ebaf1 --- /dev/null +++ b/common/src/main/res/drawable/question.xml @@ -0,0 +1,5 @@ + + + diff --git a/common/src/main/res/drawable/red_flag.xml b/common/src/main/res/drawable/red_flag.xml new file mode 100644 index 00000000..ac684a5f --- /dev/null +++ b/common/src/main/res/drawable/red_flag.xml @@ -0,0 +1,10 @@ + + + diff --git a/common/src/main/res/drawable/replay.xml b/common/src/main/res/drawable/replay.xml new file mode 100644 index 00000000..bbde5a12 --- /dev/null +++ b/common/src/main/res/drawable/replay.xml @@ -0,0 +1,9 @@ + + + diff --git a/common/src/main/res/drawable/splash.xml b/common/src/main/res/drawable/splash.xml new file mode 100644 index 00000000..f28c45cb --- /dev/null +++ b/common/src/main/res/drawable/splash.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/common/src/main/res/drawable/splash_image.png b/common/src/main/res/drawable/splash_image.png new file mode 100644 index 00000000..14d65152 Binary files /dev/null and b/common/src/main/res/drawable/splash_image.png differ diff --git a/common/src/main/res/drawable/timer.xml b/common/src/main/res/drawable/timer.xml new file mode 100755 index 00000000..4b8b566f --- /dev/null +++ b/common/src/main/res/drawable/timer.xml @@ -0,0 +1,10 @@ + + + diff --git a/common/src/main/res/drawable/title.xml b/common/src/main/res/drawable/title.xml new file mode 100644 index 00000000..18125bcd --- /dev/null +++ b/common/src/main/res/drawable/title.xml @@ -0,0 +1,17 @@ + + + + diff --git a/common/src/main/res/drawable/unchecked.xml b/common/src/main/res/drawable/unchecked.xml new file mode 100644 index 00000000..5ed61368 --- /dev/null +++ b/common/src/main/res/drawable/unchecked.xml @@ -0,0 +1,9 @@ + + + diff --git a/common/src/main/res/layout-watch/fragment_level.xml b/common/src/main/res/layout-watch/fragment_level.xml new file mode 100644 index 00000000..6c025af6 --- /dev/null +++ b/common/src/main/res/layout-watch/fragment_level.xml @@ -0,0 +1,34 @@ + + + + + + + + + diff --git a/common/src/main/res/layout/fragment_level.xml b/common/src/main/res/layout/fragment_level.xml new file mode 100644 index 00000000..df391cfc --- /dev/null +++ b/common/src/main/res/layout/fragment_level.xml @@ -0,0 +1,32 @@ + + + + + + + + + diff --git a/common/src/main/res/layout/view_accessibility_field.xml b/common/src/main/res/layout/view_accessibility_field.xml new file mode 100644 index 00000000..08ff4ab0 --- /dev/null +++ b/common/src/main/res/layout/view_accessibility_field.xml @@ -0,0 +1,14 @@ + + + + + + diff --git a/common/src/main/res/layout/view_field.xml b/common/src/main/res/layout/view_field.xml new file mode 100644 index 00000000..676353fc --- /dev/null +++ b/common/src/main/res/layout/view_field.xml @@ -0,0 +1,14 @@ + + + + + + diff --git a/common/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/common/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 00000000..db54720e --- /dev/null +++ b/common/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/common/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/common/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 00000000..db54720e --- /dev/null +++ b/common/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/common/src/main/res/mipmap-hdpi/ic_launcher.png b/common/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000..cc1d3ea8 Binary files /dev/null and b/common/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/common/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/common/src/main/res/mipmap-hdpi/ic_launcher_foreground.png new file mode 100644 index 00000000..30462649 Binary files /dev/null and b/common/src/main/res/mipmap-hdpi/ic_launcher_foreground.png differ diff --git a/common/src/main/res/mipmap-hdpi/ic_launcher_round.png b/common/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 00000000..b9420ff8 Binary files /dev/null and b/common/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/common/src/main/res/mipmap-ldpi/ic_launcher.png b/common/src/main/res/mipmap-ldpi/ic_launcher.png new file mode 100644 index 00000000..539943f2 Binary files /dev/null and b/common/src/main/res/mipmap-ldpi/ic_launcher.png differ diff --git a/common/src/main/res/mipmap-ldpi/ic_launcher_round.png b/common/src/main/res/mipmap-ldpi/ic_launcher_round.png new file mode 100644 index 00000000..c9aad9ea Binary files /dev/null and b/common/src/main/res/mipmap-ldpi/ic_launcher_round.png differ diff --git a/common/src/main/res/mipmap-mdpi/ic_launcher.png b/common/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000..53a5abc5 Binary files /dev/null and b/common/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/common/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/common/src/main/res/mipmap-mdpi/ic_launcher_foreground.png new file mode 100644 index 00000000..5b0281ab Binary files /dev/null and b/common/src/main/res/mipmap-mdpi/ic_launcher_foreground.png differ diff --git a/common/src/main/res/mipmap-mdpi/ic_launcher_round.png b/common/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 00000000..51734f57 Binary files /dev/null and b/common/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/common/src/main/res/mipmap-xhdpi/ic_launcher.png b/common/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000..7a85b3ca Binary files /dev/null and b/common/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/common/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/common/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png new file mode 100644 index 00000000..db0d44b3 Binary files /dev/null and b/common/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png differ diff --git a/common/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/common/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 00000000..1bc2989e Binary files /dev/null and b/common/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/common/src/main/res/mipmap-xxhdpi/ic_launcher.png b/common/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..34038e87 Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/common/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/common/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png new file mode 100644 index 00000000..309ec50c Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png differ diff --git a/common/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/common/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 00000000..a4200369 Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/common/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/common/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..34dbb55f Binary files /dev/null and b/common/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/common/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/common/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png new file mode 100644 index 00000000..9cc33e82 Binary files /dev/null and b/common/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png differ diff --git a/common/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/common/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 00000000..5b319d0c Binary files /dev/null and b/common/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/common/src/main/res/raw/android_sdk.txt b/common/src/main/res/raw/android_sdk.txt new file mode 100644 index 00000000..06270f0e --- /dev/null +++ b/common/src/main/res/raw/android_sdk.txt @@ -0,0 +1,142 @@ +This is the Android Software Development Kit License Agreement + +1. Introduction + +1.1 The Android Software Development Kit (referred to in this License Agreement as the "SDK" and specifically including the Android system files, packaged APIs, and Google APIs add-ons) is licensed to you subject to the terms of this License Agreement. This License Agreement forms a legally binding contract between you and Google in relation to your use of the SDK. + +1.2 “Android” means the Android software stack for devices, as made available under the Android Open Source Project, which is located at the following URL: http://source.android.com/, as updated from time to time. + +1.3 A "compatible implementation" means any Android device that (i) complies with the Android Compatibility Definition document, which can be found at the Android compatibility website (http://source.android.com/compatibility) and which may be updated from time to time; and (ii) successfully passes the Android Compatibility Test Suite (CTS). + +1.4 "Google" means Google Inc., a Delaware corporation with principal place of business at 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States. + + +2. Accepting this License Agreement + +2.1 In order to use the SDK, you must first agree to this License Agreement. You may not use the SDK if you do not accept this License Agreement. + +2.2 By clicking to accept, you hereby agree to the terms of this License Agreement. + +2.3 You may not use the SDK and may not accept the License Agreement if you are a person barred from receiving the SDK under the laws of the United States or other countries including the country in which you are resident or from which you use the SDK. + +2.4 If you are agreeing to be bound by this License Agreement on behalf of your employer or other entity, you represent and warrant that you have full legal authority to bind your employer or such entity to this License Agreement. If you do not have the requisite authority, you may not accept the License Agreement or use the SDK on behalf of your employer or other entity. + + +3. SDK License from Google + +3.1 Subject to the terms of this License Agreement, Google grants you a limited, worldwide, royalty-free, non-assignable, non-exclusive, and non-sublicensable license to use the SDK solely to develop applications to run on the Android platform. + +3.2 You may not use this SDK to develop applications for other platforms (including non-compatible implementations of Android) or to develop another SDK. You are of course free to develop applications for other platforms, including non-compatible implementations of Android, provided that this SDK is not used for that purpose. + +3.3 You agree that Google or third parties own all legal right, title and interest in and to the SDK, including any Intellectual Property Rights that subsist in the SDK. "Intellectual Property Rights" means any and all rights under patent law, copyright law, trade secret law, trademark law, and any and all other proprietary rights. Google reserves all rights not expressly granted to you. + +3.4 You may not use the SDK for any purpose not expressly permitted by this License Agreement. Except to the extent required by applicable third party licenses, you may not: (a) copy (except for backup purposes), modify, adapt, redistribute, decompile, reverse engineer, disassemble, or create derivative works of the SDK or any part of the SDK; or (b) load any part of the SDK onto a mobile handset or any other hardware device except a personal computer, combine any part of the SDK with other software, or distribute any software or device incorporating a part of the SDK. + +3.5 Use, reproduction and distribution of components of the SDK licensed under an open source software license are governed solely by the terms of that open source software license and not this License Agreement. + +3.6 You agree that the form and nature of the SDK that Google provides may change without prior notice to you and that future versions of the SDK may be incompatible with applications developed on previous versions of the SDK. You agree that Google may stop (permanently or temporarily) providing the SDK (or any features within the SDK) to you or to users generally at Google's sole discretion, without prior notice to you. + +3.7 Nothing in this License Agreement gives you a right to use any of Google's trade names, trademarks, service marks, logos, domain names, or other distinctive brand features. + +3.8 You agree that you will not remove, obscure, or alter any proprietary rights notices (including copyright and trademark notices) that may be affixed to or contained within the SDK. + + +4. Use of the SDK by You + +4.1 Google agrees that it obtains no right, title or interest from you (or your licensors) under this License Agreement in or to any software applications that you develop using the SDK, including any intellectual property rights that subsist in those applications. + +4.2 You agree to use the SDK and write applications only for purposes that are permitted by (a) this License Agreement and (b) any applicable law, regulation or generally accepted practices or guidelines in the relevant jurisdictions (including any laws regarding the export of data or software to and from the United States or other relevant countries). + +4.3 You agree that if you use the SDK to develop applications for general public users, you will protect the privacy and legal rights of those users. If the users provide you with user names, passwords, or other login information or personal information, you must make the users aware that the information will be available to your application, and you must provide legally adequate privacy notice and protection for those users. If your application stores personal or sensitive information provided by users, it must do so securely. If the user provides your application with Google Account information, your application may only use that information to access the user's Google Account when, and for the limited purposes for which, the user has given you permission to do so. + +4.4 You agree that you will not engage in any activity with the SDK, including the development or distribution of an application, that interferes with, disrupts, damages, or accesses in an unauthorized manner the servers, networks, or other properties or services of any third party including, but not limited to, Google or any mobile communications carrier. + +4.5 You agree that you are solely responsible for (and that Google has no responsibility to you or to any third party for) any data, content, or resources that you create, transmit or display through Android and/or applications for Android, and for the consequences of your actions (including any loss or damage which Google may suffer) by doing so. + +4.6 You agree that you are solely responsible for (and that Google has no responsibility to you or to any third party for) any breach of your obligations under this License Agreement, any applicable third party contract or Terms of Service, or any applicable law or regulation, and for the consequences (including any loss or damage which Google or any third party may suffer) of any such breach. + + +5. Your Developer Credentials + +5.1 You agree that you are responsible for maintaining the confidentiality of any developer credentials that may be issued to you by Google or which you may choose yourself and that you will be solely responsible for all applications that are developed under your developer credentials. + + +6. Privacy and Information + +6.1 In order to continually innovate and improve the SDK, Google may collect certain usage statistics from the software including but not limited to a unique identifier, associated IP address, version number of the software, and information on which tools and/or services in the SDK are being used and how they are being used. Before any of this information is collected, the SDK will notify you and seek your consent. If you withhold consent, the information will not be collected. + +6.2 The data collected is examined in the aggregate to improve the SDK and is maintained in accordance with Google's Privacy Policy. + + +7. Third Party Applications + +7.1 If you use the SDK to run applications developed by a third party or that access data, content or resources provided by a third party, you agree that Google is not responsible for those applications, data, content, or resources. You understand that all data, content or resources which you may access through such third party applications are the sole responsibility of the person from which they originated and that Google is not liable for any loss or damage that you may experience as a result of the use or access of any of those third party applications, data, content, or resources. + +7.2 You should be aware the data, content, and resources presented to you through such a third party application may be protected by intellectual property rights which are owned by the providers (or by other persons or companies on their behalf). You may not modify, rent, lease, loan, sell, distribute or create derivative works based on these data, content, or resources (either in whole or in part) unless you have been specifically given permission to do so by the relevant owners. + +7.3 You acknowledge that your use of such third party applications, data, content, or resources may be subject to separate terms between you and the relevant third party. In that case, this License Agreement does not affect your legal relationship with these third parties. + + +8. Using Android APIs + +8.1 Google Data APIs + +8.1.1 If you use any API to retrieve data from Google, you acknowledge that the data may be protected by intellectual property rights which are owned by Google or those parties that provide the data (or by other persons or companies on their behalf). Your use of any such API may be subject to additional Terms of Service. You may not modify, rent, lease, loan, sell, distribute or create derivative works based on this data (either in whole or in part) unless allowed by the relevant Terms of Service. + +8.1.2 If you use any API to retrieve a user's data from Google, you acknowledge and agree that you shall retrieve data only with the user's explicit consent and only when, and for the limited purposes for which, the user has given you permission to do so. + + +9. Terminating this License Agreement + +9.1 This License Agreement will continue to apply until terminated by either you or Google as set out below. + +9.2 If you want to terminate this License Agreement, you may do so by ceasing your use of the SDK and any relevant developer credentials. + +9.3 Google may at any time, terminate this License Agreement with you if: +(A) you have breached any provision of this License Agreement; or +(B) Google is required to do so by law; or +(C) the partner with whom Google offered certain parts of SDK (such as APIs) to you has terminated its relationship with Google or ceased to offer certain parts of the SDK to you; or +(D) Google decides to no longer provide the SDK or certain parts of the SDK to users in the country in which you are resident or from which you use the service, or the provision of the SDK or certain SDK services to you by Google is, in Google's sole discretion, no longer commercially viable. + +9.4 When this License Agreement comes to an end, all of the legal rights, obligations and liabilities that you and Google have benefited from, been subject to (or which have accrued over time whilst this License Agreement has been in force) or which are expressed to continue indefinitely, shall be unaffected by this cessation, and the provisions of paragraph 14.7 shall continue to apply to such rights, obligations and liabilities indefinitely. + + +10. DISCLAIMER OF WARRANTIES + +10.1 YOU EXPRESSLY UNDERSTAND AND AGREE THAT YOUR USE OF THE SDK IS AT YOUR SOLE RISK AND THAT THE SDK IS PROVIDED "AS IS" AND "AS AVAILABLE" WITHOUT WARRANTY OF ANY KIND FROM GOOGLE. + +10.2 YOUR USE OF THE SDK AND ANY MATERIAL DOWNLOADED OR OTHERWISE OBTAINED THROUGH THE USE OF THE SDK IS AT YOUR OWN DISCRETION AND RISK AND YOU ARE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR OTHER DEVICE OR LOSS OF DATA THAT RESULTS FROM SUCH USE. + +10.3 GOOGLE FURTHER EXPRESSLY DISCLAIMS ALL WARRANTIES AND CONDITIONS OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + + +11. LIMITATION OF LIABILITY + +11.1 YOU EXPRESSLY UNDERSTAND AND AGREE THAT GOOGLE, ITS SUBSIDIARIES AND AFFILIATES, AND ITS LICENSORS SHALL NOT BE LIABLE TO YOU UNDER ANY THEORY OF LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL OR EXEMPLARY DAMAGES THAT MAY BE INCURRED BY YOU, INCLUDING ANY LOSS OF DATA, WHETHER OR NOT GOOGLE OR ITS REPRESENTATIVES HAVE BEEN ADVISED OF OR SHOULD HAVE BEEN AWARE OF THE POSSIBILITY OF ANY SUCH LOSSES ARISING. + + +12. Indemnification + +12.1 To the maximum extent permitted by law, you agree to defend, indemnify and hold harmless Google, its affiliates and their respective directors, officers, employees and agents from and against any and all claims, actions, suits or proceedings, as well as any and all losses, liabilities, damages, costs and expenses (including reasonable attorneys fees) arising out of or accruing from (a) your use of the SDK, (b) any application you develop on the SDK that infringes any copyright, trademark, trade secret, trade dress, patent or other intellectual property right of any person or defames any person or violates their rights of publicity or privacy, and (c) any non-compliance by you with this License Agreement. + + +13. Changes to the License Agreement + +13.1 Google may make changes to the License Agreement as it distributes new versions of the SDK. When these changes are made, Google will make a new version of the License Agreement available on the website where the SDK is made available. + + +14. General Legal Terms + +14.1 This License Agreement constitutes the whole legal agreement between you and Google and governs your use of the SDK (excluding any services which Google may provide to you under a separate written agreement), and completely replaces any prior agreements between you and Google in relation to the SDK. + +14.2 You agree that if Google does not exercise or enforce any legal right or remedy which is contained in this License Agreement (or which Google has the benefit of under any applicable law), this will not be taken to be a formal waiver of Google's rights and that those rights or remedies will still be available to Google. + +14.3 If any court of law, having the jurisdiction to decide on this matter, rules that any provision of this License Agreement is invalid, then that provision will be removed from this License Agreement without affecting the rest of this License Agreement. The remaining provisions of this License Agreement will continue to be valid and enforceable. + +14.4 You acknowledge and agree that each member of the group of companies of which Google is the parent shall be third party beneficiaries to this License Agreement and that such other companies shall be entitled to directly enforce, and rely upon, any provision of this License Agreement that confers a benefit on (or rights in favor of) them. Other than this, no other person or company shall be third party beneficiaries to this License Agreement. + +14.5 EXPORT RESTRICTIONS. THE SDK IS SUBJECT TO UNITED STATES EXPORT LAWS AND REGULATIONS. YOU MUST COMPLY WITH ALL DOMESTIC AND INTERNATIONAL EXPORT LAWS AND REGULATIONS THAT APPLY TO THE SDK. THESE LAWS INCLUDE RESTRICTIONS ON DESTINATIONS, END USERS AND END USE. + +14.6 The rights granted in this License Agreement may not be assigned or transferred by either you or Google without the prior written approval of the other party. Neither you nor Google shall be permitted to delegate their responsibilities or obligations under this License Agreement without the prior written approval of the other party. + +14.7 This License Agreement, and your relationship with Google under this License Agreement, shall be governed by the laws of the State of California without regard to its conflict of laws provisions. You and Google agree to submit to the exclusive jurisdiction of the courts located within the county of Santa Clara, California to resolve any legal matter arising from this License Agreement. Notwithstanding this, you agree that Google shall still be allowed to apply for injunctive remedies (or an equivalent type of urgent legal relief) in any jurisdiction. diff --git a/common/src/main/res/raw/apache2.txt b/common/src/main/res/raw/apache2.txt new file mode 100644 index 00000000..7a4a3ea2 --- /dev/null +++ b/common/src/main/res/raw/apache2.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/common/src/main/res/raw/mine_explosion_sound.ogg b/common/src/main/res/raw/mine_explosion_sound.ogg new file mode 100644 index 00000000..a1a57183 Binary files /dev/null and b/common/src/main/res/raw/mine_explosion_sound.ogg differ diff --git a/common/src/main/res/raw/mockito.txt b/common/src/main/res/raw/mockito.txt new file mode 100644 index 00000000..9a90317d --- /dev/null +++ b/common/src/main/res/raw/mockito.txt @@ -0,0 +1,9 @@ +The MIT License + +Copyright (c) 2007 Mockito contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/common/src/main/res/raw/sounds.txt b/common/src/main/res/raw/sounds.txt new file mode 100644 index 00000000..d05aa6d2 --- /dev/null +++ b/common/src/main/res/raw/sounds.txt @@ -0,0 +1,6 @@ +Mine Explosion + +By shaynecantly +Link https://www.freesound.org/people/shaynecantly/sounds/131555/ +License: Creative Commons 3.0 +License URL: http://creativecommons.org/licenses/by/3.0/ diff --git a/common/src/main/res/values-es/strings.xml b/common/src/main/res/values-es/strings.xml new file mode 100644 index 00000000..59d58ef4 --- /dev/null +++ b/common/src/main/res/values-es/strings.xml @@ -0,0 +1,82 @@ + + + Anti-Mine + Deshabilitar las minas ocultas del campo de minas. + Minas Restantes + Dificultad + Estándar + Principiante + Intermediario + Especialista + Abrir Menú + Cerrar Menú + Ajustes + Animaciones + Respuesta táctil + Acerca de… + Sin conexión a Internet. + Estadística + Nuevo juego + Si iniciar un nuevo juego\nse perderá su progreso actual. + Cancelar + Continuar + Mostrar Licencias + Licencias + Google Play Games + Tablas de Clasificación + Conectar + Conectando… + Desconectar + Desconectado + Nuevo juego + ¿Quieres iniciar un nuevo juego? + + General + Todas las minas fueron desactivadas. + %d minas + Tiempo de juego + Campo Cubierto + Mina + Mina despiezada + El juego comienza ahora + ¡Usted ha estallado una mina! + Bandera colocada! + Bandera retirada! + Este juego utiliza el siguiente software: + No se ha podido iniciar sesión. Por favor, compruebe la conexión de red y vuelve a intentarlo. + Error desconocido. + Rever + Vacío + Perderá todos los movimientos en el juego actual. + ¡Ganaste! + ¡Perdiste! + %s - %s + Efectos de Sonido + Dejar + ¿Estás seguro? + + Personalizado + Empezar + Anchura + Altura + Minas + Bandera Automática + + Área cubierta + Área marcada + Área dudosa + Área marcada incorrectamente + + General + Vibra al explotar o al alternar la marcacion + Hace un sonido de explosión + Agrega una marca en minas resueltas automáticamente + Accesibilidad + Use áreas grandes + Aumenta el área táctil + + Nos califica ❤ + Si te gusta este juego, danos un comentario. Nos ayudará mucho. + Si ❤️️️ + No + diff --git a/common/src/main/res/values-night/colors.xml b/common/src/main/res/values-night/colors.xml new file mode 100644 index 00000000..3e1c073c --- /dev/null +++ b/common/src/main/res/values-night/colors.xml @@ -0,0 +1,32 @@ + + + #546E7A + #FFFFFF + + #212121 + #212121 + + #FFFFFF + + #527F8D + + #d5d2cc + #d5d2cc + #d5d2cc + #d5d2cc + #d5d2cc + #d5d2cc + #d5d2cc + #d5d2cc + + #FCC216 + + #FFFFFF + #2B2824 + #FFFFFF + + #757575 + #171717 + #ff424242 + + \ No newline at end of file diff --git a/common/src/main/res/values-pt/strings.xml b/common/src/main/res/values-pt/strings.xml new file mode 100644 index 00000000..261f2b68 --- /dev/null +++ b/common/src/main/res/values-pt/strings.xml @@ -0,0 +1,82 @@ + + + Anti-Mine + Encontre todas as minas escondidas no campo minado. + Minas Restantes + Dificuldade + Padrão + Iniciante + Intermediário + Experiente + Abrir Menu + Fechar Menu + Configurações + Animações + Vibração + Sobre + Sem conexão com a internet. + Estatísticas + Novo Jogo + Se você começar um novo jogo,\no progresso atual será perdido. + Cancelar + Continuar + Mostar Licenças + Licenças + Google Play Games + Placares + Conectar + Conectando… + Desconectar + Desconectado + Novo Jogo + Deseja começar um novo jogo? + Sim + Geral + Todas as minas foram desativadas. + %d minas + Tempo de Jogo + Campo Coberto + Mina + Mina explodida + Jogo iniciado + Você explodiu uma mina! + Bandeira posicionada! + Bandeira removida! + Esse jogo foi desenvolvido utilizando as seguintes bibliotecas: + Falha ao conectar. Por favor, verifique sua conexão com a internet e tente novamente. + Erro desconhecido. + Reiniciar + Vazio + Você perderá todos os movimentos do jogo atual. + Você venceu! + Você perdeu! + %s - %s + Efeitos Sonoros + Sair + Você tem certeza? + + Personalizado + Iniciar + Largura + Altura + Minas + Bandeiras Automáticas + + Área coberta + Área marcada + Área duvidosa + Área marcada erroneamente + + Geral + Vibra ao explodir ou alternar marcação + Faz um som ao explodir + Faz marcação automaticamente em minas resolvidas + Acessibilidade + Usar Área Grande + Aumenta a área tocável + + Avaliar o app ❤ + Se você está gostando do jogo, por favor deixe um comentário! Isso nos ajuda muito. + Sim ❤️️️ + Não + diff --git a/common/src/main/res/values-v21/themes.xml b/common/src/main/res/values-v21/themes.xml new file mode 100644 index 00000000..b4443c1c --- /dev/null +++ b/common/src/main/res/values-v21/themes.xml @@ -0,0 +1,21 @@ + + + + + + diff --git a/common/src/main/res/values-w600dp/dimens.xml b/common/src/main/res/values-w600dp/dimens.xml new file mode 100644 index 00000000..6c68e84e --- /dev/null +++ b/common/src/main/res/values-w600dp/dimens.xml @@ -0,0 +1,4 @@ + + 38dp + 20sp + diff --git a/common/src/main/res/values-zh/strings.xml b/common/src/main/res/values-zh/strings.xml new file mode 100644 index 00000000..f0598e4e --- /dev/null +++ b/common/src/main/res/values-zh/strings.xml @@ -0,0 +1,82 @@ + + + 反雷 - 扫雷 + 你需要清除一个隐藏着地雷的矩形面板,不能使任何地雷爆炸。 + 剩余地雷 + 难度 + 标准 + 初级 + 中级 + 专家 + 打开菜单 + 关闭选单 + 设置 + 动画 + 触觉反馈 + 关于 + 没有网络连接。 + 统计 + 新游戏 + 如果你开始一个新游戏,\n你的当前进度将会丢失。 + 取消 + 恢复 + 显示许可证 + 许可证 + Google Play 游戏 + 排行榜 + 连接 + 正在连接…… + 断开 + 已断开 + 新游戏 + 你要开始一个新游戏吗? + + 常规 + 所有地雷都已失效。 + %d个地雷 + 游戏时间 + 覆盖区域 + 地雷 + 爆炸的地雷 + 游戏已开始 + 你爆炸了一个地雷! + 标记已放置! + 标记已移除! + 该游戏使用以下第三方软件: + 登录失败。请检查你的网络连接,然后重试。 + 未知错误。 + 重试 + + 你将丢失当前游戏中的所有进度。 + 你赢了! + 你输了! + %s - %s + 音效 + 退出 + 确定吗? + + 自定义 + 开始 + 宽度 + 高度 + 地雷 + 游戏助手 + + 覆盖面积 + 标记区域 + 怀疑 + 标记区域错误 + + + + + + 辅助功能 + 使用大面积 + + + 评价应用 + + ️️️ + + diff --git a/common/src/main/res/values/colors.xml b/common/src/main/res/values/colors.xml new file mode 100644 index 00000000..5bc3980b --- /dev/null +++ b/common/src/main/res/values/colors.xml @@ -0,0 +1,32 @@ + + + #546E7A + #FFFFFF + + #212121 + #212121 + + #FFFFFF + + #527F8D + + #527F8D + #2B8D43 + #E65100 + #20A5f7 + #ED1C24 + #FFC107 + #66126B + #000000 + + #FCC216 + + #D32F2F + #2B2824 + #212121 + + #000 + #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 new file mode 100644 index 00000000..48c5c368 --- /dev/null +++ b/common/src/main/res/values/dimens.xml @@ -0,0 +1,11 @@ + + 180dp + 6dp + + 38dp + 48dp + 2dp + 1dp + 5dp + 18sp + diff --git a/common/src/main/res/values/keys.xml b/common/src/main/res/values/keys.xml new file mode 100644 index 00000000..83a9ae87 --- /dev/null +++ b/common/src/main/res/values/keys.xml @@ -0,0 +1,5 @@ + + + {-AMPLITUDE-kEY-} + {-CRASHLYTICS-KEY-} + diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml new file mode 100644 index 00000000..b14f2a6e --- /dev/null +++ b/common/src/main/res/values/strings.xml @@ -0,0 +1,82 @@ + + + Anti-Mine + You have to clear a rectangular board containing hidden "mines" without detonating any of them. + Remaining mines + Difficulty + Standard + Beginner + Intermediate + Expert + Open Menu + Close Menu + Settings + Animations + Haptic Feedback + About + No internet connection. + Statistics + New Game + If you start a new game,\nyour current progress will be lost. + Cancel + Resume + Show Licenses + Licenses + Google Play Games + Leaderboards + Connect + Connecting… + Disconnect + Disconnected + New Game + Do you want to start a new game? + Yes + General + All mines were disabled. + %d mines + Game Time + Covered Field + Mine + Exploded Mine + Game Started + You exploded a mine! + Flag placed! + Flag removed! + This game uses the following third parties software: + Failed to sign in. Please check your network connection and try again. + Unknown error. + Retry + Empty + You\'ll lose all moves on current game. + You won! + You lost! + %s - %s + Sound Effects + Quit + Are you sure? + + Custom + Start + Width + Height + Mines + Game Assistant + + Covered area + Marked area + Doubtful area + Wrongly marked area + + General + Vibrates on explosion or flag toggle + Makes a sound of explosion + Adds a flag on resolved mines automatically + Accessibility + Use Large Areas + Increases the touch area + + Feedback ❤ + If you like this game, please give us a feedback. It will help us a lot. + Yes ❤️️️ + No + diff --git a/common/src/main/res/values/themes.xml b/common/src/main/res/values/themes.xml new file mode 100644 index 00000000..6f943afb --- /dev/null +++ b/common/src/main/res/values/themes.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + +