Skip to content

Commit

Permalink
Merge pull request #4 from delacrixmorgan/develop
Browse files Browse the repository at this point in the history
2.3.6 - Develop to Master
  • Loading branch information
delacrixmorgan authored Jul 23, 2018
2 parents 0c1c320 + fa8bab8 commit c86badb
Show file tree
Hide file tree
Showing 33 changed files with 211 additions and 141 deletions.
21 changes: 12 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'org.jetbrains.kotlin.android.extensions'
apply plugin: 'io.fabric'

androidExtensions {
experimental = true
Expand All @@ -15,8 +15,8 @@ android {
applicationId "com.delacrixmorgan.kingscup"
minSdkVersion 19
targetSdkVersion 27
versionCode 17
versionName "2.3.1"
versionCode 22
versionName "2.3.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -28,6 +28,9 @@ android {
dataBinding {
enabled = true
}
bundle {
language.enableSplit = false
}
}

dependencies {
Expand All @@ -37,17 +40,17 @@ dependencies {
})

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') { transitive = true }

implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.google.firebase:firebase-perf:16.0.0'
implementation 'com.google.firebase:firebase-core:16.0.1'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "com.android.support:recyclerview-v7:$support_library_version"
implementation "com.android.support:design:$support_library_version"

implementation "com.jcminarro:RoundKornerLayouts:$korner_library_version"
implementation "com.github.rubensousa:gravitysnaphelper:1.5"
}

repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
apply plugin: 'com.google.gms.google-services'
7 changes: 3 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.delacrixmorgan.kingscup">

<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -10,7 +11,8 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<activity
android:name=".MainActivity"
Expand All @@ -21,8 +23,5 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="34f5cbf3182f76b1607fe8a4914f126e4699b6ab" />
</application>
</manifest>
6 changes: 3 additions & 3 deletions app/src/main/java/com/delacrixmorgan/kingscup/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import android.support.v7.app.AppCompatActivity
import android.util.TypedValue
import android.view.Gravity
import android.view.View
import com.crashlytics.android.Crashlytics
import com.delacrixmorgan.kingscup.common.SoundEngine
import com.delacrixmorgan.kingscup.common.showFragmentSliding
import com.delacrixmorgan.kingscup.menu.MenuFragment
import io.fabric.sdk.android.Fabric
import com.google.firebase.analytics.FirebaseAnalytics

/**
* MainActivity
Expand All @@ -28,7 +27,8 @@ import io.fabric.sdk.android.Fabric
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Fabric.with(this, Crashlytics())

FirebaseAnalytics.getInstance(this)

setContentView(R.layout.activity_main)
this.showFragmentSliding(MenuFragment.newInstance(), Gravity.BOTTOM)
Expand Down
15 changes: 3 additions & 12 deletions app/src/main/java/com/delacrixmorgan/kingscup/common/GameEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class GameEngine private constructor(context: Context) {
}

private fun buildGameEngine(context: Context) {

SuitType.values().forEach { suit ->
ActionType.values().let { actionTypes ->
actionTypes.indices.mapTo(deckList) {
Expand All @@ -79,10 +78,6 @@ class GameEngine private constructor(context: Context) {
deckList.shuffle(Random(System.nanoTime()))
}

fun checkWin(card: Card): Boolean {
return card.rank == kingRank && kingCounter == 1
}

fun removeCard(position: Int) {
if (deckList[position].rank == kingRank) {
kingCounter--
Expand Down Expand Up @@ -130,11 +125,7 @@ class GameEngine private constructor(context: Context) {
}
}

fun getCardByPosition(position: Int): Card {
return deckList[position]
}

fun getDeckSize(): Int {
return deckList.size
}
fun getDeckSize() = deckList.size
fun getCardByPosition(position: Int) = deckList[position]
fun checkWin(card: Card) = card.rank == kingRank && kingCounter == 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.view.*
import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import com.delacrixmorgan.kingscup.R
import com.delacrixmorgan.kingscup.common.*
import com.delacrixmorgan.kingscup.common.PreferenceHelper.get
import com.delacrixmorgan.kingscup.common.PreferenceHelper.set
import com.delacrixmorgan.kingscup.model.Card
import com.delacrixmorgan.kingscup.model.LoadType
import com.delacrixmorgan.kingscup.model.VibrateType
import com.github.rubensousa.gravitysnaphelper.GravitySnapHelper
import kotlinx.android.synthetic.main.dialog_pause.*
import kotlinx.android.synthetic.main.fragment_game_board.*

Expand All @@ -24,68 +28,93 @@ import kotlinx.android.synthetic.main.fragment_game_board.*
*/

