mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-20 21:05:00 +00:00
Fix deprecations
This commit is contained in:
parent
75f6181cec
commit
6d4af9f934
9 changed files with 55 additions and 67 deletions
|
|
@ -150,7 +150,7 @@ android {
|
|||
buildConfigField "String", "TESTING_LEVEL", "\"production\""
|
||||
resConfigs "en", "bg", "de", "en-rGB", "es", "fr", "hr-rHR", "in", "it", "iw", "ja", "ko", "lt", "nl", "pl", "pt-rBR", "pt-rPT", "ru", "tr", "zh", "zh-rTW"
|
||||
|
||||
versionCode 2620
|
||||
versionCode 2623
|
||||
versionName "3.1"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import com.habitrpg.android.habitica.models.user.User
|
|||
import io.reactivex.rxjava3.core.Flowable
|
||||
import io.reactivex.rxjava3.core.Maybe
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmResults
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
|
@ -73,6 +72,7 @@ class TaskRepositoryImpl(localRepository: TaskLocalRepository, apiClient: ApiCli
|
|||
result.manaDelta = localData.mp - (stats?.mp ?: 0.0)
|
||||
result.goldDelta = localData.gp - (stats?.gp ?: 0.0)
|
||||
result.hasLeveledUp = localData.lvl > stats?.lvl ?: 0
|
||||
result.level = localData.lvl
|
||||
result.questDamage = localData._tmp?.quest?.progressDelta
|
||||
result.questItemsFound = localData._tmp?.quest?.collection
|
||||
result.drop = localData._tmp?.drop
|
||||
|
|
@ -106,6 +106,7 @@ class TaskRepositoryImpl(localRepository: TaskLocalRepository, apiClient: ApiCli
|
|||
result.manaDelta = res.mp - (stats?.mp ?: 0.0)
|
||||
result.goldDelta = res.gp - (stats?.gp ?: 0.0)
|
||||
result.hasLeveledUp = res.lvl > stats?.lvl ?: 0
|
||||
result.level = res.lvl
|
||||
result.questDamage = res._tmp?.quest?.progressDelta
|
||||
result.questItemsFound = res._tmp?.quest?.collection
|
||||
result.drop = res._tmp?.drop
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class SoundFileLoader(private val context: Context) {
|
|||
return cacheDir?.path
|
||||
}
|
||||
|
||||
@SuppressLint("SetWorldReadable", "ObsoleteSdkInt", "ReturnCount")
|
||||
@SuppressLint("SetWorldReadable", "ReturnCount")
|
||||
fun download(files: List<SoundFile>): Single<List<SoundFile>> {
|
||||
return Observable.fromIterable(files)
|
||||
.flatMap({ audioFile ->
|
||||
|
|
@ -51,22 +51,20 @@ class SoundFileLoader(private val context: Context) {
|
|||
return@create
|
||||
}
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
|
||||
try {
|
||||
val sink = file.sink().buffer()
|
||||
sink.writeAll(response.body!!.source())
|
||||
sink.flush()
|
||||
sink.close()
|
||||
} catch (io: IOException) {
|
||||
sub.onComplete()
|
||||
return@create
|
||||
}
|
||||
|
||||
file.setReadable(true, false)
|
||||
audioFile.file = file
|
||||
sub.onNext(audioFile)
|
||||
try {
|
||||
val sink = file.sink().buffer()
|
||||
sink.writeAll(response.body!!.source())
|
||||
sink.flush()
|
||||
sink.close()
|
||||
} catch (io: IOException) {
|
||||
sub.onComplete()
|
||||
return@create
|
||||
}
|
||||
|
||||
file.setReadable(true, false)
|
||||
audioFile.file = file
|
||||
sub.onNext(audioFile)
|
||||
sub.onComplete()
|
||||
}
|
||||
fileObservable.subscribeOn(Schedulers.io())
|
||||
}, 5)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.interactors
|
|||
import android.widget.ImageView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.databinding.DialogLevelup10Binding
|
||||
import com.habitrpg.android.habitica.events.ShareEvent
|
||||
import com.habitrpg.android.habitica.executors.PostExecutionThread
|
||||
import com.habitrpg.android.habitica.executors.ThreadExecutor
|
||||
|
|
@ -31,18 +32,16 @@ constructor(private val soundManager: SoundManager, threadExecutor: ThreadExecut
|
|||
return@defer Flowable.just<Stats>(requestValues.user.stats)
|
||||
}
|
||||
|
||||
if (requestValues.newLevel == 10) {
|
||||
val customView = requestValues.activity.layoutInflater.inflate(R.layout.dialog_levelup_10, null)
|
||||
if (customView != null) {
|
||||
customView.findViewById<ImageView>(R.id.healer_icon_view).setImageBitmap(HabiticaIconsHelper.imageOfHealerLightBg())
|
||||
customView.findViewById<ImageView>(R.id.mage_icon_view).setImageBitmap(HabiticaIconsHelper.imageOfMageLightBg())
|
||||
customView.findViewById<ImageView>(R.id.rogue_icon_view).setImageBitmap(HabiticaIconsHelper.imageOfRogueLightBg())
|
||||
customView.findViewById<ImageView>(R.id.warrior_icon_view).setImageBitmap(HabiticaIconsHelper.imageOfWarriorLightBg())
|
||||
}
|
||||
if (requestValues.newLevel == 10L) {
|
||||
val binding = DialogLevelup10Binding.inflate(requestValues.activity.layoutInflater)
|
||||
binding.healerIconView.setImageBitmap(HabiticaIconsHelper.imageOfHealerLightBg())
|
||||
binding.mageIconView.setImageBitmap(HabiticaIconsHelper.imageOfMageLightBg())
|
||||
binding.rogueIconView.setImageBitmap(HabiticaIconsHelper.imageOfRogueLightBg())
|
||||
binding.warriorIconView.setImageBitmap(HabiticaIconsHelper.imageOfWarriorLightBg())
|
||||
|
||||
val alert = HabiticaAlertDialog(requestValues.activity)
|
||||
alert.setTitle(requestValues.activity.getString(R.string.levelup_header, requestValues.newLevel))
|
||||
alert.setAdditionalContentView(customView)
|
||||
alert.setAdditionalContentView(binding.root)
|
||||
alert.addButton(R.string.select_class, true) { _, _ ->
|
||||
showClassSelection(requestValues)
|
||||
}
|
||||
|
|
@ -63,7 +62,7 @@ constructor(private val soundManager: SoundManager, threadExecutor: ThreadExecut
|
|||
event.sharedMessage = requestValues.activity.getString(R.string.share_levelup, requestValues.newLevel)
|
||||
val avatarView = AvatarView(requestValues.activity, showBackground = true, showMount = true, showPet = true)
|
||||
avatarView.setAvatar(requestValues.user)
|
||||
avatarView.onAvatarImageReady({ t -> event.shareImage = t })
|
||||
avatarView.onAvatarImageReady { t -> event.shareImage = t }
|
||||
|
||||
val alert = HabiticaAlertDialog(requestValues.activity)
|
||||
alert.setTitle(requestValues.activity.getString(R.string.levelup_header, requestValues.newLevel))
|
||||
|
|
@ -74,6 +73,7 @@ constructor(private val soundManager: SoundManager, threadExecutor: ThreadExecut
|
|||
alert.addButton(R.string.share, false) { _, _ ->
|
||||
EventBus.getDefault().post(event)
|
||||
}
|
||||
alert.isCelebratory = true
|
||||
|
||||
if (!requestValues.activity.isFinishing) {
|
||||
alert.enqueue()
|
||||
|
|
@ -89,7 +89,7 @@ constructor(private val soundManager: SoundManager, threadExecutor: ThreadExecut
|
|||
.subscribe({ }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
|
||||
class RequestValues(val user: User, val activity: AppCompatActivity) : UseCase.RequestValues {
|
||||
val newLevel: Int = (user.stats?.lvl ?: 0 )
|
||||
class RequestValues(val user: User, val level: Long?, val activity: AppCompatActivity) : UseCase.RequestValues {
|
||||
val newLevel: Long = level ?: 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ constructor(threadExecutor: ThreadExecutor, postExecutionThread: PostExecutionTh
|
|||
val stats = requestValues.user.stats
|
||||
|
||||
if (requestValues.hasLeveledUp == true) {
|
||||
return@defer levelUpUseCase.observable(LevelUpUseCase.RequestValues(requestValues.user, requestValues.context))
|
||||
return@defer levelUpUseCase.observable(LevelUpUseCase.RequestValues(requestValues.user, requestValues.level, requestValues.context))
|
||||
.flatMap { userRepository.retrieveUser(true) }
|
||||
.map { it.stats }
|
||||
} else {
|
||||
|
|
@ -53,7 +53,7 @@ constructor(threadExecutor: ThreadExecutor, postExecutionThread: PostExecutionTh
|
|||
}
|
||||
}
|
||||
|
||||
class RequestValues( val context: AppCompatActivity, val snackbarTargetView: ViewGroup, val user: User?, val xp: Double?, val hp: Double?, val gold: Double?, val mp: Double?, val questDamage: Double?, val hasLeveledUp: Boolean?) : UseCase.RequestValues
|
||||
class RequestValues( val context: AppCompatActivity, val snackbarTargetView: ViewGroup, val user: User?, val xp: Double?, val hp: Double?, val gold: Double?, val mp: Double?, val questDamage: Double?, val hasLeveledUp: Boolean?, val level: Long?) : UseCase.RequestValues
|
||||
|
||||
companion object {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.habitrpg.android.habitica.models.responses
|
||||
|
||||
class TaskScoringResult {
|
||||
class TaskScoringResult() {
|
||||
|
||||
var drop: TaskDirectionDataDrop? = null
|
||||
var experienceDelta: Double? = null
|
||||
|
|
@ -8,6 +8,7 @@ class TaskScoringResult {
|
|||
var goldDelta: Double? = null
|
||||
var manaDelta: Double? = null
|
||||
var hasLeveledUp: Boolean = false
|
||||
var level: Long? = null
|
||||
var questDamage: Double? = null
|
||||
var questItemsFound: Int? = null
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,7 +156,6 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
|
||||
private var launchTrace: com.google.firebase.perf.metrics.Trace? = null
|
||||
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
try {
|
||||
launchTrace = FirebasePerformance.getInstance().newTrace("MainActivityLaunch")
|
||||
|
|
@ -182,9 +181,9 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
this@MainActivity.user = newUser
|
||||
this@MainActivity.setUserData()
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
compositeSubscription.add(userRepository.getUserQuestStatus().subscribeWithErrorHandler(Consumer {
|
||||
compositeSubscription.add(userRepository.getUserQuestStatus().subscribeWithErrorHandler {
|
||||
userQuestStatus = it
|
||||
}))
|
||||
})
|
||||
|
||||
val viewModel = ViewModelProvider(this).get(NotificationsViewModel::class.java)
|
||||
notificationsViewModel = viewModel
|
||||
|
|
@ -540,8 +539,8 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
else -> 0.0
|
||||
}
|
||||
compositeSubscription.add(notifyUserUseCase.observable(NotifyUserUseCase.RequestValues(this, snackbarContainer,
|
||||
user, data.experienceDelta, data.healthDelta, data.goldDelta, data.manaDelta, damageValue, data.hasLeveledUp))
|
||||
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError()))
|
||||
user, data.experienceDelta, data.healthDelta, data.goldDelta, data.manaDelta, damageValue, data.hasLeveledUp, data.level))
|
||||
.subscribe({ }, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
||||
val showItemsFound = when (userQuestStatus) {
|
||||
|
|
@ -549,7 +548,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
else -> false
|
||||
}
|
||||
compositeSubscription.add(displayItemDropUseCase.observable(DisplayItemDropUseCase.RequestValues(data, this, snackbarContainer, showItemsFound))
|
||||
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError()))
|
||||
.subscribe({ }, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.preferences
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.ProgressDialog
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Configuration
|
||||
|
|
@ -17,6 +16,7 @@ import com.habitrpg.android.habitica.HabiticaBaseApplication
|
|||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.data.ApiClient
|
||||
import com.habitrpg.android.habitica.data.ContentRepository
|
||||
import com.habitrpg.android.habitica.events.ShowSnackbarEvent
|
||||
import com.habitrpg.android.habitica.helpers.*
|
||||
import com.habitrpg.android.habitica.helpers.notifications.PushNotificationManager
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
|
|
@ -25,6 +25,8 @@ import com.habitrpg.android.habitica.ui.activities.ClassSelectionActivity
|
|||
import com.habitrpg.android.habitica.ui.activities.FixCharacterValuesActivity
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity
|
||||
import com.habitrpg.android.habitica.ui.activities.PrefsActivity
|
||||
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -126,18 +128,12 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
|
|||
return true
|
||||
}
|
||||
"reload_content" -> {
|
||||
@Suppress("DEPRECATION")
|
||||
val dialog = ProgressDialog.show(context, context?.getString(R.string.reloading_content), null, true)
|
||||
val event = ShowSnackbarEvent()
|
||||
event.text = context?.getString(R.string.reloading_content)
|
||||
event.type = HabiticaSnackbar.SnackbarDisplayType.NORMAL
|
||||
EventBus.getDefault().post(event)
|
||||
contentRepository.retrieveContent(context,true).subscribe({
|
||||
if (dialog.isShowing) {
|
||||
dialog.dismiss()
|
||||
}
|
||||
}) { throwable ->
|
||||
if (dialog.isShowing) {
|
||||
dialog.dismiss()
|
||||
}
|
||||
RxErrorHandler.reportError(throwable)
|
||||
}
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
"fixCharacterValues" -> {
|
||||
val intent = Intent(activity, FixCharacterValuesActivity::class.java)
|
||||
|
|
@ -148,7 +144,6 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
|
|||
}
|
||||
|
||||
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
|
||||
when (key) {
|
||||
"use_reminder" -> {
|
||||
|
|
@ -190,27 +185,21 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
|
|||
|
||||
Locale.setDefault(languageHelper.locale)
|
||||
val configuration = Configuration()
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
@Suppress("Deprecation")
|
||||
configuration.locale = languageHelper.locale
|
||||
} else {
|
||||
configuration.setLocale(languageHelper.locale)
|
||||
}
|
||||
configuration.setLocale(languageHelper.locale)
|
||||
@Suppress("DEPRECATION")
|
||||
activity?.resources?.updateConfiguration(configuration, activity?.resources?.displayMetrics)
|
||||
|
||||
if (user?.preferences?.language == languageHelper.languageCode) {
|
||||
return
|
||||
}
|
||||
|
||||
userRepository.updateLanguage(user, languageHelper.languageCode ?: "en")
|
||||
.flatMap { contentRepository.retrieveContent(context,true) }
|
||||
.subscribe({ }, RxErrorHandler.handleEmptyError())
|
||||
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
|
||||
val intent = Intent(activity, MainActivity::class.java)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
startActivity(intent)
|
||||
} else {
|
||||
val intent = Intent(activity, MainActivity::class.java)
|
||||
this.startActivity(intent)
|
||||
activity?.finishAffinity()
|
||||
}
|
||||
val intent = Intent(activity, MainActivity::class.java)
|
||||
this.startActivity(intent)
|
||||
activity?.finishAffinity()
|
||||
}
|
||||
"audioTheme" -> {
|
||||
val newAudioTheme = sharedPreferences.getString(key, "off")
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class WorldStateSerialization: JsonDeserializer<WorldState> {
|
|||
}
|
||||
}
|
||||
|
||||
if (json?.asJsonObject?.has("currentEvent") == true) {
|
||||
if (json?.asJsonObject?.has("currentEvent") == true && json.asJsonObject?.get("currentEvent")?.isJsonObject == true) {
|
||||
val event = json.asJsonObject?.getAsJsonObject("currentEvent")
|
||||
if (event != null) {
|
||||
state.currentEventKey = event.getAsString("event")
|
||||
|
|
|
|||
Loading…
Reference in a new issue