Skip to content

Commit 9b15a32

Browse files
DeepaMalaniashishkumar468
authored andcommitted
Fix commons-app#3203 App Crash when rotating the Peer Review Screen (commons-app#3215)
* Fixing 3203 App crash when rotating the screen * Add java comments for issue commons-app#3203 * Add if-else curly braces for issue commons-app#3203
1 parent 891d9ec commit 9b15a32

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.java

+32-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import android.widget.ProgressBar;
1212
import android.widget.TextView;
1313

14-
import java.util.List;
14+
import androidx.annotation.NonNull;
1515

1616
import butterknife.BindView;
1717
import butterknife.ButterKnife;
@@ -40,6 +40,12 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
4040
@BindView(R.id.button_no)
4141
Button noButton;
4242

43+
// Constant variable used to store user's key name for onSaveInstanceState method
44+
private final String SAVED_USER = "saved_user";
45+
46+
//Variable that stores the value of user
47+
private String user;
48+
4349
public void update(int position) {
4450
this.position = position;
4551
}
@@ -68,7 +74,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
6874
position = getArguments().getInt("position");
6975
View layoutView = inflater.inflate(R.layout.fragment_review_image, container,
7076
false);
71-
ButterKnife.bind(this,layoutView);
77+
ButterKnife.bind(this, layoutView);
7278

7379
String question, explanation, yesButtonText, noButtonText;
7480
switch (position) {
@@ -106,7 +112,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
106112
case THANKS:
107113
enableButtons();
108114
question = getString(R.string.review_thanks);
109-
explanation = getString(R.string.review_thanks_explanation, getReviewActivity().reviewController.firstRevision.getUser());
115+
116+
//Get existing user name if it is already saved using savedInstanceState else get from reviewController
117+
if (savedInstanceState == null) {
118+
user = getReviewActivity().reviewController.firstRevision.getUser();
119+
} else {
120+
user = savedInstanceState.getString(SAVED_USER);
121+
}
122+
123+
explanation = getString(R.string.review_thanks_explanation, user);
124+
110125
yesButtonText = getString(R.string.review_thanks_yes_button_text);
111126
noButtonText = getString(R.string.review_thanks_no_button_text);
112127
yesButton.setTextColor(Color.parseColor("#228b22"));
@@ -131,6 +146,20 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
131146
return layoutView;
132147
}
133148

149+
150+
/**
151+
* This method will be called when configuration changes happen
152+
*
153+
* @param outState
154+
*/
155+
@Override
156+
public void onSaveInstanceState(@NonNull Bundle outState) {
157+
super.onSaveInstanceState(outState);
158+
159+
//Save user name when configuration changes happen
160+
outState.putString(SAVED_USER, user);
161+
}
162+
134163
private ReviewController.ReviewCallback getReviewCallback() {
135164
return new ReviewController
136165
.ReviewCallback() {

0 commit comments

Comments
 (0)