class GameBoardFragment : Fragment(), View.OnClickListener, CardListener {

companion object {
fun newInstance(): GameBoardFragment {
return GameBoardFragment()
}
fun newInstance() = GameBoardFragment()
}

private lateinit var statusTextAnimation: AlphaAnimation
private lateinit var cardAdapter: GameCardAdapter
private lateinit var menuDialog: Dialog

private var isCardSelected: Boolean = false
private var statusText = ""

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_game_board, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
this.setupView()
}

private fun setupView() {
val manager = LinearLayoutManager(this.activity, LinearLayoutManager.HORIZONTAL, false)
setupLayouts()
setupListeners()

this.cardAdapter = GameCardAdapter(this, GameEngine.getInstance().getDeckSize())
this.isCardSelected = false
this.statusTextView.startAnimation(this.statusTextAnimation)
}

this.recyclerView.removeAllViews()
this.recyclerView.layoutManager = manager
this.recyclerView.adapter = cardAdapter
private fun setupLayouts() {
val deckAnimation = AnimationUtils.loadLayoutAnimation(context, R.anim.layout_animation_slide_right)
val cellHeight = (resources.displayMetrics.heightPixels / 2.5).toInt()
val cellWidth = (cellHeight * (10.0 / 16.0)).toInt()

this.volumeImageView.setImageResource(R.drawable.ic_cup_whole)
this.setupMenuDialog()

setupProgressBar(manager, recyclerView, progressBar)

this.restartButton.setOnClickListener {
this.startNewGame()
this.statusText = getString(R.string.board_title_lets_begin)
this.statusTextAnimation = AlphaAnimation(1.0f, 0.0f)
this.isCardSelected = false
this.cardAdapter = GameCardAdapter(
cellHeight = cellHeight,
cellWidth = cellWidth,
deckSize = GameEngine.getInstance().getDeckSize(),
listener = this
)

with(this.recyclerView) {
removeAllViews()
adapter = cardAdapter
layoutAnimation = deckAnimation
scheduleLayoutAnimation()
GravitySnapHelper(Gravity.START).attachToRecyclerView(this)
}

this.menuButton.setOnClickListener {
this.menuDialog.show()
with(this.statusTextAnimation) {
duration = 200
repeatCount = 1
repeatMode = Animation.REVERSE
}

setupMenuDialog()
setupProgressBar(this.recyclerView.layoutManager as LinearLayoutManager, recyclerView, progressBar)
}

private fun setupListeners() {
this.restartButton.setOnClickListener { startNewGame() }
this.menuButton.setOnClickListener { this.menuDialog.show() }

this.statusTextAnimation.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationEnd(animation: Animation?) = Unit
override fun onAnimationStart(animation: Animation?) = Unit
override fun onAnimationRepeat(animation: Animation?) {
this@GameBoardFragment.statusTextView.text = this@GameBoardFragment.statusText
}
})
}

