Skip to content

Commit

Permalink
Merge branch 'dashpay-voting' of https://github.com/dashevo/dash-wallet
Browse files Browse the repository at this point in the history
… into dashpay-bugfix-ui-translation
  • Loading branch information
HashEngineering committed Nov 6, 2024
2 parents 41d0eae + 80dc184 commit 1643ddf
Show file tree
Hide file tree
Showing 34 changed files with 1,752 additions and 414 deletions.
98 changes: 98 additions & 0 deletions common/src/main/java/org/dash/wallet/common/ui/ResourcesExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

package org.dash.wallet.common.ui

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.RippleDrawable
import android.view.View
import android.widget.Button
import androidx.annotation.StyleRes
import androidx.core.content.res.ResourcesCompat
import org.dash.wallet.common.R
Expand All @@ -41,3 +46,96 @@ fun View.setRoundedRippleBackground(@StyleRes style: Int?) {
)
}
}

fun View.applyStyle(@StyleRes style: Int?) {
style?.let {
context.theme.applyStyle(style, true)
}
}

//fun View.setRoundedRippleBackgroundButtonStyle1(@StyleRes style: Int?) {
// style?.let {
// val theme = this.resources.newTheme().apply { applyStyle(style, true) }
//
// // Extract the cornerRadius attribute
//// val cornerRadiusAttr = intArrayOf(R.attr.cornerRadius)
//// val cornerRadiusArray = theme.obtainStyledAttributes(cornerRadiusAttr)
//// val cornerRadius = cornerRadiusArray.getDimension(0, 0f) // Default to 0 if not set
//// cornerRadiusArray.recycle()
// val cornerRadius = 7.dpToPx(context).toFloat()
//
// // Extract the titleTextColor attribute
// val titleTextColorAttr = intArrayOf(R.attr.titleTextColor)
// val textColorArray = theme.obtainStyledAttributes(titleTextColorAttr)
// val titleTextColor = textColorArray.getColor(0, Color.BLACK) // Default to black if not set
// textColorArray.recycle()
//
// // Apply cornerRadius and titleTextColor as needed (e.g., to a button)
// val drawable = ResourcesCompat.getDrawable(
// this.resources,
// R.drawable.rounded_ripple_background,
// theme
// )
//
// // Assuming rounded_ripple_background is a shape drawable that supports corner radius
// if (drawable is RippleDrawable) {
// // For the mask
// val maskDrawable = drawable.findDrawableByLayerId(android.R.id.mask) as? GradientDrawable
// maskDrawable?.cornerRadius = cornerRadius
//
// // For the content shape (background)
// val contentDrawable = drawable.getDrawable(0) as? GradientDrawable
// contentDrawable?.cornerRadius = cornerRadius
// }
//
// // Apply drawable as background and set titleTextColor
// this.background = drawable
// (this as? Button)?.setTextColor(titleTextColor)
// }
//}
//
fun View.setRoundedRippleBackgroundButtonStyle(@StyleRes style: Int?, defaultCornerRadius: Int = 7) {
style?.let {
val theme = this.resources.newTheme().apply { applyStyle(style, true) }
val defaultCornerRadius = defaultCornerRadius.dpToPx(this.context)

// Resolve the cornerRadius and rippleColor attributes from the applied style
val attrs = intArrayOf(
R.attr.backgroundColor,
R.attr.titleTextColor
)

val typedArray = theme.obtainStyledAttributes(style, attrs)

// Extract the attributes from the typed array
val backgroundColor = typedArray.getColor(0, Color.TRANSPARENT)
val titleTextColor = typedArray.getColor(1, Color.BLACK) // Default to black if not set
typedArray.recycle()

// Apply the ripple drawable from your XML
val rippleDrawable = ResourcesCompat.getDrawable(
this.resources,
R.drawable.rounded_ripple_background, // Your ripple drawable
theme
) as? RippleDrawable

rippleDrawable?.let { rd ->

// Modify the background color, corner radius, and stroke in the ripple's shape
val contentDrawable = rd.getDrawable(1) as? GradientDrawable
contentDrawable?.apply {
setColor(backgroundColor)
cornerRadius = defaultCornerRadius.dpToPx(context).toFloat()
}

// Set the ripple drawable as the background
this.background = rd
}
(this as? Button)?.setTextColor(titleTextColor)
}
}

