From 2c0b8ac6f533aadffb71967ee019e3f4aa7dfd46 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 1 Dec 2020 01:16:54 +0300 Subject: [PATCH] Fix some issues after merge --- .../com/keylesspalace/tusky/MainActivity.kt | 4 +- .../announcements/AnnouncementsViewModel.kt | 3 +- .../components/compose/ComposeViewModel.kt | 97 ------------------- .../com/keylesspalace/tusky/entity/Emoji.kt | 1 + .../tusky/entity/Relationship.kt | 2 +- 5 files changed, 7 insertions(+), 100 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt b/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt index 9e7b04d2..3e2d4d64 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt @@ -225,11 +225,12 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje is ProfileEditedEvent -> onFetchUserInfoSuccess(event.newProfileData) is MainTabsChangedEvent -> setupTabs(false) is PreferenceChangedEvent -> { - when(event.preferenceKey) { + when (event.preferenceKey) { PrefKeys.LIVE_NOTIFICATIONS -> { initPullNotifications() } } + } is AnnouncementReadEvent -> { unreadAnnouncementsCount-- updateAnnouncementsBadge() @@ -241,6 +242,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje // Flush old media that was cached for sharing deleteStaleCachedMedia(applicationContext.getExternalFilesDir("Husky")) } + } private fun initPullNotifications() { if (NotificationHelper.areNotificationsEnabled(this, accountManager)) { diff --git a/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsViewModel.kt index 964cc739..b2aa7787 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsViewModel.kt @@ -61,7 +61,8 @@ class AnnouncementsViewModel @Inject constructor( either.asRight().maxTootChars, either.asRight().pollLimits?.maxOptions, either.asRight().pollLimits?.maxOptionChars, - either.asRight().version + either.asRight().version, + either.asRight().chatLimit ) } .doOnSuccess { diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeViewModel.kt index dcd93685..43c94797 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeViewModel.kt @@ -81,105 +81,8 @@ class ComposeViewModel val poll: MutableLiveData = mutableLiveData(null) val scheduledAt: MutableLiveData = mutableLiveData(null) - val media = mutableLiveData>(listOf()) - val uploadError = MutableLiveData() - - private val mediaToDisposable = mutableMapOf() - private val isEditingScheduledToot get() = !scheduledTootUid.isNullOrEmpty() - init { - - Singles.zip(api.getCustomEmojis(), api.getInstance()) { emojis, instance -> - InstanceEntity( - instance = accountManager.activeAccount?.domain!!, - emojiList = emojis, - maximumTootCharacters = instance.maxTootChars, - maxPollOptions = instance.pollLimits?.maxOptions, - maxPollOptionLength = instance.pollLimits?.maxOptionChars, - version = instance.version - ) - } - .doOnSuccess { - db.instanceDao().insertOrReplace(it) - } - .onErrorResumeNext( - db.instanceDao().loadMetadataForInstance(accountManager.activeAccount?.domain!!) - ) - .subscribe ({ instanceEntity -> - emoji.postValue(instanceEntity.emojiList) - instance.postValue(instanceEntity) - }, { throwable -> - // this can happen on network error when no cached data is available - Log.w(TAG, "error loading instance data", throwable) - }) - .autoDispose() - } - - fun pickMedia(uri: Uri): LiveData> { - // We are not calling .toLiveData() here because we don't want to stop the process when - // the Activity goes away temporarily (like on screen rotation). - val liveData = MutableLiveData>() - mediaUploader.prepareMedia(uri) - .map { (type, uri, size) -> - val mediaItems = media.value!! - if (type != QueuedMedia.Type.IMAGE - && mediaItems.isNotEmpty() - && mediaItems[0].type == QueuedMedia.Type.IMAGE) { - throw VideoOrImageException() - } else { - addMediaToQueue(type, uri, size) - } - } - .subscribe({ queuedMedia -> - liveData.postValue(Either.Right(queuedMedia)) - }, { error -> - liveData.postValue(Either.Left(error)) - }) - .autoDispose() - return liveData - } - - private fun addMediaToQueue(type: QueuedMedia.Type, uri: Uri, mediaSize: Long): QueuedMedia { - val mediaItem = QueuedMedia(System.currentTimeMillis(), uri, type, mediaSize) - media.value = media.value!! + mediaItem - mediaToDisposable[mediaItem.localId] = mediaUploader - .uploadMedia(mediaItem) - .subscribe ({ event -> - val item = media.value?.find { it.localId == mediaItem.localId } - ?: return@subscribe - val newMediaItem = when (event) { - is UploadEvent.ProgressEvent -> - item.copy(uploadPercent = event.percentage) - is UploadEvent.FinishedEvent -> - item.copy(id = event.attachment.id, uploadPercent = -1) - } - synchronized(media) { - val mediaValue = media.value!! - val index = mediaValue.indexOfFirst { it.localId == newMediaItem.localId } - media.postValue(if (index == -1) { - mediaValue + newMediaItem - } else { - mediaValue.toMutableList().also { it[index] = newMediaItem } - }) - } - }, { error -> - media.postValue(media.value?.filter { it.localId != mediaItem.localId } ?: emptyList()) - uploadError.postValue(error) - }) - return mediaItem - } - - private fun addUploadedMedia(id: String, type: QueuedMedia.Type, uri: Uri, description: String?) { - val mediaItem = QueuedMedia(System.currentTimeMillis(), uri, type, 0, -1, id, description) - media.value = media.value!! + mediaItem - } - - fun removeMediaFromQueue(item: QueuedMedia) { - mediaToDisposable[item.localId]?.dispose() - media.value = media.value!!.withoutFirstWhich { it.localId == item.localId } - } - fun didChange(content: String?, contentWarning: String?): Boolean { val textChanged = !(content.isNullOrEmpty() diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/Emoji.kt b/app/src/main/java/com/keylesspalace/tusky/entity/Emoji.kt index 7fabed98..029b392d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/entity/Emoji.kt +++ b/app/src/main/java/com/keylesspalace/tusky/entity/Emoji.kt @@ -20,6 +20,7 @@ import android.os.Parcelable import com.google.gson.annotations.SerializedName import kotlinx.android.parcel.Parcelize +@Parcelize data class Emoji( val shortcode: String, val url: String, diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/Relationship.kt b/app/src/main/java/com/keylesspalace/tusky/entity/Relationship.kt index cdbc3e81..e90c642f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/entity/Relationship.kt +++ b/app/src/main/java/com/keylesspalace/tusky/entity/Relationship.kt @@ -26,6 +26,6 @@ data class Relationship ( val requested: Boolean, @SerializedName("showing_reblogs") val showingReblogs: Boolean, val subscribing: Boolean? = null, // Pleroma extension - @SerializedName("domain_blocking") val blockingDomain: Boolean + @SerializedName("domain_blocking") val blockingDomain: Boolean, val note: String? // nullable for backward compatibility / feature detection )