Commit 9b8adce7 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Merge branch 'feature/project_files_screen_improvements' into 'develop'

Implement project file improvements.

See merge request !187
parents cbde73a6 77cef26f
......@@ -9,6 +9,7 @@ import android.graphics.drawable.Drawable
import android.net.Uri
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.TextUtils
import android.text.style.ForegroundColorSpan
import android.view.LayoutInflater
import android.view.View
......@@ -19,6 +20,7 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.annotation.LayoutRes
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.fragment.app.Fragment
......@@ -218,4 +220,17 @@ fun Any.objectScopeName() = "${javaClass.simpleName}_${hashCode()}"
fun View.setBackgroundTintByColor(@ColorInt color: Int) {
val wrappedDrawable = DrawableCompat.wrap(background)
DrawableCompat.setTint(wrappedDrawable.mutate(), color)
}
fun Toolbar.setTitleEllipsize(ellipsize: TextUtils.TruncateAt) {
val fakeTitle = "fakeTitle"
title = fakeTitle
for(i in 0..childCount) {
val child = getChildAt(i)
if (child is TextView && child.text == fakeTitle) {
child.ellipsize = TextUtils.TruncateAt.START
break
}
}
title = ""
}
\ No newline at end of file
......@@ -42,11 +42,10 @@ class ProjectFileDestination {
fun isInitiated() = defaultPath.isNotEmpty() && branchName.isNotEmpty() && paths.isNotEmpty()
fun moveToRoot() {
val fromRoot = isInitiated() && !isInRoot()
if (!isInitiated()) {
paths.add(ROOT_PATH)
}
callback?.onMoveForward(fromRoot)
callback?.onMoveForward(true)
}
fun moveForward(path: String) {
......@@ -65,12 +64,12 @@ class ProjectFileDestination {
fun isInRoot() = paths.size <= 1
fun changeBranch(branchName: String) {
if (this.branchName != branchName) {
this.branchName = branchName
this.paths.clear()
this.paths.add(ROOT_PATH)
callback?.onBranchChange(branchName)
fun changeBranch(newBranchName: String) {
if (branchName != newBranchName) {
branchName = newBranchName
paths.clear()
paths.add(ROOT_PATH)
callback?.onBranchChange(newBranchName)
}
}
......
......@@ -4,9 +4,9 @@ import com.arellomobile.mvp.InjectViewState
import io.reactivex.Single
import io.reactivex.functions.BiFunction
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.di.PrimitiveWrapper
import ru.terrakok.gitlabclient.di.ProjectId
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.entity.Branch
import ru.terrakok.gitlabclient.entity.Project
import ru.terrakok.gitlabclient.entity.RepositoryTreeNodeType
......@@ -38,15 +38,12 @@ class ProjectFilesPresenter @Inject constructor(
init {
projectFileDestination.setCallback(object : ProjectFileDestination.Callback {
override fun onMoveForward(fromRoot: Boolean) {
val inRoot = projectFileDestination.isInRoot()
if (fromRoot) {
viewState.setBranch("")
viewState.showBranchSelection(false)
} else if (inRoot) {
viewState.setBranch(projectFileDestination.branchName)
viewState.showBranchSelection(true)
with(projectFileDestination) {
if (fromRoot) {
viewState.setBranch(branchName)
}
viewState.setPath(getUIPath(isInRoot(), defaultPath, paths))
}
viewState.setPath(getUIPath(inRoot, projectFileDestination.defaultPath, projectFileDestination.paths))
refreshFiles()
}
......@@ -55,14 +52,9 @@ class ProjectFilesPresenter @Inject constructor(
if (fromRoot) {
router.exit()
} else {
val inRoot = projectFileDestination.isInRoot()
if (inRoot) {
viewState.setBranch(projectFileDestination.branchName)
viewState.showBranchSelection(true)
with(projectFileDestination) {
viewState.setPath(getUIPath(isInRoot(), defaultPath, paths))
}
viewState.setPath(
getUIPath(inRoot, projectFileDestination.defaultPath, projectFileDestination.paths)
)
refreshFiles()
}
......@@ -70,6 +62,9 @@ class ProjectFilesPresenter @Inject constructor(
override fun onBranchChange(branchName: String) {
viewState.setBranch(branchName)
with(projectFileDestination) {
viewState.setPath(getUIPath(isInRoot(), defaultPath, paths))
}
refreshFiles()
}
......@@ -131,8 +126,16 @@ class ProjectFilesPresenter @Inject constructor(
}
private fun handleLoadingProjectDetailsError(error: Throwable) {
viewState.setPath(resourceManager.getString(R.string.project_files_default_path))
viewState.showBranchSelection(false)
if (projectFileDestination.isInitiated()) {
with(projectFileDestination) {
viewState.setBranch(branchName)
viewState.setPath(getUIPath(isInRoot(), defaultPath, paths))
}
viewState.showBranchSelection(true)
} else {
viewState.setPath(resourceManager.getString(R.string.project_files_default_path))
viewState.showBranchSelection(false)
}
if (error is NoBranchesError) {
viewState.showEmptyError(true, resourceManager.getString(R.string.project_files_no_branches))
} else {
......@@ -203,6 +206,7 @@ class ProjectFilesPresenter @Inject constructor(
fun loadNextFilesPage() = paginator.loadNewPage()
fun onShowBranchesClick() = viewState.showBranches(projectBranches)
fun onBackPressed() = projectFileDestination.moveBack()
fun onNavigationCloseClicked() = router.exit()
fun onBranchClick(branchName: String) = projectFileDestination.changeBranch(branchName)
fun onFileClick(item: ProjectFile) {
......
package ru.terrakok.gitlabclient.ui.project.files
import android.os.Bundle
import android.text.TextUtils
import android.widget.PopupMenu
import androidx.recyclerview.widget.LinearLayoutManager
import com.arellomobile.mvp.presenter.InjectPresenter
......@@ -10,6 +11,7 @@ import kotlinx.android.synthetic.main.layout_base_list.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.entity.Branch
import ru.terrakok.gitlabclient.entity.app.ProjectFile
import ru.terrakok.gitlabclient.extension.setTitleEllipsize
import ru.terrakok.gitlabclient.extension.showSnackMessage
import ru.terrakok.gitlabclient.extension.visible
import ru.terrakok.gitlabclient.presentation.project.files.ProjectFileDestination
......@@ -68,7 +70,7 @@ class ProjectFilesFragment : BaseFragment(), ProjectFilesView {
}
toolbar.apply {
inflateMenu(R.menu.project_files_menu)
setNavigationOnClickListener { presenter.onBackPressed() }
setNavigationOnClickListener { presenter.onNavigationCloseClicked() }
setOnMenuItemClickListener {
when (it.itemId) {
R.id.showBranchesAction -> {
......@@ -78,6 +80,7 @@ class ProjectFilesFragment : BaseFragment(), ProjectFilesView {
else -> false
}
}
setTitleEllipsize(TextUtils.TruncateAt.START)
}
swipeToRefresh.setOnRefreshListener { presenter.refreshFiles() }
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z" />
</vector>
......@@ -13,7 +13,7 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="0dp"
app:navigationIcon="@drawable/ic_arrow_back_24dp"
app:navigationIcon="@drawable/ic_close_white_24dp"
tools:subtitle="develop"
tools:title="Files" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment