Skip to content

유틸 추가 및 화면 목록 정렬 기능 추가#19

Open
KaquiIOS wants to merge 2 commits into
boostcampth:masterfrom
KaquiIOS:#1_develop
Open

유틸 추가 및 화면 목록 정렬 기능 추가#19
KaquiIOS wants to merge 2 commits into
boostcampth:masterfrom
KaquiIOS:#1_develop

Conversation

@KaquiIOS

@KaquiIOS KaquiIOS commented Jan 19, 2019

Copy link
Copy Markdown
  1. 주석달기
  • 기본적인 코드 이해를 위해 주석 처리 다수
  1. NetworkUtil 을 생성 및 BroadcastReceiver 를 이용한 Network 상태 Observe
  • BroadcastReceiver 를 이용하여 네트워크 상태를 실시간으로 확인
  • View 에서 발생하는 이벤트를 Presenter 에 위임하기 Acitvity 에서 receiver 등록 및 Presenter 에 네트워크 상태시 이벤트 처리 위임 (setNetworkStatus 메소드 추가)
  1. Strategy Pattern 을 이용한 현재 목록 정렬
  • 현재 목록에 있는 Item 들의 정렬 기능을 추가
  • OS Version 에 따라 다른 정렬 로직 수행
  • SortInterface Factory 를 이용하여 의존도를 낮추려고 노력..
    ( 24 버전 이상부터는 Stream API 를 이용, 이외에는 Collection.Sort 사용)
  1. BasePresenter 에 Detached Method 추가
  • 현재 뷰가 Focus 를 잃었을 때 수행해야하는 처리를 위해 onViewDetached() Method 추가
  1. Deprecated 된 Listener 변경
    ezgif com-video-to-gif

boostcampth#2 NetworkUtil 을 생성 및 BroadcastReceiver 를 이용한 Network 상태 Observe
boostcampth#3 Strategy Pattern 을 이용한 현재 목록 정렬
   ( OS Version 에 따라 다른 로직 수행 )
boostcampth#4 BasePresenter 에 Detached Method 추가
// 연결 상태 반환
return currentNetworkStatus != null && currentNetworkStatus.isConnected();
}
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Network 상태를 확인하기 위한 Util 입니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수들을 final로 선언하신 이유를 알 수 있을까요??

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저같은 경우엔 잘못된 입력이나 변경을 막으려고 final 로 선언하여 사용하고 있습니다.

}
}
};

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broadcast Receiver 를 이용해 실시간으로 인터넷 연결 상태를 확인합니다.
변경이 된 경우 Util 을 통해 연결 상태를 가져오고 이를 Presenter 의 멤버 변수에 대입합니다

binding.recyclerMovie.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));

// 최하단 스크롤 감지
binding.recyclerMovie.setOnScrollListener(new RecyclerView.OnScrollListener(){

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecated 된 Listener 를 변경하였습니다.


private MovieListAdapter adapter;

private BroadcastReceiver mNetworkStatusReceiver = new BroadcastReceiver() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모든 액티비티에서 Broadcast Receiver의 기능이 필요하다면 정적 리시버 사용은 어떠신가요??

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

화면이 현재는 하나밖에 없어서 동적 리시버를 이용하였습니다.
추가로 정적 리시버의 경우에 등록/삭제를 직접하지 못하고 OS 버전이 올라가면서 많은 기능들이 제한되었다고 합니당.. 확장성을 고려해서 Receiver 를 상속받는 class 작성을 하도록 하겠습니다 감사합니다 ^_^

public static final int HIGHEST_RATING_ORDER = 3;
public static final int LOWEST_RATING_ORDER = 4;

List<Movie> sort(List<Movie> list);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interface에 상수를 정의하는 방법은 Anti-Pattern이라고 불리는 방법으로 알고 있습니다.
public static final int example = 1, enum , IntDef 와 같은 상수 정의 방법이 아닌
Interface 상수를 선택한 이유가 있을까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 StrategyInterface 에 있는 상수는 Factory 에서만 사용하고 있어 상수가 다른 Class 의 네임스페이스를 오염시키지 않는다고 생각되어 사용했습니다. 다시 생각해보니 Factory 에 넣어두는게 더 적절했다고 생각됩니다. 좋은 지적 감사합니다 ! 그리고 IntDef 는 한번도 사용해보지 못했는데 이번에 이용해서 수정하도록 하겠습니다 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants