-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
186 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
.../org/hyperskill/app/android/step_quiz_fill_blanks/dialog/FillBlanksInputDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.hyperskill.app.android.step_quiz_fill_blanks.dialog | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.inputmethod.EditorInfo | ||
import android.view.inputmethod.InputMethodManager | ||
import by.kirich1409.viewbindingdelegate.viewBinding | ||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment | ||
import org.hyperskill.app.android.R | ||
import org.hyperskill.app.android.databinding.FragmentFillBlanksInputBinding | ||
import ru.nobird.android.view.base.ui.extension.argument | ||
|
||
class FillBlanksInputDialogFragment : BottomSheetDialogFragment() { | ||
companion object { | ||
const val TAG: String = "FillBlanksInputDialogFragment" | ||
|
||
private const val ARG_INDEX = "INDEX" | ||
private const val ARG_TEXT = "TEXT" | ||
|
||
fun newInstance( | ||
index: Int, | ||
text: String | ||
): FillBlanksInputDialogFragment = | ||
FillBlanksInputDialogFragment().apply { | ||
this.index = index | ||
this.text = text | ||
} | ||
} | ||
|
||
private var index: Int by argument() | ||
private var text: String by argument() | ||
|
||
private val fillBlanksInputBinding: FragmentFillBlanksInputBinding by viewBinding( | ||
FragmentFillBlanksInputBinding::bind | ||
) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setStyle(STYLE_NO_TITLE, R.style.TopCornersRoundedBottomSheetDialog) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? = | ||
inflater.inflate(R.layout.fragment_fill_blanks_input, container, false) | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
if (savedInstanceState != null) { | ||
index = savedInstanceState.getInt(ARG_INDEX) | ||
text = savedInstanceState.getString(ARG_TEXT) ?: return | ||
} | ||
with(fillBlanksInputBinding) { | ||
fillBlanksInputField.append(text) | ||
fillBlanksInputField.setOnEditorActionListener { _, actionId, _ -> | ||
if (actionId == EditorInfo.IME_ACTION_DONE) { | ||
super.dismiss() | ||
} | ||
false | ||
} | ||
fillBlanksInputField.post { | ||
fillBlanksInputField.requestFocus() | ||
val inputMethodManager = | ||
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | ||
inputMethodManager.showSoftInput(fillBlanksInputField, InputMethodManager.SHOW_IMPLICIT) | ||
} | ||
} | ||
} | ||
|
||
override fun onPause() { | ||
(parentFragment as? Callback) | ||
?.onSyncInputItemWithParent( | ||
index = index, | ||
text = fillBlanksInputBinding.fillBlanksInputField.text.toString() | ||
) | ||
super.onPause() | ||
} | ||
|
||
override fun onSaveInstanceState(outState: Bundle) { | ||
super.onSaveInstanceState(outState) | ||
outState.putInt(ARG_INDEX, index) | ||
outState.putString(ARG_TEXT, text) | ||
} | ||
|
||
interface Callback { | ||
fun onSyncInputItemWithParent(index: Int, text: String) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
androidHyperskillApp/src/main/res/drawable/bg_step_quiz_fill_blanks_input_text_field.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
<stroke | ||
android:width="1dp" | ||
android:color="@color/color_primary" /> | ||
<corners android:radius="@dimen/step_quiz_fill_blanks_input_radius" /> | ||
</shape> |
31 changes: 31 additions & 0 deletions
31
androidHyperskillApp/src/main/res/layout/fragment_fill_blanks_input.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<com.google.android.material.textfield.TextInputEditText | ||
android:id="@+id/fillBlanksInputField" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:minHeight="@dimen/step_quiz_fill_blanks_input_text_min_height" | ||
app:fontFamily="@font/roboto_medium" | ||
android:textAppearance="?textAppearanceBody1" | ||
android:maxLines="1" | ||
android:lines="1" | ||
android:singleLine="true" | ||
android:imeOptions="actionDone" | ||
android:hint="@string/step_quiz_text_field_hint" | ||
android:background="@drawable/bg_step_quiz_fill_blanks_input_text_field" | ||
android:gravity="center_vertical" | ||
android:paddingStart="16dp" | ||
android:paddingEnd="12dp" | ||
android:paddingTop="12dp" | ||
android:paddingBottom="8dp" | ||
android:layout_margin="20dp" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
/> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters