Skip to content

Commit

Permalink
Fix #5168: appcompat custom view fragment tag usage lint error (#5582)
Browse files Browse the repository at this point in the history
<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
Fixes [#5168](#5186)
1. For `AppCompatCustomView`, replaced it with AppCompat Views
2. For `FragmentTagUsage`, replaced `<fragment/>` with
<androidx.fragment.app.FragmentContainerView/>. Made some changes to
`NavigationDrawerFragment` to:
- ensured `setUpDrawer()` is called first to initialize the
`drawerLayout`, `toolbar` and `menuItemId`
- followed by `onCreateView()` ensuring to bind the fragment
- followed on `onViewCreated()` to setup drawer functions/listeners
3. Faced an issue similar to [drawer not
working](#5266), by
minimising and resuming the app, (the drawer button stopped working).
- Fixed this by removing `onRestart()` from respective Activies making a
call to `setUpNavigationDrawer()` which at that point is not necessary,
since the fragment has been inflated initially, and would be re-inflated
if the fragment is recreated.
4. Also tested this
[bug](#5284) following the
steps to reproduce. No issues encountered

**Lint report (Before):**
![Screenshot 2024-11-24 at 6 11
50 AM](https://github.com/user-attachments/assets/479da7e9-ea3d-47d5-9c69-ff5c97992750)

**Lint report (After):**
![Screenshot 2024-11-24 at 8 06
27 AM](https://github.com/user-attachments/assets/68ef6cb9-b9b6-45ac-a901-ed64540ee674)

## Screen Record


https://github.com/user-attachments/assets/6db98657-d470-4263-a5ac-d055f4d64e66



## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).
  • Loading branch information
tobioyelekan authored Dec 5, 2024
1 parent 242fef4 commit 42b1c8f
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 85 deletions.
1 change: 1 addition & 0 deletions app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ android_library(
"//third_party:androidx_databinding_databinding-common",
"//third_party:androidx_databinding_databinding-runtime",
"//third_party:androidx_drawerlayout_drawerlayout",
"//third_party:androidx_fragment_fragment",
"//third_party:androidx_lifecycle_lifecycle-livedata-core",
"//third_party:androidx_recyclerview_recyclerview",
"//third_party:androidx_viewpager2_viewpager2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,20 @@ class ClassroomListActivity :
title = resourceHandler.getStringInLocale(R.string.classroom_list_activity_title)
}

override fun onRestart() {
super.onRestart()
classroomListActivityPresenter.handleOnRestart()
override fun onBackPressed() {
val previousFragment =
supportFragmentManager.findFragmentByTag(TAG_SWITCH_PROFILE_DIALOG)
if (previousFragment != null) {
supportFragmentManager.beginTransaction().remove(previousFragment).commitNow()
}
val exitProfileDialogArguments =
ExitProfileDialogArguments
.newBuilder()
.setHighlightItem(HighlightItem.NONE)
.build()
val dialogFragment = ExitProfileDialogFragment
.newInstance(exitProfileDialogArguments = exitProfileDialogArguments)
dialogFragment.showNow(supportFragmentManager, TAG_SWITCH_PROFILE_DIALOG)
}

override fun routeToRecentlyPlayed(recentlyPlayedActivityTitle: RecentlyPlayedActivityTitle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ class ClassroomListActivityPresenter @Inject constructor(private val activity: A
}
}

/** Handles the activity restart. Re-initializes the navigation drawer. */
fun handleOnRestart() {
setUpNavigationDrawer()
}

private fun setUpNavigationDrawer() {
val toolbar = activity.findViewById<View>(R.id.classroom_list_activity_toolbar) as Toolbar
activity.setSupportActionBar(toolbar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.view.KeyEvent.ACTION_UP
import android.view.KeyEvent.KEYCODE_BACK
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import androidx.appcompat.widget.AppCompatEditText
import org.oppia.android.app.player.state.listener.StateKeyboardButtonListener
import org.oppia.android.app.utility.KeyboardHelper.Companion.hideSoftKeyboard
import org.oppia.android.app.utility.KeyboardHelper.Companion.showSoftKeyboard
Expand All @@ -20,19 +20,19 @@ import org.oppia.android.app.utility.KeyboardHelper.Companion.showSoftKeyboard
// background="@drawable/edit_text_background"
// maxLength="200".

/** The custom EditText class for fraction input interaction view. */
/** The custom AppCompatEditText class for fraction input interaction view. */
class FractionInputInteractionView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.editTextStyle
) : EditText(context, attrs, defStyle), View.OnFocusChangeListener {
) : AppCompatEditText(context, attrs, defStyle), View.OnFocusChangeListener {
private var hintText: CharSequence = ""
private val stateKeyboardButtonListener: StateKeyboardButtonListener

init {
onFocusChangeListener = this
// Assume multi-line for the purpose of properly showing long hints.
setSingleLine(hint != null)
isSingleLine = hint != null
stateKeyboardButtonListener = context as StateKeyboardButtonListener
}

Expand Down Expand Up @@ -64,12 +64,12 @@ class FractionInputInteractionView @JvmOverloads constructor(
private fun hideHint() {
hint = ""
typeface = Typeface.DEFAULT
setSingleLine(true)
isSingleLine = true
}

private fun restoreHint() {
hint = hintText
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
setSingleLine(false)
if (text?.isEmpty() == true) setTypeface(typeface, Typeface.ITALIC)
isSingleLine = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.util.AttributeSet
import android.view.KeyEvent
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import androidx.appcompat.widget.AppCompatEditText
import org.oppia.android.app.player.state.listener.StateKeyboardButtonListener
import org.oppia.android.app.utility.KeyboardHelper.Companion.hideSoftKeyboard
import org.oppia.android.app.utility.KeyboardHelper.Companion.showSoftKeyboard
Expand All @@ -19,7 +19,7 @@ import org.oppia.android.app.utility.KeyboardHelper.Companion.showSoftKeyboard
// maxLength="200".

/**
* The custom [EditText] class for math expression interactions interaction view.
* The custom [AppCompatEditText] class for math expression interactions interaction view.
*
* Note that the hint should be set via [setPlaceholder] to ensure that it's properly initialized if
* using databinding, otherwise setting the hint through android:hint should work fine.
Expand All @@ -28,14 +28,14 @@ class MathExpressionInteractionsView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.editTextStyle
) : EditText(context, attrs, defStyle), View.OnFocusChangeListener {
) : AppCompatEditText(context, attrs, defStyle), View.OnFocusChangeListener {
private var hintText: CharSequence = ""
private val stateKeyboardButtonListener: StateKeyboardButtonListener

init {
onFocusChangeListener = this
// Assume multi-line for the purpose of properly showing long hints.
setSingleLine(hint != null)
isSingleLine = hint != null
stateKeyboardButtonListener = context as StateKeyboardButtonListener
}

Expand Down Expand Up @@ -79,12 +79,13 @@ class MathExpressionInteractionsView @JvmOverloads constructor(
private fun hideHint() {
hint = ""
typeface = Typeface.DEFAULT
setSingleLine(true)
isSingleLine = true
}

private fun restoreHint() {
hint = hintText
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
setSingleLine(false)

if (text?.isEmpty() == true) setTypeface(typeface, Typeface.ITALIC)
isSingleLine = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.view.KeyEvent.ACTION_UP
import android.view.KeyEvent.KEYCODE_BACK
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import androidx.appcompat.widget.AppCompatEditText
import org.oppia.android.app.player.state.listener.StateKeyboardButtonListener
import org.oppia.android.app.utility.KeyboardHelper.Companion.hideSoftKeyboard
import org.oppia.android.app.utility.KeyboardHelper.Companion.showSoftKeyboard
Expand All @@ -20,19 +20,19 @@ import org.oppia.android.app.utility.KeyboardHelper.Companion.showSoftKeyboard
// background="@drawable/edit_text_background"
// maxLength="200".

/** The custom EditText class for numeric input interaction view. */
/** The custom AppCompatEditText class for numeric input interaction view. */
class NumericInputInteractionView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.editTextStyle
) : EditText(context, attrs, defStyle), View.OnFocusChangeListener {
) : AppCompatEditText(context, attrs, defStyle), View.OnFocusChangeListener {
private val stateKeyboardButtonListener: StateKeyboardButtonListener
private var hintText: CharSequence = ""

init {
onFocusChangeListener = this
// Assume multi-line for the purpose of properly showing long hints.
setSingleLine(hint != null)
isSingleLine = hint != null
stateKeyboardButtonListener = context as StateKeyboardButtonListener
}

Expand Down Expand Up @@ -64,12 +64,12 @@ class NumericInputInteractionView @JvmOverloads constructor(
private fun hideHint() {
hint = ""
typeface = Typeface.DEFAULT
setSingleLine(true)
isSingleLine = true
}

private fun restoreHint() {
hint = hintText
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
setSingleLine(false)
if (text?.isEmpty() == true) setTypeface(typeface, Typeface.ITALIC)
isSingleLine = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import android.util.AttributeSet
import android.view.KeyEvent
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import androidx.appcompat.widget.AppCompatEditText
import org.oppia.android.app.player.state.listener.StateKeyboardButtonListener
import org.oppia.android.app.utility.KeyboardHelper

/** The custom EditText class for ratio input interaction view. */
/** The custom AppCompatEditText class for ratio input interaction view. */
class RatioInputInteractionView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.editTextStyle
) : EditText(context, attrs, defStyle), View.OnFocusChangeListener {
) : AppCompatEditText(context, attrs, defStyle), View.OnFocusChangeListener {
private var hintText: CharSequence = ""
private val stateKeyboardButtonListener: StateKeyboardButtonListener

init {
onFocusChangeListener = this
// Assume multi-line for the purpose of properly showing long hints.
setSingleLine(hint != null)
isSingleLine = hint != null
stateKeyboardButtonListener = context as StateKeyboardButtonListener
}

Expand Down Expand Up @@ -54,12 +54,12 @@ class RatioInputInteractionView @JvmOverloads constructor(
private fun hideHint() {
hint = ""
typeface = Typeface.DEFAULT
setSingleLine(true)
isSingleLine = true
}

private fun restoreHint() {
hint = hintText
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
setSingleLine(false)
if (text?.isEmpty() == true) setTypeface(typeface, Typeface.ITALIC)
isSingleLine = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.util.AttributeSet
import android.view.KeyEvent
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import androidx.appcompat.widget.AppCompatEditText
import org.oppia.android.app.player.state.listener.StateKeyboardButtonListener
import org.oppia.android.app.utility.KeyboardHelper.Companion.hideSoftKeyboard
import org.oppia.android.app.utility.KeyboardHelper.Companion.showSoftKeyboard
Expand All @@ -17,19 +17,19 @@ import org.oppia.android.app.utility.KeyboardHelper.Companion.showSoftKeyboard
// background="@drawable/edit_text_background"
// maxLength="200".

/** The custom EditText class for text input interaction view. */
/** The custom AppCompatEditText class for text input interaction view. */
class TextInputInteractionView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = android.R.attr.editTextStyle
) : EditText(context, attrs, defStyle), View.OnFocusChangeListener {
) : AppCompatEditText(context, attrs, defStyle), View.OnFocusChangeListener {
private var hintText: CharSequence = ""
private val stateKeyboardButtonListener: StateKeyboardButtonListener

init {
onFocusChangeListener = this
// Assume multi-line for the purpose of properly showing long hints.
setSingleLine(hint != null)
isSingleLine = hint != null
stateKeyboardButtonListener = context as StateKeyboardButtonListener
}

Expand Down Expand Up @@ -61,12 +61,12 @@ class TextInputInteractionView @JvmOverloads constructor(
private fun hideHint() {
hint = ""
typeface = Typeface.DEFAULT
setSingleLine(true)
isSingleLine = true
}

private fun restoreHint() {
hint = hintText
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
setSingleLine(false)
if (text?.isEmpty() == true) setTypeface(typeface, Typeface.ITALIC)
isSingleLine = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class NavigationDrawerFragment :
RouteToProfileProgressListener,
ExitProfileDialogInterface {

private lateinit var drawerLayout: DrawerLayout
private lateinit var toolbar: Toolbar
private var menuItemId: Int = 0

@Inject
lateinit var navigationDrawerFragmentPresenter: NavigationDrawerFragmentPresenter

Expand All @@ -33,10 +37,17 @@ class NavigationDrawerFragment :
return navigationDrawerFragmentPresenter.handleCreateView(inflater, container)
}

fun setUpDrawer(drawerLayout: DrawerLayout, toolbar: Toolbar, menuItemId: Int) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
navigationDrawerFragmentPresenter.setUpDrawer(drawerLayout, toolbar, menuItemId)
}

fun setUpDrawer(drawerLayout: DrawerLayout, toolbar: Toolbar, menuItemId: Int) {
this.drawerLayout = drawerLayout
this.toolbar = toolbar
this.menuItemId = menuItemId
}

override fun routeToProfileProgress(profileId: Int) {
navigationDrawerFragmentPresenter.openProfileProgress(profileId)
}
Expand Down
Loading

0 comments on commit 42b1c8f

Please sign in to comment.