Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide balance on tap #719

Merged
merged 33 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a82e28e
Merge branch 'develop'
tomastiminskas May 25, 2023
c2e24ce
Merge branch 'develop'
tomastiminskas May 26, 2023
8981b4c
Merge branch 'develop'
tomastiminskas Jun 9, 2023
149d411
Merge branch 'develop'
tomastiminskas Jun 12, 2023
af56ed6
Merge branch 'develop'
tomastiminskas Jun 26, 2023
a8965e7
Merge branch 'develop'
tomastiminskas Jul 12, 2023
aafee21
Merge branch 'develop'
tomastiminskas Jul 31, 2023
3052dac
Merge pull request #625 from stakwork/aa/feature/contact-restore-pagi…
tomastiminskas Aug 14, 2023
5f4eeb6
Merge branch 'develop'
tomastiminskas Aug 14, 2023
39b7123
Merge branch 'develop'
tomastiminskas Aug 17, 2023
5a9220a
Merge branch 'develop'
tomastiminskas Aug 21, 2023
42cf8f4
Merge branch 'develop'
tomastiminskas Sep 21, 2023
e3c1f27
Merge branch 'develop'
ariel10aguero Sep 25, 2023
a47ef8e
Merge branch 'develop'
ariel10aguero Oct 12, 2023
097a27e
Merge branch 'develop'
ariel10aguero Oct 13, 2023
7712e2a
Prepare release 1.0.0-beta08
ariel10aguero Oct 20, 2023
d2b2d8c
Merge branch 'develop'
ariel10aguero Oct 20, 2023
f15a0b2
Merge branch 'develop'
ariel10aguero Nov 2, 2023
480dca2
Merge branch 'develop'
ariel10aguero Nov 3, 2023
11a576d
Merge branch 'develop'
tomastiminskas Nov 17, 2023
cddee8b
Merge branch 'develop'
tomastiminskas Dec 14, 2023
6252c19
Merge branch 'develop'
tomastiminskas Dec 15, 2023
a021241
Merge branch 'develop'
tomastiminskas Jan 5, 2024
4fd9556
Merge branch 'develop'
tomastiminskas Feb 10, 2024
ec688d2
Introduce HideBalance state.
KotlinGeekDev Feb 17, 2024
f405cde
Add toggleHideBalanceState. Wire up UI.
KotlinGeekDev Feb 17, 2024
34e352f
Get and set balance state from Preferences. Transition from Boolean t…
KotlinGeekDev Feb 19, 2024
d6c64fd
Move suspending call to the ViewModel.
KotlinGeekDev Feb 19, 2024
1aff5f7
Make HideBalance an object, as no sealed-class functionality is neede…
KotlinGeekDev Feb 19, 2024
048850d
Make use of Flow's combine. It is better suited for operating on the …
KotlinGeekDev Feb 19, 2024
ad815be
Adjust height configuration for the different states of the balance's…
KotlinGeekDev Feb 19, 2024
1b2fad6
Merge pull request #718 from KotlinGeekDev/aa/feature/hide-balance
tomastiminskas Feb 20, 2024
f4504b4
Some small ui adustments
tomastiminskas Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package chat.sphinx.wrapper_common

object HideBalance {

const val ENABLED = 1
const val DISABLED = 0

const val HIDE_BALANCE_SHARED_PREFERENCES = "general_settings"
const val HIDE_BALANCE_ENABLED_KEY = "hide-balance-enabled"

}
Original file line number Diff line number Diff line change
@@ -1,101 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="nav_drawer_width">240dp</dimen>
<item name="nav_drawer_input_lock_alpha" format="float" type="dimen">.5</item>

<!-- Text size -->
<dimen name="nav_drawer_default_text_size">16sp</dimen>
<dimen name="nav_drawer_version_text_size">10sp</dimen>
<dimen name="dashboard_search_text_size">14sp</dimen>

<dimen name="nav_drawer_header_margin">32dp</dimen>
<dimen name="nav_drawer_header_profile_picture_xy">46dp</dimen>
<dimen name="nav_drawer_header_profile_picture_radius">23dp</dimen>
<dimen name="nav_drawer_header_profile_text_margin">8dp</dimen>

<dimen name="nav_drawer_button_image_xy">29dp</dimen>

<!-- This is the profile_picture_xy + profile_text_margin -->
<dimen name="nav_drawer_button_text_margin_start">53dp</dimen>

<!-- This is the profile_picture_xy - nav_drawer_button_image_xy / 2-->
<dimen name="nav_drawer_button_image_margin_start">8dp</dimen>

<dimen name="nav_drawer_button_margin_top">32dp</dimen>

