Skip to content

Commit

Permalink
Merge branch 'master' into api-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
sirambd committed May 14, 2024
2 parents 14d0d38 + 7478f93 commit e86d707
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Core
Submodule Core updated 2 files
+1 −1 Stores/build.gradle
+5 −5 build.gradle
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ dependencies {

implementation 'androidx.concurrent:concurrent-futures-ktx:1.1.0'
implementation 'androidx.lifecycle:lifecycle-process:2.7.0'
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta02'
implementation 'androidx.webkit:webkit:1.10.0'
implementation 'androidx.viewpager2:viewpager2:1.1.0-rc01'
implementation 'androidx.webkit:webkit:1.11.0'

def exoplayer_version = '2.19.1'
implementation "com.google.android.exoplayer:exoplayer-core:$exoplayer_version"
Expand All @@ -153,7 +153,7 @@ dependencies {

implementation 'io.realm:android-adapters:4.0.0'

standardImplementation 'com.google.firebase:firebase-messaging-ktx:23.4.1'
standardImplementation 'com.google.firebase:firebase-messaging-ktx:24.0.0'

implementation 'com.googlecode.plist:dd-plist:1.28'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object DriveInfosController {
.modules(RealmModules.DriveFilesModule())
.build()

private fun getRealmInstance() = Realm.getInstance(realmConfiguration)
fun getRealmInstance() = Realm.getInstance(realmConfiguration)

private fun ArrayList<Drive>.initDriveForRealm(
drive: Drive,
Expand Down Expand Up @@ -130,11 +130,15 @@ object DriveInfosController {
userId: Int? = null,
driveId: Int? = null,
sharedWithMe: Boolean? = null,
maintenance: Boolean? = null
maintenance: Boolean? = null,
customRealm: Realm? = null,
): Drive? {
return getRealmInstance().use { realm ->
realm.getDrivesQuery(userId, driveId, sharedWithMe, maintenance).findFirst()?.let { realm.copyFromRealm(it, 1) }
val block: (Realm) -> Drive? = { realm ->
realm.getDrivesQuery(userId, driveId, sharedWithMe, maintenance).findFirst()?.let {
if (customRealm == null) realm.copyFromRealm(it, 1) else it
}
}
return customRealm?.let(block) ?: getRealmInstance().use(block)
}

fun getDrivesCount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.navigation.navGraphViewModels
import com.infomaniak.drive.R
import com.infomaniak.drive.data.cache.DriveInfosController
import com.infomaniak.drive.data.models.drive.Drive
import com.infomaniak.drive.databinding.FragmentNewFolderBinding
import com.infomaniak.drive.utils.AccountUtils
import com.infomaniak.lib.core.utils.safeBinding
import com.infomaniak.lib.core.utils.safeNavigate

Expand Down Expand Up @@ -58,8 +57,11 @@ class NewFolderFragment : Fragment() {
}

initPrivateFolder()
initCommonFolder()
initDropBoxFolder()

newFolderViewModel.currentDriveLiveData().observe(viewLifecycleOwner) { drive ->
initCommonFolder(drive)
initDropBoxFolder(drive)
}
}

private fun initPrivateFolder() {
Expand All @@ -68,11 +70,7 @@ class NewFolderFragment : Fragment() {
}
}

private fun initCommonFolder() = with(binding) {
val drive = newFolderViewModel.userDrive?.let {
DriveInfosController.getDrive(it.userId, it.driveId)
} ?: AccountUtils.getCurrentDrive()

private fun initCommonFolder(drive: Drive?) = with(binding) {
if (drive?.capabilities?.useTeamSpace == true) {
commonFolderDescription.text = getString(R.string.commonFolderDescription, drive.name)
commonFolder.setOnClickListener {
Expand All @@ -83,10 +81,10 @@ class NewFolderFragment : Fragment() {
}
}

private fun initDropBoxFolder() {
private fun initDropBoxFolder(drive: Drive?) {
binding.dropBox.setOnClickListener {
safeNavigate(
if (AccountUtils.getCurrentDrive()?.pack?.capabilities?.useDropbox == true) R.id.createDropBoxFolderFragment
if (drive?.pack?.capabilities?.useDropbox == true) R.id.createDropBoxFolderFragment
else R.id.dropBoxBottomSheetDialog
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,33 @@ package com.infomaniak.drive.ui.addFiles
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.infomaniak.drive.data.cache.DriveInfosController
import com.infomaniak.drive.data.cache.FileController
import com.infomaniak.drive.data.models.File
import com.infomaniak.drive.data.models.Permission
import com.infomaniak.drive.data.models.UserDrive
import com.infomaniak.drive.data.models.drive.Drive
import com.infomaniak.drive.utils.AccountUtils
import kotlinx.coroutines.Dispatchers

class NewFolderViewModel : ViewModel() {

private val driveRealm = DriveInfosController.getRealmInstance()

val currentFolderId = MutableLiveData<Int>()
var userDrive: UserDrive? = null
var currentPermission: Permission? = null

fun currentDriveLiveData() = liveData<Drive?> {
val drive = DriveInfosController.getDrive(
userId = userDrive?.userId ?: AccountUtils.currentUserId,
driveId = userDrive?.driveId ?: AccountUtils.currentDriveId,
maintenance = false,
customRealm = driveRealm,
)
emit(drive?.freeze())
}

fun createFolder(name: String, parentId: Int, onlyForMe: Boolean) = liveData(Dispatchers.IO) {
emit(FileController.createFolder(name, parentId, onlyForMe, userDrive))
}
Expand All @@ -44,4 +59,9 @@ class NewFolderViewModel : ViewModel() {
fun saveNewFolder(parentFolderId: Int, newFolder: File) {
FileController.addFileTo(parentFolderId, newFolder, userDrive)
}

override fun onCleared() {
super.onCleared()
runCatching { driveRealm.close() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.infomaniak.drive.R
import com.infomaniak.drive.data.models.File
import com.infomaniak.drive.data.models.UserDrive
import com.infomaniak.drive.databinding.FragmentPreviewPdfBinding
import com.infomaniak.drive.ui.fileList.preview.PreviewSliderFragment.Companion.openWithClicked
import com.infomaniak.drive.ui.fileList.preview.PreviewSliderFragment.Companion.setPageNumber
import com.infomaniak.drive.ui.fileList.preview.PreviewSliderFragment.Companion.setPageNumberChipVisibility
import com.infomaniak.drive.ui.fileList.preview.PreviewSliderFragment.Companion.toggleFullscreen
Expand Down Expand Up @@ -109,7 +110,9 @@ class PreviewPDFFragment : PreviewFragment() {

bigOpenWithButton.apply {
isGone = true
setOnClickListener { showPasswordDialog() }
setOnClickListener {
if (isPasswordProtected) showPasswordDialog() else openWithClicked()
}
}
}

Expand Down

0 comments on commit e86d707

Please sign in to comment.