-
Notifications
You must be signed in to change notification settings - Fork 21
유틸 추가 및 화면 목록 정렬 기능 추가 #19
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.example.yeseul.movieapp.data.model; | ||
|
|
||
| import android.os.Build; | ||
|
|
||
| import com.example.yeseul.movieapp.pojo.Movie; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class MovieSortByDictionary implements MovieSortStrategy { | ||
| @Override | ||
| public List<Movie> sort(List<Movie> list) { | ||
| if(Build.VERSION_CODES.N <= Build.VERSION.SDK_INT) { | ||
| list = list.stream().sorted(Comparator.comparing(Movie::getTitle)).collect(Collectors.toList()); | ||
| } else { | ||
| Collections.sort(list, (o1, o2) -> (o1.getTitle().compareTo(o2.getTitle()))); | ||
| } | ||
| return list; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.example.yeseul.movieapp.data.model; | ||
|
|
||
| import android.os.Build; | ||
|
|
||
| import com.example.yeseul.movieapp.pojo.Movie; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class MovieSortByHighestRating implements MovieSortStrategy { | ||
| @Override | ||
| public List<Movie> sort(List<Movie> list) { | ||
| if(Build.VERSION_CODES.N <= Build.VERSION.SDK_INT) { | ||
| list = list.stream(). | ||
| sorted((o1, o2) -> Double.compare(Double.parseDouble(o2.getUserRating()), Double.parseDouble(o1.getUserRating()))). | ||
| collect(Collectors.toList()); | ||
| } else { | ||
| Collections.sort(list, (o1, o2) -> (Double.compare(Double.parseDouble(o2.getUserRating()), Double.parseDouble(o1.getUserRating())))); | ||
| } | ||
| return list; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.example.yeseul.movieapp.data.model; | ||
|
|
||
| import android.os.Build; | ||
|
|
||
| import com.example.yeseul.movieapp.pojo.Movie; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class MovieSortByLatestPubDate implements MovieSortStrategy { | ||
| @Override | ||
| public List<Movie> sort(List<Movie> list) { | ||
| if(Build.VERSION_CODES.N <= Build.VERSION.SDK_INT) { | ||
| list = list.stream().sorted(Comparator.comparing(Movie::getPubDate).reversed()).collect(Collectors.toList()); | ||
| } else { | ||
| Collections.sort(list, (o1, o2) -> (o2.getPubDate().compareTo(o1.getPubDate()))); | ||
| } | ||
| return list; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.example.yeseul.movieapp.data.model; | ||
|
|
||
| import android.os.Build; | ||
|
|
||
| import com.example.yeseul.movieapp.pojo.Movie; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class MovieSortByLowestRating implements MovieSortStrategy { | ||
| @Override | ||
| public List<Movie> sort(List<Movie> list) { | ||
| if(Build.VERSION_CODES.N <= Build.VERSION.SDK_INT) { | ||
| list = list.stream(). | ||
| sorted((o1, o2) -> Double.compare(Double.parseDouble(o1.getUserRating()), Double.parseDouble(o2.getUserRating()))). | ||
| collect(Collectors.toList()); | ||
| } else { | ||
| Collections.sort(list, (o1, o2) -> (Double.compare(Double.parseDouble(o1.getUserRating()), Double.parseDouble(o2.getUserRating())))); | ||
| } | ||
| return list; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.example.yeseul.movieapp.data.model; | ||
|
|
||
| import android.annotation.TargetApi; | ||
| import android.os.Build; | ||
|
|
||
| import com.example.yeseul.movieapp.pojo.Movie; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class MovieSortByOldPubDate implements MovieSortStrategy { | ||
| @Override | ||
| public List<Movie> sort(List<Movie> list) { | ||
| if(Build.VERSION_CODES.N <= Build.VERSION.SDK_INT) { | ||
| list = list.stream().sorted(Comparator.comparing(Movie::getPubDate)).collect(Collectors.toList()); | ||
| } else { | ||
| Collections.sort(list, (o1, o2) -> (o2.getPubDate().compareTo(o1.getPubDate()))); | ||
| } | ||
| return list; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.example.yeseul.movieapp.data.model; | ||
|
|
||
| import android.annotation.TargetApi; | ||
| import android.os.Build; | ||
|
|
||
| import com.example.yeseul.movieapp.pojo.Movie; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface MovieSortStrategy { | ||
|
|
||
| public static final int DICTIONARY_ORDER = 0; | ||
| public static final int LATEST_ORDER = 1; | ||
| public static final int OLDEST_ORDER = 2; | ||
| public static final int HIGHEST_RATING_ORDER = 3; | ||
| public static final int LOWEST_RATING_ORDER = 4; | ||
|
|
||
| List<Movie> sort(List<Movie> list); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.example.yeseul.movieapp.data.model; | ||
|
|
||
| import static com.example.yeseul.movieapp.data.model.MovieSortStrategy.*; | ||
|
|
||
| public class MovieStrategyFactory { | ||
| public static MovieSortStrategy create(int idx) { | ||
|
|
||
| switch (idx) { | ||
| case DICTIONARY_ORDER: | ||
| return new MovieSortByDictionary(); | ||
| case LATEST_ORDER: | ||
| return new MovieSortByLatestPubDate(); | ||
| case OLDEST_ORDER: | ||
| return new MovieSortByOldPubDate(); | ||
| case HIGHEST_RATING_ORDER: | ||
| return new MovieSortByHighestRating(); | ||
| case LOWEST_RATING_ORDER: | ||
| return new MovieSortByLowestRating(); | ||
| } | ||
| return null; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.example.yeseul.movieapp.utils; | ||
|
|
||
| import android.content.Context; | ||
| import android.net.ConnectivityManager; | ||
| import android.net.NetworkInfo; | ||
|
|
||
| public class NetworkStatusCheckUtil { | ||
|
|
||
| public static final String NETWORK_STATUS_CHANGE_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; | ||
|
|
||
| public static boolean checkCurrentNetworkStatus(final Context context) { | ||
| final ConnectivityManager connectivityManager = | ||
| (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); | ||
|
|
||
| final NetworkInfo currentNetworkStatus = connectivityManager.getActiveNetworkInfo(); | ||
|
|
||
| // 연결 상태 반환 | ||
| return currentNetworkStatus != null && currentNetworkStatus.isConnected(); | ||
| } | ||
| } | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Network 상태를 확인하기 위한 Util 입니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 변수들을 final로 선언하신 이유를 알 수 있을까요??
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저같은 경우엔 잘못된 입력이나 변경을 막으려고 final 로 선언하여 사용하고 있습니다. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| package com.example.yeseul.movieapp.view; | ||
|
|
||
| /* | ||
| * 모든 Presenter 가 공통으로 가져야하는 함수들 선언 */ | ||
| public interface BasePresenter { | ||
|
|
||
| void onViewCreated(); | ||
| void onViewAttached(); | ||
|
|
||
| void onViewDetached(); | ||
|
|
||
| void loadItems(boolean isRefresh); | ||
| } |
There was a problem hiding this comment.
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 상수를 선택한 이유가 있을까요?
There was a problem hiding this comment.
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 는 한번도 사용해보지 못했는데 이번에 이용해서 수정하도록 하겠습니다 !