<dimen name="nav_bar_button_padding">20dp</dimen>

<dimen name="dashboard_search_bar_height">58sp</dimen>
<dimen name="dashboard_header_network_xy">24dp</dimen>

<dimen name="dashboard_chips_view_height">60dp</dimen>
<dimen name="dashboard_chip_height">38dp</dimen>
<dimen name="dashboard_chip_vertical_spacing">22dp</dimen>
<dimen name="dashboard_chip_spacing">5dp</dimen>

<dimen name="recycler_view_holder_height">90dp</dimen>

<!-- Restore popup -->
<dimen name="dashboard_restore_popup_width">240dp</dimen>
<dimen name="dashboard_restore_popup_height">100dp</dimen>
<dimen name="dashboard_restore_progress_bar_height">7dp</dimen>

<!-- Podcast search -->
<dimen name="feed_podcast_search_progress_bar_xy">32dp</dimen>
<dimen name="feed_podcast_search_results_row_height">92dp</dimen>
<dimen name="feed_podcast_search_results_image_radius">8dp</dimen>
<dimen name="feed_podcast_search_results_image_xy">72dp</dimen>
<dimen name="feed_podcast_search_subscribe_text_view_width">50dp</dimen>
<dimen name="feed_podcast_search_result_progress_bar_xy">30dp</dimen>
<dimen name="feed_podcast_search_results_header_height">48dp</dimen>

<!-- Deep link authorize popup -->
<dimen name="dashboard_authorize_popup_width">240dp</dimen>
<dimen name="dashboard_authorize_popup_height">300dp</dimen>
<dimen name="dashboard_authorize_popup_verified_icon_margin_top">40sp</dimen>
<dimen name="dashboard_authorize_popup_verified_icon_text_size">40sp</dimen>
<dimen name="dashboard_authorize_popup_authorize_title_text_size">13sp</dimen>
<dimen name="dashboard_authorize_popup_authorize_name_text_size">14sp</dimen>
<dimen name="dashboard_authorize_popup_authorize_button_height">52dp</dimen>
<dimen name="dashboard_authorize_popup_authorize_button_text_size">12sp</dimen>
<dimen name="dashboard_authorize_popup_progress_bar_zy">32dp</dimen>

<!-- Deep link redeem badge token popup -->
<dimen name="dashboard_redeem_badge_token_popup_width">240dp</dimen>
<dimen name="dashboard_redeem_badge_token_popup_height">300dp</dimen>
<dimen name="dashboard_redeem_badge_token_popup_verified_icon_margin_top">40sp</dimen>
<dimen name="dashboard_redeem_badge_token_popup_verified_icon_text_size">40sp</dimen>
<dimen name="dashboard_redeem_badge_token_popup_redeem_badge_token_title_text_size">13sp</dimen>
<dimen name="dashboard_redeem_badge_token_popup_redeem_badge_token_name_text_size">14sp</dimen>
<dimen name="dashboard_redeem_badge_token_popup_redeem_badge_token_button_height">52dp</dimen>
<dimen name="dashboard_redeem_badge_token_popup_redeem_badge_token_button_text_size">12sp</dimen>
<dimen name="dashboard_redeem_badge_token_popup_progress_bar_zy">32dp</dimen>

<!-- Deep save profile authorize popup -->
<dimen name="dashboard_save_profile_popup_width">240dp</dimen>
<dimen name="dashboard_save_profile_popup_height">300dp</dimen>
<dimen name="dashboard_save_profile_popup_verified_icon_margin_top">40sp</dimen>
<dimen name="dashboard_save_profile_popup_verified_icon_text_size">40sp</dimen>
<dimen name="dashboard_save_profile_popup_save_profile_title_text_size">13sp</dimen>
<dimen name="dashboard_save_profile_popup_save_profile_name_text_size">14sp</dimen>
<dimen name="dashboard_save_profile_popup_save_profile_button_height">52dp</dimen>
<dimen name="dashboard_save_profile_popup_save_profile_button_text_size">12sp</dimen>
<dimen name="dashboard_save_profile_popup_progress_bar_zy">32dp</dimen>

<dimen name="dashboard_connect_popup_width">260dp</dimen>
<dimen name="dashboard_connect_popup_height">420dp</dimen>
<dimen name="dashboard_connect_popup_profile_pic_xy">100dp</dimen>
<dimen name="dashboard_connect_popup_profile_pic_margin_top">30dp</dimen>
<dimen name="dashboard_connect_popup_name_text_size">17sp</dimen>
<dimen name="dashboard_connect_popup_price_text_size">12sp</dimen>
<dimen name="dashboard_connect_popup_description_text_size">14sp</dimen>
<dimen name="dashboard_connect_popup_form_edit_view_text_size">14sp</dimen>
<dimen name="text_margin">16dp</dimen>

