Skip to content

Fix Crash Edit Categories Fragment #5510

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

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 @@ -102,17 +102,17 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
wikiText = bundle.getString("WikiText");
nearbyPlaceCategory = bundle.getString(SELECTED_NEARBY_PLACE_CATEGORY);
}
if(callback!=null) {
init();
presenter.getCategories().observe(getViewLifecycleOwner(), this::setCategories);
}
init();
presenter.getCategories().observe(getViewLifecycleOwner(), this::setCategories);

}

private void init() {
if (media == null) {
tvTitle.setText(getString(R.string.step_count, callback.getIndexInViewFlipper(this) + 1,
callback.getTotalNumberOfSteps(), getString(R.string.categories_activity_title)));
if (callback != null) {
tvTitle.setText(getString(R.string.step_count, callback.getIndexInViewFlipper(this) + 1,
callback.getTotalNumberOfSteps(), getString(R.string.categories_activity_title)));
}
} else {
tvTitle.setText(R.string.edit_categories);
tvSubTitle.setVisibility(View.GONE);
Expand Down Expand Up @@ -221,7 +221,9 @@ public void run() {

@Override
public void goToNextScreen() {
callback.onNextButtonClicked(callback.getIndexInViewFlipper(this));
if (callback != null){
callback.onNextButtonClicked(callback.getIndexInViewFlipper(this));
}
}

@Override
Expand Down Expand Up @@ -314,7 +316,9 @@ public void onPreviousButtonClicked() {
mediaDetailFragment.onResume();
goBackToPreviousScreen();
} else {
callback.onPreviousButtonClicked(callback.getIndexInViewFlipper(this));
if (callback != null) {
callback.onPreviousButtonClicked(callback.getIndexInViewFlipper(this));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.ProgressDialog
import android.content.Context
import android.os.Looper
import android.text.Editable
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
Expand Down Expand Up @@ -116,7 +117,6 @@ class UploadCategoriesFragmentUnitTests {
Whitebox.setInternalState(fragment, "pbCategories", pbCategories)
Whitebox.setInternalState(fragment, "tilContainerEtSearch", tilContainerEtSearch)
Whitebox.setInternalState(fragment, "adapter", adapter)
Whitebox.setInternalState(fragment, "callback", callback)
Whitebox.setInternalState(fragment, "presenter", presenter)
Whitebox.setInternalState(fragment, "etSearch", etSearch)
Whitebox.setInternalState(fragment, "rvCategories", rvCategories)
Expand Down Expand Up @@ -365,4 +365,15 @@ class UploadCategoriesFragmentUnitTests {
method.invoke(fragment)
}

}
@Test
@Throws(Exception::class)
fun `Test init when callback is null`() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = UploadCategoriesFragment::class.java.getDeclaredMethod(
"init"
)
method.isAccessible = true
method.invoke(fragment)
}

}