Skip to content

Commit

Permalink
Fix: #5186: MissingDefaultResource + AppCompatCustomView + FragmentTa…
Browse files Browse the repository at this point in the history
…gUsage (#5191)

<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->

Fixes #5186 [part of #5169]

1. `MissingDefaultResource` has been fixed already by
#5172. It had issues with
these plurals:
-
[minutes_ago](https://github.com/oppia/oppia-android/blob/e060e2ff265ce35c92f1b969f6d7ad002d1a62ad/app/src/main/res/values/strings.xml#L456)
-
[hours_ago](https://github.com/oppia/oppia-android/blob/e060e2ff265ce35c92f1b969f6d7ad002d1a62ad/app/src/main/res/values/strings.xml#L461C18-L461C27)
-
[days_ago](https://github.com/oppia/oppia-android/blob/e060e2ff265ce35c92f1b969f6d7ad002d1a62ad/app/src/main/res/values/strings.xml#L465C18-L465C26)

3. For `AppCompatCustomView`, it is fixed by replacing the Normal views
with AppCompat views

4. `<fragment/>` tags are replaced with
`<androidx.fragment.app.FragmentContainerView/>`, with some changes in
the NavigationDrawerFragment to ensure that binding has been initialized
before it is accessed.

## Screen Recording

https://github.com/oppia/oppia-android/assets/84731134/3a340cff-70a4-4e77-a1a3-e5b7a8c71a6e



## 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)).
<br>

---------

Co-authored-by: Adhiambo Peres <[email protected]>
  • Loading branch information
theMr17 and adhiamboperes authored Dec 5, 2023
1 parent bee2b58 commit 5075c54
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 44 deletions.
1 change: 1 addition & 0 deletions app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ kt_android_library(
"//third_party:androidx_core_core-ktx",
"//third_party:androidx_databinding_databinding-common",
"//third_party:androidx_databinding_databinding-runtime",
"//third_party:androidx_fragment_fragment",
"//third_party:circularimageview_circular_image_view",
"//utility/src/main/java/org/oppia/android/util/accessibility",
"//utility/src/main/java/org/oppia/android/util/parser/html:html_parser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class AdministratorControlsActivityPresenter @Inject constructor(
.findFragmentById(
R.id.administrator_controls_activity_fragment_navigation_drawer
) as NavigationDrawerFragment
navigationDrawerFragment.setUpDrawer(
navigationDrawerFragment.initializeDrawer(
binding.administratorControlsActivityDrawerLayout,
toolbar, /* menuItemId= */ 0
)
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 @@ -22,12 +22,12 @@ import org.oppia.android.app.utility.KeyboardHelper.Companion.showSoftKeyboard

// TODO(#4135): Add a dedicated test suite for this class.

/** 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

Expand Down Expand Up @@ -71,7 +71,7 @@ class FractionInputInteractionView @JvmOverloads constructor(

private fun restoreHint() {
hint = hintText
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
if (text?.isEmpty() == true) setTypeface(typeface, Typeface.ITALIC)
setSingleLine(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,7 +28,7 @@ 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

Expand Down Expand Up @@ -84,7 +84,7 @@ class MathExpressionInteractionsView @JvmOverloads constructor(

private fun restoreHint() {
hint = hintText
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
if (text?.isEmpty() == true) setTypeface(typeface, Typeface.ITALIC)
setSingleLine(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,12 +20,12 @@ 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 = ""

Expand Down Expand Up @@ -69,7 +69,7 @@ class NumericInputInteractionView @JvmOverloads constructor(

private fun restoreHint() {
hint = hintText
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
if (text?.isEmpty() == true) setTypeface(typeface, Typeface.ITALIC)
setSingleLine(false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ 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

Expand Down Expand Up @@ -59,7 +59,7 @@ class RatioInputInteractionView @JvmOverloads constructor(

private fun restoreHint() {
hint = hintText
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
if (text?.isEmpty() == true) setTypeface(typeface, Typeface.ITALIC)
setSingleLine(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,12 +17,12 @@ 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

Expand Down Expand Up @@ -66,7 +66,7 @@ class TextInputInteractionView @JvmOverloads constructor(

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 @@ -41,7 +41,7 @@ class DeveloperOptionsActivityPresenter @Inject constructor(
.findFragmentById(
R.id.developer_options_activity_fragment_navigation_drawer
) as NavigationDrawerFragment
navigationDrawerFragment.setUpDrawer(
navigationDrawerFragment.initializeDrawer(
binding.developerOptionsActivityDrawerLayout,
toolbar, menuItemId = -1
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class NavigationDrawerFragment :
return navigationDrawerFragmentPresenter.handleCreateView(inflater, container)
}

fun setUpDrawer(drawerLayout: DrawerLayout, toolbar: Toolbar, menuItemId: Int) {
navigationDrawerFragmentPresenter.setUpDrawer(drawerLayout, toolbar, menuItemId)
fun initializeDrawer(drawerLayout: DrawerLayout, toolbar: Toolbar, menuItemId: Int) {
navigationDrawerFragmentPresenter.initializeDrawer(drawerLayout, toolbar, menuItemId)
}

override fun routeToProfileProgress(profileId: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@ class NavigationDrawerFragmentPresenter @Inject constructor(
private lateinit var drawerLayout: DrawerLayout
private lateinit var binding: DrawerFragmentBinding
private lateinit var profileId: ProfileId
private lateinit var toolbar: Toolbar
private var previousMenuItemId: Int? = null
private var internalProfileId: Int = -1
private var menuItemId: Int = 0

fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? {
binding = DrawerFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
binding.fragmentDrawerNavView.setNavigationItemSelectedListener(this)

setUpDrawer(drawerLayout, toolbar, menuItemId)

fragment.setHasOptionsMenu(true)

internalProfileId = activity.intent.getIntExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, -1)
Expand Down Expand Up @@ -366,11 +370,17 @@ class NavigationDrawerFragmentPresenter @Inject constructor(
}
}

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

/**
* Initializes the navigation drawer for the specified [DrawerLayout] and [Toolbar], which the host activity is
* expected to provide. The [menuItemId] corresponds to the menu ID of the current activity, for navigation purposes.
*/
fun setUpDrawer(drawerLayout: DrawerLayout, toolbar: Toolbar, menuItemId: Int) {
private fun setUpDrawer(drawerLayout: DrawerLayout, toolbar: Toolbar, menuItemId: Int) {
previousMenuItemId = if (activity is TopicActivity) null else menuItemId
if (menuItemId != 0 && menuItemId != -1) {
getFooterViewModel().isAdministratorControlsSelected.set(false)
Expand Down Expand Up @@ -407,7 +417,6 @@ class NavigationDrawerFragmentPresenter @Inject constructor(
true
}
}
this.drawerLayout = drawerLayout
drawerToggle = object : ActionBarDrawerToggle(
fragment.activity,
drawerLayout,
Expand Down Expand Up @@ -446,7 +455,6 @@ class NavigationDrawerFragmentPresenter @Inject constructor(
// For showing navigation drawer in DeveloperOptionsActivity
else if (menuItemId == -1) getFooterViewModel().isDeveloperOptionsSelected.set(true)
uncheckAllMenuItemsWhenAdministratorControlsOrDeveloperOptionsIsSelected()
this.drawerLayout = drawerLayout
drawerToggle = object : ActionBarDrawerToggle(
fragment.activity,
drawerLayout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class HelpActivityPresenter @Inject constructor(
.findFragmentById(
R.id.help_activity_fragment_navigation_drawer
) as NavigationDrawerFragment
navigationDrawerFragment.setUpDrawer(
navigationDrawerFragment.initializeDrawer(
activity.findViewById<View>(R.id.help_activity_drawer_layout) as DrawerLayout,
toolbar, R.id.nav_help
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class HomeActivityPresenter @Inject constructor(private val activity: AppCompatA
navigationDrawerFragment = activity
.supportFragmentManager
.findFragmentById(R.id.home_activity_fragment_navigation_drawer) as NavigationDrawerFragment
navigationDrawerFragment!!.setUpDrawer(
navigationDrawerFragment!!.initializeDrawer(
activity.findViewById<View>(R.id.home_activity_drawer_layout) as DrawerLayout,
toolbar, R.id.nav_home
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class OptionsActivityPresenter @Inject constructor(
.findFragmentById(
R.id.options_activity_fragment_navigation_drawer
) as NavigationDrawerFragment
navigationDrawerFragment!!.setUpDrawer(
navigationDrawerFragment!!.initializeDrawer(
activity.findViewById<View>(R.id.options_activity_drawer_layout) as DrawerLayout,
toolbar, R.id.nav_options
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
app:layout_constraintTop_toBottomOf="@id/administrator_controls_activity_toolbar" />
</androidx.constraintlayout.widget.ConstraintLayout>

<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/administrator_controls_activity_fragment_navigation_drawer"
android:name="org.oppia.android.app.drawer.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout-sw600dp/help_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/help_activity_fragment_navigation_drawer"
android:name="org.oppia.android.app.drawer.NavigationDrawerFragment"
android:layout_width="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout-sw600dp/option_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/options_activity_fragment_navigation_drawer"
android:name="org.oppia.android.app.drawer.NavigationDrawerFragment"
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
android:layout_height="match_parent" />
</LinearLayout>

<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/administrator_controls_activity_fragment_navigation_drawer"
android:name="org.oppia.android.app.drawer.NavigationDrawerFragment"
android:layout_width="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/developer_options_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</FrameLayout>
</LinearLayout>

<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/developer_options_activity_fragment_navigation_drawer"
android:name="org.oppia.android.app.drawer.NavigationDrawerFragment"
android:layout_width="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/help_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</FrameLayout>
</LinearLayout>

<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/help_activity_fragment_navigation_drawer"
android:name="org.oppia.android.app.drawer.NavigationDrawerFragment"
android:layout_width="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/home_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
android:layout_weight="1" />
</LinearLayout>

<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/home_activity_fragment_navigation_drawer"
android:name="org.oppia.android.app.drawer.NavigationDrawerFragment"
android:layout_width="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/option_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</FrameLayout>
</LinearLayout>

<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/options_activity_fragment_navigation_drawer"
android:name="org.oppia.android.app.drawer.NavigationDrawerFragment"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ kt_android_library(
"//testing/src/main/java/org/oppia/android/testing/threading:test_coroutine_dispatchers",
"//testing/src/main/java/org/oppia/android/testing/time:fake_oppia_clock",
"//third_party:androidx_core_core-ktx",
"//third_party:androidx_fragment_fragment",
"//third_party:androidx_lifecycle_lifecycle-livedata-ktx",
"//third_party:androidx_test_espresso_espresso-accessibility",
"//third_party:androidx_test_espresso_espresso-contrib",
Expand Down
Loading

0 comments on commit 5075c54

Please sign in to comment.