Skip to content

Commit

Permalink
Merge pull request #22 from meganz/release/2.0.6
Browse files Browse the repository at this point in the history
release/2.0.6
  • Loading branch information
javiergm1983 authored Mar 8, 2021
2 parents 07b173a + 07968c3 commit d713a81
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 28 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
versionCode = 12
versionName = "2.0.5"
versionCode = 13
versionName = "2.0.6"
compileSdkVersion = 29
minSdkVersion = 21
group = "com.github.meganz"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import androidx.core.view.children
import androidx.core.view.isVisible
import androidx.core.widget.doAfterTextChanged
Expand All @@ -16,7 +17,7 @@ import nz.mega.documentscanner.R
import nz.mega.documentscanner.data.Document
import nz.mega.documentscanner.databinding.FragmentSaveBinding
import nz.mega.documentscanner.databinding.ItemDestinationBinding
import nz.mega.documentscanner.utils.ViewUtils.selectLastCharacter
import nz.mega.documentscanner.utils.ViewUtils.setChildrenEnabled

class SaveFragment : Fragment() {

Expand All @@ -32,7 +33,7 @@ class SaveFragment : Fragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
binding = FragmentSaveBinding.inflate(inflater, container, false)
return binding.root
}
Expand All @@ -48,12 +49,19 @@ class SaveFragment : Fragment() {
viewModel.setDocumentTitle(editable?.toString())
}

binding.editFileName.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->
binding.imgEdit.isVisible = !hasFocus
binding.editFileName.setOnEditorActionListener { view, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
view.clearFocus()
}
false
}

binding.imgEdit.setOnClickListener {
binding.editFileName.selectLastCharacter()
binding.editFileName.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
binding.editFileName.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0)
} else {
binding.editFileName.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.ic_rename, 0)
}
}

binding.chipGroupFileType.setOnCheckedChangeListener { _, checkedId ->
Expand Down Expand Up @@ -140,7 +148,7 @@ class SaveFragment : Fragment() {
}
}

binding.inputFileName.suffixText = fileType.suffix
binding.editFileName.suffix = " ${fileType.suffix}"
binding.imgFileType.setImageResource(imageResId)

if (binding.chipGroupFileType.checkedChipId != chipResId) {
Expand Down Expand Up @@ -169,6 +177,10 @@ class SaveFragment : Fragment() {

private fun showProgress(show: Boolean) {
binding.btnSave.isEnabled = !show
binding.editFileName.isEnabled = !show
binding.chipGroupFileType.setChildrenEnabled(!show)
binding.chipGroupDestinations.setChildrenEnabled(!show)
binding.chipGroupQuality.setChildrenEnabled(!show)

if (show) {
binding.progress.show()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package nz.mega.documentscanner.utils

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.Typeface
import android.text.TextPaint
import android.util.AttributeSet
import com.google.android.material.textfield.TextInputEditText

/**
* [TextInputEditText] with suffix support.
*
* Inspired by https://github.com/tobiasschuerg/android-prefix-suffix-edit-text/
*/
class SuffixTextInputEditText constructor(
context: Context,
attrs: AttributeSet
) : TextInputEditText(context, attrs) {

// These are used to store details obtained from the EditText's rendering process
private val firstLineBounds = Rect()
private var isInitialized = false

private val textPaint: TextPaint by lazy {
TextPaint().apply {
color = currentHintTextColor
textAlign = Paint.Align.LEFT
isAntiAlias = true
this.typeface = typeface
}
}

var suffix: String? = null
set(value) {
field = value
invalidate()
}

init {
textPaint.textSize = textSize

isInitialized = true
}

override fun setTypeface(typeface: Typeface?) {
super.setTypeface(typeface)

if (typeface != null && isInitialized) {
// this is first called from the constructor when it's not initialized, yet
textPaint.typeface = typeface
postInvalidate()
}
}

public override fun onDraw(c: Canvas) {
textPaint.color = currentHintTextColor

getLineBounds(0, firstLineBounds)

super.onDraw(c)

// Now we can calculate what we need!
val text = text.toString()
val textWidth = if (text.isNotEmpty()) {
textPaint.measureText(text) + compoundPaddingStart
} else if (!hint.isNullOrBlank()) {
textPaint.measureText(hint?.toString()) + compoundPaddingStart
} else {
compoundPaddingStart.toFloat()
}

suffix?.let {
// We need to draw this like this because
// setting a right drawable doesn't work properly and we want this
// just after the text we are editing (but untouchable)
val y2 = firstLineBounds.bottom - textPaint.descent()
c.drawText(it, textWidth, y2, textPaint)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import androidx.camera.core.AspectRatio
import androidx.core.view.ViewCompat
import androidx.core.view.children
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.chip.ChipGroup
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
Expand Down Expand Up @@ -58,4 +60,8 @@ object ViewUtils {
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
}
}

fun ChipGroup.setChildrenEnabled(enable: Boolean) {
children.forEach { it.isEnabled = enable }
}
}
27 changes: 8 additions & 19 deletions documentscanner/src/main/res/layout/fragment_save.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,25 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="72dp"
android:layout_marginEnd="44dp"
android:layout_marginEnd="16dp"
app:errorEnabled="true"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/txt_file_name"
app:layout_constraintWidth_default="wrap"
app:suffixTextColor="?colorOnSurface"
tools:suffixText=".pdf">
app:layout_constraintTop_toBottomOf="@id/txt_file_name">

<com.google.android.material.textfield.TextInputEditText
<nz.mega.documentscanner.utils.SuffixTextInputEditText
android:id="@+id/edit_file_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="@drawable/ic_rename"
android:imeOptions="actionDone"
android:inputType="text"
android:lines="1"
android:maxLines="1"
android:paddingStart="0dp"
tools:text="Scanned_20200804" />
android:paddingEnd="0dp"
android:textColorHint="?colorOnSurface"
tools:text="Scanned_20200804.pdf" />

</com.google.android.material.textfield.TextInputLayout>

Expand All @@ -85,16 +84,6 @@
app:layout_constraintBaseline_toBaselineOf="@id/input_file_name"
app:layout_constraintStart_toStartOf="parent" />

<ImageView
android:id="@+id/img_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:baselineAlignBottom="true"
android:src="@drawable/ic_rename"
app:layout_constraintBaseline_toBaselineOf="@id/input_file_name"
app:layout_constraintEnd_toEndOf="parent" />

<View
android:id="@+id/separator_file_name"
android:layout_width="0dp"
Expand Down

0 comments on commit d713a81

Please sign in to comment.