-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from delacrixmorgan/develop
v3.1.0 Redesigned Language Selection
- Loading branch information
Showing
40 changed files
with
552 additions
and
381 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 85 additions & 70 deletions
155
...xmorgan/kingscup/common/GameExtensions.kt → ...acrixmorgan/kingscup/common/Extensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
61 changes: 61 additions & 0 deletions
61
app/src/main/java/com/delacrixmorgan/kingscup/common/GridSpacingItemDecoration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.