parent
6b7eb38fc9
commit
e663e55f1f
@ -1,23 +0,0 @@ |
|||||||
package net.pokeranalytics.android.model.realm |
|
||||||
|
|
||||||
import io.realm.Realm |
|
||||||
import io.realm.RealmObject |
|
||||||
|
|
||||||
class Configuration : RealmObject() { |
|
||||||
|
|
||||||
companion object { |
|
||||||
|
|
||||||
fun getConfiguration(realm: Realm): Configuration { |
|
||||||
realm.where(Configuration::class.java).findFirst()?.let { |
|
||||||
return it |
|
||||||
} |
|
||||||
return Configuration() |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
var liveDealtHandsPerHour: Int = 250 |
|
||||||
|
|
||||||
var onlineDealtHandsPerHour: Int = 500 |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,28 @@ |
|||||||
|
package net.pokeranalytics.android.model.realm |
||||||
|
|
||||||
|
import io.realm.Realm |
||||||
|
import io.realm.RealmObject |
||||||
|
import io.realm.annotations.PrimaryKey |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
open class UserConfig : RealmObject() { |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
fun getConfiguration(realm: Realm): UserConfig { |
||||||
|
realm.where(UserConfig::class.java).findFirst()?.let { config -> |
||||||
|
return config |
||||||
|
} |
||||||
|
return UserConfig() |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@PrimaryKey |
||||||
|
var id = UUID.randomUUID().toString() |
||||||
|
|
||||||
|
var liveDealtHandsPerHour: Int = 250 |
||||||
|
|
||||||
|
var onlineDealtHandsPerHour: Int = 500 |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
package net.pokeranalytics.android.ui.modules.settings |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.content.Intent |
||||||
|
import android.os.Bundle |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.ui.activity.CurrenciesActivity |
||||||
|
import net.pokeranalytics.android.ui.activity.components.BaseActivity |
||||||
|
|
||||||
|
class DealtHandsPerHourActivity : BaseActivity() { |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
fun newInstance(context: Context) { |
||||||
|
val intent = Intent(context, DealtHandsPerHourActivity::class.java) |
||||||
|
context.startActivity(intent) |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) { |
||||||
|
super.onCreate(savedInstanceState) |
||||||
|
setContentView(R.layout.activity_dealt_hands_config) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,11 +1,89 @@ |
|||||||
package net.pokeranalytics.android.ui.modules.settings |
package net.pokeranalytics.android.ui.modules.settings |
||||||
|
|
||||||
import net.pokeranalytics.android.ui.fragment.components.BaseFragment |
import android.app.Activity |
||||||
|
import android.os.Bundle |
||||||
|
import android.view.* |
||||||
|
import android.view.inputmethod.InputMethodManager |
||||||
|
import kotlinx.android.synthetic.main.fragment_dealt_hands_config.* |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.databinding.FragmentDealtHandsConfigBinding |
||||||
|
import net.pokeranalytics.android.model.realm.ComputableResult |
||||||
|
import net.pokeranalytics.android.model.realm.Session |
||||||
|
import net.pokeranalytics.android.model.realm.UserConfig |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.RealmFragment |
||||||
|
|
||||||
class DealtHandsPerHourFragment : BaseFragment() { |
|
||||||
|
|
||||||
|
class DealtHandsPerHourFragment : RealmFragment() { |
||||||
|
|
||||||
|
private var _binding: FragmentDealtHandsConfigBinding? = null |
||||||
|
private val binding get() = _binding!! |
||||||
|
|
||||||
|
override fun onCreateView( |
||||||
|
inflater: LayoutInflater, |
||||||
|
container: ViewGroup?, |
||||||
|
savedInstanceState: Bundle? |
||||||
|
): View { |
||||||
|
super.onCreateView(inflater, container, savedInstanceState) |
||||||
|
_binding = FragmentDealtHandsConfigBinding.inflate(inflater, container, false) |
||||||
|
return binding.root |
||||||
|
} |
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||||
|
super.onViewCreated(view, savedInstanceState) |
||||||
|
initUI() |
||||||
|
} |
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { |
||||||
|
menu.clear() |
||||||
|
inflater.inflate(R.menu.toolbar_dealt_hands_per_hour, menu) |
||||||
|
super.onCreateOptionsMenu(menu, inflater) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean { |
||||||
|
when (item.itemId) { |
||||||
|
R.id.save -> save() |
||||||
|
} |
||||||
|
return true |
||||||
|
} |
||||||
|
|
||||||
|
private fun initUI() { |
||||||
|
|
||||||
|
setDisplayHomeAsUpEnabled(true) |
||||||
|
|
||||||
|
val userConfig = UserConfig.getConfiguration(this.getRealm()) |
||||||
|
this.liveValue.hint = "${userConfig.liveDealtHandsPerHour}" |
||||||
|
this.onlineValue.hint = "${userConfig.onlineDealtHandsPerHour}" |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private fun save() { |
||||||
|
|
||||||
|
getRealm().executeTransaction { realm -> |
||||||
|
|
||||||
|
val userConfig = UserConfig.getConfiguration(realm) |
||||||
|
this.liveValue.text.toString().toIntOrNull()?.let { liveDealtHandsPerHour -> |
||||||
|
userConfig.liveDealtHandsPerHour = liveDealtHandsPerHour |
||||||
|
} |
||||||
|
this.onlineValue.text.toString().toIntOrNull()?.let { onlineDealtHandsPerHour -> |
||||||
|
userConfig.onlineDealtHandsPerHour = onlineDealtHandsPerHour |
||||||
|
} |
||||||
|
realm.copyToRealmOrUpdate(userConfig) |
||||||
|
|
||||||
|
// update all precomputed hand counts |
||||||
|
realm.where(ComputableResult::class.java).findAll().forEach { cr -> |
||||||
|
cr.session?.let { session -> |
||||||
|
cr.estimatedHands = session.estimatedHands |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
this.liveValue.clearFocus() |
||||||
|
this.onlineValue.clearFocus() |
||||||
|
|
||||||
|
// Hides keyboard |
||||||
|
val imm: InputMethodManager = |
||||||
|
requireContext().getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager |
||||||
|
imm.hideSoftInputFromWindow(view!!.windowToken, 0) |
||||||
|
} |
||||||
|
|
||||||
} |
} |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
xmlns:tools="http://schemas.android.com/tools" |
||||||
|
android:orientation="vertical"> |
||||||
|
|
||||||
|
<androidx.fragment.app.FragmentContainerView |
||||||
|
android:id="@+id/currenciesFragment" |
||||||
|
android:name="net.pokeranalytics.android.ui.modules.settings.DealtHandsPerHourFragment" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
tools:layout="@layout/fragment_currencies" /> |
||||||
|
|
||||||
|
</LinearLayout> |
||||||
@ -1,76 +1,123 @@ |
|||||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||||
<androidx.constraintlayout.widget.ConstraintLayout |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
xmlns:android="http://schemas.android.com/apk/res/android" |
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||||
xmlns:tools="http://schemas.android.com/tools" |
xmlns:tools="http://schemas.android.com/tools" |
||||||
android:layout_width="match_parent" |
android:layout_width="match_parent" |
||||||
android:layout_height="match_parent"> |
android:layout_height="match_parent"> |
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView |
<com.google.android.material.appbar.AppBarLayout |
||||||
android:id="@+id/liveTitle" |
android:id="@+id/appBar" |
||||||
style="@style/PokerAnalyticsTheme.TextView.RowTitle" |
android:layout_width="match_parent" |
||||||
android:layout_width="wrap_content" |
android:layout_height="128dp" |
||||||
android:layout_height="wrap_content" |
android:theme="@style/PokerAnalyticsTheme.Toolbar.Session" |
||||||
android:layout_marginTop="16dp" |
|
||||||
android:layout_marginBottom="16dp" |
|
||||||
app:layout_constraintStart_toStartOf="parent" |
|
||||||
app:layout_constraintBottom_toBottomOf="parent" |
|
||||||
app:layout_constraintTop_toTopOf="parent" |
|
||||||
tools:text="Title" /> |
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView |
|
||||||
android:id="@+id/liveValue" |
|
||||||
style="@style/PokerAnalyticsTheme.TextView.RowValue" |
|
||||||
android:layout_width="0dp" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:layout_marginStart="16dp" |
|
||||||
android:ellipsize="end" |
|
||||||
android:gravity="end" |
|
||||||
android:maxLines="1" |
|
||||||
app:layout_constraintEnd_toEndOf="parent" |
app:layout_constraintEnd_toEndOf="parent" |
||||||
app:layout_constraintBottom_toBottomOf="parent" |
|
||||||
app:layout_constraintTop_toTopOf="parent" |
|
||||||
tools:text="Value" /> |
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView |
|
||||||
android:id="@+id/onlineTitle" |
|
||||||
style="@style/PokerAnalyticsTheme.TextView.RowTitle" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:layout_marginTop="16dp" |
|
||||||
android:layout_marginBottom="16dp" |
|
||||||
app:layout_constraintStart_toStartOf="parent" |
app:layout_constraintStart_toStartOf="parent" |
||||||
app:layout_constraintBottom_toBottomOf="parent" |
app:layout_constraintTop_toTopOf="parent"> |
||||||
app:layout_constraintTop_toBottomOf="@id/liveTitle" |
|
||||||
tools:text="Title" /> |
<com.google.android.material.appbar.CollapsingToolbarLayout |
||||||
|
android:id="@+id/collapsingToolbar" |
||||||
<androidx.appcompat.widget.AppCompatTextView |
android:layout_width="match_parent" |
||||||
android:id="@+id/onlineValue" |
android:layout_height="match_parent" |
||||||
style="@style/PokerAnalyticsTheme.TextView.RowValue" |
app:collapsedTitleTextAppearance="@style/PokerAnalyticsTheme.Toolbar.CollapsedTitleAppearance" |
||||||
android:layout_width="0dp" |
app:contentScrim="?attr/colorPrimary" |
||||||
android:layout_height="wrap_content" |
app:expandedTitleGravity="bottom" |
||||||
android:layout_marginStart="16dp" |
app:expandedTitleMarginStart="72dp" |
||||||
android:ellipsize="end" |
app:expandedTitleTextAppearance="@style/PokerAnalyticsTheme.Toolbar.ExpandedTitleAppearance" |
||||||
android:gravity="end" |
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"> |
||||||
android:maxLines="1" |
|
||||||
app:layout_constraintEnd_toEndOf="parent" |
<androidx.appcompat.widget.Toolbar |
||||||
app:layout_constraintBottom_toBottomOf="parent" |
android:id="@+id/toolbar" |
||||||
app:layout_constraintTop_toBottomOf="@id/liveValue" |
android:layout_width="match_parent" |
||||||
tools:text="Value" /> |
android:layout_height="?attr/actionBarSize" |
||||||
|
app:layout_collapseMode="pin" |
||||||
<androidx.appcompat.widget.AppCompatTextView |
app:title="@string/dealt_hands_per_hour" |
||||||
android:id="@+id/explanation" |
app:titleTextColor="@color/white" /> |
||||||
style="@style/PokerAnalyticsTheme.TextView.RowValue" |
|
||||||
android:layout_width="0dp" |
</com.google.android.material.appbar.CollapsingToolbarLayout> |
||||||
|
|
||||||
|
</com.google.android.material.appbar.AppBarLayout> |
||||||
|
|
||||||
|
<LinearLayout |
||||||
|
android:layout_width="match_parent" |
||||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" |
||||||
android:layout_marginStart="16dp" |
android:orientation="vertical" |
||||||
android:ellipsize="end" |
android:padding="16dp" |
||||||
android:gravity="end" |
|
||||||
android:maxLines="10" |
|
||||||
app:layout_constraintEnd_toEndOf="parent" |
app:layout_constraintEnd_toEndOf="parent" |
||||||
app:layout_constraintBottom_toBottomOf="parent" |
app:layout_constraintStart_toStartOf="parent" |
||||||
app:layout_constraintTop_toBottomOf="@id/onlineValue" |
app:layout_constraintTop_toBottomOf="@id/appBar"> |
||||||
tools:text="Value" /> |
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="50dp"> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView |
||||||
|
android:id="@+id/liveTitle" |
||||||
|
style="@style/PokerAnalyticsTheme.TextView.RowTitle" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="22dp" |
||||||
|
android:layout_gravity="center_vertical" |
||||||
|
android:text="@string/live" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" /> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatEditText |
||||||
|
android:id="@+id/liveValue" |
||||||
|
style="@style/PokerAnalyticsTheme.TextView.RowValue" |
||||||
|
android:textAlignment="textEnd" |
||||||
|
android:layout_width="100dp" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:textColorHint="@color/kaki_lighter" |
||||||
|
android:inputType="number" |
||||||
|
android:maxLines="1" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" |
||||||
|
tools:text="Value" /> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="50dp" |
||||||
|
android:layout_gravity="center_vertical"> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView |
||||||
|
android:id="@+id/onlineTitle" |
||||||
|
style="@style/PokerAnalyticsTheme.TextView.RowTitle" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="22dp" |
||||||
|
android:layout_gravity="center_vertical" |
||||||
|
android:text="@string/online" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" /> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatEditText |
||||||
|
android:id="@+id/onlineValue" |
||||||
|
style="@style/PokerAnalyticsTheme.TextView.RowValue" |
||||||
|
android:textAlignment="textEnd" |
||||||
|
android:layout_width="100dp" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:textColorHint="@color/kaki_lighter" |
||||||
|
android:inputType="number" |
||||||
|
android:maxLines="1" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
tools:text="Value" /> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView |
||||||
|
style="@style/PokerAnalyticsTheme.TextView.RowValue" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:layout_marginTop="16dp" |
||||||
|
android:textSize="14sp" |
||||||
|
android:maxLines="8" |
||||||
|
android:text="@string/dhph_explanation" /> |
||||||
|
|
||||||
|
</LinearLayout> |
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout> |
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"> |
||||||
|
|
||||||
|
<item |
||||||
|
android:id="@+id/save" |
||||||
|
android:title="@string/save" |
||||||
|
android:icon="@drawable/ic_check" |
||||||
|
app:showAsAction="ifRoom" /> |
||||||
|
|
||||||
|
</menu> |
||||||
Loading…
Reference in new issue