Skip to content

Commit

Permalink
Merge pull request #5 from delacrixmorgan/develop
Browse files Browse the repository at this point in the history
v2.3.7 Merge to Master
  • Loading branch information
delacrixmorgan authored Nov 21, 2018
2 parents adf6fd7 + 10eab65 commit 684ee01
Show file tree
Hide file tree
Showing 35 changed files with 448 additions and 288 deletions.
25 changes: 12 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ androidExtensions {
}

android {
compileSdkVersion 27
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "com.delacrixmorgan.kingscup"
minSdkVersion 19
targetSdkVersion 27
versionCode 22
versionName "2.3.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
targetSdkVersion rootProject.ext.compileSdkVersion
versionCode 23
versionName "2.3.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -35,22 +35,21 @@ android {

dependencies {
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})

implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.google.firebase:firebase-perf:16.0.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation "com.google.firebase:firebase-perf:$firebase_perf_version"
implementation "com.google.firebase:firebase-core:$firebase_core_version"
implementation "com.google.android.material:material:$material_components_version"
implementation "androidx.recyclerview:recyclerview:$androidx_recyclerview_version"
implementation "androidx.constraintlayout:constraintlayout:$androidx_constraint_layout_version"

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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.jcminarro:RoundKornerLayouts:$korner_library_version"
implementation "com.github.rubensousa:gravitysnaphelper:1.5"
}

apply plugin: 'com.google.gms.google-services'
4 changes: 2 additions & 2 deletions app/src/main/java/com/delacrixmorgan/kingscup/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import android.graphics.BitmapFactory
import android.media.AudioManager
import android.os.Build
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity
import androidx.core.content.ContextCompat
import android.util.TypedValue
import android.view.Gravity
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.delacrixmorgan.kingscup.common.SoundEngine
import com.delacrixmorgan.kingscup.common.showFragmentSliding
import com.delacrixmorgan.kingscup.menu.MenuFragment
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/java/com/delacrixmorgan/kingscup/common/GameEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Build
import android.os.Bundle
import android.os.VibrationEffect
import android.os.Vibrator
import android.view.View
import com.delacrixmorgan.kingscup.R
import com.delacrixmorgan.kingscup.common.PreferenceHelper.get
import com.delacrixmorgan.kingscup.model.*
Expand Down Expand Up @@ -112,15 +113,23 @@ class GameEngine private constructor(context: Context) {
return args
}

