diff --git a/app/src/main/java/com/infomaniak/drive/ui/MainActivity.kt b/app/src/main/java/com/infomaniak/drive/ui/MainActivity.kt index ba4029058f..5c7fe40c12 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/MainActivity.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/MainActivity.kt @@ -148,8 +148,7 @@ class MainActivity : BaseActivity() { message = "Upload notification has been clicked" level = SentryLevel.INFO }) - navController.navigate(R.id.fileListFragment) - mainViewModel.intentShowProgressByFolderId.value = folderId + mainViewModel.navigateFileListToFolderId(navController, folderId) } } @@ -161,7 +160,7 @@ class MainActivity : BaseActivity() { } } - LiveDataNetworkStatus(this).observe(this, { isAvailable -> + LiveDataNetworkStatus(this).observe(this) { isAvailable -> Log.d("Internet availability", if (isAvailable) "Available" else "Unavailable") Sentry.addBreadcrumb(Breadcrumb().apply { category = "Network" @@ -174,7 +173,7 @@ class MainActivity : BaseActivity() { AccountUtils.updateCurrentUserAndDrives(this@MainActivity) } } - }) + } navController.addOnDestinationChangedListener { _, destination, navigationArgs -> onDestinationChanged(destination, navigationArgs) diff --git a/app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt b/app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt index 7e2c2df581..a31b332ffb 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt @@ -23,11 +23,13 @@ import android.content.Context import android.provider.MediaStore import androidx.collection.arrayMapOf import androidx.lifecycle.* +import androidx.navigation.NavController import androidx.work.WorkInfo import androidx.work.WorkManager import androidx.work.WorkQuery import com.google.gson.JsonObject import com.infomaniak.drive.ApplicationMain +import com.infomaniak.drive.R import com.infomaniak.drive.data.api.ApiRepository import com.infomaniak.drive.data.cache.FileController import com.infomaniak.drive.data.models.* @@ -60,7 +62,7 @@ class MainViewModel(appContext: Application) : AndroidViewModel(appContext) { val createDropBoxSuccess = SingleLiveEvent() - val intentShowProgressByFolderId = SingleLiveEvent() + val navigateFileListToFolderId = SingleLiveEvent() val deleteFileFromHome = SingleLiveEvent() val refreshActivities = SingleLiveEvent() @@ -75,6 +77,11 @@ class MainViewModel(appContext: Application) : AndroidViewModel(appContext) { private fun getContext() = getApplication() + fun navigateFileListToFolderId(navController: NavController, folderId: Int) { + navController.navigate(R.id.fileListFragment) + if (folderId > Utils.ROOT_ID) navigateFileListToFolderId.value = folderId + } + fun createMultiSelectMediator(): MediatorLiveData> { return MediatorLiveData>().apply { value = /*success*/0 to /*total*/0 } } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/FileListFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/FileListFragment.kt index 91ba62e8d7..c8b21c6e66 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/FileListFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/FileListFragment.kt @@ -147,7 +147,7 @@ open class FileListFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener { } } - mainViewModel.intentShowProgressByFolderId.observe(viewLifecycleOwner) { + mainViewModel.navigateFileListToFolderId.observe(viewLifecycleOwner) { it?.let { intentFolderId -> FileController.getFileById(intentFolderId)?.let { file -> safeNavigate( @@ -300,6 +300,7 @@ open class FileListFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener { override fun onStop() { fileAdapter.removeRealmDataListener() + isDownloading = false super.onStop() } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsInfoFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsInfoFragment.kt index 9cf07b3d59..911e02466c 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsInfoFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsInfoFragment.kt @@ -32,6 +32,7 @@ import androidx.navigation.fragment.findNavController import com.infomaniak.drive.R import com.infomaniak.drive.data.api.ErrorCode.Companion.translateError 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.Share @@ -64,6 +65,7 @@ class FileDetailsInfoFragment : FileDetailsSubFragment() { setupCategoriesContainer(file.getCategories()) displayUsersAvatars() setupShareButton() + setupPathLocationButton() if (file.createdAt.isPositive()) { addedDateValue.text = file.getCreatedAt().format(ShareLinkContainerView.formatFullDate) @@ -123,7 +125,7 @@ class FileDetailsInfoFragment : FileDetailsSubFragment() { private fun setPath(path: String) { val drive = DriveInfosController.getDrives(AccountUtils.currentUserId, driveId = file.driveId).first() driveIcon.imageTintList = ColorStateList.valueOf(Color.parseColor(drive.preferences.color)) - pathValue.text = "${drive.name}$path" + pathValue.text = "${drive.name}${path.substringBeforeLast("/")}" pathView.isVisible = true } @@ -140,6 +142,19 @@ class FileDetailsInfoFragment : FileDetailsSubFragment() { } } + private fun setupPathLocationButton() { + FileController.getParentFile(this.file.id)?.let { folder -> + pathLocationButton.isVisible = true + pathLocationButton.setOnClickListener { + with(findNavController()) { + popBackStack(R.id.homeFragment, false) + mainViewModel.navigateFileListToFolderId(this, folder.id) + } + + } + } + } + private fun setupShareLink(share: Share?) { when { file.isDropBox() -> setupDropBoxShareLink() diff --git a/app/src/main/res/layout/fragment_file_details_infos.xml b/app/src/main/res/layout/fragment_file_details_infos.xml index 4bc7dfd878..b4c43910b5 100644 --- a/app/src/main/res/layout/fragment_file_details_infos.xml +++ b/app/src/main/res/layout/fragment_file_details_infos.xml @@ -292,12 +292,28 @@ android:layout_marginHorizontal="@dimen/marginStandardVerySmall" android:gravity="center_vertical" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintEnd_toStartOf="@id/pathLocationButton" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toEndOf="@id/driveIcon" app:layout_constraintTop_toTopOf="@id/driveIcon" tools:text="/" /> + +