<dimen name="dashboard_badge_count_xy">26dp</dimen>
<dimen name="dashboard_badge_count_padding_horizontal">6dp</dimen>
<dimen name="dashboard_feed_placeholder_text_size">20sp</dimen>
<dimen name="feed_row_text_point_divider">4sp</dimen>

<dimen name="feed_all_loading_height">285dp</dimen>
<!-- <dimen name="dashboard_search_bar_height">58sp</dimen>-->
<!-- <dimen name="dashboard_header_network_xy">24dp</dimen>-->

<!-- <dimen name="dashboard_chips_view_height">60dp</dimen>-->
<!-- <dimen name="dashboard_chip_height">38dp</dimen>-->
<!-- <dimen name="dashboard_chip_vertical_spacing">22dp</dimen>-->
<!-- <dimen name="dashboard_chip_spacing">5dp</dimen>-->

<!-- <dimen name="recycler_view_holder_height">90dp</dimen>-->

<!-- &lt;!&ndash; Restore popup &ndash;&gt;-->
<!-- <dimen name="dashboard_restore_popup_width">240dp</dimen>-->
<!-- <dimen name="dashboard_restore_popup_height">100dp</dimen>-->
<!-- <dimen name="dashboard_restore_progress_bar_height">7dp</dimen>-->

<!-- &lt;!&ndash; Podcast search &ndash;&gt;-->
<!-- <dimen name="feed_podcast_search_progress_bar_xy">32dp</dimen>-->
<!-- <dimen name="feed_podcast_search_results_row_height">92dp</dimen>-->
<!-- <dimen name="feed_podcast_search_results_image_radius">8dp</dimen>-->
<!-- <dimen name="feed_podcast_search_results_image_xy">72dp</dimen>-->
<!-- <dimen name="feed_podcast_search_subscribe_text_view_width">50dp</dimen>-->
<!-- <dimen name="feed_podcast_search_result_progress_bar_xy">30dp</dimen>-->
<!-- <dimen name="feed_podcast_search_results_header_height">48dp</dimen>-->

<!-- &lt;!&ndash; Deep link authorize popup &ndash;&gt;-->
<!-- <dimen name="dashboard_authorize_popup_width">240dp</dimen>-->
<!-- <dimen name="dashboard_authorize_popup_height">300dp</dimen>-->
<!-- <dimen name="dashboard_authorize_popup_verified_icon_margin_top">40sp</dimen>-->
<!-- <dimen name="dashboard_authorize_popup_verified_icon_text_size">40sp</dimen>-->
<!-- <dimen name="dashboard_authorize_popup_authorize_title_text_size">13sp</dimen>-->
<!-- <dimen name="dashboard_authorize_popup_authorize_name_text_size">14sp</dimen>-->
<!-- <dimen name="dashboard_authorize_popup_authorize_button_height">52dp</dimen>-->
<!-- <dimen name="dashboard_authorize_popup_authorize_button_text_size">12sp</dimen>-->
<!-- <dimen name="dashboard_authorize_popup_progress_bar_zy">32dp</dimen>-->

<!-- &lt;!&ndash; Deep link redeem badge token popup &ndash;&gt;-->
<!-- <dimen name="dashboard_redeem_badge_token_popup_width">240dp</dimen>-->
<!-- <dimen name="dashboard_redeem_badge_token_popup_height">300dp</dimen>-->
<!-- <dimen name="dashboard_redeem_badge_token_popup_verified_icon_margin_top">40sp</dimen>-->
<!-- <dimen name="dashboard_redeem_badge_token_popup_verified_icon_text_size">40sp</dimen>-->
<!-- <dimen name="dashboard_redeem_badge_token_popup_redeem_badge_token_title_text_size">13sp</dimen>-->
<!-- <dimen name="dashboard_redeem_badge_token_popup_redeem_badge_token_name_text_size">14sp</dimen>-->
<!-- <dimen name="dashboard_redeem_badge_token_popup_redeem_badge_token_button_height">52dp</dimen>-->
<!-- <dimen name="dashboard_redeem_badge_token_popup_redeem_badge_token_button_text_size">12sp</dimen>-->
<!-- <dimen name="dashboard_redeem_badge_token_popup_progress_bar_zy">32dp</dimen>-->

