Compare commits
46 Commits
master
...
feature/pl
| Author | SHA1 | Date |
|---|---|---|
|
|
cd6d5ab2ae | 6 years ago |
|
|
26cd102e46 | 6 years ago |
|
|
73b72deeb9 | 6 years ago |
|
|
d9c07bf291 | 6 years ago |
|
|
ea8bad6acc | 6 years ago |
|
|
c734898241 | 6 years ago |
|
|
75a2248469 | 6 years ago |
|
|
dcc6be514a | 6 years ago |
|
|
eef60124ed | 6 years ago |
|
|
1aef1c9745 | 6 years ago |
|
|
28699f594f | 6 years ago |
|
|
f1b47a6e51 | 6 years ago |
|
|
3843ab4185 | 6 years ago |
|
|
75b4097851 | 6 years ago |
|
|
071a39c241 | 6 years ago |
|
|
dff498ffa5 | 6 years ago |
|
|
d90aaa72bc | 6 years ago |
|
|
9ad428152c | 6 years ago |
|
|
54b6457fc9 | 6 years ago |
|
|
48868992a4 | 6 years ago |
|
|
358c65f9aa | 6 years ago |
|
|
5dfb008261 | 6 years ago |
|
|
3fa447e26c | 6 years ago |
|
|
599c29989a | 6 years ago |
|
|
2ca63b3a1a | 6 years ago |
|
|
2751850a92 | 6 years ago |
|
|
7abf6fd268 | 6 years ago |
|
|
7474b33a7e | 6 years ago |
|
|
7653ea86ce | 6 years ago |
|
|
c025f35d43 | 6 years ago |
|
|
e8f83ba08b | 6 years ago |
|
|
8835a7d4d6 | 6 years ago |
|
|
5882fd8cd6 | 6 years ago |
|
|
63d6c9b5b9 | 6 years ago |
|
|
20494c7849 | 6 years ago |
|
|
5689b8dfe4 | 6 years ago |
|
|
a2e9b8309c | 6 years ago |
|
|
ac2000ea8c | 6 years ago |
|
|
86a2f3bb1b | 6 years ago |
|
|
fa5e098b31 | 6 years ago |
|
|
45bdd93b78 | 7 years ago |
|
|
f1423257b1 | 7 years ago |
|
|
047a08c2a0 | 7 years ago |
|
|
b1064100a6 | 7 years ago |
|
|
c2f79015bc | 7 years ago |
|
|
75248ffdec | 7 years ago |
@ -0,0 +1,83 @@ |
|||||||
|
package net.pokeranalytics.android.model.realm |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import androidx.fragment.app.Fragment |
||||||
|
import io.realm.Realm |
||||||
|
import io.realm.RealmObject |
||||||
|
import io.realm.annotations.Ignore |
||||||
|
import io.realm.annotations.PrimaryKey |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.exceptions.ModelException |
||||||
|
import net.pokeranalytics.android.model.interfaces.DeleteValidityStatus |
||||||
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
||||||
|
import net.pokeranalytics.android.model.interfaces.Manageable |
||||||
|
import net.pokeranalytics.android.model.interfaces.SaveValidityStatus |
||||||
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.input.InputFragment |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.input.InputFragmentType |
||||||
|
import net.pokeranalytics.android.ui.view.RowEditableDataSource |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
|
import net.pokeranalytics.android.util.NULL_TEXT |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
open class Comment : RealmObject(), Manageable, RowRepresentable { |
||||||
|
|
||||||
|
@PrimaryKey |
||||||
|
override var id = UUID.randomUUID().toString() |
||||||
|
var content: String = "" |
||||||
|
var date: Date = Date() |
||||||
|
|
||||||
|
@Ignore |
||||||
|
override val realmObjectClass: Class<out Identifiable> = Comment::class.java |
||||||
|
|
||||||
|
@Ignore |
||||||
|
override val viewType: Int = RowViewType.CONTENT.ordinal |
||||||
|
|
||||||
|
@Ignore |
||||||
|
override val inputFragmentType: InputFragmentType = InputFragmentType.EDIT_TEXT_MULTI_LINES |
||||||
|
|
||||||
|
@Ignore |
||||||
|
override val valueCanBeClearedWhenEditing: Boolean = false |
||||||
|
|
||||||
|
override fun localizedTitle(context: Context): String { |
||||||
|
return context.getString(R.string.comment) |
||||||
|
} |
||||||
|
|
||||||
|
override fun getDisplayName(context: Context): String { |
||||||
|
return if (content.isNotEmpty()) content else NULL_TEXT |
||||||
|
} |
||||||
|
|
||||||
|
override fun startEditing(dataSource: Any?, parent: Fragment?) { |
||||||
|
if (parent == null) return |
||||||
|
if (parent !is RowRepresentableDelegate) return |
||||||
|
val data = RowEditableDataSource() |
||||||
|
data.append(this.content, R.string.value) |
||||||
|
InputFragment.buildAndShow(this, parent, data, isDeletable = true) |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
override fun updateValue(value: Any?, row: RowRepresentable) { |
||||||
|
this.content = value as String? ?: "" |
||||||
|
} |
||||||
|
|
||||||
|
override fun isValidForSave(): Boolean { |
||||||
|
return true |
||||||
|
} |
||||||
|
|
||||||
|
override fun alreadyExists(realm: Realm): Boolean { |
||||||
|
return realm.where(this::class.java).notEqualTo("id", this.id).findAll().isNotEmpty() |
||||||
|
} |
||||||
|
|
||||||
|
override fun getFailedSaveMessage(status: SaveValidityStatus): Int { |
||||||
|
throw ModelException("${this::class.java} getFailedSaveMessage for $status not handled") |
||||||
|
} |
||||||
|
|
||||||
|
override fun isValidForDelete(realm: Realm): Boolean { |
||||||
|
return true |
||||||
|
} |
||||||
|
|
||||||
|
override fun getFailedDeleteMessage(status: DeleteValidityStatus): Int { |
||||||
|
return R.string.cf_entry_delete_popup_message |
||||||
|
} |
||||||
|
} |
||||||
@ -1,15 +1,175 @@ |
|||||||
package net.pokeranalytics.android.model.realm |
package net.pokeranalytics.android.model.realm |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import io.realm.Realm |
||||||
|
import io.realm.RealmList |
||||||
import io.realm.RealmObject |
import io.realm.RealmObject |
||||||
|
import io.realm.annotations.Ignore |
||||||
import io.realm.annotations.PrimaryKey |
import io.realm.annotations.PrimaryKey |
||||||
|
import io.realm.kotlin.where |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.model.interfaces.* |
||||||
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.PlayerRow |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SeparatorRow |
||||||
|
import net.pokeranalytics.android.util.NULL_TEXT |
||||||
|
import net.pokeranalytics.android.util.extensions.isSameDay |
||||||
|
import net.pokeranalytics.android.util.extensions.mediumDate |
||||||
import java.util.* |
import java.util.* |
||||||
|
|
||||||
open class Player : RealmObject() { |
open class Player : RealmObject(), NameManageable, Deletable, StaticRowRepresentableDataSource, RowRepresentable { |
||||||
|
|
||||||
@PrimaryKey |
@PrimaryKey |
||||||
var id = UUID.randomUUID().toString() |
override var id = UUID.randomUUID().toString() |
||||||
|
|
||||||
// The name of the player |
// The name of the player |
||||||
var name: String = "" |
override var name: String = "" |
||||||
|
|
||||||
} |
// New fields |
||||||
|
var summary: String = "" |
||||||
|
var color: Int? = null |
||||||
|
var picture: String? = null |
||||||
|
var comments: RealmList<Comment> = RealmList() |
||||||
|
|
||||||
|
@Ignore |
||||||
|
override val realmObjectClass: Class<out Identifiable> = Player::class.java |
||||||
|
|
||||||
|
@Ignore |
||||||
|
override val viewType: Int = RowViewType.ROW_PLAYER.ordinal |
||||||
|
|
||||||
|
@Ignore |
||||||
|
private var rowRepresentation: List<RowRepresentable> = mutableListOf() |
||||||
|
|
||||||
|
@Ignore |
||||||
|
private var commentsToDelete: ArrayList<Comment> = ArrayList() |
||||||
|
|
||||||
|
|
||||||
|
override fun isValidForDelete(realm: Realm): Boolean { |
||||||
|
//TODO |
||||||
|
return true |
||||||
|
} |
||||||
|
|
||||||
|
override fun getFailedSaveMessage(status: SaveValidityStatus): Int { |
||||||
|
return when(status) { |
||||||
|
SaveValidityStatus.ALREADY_EXISTS -> R.string.duplicate_user_error |
||||||
|
else -> super.getFailedSaveMessage(status) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun getFailedDeleteMessage(status: DeleteValidityStatus): Int { |
||||||
|
//TODO |
||||||
|
return R.string.relationship_error |
||||||
|
} |
||||||
|
|
||||||
|
override fun adapterRows(): List<RowRepresentable>? { |
||||||
|
return rowRepresentation |
||||||
|
} |
||||||
|
|
||||||
|
override fun getDisplayName(context: Context): String { |
||||||
|
return this.name |
||||||
|
} |
||||||
|
|
||||||
|
override fun stringForRow(row: RowRepresentable): String { |
||||||
|
return when (row) { |
||||||
|
PlayerRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT |
||||||
|
else -> return super.stringForRow(row) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun updateValue(value: Any?, row: RowRepresentable) { |
||||||
|
when (row) { |
||||||
|
PlayerRow.NAME -> this.name = value as String? ?: "" |
||||||
|
PlayerRow.SUMMARY -> this.summary = value as String? ?: "" |
||||||
|
PlayerRow.IMAGE -> this.picture = value as String? ?: "" |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Update the row representation |
||||||
|
*/ |
||||||
|
private fun updatedRowRepresentationForCurrentState(): List<RowRepresentable> { |
||||||
|
val rows = ArrayList<RowRepresentable>() |
||||||
|
rows.add(PlayerRow.IMAGE) |
||||||
|
rows.add(PlayerRow.NAME) |
||||||
|
rows.add(PlayerRow.SUMMARY) |
||||||
|
|
||||||
|
if (comments.size > 0) { |
||||||
|
rows.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, R.string.comments)) |
||||||
|
|
||||||
|
val currentCommentCalendar = Calendar.getInstance() |
||||||
|
val currentDateCalendar = Calendar.getInstance() |
||||||
|
|
||||||
|
val commentsToDisplay = ArrayList<Comment>() |
||||||
|
commentsToDisplay.addAll(comments) |
||||||
|
commentsToDisplay.sortByDescending { it.date } |
||||||
|
|
||||||
|
commentsToDisplay.forEachIndexed { index, comment -> |
||||||
|
currentCommentCalendar.time = comment.date |
||||||
|
|
||||||
|
if (!currentCommentCalendar.isSameDay(currentDateCalendar) || index == 0) { |
||||||
|
currentDateCalendar.time = currentCommentCalendar.time |
||||||
|
rows.add(CustomizableRowRepresentable(RowViewType.HEADER_SUBTITLE, title = currentDateCalendar.time.mediumDate())) |
||||||
|
} |
||||||
|
|
||||||
|
rows.add(comment) |
||||||
|
} |
||||||
|
|
||||||
|
rows.add(SeparatorRow()) |
||||||
|
} |
||||||
|
|
||||||
|
return rows |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Return if the player has a picture |
||||||
|
*/ |
||||||
|
fun hasPicture(): Boolean { |
||||||
|
return picture != null && picture?.isNotEmpty() == true |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Update row representation |
||||||
|
*/ |
||||||
|
fun updateRowRepresentation() { |
||||||
|
this.rowRepresentation = this.updatedRowRepresentationForCurrentState() |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Add an entry |
||||||
|
*/ |
||||||
|
fun addComment(): Comment { |
||||||
|
val entry = Comment() |
||||||
|
this.comments.add(entry) |
||||||
|
updateRowRepresentation() |
||||||
|
return entry |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Delete an entry |
||||||
|
*/ |
||||||
|
fun deleteComment(comment: Comment) { |
||||||
|
commentsToDelete.add(comment) |
||||||
|
this.comments.remove(comment) |
||||||
|
updateRowRepresentation() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Clean up deleted entries |
||||||
|
*/ |
||||||
|
fun cleanupComments() { // called when saving the custom field |
||||||
|
val realm = Realm.getDefaultInstance() |
||||||
|
realm.executeTransaction { |
||||||
|
this.commentsToDelete.forEach { // entries are out of realm |
||||||
|
realm.where<Comment>().equalTo("id", it.id).findFirst()?.deleteFromRealm() |
||||||
|
} |
||||||
|
} |
||||||
|
realm.close() |
||||||
|
this.commentsToDelete.clear() |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,77 @@ |
|||||||
|
package net.pokeranalytics.android.ui.activity |
||||||
|
|
||||||
|
import android.app.Activity |
||||||
|
import android.content.Context |
||||||
|
import android.content.Intent |
||||||
|
import android.os.Bundle |
||||||
|
import android.view.View |
||||||
|
import androidx.fragment.app.Fragment |
||||||
|
import kotlinx.android.synthetic.main.activity_color_picker.* |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
||||||
|
|
||||||
|
class ColorPickerActivity : PokerAnalyticsActivity() { |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
const val INTENT_COLOR = "INTENT_COLOR" |
||||||
|
|
||||||
|
fun newInstance(context: Context) { |
||||||
|
val intent = Intent(context, ColorPickerActivity::class.java) |
||||||
|
context.startActivity(intent) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Create a new instance for result |
||||||
|
*/ |
||||||
|
fun newInstanceForResult(fragment: Fragment, requestCode: Int) { |
||||||
|
val intent = Intent(fragment.requireContext(), ColorPickerActivity::class.java) |
||||||
|
fragment.startActivityForResult(intent, requestCode) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) { |
||||||
|
super.onCreate(savedInstanceState) |
||||||
|
setContentView(R.layout.activity_color_picker) |
||||||
|
|
||||||
|
initUI() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init UI |
||||||
|
*/ |
||||||
|
private fun initUI() { |
||||||
|
color1.setOnClickListener { manageSelectedColor(it) } |
||||||
|
color2.setOnClickListener { manageSelectedColor(it) } |
||||||
|
color3.setOnClickListener { manageSelectedColor(it) } |
||||||
|
color4.setOnClickListener { manageSelectedColor(it) } |
||||||
|
color5.setOnClickListener { manageSelectedColor(it) } |
||||||
|
color6.setOnClickListener { manageSelectedColor(it) } |
||||||
|
color7.setOnClickListener { manageSelectedColor(it) } |
||||||
|
color8.setOnClickListener { manageSelectedColor(it) } |
||||||
|
color9.setOnClickListener { manageSelectedColor(it) } |
||||||
|
} |
||||||
|
|
||||||
|
private fun manageSelectedColor(view: View) { |
||||||
|
|
||||||
|
val color = when(view) { |
||||||
|
color1 -> getColor(R.color.player_color_1) |
||||||
|
color2 -> getColor(R.color.player_color_2) |
||||||
|
color3 -> getColor(R.color.player_color_3) |
||||||
|
color4 -> getColor(R.color.player_color_4) |
||||||
|
color5 -> getColor(R.color.player_color_5) |
||||||
|
color6 -> getColor(R.color.player_color_6) |
||||||
|
color7 -> getColor(R.color.player_color_7) |
||||||
|
color8 -> getColor(R.color.player_color_8) |
||||||
|
color9 -> getColor(R.color.player_color_9) |
||||||
|
else -> getColor(R.color.player_color_1) |
||||||
|
} |
||||||
|
|
||||||
|
val intent = Intent() |
||||||
|
intent.putExtra(INTENT_COLOR, color) |
||||||
|
setResult(Activity.RESULT_OK, intent) |
||||||
|
finish() |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,33 +0,0 @@ |
|||||||
package net.pokeranalytics.android.ui.activity |
|
||||||
|
|
||||||
import android.content.Context |
|
||||||
import android.content.Intent |
|
||||||
import android.os.Bundle |
|
||||||
import androidx.fragment.app.Fragment |
|
||||||
import net.pokeranalytics.android.R |
|
||||||
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
||||||
|
|
||||||
class ComparisonChartActivity : PokerAnalyticsActivity() { |
|
||||||
|
|
||||||
companion object { |
|
||||||
fun newInstance(context: Context) { |
|
||||||
val intent = Intent(context, ComparisonChartActivity::class.java) |
|
||||||
context.startActivity(intent) |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Create a new instance for result |
|
||||||
*/ |
|
||||||
fun newInstanceForResult(fragment: Fragment, requestCode: Int) { |
|
||||||
val intent = Intent(fragment.requireContext(), ComparisonChartActivity::class.java) |
|
||||||
fragment.startActivityForResult(intent, requestCode) |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) { |
|
||||||
super.onCreate(savedInstanceState) |
|
||||||
setContentView(R.layout.activity_comparison_chart) |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,268 @@ |
|||||||
|
package net.pokeranalytics.android.ui.activity.components |
||||||
|
|
||||||
|
import android.Manifest |
||||||
|
import android.app.Activity |
||||||
|
import android.content.Intent |
||||||
|
import android.content.pm.PackageManager |
||||||
|
import android.graphics.Bitmap |
||||||
|
import android.provider.MediaStore |
||||||
|
import androidx.core.app.ActivityCompat |
||||||
|
import androidx.core.content.ContextCompat |
||||||
|
import androidx.core.content.FileProvider |
||||||
|
import kotlinx.coroutines.Dispatchers |
||||||
|
import kotlinx.coroutines.GlobalScope |
||||||
|
import kotlinx.coroutines.launch |
||||||
|
import net.pokeranalytics.android.util.ImageUtils |
||||||
|
import timber.log.Timber |
||||||
|
import java.io.File |
||||||
|
import java.io.IOException |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
|
||||||
|
open class MediaActivity : PokerAnalyticsActivity() { |
||||||
|
|
||||||
|
companion object { |
||||||
|
const val SELECTED_CHOICE_TAKE_PICTURE = 10 |
||||||
|
const val SELECTED_CHOICE_SELECT_PICTURE = 11 |
||||||
|
const val REQUEST_CODE_TAKE_PICTURE = 100 |
||||||
|
const val REQUEST_CODE_SELECT_PICTURE = 101 |
||||||
|
const val PERMISSION_REQUEST_EXTERNAL_STORAGE = 201 |
||||||
|
const val PERMISSION_REQUEST_CAMERA = 202 |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
// Data |
||||||
|
private var tempFile: File? = null |
||||||
|
private var mCurrentPhotoPath: String? = null |
||||||
|
private var selectedChoice = -1 |
||||||
|
private var multiplePictures = false |
||||||
|
|
||||||
|
override fun onDestroy() { |
||||||
|
super.onDestroy() |
||||||
|
if (tempFile != null) { |
||||||
|
tempFile!!.delete() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
||||||
|
super.onActivityResult(requestCode, resultCode, data) |
||||||
|
|
||||||
|
if (resultCode == Activity.RESULT_OK) { |
||||||
|
if (requestCode == REQUEST_CODE_SELECT_PICTURE || requestCode == REQUEST_CODE_TAKE_PICTURE) { |
||||||
|
|
||||||
|
val filesList = ArrayList<File>() |
||||||
|
|
||||||
|
GlobalScope.launch { |
||||||
|
|
||||||
|
if (tempFile != null) { |
||||||
|
tempFile?.let { |
||||||
|
GlobalScope.launch(Dispatchers.Main) { |
||||||
|
filesList.add(it) |
||||||
|
getPictures(filesList) |
||||||
|
} |
||||||
|
} |
||||||
|
} else if (data?.clipData != null) { |
||||||
|
data?.clipData?.let { clipData -> |
||||||
|
try { |
||||||
|
|
||||||
|
GlobalScope.launch(Dispatchers.Main) { |
||||||
|
isLoadingNewPictures() |
||||||
|
} |
||||||
|
|
||||||
|
for (i in 0 until clipData.itemCount) { |
||||||
|
val item = clipData.getItemAt(i) |
||||||
|
val uri = item.uri |
||||||
|
val inputStream = contentResolver.openInputStream(uri) |
||||||
|
val photoFile = ImageUtils.createTempImageFile(this@MediaActivity) |
||||||
|
ImageUtils.copyInputStreamToFile(inputStream!!, photoFile) |
||||||
|
filesList.add(photoFile) |
||||||
|
} |
||||||
|
|
||||||
|
GlobalScope.launch(Dispatchers.Main) { |
||||||
|
getPictures(filesList) |
||||||
|
} |
||||||
|
|
||||||
|
} catch (e: Exception) { |
||||||
|
e.printStackTrace() |
||||||
|
} |
||||||
|
} |
||||||
|
} else if (data?.data != null) { |
||||||
|
data?.data?.let { uri -> |
||||||
|
try { |
||||||
|
|
||||||
|
GlobalScope.launch(Dispatchers.Main) { |
||||||
|
isLoadingNewPictures() |
||||||
|
} |
||||||
|
|
||||||
|
val inputStream = contentResolver.openInputStream(uri) |
||||||
|
val photoFile = ImageUtils.createTempImageFile(this@MediaActivity) |
||||||
|
ImageUtils.copyInputStreamToFile(inputStream!!, photoFile) |
||||||
|
filesList.add(photoFile) |
||||||
|
GlobalScope.launch(Dispatchers.Main) { |
||||||
|
getPictures(filesList) |
||||||
|
} |
||||||
|
|
||||||
|
} catch (e: Exception) { |
||||||
|
e.printStackTrace() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { |
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults) |
||||||
|
|
||||||
|
if (grantResults.isNotEmpty()) { |
||||||
|
for (result in grantResults) { |
||||||
|
if (result != PackageManager.PERMISSION_GRANTED) { |
||||||
|
//Toast.makeText(this, getString(R.string.photo_library_add_usage_description), Toast.LENGTH_SHORT).show() |
||||||
|
selectedChoice = -1 |
||||||
|
return |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
when (selectedChoice) { |
||||||
|
SELECTED_CHOICE_TAKE_PICTURE -> { |
||||||
|
openImageCaptureIntent(multiplePictures) |
||||||
|
} |
||||||
|
SELECTED_CHOICE_SELECT_PICTURE -> { |
||||||
|
openImageGalleryIntent(multiplePictures) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
selectedChoice = -1 |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Open the Camera Intent |
||||||
|
*/ |
||||||
|
fun openImageCaptureIntent(multiplePictures: Boolean) { |
||||||
|
|
||||||
|
tempFile = null |
||||||
|
|
||||||
|
this.mCurrentPhotoPath = null |
||||||
|
this.multiplePictures = multiplePictures |
||||||
|
|
||||||
|
// Test if we have the permission |
||||||
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { |
||||||
|
selectedChoice = SELECTED_CHOICE_TAKE_PICTURE |
||||||
|
askForStoragePermission() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) |
||||||
|
// Ensure that there's a camera activity to handle the intent |
||||||
|
if (takePictureIntent.resolveActivity(packageManager) != null) { |
||||||
|
// Create the File where the photo should go |
||||||
|
try { |
||||||
|
tempFile = ImageUtils.createImageFile(this) |
||||||
|
mCurrentPhotoPath = "file:" + tempFile?.absolutePath |
||||||
|
} catch (ex: IOException) { |
||||||
|
// Error occurred while creating the File |
||||||
|
} |
||||||
|
|
||||||
|
// Continue only if the File was successfully created |
||||||
|
if (tempFile != null) { |
||||||
|
Timber.d("tempFile: ${tempFile?.absolutePath}") |
||||||
|
val photoURI = FileProvider.getUriForFile( |
||||||
|
this, |
||||||
|
applicationContext.packageName + ".fileprovider", tempFile!! |
||||||
|
) |
||||||
|
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI) |
||||||
|
startActivityForResult(takePictureIntent, REQUEST_CODE_TAKE_PICTURE) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Open the gallery intent |
||||||
|
*/ |
||||||
|
fun openImageGalleryIntent(multiplePictures: Boolean) { |
||||||
|
|
||||||
|
tempFile = null |
||||||
|
|
||||||
|
this.multiplePictures = multiplePictures |
||||||
|
|
||||||
|
// Test if we have the permission |
||||||
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { |
||||||
|
selectedChoice = SELECTED_CHOICE_SELECT_PICTURE |
||||||
|
askForStoragePermission() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
this.multiplePictures = multiplePictures |
||||||
|
|
||||||
|
val galleryIntent = Intent() |
||||||
|
galleryIntent.type = "image/*" |
||||||
|
galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiplePictures) |
||||||
|
galleryIntent.action = Intent.ACTION_GET_CONTENT |
||||||
|
startActivityForResult(galleryIntent, REQUEST_CODE_SELECT_PICTURE) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Ask for the external storage permission |
||||||
|
*/ |
||||||
|
private fun askForStoragePermission() { |
||||||
|
// Here, thisActivity is the current activity |
||||||
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { |
||||||
|
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), |
||||||
|
PERMISSION_REQUEST_EXTERNAL_STORAGE) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Ask for the acmera permission |
||||||
|
*/ |
||||||
|
private fun askForCameraPermission() { |
||||||
|
// Here, thisActivity is the current activity |
||||||
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { |
||||||
|
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), |
||||||
|
PERMISSION_REQUEST_CAMERA) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Ask for camera and storage permission |
||||||
|
*/ |
||||||
|
private fun askForCameraAndStoragePermissions() { |
||||||
|
|
||||||
|
val permissions = ArrayList<String>() |
||||||
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { |
||||||
|
permissions.add(Manifest.permission.CAMERA) |
||||||
|
} |
||||||
|
|
||||||
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { |
||||||
|
permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE) |
||||||
|
} |
||||||
|
|
||||||
|
if (permissions.size > 0) { |
||||||
|
ActivityCompat.requestPermissions(this, permissions.toArray(arrayOfNulls<String>(permissions.size)), PERMISSION_REQUEST_CAMERA) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Called when a bitmap is return |
||||||
|
* |
||||||
|
* @param bitmap the bitmap returned |
||||||
|
*/ |
||||||
|
open fun getBitmapImage(file: File?, bitmap: Bitmap?) {} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Called when the user is adding new photos |
||||||
|
*/ |
||||||
|
open fun isLoadingNewPictures() {} |
||||||
|
|
||||||
|
/** |
||||||
|
* Called when the user has selected photos |
||||||
|
*/ |
||||||
|
open fun getPictures(files: ArrayList<File>) {} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -1,115 +0,0 @@ |
|||||||
package net.pokeranalytics.android.ui.fragment |
|
||||||
|
|
||||||
import android.os.Bundle |
|
||||||
import android.view.* |
|
||||||
import kotlinx.android.synthetic.main.fragment_comparison_chart.* |
|
||||||
import net.pokeranalytics.android.R |
|
||||||
import net.pokeranalytics.android.ui.activity.BankrollActivity |
|
||||||
import net.pokeranalytics.android.ui.activity.SettingsActivity |
|
||||||
import net.pokeranalytics.android.ui.adapter.ComparisonChartPagerAdapter |
|
||||||
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
||||||
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
||||||
import net.pokeranalytics.android.ui.extensions.toast |
|
||||||
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
||||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
||||||
import net.pokeranalytics.android.ui.view.rowrepresentable.MoreTabRow |
|
||||||
|
|
||||||
class ComparisonChartFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
||||||
|
|
||||||
companion object { |
|
||||||
|
|
||||||
/** |
|
||||||
* Create new instance |
|
||||||
*/ |
|
||||||
fun newInstance(): ComparisonChartFragment { |
|
||||||
val fragment = ComparisonChartFragment() |
|
||||||
val bundle = Bundle() |
|
||||||
fragment.arguments = bundle |
|
||||||
return fragment |
|
||||||
} |
|
||||||
|
|
||||||
val rowRepresentation: List<RowRepresentable> by lazy { |
|
||||||
val rows = ArrayList<RowRepresentable>() |
|
||||||
rows.addAll(MoreTabRow.values()) |
|
||||||
rows |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
private lateinit var viewPagerAdapter: ComparisonChartPagerAdapter |
|
||||||
private var comparisonChartMenu: Menu? = null |
|
||||||
|
|
||||||
|
|
||||||
// Life Cycle |
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
||||||
return inflater.inflate(R.layout.fragment_comparison_chart, container, false) |
|
||||||
} |
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
||||||
super.onViewCreated(view, savedInstanceState) |
|
||||||
initData() |
|
||||||
initUI() |
|
||||||
} |
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { |
|
||||||
menu?.clear() |
|
||||||
inflater?.inflate(R.menu.toolbar_comparison_chart, menu) |
|
||||||
this.comparisonChartMenu = menu |
|
||||||
super.onCreateOptionsMenu(menu, inflater) |
|
||||||
} |
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean { |
|
||||||
when (item!!.itemId) { |
|
||||||
R.id.settings -> openChangeStatistics() |
|
||||||
} |
|
||||||
return true |
|
||||||
} |
|
||||||
|
|
||||||
// Rows |
|
||||||
override fun adapterRows(): List<RowRepresentable>? { |
|
||||||
return rowRepresentation |
|
||||||
} |
|
||||||
|
|
||||||
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
||||||
super.onRowSelected(position, row, fromAction) |
|
||||||
when(row) { |
|
||||||
MoreTabRow.BANKROLL -> BankrollActivity.newInstance(requireContext()) |
|
||||||
MoreTabRow.SETTINGS -> SettingsActivity.newInstance(requireContext()) |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Business |
|
||||||
|
|
||||||
/** |
|
||||||
* Init data |
|
||||||
*/ |
|
||||||
private fun initData() { |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Init UI |
|
||||||
*/ |
|
||||||
private fun initUI() { |
|
||||||
|
|
||||||
setDisplayHomeAsUpEnabled(true) |
|
||||||
setToolbarTitle(getString(R.string.comparison_chart)) |
|
||||||
|
|
||||||
parentActivity?.let { |
|
||||||
viewPagerAdapter = ComparisonChartPagerAdapter(requireContext(), it.supportFragmentManager) |
|
||||||
viewPager.adapter = viewPagerAdapter |
|
||||||
viewPager.offscreenPageLimit = 2 |
|
||||||
tabs.setupWithViewPager(viewPager) |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Open change statistics |
|
||||||
*/ |
|
||||||
private fun openChangeStatistics() { |
|
||||||
//TODO |
|
||||||
toast("Open change statistics") |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,94 +1,198 @@ |
|||||||
package net.pokeranalytics.android.ui.fragment |
package net.pokeranalytics.android.ui.fragment |
||||||
|
|
||||||
|
import android.app.Activity |
||||||
|
import android.content.ActivityNotFoundException |
||||||
|
import android.content.Intent |
||||||
|
import android.net.Uri |
||||||
import android.os.Bundle |
import android.os.Bundle |
||||||
import android.view.LayoutInflater |
import android.view.LayoutInflater |
||||||
import android.view.View |
import android.view.View |
||||||
import android.view.ViewGroup |
import android.view.ViewGroup |
||||||
import androidx.recyclerview.widget.LinearLayoutManager |
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import io.realm.Realm |
||||||
import kotlinx.android.synthetic.main.fragment_more.* |
import kotlinx.android.synthetic.main.fragment_more.* |
||||||
|
import net.pokeranalytics.android.BuildConfig |
||||||
import net.pokeranalytics.android.R |
import net.pokeranalytics.android.R |
||||||
import net.pokeranalytics.android.ui.activity.BankrollActivity |
import net.pokeranalytics.android.model.LiveData |
||||||
import net.pokeranalytics.android.ui.activity.SettingsActivity |
import net.pokeranalytics.android.model.realm.Currency |
||||||
import net.pokeranalytics.android.ui.activity.Top10Activity |
import net.pokeranalytics.android.model.realm.Session |
||||||
|
import net.pokeranalytics.android.ui.activity.* |
||||||
|
import net.pokeranalytics.android.ui.activity.components.RequestCode |
||||||
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
||||||
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
||||||
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
||||||
|
import net.pokeranalytics.android.ui.extensions.openContactMail |
||||||
|
import net.pokeranalytics.android.ui.extensions.openPlayStorePage |
||||||
|
import net.pokeranalytics.android.ui.extensions.openUrl |
||||||
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
||||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
import net.pokeranalytics.android.ui.view.rowrepresentable.MoreTabRow |
import net.pokeranalytics.android.ui.view.rowrepresentable.SettingRow |
||||||
|
import net.pokeranalytics.android.util.Preferences |
||||||
|
import net.pokeranalytics.android.util.URL |
||||||
|
import net.pokeranalytics.android.util.UserDefaults |
||||||
|
import net.pokeranalytics.android.util.billing.AppGuard |
||||||
|
import net.pokeranalytics.android.util.billing.IAPProducts |
||||||
|
import timber.log.Timber |
||||||
|
import java.util.* |
||||||
|
|
||||||
class MoreFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
||||||
|
|
||||||
companion object { |
class MoreFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, StaticRowRepresentableDataSource { |
||||||
|
|
||||||
/** |
|
||||||
* Create new instance |
|
||||||
*/ |
|
||||||
fun newInstance(): MoreFragment { |
|
||||||
val fragment = MoreFragment() |
|
||||||
val bundle = Bundle() |
|
||||||
fragment.arguments = bundle |
|
||||||
return fragment |
|
||||||
} |
|
||||||
|
|
||||||
val rowRepresentation: List<RowRepresentable> by lazy { |
companion object { |
||||||
val rows = ArrayList<RowRepresentable>() |
|
||||||
rows.addAll(MoreTabRow.values()) |
|
||||||
rows |
|
||||||
} |
|
||||||
|
|
||||||
} |
/** |
||||||
|
* Create new instance |
||||||
|
*/ |
||||||
|
fun newInstance(): MoreFragment { |
||||||
|
val fragment = MoreFragment() |
||||||
|
val bundle = Bundle() |
||||||
|
fragment.arguments = bundle |
||||||
|
return fragment |
||||||
|
} |
||||||
|
|
||||||
|
val rowRepresentation: List<RowRepresentable> by lazy { |
||||||
|
val rows = ArrayList<RowRepresentable>() |
||||||
|
rows.addAll(SettingRow.getRows()) |
||||||
|
rows |
||||||
|
} |
||||||
|
|
||||||
private lateinit var moreAdapter: RowRepresentableAdapter |
} |
||||||
|
|
||||||
|
private lateinit var settingsAdapterRow: RowRepresentableAdapter |
||||||
|
|
||||||
// Life Cycle |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
||||||
|
return inflater.inflate(R.layout.fragment_more, container, false) |
||||||
|
} |
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||||
return inflater.inflate(R.layout.fragment_more, container, false) |
super.onViewCreated(view, savedInstanceState) |
||||||
} |
initData() |
||||||
|
initUI() |
||||||
|
} |
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
||||||
super.onViewCreated(view, savedInstanceState) |
|
||||||
initData() |
when (requestCode) { |
||||||
initUI() |
RequestCode.CURRENCY.value -> { |
||||||
} |
if (resultCode == Activity.RESULT_OK) { |
||||||
|
data?.let { |
||||||
|
Preferences.setCurrencyCode(data.getStringExtra(CurrenciesFragment.INTENT_CURRENCY_CODE), requireContext()) |
||||||
|
val realm = Realm.getDefaultInstance() |
||||||
|
realm.executeTransaction { |
||||||
|
realm.where(Currency::class.java).isNull("code").or().equalTo("code", UserDefaults.currency.currencyCode).findAll() |
||||||
|
.forEach { currency -> |
||||||
|
currency.rate = Currency.DEFAULT_RATE |
||||||
|
} |
||||||
|
|
||||||
|
realm.where(Session::class.java).isNull("bankroll.currency.code").findAll().forEach { session -> |
||||||
|
session.bankrollHasBeenUpdated() |
||||||
|
} |
||||||
|
} |
||||||
|
realm.close() |
||||||
|
settingsAdapterRow.refreshRow(SettingRow.CURRENCY) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
RequestCode.SUBSCRIPTION.value -> { |
||||||
|
settingsAdapterRow.refreshRow(SettingRow.SUBSCRIPTION) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
// Rows |
|
||||||
override fun adapterRows(): List<RowRepresentable>? { |
override fun adapterRows(): List<RowRepresentable>? { |
||||||
return rowRepresentation |
return rowRepresentation |
||||||
} |
} |
||||||
|
|
||||||
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
override fun stringForRow(row: RowRepresentable): String { |
||||||
super.onRowSelected(position, row, fromAction) |
return when (row) { |
||||||
when(row) { |
SettingRow.SUBSCRIPTION -> AppGuard.subscriptionStatus(requireContext()) |
||||||
MoreTabRow.BANKROLL -> BankrollActivity.newInstance(requireContext()) |
SettingRow.VERSION -> BuildConfig.VERSION_NAME + if (BuildConfig.DEBUG) " (${BuildConfig.VERSION_CODE}) DEBUG" else "" |
||||||
MoreTabRow.TOP_10 -> Top10Activity.newInstance(requireContext()) |
SettingRow.CURRENCY -> UserDefaults.currency.symbol |
||||||
MoreTabRow.SETTINGS -> SettingsActivity.newInstance(requireContext()) |
else -> "" |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
// Business |
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
||||||
|
when (row) { |
||||||
|
SettingRow.BANKROLL_REPORT -> BankrollActivity.newInstance(requireContext()) |
||||||
|
SettingRow.TOP_10 -> Top10Activity.newInstance(requireContext()) |
||||||
|
SettingRow.PLAYERS -> DataListActivity.newInstance(requireContext(), LiveData.PLAYER.ordinal) |
||||||
|
SettingRow.SUBSCRIPTION -> { |
||||||
|
if (!AppGuard.isProUser) { |
||||||
|
BillingActivity.newInstanceForResult(this, false) |
||||||
|
} else { |
||||||
|
this.openPlaystoreAccount() |
||||||
|
} |
||||||
|
} |
||||||
|
SettingRow.RATE_APP -> parentActivity?.openPlayStorePage() |
||||||
|
SettingRow.CONTACT_US -> parentActivity?.openContactMail(R.string.contact) |
||||||
|
SettingRow.BUG_REPORT -> parentActivity?.openContactMail(R.string.bug_report_subject, Realm.getDefaultInstance().path) |
||||||
|
SettingRow.CURRENCY -> CurrenciesActivity.newInstanceForResult(this@MoreFragment, RequestCode.CURRENCY.value) |
||||||
|
SettingRow.FOLLOW_US -> { |
||||||
|
when (position) { |
||||||
|
0 -> parentActivity?.openUrl(URL.BLOG.value) |
||||||
|
1 -> parentActivity?.openUrl(URL.INSTAGRAM.value) |
||||||
|
2 -> parentActivity?.openUrl(URL.TWITTER.value) |
||||||
|
3 -> parentActivity?.openUrl(URL.FACEBOOK.value) |
||||||
|
} |
||||||
|
} |
||||||
|
SettingRow.PRIVACY_POLICY -> parentActivity?.openUrl(URL.PRIVACY_POLICY.value) |
||||||
|
SettingRow.TERMS_OF_USE -> parentActivity?.openUrl(URL.TERMS.value) |
||||||
|
SettingRow.GDPR -> openGDPRActivity() |
||||||
|
} |
||||||
|
|
||||||
/** |
row.relatedResultsRepresentable?.let { |
||||||
* Init data |
DataListActivity.newInstance(requireContext(), it.ordinal) |
||||||
*/ |
} |
||||||
private fun initData() { |
} |
||||||
} |
|
||||||
|
|
||||||
/** |
/** |
||||||
* Init UI |
* Init UI |
||||||
*/ |
*/ |
||||||
private fun initUI() { |
private fun initUI() { |
||||||
|
|
||||||
moreAdapter = RowRepresentableAdapter(this, this) |
setToolbarTitle(getString(R.string.more)) |
||||||
|
|
||||||
val viewManager = LinearLayoutManager(requireContext()) |
val viewManager = LinearLayoutManager(requireContext()) |
||||||
|
settingsAdapterRow = RowRepresentableAdapter( |
||||||
|
this, this |
||||||
|
) |
||||||
|
|
||||||
recyclerView.apply { |
recyclerView.apply { |
||||||
setHasFixedSize(true) |
setHasFixedSize(true) |
||||||
layoutManager = viewManager |
layoutManager = viewManager |
||||||
adapter = moreAdapter |
adapter = settingsAdapterRow |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init data |
||||||
|
*/ |
||||||
|
private fun initData() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Open GDPR Activity |
||||||
|
*/ |
||||||
|
private fun openGDPRActivity() { |
||||||
|
val intent = Intent(requireContext(), GDPRActivity::class.java) |
||||||
|
startActivity(intent) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Open Google Play account |
||||||
|
*/ |
||||||
|
private fun openPlaystoreAccount() { |
||||||
|
|
||||||
|
val packageName = "net.pokeranalytics.android" |
||||||
|
val sku = IAPProducts.PRO.identifier |
||||||
|
|
||||||
|
try { |
||||||
|
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/account/subscriptions?sku=$sku&package=$packageName"))) |
||||||
|
} catch (e: ActivityNotFoundException) { |
||||||
|
Timber.d(e) |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
|||||||
@ -1,198 +0,0 @@ |
|||||||
package net.pokeranalytics.android.ui.fragment |
|
||||||
|
|
||||||
import android.app.Activity |
|
||||||
import android.content.ActivityNotFoundException |
|
||||||
import android.content.Intent |
|
||||||
import android.net.Uri |
|
||||||
import android.os.Bundle |
|
||||||
import android.view.LayoutInflater |
|
||||||
import android.view.View |
|
||||||
import android.view.ViewGroup |
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager |
|
||||||
import io.realm.Realm |
|
||||||
import kotlinx.android.synthetic.main.fragment_settings.* |
|
||||||
import net.pokeranalytics.android.BuildConfig |
|
||||||
import net.pokeranalytics.android.R |
|
||||||
import net.pokeranalytics.android.model.realm.Currency |
|
||||||
import net.pokeranalytics.android.model.realm.Session |
|
||||||
import net.pokeranalytics.android.ui.activity.* |
|
||||||
import net.pokeranalytics.android.ui.activity.components.RequestCode |
|
||||||
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
||||||
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
||||||
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
||||||
import net.pokeranalytics.android.ui.extensions.openContactMail |
|
||||||
import net.pokeranalytics.android.ui.extensions.openPlayStorePage |
|
||||||
import net.pokeranalytics.android.ui.extensions.openUrl |
|
||||||
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
||||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
||||||
import net.pokeranalytics.android.ui.view.rowrepresentable.SettingRow |
|
||||||
import net.pokeranalytics.android.util.Preferences |
|
||||||
import net.pokeranalytics.android.util.URL |
|
||||||
import net.pokeranalytics.android.util.UserDefaults |
|
||||||
import net.pokeranalytics.android.util.billing.AppGuard |
|
||||||
import net.pokeranalytics.android.util.billing.IAPProducts |
|
||||||
import timber.log.Timber |
|
||||||
import java.util.* |
|
||||||
|
|
||||||
|
|
||||||
class SettingsFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, StaticRowRepresentableDataSource { |
|
||||||
|
|
||||||
|
|
||||||
companion object { |
|
||||||
|
|
||||||
/** |
|
||||||
* Create new instance |
|
||||||
*/ |
|
||||||
fun newInstance(): SettingsFragment { |
|
||||||
val fragment = SettingsFragment() |
|
||||||
val bundle = Bundle() |
|
||||||
fragment.arguments = bundle |
|
||||||
return fragment |
|
||||||
} |
|
||||||
|
|
||||||
val rowRepresentation: List<RowRepresentable> by lazy { |
|
||||||
val rows = ArrayList<RowRepresentable>() |
|
||||||
rows.addAll(SettingRow.getRows()) |
|
||||||
rows |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
private lateinit var settingsAdapterRow: RowRepresentableAdapter |
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
||||||
return inflater.inflate(R.layout.fragment_settings, container, false) |
|
||||||
} |
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
||||||
super.onViewCreated(view, savedInstanceState) |
|
||||||
initData() |
|
||||||
initUI() |
|
||||||
} |
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
||||||
|
|
||||||
when (requestCode) { |
|
||||||
RequestCode.CURRENCY.value -> { |
|
||||||
if (resultCode == Activity.RESULT_OK) { |
|
||||||
data?.let { |
|
||||||
Preferences.setCurrencyCode(data.getStringExtra(CurrenciesFragment.INTENT_CURRENCY_CODE), requireContext()) |
|
||||||
val realm = Realm.getDefaultInstance() |
|
||||||
realm.executeTransaction { |
|
||||||
realm.where(Currency::class.java).isNull("code").or().equalTo("code", UserDefaults.currency.currencyCode).findAll().forEach { currency -> |
|
||||||
currency.rate = Currency.DEFAULT_RATE |
|
||||||
} |
|
||||||
|
|
||||||
realm.where(Session::class.java).isNull("bankroll.currency.code").findAll().forEach { session -> |
|
||||||
session.bankrollHasBeenUpdated() |
|
||||||
} |
|
||||||
} |
|
||||||
realm.close() |
|
||||||
settingsAdapterRow.refreshRow(SettingRow.CURRENCY) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
RequestCode.SUBSCRIPTION.value -> { |
|
||||||
settingsAdapterRow.refreshRow(SettingRow.SUBSCRIPTION) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
override fun adapterRows(): List<RowRepresentable>? { |
|
||||||
return rowRepresentation |
|
||||||
} |
|
||||||
|
|
||||||
override fun stringForRow(row: RowRepresentable): String { |
|
||||||
return when (row) { |
|
||||||
SettingRow.SUBSCRIPTION -> AppGuard.subscriptionStatus(requireContext()) |
|
||||||
SettingRow.VERSION -> BuildConfig.VERSION_NAME + if (BuildConfig.DEBUG) " (${BuildConfig.VERSION_CODE}) DEBUG" else "" |
|
||||||
SettingRow.CURRENCY -> UserDefaults.currency.symbol |
|
||||||
else -> "" |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
||||||
when (row) { |
|
||||||
SettingRow.BANKROLL_REPORT -> BankrollActivity.newInstance(requireContext()) |
|
||||||
SettingRow.TOP_10 -> Top10Activity.newInstance(requireContext()) |
|
||||||
SettingRow.SUBSCRIPTION -> { |
|
||||||
if (!AppGuard.isProUser) { |
|
||||||
BillingActivity.newInstanceForResult(this, false) |
|
||||||
} else { |
|
||||||
this.openPlaystoreAccount() |
|
||||||
} |
|
||||||
} |
|
||||||
SettingRow.RATE_APP -> parentActivity?.openPlayStorePage() |
|
||||||
SettingRow.CONTACT_US -> parentActivity?.openContactMail(R.string.contact) |
|
||||||
SettingRow.BUG_REPORT -> parentActivity?.openContactMail(R.string.bug_report_subject, Realm.getDefaultInstance().path) |
|
||||||
SettingRow.CURRENCY -> CurrenciesActivity.newInstanceForResult(this@SettingsFragment, RequestCode.CURRENCY.value) |
|
||||||
SettingRow.FOLLOW_US -> { |
|
||||||
when (position) { |
|
||||||
0 -> parentActivity?.openUrl(URL.BLOG.value) |
|
||||||
1 -> parentActivity?.openUrl(URL.INSTAGRAM.value) |
|
||||||
2 -> parentActivity?.openUrl(URL.TWITTER.value) |
|
||||||
3 -> parentActivity?.openUrl(URL.FACEBOOK.value) |
|
||||||
} |
|
||||||
} |
|
||||||
SettingRow.PRIVACY_POLICY -> parentActivity?.openUrl(URL.PRIVACY_POLICY.value) |
|
||||||
SettingRow.TERMS_OF_USE -> parentActivity?.openUrl(URL.TERMS.value) |
|
||||||
SettingRow.GDPR -> openGDPRActivity() |
|
||||||
} |
|
||||||
|
|
||||||
row.relatedResultsRepresentable?.let { |
|
||||||
DataListActivity.newInstance(requireContext(), it.ordinal) |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Init UI |
|
||||||
*/ |
|
||||||
private fun initUI() { |
|
||||||
|
|
||||||
setToolbarTitle(getString(R.string.more)) |
|
||||||
|
|
||||||
setDisplayHomeAsUpEnabled(true) |
|
||||||
|
|
||||||
val viewManager = LinearLayoutManager(requireContext()) |
|
||||||
settingsAdapterRow = RowRepresentableAdapter( |
|
||||||
this, this |
|
||||||
) |
|
||||||
|
|
||||||
recyclerView.apply { |
|
||||||
setHasFixedSize(true) |
|
||||||
layoutManager = viewManager |
|
||||||
adapter = settingsAdapterRow |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Init data |
|
||||||
*/ |
|
||||||
private fun initData() { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Open GDPR Activity |
|
||||||
*/ |
|
||||||
private fun openGDPRActivity() { |
|
||||||
val intent = Intent(requireContext(), GDPRActivity::class.java) |
|
||||||
startActivity(intent) |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Open Google Play account |
|
||||||
*/ |
|
||||||
private fun openPlaystoreAccount() { |
|
||||||
|
|
||||||
val packageName = "net.pokeranalytics.android" |
|
||||||
val sku = IAPProducts.PRO.identifier |
|
||||||
|
|
||||||
try { |
|
||||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/account/subscriptions?sku=$sku&package=$packageName"))) |
|
||||||
} catch (e: ActivityNotFoundException) { |
|
||||||
Timber.d(e) |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,50 +0,0 @@ |
|||||||
package net.pokeranalytics.android.ui.fragment.components.bottomsheet |
|
||||||
|
|
||||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
||||||
|
|
||||||
enum class BottomSheetType { |
|
||||||
NONE, |
|
||||||
LIST, |
|
||||||
LIST_STATIC, |
|
||||||
LIST_GAME, |
|
||||||
DOUBLE_LIST, |
|
||||||
MULTI_SELECTION, |
|
||||||
GRID, |
|
||||||
EDIT_TEXT, |
|
||||||
EDIT_TEXT_MULTI_LINES, |
|
||||||
DOUBLE_EDIT_TEXT, |
|
||||||
NUMERIC_TEXT, |
|
||||||
SUM; |
|
||||||
|
|
||||||
fun newInstance(row: RowRepresentable): BottomSheetFragment { |
|
||||||
return when (this) { |
|
||||||
NONE -> BottomSheetFragment(row) |
|
||||||
LIST -> BottomSheetListFragment(row) |
|
||||||
LIST_STATIC -> BottomSheetStaticListFragment(row) |
|
||||||
LIST_GAME -> BottomSheetListGameFragment(row) |
|
||||||
DOUBLE_LIST -> BottomSheetListGameFragment(row) |
|
||||||
MULTI_SELECTION -> BottomSheetMultiSelectionFragment(row) |
|
||||||
GRID -> BottomSheetTableSizeGridFragment(row) |
|
||||||
EDIT_TEXT -> BottomSheetEditTextFragment(row) |
|
||||||
EDIT_TEXT_MULTI_LINES -> BottomSheetEditTextMultiLinesFragment(row) |
|
||||||
DOUBLE_EDIT_TEXT -> BottomSheetDoubleEditTextFragment(row) |
|
||||||
NUMERIC_TEXT -> BottomSheetNumericTextFragment(row) |
|
||||||
SUM -> BottomSheetSumFragment(row) |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
val validationRequired: Boolean |
|
||||||
get() = when (this) { |
|
||||||
LIST, LIST_GAME, LIST_STATIC, GRID, DOUBLE_LIST -> false |
|
||||||
else -> true |
|
||||||
} |
|
||||||
|
|
||||||
val clearRequired: Boolean |
|
||||||
get() = true |
|
||||||
|
|
||||||
val addRequired: Boolean |
|
||||||
get() = when (this) { |
|
||||||
EDIT_TEXT, NUMERIC_TEXT, DOUBLE_EDIT_TEXT, EDIT_TEXT_MULTI_LINES, GRID, LIST_STATIC, SUM -> false |
|
||||||
else -> true |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,50 @@ |
|||||||
|
package net.pokeranalytics.android.ui.fragment.components.input |
||||||
|
|
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
|
||||||
|
enum class InputFragmentType { |
||||||
|
NONE, |
||||||
|
LIST, |
||||||
|
LIST_STATIC, |
||||||
|
LIST_GAME, |
||||||
|
DOUBLE_LIST, |
||||||
|
MULTI_SELECTION, |
||||||
|
GRID, |
||||||
|
EDIT_TEXT, |
||||||
|
EDIT_TEXT_MULTI_LINES, |
||||||
|
DOUBLE_EDIT_TEXT, |
||||||
|
NUMERIC_TEXT, |
||||||
|
SUM; |
||||||
|
|
||||||
|
fun newInstance(row: RowRepresentable): InputFragment { |
||||||
|
return when (this) { |
||||||
|
NONE -> InputFragment(row) |
||||||
|
LIST -> InputListFragment(row) |
||||||
|
LIST_STATIC -> InputStaticListFragment(row) |
||||||
|
LIST_GAME -> InputListGameFragment(row) |
||||||
|
DOUBLE_LIST -> InputListGameFragment(row) |
||||||
|
MULTI_SELECTION -> InputMultiSelectionFragment(row) |
||||||
|
GRID -> InputTableSizeGridFragment(row) |
||||||
|
EDIT_TEXT -> InputEditTextFragment(row) |
||||||
|
EDIT_TEXT_MULTI_LINES -> InputEditTextMultiLinesFragment(row) |
||||||
|
DOUBLE_EDIT_TEXT -> InputDoubleEditTextFragment(row) |
||||||
|
NUMERIC_TEXT -> InputNumericTextFragment(row) |
||||||
|
SUM -> InputSumFragment(row) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
val validationRequired: Boolean |
||||||
|
get() = when (this) { |
||||||
|
LIST, LIST_GAME, LIST_STATIC, GRID, DOUBLE_LIST -> false |
||||||
|
else -> true |
||||||
|
} |
||||||
|
|
||||||
|
val clearRequired: Boolean |
||||||
|
get() = true |
||||||
|
|
||||||
|
val addRequired: Boolean |
||||||
|
get() = when (this) { |
||||||
|
EDIT_TEXT, NUMERIC_TEXT, DOUBLE_EDIT_TEXT, EDIT_TEXT_MULTI_LINES, GRID, LIST_STATIC, SUM -> false |
||||||
|
else -> true |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,205 @@ |
|||||||
|
package net.pokeranalytics.android.ui.fragment.data |
||||||
|
|
||||||
|
import android.app.Activity.RESULT_OK |
||||||
|
import android.content.Intent |
||||||
|
import android.graphics.Color |
||||||
|
import android.os.Bundle |
||||||
|
import android.view.LayoutInflater |
||||||
|
import android.view.View |
||||||
|
import android.view.ViewGroup |
||||||
|
import androidx.appcompat.app.AlertDialog |
||||||
|
import kotlinx.android.synthetic.main.fragment_player.* |
||||||
|
import kotlinx.coroutines.Dispatchers |
||||||
|
import kotlinx.coroutines.GlobalScope |
||||||
|
import kotlinx.coroutines.delay |
||||||
|
import kotlinx.coroutines.launch |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.model.realm.Comment |
||||||
|
import net.pokeranalytics.android.model.realm.Player |
||||||
|
import net.pokeranalytics.android.ui.activity.ColorPickerActivity |
||||||
|
import net.pokeranalytics.android.ui.activity.components.MediaActivity |
||||||
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource |
||||||
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
||||||
|
import net.pokeranalytics.android.ui.extensions.showAlertDialog |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.PlayerRow |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow |
||||||
|
import net.pokeranalytics.android.util.NULL_TEXT |
||||||
|
import java.io.File |
||||||
|
|
||||||
|
/** |
||||||
|
* Player data fragment |
||||||
|
*/ |
||||||
|
class PlayerDataFragment : EditableDataFragment(), StaticRowRepresentableDataSource { |
||||||
|
|
||||||
|
companion object { |
||||||
|
const val REQUEST_CODE_PICK_COLOR = 1000 |
||||||
|
} |
||||||
|
|
||||||
|
private val player: Player |
||||||
|
get() { |
||||||
|
return this.item as Player |
||||||
|
} |
||||||
|
|
||||||
|
private var mediaActivity: MediaActivity? = null |
||||||
|
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
||||||
|
super.onCreateView(inflater, container, savedInstanceState) |
||||||
|
shouldOpenKeyboard = false |
||||||
|
return inflater.inflate(R.layout.fragment_player, container, false) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
||||||
|
super.onActivityResult(requestCode, resultCode, data) |
||||||
|
|
||||||
|
if (requestCode == REQUEST_CODE_PICK_COLOR && resultCode == RESULT_OK && data?.hasExtra(ColorPickerActivity.INTENT_COLOR) == true) { |
||||||
|
val color = data.getIntExtra(ColorPickerActivity.INTENT_COLOR, Color.TRANSPARENT) |
||||||
|
player.color = if (color != Color.TRANSPARENT) color else null |
||||||
|
rowRepresentableAdapter.refreshRow(PlayerRow.IMAGE) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||||
|
super.onViewCreated(view, savedInstanceState) |
||||||
|
initUI() |
||||||
|
} |
||||||
|
|
||||||
|
override fun getPhotos(files: ArrayList<File>) { |
||||||
|
super.getPhotos(files) |
||||||
|
files.firstOrNull()?.let { picture -> |
||||||
|
player.updateValue(picture.absolutePath, PlayerRow.IMAGE) |
||||||
|
rowRepresentableAdapter.refreshRow(PlayerRow.IMAGE) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun getDataSource(): RowRepresentableDataSource { |
||||||
|
return this |
||||||
|
} |
||||||
|
|
||||||
|
override fun adapterRows(): List<RowRepresentable>? { |
||||||
|
return player.adapterRows() |
||||||
|
} |
||||||
|
|
||||||
|
override fun viewTypeForPosition(position: Int): Int { |
||||||
|
return when (position) { |
||||||
|
0 -> RowViewType.ROW_PLAYER_IMAGE.ordinal |
||||||
|
else -> super.viewTypeForPosition(position) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun rowRepresentableForPosition(position: Int): RowRepresentable? { |
||||||
|
return when (position) { |
||||||
|
0 -> player |
||||||
|
else -> super.rowRepresentableForPosition(position) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun stringForRow(row: RowRepresentable): String { |
||||||
|
return when (row) { |
||||||
|
PlayerRow.NAME -> if (player.name.isNotEmpty()) player.name else NULL_TEXT |
||||||
|
PlayerRow.SUMMARY -> if (player.summary.isNotEmpty()) player.summary else NULL_TEXT |
||||||
|
else -> super.stringForRow(row) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
||||||
|
when (row) { |
||||||
|
PlayerRow.IMAGE -> openPictureDialog() |
||||||
|
else -> super.onRowSelected(position, row, fromAction) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onRowValueChanged(value: Any?, row: RowRepresentable) { |
||||||
|
when (row) { |
||||||
|
is Comment -> { |
||||||
|
row.updateValue(value, row) |
||||||
|
player.updateRowRepresentation() |
||||||
|
rowRepresentableAdapter.notifyDataSetChanged() |
||||||
|
} |
||||||
|
else -> { |
||||||
|
super.onRowValueChanged(value, row) |
||||||
|
if (row == PlayerRow.NAME) { |
||||||
|
rowRepresentableAdapter.refreshRow(PlayerRow.IMAGE) |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onRowDeleted(row: RowRepresentable) { |
||||||
|
super.onRowDeleted(row) |
||||||
|
when (row) { |
||||||
|
is Comment -> { |
||||||
|
if (row.isValidForDelete(getRealm())) { |
||||||
|
GlobalScope.launch(Dispatchers.Main) { |
||||||
|
delay(300) |
||||||
|
showAlertDialog(requireContext(), message = R.string.are_you_sure_you_want_to_delete, showCancelButton = true, positiveAction = { |
||||||
|
player.deleteComment(row) |
||||||
|
rowRepresentableAdapter.notifyDataSetChanged() |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init UI |
||||||
|
*/ |
||||||
|
private fun initUI() { |
||||||
|
mediaActivity = parentActivity as MediaActivity? |
||||||
|
|
||||||
|
player.updateRowRepresentation() |
||||||
|
|
||||||
|
if (!deleteButtonShouldAppear) { |
||||||
|
onRowSelected(0, SimpleRow.NAME) |
||||||
|
} |
||||||
|
|
||||||
|
addComment.setOnClickListener { |
||||||
|
val comment = player.addComment() |
||||||
|
rowRepresentableAdapter.notifyDataSetChanged() |
||||||
|
onRowSelected(-1, comment) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Open picture dialog |
||||||
|
*/ |
||||||
|
private fun openPictureDialog() { |
||||||
|
|
||||||
|
val builder = AlertDialog.Builder(requireContext()) |
||||||
|
|
||||||
|
val placesArray = ArrayList<CharSequence>() |
||||||
|
placesArray.add(getString(R.string.take_a_picture)) |
||||||
|
placesArray.add(getString(R.string.library)) |
||||||
|
placesArray.add(getString(R.string.select_a_color)) |
||||||
|
|
||||||
|
if (player.hasPicture()) { |
||||||
|
placesArray.add(getString(R.string.remove_picture)) |
||||||
|
} |
||||||
|
|
||||||
|
builder.setItems(placesArray.toTypedArray()) { _, which -> |
||||||
|
when (placesArray[which]) { |
||||||
|
getString(R.string.take_a_picture) -> mediaActivity?.openImageCaptureIntent(false) |
||||||
|
getString(R.string.library) -> mediaActivity?.openImageGalleryIntent(false) |
||||||
|
getString(R.string.select_a_color) -> { |
||||||
|
ColorPickerActivity.newInstanceForResult(this, REQUEST_CODE_PICK_COLOR) |
||||||
|
} |
||||||
|
getString(R.string.remove_picture) -> { |
||||||
|
player.updateValue(null, PlayerRow.IMAGE) |
||||||
|
rowRepresentableAdapter.refreshRow(PlayerRow.IMAGE) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
builder.show() |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
override fun onDataSaved() { |
||||||
|
super.onDataSaved() |
||||||
|
player.cleanupComments() |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,92 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view |
||||||
|
|
||||||
|
import io.realm.RealmResults |
||||||
|
import net.pokeranalytics.android.exceptions.RowRepresentableEditDescriptorException |
||||||
|
import net.pokeranalytics.android.util.UserDefaults |
||||||
|
import java.util.* |
||||||
|
import kotlin.collections.ArrayList |
||||||
|
|
||||||
|
/** |
||||||
|
* An container class to describe the way an field of an object will be edited |
||||||
|
*/ |
||||||
|
|
||||||
|
enum class RowEditableDescriptorType { |
||||||
|
DATE, |
||||||
|
DATA, |
||||||
|
STATIC, |
||||||
|
DEFAULT |
||||||
|
} |
||||||
|
|
||||||
|
open class RowEditableDescriptor(var defaultValue: Any? = null, |
||||||
|
var hint: Int? = null, |
||||||
|
var inputType: Int? = null) |
||||||
|
|
||||||
|
class DateRowEditableDescriptor(date: Date? = null, |
||||||
|
val minimumDate: Date? = null, |
||||||
|
var onlyDate: Boolean = false, |
||||||
|
var onlyTime: Boolean = false): RowEditableDescriptor(defaultValue = date) { |
||||||
|
val date: Date? |
||||||
|
get() { |
||||||
|
return defaultValue as Date? |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class DataRowEditableDescriptor( |
||||||
|
defaultValue: Any? = null, |
||||||
|
hint: Int? = null, |
||||||
|
inputType: Int? = null, |
||||||
|
data: RealmResults<*>? = null): RowEditableDescriptor(defaultValue, hint, inputType) { |
||||||
|
|
||||||
|
var data: RealmResults<RowRepresentable>? = null |
||||||
|
|
||||||
|
init { |
||||||
|
if (data != null && data.count() > 0) { |
||||||
|
if (data.first() is RowRepresentable) { |
||||||
|
this.data = data as RealmResults<RowRepresentable>? |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class StaticDataRowEditableDescriptor( |
||||||
|
defaultValue: Any? = null, |
||||||
|
hint: Int? = null, |
||||||
|
inputType: Int? = null, |
||||||
|
var staticData: List<RowRepresentable>? = null): RowEditableDescriptor(defaultValue, hint, inputType) { |
||||||
|
} |
||||||
|
|
||||||
|
class RowEditableDataSource(customCurrency: Currency? = null) { |
||||||
|
var currency: Currency = UserDefaults.currency |
||||||
|
|
||||||
|
init { |
||||||
|
customCurrency?.let { currency = it } |
||||||
|
} |
||||||
|
|
||||||
|
var descriptors = ArrayList<RowEditableDescriptor>() |
||||||
|
|
||||||
|
fun append(defaultValue: Any? = null, hint: Int? = null, inputType: Int? = null, data: RealmResults<*>? = null, staticData: List<RowRepresentable>? = null) { |
||||||
|
when { |
||||||
|
data != null -> descriptors.add(DataRowEditableDescriptor(defaultValue, hint, inputType, data)) |
||||||
|
staticData != null -> descriptors.add(StaticDataRowEditableDescriptor(defaultValue, hint, inputType, staticData)) |
||||||
|
else -> descriptors.add(RowEditableDescriptor(defaultValue, hint, inputType)) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fun appendDateDescriptor(date:Date?= null, |
||||||
|
minimumDate: Date? = null, |
||||||
|
onlyDate: Boolean = false, |
||||||
|
onlyTime: Boolean = false) { |
||||||
|
descriptors.add(DateRowEditableDescriptor(date, minimumDate, onlyDate, onlyTime)) |
||||||
|
} |
||||||
|
|
||||||
|
val descriptorType: RowEditableDescriptorType |
||||||
|
get() { |
||||||
|
return when (descriptors.firstOrNull()) { |
||||||
|
null -> throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency") |
||||||
|
is DateRowEditableDescriptor -> RowEditableDescriptorType.DATE |
||||||
|
is DataRowEditableDescriptor -> RowEditableDescriptorType.DATA |
||||||
|
is StaticDataRowEditableDescriptor -> RowEditableDescriptorType.STATIC |
||||||
|
else -> RowEditableDescriptorType.DEFAULT |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -1,14 +0,0 @@ |
|||||||
package net.pokeranalytics.android.ui.view |
|
||||||
|
|
||||||
import io.realm.RealmResults |
|
||||||
|
|
||||||
/** |
|
||||||
* An container class to describe the way an field of an object will be edited |
|
||||||
*/ |
|
||||||
class RowRepresentableEditDescriptor( |
|
||||||
var defaultValue: Any? = null, |
|
||||||
var hint: Int? = null, |
|
||||||
var inputType: Int? = null, |
|
||||||
var data: RealmResults<RowRepresentable>? = null, |
|
||||||
var staticData: List<RowRepresentable>? = null |
|
||||||
) |
|
||||||
@ -1,34 +0,0 @@ |
|||||||
package net.pokeranalytics.android.ui.view.rowrepresentable |
|
||||||
|
|
||||||
import net.pokeranalytics.android.R |
|
||||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
||||||
import net.pokeranalytics.android.ui.view.RowViewType |
|
||||||
|
|
||||||
/** |
|
||||||
* An enum managing the rows in the more tabs |
|
||||||
*/ |
|
||||||
enum class MoreTabRow : RowRepresentable { |
|
||||||
BANKROLL, |
|
||||||
TOP_10, |
|
||||||
SETTINGS; |
|
||||||
|
|
||||||
override val resId: Int? |
|
||||||
get() { |
|
||||||
return when(this) { |
|
||||||
BANKROLL -> R.string.bankroll |
|
||||||
TOP_10 -> R.string.top_10 |
|
||||||
SETTINGS -> R.string.services |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
override val imageRes: Int? |
|
||||||
get() { |
|
||||||
return when(this) { |
|
||||||
BANKROLL -> R.drawable.ic_outline_lock |
|
||||||
TOP_10 -> R.drawable.ic_outline_star |
|
||||||
SETTINGS -> R.drawable.ic_outline_settings |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
override val viewType: Int = RowViewType.TITLE_ICON_ARROW.ordinal |
|
||||||
} |
|
||||||
@ -0,0 +1,63 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view.rowrepresentable |
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.exceptions.PokerAnalyticsException |
||||||
|
import net.pokeranalytics.android.model.realm.Player |
||||||
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.input.InputFragment |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.input.InputFragmentType |
||||||
|
import net.pokeranalytics.android.ui.view.RowEditableDataSource |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
|
|
||||||
|
/** |
||||||
|
* An enum managing the player rows |
||||||
|
*/ |
||||||
|
enum class PlayerRow : RowRepresentable { |
||||||
|
IMAGE, |
||||||
|
NAME, |
||||||
|
SUMMARY; |
||||||
|
|
||||||
|
override val resId: Int? |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
IMAGE -> null |
||||||
|
NAME -> R.string.name |
||||||
|
SUMMARY -> R.string.summary |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override val viewType: Int |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
IMAGE -> RowViewType.ROW_PLAYER_IMAGE.ordinal |
||||||
|
NAME -> RowViewType.TITLE_SUBTITLE.ordinal |
||||||
|
SUMMARY -> RowViewType.TITLE_SUBTITLE.ordinal |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override val inputFragmentType: InputFragmentType |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
IMAGE -> InputFragmentType.NONE |
||||||
|
NAME -> InputFragmentType.EDIT_TEXT |
||||||
|
SUMMARY -> InputFragmentType.EDIT_TEXT_MULTI_LINES |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun startEditing(dataSource: Any?, parent: Fragment?) { |
||||||
|
if (dataSource == null) return |
||||||
|
if (dataSource !is Player) return |
||||||
|
if (parent == null) return |
||||||
|
if (parent !is RowRepresentableDelegate) return |
||||||
|
val data = RowEditableDataSource() |
||||||
|
when (this) { |
||||||
|
NAME -> data.append(dataSource.name) |
||||||
|
SUMMARY -> data.append(dataSource.summary) |
||||||
|
else -> PokerAnalyticsException.InputFragmentException |
||||||
|
} |
||||||
|
InputFragment.buildAndShow(this, parent, data) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,315 +1,286 @@ |
|||||||
package net.pokeranalytics.android.ui.view.rowrepresentable |
package net.pokeranalytics.android.ui.view.rowrepresentable |
||||||
|
|
||||||
import android.text.InputType |
import android.text.InputType |
||||||
import io.realm.RealmResults |
import android.widget.Toast |
||||||
|
import androidx.fragment.app.Fragment |
||||||
import net.pokeranalytics.android.R |
import net.pokeranalytics.android.R |
||||||
import net.pokeranalytics.android.model.TournamentType |
import net.pokeranalytics.android.model.TournamentType |
||||||
import net.pokeranalytics.android.model.extensions.SessionState |
import net.pokeranalytics.android.model.extensions.SessionState |
||||||
import net.pokeranalytics.android.model.extensions.getState |
import net.pokeranalytics.android.model.extensions.getState |
||||||
import net.pokeranalytics.android.model.realm.Session |
import net.pokeranalytics.android.model.realm.* |
||||||
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType |
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.input.InputFragment |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.input.InputFragmentType |
||||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor |
import net.pokeranalytics.android.ui.view.RowEditableDataSource |
||||||
import net.pokeranalytics.android.ui.view.RowViewType |
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
import net.pokeranalytics.android.util.extensions.round |
import net.pokeranalytics.android.util.extensions.round |
||||||
|
import net.pokeranalytics.android.util.extensions.sorted |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
|
||||||
enum class SessionRow : RowRepresentable { |
enum class SessionRow : RowRepresentable { |
||||||
|
|
||||||
PRIZE, |
PRIZE, |
||||||
CASHED_OUT, |
CASHED_OUT, |
||||||
NET_RESULT, |
NET_RESULT, |
||||||
INITIAL_BUY_IN, |
INITIAL_BUY_IN, |
||||||
BUY_IN, |
BUY_IN, |
||||||
POSITION, |
POSITION, |
||||||
PLAYERS, |
PLAYERS, |
||||||
TIPS, |
TIPS, |
||||||
|
|
||||||
GAME, |
GAME, |
||||||
BLINDS, |
BLINDS, |
||||||
LOCATION, |
LOCATION, |
||||||
BANKROLL, |
BANKROLL, |
||||||
TABLE_SIZE, |
TABLE_SIZE, |
||||||
TOURNAMENT_TYPE, |
TOURNAMENT_TYPE, |
||||||
TOURNAMENT_NAME, |
TOURNAMENT_NAME, |
||||||
TOURNAMENT_FEATURE, |
TOURNAMENT_FEATURE, |
||||||
START_DATE, |
START_DATE, |
||||||
END_DATE, |
END_DATE, |
||||||
|
|
||||||
BREAK_TIME, |
BREAK_TIME, |
||||||
COMMENT; |
COMMENT; |
||||||
|
|
||||||
companion object { |
companion object { |
||||||
/** |
/** |
||||||
* Return the rows to display for the current session state |
* Return the rows to display for the current session state |
||||||
*/ |
*/ |
||||||
fun getRows(session: Session): List<RowRepresentable> { |
fun getRows(session: Session): List<RowRepresentable> { |
||||||
when (session.type) { |
when (session.type) { |
||||||
Session.Type.TOURNAMENT.ordinal -> { |
Session.Type.TOURNAMENT.ordinal -> { |
||||||
return when (session.getState()) { |
return when (session.getState()) { |
||||||
SessionState.PENDING, SessionState.PLANNED -> { |
SessionState.PENDING, SessionState.PLANNED -> { |
||||||
arrayListOf( |
arrayListOf( |
||||||
GAME, |
GAME, |
||||||
INITIAL_BUY_IN, |
INITIAL_BUY_IN, |
||||||
LOCATION, |
LOCATION, |
||||||
BANKROLL, |
BANKROLL, |
||||||
TABLE_SIZE, |
TABLE_SIZE, |
||||||
TOURNAMENT_TYPE, |
TOURNAMENT_TYPE, |
||||||
TOURNAMENT_NAME, |
TOURNAMENT_NAME, |
||||||
TOURNAMENT_FEATURE, |
TOURNAMENT_FEATURE, |
||||||
START_DATE, |
START_DATE, |
||||||
END_DATE |
END_DATE |
||||||
) |
) |
||||||
} |
} |
||||||
SessionState.STARTED, SessionState.PAUSED, SessionState.FINISHED -> { |
SessionState.STARTED, SessionState.PAUSED, SessionState.FINISHED -> { |
||||||
arrayListOf( |
arrayListOf( |
||||||
PRIZE, |
PRIZE, |
||||||
BUY_IN, |
BUY_IN, |
||||||
POSITION, |
POSITION, |
||||||
PLAYERS, |
PLAYERS, |
||||||
TIPS, |
TIPS, |
||||||
COMMENT, |
COMMENT, |
||||||
SeparatorRow(), |
SeparatorRow(), |
||||||
GAME, |
GAME, |
||||||
INITIAL_BUY_IN, |
INITIAL_BUY_IN, |
||||||
LOCATION, |
LOCATION, |
||||||
BANKROLL, |
BANKROLL, |
||||||
TABLE_SIZE, |
TABLE_SIZE, |
||||||
TOURNAMENT_TYPE, |
TOURNAMENT_TYPE, |
||||||
TOURNAMENT_NAME, |
TOURNAMENT_NAME, |
||||||
TOURNAMENT_FEATURE, |
TOURNAMENT_FEATURE, |
||||||
SeparatorRow(), |
SeparatorRow(), |
||||||
START_DATE, |
START_DATE, |
||||||
END_DATE, |
END_DATE, |
||||||
BREAK_TIME |
BREAK_TIME |
||||||
) |
) |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
Session.Type.CASH_GAME.ordinal -> { |
Session.Type.CASH_GAME.ordinal -> { |
||||||
when (session.getState()) { |
when (session.getState()) { |
||||||
SessionState.PENDING, SessionState.PLANNED -> { |
SessionState.PENDING, SessionState.PLANNED -> { |
||||||
return arrayListOf(GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, START_DATE, END_DATE) |
return arrayListOf(GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, START_DATE, END_DATE) |
||||||
} |
} |
||||||
SessionState.STARTED, SessionState.PAUSED, SessionState.FINISHED -> { |
SessionState.STARTED, SessionState.PAUSED, SessionState.FINISHED -> { |
||||||
|
|
||||||
val fields = mutableListOf<RowRepresentable>() |
val fields = mutableListOf<RowRepresentable>() |
||||||
when { |
when { |
||||||
session.hasBuyin -> fields.addAll(listOf(CASHED_OUT, BUY_IN, TIPS)) |
session.hasBuyin -> fields.addAll(listOf(CASHED_OUT, BUY_IN, TIPS)) |
||||||
session.hasNetResult -> fields.add(NET_RESULT) |
session.hasNetResult -> fields.add(NET_RESULT) |
||||||
session.isLive -> fields.addAll(listOf(CASHED_OUT, BUY_IN, TIPS)) |
session.isLive -> fields.addAll(listOf(CASHED_OUT, BUY_IN, TIPS)) |
||||||
else -> fields.add(NET_RESULT) |
else -> fields.add(NET_RESULT) |
||||||
} |
} |
||||||
fields.add(COMMENT) |
fields.add(COMMENT) |
||||||
fields.add(SeparatorRow()) |
fields.add(SeparatorRow()) |
||||||
fields.addAll(listOf( |
fields.addAll( |
||||||
GAME, |
listOf( |
||||||
BLINDS, |
GAME, |
||||||
LOCATION, |
BLINDS, |
||||||
BANKROLL, |
LOCATION, |
||||||
TABLE_SIZE, |
BANKROLL, |
||||||
START_DATE, |
TABLE_SIZE, |
||||||
END_DATE, |
START_DATE, |
||||||
BREAK_TIME |
END_DATE, |
||||||
|
BREAK_TIME |
||||||
|
|
||||||
) |
) |
||||||
) |
) |
||||||
return fields |
return fields |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
return arrayListOf() |
return arrayListOf() |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
override val resId: Int? |
override val resId: Int? |
||||||
get() { |
get() { |
||||||
return when (this) { |
return when (this) { |
||||||
NET_RESULT -> R.string.net_result |
NET_RESULT -> R.string.net_result |
||||||
PRIZE -> R.string.prize |
PRIZE -> R.string.prize |
||||||
POSITION -> R.string.position |
POSITION -> R.string.position |
||||||
PLAYERS -> R.string.players |
PLAYERS -> R.string.players |
||||||
CASHED_OUT -> R.string.cashed_out |
CASHED_OUT -> R.string.cashed_out |
||||||
INITIAL_BUY_IN -> R.string.initial_stack |
INITIAL_BUY_IN -> R.string.initial_stack |
||||||
BUY_IN -> R.string.buyin |
BUY_IN -> R.string.buyin |
||||||
TIPS -> R.string.tips |
TIPS -> R.string.tips |
||||||
GAME -> R.string.game |
GAME -> R.string.game |
||||||
BLINDS -> R.string.blinds |
BLINDS -> R.string.blinds |
||||||
LOCATION -> R.string.location |
LOCATION -> R.string.location |
||||||
BANKROLL -> R.string.bankroll |
BANKROLL -> R.string.bankroll |
||||||
TABLE_SIZE -> R.string.table_size |
TABLE_SIZE -> R.string.table_size |
||||||
TOURNAMENT_TYPE -> R.string.tournament_type |
TOURNAMENT_TYPE -> R.string.tournament_type |
||||||
TOURNAMENT_NAME -> R.string.tournament_name |
TOURNAMENT_NAME -> R.string.tournament_name |
||||||
TOURNAMENT_FEATURE -> R.string.tournament_feature |
TOURNAMENT_FEATURE -> R.string.tournament_feature |
||||||
START_DATE -> R.string.start_date |
START_DATE -> R.string.start_date |
||||||
END_DATE -> R.string.end_date |
END_DATE -> R.string.end_date |
||||||
BREAK_TIME -> R.string.break_time |
BREAK_TIME -> R.string.break_time |
||||||
COMMENT -> R.string.comment |
COMMENT -> R.string.comment |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
override val viewType: Int |
override val viewType: Int |
||||||
get() { |
get() { |
||||||
return when (this) { |
return when (this) { |
||||||
NET_RESULT, PRIZE, POSITION, PLAYERS, CASHED_OUT, INITIAL_BUY_IN, BUY_IN, TIPS, |
NET_RESULT, PRIZE, POSITION, PLAYERS, CASHED_OUT, INITIAL_BUY_IN, BUY_IN, TIPS, |
||||||
GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, COMMENT, |
GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, COMMENT, |
||||||
TOURNAMENT_TYPE, TOURNAMENT_NAME, TOURNAMENT_FEATURE, START_DATE, END_DATE, BREAK_TIME -> RowViewType.TITLE_VALUE.ordinal |
TOURNAMENT_TYPE, TOURNAMENT_NAME, TOURNAMENT_FEATURE, START_DATE, END_DATE, BREAK_TIME -> RowViewType.TITLE_VALUE.ordinal |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
override val bottomSheetType: BottomSheetType |
override val inputFragmentType: InputFragmentType |
||||||
get() { |
get() { |
||||||
return when (this) { |
return when (this) { |
||||||
NET_RESULT, CASHED_OUT, INITIAL_BUY_IN, BREAK_TIME, POSITION, PLAYERS, PRIZE -> BottomSheetType.NUMERIC_TEXT |
NET_RESULT, CASHED_OUT, INITIAL_BUY_IN, BREAK_TIME, POSITION, PLAYERS, PRIZE -> InputFragmentType.NUMERIC_TEXT |
||||||
BUY_IN, TIPS -> BottomSheetType.SUM |
BUY_IN, TIPS -> InputFragmentType.SUM |
||||||
BLINDS -> BottomSheetType.DOUBLE_EDIT_TEXT |
BLINDS -> InputFragmentType.DOUBLE_EDIT_TEXT |
||||||
GAME -> BottomSheetType.LIST_GAME |
GAME -> InputFragmentType.LIST_GAME |
||||||
TOURNAMENT_TYPE -> BottomSheetType.LIST_STATIC |
TOURNAMENT_TYPE -> InputFragmentType.LIST_STATIC |
||||||
LOCATION, BANKROLL, TOURNAMENT_NAME -> BottomSheetType.LIST |
LOCATION, BANKROLL, TOURNAMENT_NAME -> InputFragmentType.LIST |
||||||
TOURNAMENT_FEATURE -> BottomSheetType.MULTI_SELECTION |
TOURNAMENT_FEATURE -> InputFragmentType.MULTI_SELECTION |
||||||
TABLE_SIZE -> BottomSheetType.GRID |
TABLE_SIZE -> InputFragmentType.GRID |
||||||
COMMENT -> BottomSheetType.EDIT_TEXT_MULTI_LINES |
COMMENT -> InputFragmentType.EDIT_TEXT_MULTI_LINES |
||||||
else -> BottomSheetType.NONE |
else -> InputFragmentType.NONE |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? { |
override fun startEditing(dataSource: Any?, parent: Fragment?) { |
||||||
return when (this) { |
if (dataSource == null) return |
||||||
BLINDS -> { |
if (dataSource !is Session) return |
||||||
val sb: String? by map |
if (parent == null) return |
||||||
val bb: String? by map |
if (parent !is RowRepresentableDelegate) return |
||||||
arrayListOf( |
|
||||||
RowRepresentableEditDescriptor( |
|
||||||
sb, R.string.smallblind, InputType.TYPE_CLASS_NUMBER |
|
||||||
or InputType.TYPE_NUMBER_FLAG_DECIMAL |
|
||||||
), |
|
||||||
RowRepresentableEditDescriptor( |
|
||||||
bb, R.string.bigblind, InputType.TYPE_CLASS_NUMBER |
|
||||||
or InputType.TYPE_NUMBER_FLAG_DECIMAL |
|
||||||
) |
|
||||||
) |
|
||||||
} |
|
||||||
BUY_IN -> { |
|
||||||
val bb: Double? by map |
|
||||||
val fee: Double? by map |
|
||||||
val ratedBuyin: Double? by map |
|
||||||
val data = arrayListOf<RowRepresentableEditDescriptor>() |
|
||||||
if (bb != null) { |
|
||||||
data.add(RowRepresentableEditDescriptor(100.0 * (bb ?: 0.0))) |
|
||||||
data.add(RowRepresentableEditDescriptor(200.0 * (bb ?: 0.0))) |
|
||||||
} else if (fee != null) { |
|
||||||
data.add(RowRepresentableEditDescriptor((fee ?: 0.0) * 1.0)) |
|
||||||
data.add(RowRepresentableEditDescriptor((fee ?: 0.0) * 2.0)) |
|
||||||
} else { |
|
||||||
data.add(RowRepresentableEditDescriptor(0)) |
|
||||||
data.add(RowRepresentableEditDescriptor(0)) |
|
||||||
} |
|
||||||
|
|
||||||
data.add(RowRepresentableEditDescriptor(ratedBuyin)) |
val session: Session = dataSource |
||||||
data.add( |
|
||||||
RowRepresentableEditDescriptor( |
|
||||||
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL |
|
||||||
) |
|
||||||
) |
|
||||||
data.add( |
|
||||||
RowRepresentableEditDescriptor( |
|
||||||
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL |
|
||||||
) |
|
||||||
) |
|
||||||
data |
|
||||||
} |
|
||||||
CASHED_OUT, PRIZE, NET_RESULT -> { |
|
||||||
val defaultValue: Double? by map |
|
||||||
arrayListOf( |
|
||||||
RowRepresentableEditDescriptor( |
|
||||||
defaultValue, |
|
||||||
inputType = InputType.TYPE_CLASS_NUMBER |
|
||||||
or InputType.TYPE_NUMBER_FLAG_DECIMAL |
|
||||||
or InputType.TYPE_NUMBER_FLAG_SIGNED |
|
||||||
) |
|
||||||
) |
|
||||||
} |
|
||||||
COMMENT -> { |
|
||||||
val defaultValue: String? by map |
|
||||||
arrayListOf(RowRepresentableEditDescriptor(defaultValue, R.string.comment)) |
|
||||||
} |
|
||||||
BREAK_TIME -> { |
|
||||||
arrayListOf( |
|
||||||
RowRepresentableEditDescriptor( |
|
||||||
hint = R.string.in_minutes, inputType = InputType.TYPE_CLASS_NUMBER |
|
||||||
) |
|
||||||
) |
|
||||||
} |
|
||||||
GAME -> { |
|
||||||
val limit: Int? by map |
|
||||||
val defaultValue: Any? by map |
|
||||||
val data: RealmResults<RowRepresentable>? by map |
|
||||||
arrayListOf( |
|
||||||
RowRepresentableEditDescriptor(limit), |
|
||||||
RowRepresentableEditDescriptor(defaultValue, data = data) |
|
||||||
) |
|
||||||
} |
|
||||||
INITIAL_BUY_IN -> { |
|
||||||
val defaultValue: Double? by map |
|
||||||
arrayListOf( |
|
||||||
RowRepresentableEditDescriptor(defaultValue?.round(), inputType = InputType.TYPE_CLASS_NUMBER) |
|
||||||
) |
|
||||||
} |
|
||||||
BANKROLL, LOCATION, TOURNAMENT_FEATURE, TOURNAMENT_NAME -> { |
|
||||||
val defaultValue: Any? by map |
|
||||||
val data: RealmResults<RowRepresentable>? by map |
|
||||||
arrayListOf( |
|
||||||
RowRepresentableEditDescriptor(defaultValue, data = data) |
|
||||||
) |
|
||||||
} |
|
||||||
PLAYERS -> { |
|
||||||
val defaultValue: Int? by map |
|
||||||
arrayListOf( |
|
||||||
RowRepresentableEditDescriptor( |
|
||||||
defaultValue?.toString(), |
|
||||||
inputType = InputType.TYPE_CLASS_NUMBER |
|
||||||
) |
|
||||||
) |
|
||||||
} |
|
||||||
POSITION -> { |
|
||||||
val defaultValue: Int? by map |
|
||||||
arrayListOf( |
|
||||||
RowRepresentableEditDescriptor( |
|
||||||
defaultValue, |
|
||||||
inputType = InputType.TYPE_CLASS_NUMBER |
|
||||||
) |
|
||||||
) |
|
||||||
} |
|
||||||
TABLE_SIZE -> { |
|
||||||
val defaultValue: Int? by map |
|
||||||
arrayListOf(RowRepresentableEditDescriptor(defaultValue)) |
|
||||||
} |
|
||||||
TIPS -> { |
|
||||||
val sb: String? by map |
|
||||||
val bb: String? by map |
|
||||||
val tips: Double? by map |
|
||||||
|
|
||||||
// Disable the buttons with value = 0, add current value & set the 2 edit texts |
val data = RowEditableDataSource(session.currency) |
||||||
arrayListOf( |
when (this) { |
||||||
RowRepresentableEditDescriptor(sb ?: 0.0), |
START_DATE -> { |
||||||
RowRepresentableEditDescriptor(bb ?: 0.0), |
data.appendDateDescriptor(session.startDate) |
||||||
RowRepresentableEditDescriptor(tips ?: 0.0), |
} |
||||||
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER), |
END_DATE -> { |
||||||
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER) |
if (session.startDate == null) { |
||||||
) |
Toast.makeText(parent.context, R.string.session_missing_start_date, Toast.LENGTH_SHORT).show() |
||||||
} |
return |
||||||
TOURNAMENT_TYPE -> { |
} else { |
||||||
val defaultValue: Any? by map |
data.appendDateDescriptor(session.endDate ?: session.startDate ?: Date(), session.startDate) |
||||||
arrayListOf( |
} |
||||||
RowRepresentableEditDescriptor(defaultValue, staticData = TournamentType.values().map { |
} |
||||||
it |
|
||||||
}) |
|
||||||
) |
|
||||||
} |
|
||||||
else -> null |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
BANKROLL -> data.append(session.bankroll, data = session.realm.sorted<Bankroll>()) |
||||||
|
CASHED_OUT, PRIZE -> data.append( |
||||||
|
session.result?.cashout, |
||||||
|
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL or InputType.TYPE_NUMBER_FLAG_SIGNED |
||||||
|
) |
||||||
|
NET_RESULT -> data.append( |
||||||
|
session.result?.netResult, |
||||||
|
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL or InputType.TYPE_NUMBER_FLAG_SIGNED |
||||||
|
) |
||||||
|
INITIAL_BUY_IN -> data.append(session.tournamentEntryFee?.round(), inputType = InputType.TYPE_CLASS_NUMBER) |
||||||
|
BUY_IN -> { |
||||||
|
val bb: Double? = session.cgBigBlind |
||||||
|
val fee: Double? = session.tournamentEntryFee |
||||||
|
val ratedBuyin: Double? = session.result?.buyin |
||||||
|
if (bb != null) { |
||||||
|
data.append(100.0 * bb) |
||||||
|
data.append(200.0 * bb) |
||||||
|
} else if (fee != null) { |
||||||
|
data.append(fee) |
||||||
|
data.append(fee * 2.0) |
||||||
|
} else { |
||||||
|
data.append(0) |
||||||
|
data.append(0) |
||||||
|
} |
||||||
|
data.append(ratedBuyin) |
||||||
|
data.append(inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL) |
||||||
|
data.append(inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL) |
||||||
|
} |
||||||
|
POSITION -> data.append(session.result?.tournamentFinalPosition, inputType = InputType.TYPE_CLASS_NUMBER) |
||||||
|
PLAYERS -> data.append( |
||||||
|
session.tournamentNumberOfPlayers.toString(), |
||||||
|
inputType = InputType.TYPE_CLASS_NUMBER |
||||||
|
) |
||||||
|
TIPS -> { |
||||||
|
val sb: String? = session.cgSmallBlind?.round() |
||||||
|
val bb: String? = session.cgBigBlind?.round() |
||||||
|
val tips: Double? = session.result?.tips |
||||||
|
data.append(sb ?: 0.0) |
||||||
|
data.append(bb ?: 0.0) |
||||||
|
data.append(tips ?: 0.0) |
||||||
|
data.append("", inputType = InputType.TYPE_CLASS_NUMBER) |
||||||
|
data.append("", inputType = InputType.TYPE_CLASS_NUMBER) |
||||||
|
} |
||||||
|
GAME -> { |
||||||
|
data.append(session.limit) |
||||||
|
data.append(session.game, data = session.realm.sorted<Game>()) |
||||||
|
} |
||||||
|
BLINDS -> { |
||||||
|
data.append( |
||||||
|
session.cgSmallBlind?.round(), |
||||||
|
R.string.smallblind, |
||||||
|
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL |
||||||
|
) |
||||||
|
data.append( |
||||||
|
session.cgBigBlind?.round(), |
||||||
|
R.string.bigblind, |
||||||
|
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL |
||||||
|
) |
||||||
|
} |
||||||
|
LOCATION -> data.append(session.location, data = session.realm.sorted<Location>()) |
||||||
|
TABLE_SIZE -> data.append(session.tableSize) |
||||||
|
TOURNAMENT_TYPE -> data.append(session.tournamentType, staticData = TournamentType.values().map { it }) |
||||||
|
TOURNAMENT_NAME -> data.append(session.tournamentName, data = session.realm.sorted<TournamentName>()) |
||||||
|
TOURNAMENT_FEATURE -> data.append( |
||||||
|
session.tournamentFeatures, |
||||||
|
data = session.realm.sorted<TournamentFeature>() |
||||||
|
) |
||||||
|
BREAK_TIME -> data.append(hint = R.string.in_minutes, inputType = InputType.TYPE_CLASS_NUMBER) |
||||||
|
COMMENT -> data.append(session.comment, R.string.comment) |
||||||
|
} |
||||||
|
InputFragment.buildAndShow(this, parent, data) |
||||||
|
} |
||||||
|
|
||||||
|
override val valueCanBeClearedWhenEditing: Boolean |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
BANKROLL -> false |
||||||
|
else -> true |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
@ -1,16 +1,15 @@ |
|||||||
package net.pokeranalytics.android.ui.view.rowrepresentable |
package net.pokeranalytics.android.ui.view.rowrepresentable |
||||||
|
|
||||||
import net.pokeranalytics.android.R |
import net.pokeranalytics.android.R |
||||||
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType |
import net.pokeranalytics.android.ui.fragment.components.input.InputFragmentType |
||||||
import net.pokeranalytics.android.ui.view.DefaultEditDataSource |
|
||||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
import net.pokeranalytics.android.ui.view.RowViewType |
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
|
|
||||||
|
|
||||||
enum class SimpleRow : RowRepresentable, DefaultEditDataSource { |
enum class SimpleRow : RowRepresentable { |
||||||
NAME; |
NAME; |
||||||
|
|
||||||
override val resId: Int? = R.string.name |
override val resId: Int? = R.string.name |
||||||
override val viewType: Int = RowViewType.TITLE_VALUE.ordinal |
override val viewType: Int = RowViewType.TITLE_VALUE.ordinal |
||||||
override val bottomSheetType: BottomSheetType = BottomSheetType.EDIT_TEXT |
override val inputFragmentType: InputFragmentType = InputFragmentType.EDIT_TEXT |
||||||
} |
} |
||||||
@ -1,6 +1,49 @@ |
|||||||
package net.pokeranalytics.android.ui.view.rowrepresentable |
package net.pokeranalytics.android.ui.view.rowrepresentable |
||||||
|
|
||||||
import net.pokeranalytics.android.ui.view.DefaultEditDataSource |
import androidx.fragment.app.Fragment |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.model.realm.TournamentFeature |
||||||
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.input.InputFragment |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.input.InputFragmentType |
||||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.RowEditableDataSource |
||||||
|
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
|
|
||||||
enum class TournamentFeatureRow : RowRepresentable, DefaultEditDataSource |
enum class TournamentFeatureRow : RowRepresentable { |
||||||
|
NAME; |
||||||
|
|
||||||
|
override val resId: Int? |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
NAME -> R.string.name |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override val viewType: Int |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
NAME -> RowViewType.TITLE_VALUE.ordinal |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override val inputFragmentType: InputFragmentType |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
NAME -> InputFragmentType.EDIT_TEXT |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun startEditing(dataSource: Any?, parent: Fragment?) { |
||||||
|
if (dataSource == null) return |
||||||
|
if (dataSource !is TournamentFeature) return |
||||||
|
if (parent == null) return |
||||||
|
if (parent !is RowRepresentableDelegate) return |
||||||
|
val data = RowEditableDataSource() |
||||||
|
when (this) { |
||||||
|
NAME -> data.append(dataSource.name) |
||||||
|
} |
||||||
|
InputFragment.buildAndShow(this, parent, data) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,6 +1,49 @@ |
|||||||
package net.pokeranalytics.android.ui.view.rowrepresentable |
package net.pokeranalytics.android.ui.view.rowrepresentable |
||||||
|
|
||||||
import net.pokeranalytics.android.ui.view.DefaultEditDataSource |
import androidx.fragment.app.Fragment |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.model.realm.TournamentName |
||||||
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.input.InputFragment |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.input.InputFragmentType |
||||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.RowEditableDataSource |
||||||
|
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
|
|
||||||
enum class TournamentNameRow : RowRepresentable, DefaultEditDataSource |
enum class TournamentNameRow : RowRepresentable { |
||||||
|
NAME; |
||||||
|
|
||||||
|
override val resId: Int? |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
NAME -> R.string.name |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override val viewType: Int |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
NAME -> RowViewType.TITLE_VALUE.ordinal |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override val inputFragmentType: InputFragmentType |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
NAME -> InputFragmentType.EDIT_TEXT |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun startEditing(dataSource: Any?, parent: Fragment?) { |
||||||
|
if (dataSource == null) return |
||||||
|
if (dataSource !is TournamentName) return |
||||||
|
if (parent == null) return |
||||||
|
if (parent !is RowRepresentableDelegate) return |
||||||
|
val data = RowEditableDataSource() |
||||||
|
when (this) { |
||||||
|
NAME -> data.append(dataSource.name) |
||||||
|
} |
||||||
|
InputFragment.buildAndShow(this, parent, data) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,377 @@ |
|||||||
|
package net.pokeranalytics.android.util |
||||||
|
|
||||||
|
|
||||||
|
import android.app.Activity |
||||||
|
import android.content.Context |
||||||
|
import android.content.Intent |
||||||
|
import android.graphics.* |
||||||
|
import android.graphics.Paint.FILTER_BITMAP_FLAG |
||||||
|
import android.media.ExifInterface |
||||||
|
import android.net.Uri |
||||||
|
import android.os.Environment |
||||||
|
import androidx.core.content.ContextCompat |
||||||
|
import kotlinx.coroutines.Dispatchers |
||||||
|
import kotlinx.coroutines.GlobalScope |
||||||
|
import kotlinx.coroutines.launch |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import timber.log.Timber |
||||||
|
import java.io.File |
||||||
|
import java.io.FileOutputStream |
||||||
|
import java.io.IOException |
||||||
|
import java.io.InputStream |
||||||
|
import java.text.SimpleDateFormat |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
|
||||||
|
object ImageUtils { |
||||||
|
|
||||||
|
/** |
||||||
|
* Rotate a bitmap if it's necessary (depending of the EXIF data) |
||||||
|
* Some devices don't rotate the picture but instead add the orientation |
||||||
|
* value in the EXIF data. |
||||||
|
* That's why we need sometimes to rotate by ourselves the bitmap |
||||||
|
* |
||||||
|
* @param src The file to check (for getting the Exif data) |
||||||
|
* @param bitmap The bitmap to modify (if necessary) |
||||||
|
* @return The bitmap in the correct orientation |
||||||
|
*/ |
||||||
|
fun rotateBitmap(src: String, bitmap: Bitmap, updateFile: Boolean): Bitmap { |
||||||
|
try { |
||||||
|
val orientation = getExifOrientation(src) |
||||||
|
|
||||||
|
if (orientation == ExifInterface.ORIENTATION_NORMAL) { |
||||||
|
return bitmap |
||||||
|
} |
||||||
|
|
||||||
|
val matrix = Matrix() |
||||||
|
when (orientation) { |
||||||
|
ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> matrix.setScale(-1f, 1f) |
||||||
|
ExifInterface.ORIENTATION_ROTATE_180 -> matrix.setRotate(180f) |
||||||
|
ExifInterface.ORIENTATION_FLIP_VERTICAL -> { |
||||||
|
matrix.setRotate(180f) |
||||||
|
matrix.postScale(-1f, 1f) |
||||||
|
} |
||||||
|
ExifInterface.ORIENTATION_TRANSPOSE -> { |
||||||
|
matrix.setRotate(90f) |
||||||
|
matrix.postScale(-1f, 1f) |
||||||
|
} |
||||||
|
ExifInterface.ORIENTATION_ROTATE_90 -> matrix.setRotate(90f) |
||||||
|
ExifInterface.ORIENTATION_TRANSVERSE -> { |
||||||
|
matrix.setRotate(-90f) |
||||||
|
matrix.postScale(-1f, 1f) |
||||||
|
} |
||||||
|
ExifInterface.ORIENTATION_ROTATE_270 -> matrix.setRotate(-90f) |
||||||
|
else -> return bitmap |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
val oriented = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true) |
||||||
|
bitmap.recycle() |
||||||
|
if (updateFile) { |
||||||
|
updateFile(src, oriented) |
||||||
|
} |
||||||
|
return oriented |
||||||
|
} catch (e: OutOfMemoryError) { |
||||||
|
e.printStackTrace() |
||||||
|
return bitmap |
||||||
|
} |
||||||
|
|
||||||
|
} catch (e: IOException) { |
||||||
|
e.printStackTrace() |
||||||
|
} |
||||||
|
|
||||||
|
return bitmap |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the Exif orientation value |
||||||
|
* |
||||||
|
* @param filePath The path of the file |
||||||
|
* @return the orientation value |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
@Throws(IOException::class) |
||||||
|
private fun getExifOrientation(filePath: String): Int { |
||||||
|
val exifInterface = ExifInterface(filePath) |
||||||
|
return exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Save a bitmap into a file (& apply 90% compression) |
||||||
|
* |
||||||
|
* @param filePath Path of the file |
||||||
|
* @param bitmap Bitmap to save |
||||||
|
*/ |
||||||
|
fun updateFile(filePath: String, bitmap: Bitmap) { |
||||||
|
var out: FileOutputStream? = null |
||||||
|
try { |
||||||
|
out = FileOutputStream(filePath) |
||||||
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out) |
||||||
|
} catch (e: Exception) { |
||||||
|
e.printStackTrace() |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
out?.close() |
||||||
|
} catch (e: IOException) { |
||||||
|
e.printStackTrace() |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Resize a file with the given maximum width or height (and keep the ratio!) |
||||||
|
* @param filePath String: File path |
||||||
|
* @param bitmap Bitmap: Image |
||||||
|
* @param maxWidth int: Max width |
||||||
|
* @param maxHeight int: Max height |
||||||
|
*/ |
||||||
|
fun resizeFile(filePath: String, bitmap: Bitmap, maxWidth: Int, maxHeight: Int) { |
||||||
|
var bitmap = bitmap |
||||||
|
|
||||||
|
val options = BitmapFactory.Options() |
||||||
|
options.inJustDecodeBounds = true |
||||||
|
BitmapFactory.decodeFile(filePath, options) |
||||||
|
val imageWidth = options.outWidth |
||||||
|
val imageHeight = options.outHeight |
||||||
|
|
||||||
|
var newWidth: Int |
||||||
|
var newHeight: Int |
||||||
|
|
||||||
|
if (imageWidth > imageHeight) { |
||||||
|
newWidth = maxWidth |
||||||
|
newHeight = imageHeight * maxWidth / imageWidth |
||||||
|
if (newHeight > maxHeight) { |
||||||
|
newHeight = maxHeight |
||||||
|
newWidth = imageWidth * maxHeight / imageHeight |
||||||
|
} |
||||||
|
} else { |
||||||
|
newHeight = maxHeight |
||||||
|
newWidth = imageWidth * maxHeight / imageHeight |
||||||
|
if (newWidth > maxWidth) { |
||||||
|
newWidth = maxWidth |
||||||
|
newHeight = imageHeight * maxWidth / imageWidth |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true) |
||||||
|
updateFile(filePath, bitmap) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Create a unique temp image file name |
||||||
|
* |
||||||
|
* @return |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
@Throws(IOException::class) |
||||||
|
fun createTempImageFile(context: Context): File { |
||||||
|
// Create an image file name |
||||||
|
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date()) |
||||||
|
val imageFileName = "JPEG_" + timeStamp + "_" |
||||||
|
val storageDir = context.cacheDir |
||||||
|
return File.createTempFile(imageFileName, ".jpg", storageDir) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Create a unique image file name |
||||||
|
* |
||||||
|
* @return |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
@Throws(IOException::class) |
||||||
|
fun createImageFile(context: Context): File { |
||||||
|
// Create an image file name |
||||||
|
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date()) |
||||||
|
val imageFileName = "JPEG_" + timeStamp + "_" |
||||||
|
|
||||||
|
val storage = ContextCompat.getExternalFilesDirs(context, Environment.DIRECTORY_PICTURES) |
||||||
|
val storageDir = if (storage.isNotEmpty()) storage.first() else Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) |
||||||
|
|
||||||
|
val appStorageDir = File(storageDir.path + "/" + context.getString(R.string.app_name)) |
||||||
|
if (!appStorageDir.exists()) { |
||||||
|
appStorageDir.mkdirs() |
||||||
|
} |
||||||
|
|
||||||
|
return File.createTempFile(imageFileName, ".jpg", appStorageDir) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Decode sample Bitmap |
||||||
|
* |
||||||
|
* @param filePath The bitmap file path |
||||||
|
* @param reqWidth Max width required |
||||||
|
* @param reqHeight Max height required |
||||||
|
* @return The sampled bitmap |
||||||
|
*/ |
||||||
|
fun decodeSampledBitmapFromFile(filePath: String, reqWidth: Int, reqHeight: Int): Bitmap { |
||||||
|
|
||||||
|
// First decode with inJustDecodeBounds=true to check dimensions |
||||||
|
val options = BitmapFactory.Options() |
||||||
|
options.inJustDecodeBounds = true |
||||||
|
BitmapFactory.decodeFile(filePath, options) |
||||||
|
|
||||||
|
// Calculate inSampleSize |
||||||
|
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight) |
||||||
|
|
||||||
|
// Decode bitmap with inSampleSize set |
||||||
|
options.inJustDecodeBounds = false |
||||||
|
return BitmapFactory.decodeFile(filePath, options) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Calculate the sample size |
||||||
|
*/ |
||||||
|
fun calculateInSampleSize(options: BitmapFactory.Options, reqWidth: Int, |
||||||
|
reqHeight: Int): Int { |
||||||
|
// Raw height and width of image |
||||||
|
val height = options.outHeight |
||||||
|
val width = options.outWidth |
||||||
|
var inSampleSize = 1 |
||||||
|
|
||||||
|
if (height > reqHeight || width > reqWidth) { |
||||||
|
|
||||||
|
val halfHeight = height / 2 |
||||||
|
val halfWidth = width / 2 |
||||||
|
|
||||||
|
// Calculate the largest inSampleSize value that is a power of 2 and keeps both |
||||||
|
// height and width larger than the requested height and width. |
||||||
|
while (halfHeight / inSampleSize > reqHeight && halfWidth / inSampleSize > reqWidth) { |
||||||
|
inSampleSize *= 2 |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return inSampleSize |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Copy an input stream inside a file |
||||||
|
* |
||||||
|
* @param in Input Stream |
||||||
|
* @param file Destination file |
||||||
|
*/ |
||||||
|
fun copyInputStreamToFile(inputStream: InputStream, file: File) { |
||||||
|
try { |
||||||
|
val out = FileOutputStream(file) |
||||||
|
val buf = ByteArray(4096) |
||||||
|
var len = 0 |
||||||
|
while ({ len = inputStream.read(buf); len }() > 0) { |
||||||
|
out.write(buf, 0, len) |
||||||
|
} |
||||||
|
|
||||||
|
out.close() |
||||||
|
inputStream.close() |
||||||
|
} catch (e: Exception) { |
||||||
|
e.printStackTrace() |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Update the gallery with the current file |
||||||
|
* |
||||||
|
* @param context Context |
||||||
|
* @param filePath The file to add |
||||||
|
*/ |
||||||
|
fun updateGallery(context: Context, filePath: String) { |
||||||
|
val mediaScanIntent = Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE) |
||||||
|
val f = File(filePath) |
||||||
|
val contentUri = Uri.fromFile(f) |
||||||
|
mediaScanIntent.data = contentUri |
||||||
|
context.sendBroadcast(mediaScanIntent) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Save the bitmap in a file |
||||||
|
*/ |
||||||
|
fun saveBitmapInFile(context: Context, bitmap: Bitmap, filename: String, action: (filePath: String) -> Unit) { |
||||||
|
|
||||||
|
GlobalScope.launch { |
||||||
|
|
||||||
|
val outputFile = File(context.filesDir, filename) |
||||||
|
|
||||||
|
var out: FileOutputStream? = null |
||||||
|
try { |
||||||
|
out = FileOutputStream(outputFile.absolutePath) |
||||||
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out) // bmp is your Bitmap instance |
||||||
|
} catch (e: Exception) { |
||||||
|
e.printStackTrace() |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
if (out != null) { |
||||||
|
out.close() |
||||||
|
} |
||||||
|
} catch (e: IOException) { |
||||||
|
e.printStackTrace() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
GlobalScope.launch(Dispatchers.Main) { |
||||||
|
Timber.d("Save file here: ${outputFile.absolutePath}") |
||||||
|
action(outputFile.absolutePath) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Bitmap resizer |
||||||
|
*/ |
||||||
|
fun bitmapResizer(bitmap: Bitmap, newWidth: Int, newHeight: Int): Bitmap { |
||||||
|
val scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888) |
||||||
|
|
||||||
|
val ratioX = newWidth / bitmap.width.toFloat() |
||||||
|
val ratioY = newHeight / bitmap.height.toFloat() |
||||||
|
val middleX = newWidth / 2.0f |
||||||
|
val middleY = newHeight / 2.0f |
||||||
|
|
||||||
|
val scaleMatrix = Matrix() |
||||||
|
scaleMatrix.setScale(ratioX, ratioY, middleX, middleY) |
||||||
|
|
||||||
|
val canvas = Canvas(scaledBitmap) |
||||||
|
canvas.matrix = scaleMatrix |
||||||
|
canvas.drawBitmap(bitmap, middleX - bitmap.width / 2, middleY - bitmap.height / 2, Paint(FILTER_BITMAP_FLAG)) |
||||||
|
|
||||||
|
return scaledBitmap |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Export a bitmap |
||||||
|
*/ |
||||||
|
private fun exportFile(context: Activity, bitmap: Bitmap) { |
||||||
|
/* |
||||||
|
val outputFile = File.createTempFile("test_export", ".jpg", context.cacheDir) |
||||||
|
|
||||||
|
var out: FileOutputStream? = null |
||||||
|
try { |
||||||
|
out = FileOutputStream(outputFile.absolutePath) |
||||||
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out) |
||||||
|
} catch (e: Exception) { |
||||||
|
e.printStackTrace() |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
if (out != null) { |
||||||
|
out.close() |
||||||
|
} |
||||||
|
} catch (e: IOException) { |
||||||
|
e.printStackTrace() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
val uri = FileProvider.getUriForFile(context, |
||||||
|
context.packageName + ".provider", outputFile) |
||||||
|
|
||||||
|
val shareIntent = ShareCompat.IntentBuilder.from(context) |
||||||
|
.setType("image/jpg") |
||||||
|
.setSubject(context.getString(R.string.share_file_name)) |
||||||
|
.setStream(uri) |
||||||
|
.setChooserTitle(context.getString(R.string.share_title)) |
||||||
|
.createChooserIntent() |
||||||
|
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) |
||||||
|
|
||||||
|
context.startActivity(shareIntent) |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,36 +0,0 @@ |
|||||||
package net.pokeranalytics.android.util |
|
||||||
|
|
||||||
import android.content.Context |
|
||||||
import java.util.* |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LocaleUtils { |
|
||||||
|
|
||||||
companion object { |
|
||||||
|
|
||||||
/** |
|
||||||
* Return the current locale |
|
||||||
*/ |
|
||||||
fun getCurrentLocale(context: Context) : Locale { |
|
||||||
val defaultLocaleCode = Preferences.getString(Preferences.Keys.LOCALE_CODE, context) |
|
||||||
var locale = Locale.getDefault() |
|
||||||
if (defaultLocaleCode != null) { |
|
||||||
locale = Locale(defaultLocaleCode) |
|
||||||
Locale.setDefault(locale) |
|
||||||
} |
|
||||||
return locale |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* |
|
||||||
*/ |
|
||||||
fun setCurrentLocale(context: Context, language: String) { |
|
||||||
Preferences.setString(Preferences.Keys.LOCALE_CODE, language, context) |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,15 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:shape="oval"> |
||||||
|
|
||||||
|
<solid android:color="@color/player_color_1" /> |
||||||
|
|
||||||
|
<stroke |
||||||
|
android:color="@color/gray" |
||||||
|
android:width="1dp" /> |
||||||
|
|
||||||
|
<size |
||||||
|
android:width="48dp" |
||||||
|
android:height="48dp" /> |
||||||
|
|
||||||
|
</shape> |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:shape="oval"> |
||||||
|
|
||||||
|
<solid android:color="@color/player_color_2" /> |
||||||
|
|
||||||
|
<size |
||||||
|
android:width="48dp" |
||||||
|
android:height="48dp" /> |
||||||
|
|
||||||
|
</shape> |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:shape="oval"> |
||||||
|
|
||||||
|
<solid android:color="@color/player_color_3" /> |
||||||
|
|
||||||
|
<size |
||||||
|
android:width="48dp" |
||||||
|
android:height="48dp" /> |
||||||
|
|
||||||
|
</shape> |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:shape="oval"> |
||||||
|
|
||||||
|
<solid android:color="@color/player_color_4" /> |
||||||
|
|
||||||
|
<size |
||||||
|
android:width="48dp" |
||||||
|
android:height="48dp" /> |
||||||
|
|
||||||
|
</shape> |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:shape="oval"> |
||||||
|
|
||||||
|
<solid android:color="@color/player_color_5" /> |
||||||
|
|
||||||
|
<size |
||||||
|
android:width="48dp" |
||||||
|
android:height="48dp" /> |
||||||
|
|
||||||
|
</shape> |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:shape="oval"> |
||||||
|
|
||||||
|
<solid android:color="@color/player_color_6" /> |
||||||
|
|
||||||
|
<size |
||||||
|
android:width="48dp" |
||||||
|
android:height="48dp" /> |
||||||
|
|
||||||
|
</shape> |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:shape="oval"> |
||||||
|
|
||||||
|
<solid android:color="@color/player_color_7" /> |
||||||
|
|
||||||
|
<size |
||||||
|
android:width="48dp" |
||||||
|
android:height="48dp" /> |
||||||
|
|
||||||
|
</shape> |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:shape="oval"> |
||||||
|
|
||||||
|
<solid android:color="@color/player_color_8" /> |
||||||
|
|
||||||
|
<size |
||||||
|
android:width="48dp" |
||||||
|
android:height="48dp" /> |
||||||
|
|
||||||
|
</shape> |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:shape="oval"> |
||||||
|
|
||||||
|
<solid android:color="@color/player_color_9" /> |
||||||
|
|
||||||
|
<size |
||||||
|
android:width="48dp" |
||||||
|
android:height="48dp" /> |
||||||
|
|
||||||
|
</shape> |
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue