Skip to content

Commit

Permalink
feat: added prominent disclosure for crash reports/diagnostic data wi…
Browse files Browse the repository at this point in the history
…th toggle in setup wizard
  • Loading branch information
timschneeb committed Mar 29, 2023
1 parent 593c0dc commit b7ead7e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import me.timschneeberger.rootlessjamesdsp.utils.extensions.PermissionExtensions
import me.timschneeberger.rootlessjamesdsp.utils.extensions.PermissionExtensions.hasRecordPermission
import me.timschneeberger.rootlessjamesdsp.utils.preferences.Preferences
import me.timschneeberger.rootlessjamesdsp.utils.sdkAbove
import me.timschneeberger.rootlessjamesdsp.view.Card
import org.koin.android.ext.android.inject
import rikka.shizuku.Shizuku
import timber.log.Timber
Expand Down Expand Up @@ -374,6 +375,14 @@ class OnboardingFragment : Fragment() {
if(!SdkCheck.isTiramisu) {
pageBinding.findViewById<View>(R.id.onboarding_notification_permission).visibility = View.GONE
}
pageBinding.findViewById<Card>(R.id.privacy_card).apply {
isVisible = !BuildConfig.FOSS_ONLY
checkboxIsChecked = prefsApp.get(R.string.key_share_crash_reports)
setOnCheckChangedListener {
Timber.d("Should share crash reports? $it")
prefsApp.set(R.string.key_share_crash_reports, it)
}
}
}

// Hide next button because user should continue by choosing a setup method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.core.view.setMargins
import com.google.android.material.checkbox.MaterialCheckBox
import me.timschneeberger.rootlessjamesdsp.R
import me.timschneeberger.rootlessjamesdsp.databinding.ViewCardBinding
import me.timschneeberger.rootlessjamesdsp.utils.extensions.asHtml
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.dpToPx
import me.timschneeberger.rootlessjamesdsp.utils.extensions.asHtml


class Card @JvmOverloads constructor(
Expand All @@ -26,9 +27,20 @@ class Card @JvmOverloads constructor(
) : LinearLayout(context, attrs) {

private var onButtonClickListener: (() -> Unit)? = null
private var onCheckChangedListener: ((Boolean) -> Unit)? = null
private var onCloseClickListener: (() -> Unit)? = null
private val binding: ViewCardBinding

var checkboxVisible: Boolean = true
set(value) {
field = value
binding.closeButtonLayout.isVisible = value
binding.checkbox.isVisible = value
binding.close.isVisible = false
}
var checkboxIsChecked: Boolean
get() = binding.checkbox.isChecked
set(value) { binding.checkbox.isChecked = value }
var buttonEnabled: Boolean = true
set(value) {
field = value
Expand All @@ -46,6 +58,8 @@ class Card @JvmOverloads constructor(
set(value) {
field = value
binding.closeButtonLayout.isVisible = value
binding.close.isVisible = value
binding.checkbox.isVisible = false
}
var titleText: String? = null
set(value) {
Expand Down Expand Up @@ -97,6 +111,7 @@ class Card @JvmOverloads constructor(
closeButtonVisible = a.getBoolean(R.styleable.Card_closeButtonVisible, false)
buttonText = a.getString(R.styleable.Card_buttonText)
buttonEnabled = a.getBoolean(R.styleable.Card_buttonEnabled, true)
checkboxVisible = a.getBoolean(R.styleable.Card_checkboxVisible, false)
iconSrc = a.getResourceId(R.styleable.Card_iconSrc, 0)
iconTint = a.getColorStateList(R.styleable.Card_iconTint)

Expand All @@ -121,9 +136,25 @@ class Card @JvmOverloads constructor(
onCloseClickListener?.invoke()
}

binding.root.setOnClickListener {
binding.checkbox.isChecked = !binding.checkbox.isChecked
}

updateForeground()
}

override fun onAttachedToWindow() {
binding.checkbox.addOnCheckedStateChangedListener { _, state ->
onCheckChangedListener?.invoke(state == MaterialCheckBox.STATE_CHECKED)
}
super.onAttachedToWindow()
}

override fun onDetachedFromWindow() {
binding.checkbox.clearOnCheckedStateChangedListeners()
super.onDetachedFromWindow()
}

private fun updateForeground() {
binding.root.foreground = if(isClickable) {
val value = TypedValue()
Expand All @@ -138,6 +169,10 @@ class Card @JvmOverloads constructor(
onButtonClickListener = listener
}

fun setOnCheckChangedListener(listener: ((Boolean) -> Unit)?) {
onCheckChangedListener = listener
}

fun setOnCloseClickListener(listener: (() -> Unit)?) {
onCloseClickListener = listener
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/ic_twotone_privacy_tip_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillAlpha="0.3"
android:fillColor="@android:color/white"
android:pathData="M12,3.19L5,6.3V11c0,4.52 2.98,8.69 7,9.93c4.02,-1.23 7,-5.41 7,-9.93V6.3L12,3.19zM13,17h-2v-6h2V17zM13,9h-2V7h2V9z" android:strokeAlpha="0.3"/>
<path android:fillColor="@android:color/white" android:pathData="M12,3.19l7,3.11V11c0,4.52 -2.98,8.69 -7,9.93C7.98,19.69 5,15.52 5,11V6.3L12,3.19M12,1L3,5v6c0,5.55 3.84,10.74 9,12c5.16,-1.26 9,-6.45 9,-12V5L12,1L12,1zM11,7h2v2h-2V7zM11,11h2v6h-2V11z"/>
</vector>
14 changes: 14 additions & 0 deletions app/src/main/res/layout/onboarding_page5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<me.timschneeberger.rootlessjamesdsp.view.Card
android:id="@+id/privacy_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleText="@string/onboarding_perm_diag"
app:bodyText="@string/onboarding_perm_diag_caption"
app:iconCentered="true"
app:iconSrc="@drawable/ic_twotone_privacy_tip_24dp"
app:iconTint="?attr/colorOnSurface"
app:checkboxVisible="true"
app:cardMargin="8dp" />


<me.timschneeberger.rootlessjamesdsp.view.Card
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -55,6 +68,7 @@
app:iconTint="?attr/colorOnSurface"
app:cardMargin="8dp" />


<me.timschneeberger.rootlessjamesdsp.view.Card
android:id="@+id/onboarding_notification_permission"
android:layout_width="match_parent"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/view_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
android:contentDescription="@string/close"
android:tooltipText="@string/close"
app:icon="@drawable/ic_close_24dp" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/checkbox"
android:visibility="gone"
android:layout_width="48dp"
android:layout_height="48dp" />
<Space
android:layout_width="wrap_content"
android:layout_height="0dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<attr name="closeButtonVisible" format="boolean" />
<attr name="buttonText" format="string" />
<attr name="buttonEnabled" format="boolean" />
<attr name="checkboxVisible" format="boolean" />
<attr name="iconSrc" format="reference" />
<attr name="iconTint" />
<attr name="iconCentered" format="boolean" />
Expand Down

0 comments on commit b7ead7e

Please sign in to comment.