Skip to content

Commit

Permalink
Updated Matomo for MultiSelect
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Boulongne <[email protected]>
  • Loading branch information
KevinBoulongne committed Mar 9, 2022
1 parent a40dbc9 commit 5da61c7
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import com.infomaniak.lib.core.utils.showProgress
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.*

open class FileListFragment : MultiSelectFragment(), SwipeRefreshLayout.OnRefreshListener {
open class FileListFragment : MultiSelectFragment(MATOMO_CATEGORY), SwipeRefreshLayout.OnRefreshListener {

private lateinit var binding: FragmentFileListBinding

Expand Down Expand Up @@ -113,6 +113,8 @@ open class FileListFragment : MultiSelectFragment(), SwipeRefreshLayout.OnRefres

// Beware, if this value is modified, the Categories' layouts should be modified accordingly.
const val MAX_DISPLAYED_CATEGORIES = 3

const val MATOMO_CATEGORY = "fileListFileAction"
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import com.infomaniak.drive.data.cache.FileController
import com.infomaniak.drive.ui.MainViewModel
import com.infomaniak.drive.ui.fileList.FileListFragment
import kotlinx.android.synthetic.main.fragment_bottom_sheet_multi_select_actions.*

class FileListMultiSelectActionsBottomSheetDialog : MultiSelectActionsBottomSheetDialog() {
class FileListMultiSelectActionsBottomSheetDialog : MultiSelectActionsBottomSheetDialog(FileListFragment.MATOMO_CATEGORY) {

private val mainViewModel: MainViewModel by activityViewModels()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ import com.infomaniak.drive.data.api.ApiRepository
import com.infomaniak.drive.data.api.ApiRoutes
import com.infomaniak.drive.data.models.BulkOperationType
import com.infomaniak.drive.utils.*
import com.infomaniak.drive.utils.MatomoUtils.trackBulkActionEvent
import com.infomaniak.drive.utils.MatomoUtils.trackEvent
import kotlinx.android.synthetic.main.fragment_bottom_sheet_multi_select_actions.*
import kotlinx.android.synthetic.main.view_file_info_actions.view.*
import kotlinx.coroutines.Dispatchers

abstract class MultiSelectActionsBottomSheetDialog : BottomSheetDialogFragment() {
abstract class MultiSelectActionsBottomSheetDialog(private val matomoCategory: String) : BottomSheetDialogFragment() {

val navigationArgs: MultiSelectActionsBottomSheetDialogArgs by navArgs()

Expand Down Expand Up @@ -94,13 +93,15 @@ abstract class MultiSelectActionsBottomSheetDialog : BottomSheetDialogFragment()
if (authorized) downloadFileArchive()
}
}

downloadFile.apply {
setOnClickListener {
if (drivePermissions.checkWriteStoragePermission()) {
context?.applicationContext?.trackEvent("FileAction", TrackerAction.CLICK, "bulkDownload")
context?.applicationContext?.trackEvent(matomoCategory, TrackerAction.CLICK, "bulkDownload")
downloadFileArchive()
}
}

isVisible = navigationArgs.fileIds.isNotEmpty()
}
}
Expand Down Expand Up @@ -143,7 +144,6 @@ abstract class MultiSelectActionsBottomSheetDialog : BottomSheetDialogFragment()
if (finalType == null) {
closeMultiSelect()
} else {
context?.applicationContext?.trackBulkActionEvent(finalType, navigationArgs.fileIds.size)
when (finalType) {
BulkOperationType.COPY -> duplicateFiles()
BulkOperationType.COLOR_FOLDER -> colorFolders()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

abstract class MultiSelectFragment : Fragment(), MultiSelectResult {
abstract class MultiSelectFragment(private val matomoCategory: String) : Fragment(), MultiSelectResult {

protected val mainViewModel: MainViewModel by activityViewModels()
protected val multiSelectManager = MultiSelectManager()
Expand Down Expand Up @@ -169,12 +169,12 @@ abstract class MultiSelectFragment : Fragment(), MultiSelectResult {
val selectedFiles = multiSelectManager.getValidSelectedItems(type)
val fileCount = allSelectedFileCount ?: selectedFiles.size

applicationContext?.trackBulkActionEvent(matomoCategory, type, fileCount)

val sendActions: (dialog: Dialog?) -> Unit = sendActions(
type, areAllFromTheSameFolder, fileCount, selectedFiles, destinationFolder, color
)

applicationContext?.trackBulkActionEvent(type, fileCount)

if (type == BulkOperationType.TRASH) {
Utils.createConfirmation(
context = this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
package com.infomaniak.drive.ui.fileList.multiSelect

import androidx.core.view.isGone
import com.infomaniak.drive.ui.menu.PicturesFragment
import kotlinx.android.synthetic.main.fragment_bottom_sheet_multi_select_actions.*

class PicturesMultiSelectActionsBottomSheetDialog : MultiSelectActionsBottomSheetDialog() {
class PicturesMultiSelectActionsBottomSheetDialog : MultiSelectActionsBottomSheetDialog(PicturesFragment.MATOMO_CATEGORY) {

override fun configureColoredFolder(areIndividualActionsVisible: Boolean) {
coloredFolder.isGone = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import kotlinx.coroutines.runBlocking
import kotlin.math.max
import kotlin.math.min

class PicturesFragment(private val onFinish: (() -> Unit)? = null) : MultiSelectFragment() {
class PicturesFragment(private val onFinish: (() -> Unit)? = null) : MultiSelectFragment(MATOMO_CATEGORY) {

private val picturesViewModel: PicturesViewModel by viewModels()
private lateinit var picturesAdapter: PicturesAdapter
Expand Down Expand Up @@ -269,7 +269,8 @@ class PicturesFragment(private val onFinish: (() -> Unit)? = null) : MultiSelect
picturesAdapter.updateFileProgressByFileId(fileId, progress, onComplete)
}

private companion object {
const val NUMBER_ITEMS_LOADER = 12
companion object {
private const val NUMBER_ITEMS_LOADER = 12
const val MATOMO_CATEGORY = "picturesFileAction"
}
}
8 changes: 4 additions & 4 deletions app/src/main/java/com/infomaniak/drive/utils/MatomoUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ object MatomoUtils {
context?.applicationContext?.trackEvent(category, action, trackerName, trackerValue)
}

fun Context.trackBulkActionEvent(action: BulkOperationType, modifiedFileNumber: Int) {
val trackerName = "bulk" + if (modifiedFileNumber == 1) "Single" else "" + action.toString()
trackEvent("FileAction", TrackerAction.CLICK, trackerName, modifiedFileNumber.toFloat())
fun Context.trackBulkActionEvent(category: String, action: BulkOperationType, modifiedFileNumber: Int) {
val trackerName = "bulk" + (if (modifiedFileNumber == 1) "Single" else "") + action.toString()
trackEvent(category, TrackerAction.CLICK, trackerName, modifiedFileNumber.toFloat())
}

fun Context.trackEventWithBooleanValue(category: String, trackerName: String, trackerValue: Boolean?) {
Expand Down Expand Up @@ -99,7 +99,7 @@ object MatomoUtils {
}
}

fun Boolean.toFloat() = if (this) 1f else 0f
fun Boolean.toFloat() = if (this) 1.0f else 0.0f

enum class TrackerAction {
CLICK, INPUT;
Expand Down

0 comments on commit 5da61c7

Please sign in to comment.