Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Saving Toggle State and Restoring it
Browse files Browse the repository at this point in the history
  • Loading branch information
iadeelzafar committed Mar 20, 2019
1 parent 1ce0ab5 commit 994e521
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand All @@ -31,6 +32,8 @@
import android.widget.Button;
import butterknife.BindView;
import org.odk.share.R;
import org.odk.share.adapters.FormsAdapter;
import org.odk.share.adapters.InstanceAdapter;
import org.odk.share.adapters.SortDialogAdapter;
import org.odk.share.utilities.ArrayUtils;

Expand All @@ -45,17 +48,27 @@ abstract class AppListFragment extends InjectableFragment {
private Integer selectedSortingOrder;
private BottomSheetDialog bottomSheetDialog;
private String filterText;
public FormsAdapter formAdapter;
public InstanceAdapter instanceAdapter;

private static final String SELECTED_INSTANCES_KEY = "ROTATION_SELECTED_INSTANCES";
private static final String TOGGLE_BUTTON_STATUS_KEY = "TOGGLE_BUTTON_STATUS";
private static final String TOGGLE_BUTTON_TEXT_KEY = "TOGGLE_BUTTON_TEXT";

@BindView(R.id.send_button)
Button sendButton;
@BindView(R.id.toggle_button)
Button toggleButton;

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLongArray(SELECTED_INSTANCES_KEY, ArrayUtils.toPrimitive(
selectedInstances.toArray(new Long[selectedInstances.size()])));
outState.putBoolean(TOGGLE_BUTTON_STATUS_KEY, toggleButton.isEnabled());
// Log.v("DANG", "Saving Boolean : " + toggleButton.isEnabled());
outState.putString(TOGGLE_BUTTON_TEXT_KEY, toggleButton.getText().toString());
// Log.v("DANG", " Saving state : " + toggleButton.getText().toString());

}

Expand Down Expand Up @@ -138,9 +151,14 @@ public void restoreState(Bundle savedInstanceState) {
selectedInstances.add(previousSelectedInstance);
}
sendButton.setEnabled(selectedInstances.size() > 0);
toggleButton.setEnabled(savedInstanceState.getBoolean(TOGGLE_BUTTON_STATUS_KEY));
// Log.v("DANG", "Saving Boolean : " + savedInstanceState.getBoolean(TOGGLE_BUTTON_STATUS_KEY));
toggleButton.setText(savedInstanceState.getString(TOGGLE_BUTTON_TEXT_KEY));
// Log.v("DANG", " Restoring state : " + savedInstanceState.getString(TOGGLE_BUTTON_TEXT_KEY));
}
}



private void setupBottomSheet() {
bottomSheetDialog = new BottomSheetDialog(getActivity());
View sheetView = getActivity().getLayoutInflater().inflate(R.layout.bottom_sheet, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public class BlankFormsFragment extends FormListFragment implements LoaderManage
@Inject
TransferDao transferDao;

private FormsAdapter formAdapter;

public BlankFormsFragment() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public class FilledFormsFragment extends InstanceListFragment implements LoaderM
@Inject
InstancesDao instancesDao;

private InstanceAdapter instanceAdapter;

public FilledFormsFragment() {
}

Expand Down

0 comments on commit 994e521

Please sign in to comment.