Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
  • Loading branch information
rapterjet2004 committed Oct 23, 2024
1 parent 39305d7 commit 46efdf4
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ class ConversationInfoActivity :
}
}

if (!spreedCapabilities.features!!.contains(ARCHIVED_CONVERSATIONS)) {
if (!CapabilitiesUtil.isArchiveConversationsAvailable(spreedCapabilities)) {
binding.archiveConversationBtn.visibility = GONE
}

Expand All @@ -750,19 +750,23 @@ class ConversationInfoActivity :
viewModel.unarchiveConversation(conversationUser, conversationToken)
binding.archiveConversationIcon.setImageDrawable(resources.getDrawable(R.drawable.outline_archive_24))
binding.archiveConversationText.text = resources.getString(R.string.archive_conversation)
binding.archiveConversationTextHint.text = resources.getString(R.string.archive_hint)
} else {
viewModel.archiveConversation(conversationUser, conversationToken)
binding.archiveConversationIcon.setImageDrawable(resources.getDrawable(R.drawable.ic_eye))
binding.archiveConversationText.text = resources.getString(R.string.unarchive_conversation)
binding.archiveConversationTextHint.text = resources.getString(R.string.unarchive_hint)
}
}

if (conversation!!.hasArchived) {
binding.archiveConversationIcon.setImageDrawable(resources.getDrawable(R.drawable.ic_eye))
binding.archiveConversationText.text = resources.getString(R.string.unarchive_conversation)
binding.archiveConversationTextHint.text = resources.getString(R.string.unarchive_hint)
} else {
binding.archiveConversationIcon.setImageDrawable(resources.getDrawable(R.drawable.outline_archive_24))
binding.archiveConversationText.text = resources.getString(R.string.archive_conversation)
binding.archiveConversationTextHint.text = resources.getString(R.string.archive_hint)
}

if (!isDestroyed) {
Expand Down Expand Up @@ -1469,7 +1473,6 @@ class ConversationInfoActivity :
private const val DEMOTE_OR_PROMOTE = 1
private const val REMOVE_FROM_CONVERSATION = 2
private const val BAN_FROM_CONVERSATION = 3
private const val ARCHIVED_CONVERSATIONS = "archived-conversations"
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ class ConversationInfoViewModel @Inject constructor(
}

override fun onError(e: Throwable) {
Log.d("Julius", "Error in archive $e")
Log.d(TAG, "Error in archive $e")
}

override fun onComplete() {
// unused atm
}

override fun onNext(n: GenericOverall) {
Log.d("Julius", "Archived successful")
Log.d(TAG, "Archived successful")
}
})
}
Expand All @@ -239,15 +239,15 @@ class ConversationInfoViewModel @Inject constructor(
}

override fun onError(e: Throwable) {
Log.d("Julius", "Error in unarchive $e")
Log.d(TAG, "Error in unarchive $e")
}

override fun onComplete() {
// unused atm
}

override fun onNext(n: GenericOverall) {
Log.d("Julius", "unArchived successful")
Log.d(TAG, "unArchived successful")
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class ConversationsListActivity :
sortConversations(conversationItemsWithHeader)

// Filter Conversations
if (!containsTrue()) filterableConversationItems = conversationItems
if (!hasFilterEnabled()) filterableConversationItems = conversationItems
filterConversation()
adapter!!.updateDataSet(filterableConversationItems, false)
Handler().postDelayed({ checkToShowUnreadBubble() }, UNREAD_BUBBLE_DELAY.toLong())
Expand All @@ -397,7 +397,7 @@ class ConversationsListActivity :
}
}

private fun containsTrue(): Boolean {
private fun hasFilterEnabled(): Boolean {
for ((k, v) in filterState) {
if (k != FilterConversationFragment.DEFAULT && v) return true
}
Expand Down Expand Up @@ -473,7 +473,7 @@ class ConversationsListActivity :
}
}

Log.d("Julius", "Conversation: ${conversation.name} Result: $result")
Log.d(TAG, "Conversation: ${conversation.name} Result: $result")
return result
}