override fun onCardSelected(position: Int) {
val context = this.context ?: return

if (!this.isCardSelected) {
val card: Card? = GameEngine.getInstance().getCardByPosition(position)
if (card != null) {
this.isCardSelected = true

this.context?.let {
if (card != null) {
this.isCardSelected = true

val fragment = GameCardFragment.newInstance(card, position, this)
it.showFragmentSliding(fragment, Gravity.BOTTOM)
val fragment = GameCardFragment.newInstance(card, position, this)
context.showFragmentSliding(fragment, Gravity.BOTTOM)

GameEngine.getInstance().vibrateFeedback(it, VibrateType.SHORT)
SoundEngine.getInstance().playSound(it, SoundType.FLIP)
} else {
this.activity?.supportFragmentManager?.popBackStack()
SoundEngine.getInstance().playSound(it, SoundType.WHOOSH)
}
GameEngine.getInstance().vibrateFeedback(context, VibrateType.SHORT)
SoundEngine.getInstance().playSound(context, SoundType.FLIP)
} else {
this.activity?.supportFragmentManager?.popBackStack()
SoundEngine.getInstance().playSound(context, SoundType.WHOOSH)
}
}
}
Expand All @@ -96,9 +125,10 @@ class GameBoardFragment : Fragment(), View.OnClickListener, CardListener {

this.isCardSelected = false
this.cardAdapter.notifyItemRemoved(position)
this.statusText = args?.getString(GameEngine.GAME_ENGINE_TAUNT) ?: getString(R.string.board_title_lets_begin)

this.progressBar.max--
this.statusTextView.text = args?.getString(GameEngine.GAME_ENGINE_TAUNT)
this.statusTextView.startAnimation(this.statusTextAnimation)

args?.getInt(GameEngine.GAME_ENGINE_CUP_VOLUME)?.let { volumeImageView.setImageResource(it) }

Expand All @@ -114,24 +144,26 @@ class GameBoardFragment : Fragment(), View.OnClickListener, CardListener {
}

private fun setupMenuDialog() {
val preference = PreferenceHelper.getPreference(this.context!!)
val vibratePreference = preference[PreferenceHelper.VIBRATE, PreferenceHelper.VIBRATE_DEFAULT]
val context = this.context ?: return

val preference = PreferenceHelper.getPreference(context)
val soundPreference = preference[PreferenceHelper.SOUND, PreferenceHelper.SOUND_DEFAULT]
val vibratePreference = preference[PreferenceHelper.VIBRATE, PreferenceHelper.VIBRATE_DEFAULT]

this.menuDialog = Dialog(context!!)
this.menuDialog = Dialog(context)

with(this.menuDialog) {
requestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(R.layout.dialog_pause)

quitButton.setOnClickListener(this@GameBoardFragment)
vibrateButton.setOnClickListener(this@GameBoardFragment)
volumeButton.setOnClickListener(this@GameBoardFragment)
resumeButton.setOnClickListener(this@GameBoardFragment)
vibrateButton.setOnClickListener(this@GameBoardFragment)
startNewGameButton.setOnClickListener(this@GameBoardFragment)

vibrateButton.setImageResource(if (vibratePreference) R.drawable.ic_vibration_enable else R.drawable.ic_vibration_disable)
volumeButton.setImageResource(if (soundPreference) R.drawable.ic_volume_up else R.drawable.ic_volume_off)
vibrateButton.setImageResource(if (vibratePreference) R.drawable.ic_vibration_enable else R.drawable.ic_vibration_disable)
}
}

Expand Down Expand Up @@ -176,7 +208,7 @@ class GameBoardFragment : Fragment(), View.OnClickListener, CardListener {
}

private fun updateVibratePreference() {
val preference = PreferenceHelper.getPreference(this.context!!)
val preference = PreferenceHelper.getPreference(requireContext())
val vibratePreference = preference[PreferenceHelper.VIBRATE, PreferenceHelper.VIBRATE_DEFAULT]

if (vibratePreference) {
Expand All @@ -189,7 +221,7 @@ class GameBoardFragment : Fragment(), View.OnClickListener, CardListener {
}

private fun updateSoundPreference() {
val preference = PreferenceHelper.getPreference(this.context!!)
val preference = PreferenceHelper.getPreference(requireContext())
val soundPreference = preference[PreferenceHelper.SOUND, PreferenceHelper.SOUND_DEFAULT]

if (soundPreference) {
Expand All @@ -200,4 +232,4 @@ class GameBoardFragment : Fragment(), View.OnClickListener, CardListener {

preference[PreferenceHelper.SOUND] = !soundPreference
}
}
}
Loading

0 comments on commit c86badb

Please sign in to comment.