Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4294 : Added Profile delete message with AlertDialog #5577

Merged
merged 20 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import org.oppia.android.app.profile.ResetPinDialogFragment
import org.oppia.android.app.profileprogress.ProfilePictureEditDialogFragment
import org.oppia.android.app.profileprogress.ProfileProgressFragment
import org.oppia.android.app.resumelesson.ResumeLessonFragment
import org.oppia.android.app.settings.profile.ProfileDeleteSuccessDialogFragment
import org.oppia.android.app.settings.profile.ProfileEditDeletionDialogFragment
import org.oppia.android.app.settings.profile.ProfileEditFragment
import org.oppia.android.app.settings.profile.ProfileListFragment
Expand Down Expand Up @@ -128,6 +129,7 @@ interface FragmentComponentImpl : FragmentComponent, ViewComponentBuilderInjecto
fun inject(cellularAudioDialogFragment: CellularAudioDialogFragment)
fun inject(completedStoryListFragment: CompletedStoryListFragment)
fun inject(conceptCardFragment: ConceptCardFragment)
fun inject(profileDeleteSuccessDialogFragment: ProfileDeleteSuccessDialogFragment)
fun inject(developerOptionsFragment: DeveloperOptionsFragment)
fun inject(downloadsTabFragment: DownloadsTabFragment)
fun inject(dragDropTestFragment: DragDropTestFragment)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.oppia.android.app.settings.profile

import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import org.oppia.android.R
import org.oppia.android.app.administratorcontrols.AdministratorControlsActivity
import org.oppia.android.app.fragment.FragmentComponentImpl
import org.oppia.android.app.fragment.InjectableDialogFragment
import org.oppia.android.app.translation.AppLanguageResourceHandler
import javax.inject.Inject

/** [DialogFragment] that notifies the user after a profile is successfully deleted. */
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
class ProfileDeleteSuccessDialogFragment : InjectableDialogFragment() {
@Inject
lateinit var resourceHandler: AppLanguageResourceHandler

companion object {
/** Tag for [ProfileDeleteSuccessDialogFragment]. */
const val DELETE_PROFILE_SUCCESS_DIALOG_FRAGMENT_TAG = "DELETE_PROFILE_SUCCESS_DIALOG_FRAGMENT"

/** Returns a new instance of [ProfileDeleteSuccessDialogFragment]. */
fun createNewInstance(): ProfileDeleteSuccessDialogFragment =
ProfileDeleteSuccessDialogFragment()
}

override fun onAttach(context: Context) {
super.onAttach(context)
(fragmentComponent as FragmentComponentImpl).inject(this)
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val alertDialog =
AlertDialog
.Builder(requireContext(), R.style.OppiaAlertDialogTheme)
.apply {
setMessage(
resourceHandler.getStringInLocale(R.string.profile_edit_delete_successful_message),
)
setPositiveButton(
resourceHandler
.getStringInLocale(R.string.profile_edit_delete_success_dialog_positive_button),
) { _, _ ->
if (requireContext().resources.getBoolean(R.bool.isTablet)) {
val intent = Intent(requireContext(), AdministratorControlsActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent)
} else {
val intent = Intent(requireContext(), ProfileListActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent)
}
}
}.create()
alertDialog.setCanceledOnTouchOutside(true)
return alertDialog
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.oppia.android.app.settings.profile

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import org.oppia.android.R
import org.oppia.android.app.administratorcontrols.AdministratorControlsActivity
import org.oppia.android.app.administratorcontrols.ProfileEditDeletionDialogListener
import org.oppia.android.app.devoptions.markchapterscompleted.MarkChaptersCompletedActivity
Expand Down Expand Up @@ -151,16 +149,11 @@ class ProfileEditFragmentPresenter @Inject constructor(
fragment,
Observer {
if (it is AsyncResult.Success) {
if (fragment.requireContext().resources.getBoolean(R.bool.isTablet)) {
val intent =
Intent(fragment.requireContext(), AdministratorControlsActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
fragment.startActivity(intent)
} else {
val intent = Intent(fragment.requireContext(), ProfileListActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
fragment.startActivity(intent)
}
ProfileDeleteSuccessDialogFragment.createNewInstance()
.showNow(
fragment.childFragmentManager,
ProfileDeleteSuccessDialogFragment.DELETE_PROFILE_SUCCESS_DIALOG_FRAGMENT_TAG
)
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
}
}
)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@
<string name="profile_edit_delete_dialog_message">All progress will be deleted and cannot be recovered.</string>
<string name="profile_edit_delete_dialog_positive">Delete</string>
<string name="profile_edit_delete_dialog_negative">Cancel</string>
<string name="profile_edit_delete_successful_message">Profile deleted successfully.</string>
<string name="profile_edit_allow_download_heading">Allow Download Access</string>
<string name="profile_edit_delete_success_dialog_positive_button">OK</string>
<string name="profile_edit_allow_download_sub">User is able to download and delete content without Administrator password</string>
<!-- ProfilePictureActivity -->
<string name="profile_picture_activity_title">Profile Picture</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ class ProfileEditActivityTest {
.inRoot(isDialog())
.perform(click())
testCoroutineDispatchers.runCurrent()
onView(withText(R.string.profile_edit_delete_success_dialog_positive_button))
.inRoot(isDialog())
.perform(click())
testCoroutineDispatchers.runCurrent()
if (context.resources.getBoolean(R.bool.isTablet)) {
intended(hasComponent(AdministratorControlsActivity::class.java.name))
} else {
Expand All @@ -266,6 +270,10 @@ class ProfileEditActivityTest {
.inRoot(isDialog())
.perform(click())
testCoroutineDispatchers.runCurrent()
onView(withText(R.string.profile_edit_delete_success_dialog_positive_button))
.inRoot(isDialog())
.perform(click())
testCoroutineDispatchers.runCurrent()
if (context.resources.getBoolean(R.bool.isTablet)) {
intended(hasComponent(AdministratorControlsActivity::class.java.name))
} else {
Expand Down
Loading
Loading