Skip to content

Commit

Permalink
Merge branch 'master' into UnitTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Smarshal21 authored Sep 5, 2023
2 parents 9312684 + 4ca0620 commit 56af271
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
echo "pr=${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
echo "repo=${{ github.event.pull_request.head.repo.full_name }}" >> "$GITHUB_OUTPUT"
fi
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
with:
repository: ${{ steps.get-vars.outputs.repo }}
ref: ${{ steps.get-vars.outputs.branch }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/assembleFlavors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
matrix:
flavor: [ Generic, Gplay ]
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: set up JDK 17
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
matrix:
task: [ detekt, ktlintCheck ]
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Set up JDK 17
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
language: [ 'java' ]
steps:
- name: Checkout repository
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Set Swap Space
uses: pierotofy/set-swap-space@49819abfb41bd9b44fb781159c033dba90353a7c # v1.0
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/command-rebase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
reaction-type: "+1"

- name: Checkout the latest code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
with:
fetch-depth: 0
token: ${{ secrets.COMMAND_BOT_PAT }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jobs:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4 # v1.1.0
2 changes: 1 addition & 1 deletion .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Check if secrets are available
run: echo "::set-output name=ok::${{ secrets.KS_PASS != '' }}"
id: check-secrets
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
if: ${{ steps.check-secrets.outputs.ok == 'true' }}
- name: set up JDK 17
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

steps:
- name: "Checkout code"
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
with:
persist-credentials: false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
message.selectedIndividualHashMap!![KEY_NAME]!!,
message.selectedIndividualHashMap!![KEY_ID]!!,
message.selectedIndividualHashMap!![KEY_MIMETYPE],
message.openWhenDownloaded,
ProgressUi(progressBar, messageText, image)
)
} else if (message.getCalculateMessageType() === ChatMessage.MessageType.SINGLE_LINK_GIPHY_MESSAGE) {
Expand Down
51 changes: 45 additions & 6 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ import com.nextcloud.talk.ui.dialog.ShowReactionsDialog
import com.nextcloud.talk.ui.recyclerview.MessageSwipeActions
import com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.AudioUtils
import com.nextcloud.talk.utils.AudioUtils.audioFileToFloatArray
import com.nextcloud.talk.utils.ContactUtils
import com.nextcloud.talk.utils.ConversationUtils
import com.nextcloud.talk.utils.DateConstants
Expand All @@ -201,6 +201,7 @@ import com.nextcloud.talk.utils.FileUtils
import com.nextcloud.talk.utils.FileViewerUtils
import com.nextcloud.talk.utils.ImageEmojiEditText
import com.nextcloud.talk.utils.MagicCharPolicy
import com.nextcloud.talk.utils.Mimetype
import com.nextcloud.talk.utils.NotificationUtils
import com.nextcloud.talk.utils.ParticipantPermissions
import com.nextcloud.talk.utils.VibrationUtils
Expand Down Expand Up @@ -316,6 +317,7 @@ class ChatActivity :
var voiceOnly: Boolean = true
var isFirstMessagesProcessing = true
private var emojiPopup: EmojiPopup? = null
private lateinit var path: String

var myFirstMessage: CharSequence? = null
var checkingLobbyStatus: Boolean = false
Expand Down Expand Up @@ -887,7 +889,9 @@ class ChatActivity :
}
} else {
Log.d(TAG, "Downloaded to cache")
downloadFileToCache(message)
downloadFileToCache(message, true) {
setUpWaveform(message)
}
}
}
}
Expand All @@ -899,7 +903,7 @@ class ChatActivity :
message.isDownloadingVoiceMessage = true
adapter?.update(message)
CoroutineScope(Dispatchers.Default).launch {
val r = AudioUtils.audioFileToFloatArray(file)
val r = audioFileToFloatArray(file)
message.voiceMessageFloatArray = r
withContext(Dispatchers.Main) {
startPlayback(message)
Expand Down Expand Up @@ -1933,8 +1937,13 @@ class ChatActivity :
}

@SuppressLint("LongLogTag")
private fun downloadFileToCache(message: ChatMessage) {
private fun downloadFileToCache(
message: ChatMessage,
openWhenDownloaded: Boolean,
funToCallWhenDownloadSuccessful: (() -> Unit)
) {
message.isDownloadingVoiceMessage = true
message.openWhenDownloaded = openWhenDownloaded
adapter?.update(message)

val baseUrl = message.activeUser!!.baseUrl
Expand Down Expand Up @@ -1985,8 +1994,7 @@ class ChatActivity :
WorkManager.getInstance(context).getWorkInfoByIdLiveData(downloadWorker.id)
.observeForever { workInfo: WorkInfo ->
if (workInfo.state == WorkInfo.State.SUCCEEDED) {
setUpWaveform(message)
// startPlayback(message)
funToCallWhenDownloadSuccessful()
}
}
}
Expand Down Expand Up @@ -3997,6 +4005,37 @@ class ChatActivity :
startActivity(intent)
}

fun share(message: ChatMessage) {
val filename = message.selectedIndividualHashMap!!["name"]
path = applicationContext.cacheDir.absolutePath + "/" + filename
val shareUri = FileProvider.getUriForFile(
this,
BuildConfig.APPLICATION_ID,
File(path)
)

val shareIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, shareUri)
type = Mimetype.IMAGE_PREFIX_GENERIC
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
startActivity(Intent.createChooser(shareIntent, resources.getText(R.string.send_to)))
}