fun vibrateFeedback(context: Context, vibrateType: VibrateType) {
fun vibrateFeedback(context: Context, view: View, vibrateType: VibrateType) {
val preference = PreferenceHelper.getPreference(context)
val vibratePreference = preference[PreferenceHelper.VIBRATE, PreferenceHelper.VIBRATE_DEFAULT]

if (vibratePreference) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vibrator.vibrate(VibrationEffect.createOneShot(vibrateType.duration, -1))
} else {
vibrator.vibrate(vibrateType.duration)
when (vibrateType) {
VibrateType.SHORT -> {
view.performHapticContextClick()
}

VibrateType.LONG -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vibrator.vibrate(VibrationEffect.createOneShot(vibrateType.duration, -1))
} else {
vibrator.vibrate(vibrateType.duration)
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.content.res.Resources
import android.net.Uri
import android.support.design.widget.FloatingActionButton
import android.support.transition.Slide
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentActivity
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.os.Build
import android.view.HapticFeedbackConstants
import android.view.View
import android.view.animation.AnimationSet
import android.view.animation.AnimationUtils
import android.widget.ProgressBar
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.transition.Slide
import com.delacrixmorgan.kingscup.R
import com.google.android.material.floatingactionbutton.FloatingActionButton
import java.util.*

/**
Expand All @@ -25,6 +28,14 @@ import java.util.*
* Copyright (c) 2018 licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
*/

fun View.performHapticContextClick() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
} else {
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
}
}

fun setLocale(language: String?, resources: Resources) {
val locale = Locale(language)

Expand All @@ -45,7 +56,7 @@ fun animateButtonGrow(context: Context, button: FloatingActionButton) {

fun setupProgressBar(manager: LinearLayoutManager, recyclerView: RecyclerView, progressBar: ProgressBar) {
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if (manager.findFirstVisibleItemPosition() == 0) {
progressBar.progress = 0
} else {
Expand All @@ -55,8 +66,7 @@ fun setupProgressBar(manager: LinearLayoutManager, recyclerView: RecyclerView, p
})
}

// Context

//region Context
fun Context.showFragmentSliding(fragment: Fragment, gravity: Int) {
fragment.enterTransition = Slide(gravity).setDuration(200)

Expand All @@ -67,15 +77,24 @@ fun Context.showFragmentSliding(fragment: Fragment, gravity: Int) {
.commit()
}

fun Context.launchShareGameIntent(message: String) {
val intent = Intent(Intent.ACTION_SEND)

intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_TEXT, message)

startActivity(Intent.createChooser(intent, getString(R.string.preference_title_share_friend)))
}

fun Context.launchWebsite(url: String) {
val intent = Intent(Intent.ACTION_VIEW)

intent.data = Uri.parse(url)
startActivity(intent)
}

fun Context.launchPlayStore() {
val url = "https://play.google.com/store/apps/details?id=${this.packageName}"
fun Context.launchPlayStore(packageName: String) {
val url = "https://play.google.com/store/apps/details?id=$packageName"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))

intent.flags = FLAG_ACTIVITY_NEW_TASK
Expand All @@ -84,4 +103,4 @@ fun Context.launchPlayStore() {
SoundEngine.getInstance().playSound(this, SoundType.OOOH)
}

// End - Context
//enregion
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.delacrixmorgan.kingscup.game

import android.view.View

/**
* CardListener
* kingscup-android
Expand All @@ -9,6 +11,6 @@ package com.delacrixmorgan.kingscup.game
*/

interface CardListener {
fun onCardSelected(position: Int)
fun onCardDismissed(position: Int)
fun onCardSelected(view: View, position: Int)
fun onCardDismissed(view: View, position: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ package com.delacrixmorgan.kingscup.game

import android.app.Dialog
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 androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
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 Down Expand Up @@ -73,7 +72,6 @@ class GameBoardFragment : Fragment(), View.OnClickListener, CardListener {
adapter = cardAdapter
layoutAnimation = deckAnimation
scheduleLayoutAnimation()
GravitySnapHelper(Gravity.START).attachToRecyclerView(this)
}

with(this.statusTextAnimation) {
Expand All @@ -99,7 +97,7 @@ class GameBoardFragment : Fragment(), View.OnClickListener, CardListener {
})
}

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

if (!this.isCardSelected) {
Expand All @@ -110,7 +108,7 @@ class GameBoardFragment : Fragment(), View.OnClickListener, CardListener {
val fragment = GameCardFragment.newInstance(card, position, this)
context.showFragmentSliding(fragment, Gravity.BOTTOM)

GameEngine.getInstance().vibrateFeedback(context, VibrateType.SHORT)
GameEngine.getInstance().vibrateFeedback(context, view, VibrateType.SHORT)
SoundEngine.getInstance().playSound(context, SoundType.FLIP)
} else {
this.activity?.supportFragmentManager?.popBackStack()
Expand All @@ -119,7 +117,7 @@ class GameBoardFragment : Fragment(), View.OnClickListener, CardListener {
}
}

override fun onCardDismissed(position: Int) {
override fun onCardDismissed(view: View, position: Int) {
GameEngine.getInstance().removeCard(position)
val args: Bundle? = GameEngine.getInstance().updateGraphicStatus(this.context!!)

Expand All @@ -138,7 +136,7 @@ class GameBoardFragment : Fragment(), View.OnClickListener, CardListener {
1 -> this.kingTwoImageView.visibility = View.GONE
0 -> {
this.kingOneImageView.visibility = View.GONE
this.restartButton.visibility = View.VISIBLE
this.restartButton.show()
}
}
}
Expand Down Expand Up @@ -168,36 +166,36 @@ class GameBoardFragment : Fragment(), View.OnClickListener, CardListener {
}

override fun onClick(view: View) {
this.context?.let {
when (view.id) {
R.id.startNewGameButton -> {
menuDialog.dismiss()

this.startNewGame()
SoundEngine.getInstance().playSound(it, SoundType.WHOOSH)
}

R.id.vibrateButton -> {
this.updateVibratePreference()
GameEngine.getInstance().vibrateFeedback(it, VibrateType.SHORT)
}

R.id.volumeButton -> {
this.updateSoundPreference()
SoundEngine.getInstance().playSound(it, SoundType.CLICK)
}

R.id.resumeButton -> {
this.menuDialog.dismiss()
SoundEngine.getInstance().playSound(it, SoundType.WHOOSH)
}

R.id.quitButton -> {
this.menuDialog.dismiss()
this.activity?.supportFragmentManager?.popBackStack()

SoundEngine.getInstance().playSound(it, SoundType.WHOOSH)
}
val context = this.context ?: return

when (view.id) {
R.id.startNewGameButton -> {
menuDialog.dismiss()

this.startNewGame()
SoundEngine.getInstance().playSound(context, SoundType.WHOOSH)
}

R.id.vibrateButton -> {
this.updateVibratePreference()
GameEngine.getInstance().vibrateFeedback(context, view, VibrateType.SHORT)
}

R.id.volumeButton -> {
this.updateSoundPreference()
SoundEngine.getInstance().playSound(context, SoundType.CLICK)
}

R.id.resumeButton -> {
this.menuDialog.dismiss()
SoundEngine.getInstance().playSound(context, SoundType.WHOOSH)
}

R.id.quitButton -> {
this.menuDialog.dismiss()
this.activity?.supportFragmentManager?.popBackStack()

SoundEngine.getInstance().playSound(context, SoundType.WHOOSH)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.delacrixmorgan.kingscup.game

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.delacrixmorgan.kingscup.R

/**
Expand Down Expand Up @@ -34,7 +34,7 @@ class GameCardAdapter(
holder.itemView.setOnClickListener {
if (deckSize != 0) {
deckSize--
listener.onCardSelected(holder.adapterPosition)
listener.onCardSelected(holder.itemView, holder.adapterPosition)
}
}
}
Expand Down
Loading

0 comments on commit 684ee01

Please sign in to comment.