<!-- &lt;!&ndash; Deep save profile authorize popup &ndash;&gt;-->
<!-- <dimen name="dashboard_save_profile_popup_width">240dp</dimen>-->
<!-- <dimen name="dashboard_save_profile_popup_height">300dp</dimen>-->
<!-- <dimen name="dashboard_save_profile_popup_verified_icon_margin_top">40sp</dimen>-->
<!-- <dimen name="dashboard_save_profile_popup_verified_icon_text_size">40sp</dimen>-->
<!-- <dimen name="dashboard_save_profile_popup_save_profile_title_text_size">13sp</dimen>-->
<!-- <dimen name="dashboard_save_profile_popup_save_profile_name_text_size">14sp</dimen>-->
<!-- <dimen name="dashboard_save_profile_popup_save_profile_button_height">52dp</dimen>-->
<!-- <dimen name="dashboard_save_profile_popup_save_profile_button_text_size">12sp</dimen>-->
<!-- <dimen name="dashboard_save_profile_popup_progress_bar_zy">32dp</dimen>-->

<!-- <dimen name="dashboard_connect_popup_width">260dp</dimen>-->
<!-- <dimen name="dashboard_connect_popup_height">420dp</dimen>-->
<!-- <dimen name="dashboard_connect_popup_profile_pic_xy">100dp</dimen>-->
<!-- <dimen name="dashboard_connect_popup_profile_pic_margin_top">30dp</dimen>-->
<!-- <dimen name="dashboard_connect_popup_name_text_size">17sp</dimen>-->
<!-- <dimen name="dashboard_connect_popup_price_text_size">12sp</dimen>-->
<!-- <dimen name="dashboard_connect_popup_description_text_size">14sp</dimen>-->
<!-- <dimen name="dashboard_connect_popup_form_edit_view_text_size">14sp</dimen>-->
<!-- <dimen name="text_margin">16dp</dimen>-->

<!-- <dimen name="dashboard_badge_count_xy">26dp</dimen>-->
<!-- <dimen name="dashboard_badge_count_padding_horizontal">6dp</dimen>-->
<!-- <dimen name="dashboard_feed_placeholder_text_size">20sp</dimen>-->
<!-- <dimen name="feed_row_text_point_divider">4sp</dimen>-->

<!-- <dimen name="feed_all_loading_height">285dp</dimen>-->
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.motion.widget.MotionLayout
Expand Down Expand Up @@ -34,8 +35,10 @@ import chat.sphinx.kotlin_response.Response
import chat.sphinx.menu_bottom_scanner.BottomScannerMenu
import chat.sphinx.resources.databinding.LayoutPodcastPlayerFooterBinding
import chat.sphinx.swipe_reveal_layout.SwipeRevealLayout
import chat.sphinx.wrapper_common.HideBalance
import chat.sphinx.wrapper_common.chat.PushNotificationLink
import chat.sphinx.wrapper_common.lightning.*
import chat.sphinx.wrapper_lightning.NodeBalance
import chat.sphinx.wrapper_view.Px
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -47,6 +50,7 @@ import io.matthewnelson.concept_views.viewstate.collect
import io.matthewnelson.concept_views.viewstate.value
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand Down Expand Up @@ -277,6 +281,10 @@ internal class DashboardFragment : MotionLayoutFragment<
header.textViewDashboardHeaderNetwork.setOnClickListener {
viewModel.toastIfNetworkConnected()
}

header.textViewDashboardHeaderBalance.setOnClickListener {
viewModel.toggleHideBalanceState()
}
}
}

Expand Down Expand Up @@ -372,6 +380,10 @@ internal class DashboardFragment : MotionLayoutFragment<

navDrawer.layoutConstraintDashboardNavDrawer.setOnClickListener { viewModel }

navDrawer.navDrawerTextViewSatsBalance.setOnClickListener {
viewModel.toggleHideBalanceState()
}

navDrawer.navDrawerButtonContacts.setOnClickListener {
lifecycleScope.launch { viewModel.navDrawerNavigator.toAddressBookScreen() }
}
Expand Down Expand Up @@ -479,12 +491,38 @@ internal class DashboardFragment : MotionLayoutFragment<
}

