Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goto path location #513

Merged
merged 6 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions app/src/main/java/com/infomaniak/drive/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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"
Expand All @@ -174,7 +173,7 @@ class MainActivity : BaseActivity() {
AccountUtils.updateCurrentUserAndDrives(this@MainActivity)
}
}
})
}

navController.addOnDestinationChangedListener { _, destination, navigationArgs ->
onDestinationChanged(destination, navigationArgs)
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -60,7 +62,7 @@ class MainViewModel(appContext: Application) : AndroidViewModel(appContext) {

val createDropBoxSuccess = SingleLiveEvent<DropBox>()

val intentShowProgressByFolderId = SingleLiveEvent<Int>()
val navigateFileListToFolderId = SingleLiveEvent<FileId>()

val deleteFileFromHome = SingleLiveEvent<Boolean>()
val refreshActivities = SingleLiveEvent<Boolean>()
Expand All @@ -75,6 +77,11 @@ class MainViewModel(appContext: Application) : AndroidViewModel(appContext) {

private fun getContext() = getApplication<ApplicationMain>()

fun navigateFileListToFolderId(navController: NavController, folderId: Int) {
navController.navigate(R.id.fileListFragment)
if (folderId > Utils.ROOT_ID) navigateFileListToFolderId.value = folderId
}

fun createMultiSelectMediator(): MediatorLiveData<Pair<Int, Int>> {
return MediatorLiveData<Pair<Int, Int>>().apply { value = /*success*/0 to /*total*/0 }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -300,6 +300,7 @@ open class FileListFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener {

override fun onStop() {
fileAdapter.removeRealmDataListener()
isDownloading = false
super.onStop()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,6 +65,7 @@ class FileDetailsInfoFragment : FileDetailsSubFragment() {
setupCategoriesContainer(file.getCategories())
displayUsersAvatars()
setupShareButton()
setupPathLocationButton()

if (file.createdAt.isPositive()) {
addedDateValue.text = file.getCreatedAt().format(ShareLinkContainerView.formatFullDate)
Expand Down Expand Up @@ -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
}

Expand All @@ -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()
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/res/layout/fragment_file_details_infos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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="/" />

<com.google.android.material.button.MaterialButton
android:id="@+id/pathLocationButton"
style="@style/IconButton"
android:layout_width="38dp"
android:layout_height="38dp"
android:contentDescription="@string/allPathTitle"
android:visibility="gone"
app:icon="@drawable/ic_view"
app:iconSize="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1"
app:layout_constraintStart_toEndOf="@id/pathValue"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down