mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 11:46:32 +00:00
fix various code smell issues
This commit is contained in:
parent
62f03a9888
commit
12ca9c4b17
47 changed files with 335 additions and 370 deletions
|
|
@ -4,9 +4,7 @@ import android.content.Context
|
|||
import android.support.v7.app.AlertDialog
|
||||
import android.util.Log
|
||||
import com.amplitude.api.Amplitude
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.JsonSyntaxException
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.habitrpg.android.habitica.BuildConfig
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
import com.habitrpg.android.habitica.R
|
||||
|
|
@ -22,7 +20,8 @@ import com.habitrpg.android.habitica.models.auth.UserAuth
|
|||
import com.habitrpg.android.habitica.models.auth.UserAuthResponse
|
||||
import com.habitrpg.android.habitica.models.auth.UserAuthSocial
|
||||
import com.habitrpg.android.habitica.models.auth.UserAuthSocialTokens
|
||||
import com.habitrpg.android.habitica.models.inventory.*
|
||||
import com.habitrpg.android.habitica.models.inventory.Equipment
|
||||
import com.habitrpg.android.habitica.models.inventory.Quest
|
||||
import com.habitrpg.android.habitica.models.members.Member
|
||||
import com.habitrpg.android.habitica.models.responses.*
|
||||
import com.habitrpg.android.habitica.models.shops.Shop
|
||||
|
|
@ -33,18 +32,15 @@ import com.habitrpg.android.habitica.models.social.Group
|
|||
import com.habitrpg.android.habitica.models.tasks.Task
|
||||
import com.habitrpg.android.habitica.models.tasks.TaskList
|
||||
import com.habitrpg.android.habitica.models.user.Items
|
||||
import com.habitrpg.android.habitica.models.user.Purchases
|
||||
import com.habitrpg.android.habitica.models.user.Stats
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import com.habitrpg.android.habitica.proxy.CrashlyticsProxy
|
||||
import com.habitrpg.android.habitica.utils.*
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.FlowableTransformer
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.functions.BiFunction
|
||||
import io.reactivex.functions.Consumer
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.realm.RealmList
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
|
|
|
|||
|
|
@ -135,8 +135,8 @@ class InventoryRepositoryImpl(localRepository: InventoryLocalRepository, apiClie
|
|||
}
|
||||
}
|
||||
|
||||
override fun equipGear(user: User?, key: String, asCostume: Boolean): Flowable<Items> {
|
||||
return equip(user, if (asCostume) "costume" else "equipped", key)
|
||||
override fun equipGear(user: User?, equipment: String, asCostume: Boolean): Flowable<Items> {
|
||||
return equip(user, if (asCostume) "costume" else "equipped", equipment)
|
||||
}
|
||||
|
||||
override fun equip(user: User?, type: String, key: String): Flowable<Items> {
|
||||
|
|
|
|||
|
|
@ -1,18 +1,14 @@
|
|||
package com.habitrpg.android.habitica.data.implementation
|
||||
|
||||
import android.content.Context
|
||||
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.data.SetupCustomizationRepository
|
||||
import com.habitrpg.android.habitica.models.SetupCustomization
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.Arrays
|
||||
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
@Suppress("StringLiteralDuplication")
|
||||
class SetupCustomizationRepositoryImpl @Inject
|
||||
constructor(private val context: Context) : SetupCustomizationRepository {
|
||||
|
||||
|
|
@ -82,33 +78,33 @@ constructor(private val context: Context) : SetupCustomizationRepository {
|
|||
}
|
||||
|
||||
override fun getCustomizations(type: String, subtype: String?, user: User): List<SetupCustomization> {
|
||||
when (type) {
|
||||
return when (type) {
|
||||
"body" -> {
|
||||
return when (subtype) {
|
||||
when (subtype) {
|
||||
"size" -> sizes
|
||||
"shirt" -> getShirts(user.preferences?.size ?: "slim")
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
"skin" -> return skins
|
||||
"skin" -> skins
|
||||
"hair" -> {
|
||||
return when (subtype) {
|
||||
"bangs" -> getBangs(user.preferences?.hair!!.color)
|
||||
"ponytail" -> getHairBases(user.preferences?.hair!!.color)
|
||||
when (subtype) {
|
||||
"bangs" -> getBangs(user.preferences?.hair?.color ?: "")
|
||||
"ponytail" -> getHairBases(user.preferences?.hair?.color ?: "")
|
||||
"color" -> hairColors
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
"extras" -> {
|
||||
return when (subtype) {
|
||||
when (subtype) {
|
||||
"flower" -> flowers
|
||||
"glasses" -> glasses
|
||||
"wheelchair" -> wheelchairs
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
else -> emptyList()
|
||||
}
|
||||
return ArrayList()
|
||||
}
|
||||
|
||||
private fun getHairBases(color: String): List<SetupCustomization> {
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ import io.reactivex.Single
|
|||
import io.reactivex.functions.BiFunction
|
||||
import io.reactivex.functions.Consumer
|
||||
import io.realm.RealmResults
|
||||
import java.util.*
|
||||
|
||||
|
||||
class SocialRepositoryImpl(localRepository: SocialLocalRepository, apiClient: ApiClient, private val userId: String) : BaseRepositoryImpl<SocialLocalRepository>(localRepository, apiClient), SocialRepository {
|
||||
override fun getGroupMembership(id: String): Flowable<GroupMembership> {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class TagRepositoryImpl(localRepository: TagLocalRepository, apiClient: ApiClien
|
|||
|
||||
override fun createTags(tags: Collection<Tag>): Single<List<Tag>> {
|
||||
return Flowable.defer { Flowable.fromIterable(tags) }
|
||||
.filter { tag -> tag.name != null && !tag.getName().isEmpty() }
|
||||
.filter { tag -> tag.name != null && !tag.name.isEmpty() }
|
||||
.flatMap { this.createTag(it) }
|
||||
.toList()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.habitrpg.android.habitica.data.ApiClient
|
|||
import com.habitrpg.android.habitica.data.TaskRepository
|
||||
import com.habitrpg.android.habitica.data.local.TaskLocalRepository
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.Tag
|
||||
import com.habitrpg.android.habitica.models.responses.TaskDirection
|
||||
import com.habitrpg.android.habitica.models.responses.TaskScoringResult
|
||||
import com.habitrpg.android.habitica.models.tasks.*
|
||||
|
|
@ -53,13 +54,11 @@ class TaskRepositoryImpl(localRepository: TaskLocalRepository, apiClient: ApiCli
|
|||
.doOnNext { res -> this.localRepository.saveTasks(userId, tasksOrder, res) }
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
override fun taskChecked(user: User?, task: Task, up: Boolean, force: Boolean): Flowable<TaskScoringResult?> {
|
||||
val now = Date().time
|
||||
val id = task.id
|
||||
if (lastTaskAction > now - 500 && !force) {
|
||||
return Flowable.empty()
|
||||
}
|
||||
if (id == null) {
|
||||
if (lastTaskAction > now - 500 && !force || id == null) {
|
||||
return Flowable.empty()
|
||||
}
|
||||
lastTaskAction = now
|
||||
|
|
@ -91,7 +90,7 @@ class TaskRepositoryImpl(localRepository: TaskLocalRepository, apiClient: ApiCli
|
|||
if (Task.TYPE_DAILY == task.type) {
|
||||
task.streak = (task.streak ?: 0) + 1
|
||||
}
|
||||
}else if (Task.TYPE_HABIT == task.type) {
|
||||
} else if (Task.TYPE_HABIT == task.type) {
|
||||
if (up) {
|
||||
task.counterUp = (task.counterUp ?: 0) + 1
|
||||
} else {
|
||||
|
|
@ -140,21 +139,24 @@ class TaskRepositoryImpl(localRepository: TaskLocalRepository, apiClient: ApiCli
|
|||
lastTaskAction = now
|
||||
task.tags?.let {
|
||||
if (it.size > 0) {
|
||||
val tags = RealmList(*localRepository.getUnmanagedCopy(it).toTypedArray())
|
||||
val tags = RealmList<Tag>()
|
||||
tags.addAll(localRepository.getUnmanagedCopy(it))
|
||||
task.tags = tags
|
||||
}
|
||||
}
|
||||
|
||||
task.checklist?.let {
|
||||
if (it.size > 0) {
|
||||
val checklist = RealmList(*localRepository.getUnmanagedCopy(it).toTypedArray())
|
||||
val checklist = RealmList<ChecklistItem>()
|
||||
checklist.addAll(localRepository.getUnmanagedCopy(it))
|
||||
task.checklist = checklist
|
||||
}
|
||||
}
|
||||
|
||||
task.reminders?.let {
|
||||
if (it.size > 0) {
|
||||
val reminders = RealmList(*localRepository.getUnmanagedCopy(it).toTypedArray())
|
||||
val reminders = RealmList<RemindersItem>()
|
||||
reminders.addAll(localRepository.getUnmanagedCopy(it))
|
||||
task.reminders = reminders
|
||||
}
|
||||
}
|
||||
|
|
@ -167,6 +169,7 @@ class TaskRepositoryImpl(localRepository: TaskLocalRepository, apiClient: ApiCli
|
|||
.doOnNext { localRepository.saveTask(it) }
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
override fun updateTask(task: Task): Maybe<Task> {
|
||||
val now = Date().time
|
||||
if (lastTaskAction > now - 500 || !task.isValid) {
|
||||
|
|
@ -214,10 +217,11 @@ class TaskRepositoryImpl(localRepository: TaskLocalRepository, apiClient: ApiCli
|
|||
return localRepository.getTaskAtPosition(taskType, oldPosition)
|
||||
.firstElement()
|
||||
.flatMap { task ->
|
||||
if (task.isValid) {
|
||||
return@flatMap apiClient.postTaskNewPosition(task.id ?: "", newPosition).firstElement()
|
||||
return@flatMap if (task.isValid) {
|
||||
apiClient.postTaskNewPosition(task.id ?: "", newPosition).firstElement()
|
||||
} else {
|
||||
Maybe.just<List<String>>(ArrayList())
|
||||
}
|
||||
return@flatMap Maybe.just<List<String>>(ArrayList())
|
||||
}
|
||||
.doOnSuccess { localRepository.updateTaskPositions(it) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,6 @@ class SoundFile(val theme: String, private val fileName: String) : MediaPlayer.O
|
|||
val filePath: String
|
||||
get() = theme + "_" + fileName + ".mp3"
|
||||
|
||||
init {
|
||||
}
|
||||
|
||||
fun play() {
|
||||
if (isPlaying || file?.path == null) {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class SoundFileLoader(private val context: Context) {
|
|||
return cacheDir?.path
|
||||
}
|
||||
|
||||
@SuppressLint("SetWorldReadable", "ObsoleteSdkInt")
|
||||
@SuppressLint("SetWorldReadable", "ObsoleteSdkInt", "ReturnCount")
|
||||
fun download(files: List<SoundFile>): Single<List<SoundFile>> {
|
||||
return Observable.fromIterable(files)
|
||||
.flatMap({ audioFile ->
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import org.greenrobot.eventbus.Subscribe
|
|||
import java.util.*
|
||||
|
||||
class TaskAlarmManager(private var context: Context, private var taskRepository: TaskRepository, private var userId: String) {
|
||||
private val am: AlarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
private val am: AlarmManager? = context.getSystemService(Context.ALARM_SERVICE) as? AlarmManager
|
||||
|
||||
init {
|
||||
EventBus.getDefault().register(this)
|
||||
|
|
@ -110,7 +110,7 @@ class TaskAlarmManager(private var context: Context, private var taskRepository:
|
|||
val previousSender = PendingIntent.getBroadcast(context, intentId, intent, PendingIntent.FLAG_NO_CREATE)
|
||||
if (previousSender != null) {
|
||||
previousSender.cancel()
|
||||
am.cancel(previousSender)
|
||||
am?.cancel(previousSender)
|
||||
}
|
||||
|
||||
val sender = PendingIntent.getBroadcast(context, intentId, intent, PendingIntent.FLAG_CANCEL_CURRENT)
|
||||
|
|
|
|||
|
|
@ -59,21 +59,23 @@ class TaskFilterHelper {
|
|||
if (!task.containsAllTagIds(tagsId)) {
|
||||
return false
|
||||
}
|
||||
if (activeFilter != null && activeFilter != Task.FILTER_ALL) {
|
||||
return if (activeFilter != null && activeFilter != Task.FILTER_ALL) {
|
||||
when (activeFilter) {
|
||||
Task.FILTER_ACTIVE -> return if (task.type == Task.TYPE_DAILY) {
|
||||
Task.FILTER_ACTIVE -> if (task.type == Task.TYPE_DAILY) {
|
||||
task.isDisplayedActive
|
||||
} else {
|
||||
!task.completed
|
||||
}
|
||||
Task.FILTER_GRAY -> return task.completed || !task.isDisplayedActive
|
||||
Task.FILTER_WEAK -> return task.value < 0
|
||||
Task.FILTER_STRONG -> return task.value >= 0
|
||||
Task.FILTER_DATED -> return task.dueDate != null
|
||||
Task.FILTER_COMPLETED -> return task.completed
|
||||
Task.FILTER_GRAY -> task.completed || !task.isDisplayedActive
|
||||
Task.FILTER_WEAK -> task.value < 0
|
||||
Task.FILTER_STRONG -> task.value >= 0
|
||||
Task.FILTER_DATED -> task.dueDate != null
|
||||
Task.FILTER_COMPLETED -> task.completed
|
||||
else -> true
|
||||
}
|
||||
} else {
|
||||
true
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun setActiveFilter(type: String, activeFilter: String) {
|
||||
|
|
|
|||
|
|
@ -22,5 +22,5 @@ open class TutorialStep : RealmObject() {
|
|||
var displayedOn: Date? = null
|
||||
|
||||
fun shouldDisplay(): Boolean =
|
||||
!this.wasCompleted && (this.displayedOn == null || Date().time - this.displayedOn!!.time > 86400000)
|
||||
!this.wasCompleted && (this.displayedOn == null || Date().time - (displayedOn?.time ?: 0) > 86400000)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import com.facebook.drawee.view.DraweeHolder
|
|||
import com.facebook.drawee.view.MultiDraweeHolder
|
||||
import com.facebook.imagepipeline.image.ImageInfo
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.notNull
|
||||
import com.habitrpg.android.habitica.models.Avatar
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
|
@ -42,8 +43,8 @@ class AvatarView : View {
|
|||
|
||||
private val layerMap: Map<LayerType, String>
|
||||
get() {
|
||||
assert(avatar != null)
|
||||
return getLayerMap(avatar!!, true)
|
||||
val avatar = this.avatar ?: return emptyMap()
|
||||
return getLayerMap(avatar, true)
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -186,6 +187,7 @@ class AvatarView : View {
|
|||
return layerMap
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
private fun getAvatarLayerMap(avatar: Avatar): EnumMap<AvatarView.LayerType, String> {
|
||||
val layerMap = EnumMap<AvatarView.LayerType, String>(AvatarView.LayerType::class.java)
|
||||
|
||||
|
|
@ -434,7 +436,7 @@ class AvatarView : View {
|
|||
initAvatarRectMatrix()
|
||||
|
||||
// draw only when user is set
|
||||
if (avatar == null || !avatar!!.isValid) return
|
||||
if (avatar?.isValid != true) return
|
||||
|
||||
// request image layers if not yet processed
|
||||
if (multiDraweeHolder.size() == 0) {
|
||||
|
|
|
|||
|
|
@ -3,14 +3,12 @@ package com.habitrpg.android.habitica.ui
|
|||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
import android.content.res.TypedArray
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.LinearLayout
|
||||
|
||||
import com.habitrpg.android.habitica.R
|
||||
|
||||
class MaxHeightLinearLayout : LinearLayout {
|
||||
|
|
@ -53,8 +51,8 @@ class MaxHeightLinearLayout : LinearLayout {
|
|||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
var heightMeasurement = heightMeasureSpec
|
||||
|
||||
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
windowManager.defaultDisplay.getMetrics(displaymetrics)
|
||||
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as? WindowManager
|
||||
windowManager?.defaultDisplay?.getMetrics(displaymetrics)
|
||||
val height = (displaymetrics.heightPixels * maxHeight).toInt()
|
||||
heightMeasurement = Math.min(heightMeasurement, View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.AT_MOST))
|
||||
|
||||
|
|
|
|||
|
|
@ -67,9 +67,7 @@ class SpeechBubbleView(context: Context, attrs: AttributeSet) : FrameLayout(cont
|
|||
if (textView.isAnimating) {
|
||||
textView.stopTextAnimation()
|
||||
} else {
|
||||
if (showNextListener != null) {
|
||||
showNextListener!!.showNextStep()
|
||||
}
|
||||
showNextListener?.showNextStep()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,15 +66,15 @@ class TutorialView(context: Context, var step: TutorialStep, var onReaction: OnT
|
|||
}
|
||||
}
|
||||
|
||||
fun completeButtonClicked() {
|
||||
private fun completeButtonClicked() {
|
||||
this.onReaction?.onTutorialCompleted(this.step)
|
||||
}
|
||||
|
||||
fun dismissButtonClicked() {
|
||||
private fun dismissButtonClicked() {
|
||||
this.onReaction?.onTutorialDeferred(this.step)
|
||||
}
|
||||
|
||||
fun backgroundClicked() {
|
||||
private fun backgroundClicked() {
|
||||
speechBubbleView.onClick(speechBubbleView)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,12 +83,9 @@ class AboutActivity : BaseActivity() {
|
|||
private inner class PagerAdapter(fm: FragmentManager, internal var mNumOfTabs: Int) : FragmentStatePagerAdapter(fm) {
|
||||
|
||||
override fun getItem(position: Int): Fragment? {
|
||||
|
||||
when (position) {
|
||||
0 ->
|
||||
|
||||
return AboutFragment()
|
||||
1 -> return LibsBuilder()
|
||||
return when (position) {
|
||||
0 -> AboutFragment()
|
||||
1 -> LibsBuilder()
|
||||
//Pass the fields of your application to the lib so it can find all external lib information
|
||||
.withFields(R.string::class.java.fields)
|
||||
.withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
|
||||
|
|
@ -99,19 +96,16 @@ class AboutActivity : BaseActivity() {
|
|||
.withAboutVersionShownCode(true)
|
||||
.withAboutVersionShownName(true)
|
||||
.supportFragment()
|
||||
else -> return null
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
if (position == 0) {
|
||||
return getString(R.string.about_title)
|
||||
} else if (position == 1) {
|
||||
return getString(R.string.about_libraries)
|
||||
return when (position) {
|
||||
0 -> getString(R.string.about_title)
|
||||
1 -> getString(R.string.about_libraries)
|
||||
else -> ""
|
||||
}
|
||||
|
||||
|
||||
return getString(R.string.about_versionhistory)
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
|
|
|
|||
|
|
@ -31,20 +31,6 @@ abstract class BaseActivity : AppCompatActivity() {
|
|||
private val habiticaApplication: HabiticaApplication
|
||||
get() = application as HabiticaApplication
|
||||
|
||||
//Check for "Don't keep Activities" Developer setting
|
||||
//TODO: Make this check obsolete.
|
||||
internal val isAlwaysFinishActivitiesOptionEnabled: Boolean
|
||||
get() {
|
||||
var alwaysFinishActivitiesInt = 0
|
||||
alwaysFinishActivitiesInt = if (Build.VERSION.SDK_INT >= 17) {
|
||||
Settings.System.getInt(applicationContext.contentResolver, Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0)
|
||||
} else {
|
||||
Settings.System.getInt(applicationContext.contentResolver, Settings.System.ALWAYS_FINISH_ACTIVITIES, 0)
|
||||
}
|
||||
|
||||
return alwaysFinishActivitiesInt == 1
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
||||
InstabugTrackingDelegate.notifyActivityGotTouchEvent(ev, this)
|
||||
return super.dispatchTouchEvent(ev)
|
||||
|
|
@ -94,18 +80,12 @@ abstract class BaseActivity : AppCompatActivity() {
|
|||
override fun onDestroy() {
|
||||
destroyed = true
|
||||
|
||||
if (compositeSubscription != null && !compositeSubscription!!.isDisposed) {
|
||||
compositeSubscription!!.dispose()
|
||||
if (!compositeSubscription.isDisposed) {
|
||||
compositeSubscription.dispose()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
internal fun showDeveloperOptionsScreen() {
|
||||
val intent = Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun onEvent(event: ShowConnectionProblemEvent) {
|
||||
val builder = AlertDialog.Builder(this)
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ class ClassSelectionActivity : BaseActivity(), Consumer<User> {
|
|||
val preferences = Preferences()
|
||||
preferences.setHair(Hair())
|
||||
preferences.costume = false
|
||||
preferences.setSize(bundle.getString("size")!!)
|
||||
preferences.setSkin(bundle.getString("skin")!!)
|
||||
preferences.setShirt(bundle.getString("shirt")!!)
|
||||
preferences.setSize(bundle.getString("size") ?: "slim")
|
||||
preferences.setSkin(bundle.getString("skin") ?: "")
|
||||
preferences.setShirt(bundle.getString("shirt") ?: "")
|
||||
preferences.hair?.bangs = bundle.getInt("hairBangs")
|
||||
preferences.hair?.base = bundle.getInt("hairBase")
|
||||
preferences.hair?.color = bundle.getString("hairColor")
|
||||
|
|
@ -117,23 +117,23 @@ class ClassSelectionActivity : BaseActivity(), Consumer<User> {
|
|||
return user
|
||||
}
|
||||
|
||||
fun healerSelected() {
|
||||
private fun healerSelected() {
|
||||
displayConfirmationDialogForClass(getString(R.string.healer), Stats.HEALER)
|
||||
}
|
||||
|
||||
fun mageSelected() {
|
||||
private fun mageSelected() {
|
||||
displayConfirmationDialogForClass(getString(R.string.mage), Stats.MAGE)
|
||||
}
|
||||
|
||||
fun rogueSelected() {
|
||||
private fun rogueSelected() {
|
||||
displayConfirmationDialogForClass(getString(R.string.rogue), Stats.ROGUE)
|
||||
}
|
||||
|
||||
fun warriorSelected() {
|
||||
private fun warriorSelected() {
|
||||
displayConfirmationDialogForClass(getString(R.string.warrior), Stats.WARRIOR)
|
||||
}
|
||||
|
||||
fun optOutSelected() {
|
||||
private fun optOutSelected() {
|
||||
if (!this.isInitialSelection && this.classWasUnset == false) {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,12 +70,12 @@ class SkillTasksActivity : BaseActivity() {
|
|||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
when (position) {
|
||||
0 -> return getString(R.string.habits)
|
||||
1 -> return getString(R.string.dailies)
|
||||
2 -> return getString(R.string.todos)
|
||||
return when (position) {
|
||||
0 -> getString(R.string.habits)
|
||||
1 -> getString(R.string.dailies)
|
||||
2 -> getString(R.string.todos)
|
||||
else -> ""
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
attributeWrapper.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (taskType == "habit") {
|
||||
if (taskType == Task.TYPE_HABIT) {
|
||||
taskWrapper.removeView(startDateLayout)
|
||||
|
||||
mainWrapper.removeView(checklistWrapper)
|
||||
|
|
@ -215,7 +215,7 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
mainWrapper.removeView(actionsLayout)
|
||||
}
|
||||
|
||||
if (taskType == "daily") {
|
||||
if (taskType == Task.TYPE_DAILY) {
|
||||
val frequencyAdapter = ArrayAdapter.createFromResource(this,
|
||||
R.array.daily_frequencies, android.R.layout.simple_spinner_item)
|
||||
frequencyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
|
|
@ -226,7 +226,7 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
mainWrapper.removeView(startDateLayout)
|
||||
}
|
||||
|
||||
if (taskType == "todo") {
|
||||
if (taskType == Task.TYPE_TODO) {
|
||||
dueDatePickerLayout.removeView(dueDatePickerText)
|
||||
//Allows user to decide if they want to add a due date or not
|
||||
dueDateCheckBox.setOnCheckedChangeListener { buttonView, _ ->
|
||||
|
|
@ -240,7 +240,7 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
mainWrapper.removeView(dueDateLayout)
|
||||
}
|
||||
|
||||
if (taskType != "reward") {
|
||||
if (taskType != Task.TYPE_REWARD) {
|
||||
taskValueLayout.visibility = View.GONE
|
||||
} else {
|
||||
|
||||
|
|
@ -251,20 +251,20 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
attributeWrapper.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (taskType == "todo" || taskType == "daily") {
|
||||
if (taskType == Task.TYPE_TODO || taskType == Task.TYPE_DAILY) {
|
||||
createCheckListRecyclerView()
|
||||
createRemindersRecyclerView()
|
||||
}
|
||||
|
||||
// Emoji keyboard stuff
|
||||
var isTodo = false
|
||||
if (taskType == "todo") {
|
||||
if (taskType == Task.TYPE_TODO) {
|
||||
isTodo = true
|
||||
}
|
||||
|
||||
// If it's a to-do, change the emojiToggle2 to the actual emojiToggle2 (prevents NPEs when not a to-do task)
|
||||
emojiToggle2 = if (isTodo) {
|
||||
findViewById<View>(R.id.emoji_toggle_btn2) as ImageButton
|
||||
findViewById<View>(R.id.emoji_toggle_btn2) as? ImageButton
|
||||
} else {
|
||||
emojiToggle0
|
||||
}
|
||||
|
|
@ -293,13 +293,13 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
if (currentFocus == null || !isEmojiEditText(currentFocus) || emojicon == null) {
|
||||
return@setOnEmojiconClickedListener
|
||||
}
|
||||
val emojiEditText = currentFocus as EmojiEditText
|
||||
val start = emojiEditText.selectionStart
|
||||
val end = emojiEditText.selectionEnd
|
||||
val emojiEditText = currentFocus as? EmojiEditText
|
||||
val start = emojiEditText?.selectionStart ?: 0
|
||||
val end = emojiEditText?.selectionEnd ?: 0
|
||||
if (start < 0) {
|
||||
emojiEditText.append(emojicon.emoji)
|
||||
emojiEditText?.append(emojicon.emoji)
|
||||
} else {
|
||||
emojiEditText.text.replace(Math.min(start, end),
|
||||
emojiEditText?.text?.replace(Math.min(start, end),
|
||||
Math.max(start, end), emojicon.emoji, 0,
|
||||
emojicon.emoji.length)
|
||||
}
|
||||
|
|
@ -330,7 +330,7 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
)
|
||||
|
||||
if (taskId != null) {
|
||||
taskRepository.getTask(taskId!!)
|
||||
taskRepository.getTask(taskId ?: "")
|
||||
.firstElement()
|
||||
.subscribe(Consumer { task ->
|
||||
this.task = task
|
||||
|
|
@ -338,7 +338,7 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
populate(task)
|
||||
|
||||
setTitle(task)
|
||||
if (taskType == "todo" || taskType == "daily") {
|
||||
if (taskType == Task.TYPE_TODO || taskType == Task.TYPE_DAILY) {
|
||||
populateChecklistRecyclerView()
|
||||
populateRemindersRecyclerView()
|
||||
}
|
||||
|
|
@ -349,7 +349,7 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
|
||||
btnDelete.isEnabled = true
|
||||
} else {
|
||||
setTitle(null as Task?)
|
||||
//setTitle(null as? Task)
|
||||
taskText.requestFocus()
|
||||
}
|
||||
|
||||
|
|
@ -380,9 +380,8 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
repeatablesFrequencyContainer.layoutParams = repeatablesFrequencyContainerParams
|
||||
}
|
||||
|
||||
// @TODO: abstract business logic to Presenter and only modify view?
|
||||
private fun enableRepeatables() {
|
||||
if (!remoteConfigManager.repeatablesAreEnabled() || taskType != "daily") {
|
||||
if (!remoteConfigManager.repeatablesAreEnabled() || taskType != Task.TYPE_DAILY) {
|
||||
repeatablesLayout.visibility = View.INVISIBLE
|
||||
val repeatablesLayoutParams = repeatablesLayout.layoutParams
|
||||
repeatablesLayoutParams.height = 0
|
||||
|
|
@ -431,27 +430,29 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
generateSummary()
|
||||
val r = resources
|
||||
|
||||
// @TODO: remove magic numbers
|
||||
when (position) {
|
||||
2 -> {
|
||||
hideWeekOptions()
|
||||
|
||||
if (position == 2) {
|
||||
hideWeekOptions()
|
||||
val repeatablesOnSpinnerParams = repeatablesOnSpinner.layoutParams
|
||||
repeatablesOnSpinnerParams.height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 72f, r.displayMetrics).toInt()
|
||||
repeatablesOnSpinner.layoutParams = repeatablesOnSpinnerParams
|
||||
|
||||
val repeatablesOnSpinnerParams = repeatablesOnSpinner.layoutParams
|
||||
repeatablesOnSpinnerParams.height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 72f, r.displayMetrics).toInt()
|
||||
repeatablesOnSpinner.layoutParams = repeatablesOnSpinnerParams
|
||||
val repeatablesOnTitleParams = reapeatablesOnTextView.layoutParams
|
||||
repeatablesOnTitleParams.height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30f, r.displayMetrics).toInt()
|
||||
reapeatablesOnTextView.layoutParams = repeatablesOnTitleParams
|
||||
}
|
||||
1 -> {
|
||||
hideMonthOptions()
|
||||
|
||||
val repeatablesOnTitleParams = reapeatablesOnTextView.layoutParams
|
||||
repeatablesOnTitleParams.height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30f, r.displayMetrics).toInt()
|
||||
reapeatablesOnTextView.layoutParams = repeatablesOnTitleParams
|
||||
} else if (position == 1) {
|
||||
hideMonthOptions()
|
||||
|
||||
val repeatablesFrequencyContainerParams = repeatablesFrequencyContainer.layoutParams
|
||||
repeatablesFrequencyContainerParams.height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 220f, r.displayMetrics).toInt()
|
||||
repeatablesFrequencyContainer.layoutParams = repeatablesFrequencyContainerParams
|
||||
} else {
|
||||
hideWeekOptions()
|
||||
hideMonthOptions()
|
||||
val repeatablesFrequencyContainerParams = repeatablesFrequencyContainer.layoutParams
|
||||
repeatablesFrequencyContainerParams.height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 220f, r.displayMetrics).toInt()
|
||||
repeatablesFrequencyContainer.layoutParams = repeatablesFrequencyContainerParams
|
||||
}
|
||||
else -> {
|
||||
hideWeekOptions()
|
||||
hideMonthOptions()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -486,17 +487,17 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
val dayOfTheWeek = sharedPreferences.getString("FirstDayOfTheWeek",
|
||||
Integer.toString(Calendar.getInstance().firstDayOfWeek))
|
||||
firstDayOfTheWeekHelper = FirstDayOfTheWeekHelper.newInstance(Integer.parseInt(dayOfTheWeek))
|
||||
val weekdaysTemp = ArrayList(Arrays.asList(*weekdays))
|
||||
val weekdaysTemp = weekdays.asList()
|
||||
Collections.rotate(weekdaysTemp, firstDayOfTheWeekHelper?.dailyTaskFormOffset ?: 0)
|
||||
weekdays = weekdaysTemp.toTypedArray()
|
||||
|
||||
for (i in 0..6) {
|
||||
val weekdayRow = layoutInflater.inflate(R.layout.row_checklist, this.repeatablesFrequencyContainer, false)
|
||||
val checkbox = weekdayRow.findViewById<View>(R.id.checkbox) as CheckBox
|
||||
checkbox.text = weekdays[i]
|
||||
checkbox.isChecked = true
|
||||
checkbox.setOnClickListener { generateSummary() }
|
||||
repeatablesWeekDayCheckboxes.add(checkbox)
|
||||
val checkbox = weekdayRow.findViewById<View>(R.id.checkbox) as? CheckBox
|
||||
checkbox?.text = weekdays[i]
|
||||
checkbox?.isChecked = true
|
||||
checkbox?.setOnClickListener { generateSummary() }
|
||||
checkbox.notNull { repeatablesWeekDayCheckboxes.add(it) }
|
||||
repeatablesFrequencyContainer.addView(weekdayRow)
|
||||
}
|
||||
|
||||
|
|
@ -690,13 +691,13 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
private fun createTagsCheckBoxes() {
|
||||
this.tagsContainerLinearLayout.removeAllViews()
|
||||
for ((position, tag) in (tags ?: emptyList()).withIndex()) {
|
||||
val row = layoutInflater.inflate(R.layout.row_checklist, this.tagsContainerLinearLayout, false) as TableRow
|
||||
val checkbox = row.findViewById<View>(R.id.checkbox) as CheckBox
|
||||
row.id = position
|
||||
checkbox.text = tag.name // set text Name
|
||||
checkbox.id = position
|
||||
val row = layoutInflater.inflate(R.layout.row_checklist, this.tagsContainerLinearLayout, false) as? TableRow
|
||||
val checkbox = row?.findViewById<View>(R.id.checkbox) as? CheckBox
|
||||
row?.id = position
|
||||
checkbox?.text = tag.name // set text Name
|
||||
checkbox?.id = position
|
||||
//This is to check if the tag was selected by the user. Similar to onClickListener
|
||||
checkbox.setOnCheckedChangeListener { buttonView, _ ->
|
||||
checkbox?.setOnCheckedChangeListener { buttonView, _ ->
|
||||
if (buttonView.isChecked) {
|
||||
if (selectedTags?.contains(tag) == false) {
|
||||
selectedTags?.add(tag)
|
||||
|
|
@ -707,9 +708,9 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
checkbox.isChecked = taskFilterHelper.isTagChecked(tag.getId())
|
||||
checkbox?.isChecked = taskFilterHelper.isTagChecked(tag.getId())
|
||||
tagsContainerLinearLayout.addView(row)
|
||||
tagCheckBoxList?.add(checkbox)
|
||||
checkbox.notNull { tagCheckBoxList?.add(it) }
|
||||
}
|
||||
|
||||
if (task != null) {
|
||||
|
|
@ -728,10 +729,10 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
title = resources.getString(R.string.action_edit) + " " + task.text
|
||||
} else {
|
||||
when (taskType) {
|
||||
"todo" -> title = resources.getString(R.string.new_todo)
|
||||
"daily" -> title = resources.getString(R.string.new_daily)
|
||||
"habit" -> title = resources.getString(R.string.new_habit)
|
||||
"reward" -> title = resources.getString(R.string.new_reward)
|
||||
Task.TYPE_TODO -> title = resources.getString(R.string.new_todo)
|
||||
Task.TYPE_DAILY -> title = resources.getString(R.string.new_daily)
|
||||
Task.TYPE_HABIT -> title = resources.getString(R.string.new_habit)
|
||||
Task.TYPE_REWARD -> title = resources.getString(R.string.new_reward)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -747,25 +748,27 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
val dayOfTheWeek = sharedPreferences.getString("FirstDayOfTheWeek",
|
||||
Integer.toString(Calendar.getInstance().firstDayOfWeek))
|
||||
firstDayOfTheWeekHelper = FirstDayOfTheWeekHelper.newInstance(Integer.parseInt(dayOfTheWeek))
|
||||
val weekdaysTemp = ArrayList(Arrays.asList(*weekdays))
|
||||
val weekdaysTemp = weekdays.asList()
|
||||
Collections.rotate(weekdaysTemp, firstDayOfTheWeekHelper?.dailyTaskFormOffset ?: 0)
|
||||
weekdays = weekdaysTemp.toTypedArray()
|
||||
|
||||
for (i in 0..6) {
|
||||
val weekdayRow = layoutInflater.inflate(R.layout.row_checklist, this.frequencyContainer, false)
|
||||
val checkbox = weekdayRow.findViewById<View>(R.id.checkbox) as CheckBox
|
||||
checkbox.text = weekdays[i]
|
||||
checkbox.isChecked = true
|
||||
this.weekdayCheckboxes.add(checkbox)
|
||||
val checkbox = weekdayRow.findViewById<View>(R.id.checkbox) as? CheckBox
|
||||
checkbox?.text = weekdays[i]
|
||||
checkbox?.isChecked = true
|
||||
checkbox.notNull {
|
||||
this.weekdayCheckboxes.add(it)
|
||||
}
|
||||
this.frequencyContainer.addView(weekdayRow)
|
||||
}
|
||||
} else {
|
||||
val dayRow = layoutInflater.inflate(R.layout.row_number_picker, this.frequencyContainer, false)
|
||||
this.frequencyPicker = dayRow.findViewById<View>(R.id.numberPicker) as NumberPicker
|
||||
this.frequencyPicker = dayRow.findViewById<View>(R.id.numberPicker) as? NumberPicker
|
||||
this.frequencyPicker?.minValue = 1
|
||||
this.frequencyPicker?.maxValue = 366
|
||||
val tv = dayRow.findViewById<View>(R.id.label) as TextView
|
||||
tv.text = resources.getString(R.string.frequency_daily)
|
||||
val tv = dayRow.findViewById<View>(R.id.label) as? TextView
|
||||
tv?.text = resources.getString(R.string.frequency_daily)
|
||||
this.frequencyContainer.addView(dayRow)
|
||||
}
|
||||
|
||||
|
|
@ -841,12 +844,12 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
}
|
||||
}
|
||||
|
||||
if (task.type == "habit") {
|
||||
if (task.type == Task.TYPE_HABIT) {
|
||||
positiveCheckBox.isChecked = task.up ?: false
|
||||
negativeCheckBox.isChecked = task.down ?: false
|
||||
}
|
||||
|
||||
if (task.type == "daily") {
|
||||
if (task.type == Task.TYPE_DAILY) {
|
||||
|
||||
if (task.startDate != null) {
|
||||
startDateListener?.setCalendar(task.startDate)
|
||||
|
|
@ -874,7 +877,7 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
populateRepeatables(task)
|
||||
}
|
||||
|
||||
if (task.type == "todo") {
|
||||
if (task.type == Task.TYPE_TODO) {
|
||||
if (task.dueDate != null) {
|
||||
dueDateCheckBox.isChecked = true
|
||||
dueDateListener?.setCalendar(task.dueDate)
|
||||
|
|
@ -899,6 +902,7 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
private fun saveTask(task: Task): Boolean {
|
||||
|
||||
val text = MarkdownParser.parseCompiled(taskText.text)
|
||||
|
|
@ -955,12 +959,12 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
}
|
||||
|
||||
when (task.type) {
|
||||
"habit" -> {
|
||||
Task.TYPE_HABIT -> {
|
||||
task.up = positiveCheckBox.isChecked
|
||||
task.down = negativeCheckBox.isChecked
|
||||
}
|
||||
|
||||
"daily" -> {
|
||||
Task.TYPE_DAILY -> {
|
||||
task.startDate = Date(startDateListener?.getCalendar()?.timeInMillis ?: Date().time)
|
||||
|
||||
if (this.dailyFrequencySpinner.selectedItemPosition == 0) {
|
||||
|
|
@ -1036,7 +1040,7 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
}
|
||||
}
|
||||
|
||||
"todo" -> {
|
||||
Task.TYPE_TODO -> {
|
||||
if (dueDateCheckBox.isChecked) {
|
||||
task.dueDate = Date(dueDateListener?.getCalendar()?.timeInMillis ?: Date().time)
|
||||
} else {
|
||||
|
|
@ -1044,7 +1048,7 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
}
|
||||
}
|
||||
|
||||
"reward" -> {
|
||||
Task.TYPE_REWARD -> {
|
||||
val value = taskValue.text.toString()
|
||||
if (!value.isEmpty()) {
|
||||
val localFormat = DecimalFormat.getInstance(Locale.getDefault())
|
||||
|
|
@ -1119,10 +1123,10 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
}
|
||||
|
||||
private fun dismissKeyboard() {
|
||||
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
|
||||
val currentFocus = currentFocus
|
||||
if (currentFocus != null) {
|
||||
imm.hideSoftInputFromWindow(currentFocus.windowToken, 0)
|
||||
imm?.hideSoftInputFromWindow(currentFocus.windowToken, 0)
|
||||
}
|
||||
popup?.dismiss()
|
||||
popup = null
|
||||
|
|
@ -1165,6 +1169,7 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
updateDateText()
|
||||
}
|
||||
|
||||
@Suppress("UnsafeCast")
|
||||
fun getCalendar(): Calendar {
|
||||
return calendar.clone() as Calendar
|
||||
}
|
||||
|
|
@ -1194,8 +1199,8 @@ class TaskFormActivity : BaseActivity(), AdapterView.OnItemSelectedListener {
|
|||
view.isFocusableInTouchMode = true
|
||||
view.requestFocus()
|
||||
popup?.showAtBottomPending()
|
||||
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
||||
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
|
||||
inputMethodManager?.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
||||
changeEmojiKeyboardIcon(true)
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import android.view.ViewGroup
|
|||
import android.widget.TextView
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.notNull
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import com.habitrpg.android.habitica.models.inventory.Equipment
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||
|
|
@ -30,8 +31,8 @@ class EquipmentRecyclerViewAdapter(data: OrderedRealmCollection<Equipment>?, aut
|
|||
}
|
||||
|
||||
override fun onBindViewHolder(holder: GearViewHolder, position: Int) {
|
||||
if (data != null) {
|
||||
holder.bind(data!![position])
|
||||
data.notNull {
|
||||
holder.bind(it[position])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<Item>?, autoUpdate: Boole
|
|||
imageName = "Pet_" + type + "_" + item.key
|
||||
|
||||
if (isHatching) {
|
||||
disabled = this.isPetOwned!!
|
||||
disabled = this.isPetOwned ?: false
|
||||
}
|
||||
}
|
||||
DataBindingUtils.loadImage(imageView, imageName ?: "head_0")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter.inventory
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.habitrpg.android.habitica.R
|
|||
import com.habitrpg.android.habitica.events.commands.OpenGemPurchaseFragmentCommand
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
import com.habitrpg.android.habitica.extensions.notNull
|
||||
import com.habitrpg.android.habitica.models.inventory.Item
|
||||
import com.habitrpg.android.habitica.models.shops.Shop
|
||||
import com.habitrpg.android.habitica.models.shops.ShopCategory
|
||||
|
|
@ -109,43 +110,46 @@ class ShopRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
val obj = getItem(position)
|
||||
if (obj != null) {
|
||||
when (obj.javaClass) {
|
||||
Shop::class.java -> (holder as ShopHeaderViewHolder).bind(obj as Shop, shopSpriteSuffix)
|
||||
Shop::class.java -> (obj as? Shop).notNull { (holder as? ShopHeaderViewHolder)?.bind(it, shopSpriteSuffix) }
|
||||
ShopCategory::class.java -> {
|
||||
val category = obj as ShopCategory
|
||||
(holder as SectionViewHolder).bind((category).text)
|
||||
val category = obj as? ShopCategory
|
||||
val sectionHolder = holder as? SectionViewHolder ?: return
|
||||
sectionHolder.bind(category?.text ?: "")
|
||||
if (gearCategories.contains(category)) {
|
||||
val adapter = HabiticaClassArrayAdapter(context, R.layout.class_spinner_dropdown_item, gearCategories.map { it.identifier })
|
||||
holder.spinnerAdapter = adapter
|
||||
holder.selectedItem = gearCategories.indexOf(category)
|
||||
holder.spinnerSelectionChanged = {
|
||||
sectionHolder.spinnerAdapter = adapter
|
||||
sectionHolder.selectedItem = gearCategories.indexOf(category)
|
||||
sectionHolder.spinnerSelectionChanged = {
|
||||
if (selectedGearCategory != gearCategories[holder.selectedItem].identifier) {
|
||||
selectedGearCategory = gearCategories[holder.selectedItem].identifier
|
||||
}
|
||||
}
|
||||
if (user?.stats?.habitClass != category.identifier) {
|
||||
holder.notesView?.text = context?.getString(R.string.class_gear_disclaimer)
|
||||
holder.notesView?.visibility = View.VISIBLE
|
||||
if (user?.stats?.habitClass != category?.identifier) {
|
||||
sectionHolder.notesView?.text = context?.getString(R.string.class_gear_disclaimer)
|
||||
sectionHolder.notesView?.visibility = View.VISIBLE
|
||||
} else {
|
||||
holder.notesView?.visibility = View.GONE
|
||||
sectionHolder.notesView?.visibility = View.GONE
|
||||
}
|
||||
} else {
|
||||
holder.spinnerAdapter = null
|
||||
holder.notesView?.visibility = View.GONE
|
||||
sectionHolder.spinnerAdapter = null
|
||||
sectionHolder.notesView?.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
ShopItem::class.java -> {
|
||||
val item = obj as ShopItem
|
||||
(holder as ShopItemViewHolder).bind(item, item.canAfford(user))
|
||||
val itemHolder = holder as? ShopItemViewHolder ?: return
|
||||
itemHolder.bind(item, item.canAfford(user))
|
||||
if (ownedItems.containsKey(item.key+"-"+item.pinType)) {
|
||||
holder.itemCount = ownedItems[item.key+"-"+item.pinType]?.owned ?: 0
|
||||
itemHolder.itemCount = ownedItems[item.key+"-"+item.pinType]?.owned ?: 0
|
||||
}
|
||||
holder.isPinned = pinnedItemKeys.contains(item.key)
|
||||
itemHolder.isPinned = pinnedItemKeys.contains(item.key)
|
||||
}
|
||||
String::class.java -> (holder as EmptyStateViewHolder).text = obj as String
|
||||
String::class.java -> (holder as? EmptyStateViewHolder)?.text = obj as? String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
private fun getItem(position: Int): Any? {
|
||||
if (items.size == 0) {
|
||||
return null
|
||||
|
|
@ -191,8 +195,8 @@ class ShopRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
0
|
||||
} else {
|
||||
val selectedCategory: ShopCategory? = getSelectedShopCategory()
|
||||
return if (selectedCategory != null) {
|
||||
return if (selectedCategory.items.size == 0) {
|
||||
if (selectedCategory != null) {
|
||||
if (selectedCategory.items.size == 0) {
|
||||
2
|
||||
} else {
|
||||
selectedCategory.items.size+1
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import android.view.ViewGroup
|
|||
import android.widget.TextView
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.notNull
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import com.habitrpg.android.habitica.models.inventory.Animal
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity
|
||||
|
|
@ -41,9 +42,9 @@ class StableRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
val obj = this.itemList[position]
|
||||
if (obj.javaClass == String::class.java) {
|
||||
(holder as SectionViewHolder).bind(obj as String)
|
||||
(holder as? SectionViewHolder)?.bind(obj as? String ?: "")
|
||||
} else {
|
||||
(holder as StableViewHolder).bind(itemList[position] as Animal)
|
||||
(obj as? Animal).notNull { (holder as? StableViewHolder)?.bind(it) }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -75,7 +76,7 @@ class StableRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
ownedTextView.visibility = View.VISIBLE
|
||||
this.imageView.alpha = 1.0f
|
||||
if (item.numberOwned > 0) {
|
||||
this.ownedTextView.text = animal!!.numberOwned.toString()
|
||||
this.ownedTextView.text = animal?.numberOwned?.toString()
|
||||
if (itemType == "pets") {
|
||||
DataBindingUtils.loadImage(this.imageView, "Pet-" + item.key)
|
||||
} else {
|
||||
|
|
@ -96,12 +97,12 @@ class StableRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
val fragment = PetDetailRecyclerFragment()
|
||||
fragment.animalType = animal.animal
|
||||
fragment.animalGroup = animal.animalGroup
|
||||
activity!!.displayFragment(fragment)
|
||||
activity?.displayFragment(fragment)
|
||||
} else {
|
||||
val fragment = MountDetailRecyclerFragment()
|
||||
fragment.animalType = animal.animal
|
||||
fragment.animalGroup = animal.animalGroup
|
||||
activity!!.displayFragment(fragment)
|
||||
activity?.displayFragment(fragment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import com.habitrpg.android.habitica.ui.helpers.bindView
|
|||
import org.greenrobot.eventbus.EventBus
|
||||
import java.util.*
|
||||
|
||||
class CustomizationSetupAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
internal class CustomizationSetupAdapter : RecyclerView.Adapter<CustomizationSetupAdapter.CustomizationViewHolder>() {
|
||||
|
||||
var userSize: String? = null
|
||||
var user: User? = null
|
||||
|
|
@ -30,18 +30,19 @@ class CustomizationSetupAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>(
|
|||
this.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomizationViewHolder {
|
||||
return CustomizationViewHolder(parent.inflate(R.layout.setup_customization_item))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
(holder as CustomizationViewHolder).bind(customizationList[position])
|
||||
override fun onBindViewHolder(holder: CustomizationViewHolder, position: Int) {
|
||||
holder.bind(customizationList[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return customizationList.size
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
private fun isCustomizationActive(customization: SetupCustomization): Boolean {
|
||||
val prefs = this.user?.preferences ?: return false
|
||||
when (customization.category) {
|
||||
|
|
|
|||
|
|
@ -98,14 +98,14 @@ class AchievementAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
|
||||
val customView = LayoutInflater.from(context)
|
||||
.inflate(R.layout.dialog_achievement_details, null)
|
||||
val achievementImage = customView.findViewById<View>(R.id.achievement_image) as ImageView
|
||||
achievementImage.setImageDrawable(draweeView.drawable)
|
||||
val achievementImage = customView.findViewById<View>(R.id.achievement_image) as ImageView?
|
||||
achievementImage?.setImageDrawable(draweeView.drawable)
|
||||
|
||||
val titleView = customView.findViewById<View>(R.id.achievement_title) as TextView
|
||||
titleView.text = achievement?.title
|
||||
val titleView = customView.findViewById<View>(R.id.achievement_title) as TextView?
|
||||
titleView?.text = achievement?.title
|
||||
|
||||
val textView = customView.findViewById<View>(R.id.achievement_text) as TextView
|
||||
textView.text = achievement?.text
|
||||
val textView = customView.findViewById<View>(R.id.achievement_text) as TextView?
|
||||
textView?.text = achievement?.text
|
||||
|
||||
b.setView(customView)
|
||||
b.setPositiveButton(R.string.profile_achievement_ok) { _, _ -> }
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import android.support.v7.widget.RecyclerView
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
|
|
@ -23,7 +22,6 @@ import io.realm.OrderedRealmCollection
|
|||
import io.realm.RealmRecyclerViewAdapter
|
||||
import net.pherth.android.emoji_library.EmojiParser
|
||||
import net.pherth.android.emoji_library.EmojiTextView
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
class ChallengesListViewAdapter(data: OrderedRealmCollection<Challenge>?, autoUpdate: Boolean, private val viewUserChallengesOnly: Boolean, private val userId: String) : RealmRecyclerViewAdapter<Challenge, ChallengesListViewAdapter.ChallengeViewHolder>(data, autoUpdate) {
|
||||
private var unfilteredData: OrderedRealmCollection<Challenge>? = null
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class PublicGuildsRecyclerViewAdapter(data: OrderedRealmCollection<Group>?, auto
|
|||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GuildViewHolder {
|
||||
val guildViewHolder = GuildViewHolder(parent.inflate(R.layout.item_public_guild))
|
||||
guildViewHolder.itemView.setOnClickListener { v ->
|
||||
val guild = v.tag as Group
|
||||
val guild = v.tag as? Group ?: return@setOnClickListener
|
||||
val guildFragment = GuildFragment()
|
||||
guildFragment.setGuildId(guild.id)
|
||||
guildFragment.isMember = isInGroup(guild)
|
||||
|
|
@ -43,11 +43,11 @@ class PublicGuildsRecyclerViewAdapter(data: OrderedRealmCollection<Group>?, auto
|
|||
EventBus.getDefault().post(event)
|
||||
}
|
||||
guildViewHolder.joinLeaveButton.setOnClickListener { v ->
|
||||
val guild = v.tag as Group
|
||||
val guild = v.tag as? Group ?: return@setOnClickListener
|
||||
val isMember = this.memberGuildIDs.contains(guild.id)
|
||||
if (isMember) {
|
||||
this@PublicGuildsRecyclerViewAdapter.apiClient!!.leaveGroup(guild.id)
|
||||
.subscribe(Consumer {
|
||||
this@PublicGuildsRecyclerViewAdapter.apiClient?.leaveGroup(guild.id)
|
||||
?.subscribe(Consumer {
|
||||
memberGuildIDs.remove(guild.id)
|
||||
if (data != null) {
|
||||
val indexOfGroup = data!!.indexOf(guild)
|
||||
|
|
@ -55,12 +55,12 @@ class PublicGuildsRecyclerViewAdapter(data: OrderedRealmCollection<Group>?, auto
|
|||
}
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
} else {
|
||||
this@PublicGuildsRecyclerViewAdapter.apiClient!!.joinGroup(guild.id)
|
||||
.subscribe(Consumer { group ->
|
||||
this@PublicGuildsRecyclerViewAdapter.apiClient?.joinGroup(guild.id)
|
||||
?.subscribe(Consumer { group ->
|
||||
memberGuildIDs.add(group.id)
|
||||
if (data != null) {
|
||||
val indexOfGroup = data!!.indexOf(group)
|
||||
notifyItemChanged(indexOfGroup)
|
||||
val indexOfGroup = data?.indexOf(group)
|
||||
notifyItemChanged(indexOfGroup ?: 0)
|
||||
}
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,11 +56,11 @@ abstract class BaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(var taskTyp
|
|||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
val task = filteredContent!![position]
|
||||
return task.id!!.hashCode().toLong()
|
||||
val task = filteredContent?.get(position)
|
||||
return task?.id?.hashCode()?.toLong() ?: 0
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = if (filteredContent != null) filteredContent!!.size else 0
|
||||
override fun getItemCount(): Int =filteredContent?.size ?: 0
|
||||
|
||||
internal fun getContentView(parent: ViewGroup): View = getContentView(parent, layoutResource)
|
||||
|
||||
|
|
@ -71,14 +71,14 @@ abstract class BaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(var taskTyp
|
|||
if (taskType != task.type)
|
||||
return
|
||||
var i = 0
|
||||
while (i < this.content!!.size) {
|
||||
if (content!![i].id == task.id) {
|
||||
while (i < this.content?.size ?: 0) {
|
||||
if (content?.get(i)?.id == task.id) {
|
||||
break
|
||||
}
|
||||
++i
|
||||
}
|
||||
if (i < content!!.size) {
|
||||
content!![i] = task
|
||||
if (i < content?.size ?: 0) {
|
||||
content?.set(i, task)
|
||||
}
|
||||
filter()
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ abstract class BaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(var taskTyp
|
|||
|
||||
private fun loadContent(forced: Boolean) {
|
||||
if (this.content == null || forced) {
|
||||
taskRepository.getTasks(this.taskType, this.userID!!)
|
||||
taskRepository.getTasks(this.taskType, this.userID ?: "")
|
||||
.flatMap<Task> { Flowable.fromIterable(it) }
|
||||
.map { task ->
|
||||
task.parseMarkdown()
|
||||
|
|
@ -113,7 +113,7 @@ abstract class BaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(var taskTyp
|
|||
|
||||
fun setTasks(tasks: List<Task>) {
|
||||
this.content = ArrayList()
|
||||
this.content!!.addAll(tasks)
|
||||
this.content?.addAll(tasks)
|
||||
filter()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ class SkillsFragment : BaseMainFragment() {
|
|||
adapter?.mana = response.user.stats?.mp ?: 0.0
|
||||
val activity = activity ?: return
|
||||
if ("special" == usedSkill?.habitClass) {
|
||||
showSnackbar(activity.floatingMenuWrapper, context!!.getString(R.string.used_skill_without_mana, usedSkill.text), HabiticaSnackbar.SnackbarDisplayType.BLUE)
|
||||
showSnackbar(activity.floatingMenuWrapper, context?.getString(R.string.used_skill_without_mana, usedSkill.text), HabiticaSnackbar.SnackbarDisplayType.BLUE)
|
||||
} else {
|
||||
showSnackbar(activity.floatingMenuWrapper, null,
|
||||
context?.getString(R.string.used_skill_without_mana, usedSkill?.text),
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class ChatListFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
|
|||
if (savedInstanceState.containsKey("userId")) {
|
||||
this.userId = savedInstanceState.getString("userId")
|
||||
if (this.userId != null) {
|
||||
userRepository.getUser(userId!!).subscribe(Consumer { habitRPGUser -> this.user = habitRPGUser }, RxErrorHandler.handleEmptyError())
|
||||
userRepository.getUser().subscribe(Consumer { habitRPGUser -> this.user = habitRPGUser }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ class ChatListFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
refreshLayout.setOnRefreshListener(this)
|
||||
|
||||
layoutManager = recyclerView.layoutManager as LinearLayoutManager?
|
||||
layoutManager = recyclerView.layoutManager as? LinearLayoutManager
|
||||
|
||||
if (layoutManager == null) {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
|
|
@ -162,9 +162,9 @@ class ChatListFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
|
|||
}
|
||||
|
||||
private fun copyMessageToClipboard(chatMessage: ChatMessage) {
|
||||
val clipMan = activity!!.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clipMan = activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
|
||||
val messageText = ClipData.newPlainText("Chat message", chatMessage.text)
|
||||
clipMan.primaryClip = messageText
|
||||
clipMan?.primaryClip = messageText
|
||||
val activity = activity as MainActivity?
|
||||
if (activity != null) {
|
||||
showSnackbar(activity.floatingMenuWrapper, getString(R.string.chat_message_copied), SnackbarDisplayType.NORMAL)
|
||||
|
|
@ -202,16 +202,6 @@ class ChatListFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
|
|||
}
|
||||
}
|
||||
|
||||
private fun copyMessageAsTodo(chatMessage: ChatMessage) {
|
||||
val clipboard = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText(context?.getString(R.string.chat_message), chatMessage.text)
|
||||
clipboard.primaryClip = clip
|
||||
val activity = activity as MainActivity?
|
||||
if (activity != null) {
|
||||
HabiticaSnackbar.showSnackbar(activity.floatingMenuWrapper, getString(R.string.chat_message_copied), HabiticaSnackbar.SnackbarDisplayType.NORMAL)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
outState.putString("userId", this.userId)
|
||||
outState.putString("groupId", this.groupId)
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class GroupInformationFragment : BaseFragment() {
|
|||
qrCodeManager.setUpView(qrLayout)
|
||||
}
|
||||
|
||||
buttonPartyInviteAccept.setOnClickListener({
|
||||
buttonPartyInviteAccept.setOnClickListener {
|
||||
val userId = user?.invitations?.party?.id
|
||||
if (userId != null) {
|
||||
socialRepository.joinGroup(userId)
|
||||
|
|
@ -71,21 +71,21 @@ class GroupInformationFragment : BaseFragment() {
|
|||
.flatMap<List<Member>> { group1 -> socialRepository.retrieveGroupMembers(group1.id, true) }
|
||||
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
buttonPartyInviteReject.setOnClickListener({
|
||||
buttonPartyInviteReject.setOnClickListener {
|
||||
val userId = user?.invitations?.party?.id
|
||||
if (userId != null) {
|
||||
socialRepository.rejectGroupInvite(userId)
|
||||
.subscribe(Consumer { setInvitation(null) }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
userIdView.setOnClickListener {
|
||||
val clipboard = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clipboard = context?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
|
||||
val clip = ClipData.newPlainText(context?.getString(R.string.user_id), user?.id)
|
||||
clipboard.primaryClip = clip
|
||||
val activity = activity as MainActivity?
|
||||
clipboard?.primaryClip = clip
|
||||
val activity = activity as? MainActivity
|
||||
if (activity != null) {
|
||||
HabiticaSnackbar.showSnackbar(activity.floatingMenuWrapper, getString(R.string.id_copied), HabiticaSnackbar.SnackbarDisplayType.NORMAL)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,20 +83,21 @@ class GuildFragment : BaseMainFragment() {
|
|||
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
|
||||
if (this.activity != null && this.guild != null) {
|
||||
if (this.isMember) {
|
||||
if (this.user != null && this.user!!.id == this.guild!!.leaderID) {
|
||||
this.activity!!.menuInflater.inflate(R.menu.guild_admin, menu)
|
||||
if (this.user != null && this.user?.id == this.guild?.leaderID) {
|
||||
this.activity?.menuInflater?.inflate(R.menu.guild_admin, menu)
|
||||
} else {
|
||||
this.activity!!.menuInflater.inflate(R.menu.guild_member, menu)
|
||||
this.activity?.menuInflater?.inflate(R.menu.guild_member, menu)
|
||||
}
|
||||
} else {
|
||||
this.activity!!.menuInflater.inflate(R.menu.guild_nonmember, menu)
|
||||
this.activity?.menuInflater?.inflate(R.menu.guild_nonmember, menu)
|
||||
}
|
||||
}
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||
val id = item!!.itemId
|
||||
val id = item?.itemId
|
||||
|
||||
when (id) {
|
||||
R.id.menu_guild_join -> {
|
||||
|
|
@ -136,7 +137,7 @@ class GuildFragment : BaseMainFragment() {
|
|||
}
|
||||
1 -> {
|
||||
chatListFragment = ChatListFragment()
|
||||
chatListFragment!!.configure(this@GuildFragment.guildId!!, user, false)
|
||||
chatListFragment?.configure(this@GuildFragment.guildId ?: "", user, false)
|
||||
fragment = chatListFragment
|
||||
}
|
||||
else -> fragment = Fragment()
|
||||
|
|
@ -161,13 +162,13 @@ class GuildFragment : BaseMainFragment() {
|
|||
viewPager?.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||
if (position == 1 && this@GuildFragment.guild != null) {
|
||||
chatListFragment!!.setNavigatedToFragment(this@GuildFragment.guild!!.id)
|
||||
chatListFragment?.setNavigatedToFragment(this@GuildFragment.guild?.id ?: "")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPageSelected(position: Int) {
|
||||
if (position == 1 && this@GuildFragment.guild != null && chatListFragment != null) {
|
||||
chatListFragment!!.setNavigatedToFragment(this@GuildFragment.guild!!.id)
|
||||
chatListFragment?.setNavigatedToFragment(this@GuildFragment.guild?.id ?: "")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -198,12 +199,12 @@ class GuildFragment : BaseMainFragment() {
|
|||
when (requestCode) {
|
||||
GroupFormActivity.GROUP_FORM_ACTIVITY -> {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
val bundle = data!!.extras
|
||||
val bundle = data?.extras
|
||||
this.socialRepository.updateGroup(this.guild,
|
||||
bundle!!.getString("name"),
|
||||
bundle.getString("description"),
|
||||
bundle.getString("leader"),
|
||||
bundle.getString("privacy"))
|
||||
bundle?.getString("name"),
|
||||
bundle?.getString("description"),
|
||||
bundle?.getString("leader"),
|
||||
bundle?.getString("privacy"))
|
||||
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,11 +89,11 @@ class GuildsOverviewFragment : BaseMainFragment(), View.OnClickListener, SwipeRe
|
|||
}
|
||||
this.guildIDs = ArrayList()
|
||||
this.guildsListView?.removeAllViewsInLayout()
|
||||
val inflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
val inflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as? LayoutInflater
|
||||
for (guild in guilds) {
|
||||
val entry = inflater.inflate(R.layout.plain_list_item, this.guildsListView, false) as TextView
|
||||
entry.text = guild.name
|
||||
entry.setOnClickListener(this)
|
||||
val entry = inflater?.inflate(R.layout.plain_list_item, this.guildsListView, false) as? TextView
|
||||
entry?.text = guild.name
|
||||
entry?.setOnClickListener(this)
|
||||
this.guildsListView?.addView(entry)
|
||||
this.guildIDs?.add(guild.id)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,21 +84,21 @@ class InboxFragment : BaseMainFragment(), SwipeRefreshLayout.OnRefreshListener,
|
|||
assert(this.activity != null)
|
||||
this.chooseRecipientDialogView = this.activity?.layoutInflater?.inflate(R.layout.dialog_choose_message_recipient, null)
|
||||
|
||||
val scaneQRCodeButton = chooseRecipientDialogView?.findViewById<View>(R.id.scanQRCodeButton) as Button
|
||||
val scaneQRCodeButton = chooseRecipientDialogView?.findViewById<View>(R.id.scanQRCodeButton) as? Button
|
||||
|
||||
this.activity.notNull { thisActivity ->
|
||||
val alert = AlertDialog.Builder(thisActivity)
|
||||
.setTitle(getString(R.string.choose_recipient_title))
|
||||
.setPositiveButton(getString(R.string.action_continue)) { _, _ ->
|
||||
val uuidEditText = chooseRecipientDialogView?.findViewById<View>(R.id.uuidEditText) as EditText
|
||||
openInboxMessages(uuidEditText.text.toString(), "")
|
||||
val uuidEditText = chooseRecipientDialogView?.findViewById<View>(R.id.uuidEditText) as? EditText
|
||||
openInboxMessages(uuidEditText?.text?.toString() ?: "", "")
|
||||
}
|
||||
.setNeutralButton(getString(R.string.action_cancel)) { dialog, _ ->
|
||||
KeyboardUtil.dismissKeyboard(thisActivity)
|
||||
dialog.cancel()
|
||||
}
|
||||
.create()
|
||||
scaneQRCodeButton.setOnClickListener {
|
||||
scaneQRCodeButton?.setOnClickListener {
|
||||
val scanIntegrator = IntentIntegrator(getActivity())
|
||||
scanIntegrator.initiateScan(this)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,23 +136,23 @@ class InboxMessageListFragment : BaseMainFragment(), SwipeRefreshLayout.OnRefres
|
|||
}
|
||||
|
||||
private fun copyMessageToClipboard(chatMessage: ChatMessage) {
|
||||
val clipMan = getActivity()?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clipMan = getActivity()?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
|
||||
val messageText = ClipData.newPlainText("Chat message", chatMessage.text)
|
||||
clipMan.primaryClip = messageText
|
||||
val activity = getActivity() as MainActivity?
|
||||
clipMan?.primaryClip = messageText
|
||||
val activity = getActivity() as? MainActivity
|
||||
if (activity != null) {
|
||||
showSnackbar(activity.floatingMenuWrapper, getString(R.string.chat_message_copied), HabiticaSnackbar.SnackbarDisplayType.NORMAL)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showFlagConfirmationDialog(chatMessage: ChatMessage) {
|
||||
val builder = AlertDialog.Builder(getActivity()!!)
|
||||
val activity = getActivity() as? MainActivity ?: return
|
||||
val builder = AlertDialog.Builder(activity)
|
||||
builder.setMessage(R.string.chat_flag_confirmation)
|
||||
.setPositiveButton(R.string.flag_confirm) { _, _ ->
|
||||
socialRepository.flagMessage(chatMessage)
|
||||
.subscribe(Consumer {
|
||||
val activity = getActivity() as MainActivity?
|
||||
activity?.floatingMenuWrapper.notNull {
|
||||
activity.floatingMenuWrapper.notNull {
|
||||
showSnackbar(it, "Flagged message by " + chatMessage.user, HabiticaSnackbar.SnackbarDisplayType.NORMAL)
|
||||
}
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
|
|
|
|||
|
|
@ -72,14 +72,14 @@ class PublicGuildsFragment : BaseMainFragment(), SearchView.OnQueryTextListener
|
|||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
|
||||
inflater!!.inflate(R.menu.menu_public_guild, menu)
|
||||
inflater?.inflate(R.menu.menu_public_guild, menu)
|
||||
|
||||
val searchItem = menu!!.findItem(R.id.action_guild_search)
|
||||
val guildSearchView = searchItem.actionView as SearchView
|
||||
val theTextArea = guildSearchView.findViewById<SearchView.SearchAutoComplete>(R.id.search_src_text)
|
||||
theTextArea.setHintTextColor(ContextCompat.getColor(context!!, R.color.white))
|
||||
guildSearchView.queryHint = getString(R.string.guild_search_hint)
|
||||
guildSearchView.setOnQueryTextListener(this)
|
||||
val searchItem = menu?.findItem(R.id.action_guild_search)
|
||||
val guildSearchView = searchItem?.actionView as? SearchView
|
||||
val theTextArea = guildSearchView?.findViewById<SearchView.SearchAutoComplete>(R.id.search_src_text)
|
||||
context.notNull { theTextArea?.setHintTextColor(ContextCompat.getColor(it, R.color.white)) }
|
||||
guildSearchView?.queryHint = getString(R.string.guild_search_hint)
|
||||
guildSearchView?.setOnQueryTextListener(this)
|
||||
}
|
||||
|
||||
override fun onQueryTextSubmit(s: String): Boolean {
|
||||
|
|
|
|||
|
|
@ -166,8 +166,8 @@ class ChallengeDetailFragment: BaseMainFragment() {
|
|||
|
||||
private fun addHabits(habits: ArrayList<Task>) {
|
||||
val taskGroup = taskGrouplayout?.inflate(R.layout.dialog_challenge_detail_task_group)
|
||||
val groupName = taskGroup?.findViewById(R.id.task_group_name) as TextView?
|
||||
val tasksLayout = taskGroup?.findViewById(R.id.tasks_layout) as LinearLayout?
|
||||
val groupName = taskGroup?.findViewById(R.id.task_group_name) as? TextView
|
||||
val tasksLayout = taskGroup?.findViewById(R.id.tasks_layout) as? LinearLayout
|
||||
|
||||
groupName?.text = getLabelByTypeAndCount(Challenge.TASK_ORDER_HABITS, habits.size)
|
||||
taskGroup?.findViewById<TextView>(R.id.task_count_view)?.text = habits.size.toString()
|
||||
|
|
@ -176,7 +176,7 @@ class ChallengeDetailFragment: BaseMainFragment() {
|
|||
for (i in 0 until size) {
|
||||
val task = habits[i]
|
||||
val entry = tasksLayout?.inflate(R.layout.dialog_challenge_detail_habit)
|
||||
val habitTitle = entry?.findViewById(R.id.habit_title) as TextView?
|
||||
val habitTitle = entry?.findViewById(R.id.habit_title) as? TextView
|
||||
|
||||
entry?.findViewById<ImageView>(R.id.lock_icon_plus)?.setImageBitmap(HabiticaIconsHelper.imageOfLocked(Color.parseColor("#DFDEDF")))
|
||||
entry?.findViewById<ImageView>(R.id.lock_icon_minus)?.setImageBitmap(HabiticaIconsHelper.imageOfLocked(Color.parseColor("#DFDEDF")))
|
||||
|
|
@ -205,8 +205,8 @@ class ChallengeDetailFragment: BaseMainFragment() {
|
|||
|
||||
private fun addDailys(dailies: ArrayList<Task>) {
|
||||
val taskGroup = taskGrouplayout?.inflate(R.layout.dialog_challenge_detail_task_group)
|
||||
val groupName = taskGroup?.findViewById(R.id.task_group_name) as TextView?
|
||||
val tasksLayout = taskGroup?.findViewById(R.id.tasks_layout) as LinearLayout?
|
||||
val groupName = taskGroup?.findViewById(R.id.task_group_name) as? TextView
|
||||
val tasksLayout = taskGroup?.findViewById(R.id.tasks_layout) as? LinearLayout
|
||||
|
||||
val size = dailies.size
|
||||
groupName?.text = getLabelByTypeAndCount(Challenge.TASK_ORDER_DAILYS, size)
|
||||
|
|
@ -215,7 +215,7 @@ class ChallengeDetailFragment: BaseMainFragment() {
|
|||
for (i in 0 until size) {
|
||||
val task = dailies[i]
|
||||
val entry = tasksLayout?.inflate(R.layout.dialog_challenge_detail_daily)
|
||||
val title = entry?.findViewById(R.id.daily_title) as TextView?
|
||||
val title = entry?.findViewById(R.id.daily_title) as? TextView?
|
||||
title?.text = EmojiParser.parseEmojis(task.text)
|
||||
entry?.findViewById<ImageView>(R.id.lock_icon)?.setImageBitmap(HabiticaIconsHelper.imageOfLocked(Color.parseColor("#949494")))
|
||||
context.notNull {
|
||||
|
|
@ -229,7 +229,7 @@ class ChallengeDetailFragment: BaseMainFragment() {
|
|||
|
||||
checklistIndicatorWrapper?.visibility = View.VISIBLE
|
||||
|
||||
val checkListAllTextView = entry?.findViewById<View>(R.id.checkListAllTextView) as TextView?
|
||||
val checkListAllTextView = entry?.findViewById<View>(R.id.checkListAllTextView) as? TextView
|
||||
checkListAllTextView?.text = task.checklist?.size.toString()
|
||||
}
|
||||
tasksLayout?.addView(entry)
|
||||
|
|
@ -239,8 +239,8 @@ class ChallengeDetailFragment: BaseMainFragment() {
|
|||
|
||||
private fun addTodos(todos: ArrayList<Task>) {
|
||||
val taskGroup = taskGrouplayout?.inflate(R.layout.dialog_challenge_detail_task_group)
|
||||
val groupName = taskGroup?.findViewById(R.id.task_group_name) as TextView?
|
||||
val tasksLayout = taskGroup?.findViewById(R.id.tasks_layout) as LinearLayout?
|
||||
val groupName = taskGroup?.findViewById(R.id.task_group_name) as? TextView
|
||||
val tasksLayout = taskGroup?.findViewById(R.id.tasks_layout) as? LinearLayout
|
||||
|
||||
val size = todos.size
|
||||
groupName?.text = getLabelByTypeAndCount(Challenge.TASK_ORDER_TODOS, size)
|
||||
|
|
@ -249,7 +249,7 @@ class ChallengeDetailFragment: BaseMainFragment() {
|
|||
for (i in 0 until size) {
|
||||
val task = todos[i]
|
||||
val entry = tasksLayout?.inflate(R.layout.dialog_challenge_detail_todo)
|
||||
val title = entry?.findViewById(R.id.todo_title) as TextView?
|
||||
val title = entry?.findViewById(R.id.todo_title) as? TextView
|
||||
title?.text = EmojiParser.parseEmojis(task.text)
|
||||
entry?.findViewById<ImageView>(R.id.lock_icon)?.setImageBitmap(HabiticaIconsHelper.imageOfLocked(Color.parseColor("#949494")))
|
||||
context.notNull {
|
||||
|
|
@ -264,7 +264,7 @@ class ChallengeDetailFragment: BaseMainFragment() {
|
|||
|
||||
checklistIndicatorWrapper?.visibility = View.VISIBLE
|
||||
|
||||
val checkListAllTextView = entry?.findViewById<View>(R.id.checkListAllTextView) as TextView?
|
||||
val checkListAllTextView = entry?.findViewById<View>(R.id.checkListAllTextView) as? TextView
|
||||
checkListAllTextView?.text = task.checklist?.size.toString()
|
||||
}
|
||||
tasksLayout?.addView(entry)
|
||||
|
|
@ -274,9 +274,9 @@ class ChallengeDetailFragment: BaseMainFragment() {
|
|||
|
||||
private fun addRewards(rewards: ArrayList<Task>) {
|
||||
val taskGroup = taskGrouplayout?.inflate(R.layout.dialog_challenge_detail_task_group)
|
||||
val groupName = taskGroup?.findViewById(R.id.task_group_name) as TextView?
|
||||
val groupName = taskGroup?.findViewById(R.id.task_group_name) as? TextView
|
||||
|
||||
val tasksLayout = taskGroup?.findViewById(R.id.tasks_layout) as LinearLayout?
|
||||
val tasksLayout = taskGroup?.findViewById(R.id.tasks_layout) as? LinearLayout
|
||||
|
||||
val size = rewards.size
|
||||
groupName?.text = getLabelByTypeAndCount(Challenge.TASK_ORDER_REWARDS, size)
|
||||
|
|
@ -286,8 +286,8 @@ class ChallengeDetailFragment: BaseMainFragment() {
|
|||
val task = rewards[i]
|
||||
|
||||
val entry = tasksLayout?.inflate(R.layout.dialog_challenge_detail_reward)
|
||||
(entry?.findViewById<View>(R.id.gold_icon) as ImageView?)?.setImageBitmap(HabiticaIconsHelper.imageOfGold())
|
||||
val title = entry?.findViewById<View>(R.id.reward_title) as TextView?
|
||||
(entry?.findViewById<View>(R.id.gold_icon) as? ImageView)?.setImageBitmap(HabiticaIconsHelper.imageOfGold())
|
||||
val title = entry?.findViewById<View>(R.id.reward_title) as? TextView
|
||||
title?.text = EmojiParser.parseEmojis(task.text)
|
||||
tasksLayout?.addView(entry)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ class ChallengeListFragment : BaseMainFragment(), SwipeRefreshLayout.OnRefreshLi
|
|||
inflater?.inflate(R.menu.menu_list_challenges, menu)
|
||||
|
||||
|
||||
val badgeLayout = MenuItemCompat.getActionView(menu!!.findItem(R.id.action_search)) as RelativeLayout?
|
||||
val badgeLayout = MenuItemCompat.getActionView(menu?.findItem(R.id.action_search)) as? RelativeLayout
|
||||
if (badgeLayout != null) {
|
||||
val filterCountTextView = badgeLayout.findViewById<TextView>(R.id.badge_textview)
|
||||
filterCountTextView.text = null
|
||||
|
|
@ -167,6 +167,7 @@ class ChallengeListFragment : BaseMainFragment(), SwipeRefreshLayout.OnRefreshLi
|
|||
challengeAdapter?.filter(challengeFilterOptions)
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
|
|
|
|||
|
|
@ -64,12 +64,11 @@ class ChallengesOverviewFragment : BaseMainFragment() {
|
|||
override fun getItem(position: Int): Fragment? {
|
||||
val fragment = Fragment()
|
||||
|
||||
when (position) {
|
||||
0 -> return userChallengesFragment
|
||||
1 -> return availableChallengesFragment
|
||||
return when (position) {
|
||||
0 -> userChallengesFragment
|
||||
1 -> availableChallengesFragment
|
||||
else -> fragment
|
||||
}
|
||||
|
||||
return fragment
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
|
|
@ -77,11 +76,11 @@ class ChallengesOverviewFragment : BaseMainFragment() {
|
|||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
when (position) {
|
||||
0 -> return getString(R.string.my_challenges)
|
||||
1 -> return getString(R.string.public_challenges)
|
||||
return when (position) {
|
||||
0 -> getString(R.string.my_challenges)
|
||||
1 -> getString(R.string.public_challenges)
|
||||
else -> ""
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
viewPager?.adapter = statePagerAdapter
|
||||
|
|
|
|||
|
|
@ -189,14 +189,14 @@ class PartyDetailFragment : BaseFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
fun inviteNewQuest() {
|
||||
private fun inviteNewQuest() {
|
||||
val fragment = ItemRecyclerFragment()
|
||||
fragment.itemType = "quests"
|
||||
fragment.itemTypeText = getString(R.string.quest)
|
||||
fragment.show(fragmentManager, "questDialog")
|
||||
}
|
||||
|
||||
fun leaveParty() {
|
||||
private fun leaveParty() {
|
||||
val builder = AlertDialog.Builder(activity)
|
||||
.setMessage(R.string.leave_party_confirmation)
|
||||
.setPositiveButton(R.string.yes) { _, _ ->
|
||||
|
|
@ -206,14 +206,14 @@ class PartyDetailFragment : BaseFragment() {
|
|||
builder.show()
|
||||
}
|
||||
|
||||
fun onQuestAccept() {
|
||||
private fun onQuestAccept() {
|
||||
partyId.notNull {
|
||||
socialRepository.acceptQuest(user, it).subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun onQuestReject() {
|
||||
private fun onQuestReject() {
|
||||
partyId.notNull {
|
||||
socialRepository.rejectQuest(user, it).subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
|
|
@ -240,7 +240,7 @@ class PartyDetailFragment : BaseFragment() {
|
|||
fragment.questKey = party?.quest?.key
|
||||
}
|
||||
if (activity != null) {
|
||||
val activity = activity as MainActivity?
|
||||
val activity = activity as? MainActivity
|
||||
activity?.displayFragment(fragment)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,16 +120,17 @@ class PartyFragment : BaseMainFragment() {
|
|||
|
||||
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
|
||||
if (this.group != null && this.user != null) {
|
||||
if (this.group!!.leaderID == this.user!!.id) {
|
||||
inflater!!.inflate(R.menu.menu_party_admin, menu)
|
||||
if (this.group?.leaderID == this.user?.id) {
|
||||
inflater?.inflate(R.menu.menu_party_admin, menu)
|
||||
} else {
|
||||
inflater!!.inflate(R.menu.menu_party, menu)
|
||||
inflater?.inflate(R.menu.menu_party, menu)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||
val id = item!!.itemId
|
||||
val id = item?.itemId
|
||||
|
||||
when (id) {
|
||||
R.id.menu_invite_item -> {
|
||||
|
|
@ -147,7 +148,7 @@ class PartyFragment : BaseMainFragment() {
|
|||
.setMessage(context?.getString(R.string.leave_party_confirmation))
|
||||
.setPositiveButton(context?.getString(R.string.yes)) { _, _ ->
|
||||
if (this.group != null) {
|
||||
this.socialRepository.leaveGroup(this.group!!.id)
|
||||
this.socialRepository.leaveGroup(this.group?.id ?: "")
|
||||
.subscribe(Consumer { activity?.supportFragmentManager?.beginTransaction()?.remove(this@PartyFragment)?.commit() }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
}
|
||||
|
|
@ -162,10 +163,10 @@ class PartyFragment : BaseMainFragment() {
|
|||
|
||||
private fun displayEditForm() {
|
||||
val bundle = Bundle()
|
||||
bundle.putString("groupID", if (this.group != null) this.group!!.id else null)
|
||||
bundle.putString("name", this.group!!.name)
|
||||
bundle.putString("description", this.group!!.description)
|
||||
bundle.putString("leader", this.group!!.leaderID)
|
||||
bundle.putString("groupID", group?.id)
|
||||
bundle.putString("name", this.group?.name)
|
||||
bundle.putString("description", this.group?.description)
|
||||
bundle.putString("leader", this.group?.leaderID)
|
||||
|
||||
val intent = Intent(activity, GroupFormActivity::class.java)
|
||||
intent.putExtras(bundle)
|
||||
|
|
@ -178,12 +179,14 @@ class PartyFragment : BaseMainFragment() {
|
|||
when (requestCode) {
|
||||
GroupFormActivity.GROUP_FORM_ACTIVITY -> {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
val needsSaving = false
|
||||
val bundle = data!!.extras
|
||||
val bundle = data?.extras
|
||||
if (this.group == null) {
|
||||
return
|
||||
}
|
||||
this.socialRepository.updateGroup(this.group, bundle!!.getString("name"), bundle.getString("description"), bundle.getString("leader"), bundle.getString("privacy"))
|
||||
this.socialRepository.updateGroup(this.group, bundle?.getString("name"),
|
||||
bundle?.getString("description"),
|
||||
bundle?.getString("leader"),
|
||||
bundle?.getString("privacy"))
|
||||
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
}
|
||||
|
|
@ -191,7 +194,7 @@ class PartyFragment : BaseMainFragment() {
|
|||
if (resultCode == Activity.RESULT_OK) {
|
||||
val inviteData = HashMap<String, Any>()
|
||||
inviteData["inviter"] = user?.profile?.name ?: ""
|
||||
if (data!!.getBooleanExtra(PartyInviteActivity.IS_EMAIL_KEY, false)) {
|
||||
if (data?.getBooleanExtra(PartyInviteActivity.IS_EMAIL_KEY, false) == true) {
|
||||
val emails = data.getStringArrayExtra(PartyInviteActivity.EMAILS_KEY)
|
||||
val invites = ArrayList<HashMap<String, String>>()
|
||||
for (email in emails) {
|
||||
|
|
@ -202,13 +205,13 @@ class PartyFragment : BaseMainFragment() {
|
|||
}
|
||||
inviteData["emails"] = invites
|
||||
} else {
|
||||
val userIDs = data.getStringArrayExtra(PartyInviteActivity.USER_IDS_KEY)
|
||||
val userIDs = data?.getStringArrayExtra(PartyInviteActivity.USER_IDS_KEY)
|
||||
val invites = ArrayList<String>()
|
||||
Collections.addAll(invites, *userIDs)
|
||||
inviteData["uuids"] = invites
|
||||
}
|
||||
if (this.group != null) {
|
||||
this.socialRepository.inviteToGroup(this.group!!.id, inviteData)
|
||||
this.socialRepository.inviteToGroup(this.group?.id ?: "", inviteData)
|
||||
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
}
|
||||
|
|
@ -222,8 +225,6 @@ class PartyFragment : BaseMainFragment() {
|
|||
return
|
||||
}
|
||||
|
||||
val party = this.user!!.party ?: return
|
||||
|
||||
viewPagerAdapter = object : FragmentPagerAdapter(fragmentManager) {
|
||||
|
||||
override fun getItem(position: Int): Fragment? {
|
||||
|
|
@ -232,7 +233,7 @@ class PartyFragment : BaseMainFragment() {
|
|||
|
||||
when (position) {
|
||||
0 -> {
|
||||
if (user!!.hasParty()) {
|
||||
if (user?.hasParty() == true) {
|
||||
val detailFragment = PartyDetailFragment()
|
||||
detailFragment.partyId = user?.party?.id
|
||||
fragment = detailFragment
|
||||
|
|
@ -273,12 +274,12 @@ class PartyFragment : BaseMainFragment() {
|
|||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
when (position) {
|
||||
0 -> return context!!.getString(R.string.party)
|
||||
1 -> return context!!.getString(R.string.chat)
|
||||
2 -> return context!!.getString(R.string.members)
|
||||
}
|
||||
return ""
|
||||
return when (position) {
|
||||
0 -> context?.getString(R.string.party)
|
||||
1 -> context?.getString(R.string.chat)
|
||||
2 -> context?.getString(R.string.members)
|
||||
else -> ""
|
||||
} ?: ""
|
||||
}
|
||||
}
|
||||
this.viewPager?.adapter = viewPagerAdapter
|
||||
|
|
@ -286,13 +287,13 @@ class PartyFragment : BaseMainFragment() {
|
|||
viewPager?.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||
if (position == 1 && group != null) {
|
||||
chatListFragment?.setNavigatedToFragment(group!!.id)
|
||||
chatListFragment?.setNavigatedToFragment(group?.id ?: "")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPageSelected(position: Int) {
|
||||
if (position == 1 && group != null) {
|
||||
chatListFragment?.setNavigatedToFragment(group!!.id)
|
||||
chatListFragment?.setNavigatedToFragment(group?.id ?: "")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ class PartyInviteFragment : BaseFragment() {
|
|||
get() {
|
||||
val values = ArrayList<String>()
|
||||
for (i in 0 until (invitationWrapper?.childCount ?: 0)) {
|
||||
val valueEditText = invitationWrapper?.getChildAt(i) as EditText
|
||||
if (valueEditText.text.toString().isNotEmpty()) {
|
||||
val valueEditText = invitationWrapper?.getChildAt(i) as? EditText
|
||||
if (valueEditText?.text?.toString()?.isNotEmpty() == true) {
|
||||
values.add(valueEditText.text.toString())
|
||||
}
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ class PartyInviteFragment : BaseFragment() {
|
|||
component.inject(this)
|
||||
}
|
||||
|
||||
fun addInviteField() {
|
||||
private fun addInviteField() {
|
||||
val editText = EditText(context)
|
||||
|
||||
if (isEmailInvite) {
|
||||
|
|
@ -76,7 +76,7 @@ class PartyInviteFragment : BaseFragment() {
|
|||
invitationWrapper?.addView(editText)
|
||||
}
|
||||
|
||||
fun startQRInvite() {
|
||||
private fun startQRInvite() {
|
||||
val scanIntegrator = IntentIntegrator(activity)
|
||||
scanIntegrator.initiateScan()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class PartyMemberListFragment : BaseFragment() {
|
|||
|
||||
private fun refreshMembers() {
|
||||
setRefreshing(true)
|
||||
socialRepository.retrieveGroupMembers(partyId!!, true).doOnComplete { setRefreshing(false) }.subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
|
||||
socialRepository.retrieveGroupMembers(partyId ?: "", true).doOnComplete { setRefreshing(false) }.subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
|
||||
private fun setRefreshing(isRefreshing: Boolean) {
|
||||
|
|
@ -76,7 +76,7 @@ class PartyMemberListFragment : BaseFragment() {
|
|||
if (partyId == null) {
|
||||
return
|
||||
}
|
||||
socialRepository.getGroupMembers(partyId!!).firstElement().subscribe(Consumer { users ->
|
||||
socialRepository.getGroupMembers(partyId ?: "").firstElement().subscribe(Consumer { users ->
|
||||
adapter?.updateData(users)
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12918,7 +12918,6 @@ class PaintCodeDashPathEffect {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
class PaintCodeStaticLayout {
|
||||
private StaticLayout layout;
|
||||
private int width;
|
||||
|
|
|
|||
20
detekt.yml
20
detekt.yml
|
|
@ -150,14 +150,14 @@ complexity:
|
|||
ComplexMethod:
|
||||
threshold: 10
|
||||
TooManyFunctions:
|
||||
threshold: 10
|
||||
threshold: 40
|
||||
ComplexCondition:
|
||||
threshold: 3
|
||||
threshold: 5
|
||||
LabeledExpression:
|
||||
active: false
|
||||
StringLiteralDuplication:
|
||||
active: true
|
||||
threshold: 2
|
||||
threshold: 4
|
||||
ignoreAnnotation: true
|
||||
excludeStringsWithLessThan5Characters: true
|
||||
ignoreStringsRegex: '$^'
|
||||
|
|
@ -210,13 +210,13 @@ formatting:
|
|||
autoCorrect: true
|
||||
ExpressionBodySyntax:
|
||||
active: false
|
||||
autoCorrect: false
|
||||
autoCorrect: true
|
||||
ExpressionBodySyntaxLineBreaks:
|
||||
active: false
|
||||
autoCorrect: false
|
||||
autoCorrect: true
|
||||
OptionalReturnKeyword:
|
||||
active: true
|
||||
autoCorrect: false
|
||||
autoCorrect: true
|
||||
|
||||
style:
|
||||
active: true
|
||||
|
|
@ -242,17 +242,17 @@ style:
|
|||
ModifierOrder:
|
||||
active: true
|
||||
MagicNumber:
|
||||
active: true
|
||||
active: false
|
||||
ignoreNumbers: '-1,0,1,2'
|
||||
ignoreHashCodeFunction: false
|
||||
ignorePropertyDeclaration: false
|
||||
ignorePropertyDeclaration: true
|
||||
ignoreAnnotation: false
|
||||
WildcardImport:
|
||||
active: true
|
||||
active: false
|
||||
SafeCast:
|
||||
active: true
|
||||
MaxLineLength:
|
||||
active: true
|
||||
active: false
|
||||
maxLineLength: 120
|
||||
excludePackageStatements: false
|
||||
excludeImportStatements: false
|
||||
|
|
|
|||
Loading…
Reference in a new issue