Skip to content

Commit

Permalink
Send funds/Wallet details filter tokens by type (Android) #171
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStahlfelge committed Jun 6, 2023
1 parent d83d5fc commit 3a53055
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.ergoplatform.android.tokens

import android.content.Context
import android.view.View
import android.widget.PopupMenu
import androidx.core.view.forEach
import org.ergoplatform.ErgoAmount
import org.ergoplatform.WalletStateSyncManager
import org.ergoplatform.android.R
import org.ergoplatform.ergoCurrencyText
import org.ergoplatform.persistance.*
import org.ergoplatform.uilogic.tokens.FilterTokenListUiLogic
import org.fabiomsr.moneytextview.MoneyTextView

fun TokenInformation.getGenuineDrawableId() = getGenuineDrawableId(genuineFlag)
Expand Down Expand Up @@ -41,4 +46,42 @@ fun MoneyTextView.setTokenPrice(
setAmount(tokenErgoValueSum.toBigDecimal())
setSymbol(ergoCurrencyText)
}
}

fun showTokenFilterPopup(
uiLogic: FilterTokenListUiLogic,
context: Context,
view: View,
onClick: (() -> Unit)? = null,
) {
val popupMenu = PopupMenu(context, view)

popupMenu.menuInflater.inflate(R.menu.filter_tokens, popupMenu.menu)

popupMenu.menu.forEach {
it.isChecked = uiLogic.hasTokenFilter(
when (it.itemId) {
R.id.token_type_image -> THUMBNAIL_TYPE_NFT_IMG
R.id.token_type_audio -> THUMBNAIL_TYPE_NFT_AUDIO
R.id.token_type_video -> THUMBNAIL_TYPE_NFT_VID
else -> THUMBNAIL_TYPE_NONE
}
)
}

popupMenu.setOnMenuItemClickListener {
uiLogic.toggleTokenFilter(
when (it.itemId) {
R.id.token_type_image -> THUMBNAIL_TYPE_NFT_IMG
R.id.token_type_audio -> THUMBNAIL_TYPE_NFT_AUDIO
R.id.token_type_video -> THUMBNAIL_TYPE_NFT_VID
else -> THUMBNAIL_TYPE_NONE
}
)
onClick?.invoke()
true
}

// Showing the popup menu
popupMenu.show()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import org.ergoplatform.android.databinding.FragmentChooseTokenDialogBinding
import org.ergoplatform.android.databinding.FragmentChooseTokenDialogItemBinding
import org.ergoplatform.android.tokens.ChooseTokenEntryView
import org.ergoplatform.android.tokens.showTokenFilterPopup
import org.ergoplatform.persistance.THUMBNAIL_TYPE_NFT_IMG
import org.ergoplatform.persistance.WalletToken

/**
Expand Down Expand Up @@ -41,8 +43,13 @@ class ChooseTokenListDialogFragment : BottomSheetDialogFragment() {
binding.list.layoutManager =
LinearLayoutManager(context)

val tokensToChooseFrom = viewModel.uiLogic.getTokensToChooseFrom()
binding.list.adapter = DisplayTokenAdapter(tokensToChooseFrom)
binding.list.adapter = DisplayTokenAdapter(viewModel.uiLogic.getTokensToChooseFrom())
binding.filterTokens.setOnClickListener {
showTokenFilterPopup(viewModel.uiLogic, requireContext(), it) {
binding.list.adapter =
DisplayTokenAdapter(viewModel.uiLogic.getTokensToChooseFrom())
}
}
}

private fun onChooseToken(tokenId: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.ergoplatform.android.wallet

import android.R.attr.button
import android.animation.LayoutTransition
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.*
import android.widget.PopupMenu
import android.widget.Toast
import androidx.core.view.forEach
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
Expand All @@ -27,19 +31,20 @@ import org.ergoplatform.android.databinding.EntryWalletTokenDetailsBinding
import org.ergoplatform.android.databinding.FragmentWalletDetailsBinding
import org.ergoplatform.android.tokens.WalletDetailsTokenEntryView
import org.ergoplatform.android.tokens.setTokenPrice
import org.ergoplatform.android.tokens.showTokenFilterPopup
import org.ergoplatform.android.transactions.inflateAddressTransactionEntry
import org.ergoplatform.android.ui.AndroidStringProvider
import org.ergoplatform.android.ui.QrScannerActivity
import org.ergoplatform.android.ui.navigateSafe
import org.ergoplatform.android.ui.postDelayed
import org.ergoplatform.android.wallet.addresses.AddressChooserCallback
import org.ergoplatform.android.wallet.addresses.ChooseAddressListDialogFragment
import org.ergoplatform.persistance.TokenInformation
import org.ergoplatform.persistance.Wallet
import org.ergoplatform.persistance.*
import org.ergoplatform.tokens.getTokenErgoValueSum
import org.ergoplatform.transactions.TransactionListManager
import org.ergoplatform.uilogic.transactions.AddressTransactionWithTokens


class WalletDetailsFragment : Fragment(), AddressChooserCallback {

private val walletDetailsViewModel: WalletDetailsViewModel by viewModels()
Expand Down Expand Up @@ -149,6 +154,10 @@ class WalletDetailsFragment : Fragment(), AddressChooserCallback {
QrScannerActivity.startFromFragment(this)
}

binding.filterTokens.setOnClickListener {
showTokenFilterPopup(walletDetailsViewModel.uiLogic, requireContext(), it)
}

// enable layout change animations after a short wait time
postDelayed(500) { enableLayoutChangeAnimations() }
}
Expand Down Expand Up @@ -231,7 +240,8 @@ class WalletDetailsFragment : Fragment(), AddressChooserCallback {

// tokens
val tokensList = walletDetailsViewModel.uiLogic.tokensList
binding.cardviewTokens.visibility = if (walletDetailsViewModel.uiLogic.hasTokens) View.VISIBLE else View.GONE
binding.cardviewTokens.visibility =
if (walletDetailsViewModel.uiLogic.hasTokens) View.VISIBLE else View.GONE
binding.walletTokenNum.text = tokensList.size.toString()

binding.walletTokenEntries.apply {
Expand Down Expand Up @@ -273,6 +283,8 @@ class WalletDetailsFragment : Fragment(), AddressChooserCallback {
} else {
binding.walletTokenValue.visibility = View.GONE
}
binding.filterTokens.visibility =
if (wallet.walletConfig.unfoldTokens) View.VISIBLE else View.GONE

binding.unfoldTokens.setImageResource(
if (wallet.walletConfig.unfoldTokens)
Expand Down
10 changes: 10 additions & 0 deletions android/src/main/res/drawable/ic_filter_alt_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M4.25,5.61C6.27,8.2 10,13 10,13v6c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-6c0,0 3.72,-4.8 5.74,-7.39C20.25,4.95 19.78,4 18.95,4H5.04C4.21,4 3.74,4.95 4.25,5.61z" />
</vector>
32 changes: 24 additions & 8 deletions android/src/main/res/layout/fragment_choose_token_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,31 @@
android:orientation="vertical"
tools:background="?attr/colorSurface">

<TextView
style="@style/TextAppearance.App.Body1"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:gravity="center"
android:paddingHorizontal="@dimen/activity_vertical_margin"
android:paddingVertical="@dimen/half_horizontal_margin"
android:text="@string/title_add_token" />
android:layout_height="wrap_content">

<TextView
style="@style/TextAppearance.App.Body1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:paddingHorizontal="@dimen/half_horizontal_margin"
android:paddingVertical="@dimen/half_horizontal_margin"
android:text="@string/title_add_token" />

<ImageView
android:id="@+id/filter_tokens"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/label_tokens"
android:padding="@dimen/half_horizontal_margin"
android:src="@drawable/ic_filter_alt_24" />

</LinearLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
Expand Down
11 changes: 11 additions & 0 deletions android/src/main/res/layout/fragment_wallet_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,17 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/filter_tokens"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/label_tokens"
android:paddingHorizontal="@dimen/half_horizontal_margin"
android:src="@drawable/ic_filter_alt_24"
app:layout_constraintEnd_toStartOf="@id/unfold_tokens"
app:layout_constraintTop_toTopOf="@id/unfold_tokens" />

<ImageView
android:id="@+id/tokens_logo"
android:layout_width="@dimen/medium_icon_size"
Expand Down
19 changes: 19 additions & 0 deletions android/src/main/res/menu/filter_tokens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/token_type_generic"
android:checkable="true"
android:title="@string/label_token_generic" />
<item
android:id="@+id/token_type_image"
android:checkable="true"
android:title="@string/label_token_image" />
<item
android:id="@+id/token_type_audio"
android:checkable="true"
android:title="@string/label_token_audio" />
<item
android:id="@+id/token_type_video"
android:checkable="true"
android:title="@string/label_token_video" />
</menu>

0 comments on commit 3a53055

Please sign in to comment.