// Utility function to convert dp to px for stroke width
fun Int.dpToPx(context: Context): Int {
return (this * context.resources.displayMetrics.density).toInt()
}
9 changes: 9 additions & 0 deletions common/src/main/res/drawable/ic_x.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="11dp"
android:height="12dp"
android:viewportWidth="11"
android:viewportHeight="12">
<path
android:pathData="M0.891,10.936C0.785,10.83 0.715,10.707 0.682,10.567C0.648,10.428 0.648,10.288 0.682,10.148C0.715,10.009 0.783,9.888 0.885,9.787L4.668,5.997L0.885,2.214C0.783,2.117 0.715,1.998 0.682,1.858C0.652,1.715 0.652,1.573 0.682,1.433C0.715,1.293 0.785,1.171 0.891,1.065C0.993,0.959 1.113,0.889 1.253,0.855C1.397,0.822 1.539,0.822 1.678,0.855C1.822,0.889 1.945,0.957 2.046,1.059L5.83,4.842L9.613,1.059C9.714,0.957 9.835,0.889 9.975,0.855C10.114,0.822 10.254,0.822 10.394,0.855C10.533,0.889 10.656,0.961 10.762,1.071C10.868,1.173 10.937,1.293 10.971,1.433C11.009,1.573 11.009,1.712 10.971,1.852C10.937,1.992 10.87,2.112 10.768,2.214L6.991,5.997L10.768,9.787C10.87,9.888 10.937,10.009 10.971,10.148C11.005,10.288 11.005,10.428 10.971,10.567C10.937,10.707 10.868,10.83 10.762,10.936C10.656,11.041 10.533,11.111 10.394,11.145C10.254,11.179 10.114,11.179 9.975,11.145C9.835,11.111 9.714,11.043 9.613,10.942L5.83,7.159L2.046,10.942C1.945,11.043 1.824,11.111 1.685,11.145C1.545,11.179 1.403,11.179 1.259,11.145C1.12,11.111 0.997,11.041 0.891,10.936Z"
android:fillColor="#B0B6BC"/>
</vector>
2 changes: 2 additions & 0 deletions common/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,6 @@
<color name="gray_300">#AAAEB3</color>
<color name="gray_600">#5D5F61</color>

<color name="red">#EA3943</color>
<color name="red_0.05">#0DEA3943</color>
</resources>
1 change: 1 addition & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,5 @@

<!-- basic formats -->
<string name="percent" translatable="false">%d%%</string>
<string name="two_lines_number_text" translatable="false">%d\n%s</string>
</resources>
81 changes: 81 additions & 0 deletions common/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,87 @@
<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 Down
6 changes: 6 additions & 0 deletions wallet/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@
android:exported="false"
android:foregroundServiceType="connectedDevice" /-->

<!-- WorkManager -->
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
android:exported="false" />

<!-- Prompt Google Play services to install the backported photo picker module -->
<!-- required to support Android 7 to 12 -->
<service android:name="com.google.android.gms.metadata.ModuleDependencies" android:enabled="false" android:exported="false">
Expand Down
17 changes: 17 additions & 0 deletions wallet/res/drawable-v21/selectable_round_corners_border_light.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/button_ripple_light">
<item>
<shape android:shape="rectangle">
<corners android:radius="8dp" />
<solid android:color="@android:color/white" />
<stroke android:color="@color/button_ripple_light" android:width="1dp"/>
</shape>
</item>
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<corners android:radius="8dp" />
<solid android:color="@android:color/holo_red_dark" />
</shape>
</item>
</ripple>
52 changes: 40 additions & 12 deletions wallet/res/layout/fragment_add_voting_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,7 @@
tools:itemCount="5"
tools:listitem="@layout/view_masternode_ip" />

<TextView
android:id="@+id/votes_cast_text"
style="@style/Overline.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center"
android:textAlignment="gravity"
tools:text="@string/multiple_votes_cast" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

<LinearLayout
Expand All @@ -81,7 +72,7 @@
android:paddingEnd="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/submit_button">
app:layout_constraintBottom_toTopOf="@id/dont_ask_again_button">

<ImageView
android:layout_width="wrap_content"
Expand All @@ -98,12 +89,49 @@
android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout
android:id="@+id/dont_ask_again_button"
style="@style/Button.Tertiary.Large.Blue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginHorizontal="15dp"
android:layout_marginBottom="10dp"
android:paddingEnd="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/submit_button">

<TextView
style="@style/Subtitle2.Blue"
android:textSize="15sp"
android:text="@string/dont_ask_again"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

<Button
android:id="@+id/submit_button"
style="@style/Button.Primary.Large.Blue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="@string/submit"
app:layout_constraintBottom_toBottomOf="parent" />
app:layout_constraintBottom_toTopOf="@id/votes_cast_text" />

<TextView
android:id="@+id/votes_cast_text"
style="@style/Overline.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginHorizontal="15dp"
android:layout_marginBottom="15dp"
android:gravity="center"
android:textAlignment="gravity"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="@string/multiple_votes_cast" />

</androidx.constraintlayout.widget.ConstraintLayout>
12 changes: 11 additions & 1 deletion wallet/res/layout/fragment_username_requests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@
android:text="@string/username_voting_subtitle"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/subtitletwo"
style="@style/Body2.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="15dp"
android:layout_marginTop="2dp"
android:text="@string/username_voting_subtitle_two"
app:layout_constraintTop_toBottomOf="@id/subtitle" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/filter_panel"
android:layout_width="match_parent"
Expand All @@ -102,7 +112,7 @@
android:layout_marginBottom="8dp"
android:layout_marginStart="15dp"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="@id/subtitle">
app:layout_constraintTop_toBottomOf="@id/subtitletwo">

<TextView
android:id="@+id/filter_title"
Expand Down
3 changes: 2 additions & 1 deletion wallet/res/layout/fragment_username_voting_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="@string/usernames_blocked_subtitle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/blocked_title"
app:layout_constraintTop_toBottomOf="@+id/blocked_title" />
Expand Down Expand Up @@ -204,8 +205,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="63dp"
android:layout_marginTop="14dp"
android:text="@string/keep_your_passphrase_safe"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Expand Down
Loading

0 comments on commit 1643ddf

Please sign in to comment.