Skip to content
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 @@ -9,13 +9,24 @@ public class MovieMapper {
public static final String QUERY_STRING_PAGE_UNIT = "display";
public static final String QUERY_STRING_START = "start";

public static Map<String, String> toRequest(String searchKey, int pageUnit, int start){
public static final String QUERY_STRING_GENRE = "genre";
public static final String QUERY_STRING_COUNTRY = "country";

public static Map<String, String> toRequest(String searchKey, int pageUnit, int start, String genre, String country){

Map<String, String> queryMap = new HashMap<>();
queryMap.put(QUERY_STRING_SEARCH_KEY, searchKey);
queryMap.put(QUERY_STRING_PAGE_UNIT, ""+pageUnit);
queryMap.put(QUERY_STRING_START, ""+start);

if( genre != null && !genre.equals("0") && !genre.equals("")){
queryMap.put(QUERY_STRING_GENRE, genre);
}

if( country != null && !country.equals("ALL") && !country.equals("")){
queryMap.put(QUERY_STRING_COUNTRY, country);
}

return queryMap;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
package com.example.yeseul.movieapp.view.main;

import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.customtabs.CustomTabsIntent;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.view.inputmethod.EditorInfo;
import android.widget.Toast;

import com.example.yeseul.movieapp.R;
import com.example.yeseul.movieapp.data.source.movie.MovieRepository;
import com.example.yeseul.movieapp.databinding.ActivityMovieBinding;
import com.example.yeseul.movieapp.utils.KeyboardUtil;
import com.example.yeseul.movieapp.view.BaseActivity;

import java.util.HashMap;

public class MainActivity extends BaseActivity<ActivityMovieBinding, MainPresenter> implements MainContract.View {

private MovieListAdapter adapter;


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  genrecountryMainPresenter에서 처리되기 때문에 Activity는 해당 정보를 가지고 있지 않는게 좋아 보입니다. 이 값은 Setter를 이용하여 Presenter로 넘겨주면 좋을 것 같습니다.

@Override
protected int getLayoutId() {
return R.layout.activity_movie;
Expand All @@ -44,6 +50,9 @@ protected void onCreate(Bundle savedInstanceState) {
initView();

presenter.onViewCreated();



}

private void initView() {
Expand All @@ -66,6 +75,7 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
}
});


// 키보드 검색 버튼 리스너 등록
binding.searchBox.etSearch.setOnEditorActionListener((v, actionId, event) -> {
if(actionId == EditorInfo.IME_ACTION_SEARCH){
Expand All @@ -77,6 +87,44 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat

// 검색 버튼 리스너 등록
binding.searchBox.btnSubmit.setOnClickListener(v -> onSearchButtonClicked());

// 필터 버튼 리스터 등록
binding.searchBox.btnFilter.setOnClickListener(v -> onFilterButtonClicked());

}

//필터 설정
private void onFilterButtonClicked() {


//국가 선택
AlertDialog.Builder cDialog = new AlertDialog.Builder(this);
cDialog.setTitle(R.string.country)
.setItems(R.array.country,
(dialog, which) -> {
presenter.setCountry(Integer.toString(which));
//country
}
)
.setOnDismissListener( (dialog) -> presenter.setFilter( getResources().getStringArray(R.array.genre)[Integer.parseInt(presenter.getGenre())],
getResources().getStringArray(R.array.country)[Integer.parseInt(presenter.getCountry())]
) );


//장르 선택
AlertDialog.Builder gDialog = new AlertDialog.Builder(this);
gDialog.setTitle(R.string.genre)
.setItems(R.array.genre,
(dialog, which) -> {

presenter.setGenre(Integer.toString(which));
}
)
.setOnDismissListener( (dialog) -> cDialog.show() );

gDialog.show();


}

/**
Expand All @@ -86,8 +134,9 @@ private void onSearchButtonClicked(){
// 입력값이 존재 하는지 체크
String searchKey = binding.searchBox.etSearch.getText().toString();


if(!TextUtils.isEmpty(searchKey)) {
presenter.onSearchButtonClicked(searchKey);
presenter.onSearchButtonClicked(searchKey, presenter.getGenre(), getResources().getStringArray(R.array.countryCode)[Integer.parseInt(presenter.getCountry())] );
binding.recyclerMovie.scrollToPosition(0);
binding.emptyView.setText("");
KeyboardUtil.closeKeyboard(this, binding.searchBox.etSearch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface View extends BaseView {

interface Presenter extends BasePresenter {

void onSearchButtonClicked(String searchKey);
void onSearchButtonClicked(String searchKey, String genre, String coutnry);

void setAdapterView(AdapterContract.View adapterView);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.example.yeseul.movieapp.pojo.Movie;
import com.example.yeseul.movieapp.view.adapter.AdapterContract;

import java.util.HashMap;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
Expand All @@ -23,15 +24,27 @@ public class MainPresenter implements MainContract.Presenter {
private AdapterContract.Model<Movie> adapterModel;

private String searchKey = ""; // 검색 키워드
private String genre = "0";
private String country = "0";
private final int PAGE_UNIT = 20; // 한번에 가져올 데이터 개수
private int currentPage = 0; // 현재 페이지 index
private boolean isEndOfPage = false; // 페이지 끝 flag

private ObservableField<String> filter = new ObservableField<>("필터");

public MainPresenter(MainContract.View view, MovieRepository repository) {
this.view = view;
this.repository = repository;
}

public ObservableField<String> getFilter() {
return filter;
}

public void setFilter(String genre, String country) {
filter.set("장르 : " + genre +"\n"+"국가 : "+country);
}

@Override
public void onViewCreated() {
// do nothing
Expand All @@ -54,8 +67,10 @@ public void loadItems(boolean isRefresh) {
}

@Override
public void onSearchButtonClicked(String searchKey) {
public void onSearchButtonClicked(String searchKey, String genre, String country) {
this.searchKey = searchKey;
this.genre = genre;
this.country = country;
loadItems(true);
}

Expand All @@ -76,7 +91,7 @@ private void getMovieList(){

isLoading.set(true);

repository.searchMovies(MovieMapper.toRequest(searchKey, PAGE_UNIT, (PAGE_UNIT * currentPage++) + 1))
repository.searchMovies(MovieMapper.toRequest(searchKey, PAGE_UNIT, (PAGE_UNIT * currentPage++) + 1, genre, country))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(response -> {

Expand Down Expand Up @@ -111,4 +126,20 @@ private void getMovieList(){
view.onSearchResultEmpty(searchKey);
});
}

public String getGenre() {
return genre;
}

public void setGenre(String genre) {
this.genre = genre;
}

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}
}
13 changes: 12 additions & 1 deletion app/src/main/res/layout/layout_search_box.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<EditText
android:id="@+id/et_search"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_weight="4"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/padding_main"
android:layout_marginStart="@dimen/padding_main"
Expand All @@ -30,6 +30,17 @@
android:textSize="@dimen/text_size_main"
android:gravity="center_vertical"/>

<Button
android:id="@+id/btn_filter"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="@color/colorPrimary"
android:textStyle="bold"
android:background="@null"
android:textSize="16sp"
android:text="@{presenter.filter}"
/>

<Button
android:id="@+id/btn_submit"
android:layout_width="wrap_content"
Expand Down
63 changes: 63 additions & 0 deletions app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="genre">

<item> 전체 </item>
<item> 드라마 </item>
<item> 판타지 </item>
<item> 서부 </item>
<item> 공포 </item>
<item> 로맨스 </item>
<item> 모험 </item>
<item> 스릴러 </item>
<item> 느와르 </item>
<item> 컬트 </item>
<item> 다큐멘터리 </item>
<item> 코미디 </item>
<item> 가족 </item>
<item> 미스터리 </item>
<item> 전쟁 </item>
<item> 애니메이션 </item>
<item> 범죄 </item>
<item> 뮤지컬 </item>
<item> SF </item>
<item> 액션 </item>
<item> 무협 </item>
<item> 에로 </item>
<item> 서스펜스 </item>
<item> 서사 </item>
<item> 블랙코미디 </item>
<item> 실험 </item>
<item> 영화카툰 </item>
<item> 영화음악 </item>
<item> 영화패러디포스터 </item>

</string-array>

<string-array name="country">

<item> 전체 </item>
<item> 한국 </item>
<item> 일본 </item>
<item> 미국 </item>
<item> 홍콩 </item>
<item> 영국 </item>
<item> 프랑스 </item>
<item> 기타 </item>

</string-array>

<string-array name="countryCode">

<item>ALL</item>
<item>KR</item>
<item>JP</item>
<item>US</item>
<item>HK</item>
<item>GB</item>
<item>FR</item>
<item>ETC</item>

</string-array>

</resources>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

고생하셨습니다. 확실히 영화를 검색하는 것에 있어 필터를 검색하는 것은 좋은 아이디어라고 생각합니다.
저는 기능적으로 모든 필터를 검사하는 것이 아닌, 검색한 결과에 대한 장르만 부분적으로 판별했으면 더 좋았을 것이라고 생각했습니다.
또한 resource에 값을 추가하고, HashMap으로도 관리했던 것 같은데,
두 가지를 더 간단하게 할 수 있는 방법은 없었을까? 생각했습니다.

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.

위에서 조언해주신대로 presenter에서 처리하는 방법을 생각해봐야겠네요

9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@
<string name="search_hint">검색어를 입력하세요.</string>
<string name="search_submit">검색</string>
<string name="search_result_empty">에 대한 검색결과가 없습니다.</string>

//사전 미션
<string name="search_filter">조건 검색</string>
<string name="genre">장르</string>
<string name="country">국가</string>
<string name="ok"> 확인 </string>
<string name="next"> 다음 </string>
<string name="cancel"> 취소 </string>

</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.3.0'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Dec 15 16:29:45 KST 2018
#Tue Jan 15 19:23:22 KST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip