Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access modified #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ private void updateFilterContactTypes(List<FilterContactTypeUi> filterTypes) {
}

private void updateState(FilterContactUiState state) {
binding.applyButton.setEnabled(state.isApplyEnable);
binding.applyButton.setEnabled(state.getIsApplyEnable());

if (!state.newSelectedContactTypes.isEmpty()) {
getParentFragmentManager().setFragmentResult(REQUEST_KEY, createBundle(state.newSelectedContactTypes));
if (!state.getNewSelectedContactTypes().isEmpty()) {
getParentFragmentManager().setFragmentResult(REQUEST_KEY, createBundle(state.getNewSelectedContactTypes()));
dismiss();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import ru.yandex.practicum.contacts.utils.model.ContactTypeUtils;
import ru.yandex.practicum.contacts.utils.model.FilterContactTypeUtils;

public class FilterContactTypeViewModel extends BaseBottomSheetViewModel {
class FilterContactTypeViewModel extends BaseBottomSheetViewModel {

private final FilterContactUiState uiState = new FilterContactUiState();
private final MutableLiveData<List<FilterContactTypeUi>> filterContactTypesLiveDate = new MutableLiveData<>();
Expand All @@ -41,7 +41,7 @@ public void onFilterTypeItemClick(FilterContactTypeUi filterContactType) {

@Override
public void onApplyClick() {
uiState.newSelectedContactTypes = selectedFilterContactTypes;
uiState.setNewSelectedContactTypes(selectedFilterContactTypes);
updateUiState();
}

Expand Down Expand Up @@ -75,7 +75,7 @@ private void updateFilterContactTypes() {
}

private void updateUiState() {
uiState.isApplyEnable = !defaultFilterContactTypes.equals(selectedFilterContactTypes) && !selectedFilterContactTypes.isEmpty();
uiState.setApplyEnable(!defaultFilterContactTypes.equals(selectedFilterContactTypes) && !selectedFilterContactTypes.isEmpty());
uiStateLiveDate.setValue(uiState);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,22 @@

import ru.yandex.practicum.contacts.model.ContactType;

public class FilterContactUiState {
public boolean isApplyEnable = false;
public Set<ContactType> newSelectedContactTypes = Collections.emptySet();
class FilterContactUiState {
private boolean isApplyEnable = false;
private Set<ContactType> newSelectedContactTypes = Collections.emptySet();
public boolean getIsApplyEnable(){
return isApplyEnable;
}

public Set<ContactType> getNewSelectedContactTypes() {
return newSelectedContactTypes;
}

public void setApplyEnable(boolean applyEnable) {
isApplyEnable = applyEnable;
}

public void setNewSelectedContactTypes(Set<ContactType> newSelectedContactTypes) {
this.newSelectedContactTypes = newSelectedContactTypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,27 @@ private void updateContacts(List<ContactUi> contacts) {
}

private void updateUiState(MainUiState uiState) {
final Boolean finishActivity = uiState.actions.finishActivity.data;
final Boolean finishActivity = uiState.getActions().finishActivity.data;
if (finishActivity != null && finishActivity) {
finish();
return;
}
binding.searchLayout.getRoot().setVisibility(uiState.searchVisibility ? View.VISIBLE : View.GONE);
binding.searchLayout.resetButton.setVisibility(uiState.resetSearchButtonVisibility ? View.VISIBLE : View.GONE);
if (uiState.actions.showSortTypeDialog.data != null) {
showSortDialog(uiState.actions.showSortTypeDialog.data);
binding.searchLayout.getRoot().setVisibility(uiState.isSearchVisibility() ? View.VISIBLE : View.GONE);
binding.searchLayout.resetButton.setVisibility(uiState.isResetSearchButtonVisibility() ? View.VISIBLE : View.GONE);
if (uiState.getActions().showSortTypeDialog.data != null) {
showSortDialog(uiState.getActions().showSortTypeDialog.data);
}
final Set<ContactType> filterContactTypes = uiState.actions.showFilterContactTypeDialog.data;
final Set<ContactType> filterContactTypes = uiState.getActions().showFilterContactTypeDialog.data;
if (filterContactTypes != null && filterContactTypes.size() > 0) {
showFilterContactTypeDialog(filterContactTypes);
}
updateBadges(uiState);
}

private void updateBadges(MainUiState uiState) {
updateBadge(uiState.menuBadges.sort, R.id.menu_sort);
updateBadge(uiState.menuBadges.filter, R.id.menu_filter);
updateBadge(uiState.menuBadges.search, R.id.menu_search);
updateBadge(uiState.getMenuBadges().sort, R.id.menu_sort);
updateBadge(uiState.getMenuBadges().filter, R.id.menu_filter);
updateBadge(uiState.getMenuBadges().search, R.id.menu_search);
}

private void updateBadge(MainUiState.MenuBadge badge, @IdRes int menuItemId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,43 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class MainUiState {
class MainUiState {

private boolean searchVisibility = false;
private boolean resetSearchButtonVisibility = false;
private Actions actions = new Actions();
private MenuBadges menuBadges = new MenuBadges();
public Actions getActions() {
return actions;
}

public boolean isResetSearchButtonVisibility() {
return resetSearchButtonVisibility;
}

public boolean searchVisibility = false;
public boolean resetSearchButtonVisibility = false;
public MenuBadges getMenuBadges() {
return menuBadges;
}

public Actions actions = new Actions();
public MenuBadges menuBadges = new MenuBadges();
public boolean isSearchVisibility() {
return searchVisibility;
}

public void setActions(Actions actions) {
this.actions = actions;
}

public void setMenuBadges(MenuBadges menuBadges) {
this.menuBadges = menuBadges;
}

public void setResetSearchButtonVisibility(boolean resetSearchButtonVisibility) {
this.resetSearchButtonVisibility = resetSearchButtonVisibility;
}

public void setSearchVisibility(boolean searchVisibility) {
this.searchVisibility = searchVisibility;
}

@NonNull
public MainUiState copy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

public class MainViewModel extends AndroidViewModel {
class MainViewModel extends AndroidViewModel {

private final ContactSourceRepository contactSourceRepository;
private final ContactRepository contactRepository;
Expand Down Expand Up @@ -77,13 +77,13 @@ public void search() {
public void onMenuClick(MenuClick click) {
switch (click) {
case SORT:
uiState.actions.showSortTypeDialog.data = state.getSortType();
uiState.getActions().showSortTypeDialog.data = state.getSortType();
break;
case FILTER:
uiState.actions.showFilterContactTypeDialog.data = new HashSet<>(state.getContactTypes());
uiState.getActions().showFilterContactTypeDialog.data = new HashSet<>(state.getContactTypes());
break;
case SEARCH:
uiState.searchVisibility = !uiState.searchVisibility;
uiState.setSearchVisibility(!uiState.isSearchVisibility());
break;
}
updateUiState();
Expand All @@ -102,31 +102,31 @@ public void updateFilterContactTypes(Set<ContactType> filterContactTypes) {
}

public void onBackPressed() {
if (uiState.searchVisibility) {
uiState.searchVisibility = false;
if (uiState.isSearchVisibility()) {
uiState.setSearchVisibility(false);
} else {
uiState.actions.finishActivity.data = true;
uiState.getActions().finishActivity.data = true;
}
updateUiState();
}

public void updateSearchText(String query) {
state.setQuery(query);
uiState.resetSearchButtonVisibility = state.getQuery().length() != 0;
uiState.setResetSearchButtonVisibility(state.getQuery().length() != 0);
updateUiState();
}

private void updateBadges() {
if (!state.getSortType().equals(state.getDefaultSortType())) {
uiState.menuBadges.sort = new MainUiState.MenuBadge(0);
uiState.getMenuBadges().sort = new MainUiState.MenuBadge(0);
} else {
uiState.menuBadges.sort = null;
uiState.getMenuBadges().sort = null;
}

if (!state.getContactTypes().equals(state.getDefaultContactTypes())) {
uiState.menuBadges.filter = new MainUiState.MenuBadge(state.getContactTypes().size());
uiState.getMenuBadges().filter = new MainUiState.MenuBadge(state.getContactTypes().size());
} else {
uiState.menuBadges.filter = null;
uiState.getMenuBadges().filter = null;
}

updateUiState();
Expand Down Expand Up @@ -207,6 +207,6 @@ private Comparator<MergedContact> createReversedComparator(Function<MergedContac

private void updateUiState() {
uiStateLiveDate.setValue(uiState.copy());
uiState.actions.clear();
uiState.getActions().clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ private void updateSortTypes(List<SortTypeUI> sortTypes) {
}

private void updateState(SortUiState state) {
binding.applyButton.setEnabled(state.isApplyEnable);
binding.applyButton.setEnabled(state.getIsApplyEnable());

if (state.newSelectedSortType != null) {
getParentFragmentManager().setFragmentResult(REQUEST_KEY, createBundle(state.newSelectedSortType));
if (state.getNewSelectedSortType() != null) {
getParentFragmentManager().setFragmentResult(REQUEST_KEY, createBundle(state.getNewSelectedSortType()));
dismiss();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package ru.yandex.practicum.contacts.presentation.sort;

// класс UiState должен иметь package-private доступ
public class SortUiState {
class SortUiState {

// сделайте поля isApplyEnable и newSelectedSortType приватными
public boolean isApplyEnable = false;
public String newSelectedSortType = null;
private boolean isApplyEnable = false;
private String newSelectedSortType = null;
public boolean getIsApplyEnable(){
return isApplyEnable;
}
public String getNewSelectedSortType(){
return newSelectedSortType;
}

public void setApplyEnable(boolean applyEnable) {
this.isApplyEnable = applyEnable;
}

public void setNewSelectedSortType(String newSelectedSortType) {
this.newSelectedSortType = newSelectedSortType;
}
// реализуйте get и set методы для обоих полей
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import androidx.lifecycle.MutableLiveData;

public class SortViewModel extends BaseBottomSheetViewModel {
class SortViewModel extends BaseBottomSheetViewModel {

private final SortUiState uiState = new SortUiState();
private final MutableLiveData<List<SortTypeUI>> sortTypesLiveDate = new MutableLiveData<>();
Expand All @@ -34,7 +34,7 @@ public void onSortTypeItemClick(SortTypeUI sortType) {

@Override
public void onApplyClick() {
uiState.newSelectedSortType = selectedSortType;
uiState.setNewSelectedSortType(selectedSortType);
updateUiState();
}

Expand Down Expand Up @@ -62,7 +62,7 @@ private void updateSortTypes() {
}

private void updateUiState() {
uiState.isApplyEnable = !defaultSortType.equals(selectedSortType);
uiState.setApplyEnable(!defaultSortType.equals(selectedSortType));
uiStateLiveDate.setValue(uiState);
}
}