1111import android .widget .ProgressBar ;
1212import android .widget .TextView ;
1313
14- import java . util . List ;
14+ import androidx . annotation . NonNull ;
1515
1616import butterknife .BindView ;
1717import 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