Skip to content

Commit

Permalink
Implement Crash reporting on/off preference
Browse files Browse the repository at this point in the history
  • Loading branch information
tuancoltech committed Dec 30, 2024
1 parent 806d9e4 commit cca30cb
Show file tree
Hide file tree
Showing 12 changed files with 505 additions and 350 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package dev.arkbuilders.arkmemo.ui.fragments

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import by.kirich1409.viewbindingdelegate.viewBinding
import dev.arkbuilders.arkmemo.BuildConfig
import dev.arkbuilders.arkmemo.R
import dev.arkbuilders.arkmemo.databinding.FragmentAboutBinding
import dev.arkbuilders.arkmemo.ui.dialogs.CommonActionDialog
import dev.arkbuilders.arkmemo.ui.dialogs.DonateDialog
import dev.arkbuilders.arkmemo.utils.gone
import dev.arkbuilders.arkmemo.utils.openLink
import dev.arkbuilders.arkmemo.utils.visible

open class AboutFragment : Fragment(R.layout.fragment_about) {
val binding by viewBinding(FragmentAboutBinding::bind)

override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)

binding.toolbarCustom.ivBack.setOnClickListener {
activity?.onBackPressedDispatcher?.onBackPressed()
}
binding.toolbarCustom.tvTitle.text = getString(R.string.about)
binding.toolbarCustom.tvTitle.visible()

binding.toolbarCustom.tvRightActionText.gone()
binding.toolbarCustom.ivRightActionIcon.gone()

binding.tvAppVersion.text = getString(R.string.setting_app_version, BuildConfig.VERSION_NAME)

initSettingActions()
}

