Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit d713a81

Browse files
authored
Merge pull request #22 from meganz/release/2.0.6
release/2.0.6
2 parents 07b173a + 07968c3 commit d713a81

5 files changed

Lines changed: 117 additions & 28 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
buildscript {
22
ext {
3-
versionCode = 12
4-
versionName = "2.0.5"
3+
versionCode = 13
4+
versionName = "2.0.6"
55
compileSdkVersion = 29
66
minSdkVersion = 21
77
group = "com.github.meganz"

documentscanner/src/main/java/nz/mega/documentscanner/save/SaveFragment.kt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.os.Bundle
44
import android.view.LayoutInflater
55
import android.view.View
66
import android.view.ViewGroup
7+
import android.view.inputmethod.EditorInfo
78
import androidx.core.view.children
89
import androidx.core.view.isVisible
910
import androidx.core.widget.doAfterTextChanged
@@ -16,7 +17,7 @@ import nz.mega.documentscanner.R
1617
import nz.mega.documentscanner.data.Document
1718
import nz.mega.documentscanner.databinding.FragmentSaveBinding
1819
import nz.mega.documentscanner.databinding.ItemDestinationBinding
19-
import nz.mega.documentscanner.utils.ViewUtils.selectLastCharacter
20+
import nz.mega.documentscanner.utils.ViewUtils.setChildrenEnabled
2021

2122
class SaveFragment : Fragment() {
2223

@@ -32,7 +33,7 @@ class SaveFragment : Fragment() {
3233
inflater: LayoutInflater,
3334
container: ViewGroup?,
3435
savedInstanceState: Bundle?
35-
): View? {
36+
): View {
3637
binding = FragmentSaveBinding.inflate(inflater, container, false)
3738
return binding.root
3839
}
@@ -48,12 +49,19 @@ class SaveFragment : Fragment() {
4849
viewModel.setDocumentTitle(editable?.toString())
4950
}
5051

51-
binding.editFileName.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->
52-
binding.imgEdit.isVisible = !hasFocus
52+
binding.editFileName.setOnEditorActionListener { view, actionId, _ ->
53+
if (actionId == EditorInfo.IME_ACTION_DONE) {
54+
view.clearFocus()
55+
}
56+
false
5357
}
5458

55-
binding.imgEdit.setOnClickListener {
56-
binding.editFileName.selectLastCharacter()
59+
binding.editFileName.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->
60+
if (hasFocus) {
61+
binding.editFileName.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0)
62+
} else {
63+
binding.editFileName.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.ic_rename, 0)
64+
}
5765
}
5866

5967
binding.chipGroupFileType.setOnCheckedChangeListener { _, checkedId ->
@@ -140,7 +148,7 @@ class SaveFragment : Fragment() {
140148
}
141149
}
142150

143-
binding.inputFileName.suffixText = fileType.suffix
151+
binding.editFileName.suffix = " ${fileType.suffix}"
144152
binding.imgFileType.setImageResource(imageResId)
145153

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

170178
private fun showProgress(show: Boolean) {
171179
binding.btnSave.isEnabled = !show
180+
binding.editFileName.isEnabled = !show
181+
binding.chipGroupFileType.setChildrenEnabled(!show)
182+
binding.chipGroupDestinations.setChildrenEnabled(!show)
183+
binding.chipGroupQuality.setChildrenEnabled(!show)
172184

173185
if (show) {
174186
binding.progress.show()
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package nz.mega.documentscanner.utils
2+
3+
import android.content.Context
4+
import android.graphics.Canvas
5+
import android.graphics.Paint
6+
import android.graphics.Rect
7+
import android.graphics.Typeface
8+
import android.text.TextPaint
9+
import android.util.AttributeSet
10+
import com.google.android.material.textfield.TextInputEditText
11+
12+
/**
13+
* [TextInputEditText] with suffix support.
14+
*
15+
* Inspired by https://github.com/tobiasschuerg/android-prefix-suffix-edit-text/
16+
*/
17+
class SuffixTextInputEditText constructor(
18+
context: Context,
19+
attrs: AttributeSet
20+
) : TextInputEditText(context, attrs) {
21+
22+
// These are used to store details obtained from the EditText's rendering process
23+
private val firstLineBounds = Rect()
24+
private var isInitialized = false
25+
26+
private val textPaint: TextPaint by lazy {
27+
TextPaint().apply {
28+
color = currentHintTextColor
29+
textAlign = Paint.Align.LEFT
30+
isAntiAlias = true
31+
this.typeface = typeface
32+
}
33+
}
34+
35+
var suffix: String? = null
36+
set(value) {
37+
field = value
38+
invalidate()
39+
}
40+
41+
init {
42+
textPaint.textSize = textSize
43+
44+
isInitialized = true
45+
}
46+
47+
override fun setTypeface(typeface: Typeface?) {
48+
super.setTypeface(typeface)
49+
50+
if (typeface != null && isInitialized) {
51+
// this is first called from the constructor when it's not initialized, yet
52+
textPaint.typeface = typeface
53+
postInvalidate()
54+
}
55+
}
56+
57+
public override fun onDraw(c: Canvas) {
58+
textPaint.color = currentHintTextColor
59+
60+
getLineBounds(0, firstLineBounds)
61+
62+
super.onDraw(c)
63+
64+
// Now we can calculate what we need!
65+
val text = text.toString()
66+
val textWidth = if (text.isNotEmpty()) {
67+
textPaint.measureText(text) + compoundPaddingStart
68+
} else if (!hint.isNullOrBlank()) {
69+
textPaint.measureText(hint?.toString()) + compoundPaddingStart
70+
} else {
71+
compoundPaddingStart.toFloat()
72+
}
73+
74+
suffix?.let {
75+
// We need to draw this like this because
76+
// setting a right drawable doesn't work properly and we want this
77+
// just after the text we are editing (but untouchable)
78+
val y2 = firstLineBounds.bottom - textPaint.descent()
79+
c.drawText(it, textWidth, y2, textPaint)
80+
}
81+
}
82+
}

documentscanner/src/main/java/nz/mega/documentscanner/utils/ViewUtils.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import android.view.inputmethod.InputMethodManager
99
import android.widget.EditText
1010
import androidx.camera.core.AspectRatio
1111
import androidx.core.view.ViewCompat
12+
import androidx.core.view.children
1213
import androidx.viewpager2.widget.ViewPager2
14+
import com.google.android.material.chip.ChipGroup
1315
import kotlin.math.abs
1416
import kotlin.math.max
1517
import kotlin.math.min
@@ -58,4 +60,8 @@ object ViewUtils {
5860
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
5961
}
6062
}
63+
64+
fun ChipGroup.setChildrenEnabled(enable: Boolean) {
65+
children.forEach { it.isEnabled = enable }
66+
}
6167
}

documentscanner/src/main/res/layout/fragment_save.xml

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,25 @@
5151
android:layout_width="0dp"
5252
android:layout_height="wrap_content"
5353
android:layout_marginStart="72dp"
54-
android:layout_marginEnd="44dp"
54+
android:layout_marginEnd="16dp"
5555
app:errorEnabled="true"
56-
app:layout_constrainedWidth="true"
5756
app:layout_constraintEnd_toEndOf="parent"
58-
app:layout_constraintHorizontal_bias="0.0"
5957
app:layout_constraintStart_toStartOf="parent"
60-
app:layout_constraintTop_toBottomOf="@id/txt_file_name"
61-
app:layout_constraintWidth_default="wrap"
62-
app:suffixTextColor="?colorOnSurface"
63-
tools:suffixText=".pdf">
58+
app:layout_constraintTop_toBottomOf="@id/txt_file_name">
6459

65-
<com.google.android.material.textfield.TextInputEditText
60+
<nz.mega.documentscanner.utils.SuffixTextInputEditText
6661
android:id="@+id/edit_file_name"
6762
android:layout_width="match_parent"
6863
android:layout_height="wrap_content"
64+
android:drawableEnd="@drawable/ic_rename"
65+
android:imeOptions="actionDone"
6966
android:inputType="text"
7067
android:lines="1"
7168
android:maxLines="1"
7269
android:paddingStart="0dp"
73-
tools:text="Scanned_20200804" />
70+
android:paddingEnd="0dp"
71+
android:textColorHint="?colorOnSurface"
72+
tools:text="Scanned_20200804.pdf" />
7473

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

@@ -85,16 +84,6 @@
8584
app:layout_constraintBaseline_toBaselineOf="@id/input_file_name"
8685
app:layout_constraintStart_toStartOf="parent" />
8786

88-
<ImageView
89-
android:id="@+id/img_edit"
90-
android:layout_width="wrap_content"
91-
android:layout_height="wrap_content"
92-
android:layout_marginEnd="16dp"
93-
android:baselineAlignBottom="true"
94-
android:src="@drawable/ic_rename"
95-
app:layout_constraintBaseline_toBaselineOf="@id/input_file_name"
96-
app:layout_constraintEnd_toEndOf="parent" />
97-
9887
<View
9988
android:id="@+id/separator_file_name"
10089
android:layout_width="0dp"

0 commit comments

Comments
 (0)