Expand Down Expand Up @@ -670,7 +670,7 @@ class ConversationsListActivity :
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
initSearchDisposable()
adapter!!.setHeadersShown(true)
if (!containsTrue()) filterableConversationItems = searchableConversationItems
if (!hasFilterEnabled()) filterableConversationItems = searchableConversationItems
adapter!!.updateDataSet(filterableConversationItems, false)
adapter!!.showAllHeaders()
binding.swipeRefreshLayoutView?.isEnabled = false
Expand All @@ -680,7 +680,7 @@ class ConversationsListActivity :

override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
adapter!!.setHeadersShown(false)
if (!containsTrue()) filterableConversationItems = conversationItemsWithHeader
if (!hasFilterEnabled()) filterableConversationItems = conversationItemsWithHeader
adapter!!.updateDataSet(filterableConversationItems, false)
adapter!!.hideAllHeaders()
if (searchHelper != null) {
Expand Down Expand Up @@ -1847,7 +1847,7 @@ class ConversationsListActivity :
}

fun updateFilterConversationButtonColor() {
if (containsTrue()) {
if (hasFilterEnabled()) {
binding.filterConversationsButton.let { viewThemeUtils.platform.colorImageView(it, ColorRole.PRIMARY) }
} else {
binding.filterConversationsButton.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ object Migrations {
}
}

val MIGRATION_11_12 = object : Migration(11, 12) {
override fun migrate(db: SupportSQLiteDatabase) {
Log.i("Migrations", "Migrating 11 to 12")
addArchiveConversations(db)
}
}

fun migrateToRoom(db: SupportSQLiteDatabase) {
db.execSQL(
"CREATE TABLE User_new (" +
Expand Down Expand Up @@ -237,4 +244,16 @@ object Migrations {
"ON `ChatBlocks` (`internalConversationId`)"
)
}

fun addArchiveConversations(db: SupportSQLiteDatabase) {

try {
db.execSQL(
"ALTER TABLE Conversations " +
"ADD `hasArchived` INTEGER;"
)
} catch (e: Exception) {
Log.i("Migrations", "hasArchived already exists")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ import java.util.Locale
ChatMessageEntity::class,
ChatBlockEntity::class
],
version = 11,
version = 12,
autoMigrations = [
AutoMigration(from = 9, to = 10)
AutoMigration(from = 9, to = 11)
],
exportSchema = true
)
Expand Down Expand Up @@ -113,7 +113,8 @@ abstract class TalkDatabase : RoomDatabase() {
Migrations.MIGRATION_6_8,
Migrations.MIGRATION_7_8,
Migrations.MIGRATION_8_9,
Migrations.MIGRATION_10_11
Migrations.MIGRATION_10_11,
Migrations.MIGRATION_11_12
)
.allowMainThreadQueries()
.addCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ enum class SpreedFeatures(val value: String) {
FEDERATION_V1("federation-v1"),
DELETE_MESSAGES_UNLIMITED("delete-messages-unlimited"),
BAN_V1("ban-v1"),
EDIT_MESSAGES_NOTE_TO_SELF("edit-messages-note-to-self")
EDIT_MESSAGES_NOTE_TO_SELF("edit-messages-note-to-self"),
ARCHIVE_CONVERSATIONS("archived-conversations")
}

@Suppress("TooManyFunctions")
Expand Down Expand Up @@ -255,6 +256,10 @@ object CapabilitiesUtil {
user.capabilities!!.spreedCapability!!.config!!["federation"]!!.containsKey("enabled")
}

fun isArchiveConversationsAvailable(spreedCapabilities: SpreedCapability): Boolean {
return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.ARCHIVE_CONVERSATIONS)
}

// endregion

//region ThemingCapabilities
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_conversation_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@

</LinearLayout>

<com.google.android.material.textview.MaterialTextView
android:id="@+id/archive_conversation_text_hint"
android:layout_marginHorizontal="@dimen/standard_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/archive_hint" />

<LinearLayout
android:id="@+id/danger_zone_options"
android:layout_width="match_parent"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -818,4 +818,6 @@ How to translate with transifex:
<string name="archive_conversation">Archive Conversation</string>
<string name="unarchive_conversation">Unarchive Conversation</string>
<string name="archived">Archived</string>
<string name="archive_hint">Once a conversation is archived, it will be hidden by default. Select the filter \'Archived\' to view archived conversations. Direct mentions will still be received.</string>
<string name="unarchive_hint">Once a conversation is unarchived, it will be shown by default again.</string>
</resources>

0 comments on commit 46efdf4

Please sign in to comment.