Skip to content

Commit

Permalink
feat(dashpay): add quick voting function (#1322)
Browse files Browse the repository at this point in the history
* feat: update username voting screen

* feat: add keys changes

* feat: add keys errors

* refactor: change vote system to return a tuple

* refactor: change vote queries to use get_vote_polls

* fix: improve Username Voting screen and voting

* feature: add delete masternode key functionality (disabled)

* fix: use withContext(Dispatchers.IO)

* fix: add voting keys fixes

* fix: fix vote click bug

* fix: add vote key again

* fix: prevent counting one vote as many

* chore: log the wrong vote differently

* fix: correct duplicate key detection

* fix: fix request process state

* fix: add tools:text for Results on

* chore: remove commented code

* fix: simplify Username Request vote button styles

* fix: delete vote fix

* feat: add OneVoteLeftDialog

* feat: add blue lightning bolt next to Quick Voting

* feat: add countVotes

* fix: spacing and text on OneVoteLeftDialogFragment

* feat: add new text for Quick Voting

* feat: add isQuickVoting for BroadcastUsernameVotes* classes

* feat: isApproved is based on the last vote

* fix: update voteForAll functiom

* fix: update voteForAll function

* feat: add quick voting support to UsernameRequestsFragment

* feat: improve username search in UsernameRequestsFragment

* feat: improve username search in UsernameRequestsFragment

* fix: keep track of normalized and regular labels

* fix: some bugs resulting from removing mocking
  • Loading branch information
HashEngineering authored Dec 5, 2024
1 parent d7d53c3 commit 71ceae7
Show file tree
Hide file tree
Showing 18 changed files with 413 additions and 459 deletions.
82 changes: 0 additions & 82 deletions common/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -961,87 +961,6 @@
<item name="android:theme">@style/PrimaryButtonTheme.Large.LightBlue</item>
</style>

<style name="VoteButtonTheme">
<item name="cornerRadius">7dp</item>
<item name="titleTextColor">@color/white</item>
<item name="backgroundColor">@color/content_primary</item>
<item name="strokeColor">@color/content_primary</item>
<item name="rippleColor">@color/ripple_light</item>
<item name="disabledBackgroundColor">@color/disabled_button_bg</item>
</style>

<style name="VoteButton" parent="Widget.AppCompat.Button.Borderless">
<item name="fontFamily">@font/inter_semibold</item>
<item name="android:textColor">@color/button_text</item>
<item name="android:background">@drawable/rounded_ripple_background</item>
<item name="android:theme">@style/VoteButtonTheme</item>
<item name="android:textSize">12sp</item>
<item name="android:textAllCaps">false</item>
<item name="android:paddingStart">8dp</item>
<item name="android:paddingEnd">8dp</item>
<item name="android:paddingTop">4dp</item>
<item name="android:paddingBottom">4dp</item>
<item name="android:minHeight">40dp</item>
</style>

<style name="Button.Vote" parent="Widget.AppCompat.Button.Borderless">
<item name="fontFamily">@font/inter_semibold</item>
<item name="android:textColor">@color/button_text</item>
<item name="android:background">@drawable/rounded_ripple_background</item>
<item name="android:theme">@style/VoteButtonTheme</item>
<item name="android:textSize">12sp</item>
<item name="android:textAllCaps">false</item>
<item name="android:paddingStart">8dp</item>
<item name="android:paddingEnd">8dp</item>
<item name="android:paddingTop">4dp</item>
<item name="android:paddingBottom">4dp</item>
<item name="android:minHeight">40dp</item>
</style>

<style name="VoteButton.LightBlue">
<item name="backgroundColor">@color/dash_blue_0.05</item>
<item name="strokeColor">@android:color/transparent</item>
<item name="titleTextColor">@color/dash_blue</item>
<item name="rippleColor">@color/button_ripple_color</item>
</style>

<style name="Button.Vote.LightBlue">
<item name="android:theme">@style/VoteButton.LightBlue</item>
</style>

<style name="VoteButton.LightRed">
<item name="backgroundColor">@color/red_0.05</item>
<item name="strokeColor">@android:color/transparent</item>
<item name="titleTextColor">@color/red</item>
<item name="rippleColor">@color/button_ripple_color</item>
</style>

<style name="Button.Vote.LightRed">
<item name="android:theme">@style/VoteButton.LightRed</item>
</style>

<style name="VoteButton.Blue">
<item name="backgroundColor">@color/dash_blue</item>
<item name="strokeColor">@android:color/transparent</item>
<item name="titleTextColor">@color/dash_white</item>
<item name="rippleColor">@color/button_ripple_color</item>
</style>

<style name="Button.Vote.Blue">
<item name="android:theme">@style/VoteButton.Blue</item>
</style>

<style name="VoteButton.Red">
<item name="backgroundColor">@color/red</item>
<item name="strokeColor">@android:color/transparent</item>
<item name="titleTextColor">@color/dash_white</item>
<item name="rippleColor">@color/button_ripple_color</item>
</style>

<style name="Button.Vote.Red">
<item name="android:theme">@style/VoteButton.Red</item>
</style>

<style name="Button.Primary.Small">
<item name="android:textSize">13sp</item>
<item name="android:minHeight">30dp</item>
Expand All @@ -1064,7 +983,6 @@
<item name="android:theme">@style/PrimaryButtonTheme.Small.Round</item>
</style>


<style name="Button.Primary.ExtraSmall">
<item name="android:theme">@style/PrimaryButtonTheme.ExtraSmall</item>
<item name="android:textSize">11sp</item>
Expand Down
9 changes: 9 additions & 0 deletions wallet/res/drawable/ic_blue_bolt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="10dp"
android:height="16dp"
android:viewportWidth="10"
android:viewportHeight="16">
<path
android:pathData="M0.5,8.81C0.5,8.666 0.562,8.52 0.685,8.371L6.753,0.915C6.872,0.771 6.999,0.681 7.135,0.647C7.275,0.613 7.4,0.626 7.51,0.686C7.621,0.745 7.697,0.841 7.74,0.972C7.786,1.1 7.774,1.254 7.701,1.437L5.734,6.696H9.491C9.639,6.696 9.76,6.743 9.854,6.836C9.951,6.926 10,7.04 10,7.18C10,7.329 9.941,7.477 9.822,7.626L3.754,15.076C3.635,15.224 3.505,15.316 3.365,15.349C3.229,15.384 3.106,15.371 2.996,15.311C2.886,15.252 2.807,15.156 2.76,15.025C2.718,14.893 2.731,14.736 2.799,14.554L4.772,9.294H1.009C0.865,9.294 0.744,9.25 0.646,9.16C0.549,9.067 0.5,8.95 0.5,8.81Z"
android:fillColor="#008DE4"/>
</vector>
102 changes: 102 additions & 0 deletions wallet/res/layout/dialog_one_vote_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2023 Dash Core Group.
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<View
android:id="@+id/drag_indicator"
android:layout_width="35dp"
android:layout_height="4dp"
android:layout_gravity="center"
android:layout_marginVertical="7dp"
android:background="@drawable/rounded_background"
android:theme="@style/DragIndicatorBackground"
tools:background="@color/light_gray" />

<TextView
style="@style/Headline5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:gravity="center_horizontal"
android:textAlignment="gravity"
android:layout_marginHorizontal="20dp"
android:text="@string/one_vote_left_title" />

<TextView
android:id="@+id/subtitle"
style="@style/Body2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textAlignment="gravity"
android:layout_marginHorizontal="20dp"
android:text="@string/quick_vote_subtitle" />

<TextView
android:id="@+id/show_usernames"
style="@style/Caption.Medium.Blue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textAlignment="gravity"
android:layout_marginHorizontal="20dp"
android:text="@string/one_vote_left_show_usernames" />

<TextView
android:id="@+id/username_list"
style="@style/Body2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:textAlignment="gravity"
android:layout_marginHorizontal="20dp"
android:visibility="invisible"
tools:visibility="visible"
tools:text="@string/one_vote_left_username_examples" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="15dp">

<Button
android:id="@+id/dismiss_btn"
style="@style/Button.Primary.Large.Grey"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_weight="1"
android:text="@string/cancel" />

<Button
android:id="@+id/ok_button"
style="@style/Button.Primary.Large.Blue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="15dp"
android:layout_weight="1"
android:text="@string/button_ok" />
</LinearLayout>
</LinearLayout>
2 changes: 1 addition & 1 deletion wallet/res/layout/fragment_more.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
style="@style/MenuRowSubTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/requested_voting_duration" />
tools:text="Results on 10/12/2024" />
</LinearLayout>

<LinearLayout
Expand Down
31 changes: 22 additions & 9 deletions wallet/res/layout/fragment_username_requests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,29 @@
app:navigationIcon="@drawable/ic_arrow_back"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<TextView
<LinearLayout
android:id="@+id/quick_vote_button"
style="@style/Subtitle2.Blue"
android:paddingVertical="4dp"
android:paddingHorizontal="12dp"
android:textSize="13sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="end"
android:text="@string/quick_vote" />
android:paddingVertical="4dp"
android:paddingHorizontal="12dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:src="@drawable/ic_blue_bolt"
android:layout_gravity="center_vertical"
/>
<TextView
style="@style/Subtitle2.Blue"
android:textSize="13sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/quick_vote" />
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
Expand Down Expand Up @@ -198,11 +211,11 @@
android:id="@+id/request_groups"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:paddingBottom="15dp"
android:layout_marginHorizontal="15dp"
android:layout_marginTop="15dp"
android:clipToPadding="false"
android:overScrollMode="never"
android:paddingBottom="15dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/search_panel"
Expand Down
15 changes: 2 additions & 13 deletions wallet/res/layout/username_request_group_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@
app:layout_constraintTop_toTopOf="@id/link_badge"
app:layout_constraintStart_toEndOf="@id/link_badge" />

<!-- <TextView-->
<!-- android:id="@+id/block_votes"-->
<!-- style="@style/Body2.Medium.Red"-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:paddingVertical="17dp"-->
<!-- android:layout_marginStart="15dp"-->
<!-- app:layout_constraintStart_toEndOf="@id/username"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- tools:text="(1s Blocks)" />-->

<TextView
android:id="@+id/requests_amount"
style="@style/Overline.Tertiary"
Expand All @@ -92,7 +81,7 @@

<Button
android:id="@+id/blocks_button"
style="@style/Button.Vote.LightRed"
style="@style/Button.Primary.Large.LightRed"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginVertical="5dp"
Expand All @@ -105,7 +94,7 @@

<Button
android:id="@+id/approvals_button"
style="@style/Button.Vote.LightBlue"
style="@style/Button.Primary.Large.LightBlue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginVertical="5dp"
Expand Down
32 changes: 1 addition & 31 deletions wallet/res/layout/username_request_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

<Button
android:id="@+id/approvals_button"
style="@style/Button.Vote.LightBlue"
style="@style/Button.Primary.Large.LightBlue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginHorizontal="8dp"
Expand All @@ -82,34 +82,4 @@
/>
</androidx.constraintlayout.widget.ConstraintLayout>

<!-- <TextView-->
<!-- android:id="@+id/cancel_approval_button"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginEnd="10dp"-->
<!-- style="@style/Button.Tertiary.ExtraSmall"-->
<!-- android:text="@string/cancel_approval"-->
<!-- app:layout_constraintEnd_toStartOf="@id/vote_amount"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- />-->



<!-- <TextView-->
<!-- android:id="@+id/vote_amount"-->
<!-- style="@style/Overline.Tertiary"-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="20dp"-->
<!-- android:layout_marginEnd="15dp"-->
<!-- android:minWidth="20dp"-->
<!-- android:paddingHorizontal="7dp"-->
<!-- android:gravity="center"-->
<!-- android:textAlignment="gravity"-->
<!-- android:background="@drawable/rounded_background"-->
<!-- android:theme="@style/InactiveBadgeTheme"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- tools:text="10" />-->
</androidx.constraintlayout.widget.ConstraintLayout>
6 changes: 6 additions & 0 deletions wallet/res/values/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@
<string name="add_masternode_key">Add Masternode Voting Key</string>
<string name="dont_ask_again">Don\'t ask me again</string>
<string name="vote_submitting">Submitting your vote for %s username</string>
<string name="quick_vote_submitting">Submitting your votes for all usernames</string>
<string name="vote_submitted">Voted for %s username</string>
<string name="quick_vote_submitted">Successfully voted for all usernames</string>
<string name="cancel_submitting">Canceling your vote for %s username</string>
<string name="cancel_submitted">Canceled vote for %s username</string>
<string name="block_submitting">Blocking for %s username</string>
Expand All @@ -371,6 +373,10 @@
<string name="quick_vote">Quick Voting</string>
<string name="quick_vote_subtitle">By tapping the \"Vote for All\" button, you will automatically vote for all of the filtered usernames (%d) that were submitted first</string>
<string name="vote_for_all">Vote for All</string>
<string name="one_vote_left_title">One Vote Left</string>
<string name="one_vote_left_show_usernames">Show usernames</string>
<string name="one_vote_left_subtitle">You have already voted for the following usernames %d times. You can only cast one more vote for these usernames.</string>
<string name="one_vote_left_username_examples" translatable="false">stargazer101, quantumquirk, dreamchaser22, pixelpioneer, nebulanavigator, echoexplorer, cyberscribe, lunalark, astroaficionado, mysticmuse, solarsage, galacticguru, horizonhunter, cosmiccrafter, celestialseeker, orbitoracle, stellarscribe, novanomad, astroartisan, meteormaverick</string>
<string name="voting_period_active">Username Voting Period Active</string>
<string name="there_was_a_network_error">There was a network error, you can try again at no extra cost</string>
<string name="requested_username_has_been">Username has been requested.</string>
Expand Down
3 changes: 0 additions & 3 deletions wallet/src/de/schildbach/wallet/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ public final class Constants {
public static boolean SUPPORTS_PLATFORM;
// TODO: remove all references to this when invites are enabled and functional
public static boolean SUPPORTS_INVITES;
// TODO: remove all references to this when quick voting is enabled and functional
public static final boolean SUPPORTS_QUICKVOTING = false;


public static final EnumSet<MasternodeSync.SYNC_FLAGS> SYNC_FLAGS = MasternodeSync.SYNC_DEFAULT_SPV;
public static final EnumSet<MasternodeSync.VERIFY_FLAGS> VERIFY_FLAGS = MasternodeSync.VERIFY_DEFAULT_SPV;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ interface UsernameVoteDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(usernameVote: UsernameVote)

@Query("SELECT COUNT(*) FROM username_votes WHERE username = :username")
suspend fun countVotes(username: String): Int

@Query("SELECT * FROM username_votes WHERE username = :username ORDER BY timestamp")
suspend fun getVotes(username: String): List<UsernameVote>

Expand Down
Loading

0 comments on commit 71ceae7

Please sign in to comment.