Last active
September 12, 2018 11:32
-
-
Save caneryilmaz/596fa04978fdc8f2e7b091e2e7101c45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void bindAdapter() { | |
final SectorFilterAdapter adapter = new SectorFilterAdapter(this, sectorList); | |
listViewPositions.setAdapter(adapter); | |
edtSearch.addTextChangedListener(new TextWatcher() { | |
@Override | |
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
} | |
@Override | |
public void onTextChanged(CharSequence s, int start, int before, int count) { | |
adapter.getFilter().filter(s.toString()); | |
} | |
@Override | |
public void afterTextChanged(Editable s) { | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PositionListActivity extends BaseActivity implements EditText.OnEditorActionListener { | |
@BindView(R.id.toolbar_text) | |
SecretTextView toolbarText; | |
@BindView(R.id.listview_positions) | |
ListView listViewPositions; | |
@BindView(R.id.edt_search) | |
SecretEditText edtSearch; | |
private List<Pozisyonlar> positionList = new ArrayList<>(); | |
private List<Pozisyonlar> selectedPositionList = new ArrayList<>(); | |
@Override | |
protected int getLayoutResId() { | |
return R.layout.activity_position_list; | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
toolbarText.setText(getString(R.string.positions).replace(":", "")); | |
edtSearch.setOnEditorActionListener(this); | |
positionList = Hawk.get(POSITION_OBJECT_LIST); | |
ProgressDialogUtils.getInstance().dismiss(); | |
bindAdapter(); | |
} | |
@OnClick(R.id.close_button) | |
public void OnCloseClick() { | |
if (getSelectedPos().size() > 5) { | |
SnackbarUtils.getInstance().showError(getCurrentFocus().getRootView(), getString(R.string.max_selection)); | |
} else { | |
hideKeyboard(); | |
finish(); | |
} | |
} | |
@Override | |
public void onBackPressed() { | |
if (getSelectedPos().size() > 5) { | |
SnackbarUtils.getInstance().showError(getCurrentFocus().getRootView(), getString(R.string.max_selection)); | |
} else { | |
hideKeyboard(); | |
finish(); | |
} | |
} | |
@Subscribe | |
public void OnCheckEvent(CheckedEvent event) { | |
if (event.isChecked()) { | |
selectedPositionList.add(event.getPozisyon()); | |
Hawk.put(POSITION_SELECT_LIST, selectedPositionList); | |
} else { | |
selectedPositionList.remove(event.getPozisyon()); | |
Hawk.put(POSITION_SELECT_LIST, selectedPositionList); | |
} | |
} | |
@Override | |
public void onDestroy() { | |
super.onDestroy(); | |
if (getSelectedPos().size() > 5) { | |
SnackbarUtils.getInstance().showError(getCurrentFocus().getRootView(), getString(R.string.max_selection)); | |
} else { | |
EventBus.getDefault().post(new CheckedEvent()); | |
} | |
} | |
private ArrayList<Pozisyonlar> getSelectedPos() { | |
ArrayList<Pozisyonlar> positionList = new ArrayList<>(); | |
if (Hawk.contains(POSITION_SELECT_LIST)) { | |
positionList.addAll(Hawk.get(POSITION_SELECT_LIST, positionList)); | |
} | |
return positionList; | |
} | |
private void bindAdapter() { | |
final PositionFilterAdapter adapter = new PositionFilterAdapter(this, positionList); | |
listViewPositions.setAdapter(adapter); | |
edtSearch.addTextChangedListener(new TextWatcher() { | |
@Override | |
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
} | |
@Override | |
public void onTextChanged(CharSequence s, int start, int before, int count) { | |
adapter.getFilter().filter(s.toString()); | |
} | |
@Override | |
public void afterTextChanged(Editable s) { | |
} | |
}); | |
} | |
@Override | |
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { | |
if (actionId == EditorInfo.IME_ACTION_DONE) { | |
hideKeyboard(); | |
} | |
return false; | |
} | |
@Override | |
public void onStart() { | |
super.onStart(); | |
EventBus.getDefault().register(this); | |
} | |
@Override | |
public void onStop() { | |
super.onStop(); | |
EventBus.getDefault().unregister(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment