mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-21 05:09:00 +00:00
Add settings for email notifications
This commit is contained in:
parent
7bcc4062b4
commit
f8fe4d49e6
8 changed files with 202 additions and 9 deletions
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
<string name="pref_cds_header">Custom Day Start</string>
|
||||
|
||||
<string name="pref_push_notifications_checkbox">User Push Notifications</string>
|
||||
<string name="pref_push_notifications_checkbox">Use Push Notifications</string>
|
||||
<string name="push_notifications">Push Notifications</string>
|
||||
<string name="push_notifications_sum">Set your push notifications settings</string>
|
||||
<string name="preference_push_you_won_challenge">You won a Challenge!</string>
|
||||
|
|
@ -936,4 +936,9 @@
|
|||
<string name="learn_more">Learn more</string>
|
||||
<string name="purchase_from_timetravel_shop">You can purchase this customization from the Time Travelers shop</string>
|
||||
<string name="go_shopping">Go shopping</string>
|
||||
<string name="emails">Email Notifications</string>
|
||||
<string name="pref_emails_checkbox">Use Email Notifications</string>
|
||||
<string name="preference_email_subscription_reminder">Subscription Reminders</string>
|
||||
<string name="preference_email_kicked_group">Kicked from group</string>
|
||||
<string name="preference_email_onboarding">Guidance with setting up your Habitica Account</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -273,9 +273,88 @@
|
|||
android:title="@string/preference_push_unjoined_guild_mention"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/emails"
|
||||
android:layout="@layout/preference_category">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="useEmails"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/pref_emails_checkbox"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="emailNotifications"
|
||||
android:title="@string/emails"
|
||||
android:layout="@layout/preference_child_summary">
|
||||
|
||||
<PreferenceCategory android:title="@string/emails">
|
||||
<CheckBoxPreference
|
||||
android:key="preference_email_you_won_challenge"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/preference_push_you_won_challenge"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
<CheckBoxPreference
|
||||
android:key="preference_email_onboarding"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/preference_email_onboarding"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
<CheckBoxPreference
|
||||
android:key="preference_email_received_a_private_message"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/preference_push_received_a_private_message"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
<CheckBoxPreference
|
||||
android:key="preference_email_gifted_gems"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/preference_push_gifted_gems"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
<CheckBoxPreference
|
||||
android:key="preference_email_gifted_subscription"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/preference_push_gifted_subscription"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
<CheckBoxPreference
|
||||
android:key="preference_email_invited_to_party"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/preference_push_invited_to_party"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
<CheckBoxPreference
|
||||
android:key="preference_email_invited_to_guild"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/preference_push_invited_to_guild"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
<CheckBoxPreference
|
||||
android:key="preference_email_kicked_group"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/preference_email_kicked_group"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
<CheckBoxPreference
|
||||
android:key="preference_email_your_quest_has_begun"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/preference_push_your_quest_has_begun"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
<CheckBoxPreference
|
||||
android:key="preference_email_invited_to_quest"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/preference_push_invited_to_quest"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
<CheckBoxPreference
|
||||
android:key="preference_email_important_announcements"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/preference_push_important_announcements"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
<CheckBoxPreference
|
||||
android:key="preference_email_subscription_reminder"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/preference_email_subscription_reminder"
|
||||
android:layout="@layout/preference_child_summary"/>
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import com.habitrpg.android.habitica.ui.adapter.tasks.RewardsRecyclerViewAdapter
|
|||
import com.habitrpg.android.habitica.ui.adapter.tasks.TodosRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.AboutFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.AchievementsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.preferences.EmailNotificationsPreferencesFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.purchases.GemsPurchaseFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.NavigationDrawerFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.NewsFragment;
|
||||
|
|
@ -328,4 +329,6 @@ public interface UserComponent {
|
|||
void inject(@NotNull GiftPurchaseGemsFragment giftPurchaseGemsFragment);
|
||||
|
||||
void inject(@NotNull GiftBalanceGemsFragment giftBalanceGemsFragment);
|
||||
|
||||
void inject(@NotNull EmailNotificationsPreferencesFragment emailNotificationsPreferencesFragment);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package com.habitrpg.android.habitica.models.user
|
||||
|
||||
import io.realm.RealmObject
|
||||
|
||||
open class EmailNotificationsPreference : RealmObject() {
|
||||
var unsubscribeFromAll: Boolean = false
|
||||
var invitedParty: Boolean = false
|
||||
var invitedQuest: Boolean = false
|
||||
var majorUpdates: Boolean = false
|
||||
var wonChallenge: Boolean = false
|
||||
var invitedGuild: Boolean = false
|
||||
var newPM: Boolean = false
|
||||
var questStarted: Boolean = false
|
||||
var giftedGems: Boolean = false
|
||||
var giftedSubscription: Boolean = false
|
||||
var subscriptionReminders: Boolean = false
|
||||
var onboarding: Boolean = false
|
||||
var kickedGroup: Boolean = false
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ open class Preferences : RealmObject(), AvatarPreferences {
|
|||
var timezoneOffset: Int = 0
|
||||
var timezoneOffsetAtLastCron: Int = 0
|
||||
var pushNotifications: PushNotificationsPreference? = null
|
||||
var emailNotifications: EmailNotificationsPreference? = null
|
||||
var autoEquip: Boolean = true
|
||||
|
||||
override fun getBackground(): String? {
|
||||
|
|
|
|||
|
|
@ -5,11 +5,7 @@ import androidx.preference.PreferenceFragmentCompat
|
|||
import androidx.preference.PreferenceScreen
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.UserComponent
|
||||
import com.habitrpg.android.habitica.ui.fragments.preferences.APIPreferenceFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.preferences.AuthenticationPreferenceFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.preferences.PreferencesFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.preferences.ProfilePreferencesFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.preferences.PushNotificationsPreferencesFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.preferences.*
|
||||
import kotlinx.android.synthetic.main.activity_prefs.*
|
||||
|
||||
class PrefsActivity : BaseActivity(), PreferenceFragmentCompat.OnPreferenceStartScreenCallback {
|
||||
|
|
@ -60,6 +56,7 @@ class PrefsActivity : BaseActivity(), PreferenceFragmentCompat.OnPreferenceStart
|
|||
"authentication" -> AuthenticationPreferenceFragment()
|
||||
"api" -> APIPreferenceFragment()
|
||||
"pushNotifications" -> PushNotificationsPreferencesFragment()
|
||||
"emailNotifications" -> EmailNotificationsPreferencesFragment()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.preferences
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import androidx.preference.CheckBoxPreference
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import io.reactivex.functions.Consumer
|
||||
|
||||
class EmailNotificationsPreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private var isInitialSet: Boolean = true
|
||||
private var isSettingUser: Boolean = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
HabiticaBaseApplication.userComponent?.inject(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
preferenceScreen.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
|
||||
override fun setupPreferences() { /* no-on */ }
|
||||
|
||||
override fun setUser(user: User?) {
|
||||
super.setUser(user)
|
||||
isSettingUser = !isInitialSet
|
||||
updatePreference("preference_email_you_won_challenge", user?.preferences?.emailNotifications?.wonChallenge)
|
||||
updatePreference("preference_email_received_a_private_message", user?.preferences?.emailNotifications?.newPM)
|
||||
updatePreference("preference_email_gifted_gems", user?.preferences?.emailNotifications?.giftedGems)
|
||||
updatePreference("preference_email_gifted_subscription", user?.preferences?.emailNotifications?.giftedSubscription)
|
||||
updatePreference("preference_email_invited_to_party", user?.preferences?.emailNotifications?.invitedParty)
|
||||
updatePreference("preference_email_invited_to_guild", user?.preferences?.emailNotifications?.invitedGuild)
|
||||
updatePreference("preference_email_your_quest_has_begun", user?.preferences?.emailNotifications?.questStarted)
|
||||
updatePreference("preference_email_invited_to_quest", user?.preferences?.emailNotifications?.invitedQuest)
|
||||
updatePreference("preference_email_important_announcements", user?.preferences?.emailNotifications?.majorUpdates)
|
||||
updatePreference("preference_email_kicked_group", user?.preferences?.emailNotifications?.kickedGroup)
|
||||
updatePreference("preference_email_onboarding", user?.preferences?.emailNotifications?.onboarding)
|
||||
updatePreference("preference_email_subscription_reminders", user?.preferences?.emailNotifications?.subscriptionReminders)
|
||||
isSettingUser = false
|
||||
isInitialSet = false
|
||||
}
|
||||
|
||||
private fun updatePreference(key: String, isChecked: Boolean?) {
|
||||
val preference = (findPreference(key) as? CheckBoxPreference)
|
||||
preference?.isChecked = isChecked == true
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
|
||||
if (isSettingUser) {
|
||||
return
|
||||
}
|
||||
val pathKey = when (key) {
|
||||
"preference_email_you_won_challenge" -> "wonChallenge"
|
||||
"preference_email_received_a_private_message" -> "newPM"
|
||||
"preference_email_gifted_gems" -> "giftedGems"
|
||||
"preference_email_gifted_subscription" -> "giftedSubscription"
|
||||
"preference_email_invited_to_party" -> "invitedParty"
|
||||
"preference_email_invited_to_guild" -> "invitedGuild"
|
||||
"preference_email_your_quest_has_begun" -> "questStarted"
|
||||
"preference_email_invited_to_quest" -> "invitedQuest"
|
||||
"preference_email_important_announcements" -> "majorUpdates"
|
||||
"preference_email_kicked_group" -> "kickedGroup"
|
||||
"preference_email_onboarding" -> "onboarding"
|
||||
"preference_email_subscription_reminders" -> "subscriptionReminders"
|
||||
else -> null
|
||||
}
|
||||
if (pathKey != null) {
|
||||
compositeSubscription.add(userRepository.updateUser(user, "preferences.emailNotifications.$pathKey", sharedPreferences.getBoolean(key, false)).subscribe(Consumer { }, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -44,6 +44,7 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
|
|||
|
||||
private var timePreference: TimePreference? = null
|
||||
private var pushNotificationsPreference: PreferenceScreen? = null
|
||||
private var emailNotificationsPreference: PreferenceScreen? = null
|
||||
private var classSelectionPreference: Preference? = null
|
||||
private var serverUrlPreference: ListPreference? = null
|
||||
|
||||
|
|
@ -60,8 +61,12 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
|
|||
|
||||
|
||||
pushNotificationsPreference = findPreference("pushNotifications") as? PreferenceScreen
|
||||
val userPushNotifications = preferenceManager.sharedPreferences.getBoolean("usePushNotifications", true)
|
||||
pushNotificationsPreference?.isEnabled = userPushNotifications
|
||||
val usePushNotifications = preferenceManager.sharedPreferences.getBoolean("usePushNotifications", true)
|
||||
pushNotificationsPreference?.isEnabled = usePushNotifications
|
||||
|
||||
emailNotificationsPreference = findPreference("emailNotifications") as? PreferenceScreen
|
||||
val useEmailNotifications = preferenceManager.sharedPreferences.getBoolean("useEmailNotifications", true)
|
||||
emailNotificationsPreference?.isEnabled = useEmailNotifications
|
||||
|
||||
|
||||
classSelectionPreference = findPreference("choose_class")
|
||||
|
|
@ -161,6 +166,10 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
|
|||
pushNotificationManager.removePushDeviceUsingStoredToken()
|
||||
}
|
||||
}
|
||||
"useEmailNotifications" -> {
|
||||
val useEmailNotifications = sharedPreferences.getBoolean(key, false)
|
||||
emailNotificationsPreference?.isEnabled = useEmailNotifications
|
||||
}
|
||||
"cds_time" -> {
|
||||
val timeval = sharedPreferences.getString("cds_time", "00:00")
|
||||
val pieces = timeval?.split(":".toRegex())?.dropLastWhile { it.isEmpty() }?.toTypedArray()
|
||||
|
|
|
|||
Loading…
Reference in a new issue