Skip to content

Commit

Permalink
Merge pull request #10 from delacrixmorgan/develop
Browse files Browse the repository at this point in the history
v3.1.0 Redesigned Language Selection
  • Loading branch information
delacrixmorgan authored Mar 17, 2020
2 parents dcff409 + 645afbb commit 6685a00
Show file tree
Hide file tree
Showing 40 changed files with 552 additions and 381 deletions.
1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ android {
minSdkVersion 19
targetSdkVersion 29
multiDexEnabled true
versionCode 62
versionName "3.0.0"
versionCode 66
versionName "3.1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
manifestPlaceholders = [appLabel: "@string/app_name"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,71 +1,86 @@
package com.delacrixmorgan.kingscup.common

import android.content.Intent
import android.content.res.Resources
import android.net.Uri
import android.os.Build
import android.view.HapticFeedbackConstants
import android.view.View
import android.view.animation.AnimationSet
import android.view.animation.AnimationUtils
import androidx.fragment.app.Fragment
import com.delacrixmorgan.kingscup.R
import com.delacrixmorgan.kingscup.model.Card
import java.util.*

/**
* Resource
*/
fun Resources.setLocale(language: String) {
val locale = Locale(language)

configuration.setLocale(locale)
configuration.setLayoutDirection(locale)
updateConfiguration(configuration, displayMetrics)

Locale.setDefault(locale)
}

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

fun View.animateButtonGrow() {
val animGrow = AnimationSet(true)
animGrow.addAnimation(AnimationUtils.loadAnimation(this.context, R.anim.pop_out))
startAnimation(animGrow)
}

/**
* Fragment
*/
fun Fragment.launchShareGameIntent(message: String) {
val intent = Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, message)
}
startActivity(Intent.createChooser(intent, getString(R.string.preference_title_share_friend)))
}

fun Fragment.launchWebsite(url: String) {
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(url)
}
startActivity(intent)
}

/**
* Card
*/
fun ArrayList<Card>.findCardIndex(card: Card): Int {
return indexOf(firstOrNull {
it.suitType == card.suitType && it.rank == card.rank
})
package com.delacrixmorgan.kingscup.common

import android.content.Intent
import android.content.res.Resources
import android.net.Uri
import android.os.Build
import android.view.HapticFeedbackConstants
import android.view.View
import android.view.animation.AnimationSet
import android.view.animation.AnimationUtils
import androidx.fragment.app.Fragment
import com.delacrixmorgan.kingscup.R
import com.delacrixmorgan.kingscup.model.Card
import java.util.*

/**
* Resource
*/
fun Resources.setLocale(language: String) {
val locale = Locale(language)

configuration.setLocale(locale)
configuration.setLayoutDirection(locale)
updateConfiguration(configuration, displayMetrics)

Locale.setDefault(locale)
}

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

fun View.animateButtonGrow() {
val animGrow = AnimationSet(true)
animGrow.addAnimation(AnimationUtils.loadAnimation(this.context, R.anim.pop_out))
startAnimation(animGrow)
}

/**
* Fragment
*/
fun Fragment.launchShareGameIntent(message: String) {
val intent = Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, message)
}
startActivity(Intent.createChooser(intent, getString(R.string.preference_title_share_friend)))
}

fun Fragment.launchWebsite(url: String) {
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(url)
}
startActivity(intent)
}

/**
* Card
*/
fun ArrayList<Card>.findCardIndex(card: Card): Int {
return indexOf(firstOrNull {
it.suitType == card.suitType && it.rank == card.rank
})
}

fun newEmailIntent(recipient: String, subject: String?, body: String?): Intent {
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:")
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(recipient))

if (!subject.isNullOrBlank()) {
intent.putExtra(Intent.EXTRA_SUBJECT, subject)
}

if (!body.isNullOrBlank()) {
intent.putExtra(Intent.EXTRA_TEXT, body)
}
return intent
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.delacrixmorgan.kingscup.common

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

class GridSpacingItemDecoration(
private val columnCount: Int,
private val spacing: Int,
private val shouldShowHorizontalMargin: Boolean = false,
private val shouldShowVerticalMargin: Boolean = false
) : RecyclerView.ItemDecoration() {

override fun getItemOffsets(
outRect: Rect,
view: View,
recyclerView: RecyclerView,
state: RecyclerView.State
) {
val position = recyclerView.getChildAdapterPosition(view)
val column = position % columnCount

// spacing - column * ((1f / columnCount) * spacing)
outRect.left = spacing - column * spacing / columnCount

// (column + 1) * ((1f / columnCount) * spacing)
outRect.right = (column + 1) * spacing / columnCount

// add spacing to every item's bottom
outRect.bottom = spacing

if (position < columnCount) { // top row
outRect.top = spacing
}

if (!shouldShowHorizontalMargin) {
val isFirstColumn = column == 0
val isLastColumn = column == columnCount - 1

if (isFirstColumn) {
outRect.left = 0
} else if (isLastColumn) {
outRect.right = 0
}
}

val itemSize = recyclerView.adapter?.itemCount ?: 1
val numberOfRows = itemSize / columnCount

if (!shouldShowVerticalMargin) {
val isFirstRow = position < columnCount
val isLastRow = position > (numberOfRows - 1)

if (isFirstRow) {
outRect.top = 0
} else if (isLastRow) {
outRect.bottom = 0
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MenuRateFragment : Fragment() {

starImageView.setOnClickListener {
personImageView.setImageResource(R.drawable.ic_human_happy)
starImageView.setColorFilter(ContextCompat.getColor(context, R.color.orange))
starImageView.setColorFilter(ContextCompat.getColor(context, R.color.colorOrange))

launchPlayStore(packageName)
Navigation.findNavController(view).navigateUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.delacrixmorgan.kingscup.menu

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -13,6 +12,7 @@ import com.delacrixmorgan.kingscup.BuildConfig
import com.delacrixmorgan.kingscup.R
import com.delacrixmorgan.kingscup.common.launchShareGameIntent
import com.delacrixmorgan.kingscup.common.launchWebsite
import com.delacrixmorgan.kingscup.common.newEmailIntent
import kotlinx.android.synthetic.main.fragment_menu_setting.*

class MenuSettingFragment : Fragment() {
Expand Down Expand Up @@ -80,20 +80,4 @@ class MenuSettingFragment : Fragment() {
launchShareGameIntent(message)
}
}

private fun newEmailIntent(recipient: String, subject: String?, body: String?): Intent {
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:")
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(recipient))

if (!subject.isNullOrBlank()) {
intent.putExtra(Intent.EXTRA_SUBJECT, subject)
}

if (!body.isNullOrBlank()) {
intent.putExtra(Intent.EXTRA_TEXT, body)
}

return intent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package com.delacrixmorgan.kingscup.menu.language
import com.delacrixmorgan.kingscup.model.LanguageType

interface LanguageListener {
fun onLanguageSelected(languageType: LanguageType)
fun onHelpTranslateSelected(position: Int)
fun onLanguageSelected(position: Int, languageType: LanguageType)
}
Loading

0 comments on commit 6685a00

Please sign in to comment.