onStopSupervisor.scope.launch(viewModel.mainImmediate) {
viewModel.getAccountBalance().collect { nodeBalance ->
if (nodeBalance == null) return@collect

nodeBalance.balance.asFormattedString().let { balance ->
binding.layoutDashboardHeader.textViewDashboardHeaderBalance.text = balance
binding.layoutDashboardNavDrawer.navDrawerTextViewSatsBalance.text = balance
combine(
viewModel.hideBalanceStateFlow,
viewModel.getAccountBalance()
) { hideBalanceState: Int, nodeBalance: NodeBalance? ->
BalanceState(nodeBalance, hideBalanceState)
}.collect { balanceState ->

Log.d(
"DashboardFrag",
"onStart: ShouldHide Balance: ${balanceState.hideBalanceState == HideBalance.ENABLED}")
if (balanceState.nodeBalance == null) return@collect
balanceState.nodeBalance.balance.asFormattedString().let { balance ->
with(binding.layoutDashboardHeader.textViewDashboardHeaderBalance){
if (balanceState.hideBalanceState == HideBalance.ENABLED){
layoutParams.height = resources.getDimensionPixelSize(R.dimen.hidden_balance_placeholder)
text = "*****"
}
else {
layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT
text = balance
}
}
with(binding.layoutDashboardNavDrawer.navDrawerTextViewSatsBalance){
if (balanceState.hideBalanceState == HideBalance.ENABLED){
layoutParams.height = resources.getDimensionPixelSize(R.dimen.hidden_nav_balance_placeholder)
text = "*****"
}
else {
layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT
text = balance
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import chat.sphinx.dashboard.navigation.DashboardNavigator
import chat.sphinx.dashboard.ui.viewstates.*
import chat.sphinx.kotlin_response.*
import chat.sphinx.logger.SphinxLogger
import chat.sphinx.logger.d
import chat.sphinx.menu_bottom.ui.MenuBottomViewState
import chat.sphinx.menu_bottom_scanner.ScannerMenuHandler
import chat.sphinx.menu_bottom_scanner.ScannerMenuViewModel
Expand Down Expand Up @@ -70,14 +69,16 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import io.matthewnelson.android_feature_navigation.util.navArgs
import io.matthewnelson.android_feature_viewmodel.MotionLayoutViewModel
import io.matthewnelson.android_feature_viewmodel.submitSideEffect
import io.matthewnelson.android_feature_viewmodel.updateViewState
import io.matthewnelson.build_config.BuildConfigVersionCode
import io.matthewnelson.concept_coroutines.CoroutineDispatchers
import io.matthewnelson.concept_views.viewstate.ViewStateContainer
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import javax.inject.Inject


data class BalanceState(val nodeBalance: NodeBalance?, val hideBalanceState: Int)

@HiltViewModel
internal class DashboardViewModel @Inject constructor(
private val app: Application,
Expand Down Expand Up @@ -146,6 +147,13 @@ internal class DashboardViewModel @Inject constructor(
val networkStateFlow: StateFlow<Pair<LoadResponse<Boolean, ResponseError>, Boolean>>
get() = _networkStateFlow.asStateFlow()

private val _hideBalanceStateFlow: MutableStateFlow<Int> by lazy {
MutableStateFlow(HideBalance.DISABLED)
}

val hideBalanceStateFlow: StateFlow<Int>
get() = _hideBalanceStateFlow.asStateFlow()


private lateinit var signerManager: SignerManager

Expand All @@ -156,6 +164,8 @@ internal class DashboardViewModel @Inject constructor(
}
}

getHideBalanceState()

syncFeedRecommendationsState()

getRelayKeys()
Expand All @@ -167,6 +177,42 @@ internal class DashboardViewModel @Inject constructor(

networkRefresh(true)
}

private fun getHideBalanceState() {
viewModelScope.launch(mainImmediate) {
val appContext: Context = app.applicationContext
val hideSharedPreferences = appContext.getSharedPreferences(HideBalance.HIDE_BALANCE_SHARED_PREFERENCES, Context.MODE_PRIVATE)

val shouldHide = hideSharedPreferences.getInt(HideBalance.HIDE_BALANCE_ENABLED_KEY, HideBalance.DISABLED)
_hideBalanceStateFlow.value = shouldHide
}
}

fun toggleHideBalanceState(){
viewModelScope.launch(mainImmediate) {
val newState = if(_hideBalanceStateFlow.value == HideBalance.DISABLED){
HideBalance.ENABLED
} else {
HideBalance.DISABLED
}
_hideBalanceStateFlow.value = newState

delay(50L)

val appContext: Context = app.applicationContext
val hideSharedPreferences = appContext.getSharedPreferences(HideBalance.HIDE_BALANCE_SHARED_PREFERENCES, Context.MODE_PRIVATE)

withContext(dispatchers.io) {
hideSharedPreferences.edit()
.putInt(HideBalance.HIDE_BALANCE_ENABLED_KEY, newState)
.let { editor ->
if (!editor.commit()) {
editor.apply()
}
}
}
}
}

private fun getRelayKeys() {
repositoryDashboard.getAndSaveTransportKey(forceGet = true)
Expand Down
Loading
Loading