11
11
import android .widget .ProgressBar ;
12
12
import android .widget .TextView ;
13
13
14
- import java . util . List ;
14
+ import androidx . annotation . NonNull ;
15
15
16
16
import butterknife .BindView ;
17
17
import butterknife .ButterKnife ;
@@ -40,6 +40,12 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
40
40
@ BindView (R .id .button_no )
41
41
Button noButton ;
42
42
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
+
43
49
public void update (int position ) {
44
50
this .position = position ;
45
51
}
@@ -68,7 +74,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
68
74
position = getArguments ().getInt ("position" );
69
75
View layoutView = inflater .inflate (R .layout .fragment_review_image , container ,
70
76
false );
71
- ButterKnife .bind (this ,layoutView );
77
+ ButterKnife .bind (this , layoutView );
72
78
73
79
String question , explanation , yesButtonText , noButtonText ;
74
80
switch (position ) {
@@ -106,7 +112,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
106
112
case THANKS :
107
113
enableButtons ();
108
114
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
+
110
125
yesButtonText = getString (R .string .review_thanks_yes_button_text );
111
126
noButtonText = getString (R .string .review_thanks_no_button_text );
112
127
yesButton .setTextColor (Color .parseColor ("#228b22" ));
@@ -131,6 +146,20 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
131
146
return layoutView ;
132
147
}
133
148
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
+
134
163
private ReviewController .ReviewCallback getReviewCallback () {
135
164
return new ReviewController
136
165
.ReviewCallback () {
0 commit comments