Skip to content

Commit 31c479b

Browse files
* Removed custom save state implementatio of CheckBoxTriState * Save/Restore CheckBox state in NearbyParentFragment
1 parent 93d6c52 commit 31c479b

File tree

4 files changed

+10
-68
lines changed

4 files changed

+10
-68
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/CheckBoxTriStates.java

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.free.nrw.commons.nearby;
22

33
import android.content.Context;
4+
import android.os.Bundle;
45
import android.os.Parcel;
56
import android.os.Parcelable;
67
import android.util.AttributeSet;
@@ -64,12 +65,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
6465
*/
6566
private OnCheckedChangeListener clientListener;
6667

67-
/**
68-
* This flag is needed to avoid accidentally changing the current {@link #state} when
69-
* {@link #onRestoreInstanceState(Parcelable)} calls {@link #setChecked(boolean)}
70-
* evoking our {@link #privateListener} and therefore changing the real state.
71-
*/
72-
private boolean restoring;
7368

7469
public CheckBoxTriStates(Context context) {
7570
super(context);
@@ -91,7 +86,7 @@ public int getState() {
9186
}
9287

9388
public void setState(int state) {
94-
if(!this.restoring && this.state != state) {
89+
if(this.state != state) {
9590
this.state = state;
9691

9792
if(this.clientListener != null) {
@@ -118,27 +113,6 @@ public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listene
118113
super.setOnCheckedChangeListener(privateListener);
119114
}
120115

121-
@Override
122-
public Parcelable onSaveInstanceState() {
123-
Parcelable superState = super.onSaveInstanceState();
124-
125-
SavedState ss = new SavedState(superState);
126-
127-
ss.state = state;
128-
129-
return ss;
130-
}
131-
132-
@Override
133-
public void onRestoreInstanceState(Parcelable state) {
134-
this.restoring = true; // indicates that the ui is restoring its state
135-
SavedState ss = (SavedState) state;
136-
super.onRestoreInstanceState(ss.getSuperState());
137-
setState(ss.state);
138-
requestLayout();
139-
this.restoring = false;
140-
}
141-
142116
private void init() {
143117
state = UNKNOWN;
144118
updateBtn();
@@ -164,44 +138,4 @@ private void updateBtn() {
164138
setButtonDrawable(btnDrawable);
165139

166140
}
167-
168-
static class SavedState extends BaseSavedState {
169-
int state;
170-
171-
SavedState(Parcelable superState) {
172-
super(superState);
173-
}
174-
175-
private SavedState(Parcel in) {
176-
super(in);
177-
state = in.readInt();
178-
}
179-
180-
@Override
181-
public void writeToParcel(Parcel out, int flags) {
182-
super.writeToParcel(out, flags);
183-
out.writeValue(state);
184-
}
185-
186-
@Override
187-
public String toString() {
188-
return "CheckboxTriState.SavedState{"
189-
+ Integer.toHexString(System.identityHashCode(this))
190-
+ " state=" + state + "}";
191-
}
192-
193-
@SuppressWarnings("hiding")
194-
public static final Parcelable.Creator<SavedState> CREATOR =
195-
new Parcelable.Creator<SavedState>() {
196-
@Override
197-
public SavedState createFromParcel(Parcel in) {
198-
return new SavedState(in);
199-
}
200-
201-
@Override
202-
public SavedState[] newArray(int size) {
203-
return new SavedState[size];
204-
}
205-
};
206-
}
207141
}

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyListFragment.java

Whitespace-only changes.

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyMapFragment.java

Whitespace-only changes.

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
120120
implements NearbyParentFragmentContract.View,
121121
WikidataEditListener.WikidataP18EditListener, LocationUpdateListener {
122122

123+
private static final String CHECKBOX_STATE = "checkbox_state";
123124
@BindView(R.id.bottom_sheet) RelativeLayout rlBottomSheet;
124125
@BindView(R.id.bottom_sheet_details) View bottomSheetDetails;
125126
@BindView(R.id.transparentView) View transparentView;
@@ -220,6 +221,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
220221
@Override
221222
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
222223
super.onViewCreated(view, savedInstanceState);
224+
//Restore checkbox's state
225+
if (null != savedInstanceState) {
226+
int checkBoxSavedState = savedInstanceState.getInt(CHECKBOX_STATE,
227+
CheckBoxTriStates.UNKNOWN);
228+
checkBoxTriStates.setState(checkBoxSavedState);
229+
}
223230
isDarkTheme = systemThemeUtils.isDeviceInNightMode();
224231
cameraMoveListener= () -> presenter.onCameraMove(mapBox.getCameraPosition().target);
225232
addCheckBoxCallback();
@@ -363,6 +370,7 @@ public void onStop() {
363370

364371
@Override
365372
public void onSaveInstanceState(Bundle outState) {
373+
outState.putInt(CHECKBOX_STATE,checkBoxTriStates.getState());
366374
super.onSaveInstanceState(outState);
367375
mapView.onSaveInstanceState(outState);
368376
}

0 commit comments

Comments
 (0)