fun checkIfSharable(message: ChatMessage) {
val filename = message.selectedIndividualHashMap!!["name"]
path = applicationContext.cacheDir.absolutePath + "/" + filename
val file = File(context.cacheDir, filename!!)
if (file.exists()) {
share(message)
} else {
downloadFileToCache(message, false) {
share(message)
}
}
}

fun openInFilesApp(message: ChatMessage) {
val keyID = message.selectedIndividualHashMap!![PreviewMessageViewHolder.KEY_ID]
val link = message.selectedIndividualHashMap!!["link"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ data class ChatMessage(

var expandableChildrenAmount: Int = 0,

var hiddenByCollapse: Boolean = false
var hiddenByCollapse: Boolean = false,

var openWhenDownloaded: Boolean = true

) : Parcelable, MessageContentType, MessageContentType.Image {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,17 @@ abstract class SharedItemsViewHolder(
progressBar,
null,
image
)
),
true
)
}

fileViewerUtils.resumeToUpdateViewsByProgress(
item.name,
item.id,
item.mimeType,
FileViewerUtils.ProgressUi(progressBar, null, image)
true,
FileViewerUtils.ProgressUi(progressBar, null, image),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class MessageActionsDialog(
message.previousMessageId > NO_PREVIOUS_MESSAGE_ID &&
ChatMessage.MessageType.SYSTEM_MESSAGE != message.getCalculateMessageType()
)
initMenuShare(ChatMessage.MessageType.SINGLE_NC_ATTACHMENT_MESSAGE == message.getCalculateMessageType())
initMenuItemOpenNcApp(
ChatMessage.MessageType.SINGLE_NC_ATTACHMENT_MESSAGE == message.getCalculateMessageType()
)
Expand Down Expand Up @@ -330,6 +331,15 @@ class MessageActionsDialog(

dialogMessageActionsBinding.menuTranslateMessage.visibility = getVisibility(visible)
}
private fun initMenuShare(visible: Boolean) {
if (visible) {
dialogMessageActionsBinding.menuShare.setOnClickListener {
chatActivity.checkIfSharable(message)
dismiss()
}
}
dialogMessageActionsBinding.menuShare.visibility = getVisibility(visible)
}

private fun initMenuItemOpenNcApp(visible: Boolean) {
if (visible) {
Expand Down
37 changes: 23 additions & 14 deletions app/src/main/java/com/nextcloud/talk/utils/FileViewerUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class FileViewerUtils(private val context: Context, private val user: User) {
path,
link,
mimetype,
progressUi
progressUi,
message.openWhenDownloaded
)
}

Expand All @@ -104,14 +105,16 @@ class FileViewerUtils(private val context: Context, private val user: User) {
path: String,
link: String?,
mimetype: String?,
progressUi: ProgressUi
progressUi: ProgressUi,
openWhenDownloaded: Boolean
) {
if (isSupportedForInternalViewer(mimetype) || canBeHandledByExternalApp(mimetype, fileInfo.fileName)) {
openOrDownloadFile(
fileInfo,
path,
mimetype,
progressUi
progressUi,
openWhenDownloaded
)
} else if (!link.isNullOrEmpty()) {
openFileInFilesApp(link, fileInfo.fileId)
Expand All @@ -138,7 +141,8 @@ class FileViewerUtils(private val context: Context, private val user: User) {
fileInfo: FileInfo,
path: String,
mimetype: String?,
progressUi: ProgressUi
progressUi: ProgressUi,
openWhenDownloaded: Boolean
) {
val file = File(context.cacheDir, fileInfo.fileName)
if (file.exists()) {
Expand All @@ -148,7 +152,8 @@ class FileViewerUtils(private val context: Context, private val user: User) {
fileInfo,
path,
mimetype,
progressUi
progressUi,
openWhenDownloaded
)
}
}
Expand Down Expand Up @@ -276,7 +281,8 @@ class FileViewerUtils(private val context: Context, private val user: User) {
fileInfo: FileInfo,
path: String,
mimetype: String?,
progressUi: ProgressUi
progressUi: ProgressUi,
openWhenDownloaded: Boolean
) {
// check if download worker is already running
val workers = WorkManager.getInstance(context).getWorkInfosByTag(fileInfo.fileId!!)
Expand Down Expand Up @@ -324,7 +330,8 @@ class FileViewerUtils(private val context: Context, private val user: User) {
fileInfo.fileName,
mimetype,
workInfo!!,
progressUi
progressUi,
openWhenDownloaded
)
}
}
Expand All @@ -333,7 +340,8 @@ class FileViewerUtils(private val context: Context, private val user: User) {
fileName: String,
mimetype: String?,
workInfo: WorkInfo,
progressUi: ProgressUi
progressUi: ProgressUi,
openWhenDownloaded: Boolean
) {
when (workInfo.state) {
WorkInfo.State.RUNNING -> {
Expand All @@ -347,13 +355,12 @@ class FileViewerUtils(private val context: Context, private val user: User) {
}
}
WorkInfo.State.SUCCEEDED -> {
if (progressUi.previewImage.isShown) {
if (progressUi.previewImage.isShown && openWhenDownloaded) {
openFileByMimetype(fileName, mimetype)
} else {
Log.d(
TAG,
"file " + fileName +
" was downloaded but it's not opened because view is not shown on screen"
Log.d(TAG, "file " + fileName +
" was downloaded but it's not opened because view is not shown on screen or " +
"openWhenDownloaded is false"
)
}
progressUi.messageText?.text = fileName
Expand All @@ -372,6 +379,7 @@ class FileViewerUtils(private val context: Context, private val user: User) {
fileName: String,
fileId: String,
mimeType: String?,
openWhenDownloaded: Boolean,
progressUi: ProgressUi
) {
val workers = WorkManager.getInstance(context).getWorkInfosByTag(fileId)
Expand All @@ -390,7 +398,8 @@ class FileViewerUtils(private val context: Context, private val user: User) {
fileName,
mimeType,
info!!,
progressUi
progressUi,
openWhenDownloaded
)
}
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/drawable/baseline_unfold_less_24.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<vector
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M7.41,18.59L8.83,20 12,16.83 15.17,20l1.41,-1.41L12,14l-4.59,4.59zM16.59,5.41L15.17,4 12,7.17 8.83,4 7.41,5.41 12,10l4.59,-4.59z"/>
<path android:fillColor="@color/grey_600" android:pathData="M7.41,18.59L8.83,20 12,16.83 15.17,20l1.41,-1.41L12,14l-4.59,4.59zM16.59,5.41L15.17,4 12,7.17 8.83,4 7.41,5.41 12,10l4.59,-4.59z"/>
</vector>
3 changes: 1 addition & 2 deletions app/src/main/res/drawable/baseline_unfold_more_24.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<vector
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,5.83L15.17,9l1.41,-1.41L12,3 7.41,7.59 8.83,9 12,5.83zM12,18.17L8.83,15l-1.41,1.41L12,21l4.59,-4.59L15.17,15 12,18.17z"/>
<path android:fillColor="@color/grey_600" android:pathData="M12,5.83L15.17,9l1.41,-1.41L12,3 7.41,7.59 8.83,9 12,5.83zM12,18.17L8.83,15l-1.41,1.41L12,21l4.59,-4.59L15.17,15 12,18.17z"/>
</vector>
Loading

0 comments on commit 56af271

Please sign in to comment.