Skip to content

Commit c429d0f

Browse files
committed
Hide filenames for media in chat.
Added setting to always show filenames. Signed-off-by: Jens Zalzala <jens@shakingearthdigital.com>
1 parent 48c6cc0 commit c429d0f

9 files changed

Lines changed: 82 additions & 4 deletions

File tree

app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ class ChatActivity :
619619
isOneToOneConversation = isOneToOneConversation,
620620
conversationThreadId = conversationThreadId,
621621
hasChatPermission = this::participantPermissions.isInitialized &&
622-
participantPermissions.hasChatPermission()
622+
participantPermissions.hasChatPermission(),
623+
showMediaFilenames = appPreferences.showMediaFilenames
623624
),
624625
callbacks = ChatViewCallbacks(
625626
onLoadMore = { loadMoreMessagesCompose() },

app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ class SettingsActivity :
781781
binding.run {
782782
listOf(
783783
settingsShowEcosystemSwitch,
784+
settingsShowMediaFilenamesSwitch,
784785
settingsShowNotificationWarningSwitch,
785786
settingsScreenLockSwitch,
786787
settingsScreenSecuritySwitch,
@@ -978,6 +979,7 @@ class SettingsActivity :
978979

979980
private fun setupCheckables(isOnline: Boolean) {
980981
setupShowEcosystemCheckable()
982+
setupShowMediaFilenamesCheckable()
981983

982984
binding.settingsShowNotificationWarningSwitch.isChecked =
983985
appPreferences.showRegularNotificationWarning
@@ -1052,6 +1054,15 @@ class SettingsActivity :
10521054
}
10531055
}
10541056

1057+
private fun setupShowMediaFilenamesCheckable() {
1058+
binding.settingsShowMediaFilenamesSwitch.isChecked = appPreferences.showMediaFilenames
1059+
binding.settingsShowMediaFilenames.setOnClickListener {
1060+
val isChecked = binding.settingsShowMediaFilenamesSwitch.isChecked
1061+
binding.settingsShowMediaFilenamesSwitch.isChecked = !isChecked
1062+
appPreferences.setShowMediaFilenames(!isChecked)
1063+
}
1064+
}
1065+
10551066
private fun setupPhoneBookIntegrationSetting() {
10561067
binding.settingsPhoneBookIntegrationSwitch.isChecked = appPreferences.isPhoneBookIntegrationEnabled
10571068
binding.settingsPhoneBookIntegration.setOnClickListener {

app/src/main/java/com/nextcloud/talk/ui/chat/ChatMessageView.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ private const val QUOTE_HIGHLIGHT_FADE_OUT_MILLIS = 1500
5151
data class ChatMessageContext(
5252
val isOneToOneConversation: Boolean = false,
5353
val conversationThreadId: Long? = null,
54-
val hasChatPermission: Boolean = true
54+
val hasChatPermission: Boolean = true,
55+
val showMediaFilenames: Boolean = false
5556
)
5657

5758
class ChatMessageCallbacks(
@@ -130,6 +131,7 @@ fun ChatMessageView(
130131
message = message,
131132
isOneToOneConversation = context.isOneToOneConversation,
132133
conversationThreadId = context.conversationThreadId,
134+
showMediaFilenames = context.showMediaFilenames,
133135
onImageClick = callbacks.onFileClick
134136
)
135137
}

app/src/main/java/com/nextcloud/talk/ui/chat/ChatView.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ data class ChatViewState(
8787
val isOneToOneConversation: Boolean,
8888
val conversationThreadId: Long? = null,
8989
val hasChatPermission: Boolean = true,
90+
val showMediaFilenames: Boolean = false,
9091
val initialUnreadCount: Int = 0,
9192
val initialShowUnreadPopup: Boolean = false
9293
)
@@ -311,7 +312,8 @@ fun ChatView(
311312
context = ChatMessageContext(
312313
isOneToOneConversation = state.isOneToOneConversation,
313314
conversationThreadId = state.conversationThreadId,
314-
hasChatPermission = state.hasChatPermission
315+
hasChatPermission = state.hasChatPermission,
316+
showMediaFilenames = state.showMediaFilenames
315317
),
316318
callbacks = ChatMessageCallbacks(
317319
onLongClick = callbacks.onLongClick,

app/src/main/java/com/nextcloud/talk/ui/chat/MediaMessage.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,16 @@ fun MediaMessage(
4444
message: ChatMessageUi,
4545
isOneToOneConversation: Boolean = false,
4646
conversationThreadId: Long? = null,
47+
showMediaFilenames: Boolean = false,
4748
onImageClick: (Int) -> Unit
4849
) {
49-
val captionText = message.message.takeUnless { it == FILE_PLACEHOLDER_MESSAGE }
50+
val hasExplicitCaption = message.plainMessage != FILE_PLACEHOLDER_MESSAGE
51+
val hasPreview = !typeContent.previewUrl.isNullOrEmpty()
52+
val captionText = when {
53+
hasExplicitCaption -> message.message
54+
!hasPreview || showMediaFilenames -> message.message
55+
else -> null
56+
}
5057
val hasCaption = captionText != null
5158
val mediaInset = 4.dp
5259
val mediaShape = remember(message.incoming) {

app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public interface AppPreferences {
122122

123123
void removeShowEcosystem();
124124

125+
boolean getShowMediaFilenames();
126+
127+
void setShowMediaFilenames(boolean value);
128+
125129
boolean isPhoneBookIntegrationEnabled();
126130

127131
void setPhoneBookIntegration(boolean value);

app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferencesImpl.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,18 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
317317
setShowEcosystem(false)
318318
}
319319

320+
override fun getShowMediaFilenames(): Boolean {
321+
val read = runBlocking { async { readBoolean(SHOW_MEDIA_FILENAMES).first() } }.getCompleted()
322+
return read
323+
}
324+
325+
override fun setShowMediaFilenames(value: Boolean) =
326+
runBlocking<Unit> {
327+
async {
328+
writeBoolean(SHOW_MEDIA_FILENAMES, value)
329+
}
330+
}
331+
320332
override fun isPhoneBookIntegrationEnabled(): Boolean =
321333
runBlocking {
322334
async { readBoolean(PHONE_BOOK_INTEGRATION).first() }
@@ -636,6 +648,7 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
636648
const val SCREEN_LOCK = "screen_lock"
637649
const val INCOGNITO_KEYBOARD = "incognito_keyboard"
638650
const val SHOW_ECOSYSTEM = "SHOW_ECOSYSTEM"
651+
const val SHOW_MEDIA_FILENAMES = "show_media_filenames"
639652
const val PHONE_BOOK_INTEGRATION = "phone_book_integration"
640653
const val LINK_PREVIEWS = "link_previews"
641654
const val SCREEN_LOCK_TIMEOUT = "screen_lock_timeout"

app/src/main/res/layout/activity_settings.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,41 @@
223223
android:gravity="center_vertical" />
224224
</LinearLayout>
225225

226+
<LinearLayout
227+
android:id="@+id/settings_show_media_filenames"
228+
android:layout_width="match_parent"
229+
android:layout_height="wrap_content"
230+
android:background="?android:attr/selectableItemBackground"
231+
android:orientation="horizontal"
232+
android:padding="@dimen/standard_padding">
233+
234+
<LinearLayout
235+
android:layout_width="0dp"
236+
android:layout_height="wrap_content"
237+
android:layout_weight="1"
238+
android:orientation="vertical">
239+
240+
<com.google.android.material.textview.MaterialTextView
241+
android:layout_width="wrap_content"
242+
android:layout_height="wrap_content"
243+
android:text="@string/nc_settings_show_media_filenames_title"
244+
android:textSize="@dimen/headline_text_size" />
245+
246+
<com.google.android.material.textview.MaterialTextView
247+
android:layout_width="wrap_content"
248+
android:layout_height="wrap_content"
249+
android:text="@string/nc_settings_show_media_filenames_desc"
250+
android:paddingEnd="@dimen/standard_padding"/>
251+
</LinearLayout>
252+
253+
<com.google.android.material.materialswitch.MaterialSwitch
254+
android:id="@+id/settings_show_media_filenames_switch"
255+
android:layout_width="wrap_content"
256+
android:layout_height="wrap_content"
257+
android:clickable="false"
258+
android:gravity="center_vertical" />
259+
</LinearLayout>
260+
226261
</LinearLayout>
227262

228263
<LinearLayout

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,9 @@ How to translate with transifex:
965965
<string name="no_scheduled_messages_offline">No connection to server - Scheduled messages could not be loaded</string>
966966
<string name="nc_show_ecosystem_title">Show app switcher</string>
967967
<string name="nc_show_ecosystem_description">Nextcloud app suggestions in account chooser dialog</string>
968+
<string name="nc_settings_show_media_filenames_key" translatable="false">show_media_filenames</string>
969+
<string name="nc_settings_show_media_filenames_title">Show filenames for media</string>
970+
<string name="nc_settings_show_media_filenames_desc">Always show filenames below media attachments in chat</string>
968971
<string name="turn_on_background_blur">Turn on background blur</string>
969972
<string name="turn_off_background_blur">Turn off background blur</string>
970973
</resources>

0 commit comments

Comments
 (0)