Various fixes

This commit is contained in:
Phillip Thelen 2019-01-10 14:04:49 +01:00
parent def26be822
commit af187debc4
34 changed files with 136 additions and 26 deletions

View file

@ -148,7 +148,7 @@ android {
buildConfigField "String", "STORE", "\"google\""
multiDexEnabled true
versionCode 2058
versionCode 2063
versionName "1.7"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

View file

@ -121,7 +121,7 @@
android:id="@+id/gift_subscription_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/blue_50"
android:background="@color/teal_50"
android:padding="@dimen/spacing_large"
android:gravity="center_horizontal"
android:orientation="vertical">

View file

@ -17,7 +17,7 @@
android:id="@+id/gift_subscription_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/blue_50">
android:background="@color/teal_50">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -853,9 +853,10 @@
<string name="send_gift">Send Gift</string>
<string name="server">Server</string>
<string name="gift_confirmation_title">Your gift was sent!</string>
<string name="gift_confirmation_text_g1g1">Your gifted subscription was sent and your subscription applied to your account.</string>
<string name="gift_confirmation_text">Your gifted subscription was sent and your subscription applied to your account.</string>
<string name="gift_confirmation_text_g1g1">You sent %s a %s-month Habitica subscription and the same subscription was applied to your account for our Gift One Get One promotion!</string>
<string name="gift_confirmation_text">You sent %s a %s-month Habitica subscription.</string>
<string name="discover">Discover</string>
<string name="damage_paused">Damage paused</string>
<string name="preference_push_important_announcements">Important Announcements</string>
</resources>

View file

@ -233,6 +233,11 @@
android:title="@string/preference_push_invited_to_quest"
android:layout="@layout/preference_child_summary"/>
<CheckBoxPreference
android:key="preference_push_important_announcements"
android:defaultValue="true"
android:title="@string/preference_push_important_announcements"
android:layout="@layout/preference_child_summary"/>
</PreferenceCategory>

View file

@ -17,14 +17,25 @@ class TagRepositoryImpl(localRepository: TagLocalRepository, apiClient: ApiClien
override fun createTag(tag: Tag): Flowable<Tag> {
return apiClient.createTag(tag)
.doOnNext {
it.userId = userID
localRepository.save(it)
}
}
override fun updateTag(tag: Tag): Flowable<Tag> {
return apiClient.updateTag(tag.id, tag)
.doOnNext {
it.userId = userID
localRepository.save(it)
}
}
override fun deleteTag(id: String): Flowable<Void> {
return apiClient.deleteTag(id)
.doOnNext {
localRepository.deleteTag(id)
}
}
override fun createTags(tags: Collection<Tag>): Single<List<Tag>> {

View file

@ -9,4 +9,5 @@ interface TagLocalRepository : BaseLocalRepository {
fun getTags(userId: String): Flowable<RealmResults<Tag>>
fun removeOldTags(onlineTags: List<Tag>, userID: String)
fun deleteTag(tagID: String)
}

View file

@ -8,6 +8,10 @@ import io.realm.RealmResults
class RealmTagLocalRepository(realm: Realm) : RealmBaseLocalRepository(realm), TagLocalRepository {
override fun deleteTag(tagID: String) {
val tag = realm.where(Tag::class.java).equalTo("id", tagID).findFirst()
realm.executeTransaction { tag?.deleteFromRealm() }
}
override fun getTags(userId: String): Flowable<RealmResults<Tag>> {
return realm.where(Tag::class.java).equalTo("userId", userId).findAll().asFlowable()

View file

@ -1,19 +1,10 @@
package com.habitrpg.android.habitica.helpers
import android.content.Intent
import android.os.Bundle
import androidx.core.os.bundleOf
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.helpers.notifications.PushNotificationManager
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.ui.activities.MainActivity
import com.habitrpg.android.habitica.ui.activities.PrefsActivity
import com.habitrpg.android.habitica.ui.fragments.NavigationDrawerFragment
import com.habitrpg.android.habitica.ui.fragments.preferences.PreferencesFragment
import com.habitrpg.android.habitica.ui.fragments.preferences.PreferencesFragment_MembersInjector
import com.habitrpg.android.habitica.ui.fragments.social.GuildFragment
import com.habitrpg.android.habitica.ui.fragments.social.InboxFragment
import com.habitrpg.android.habitica.ui.fragments.social.QuestDetailFragment
class NotificationOpenHandler {
@ -29,9 +20,14 @@ class NotificationOpenHandler {
PushNotificationManager.GUILD_INVITE_PUSH_NOTIFICATION_KEY -> openGuildDetailScreen(intent.getStringExtra("groupID"))
PushNotificationManager.RECEIVED_PRIVATE_MESSAGE_PUSH_NOTIFICATION_KEY -> openPrivateMessageScreen(intent.getStringExtra("replyTo"))
PushNotificationManager.CHANGE_USERNAME_PUSH_NOTIFICATION_KEY -> openSettingsScreen()
PushNotificationManager.GIFT_ONE_GET_ONE_PUSH_NOTIFICATION_KEY -> openSubscriptionScreen()
}
}
private fun openSubscriptionScreen() {
MainNavigationController.navigate(R.id.gemPurchaseActivity)
}
private fun openPrivateMessageScreen(userID: String?) {
if (userID?.isNotEmpty() == true) {
return

View file

@ -0,0 +1,6 @@
package com.habitrpg.android.habitica.helpers.notifications
import android.content.Context
class GiftOneGetOneLocalNotification(context: Context, identifier: String) : HabiticaLocalNotification(context, identifier) {
}

View file

@ -27,6 +27,8 @@ public class HabiticaLocalNotificationFactory {
return new WonChallengeLocalNotification(context, notificationType);
} else if (notificationType.contains(PushNotificationManager.CHANGE_USERNAME_PUSH_NOTIFICATION_KEY)) {
return new ChangeUsernameLocalNotification(context, notificationType);
} else if (notificationType.contains(PushNotificationManager.GIFT_ONE_GET_ONE_PUSH_NOTIFICATION_KEY)) {
return new GiftOneGetOneLocalNotification(context, notificationType);
} else {
return new GenericLocalNotification(context, notificationType);
}

View file

@ -120,6 +120,7 @@ class PushNotificationManager(var apiClient: ApiClient, private val sharedPrefer
const val QUEST_BEGUN_PUSH_NOTIFICATION_KEY = "questStarted"
const val WON_CHALLENGE_PUSH_NOTIFICATION_KEY = "wonChallenge"
const val CHANGE_USERNAME_PUSH_NOTIFICATION_KEY = "changeUsername"
const val GIFT_ONE_GET_ONE_PUSH_NOTIFICATION_KEY = "gift1get1"
private const val DEVICE_TOKEN_PREFERENCE_KEY = "device-token-preference"
}
}

View file

@ -31,6 +31,7 @@ open class Preferences : RealmObject(), AvatarPreferences {
var sound: String? = null
var dayStart: Int = 0
var timezoneOffset: Int = 0
var pushNotifications: PushNotificationsPreference? = null
override fun getBackground(): String? {
return background

View file

@ -0,0 +1,16 @@
package com.habitrpg.android.habitica.models.user
import io.realm.RealmObject
open class PushNotificationsPreference : 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
}

View file

@ -58,7 +58,7 @@ class GemPurchaseActivity : BaseActivity(), InAppMessageListener {
activityCheckout?.onActivityResult(requestCode, resultCode, data)
}
private var showSubscriptionPageFirst = false
private var showSubscriptionPageFirst = true
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

View file

@ -233,6 +233,9 @@ class GiftIAPActivity: BaseActivity() {
}
private fun purchaseSubscription(sku: Sku) {
if (giftedUserID?.isNotEmpty() != true) {
return
}
activityCheckout.notNull {
HabiticaPurchaseVerifier.pendingGifts[sku.id.code] = giftedUserID
billingRequests?.purchase(ProductTypes.IN_APP, sku.id.code, null, it.purchaseFlow)
@ -248,10 +251,25 @@ class GiftIAPActivity: BaseActivity() {
}
}
private fun selectedDurationString(): String {
return when (selectedSubscriptionSku?.id?.code) {
PurchaseTypes.Subscription1MonthNoRenew -> "1"
PurchaseTypes.Subscription3MonthNoRenew -> "3"
PurchaseTypes.Subscription6MonthNoRenew -> "6"
PurchaseTypes.Subscription12MonthNoRenew -> "12"
else -> ""
}
}
private fun displayConfirmationDialog() {
val message = getString(if (remoteConfigManager.enableGiftOneGetOne()){
R.string.gift_confirmation_text_g1g1
} else {
R.string.gift_confirmation_text
}, giftedUsername, selectedDurationString())
AlertDialog.Builder(this)
.setTitle(R.string.gift_confirmation_title)
.setMessage(if (remoteConfigManager.enableGiftOneGetOne()) R.string.gift_confirmation_text_g1g1 else R.string.gift_confirmation_text)
.setMessage(message)
.setPositiveButton(android.R.string.ok) { dialog, _ ->
dialog.dismiss()
finish()

View file

@ -26,9 +26,10 @@ abstract class BasePreferencesFragment : PreferenceFragmentCompat() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
compositeSubscription.add(userRepository.getUser(userId).subscribe(Consumer<User> {
this.user = it
}, RxErrorHandler.handleEmptyError()))
val userID = preferenceManager.sharedPreferences.getString(context?.getString(R.string.SP_userID), null)
if (userID != null) {
compositeSubscription.add(userRepository.getUser(userID).subscribe(Consumer { this.setUser(it) }, RxErrorHandler.handleEmptyError()))
}
}
override fun onDestroy() {
@ -44,4 +45,7 @@ abstract class BasePreferencesFragment : PreferenceFragmentCompat() {
protected abstract fun setupPreferences()
open fun setUser(user: User?) {
this.user = user
}
}

View file

@ -50,10 +50,6 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
HabiticaBaseApplication.component?.inject(this)
super.onCreate(savedInstanceState)
val userID = preferenceManager.sharedPreferences.getString(context?.getString(R.string.SP_userID), null)
if (userID != null) {
compositeSubscription.add(userRepository.getUser(userID).subscribe(Consumer { this@PreferencesFragment.setUser(it) }, RxErrorHandler.handleEmptyError()))
}
}
override fun setupPreferences() {
@ -240,8 +236,8 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
}
}
fun setUser(user: User?) {
this.user = user
override fun setUser(user: User?) {
super.setUser(user)
if (10 <= user?.stats?.lvl ?: 0) {
if (user?.flags?.classSelected == true) {
if (user.preferences?.disableClasses == true) {

View file

@ -2,7 +2,11 @@ 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 PushNotificationsPreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnSharedPreferenceChangeListener {
@ -11,11 +15,53 @@ class PushNotificationsPreferencesFragment : BasePreferencesFragment(), SharedPr
super.onCreate(savedInstanceState)
}
override fun onResume() {
super.onResume()
preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this)
}
override fun onPause() {
super.onPause()
preferenceScreen.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
}
override fun setupPreferences() {
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
override fun setUser(user: User?) {
super.setUser(user)
updatePreference("preference_push_you_won_challenge", user?.preferences?.pushNotifications?.wonChallenge)
updatePreference("preference_push_received_a_private_message", user?.preferences?.pushNotifications?.newPM)
updatePreference("preference_push_gifted_gems", user?.preferences?.pushNotifications?.giftedGems)
updatePreference("preference_push_gifted_subscription", user?.preferences?.pushNotifications?.giftedSubscription)
updatePreference("preference_push_invited_to_party", user?.preferences?.pushNotifications?.invitedParty)
updatePreference("preference_push_invited_to_guild", user?.preferences?.pushNotifications?.invitedGuild)
updatePreference("preference_push_your_quest_has_begun", user?.preferences?.pushNotifications?.questStarted)
updatePreference("preference_push_invited_to_quest", user?.preferences?.pushNotifications?.invitedQuest)
updatePreference("preference_push_important_announcements", user?.preferences?.pushNotifications?.majorUpdates)
}
private fun updatePreference(key: String, isChecked: Boolean?) {
val preference = (findPreference(key) as? CheckBoxPreference)
preference?.isChecked = isChecked == true
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
val pathKey = when (key) {
"preference_push_you_won_challenge" -> "wonChallenge"
"preference_push_received_a_private_message" -> "newPM"
"preference_push_gifted_gems" -> "giftedGems"
"preference_push_gifted_subscription" -> "giftedSubscription"
"preference_push_invited_to_party" -> "invitedParty"
"preference_push_invited_to_guild" -> "invitedGuild"
"preference_push_your_quest_has_begun" -> "questStarted"
"preference_push_invited_to_quest" -> "invitedQuest"
"preference_push_important_announcements" -> "majorUpdates"
else -> null
}
if (pathKey != null) {
compositeSubscription.add(userRepository.updateUser(user, "preferences.pushNotifications.$pathKey", sharedPreferences.getBoolean(key, false)).subscribe(Consumer { }, RxErrorHandler.handleEmptyError()))
}
}
}

View file

@ -1 +1,3 @@
This update brings a new navigation architecture, which is the groundwork for additional features like in-app linking and deep links. If there are any views that do not open correctly anymore or any new issues that seem releated to navigation, please let us know.
This update also has a new way to load challenge data, so please test that the challenge list still displays.