private fun initSettingActions() {
binding.tvWebsite.setOnClickListener {
context?.openLink("https://www.ark-builders.dev/")
}

binding.tvTelegram.setOnClickListener {
context?.openLink("https://t.me/ark_builders")
}

binding.tvDiscord.setOnClickListener {
context?.openLink("https://discord.gg/tPUJTxud")
}

binding.tvDonatePatreon.setOnClickListener {
context?.openLink("https://www.patreon.com/ARKBuilders")
}

binding.tvDonateCoffee.setOnClickListener {
context?.openLink("https://buymeacoffee.com/arkbuilders")
}

binding.tvDonateBtc.setOnClickListener {
DonateDialog(
walletAddress = "bc1qx8n9r4uwpgrhgnamt2uew53lmrxd8tuevp7lv5",
title = getString(R.string.setting_donate_btc),
onPositiveClick = {
},
).show(childFragmentManager, CommonActionDialog.TAG)
}

binding.tvDonateEth.setOnClickListener {
DonateDialog(
walletAddress = "0x9765C5aC38175BFbd2dC7a840b63e50762B80a1b",
title = getString(R.string.setting_donate_eth),
onPositiveClick = {
},
).show(childFragmentManager, CommonActionDialog.TAG)
}

binding.tvDiscoverIssues.setOnClickListener {
context?.openLink("https://www.ark-builders.dev/contribute/?tab=goodFirstIssue")
}

binding.tvBounties.setOnClickListener {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import dagger.hilt.android.AndroidEntryPoint
import dev.arkbuilders.arkmemo.BuildConfig
import dev.arkbuilders.arkmemo.R
import dev.arkbuilders.arkmemo.databinding.FragmentHomeBinding
import dev.arkbuilders.arkmemo.models.Note
Expand Down Expand Up @@ -156,13 +157,25 @@ class NotesFragment : BaseFragment() {
super.onViewCreated(view, savedInstanceState)
activity.title = getString(R.string.app_name)
activity.supportActionBar?.setDisplayHomeAsUpEnabled(false)
binding.ivSettings.setOnClickListener {
binding.ivAbout.setOnClickListener {
if (!checkForStorageExistence()) {
return@setOnClickListener
}
activity.fragment = AboutFragment()
activity.replaceFragment(activity.fragment, AboutFragment::class.java.name)
}

if (BuildConfig.FLAVOR == "github") {
binding.ivSettings.visible()
} else {
binding.ivSettings.gone()
}

binding.ivSettings.setOnClickListener {
activity.fragment = SettingsFragment()
activity.replaceFragment(activity.fragment, SettingsFragment::class.java.name)
}

showingFloatingButtons = false
initBottomControlViews()
initEmptyStateViews()
Expand Down Expand Up @@ -448,14 +461,14 @@ class NotesFragment : BaseFragment() {
binding.groupActionModeTexts.gone()
binding.layoutBottomControl.visible()
binding.edtSearch.visible()
binding.ivSettings.visible()
binding.ivAbout.visible()
notesAdapter?.toggleSelectAllItems(false)
} else {
binding.groupActionModeTexts.visible()
updateSelectStateTexts(selectedCountForDelete)
binding.layoutBottomControl.gone()
binding.edtSearch.gone()
binding.ivSettings.gone()
binding.ivAbout.gone()
binding.tvActionModeCancel.setOnClickListener {
toggleActionMode()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ package dev.arkbuilders.arkmemo.ui.fragments
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import by.kirich1409.viewbindingdelegate.viewBinding
import dev.arkbuilders.arkmemo.BuildConfig
import com.google.firebase.crashlytics.FirebaseCrashlytics
import dagger.hilt.android.AndroidEntryPoint
import dev.arkbuilders.arkmemo.R
import dev.arkbuilders.arkmemo.databinding.FragmentSettingsBinding
import dev.arkbuilders.arkmemo.ui.dialogs.CommonActionDialog
import dev.arkbuilders.arkmemo.ui.dialogs.DonateDialog
import dev.arkbuilders.arkmemo.ui.viewmodels.SettingsViewModel
import dev.arkbuilders.arkmemo.utils.gone
import dev.arkbuilders.arkmemo.utils.openLink
import dev.arkbuilders.arkmemo.utils.visible

@AndroidEntryPoint
open class SettingsFragment : Fragment(R.layout.fragment_settings) {
val binding by viewBinding(FragmentSettingsBinding::bind)
private val settingsViewModel: SettingsViewModel by activityViewModels()

override fun onViewCreated(
view: View,
Expand All @@ -25,61 +27,20 @@ open class SettingsFragment : Fragment(R.layout.fragment_settings) {
binding.toolbarCustom.ivBack.setOnClickListener {
activity?.onBackPressedDispatcher?.onBackPressed()
}
binding.toolbarCustom.tvTitle.text = getString(R.string.about)
binding.toolbarCustom.tvTitle.text = getString(R.string.settings)
binding.toolbarCustom.tvTitle.visible()

binding.toolbarCustom.tvRightActionText.gone()
binding.toolbarCustom.ivRightActionIcon.gone()

binding.tvAppVersion.text = getString(R.string.setting_app_version, BuildConfig.VERSION_NAME)

initSettingActions()
}

private fun initSettingActions() {
binding.tvWebsite.setOnClickListener {
context?.openLink("https://www.ark-builders.dev/")
}

binding.tvTelegram.setOnClickListener {
context?.openLink("https://t.me/ark_builders")
}

binding.tvDiscord.setOnClickListener {
context?.openLink("https://discord.gg/tPUJTxud")
}

binding.tvDonatePatreon.setOnClickListener {
context?.openLink("https://www.patreon.com/ARKBuilders")
}

binding.tvDonateCoffee.setOnClickListener {
context?.openLink("https://buymeacoffee.com/arkbuilders")
}

binding.tvDonateBtc.setOnClickListener {
DonateDialog(
walletAddress = "bc1qx8n9r4uwpgrhgnamt2uew53lmrxd8tuevp7lv5",
title = getString(R.string.setting_donate_btc),
onPositiveClick = {
},
).show(childFragmentManager, CommonActionDialog.TAG)
}

binding.tvDonateEth.setOnClickListener {
DonateDialog(
walletAddress = "0x9765C5aC38175BFbd2dC7a840b63e50762B80a1b",
title = getString(R.string.setting_donate_eth),
onPositiveClick = {
},
).show(childFragmentManager, CommonActionDialog.TAG)
}

binding.tvDiscoverIssues.setOnClickListener {
context?.openLink("https://www.ark-builders.dev/contribute/?tab=goodFirstIssue")
}

binding.tvBounties.setOnClickListener {
binding.tvCrashReport.setSwitchChecked(settingsViewModel.getCrashReportEnabled())
binding.tvCrashReport.onSwitchCheckChanged = { isChecked ->
FirebaseCrashlytics.getInstance().isCrashlyticsCollectionEnabled = isChecked
settingsViewModel.storeCrashReportEnabled(isChecked)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dev.arkbuilders.arkmemo.ui.viewmodels

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.arkbuilders.arkmemo.preferences.MemoPreferences
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class SettingsViewModel
@Inject
constructor(
private val memoPreferences: MemoPreferences,
) : ViewModel() {
fun storeCrashReportEnabled(enabled: Boolean) {
viewModelScope.launch {
memoPreferences.storeCrashReportEnabled(enabled)
}
}

fun getCrashReportEnabled(): Boolean {
return memoPreferences.getCrashReportEnabled()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ class SettingTextView
@JvmOverloads
constructor(context: Context, attrs: AttributeSet? = null) :
ConstraintLayout(context, attrs) {
private var binding: LayoutSettingTextBinding
var onSwitchCheckChanged: ((isChecked: Boolean) -> Unit)? = null

init {
val binding = LayoutSettingTextBinding.inflate(LayoutInflater.from(context), this, true)
binding = LayoutSettingTextBinding.inflate(LayoutInflater.from(context), this, true)
val typedArray: TypedArray =
context.obtainStyledAttributes(attrs, R.styleable.SettingTextView)
val textResId = typedArray.getText(R.styleable.SettingTextView_stv_text)
val iconResId = typedArray.getResourceId(R.styleable.SettingTextView_stv_icon, 0)
val enableSwitch =
typedArray.getBoolean(R.styleable.SettingTextView_stv_switch_on, false)
val switchChecked = typedArray.getBoolean(R.styleable.SettingTextView_stv_switch_checked, false)
textResId?.let {
binding.tvText.text = textResId
}
Expand All @@ -32,6 +36,22 @@ class SettingTextView
binding.switchRight.gone()
}

binding.switchRight.isChecked = switchChecked
binding.switchRight.setOnCheckedChangeListener(
object : SwitchButton.OnCheckedChangeListener {
override fun onCheckedChanged(
view: SwitchButton?,
isChecked: Boolean,
) {
onSwitchCheckChanged?.invoke(isChecked)
}
},
)

typedArray.recycle()
}

fun setSwitchChecked(checked: Boolean) {
binding.switchRight.isChecked = checked
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_crash_report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M20,8h-2.81c-0.45,-0.78 -1.07,-1.45 -1.82,-1.96L17,4.41 15.59,3l-2.17,2.17C12.96,5.06 12.49,5 12,5c-0.49,0 -0.96,0.06 -1.41,0.17L8.41,3 7,4.41l1.62,1.63C7.88,6.55 7.26,7.22 6.81,8L4,8v2h2.09c-0.05,0.33 -0.09,0.66 -0.09,1v1L4,12v2h2v1c0,0.34 0.04,0.67 0.09,1L4,16v2h2.81c1.04,1.79 2.97,3 5.19,3s4.15,-1.21 5.19,-3L20,18v-2h-2.09c0.05,-0.33 0.09,-0.66 0.09,-1v-1h2v-2h-2v-1c0,-0.34 -0.04,-0.67 -0.09,-1L20,10L20,8zM14,16h-4v-2h4v2zM14,12h-4v-2h4v2z"/>

</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M22.7,19l-9.1,-9.1c0.9,-2.3 0.4,-5 -1.5,-6.9 -2,-2 -5,-2.4 -7.4,-1.3L9,6 6,9 1.6,4.7C0.4,7.1 0.9,10.1 2.9,12.1c1.9,1.9 4.6,2.4 6.9,1.5l9.1,9.1c0.4,0.4 1,0.4 1.4,0l2.3,-2.3c0.5,-0.4 0.5,-1.1 0.1,-1.4z"/>

</vector>
Loading

0 comments on commit cca30cb

Please sign in to comment.