parent
559549e2ee
commit
abc2581d3f
@ -0,0 +1,23 @@ |
||||
package net.pokeranalytics.android.ui.activity |
||||
|
||||
import android.content.Context |
||||
import android.content.Intent |
||||
import android.os.Bundle |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
||||
|
||||
class CurrenciesActivity : PokerAnalyticsActivity() { |
||||
|
||||
companion object { |
||||
fun newInstance(context: Context) { |
||||
val intent = Intent(context, CurrenciesActivity::class.java) |
||||
context.startActivity(intent) |
||||
} |
||||
} |
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
setContentView(R.layout.activity_currencies) |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,116 @@ |
||||
package net.pokeranalytics.android.ui.fragment |
||||
|
||||
import android.content.Context |
||||
import android.os.Bundle |
||||
import android.preference.Preference |
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.recyclerview.widget.LinearLayoutManager |
||||
import kotlinx.android.synthetic.main.fragment_data_list.* |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.model.LiveData |
||||
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
||||
import net.pokeranalytics.android.ui.adapter.LiveRowRepresentableDataSource |
||||
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.fragment.components.PokerAnalyticsFragment |
||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||
import net.pokeranalytics.android.ui.view.RowViewType |
||||
import net.pokeranalytics.android.ui.view.rowrepresentable.HeaderRowRepresentable |
||||
import java.util.* |
||||
import java.util.prefs.Preferences |
||||
|
||||
class CurrenciesFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
||||
|
||||
private val mostUsedCurrencyCodes = arrayListOf("EUR", "USD", "CAD", "GBP", "AUD", "CNY") |
||||
private val systemCurrencies = Currency.getAvailableCurrencies() |
||||
|
||||
private val mostUsedCurrencies = this.mostUsedCurrencyCodes.map { code -> |
||||
CurrencyRow( |
||||
this.systemCurrencies.filter { |
||||
it.currencyCode == code |
||||
}.first() |
||||
) |
||||
} |
||||
|
||||
private val availableCurrencies = this.systemCurrencies.filter { |
||||
!mostUsedCurrencyCodes.contains(it.currencyCode) |
||||
}.sortedBy { |
||||
it.displayName |
||||
}.map { |
||||
CurrencyRow(it) |
||||
} |
||||
|
||||
private class CurrencyRow(var currency:Currency) : RowRepresentable { |
||||
|
||||
override fun localizedTitle(context: Context): String { |
||||
return currency.getDisplayName(Locale.getDefault()) |
||||
} |
||||
|
||||
fun value(): String { |
||||
return "${currency.currencyCode} (${currency.getSymbol(Locale.getDefault())})" |
||||
} |
||||
|
||||
override val viewType: Int = RowViewType.TITLE_VALUE.ordinal |
||||
} |
||||
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
||||
return inflater.inflate(R.layout.fragment_currencies, container, false) |
||||
} |
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||
super.onViewCreated(view, savedInstanceState) |
||||
initData() |
||||
initUI() |
||||
} |
||||
|
||||
|
||||
// StaticRowRepresentableDataSource |
||||
|
||||
override fun adapterRows(): List<RowRepresentable>? { |
||||
val rows = ArrayList<RowRepresentable>() |
||||
rows.addAll(mostUsedCurrencies) |
||||
rows.add(HeaderRowRepresentable(customViewType = RowViewType.HEADER_SESSION, resId = R.string.currency)) |
||||
rows.addAll(availableCurrencies) |
||||
return rows |
||||
|
||||
} |
||||
|
||||
override fun stringForRow(row: RowRepresentable): String { |
||||
return (row as CurrencyRow).value() |
||||
} |
||||
|
||||
// RowRepresentableDelegate |
||||
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
||||
} |
||||
|
||||
private fun initData() { |
||||
} |
||||
|
||||
/** |
||||
* Init UI |
||||
*/ |
||||
private fun initUI() { |
||||
|
||||
val activity = activity as PokerAnalyticsActivity |
||||
|
||||
// Avoid a bug during setting the title |
||||
toolbar.title = activity.baseContext.getString( R.string.currency) |
||||
|
||||
activity.setSupportActionBar(toolbar) |
||||
activity.supportActionBar?.setDisplayHomeAsUpEnabled(true) |
||||
setHasOptionsMenu(true) |
||||
|
||||
val viewManager = LinearLayoutManager(requireContext()) |
||||
val dataListAdapter = RowRepresentableAdapter(this, this) |
||||
|
||||
recyclerView.apply { |
||||
setHasFixedSize(true) |
||||
layoutManager = viewManager |
||||
adapter = dataListAdapter |
||||
} |
||||
} |
||||
} |
||||
@ -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"> |
||||
|
||||
<fragment |
||||
android:id="@+id/currenciesFragment" |
||||
android:name="net.pokeranalytics.android.ui.fragment.CurrenciesFragment" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:layout="@layout/fragment_currencies" /> |
||||
|
||||
</LinearLayout> |
||||
@ -0,0 +1,61 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
<androidx.core.widget.NestedScrollView |
||||
android:id="@+id/nestedScrollView" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:fillViewport="true" |
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"> |
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recyclerView" |
||||
android:layout_width="0dp" |
||||
android:layout_height="0dp" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" /> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
|
||||
</androidx.core.widget.NestedScrollView> |
||||
|
||||
<com.google.android.material.appbar.AppBarLayout |
||||
android:id="@+id/appBar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="128dp" |
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> |
||||
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout |
||||
android:id="@+id/collapsingToolbar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
app:collapsedTitleTextAppearance="@style/PokerAnalyticsTheme.Toolbar.CollapsedTitleAppearance" |
||||
app:contentScrim="?attr/colorPrimary" |
||||
app:expandedTitleGravity="bottom" |
||||
app:expandedTitleMarginStart="72dp" |
||||
app:expandedTitleTextAppearance="@style/PokerAnalyticsTheme.Toolbar.ExpandedTitleAppearance" |
||||
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"> |
||||
|
||||
<androidx.appcompat.widget.Toolbar |
||||
android:id="@+id/toolbar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="?attr/actionBarSize" |
||||
app:layout_collapseMode="pin" |
||||
app:title="Poker Analytics" |
||||
app:titleTextColor="@color/white" /> |
||||
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout> |
||||
|
||||
</com.google.android.material.appbar.AppBarLayout> |
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
||||
Loading…
Reference in new issue