// Path: app/src/main/java/com/mgilangjanuar/dev/goscele/modules/course/adapter/CourseSearchRecyclerViewAdapter.java
// public class CourseSearchRecyclerViewAdapter extends BaseRecyclerViewAdapter<CourseSearchRecyclerViewAdapter.ViewHolder> {
// 
//     private List<CourseSearchModel> list;
// 
//     public CourseSearchRecyclerViewAdapter(List<CourseSearchModel> list) {
//         this.list = list;
//     }
// 
//     @Override
//     public int findLayout() {
//         return R.layout.layout_search_course;
//     }
// 
//     @Override
//     public List<?> findList() {
//         return list;
//     }
// 
//     @Override
//     public void initialize(ViewHolder holder, int position) {
//         final CourseSearchModel model = list.get(position);
//         holder.name.setText(model.name);
//         holder.layout.setOnClickListener(new View.OnClickListener() {
//             @Override
//             public void onClick(View v) {
//                 Intent intent = new Intent(v.getContext(), BrowserActivity.class);
//                 intent.putExtra(Constant.URL, model.url);
//                 v.getContext().startActivity(intent);
//             }
//         });
//     }
// 
//     @Override
//     public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//         return new ViewHolder(createView(parent));
//     }
// 
//     public static class ViewHolder extends BaseViewHolder {
// 
//         @BindView(R.id.layout_course_search)
//         LinearLayout layout;
// 
//         @BindView(R.id.title_course_name_search)
//         TextView name;
// 
//         public ViewHolder(View itemView) {
//             super(itemView);
//         }
//     }
// }
// 
// Path: app/src/main/java/com/mgilangjanuar/dev/goscele/modules/course/listener/CourseSearchListener.java
// public interface CourseSearchListener {
// 
//     void onRetrieve(CourseSearchRecyclerViewAdapter adapter);
// 
//     void onError(String error);
// }
// 
// Path: app/src/main/java/com/mgilangjanuar/dev/goscele/modules/course/model/CourseSearchModel.java
// public class CourseSearchModel {
// 
//     public String name;
// 
//     public String url;
// 
//     public CourseSearchModel(String name, String url) {
//         this.name = name;
//         this.url = url;
//     }
// }
// 
// Path: app/src/main/java/com/mgilangjanuar/dev/goscele/modules/course/provider/CourseSearchProvider.java
// public class CourseSearchProvider extends BaseProvider {
// 
//     private CourseSearchListener listener;
//     private String query;
// 
//     public CourseSearchProvider(CourseSearchListener listener, String query) {
//         this.listener = listener;
//         this.query = query;
//     }
// 
//     @Override
//     public Map<String, String> cookies() {
//         return CookieModel.getCookiesMap();
//     }
// 
//     @Override
//     public void run() {
//         execute(".course-search-result.course-search-result-search");
//     }
// 
//     @Override
//     public String url() {
//         try {
//             return Constant.BASE_URL + "course/search.php?search=" + URLEncoder.encode(query, "UTF-8");
//         } catch (UnsupportedEncodingException e) {
//             e.printStackTrace();
//         }
//         return null;
//     }
// 
//     @Override
//     protected void onPostExecute(List<Elements> elementses) {
//         super.onPostExecute(elementses);
//         try {
//             Elements elements = elementses.get(0);
//             List<CourseSearchModel> results = new ArrayList<>();
//             for (Element e: elements.select(".coursebox")) {
//                 String name = e.select(".coursename").text();
//                 String url = e.select(".coursename a").attr("href");
//                 results.add(new CourseSearchModel(name, url));
//             }
//             listener.onRetrieve(new CourseSearchRecyclerViewAdapter(results));
//         } catch (Exception e) {
//             listener.onError(e.getMessage());
//         }
//     }
// }


import android.text.TextUtils;
import com.mgilangjanuar.dev.goscele.modules.course.adapter.CourseSearchRecyclerViewAdapter;
import com.mgilangjanuar.dev.goscele.modules.course.listener.CourseSearchListener;
import com.mgilangjanuar.dev.goscele.modules.course.model.CourseSearchModel;
import com.mgilangjanuar.dev.goscele.modules.course.provider.CourseSearchProvider;
import java.util.ArrayList;
package com.mgilangjanuar.dev.goscele.modules.course.presenter;




/**
 * Created by mgilangjanuar (mgilangjanuar@gmail.com)
 *
 * @since 2017
 */

public class CourseSearchPresenter {

    private CourseSearchListener listener;

    public CourseSearchPresenter(CourseSearchListener listener) {
        this.listener = listener;
    }

    private boolean validate(String query) {
        return !TextUtils.isEmpty(query);
    }

    public CourseSearchRecyclerViewAdapter buildEmptyAdapter() {
        return new CourseSearchRecyclerViewAdapter(new ArrayList<CourseSearchModel>());
    }

// Path: app/src/main/java/com/mgilangjanuar/dev/goscele/modules/course/adapter/CourseSearchRecyclerViewAdapter.java
// public class CourseSearchRecyclerViewAdapter extends BaseRecyclerViewAdapter<CourseSearchRecyclerViewAdapter.ViewHolder> {
// 
//     private List<CourseSearchModel> list;
// 
//     public CourseSearchRecyclerViewAdapter(List<CourseSearchModel> list) {
//         this.list = list;
//     }
// 
//     @Override
//     public int findLayout() {
//         return R.layout.layout_search_course;
//     }
// 
//     @Override
//     public List<?> findList() {
//         return list;
//     }
// 
//     @Override
//     public void initialize(ViewHolder holder, int position) {
//         final CourseSearchModel model = list.get(position);
//         holder.name.setText(model.name);
//         holder.layout.setOnClickListener(new View.OnClickListener() {
//             @Override
//             public void onClick(View v) {
//                 Intent intent = new Intent(v.getContext(), BrowserActivity.class);
//                 intent.putExtra(Constant.URL, model.url);
//                 v.getContext().startActivity(intent);
//             }
//         });
//     }
// 
//     @Override
//     public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//         return new ViewHolder(createView(parent));
//     }
// 
//     public static class ViewHolder extends BaseViewHolder {
// 
//         @BindView(R.id.layout_course_search)
//         LinearLayout layout;
// 
//         @BindView(R.id.title_course_name_search)
//         TextView name;
// 
//         public ViewHolder(View itemView) {
//             super(itemView);
//         }
//     }
// }
// 
// Path: app/src/main/java/com/mgilangjanuar/dev/goscele/modules/course/listener/CourseSearchListener.java
// public interface CourseSearchListener {
// 
//     void onRetrieve(CourseSearchRecyclerViewAdapter adapter);
// 
//     void onError(String error);
// }
// 
// Path: app/src/main/java/com/mgilangjanuar/dev/goscele/modules/course/model/CourseSearchModel.java
// public class CourseSearchModel {
// 
//     public String name;
// 
//     public String url;
// 
//     public CourseSearchModel(String name, String url) {
//         this.name = name;
//         this.url = url;
//     }
// }
// 
// Path: app/src/main/java/com/mgilangjanuar/dev/goscele/modules/course/provider/CourseSearchProvider.java
// public class CourseSearchProvider extends BaseProvider {
// 
//     private CourseSearchListener listener;
//     private String query;
// 
//     public CourseSearchProvider(CourseSearchListener listener, String query) {
//         this.listener = listener;
//         this.query = query;
//     }
// 
//     @Override
//     public Map<String, String> cookies() {
//         return CookieModel.getCookiesMap();
//     }
// 
//     @Override
//     public void run() {
//         execute(".course-search-result.course-search-result-search");
//     }
// 
//     @Override
//     public String url() {
//         try {
//             return Constant.BASE_URL + "course/search.php?search=" + URLEncoder.encode(query, "UTF-8");
//         } catch (UnsupportedEncodingException e) {
//             e.printStackTrace();
//         }
//         return null;
//     }
// 
//     @Override
//     protected void onPostExecute(List<Elements> elementses) {
//         super.onPostExecute(elementses);
//         try {
//             Elements elements = elementses.get(0);
//             List<CourseSearchModel> results = new ArrayList<>();
//             for (Element e: elements.select(".coursebox")) {
//                 String name = e.select(".coursename").text();
//                 String url = e.select(".coursename a").attr("href");
//                 results.add(new CourseSearchModel(name, url));
//             }
//             listener.onRetrieve(new CourseSearchRecyclerViewAdapter(results));
//         } catch (Exception e) {
//             listener.onError(e.getMessage());
//         }
//     }
// }


// Path: app/src/main/java/com/mgilangjanuar/dev/goscele/modules/course/presenter/CourseSearchPresenter.java
import android.text.TextUtils;
import com.mgilangjanuar.dev.goscele.modules.course.adapter.CourseSearchRecyclerViewAdapter;
import com.mgilangjanuar.dev.goscele.modules.course.listener.CourseSearchListener;
import com.mgilangjanuar.dev.goscele.modules.course.model.CourseSearchModel;
import com.mgilangjanuar.dev.goscele.modules.course.provider.CourseSearchProvider;
import java.util.ArrayList;

package com.mgilangjanuar.dev.goscele.modules.course.presenter;




/**
 * Created by mgilangjanuar (mgilangjanuar@gmail.com)
 *
 * @since 2017
 */

public class CourseSearchPresenter {

    private CourseSearchListener listener;

    public CourseSearchPresenter(CourseSearchListener listener) {
        this.listener = listener;
    }

    private boolean validate(String query) {
        return !TextUtils.isEmpty(query);
    }

    public CourseSearchRecyclerViewAdapter buildEmptyAdapter() {
        return new CourseSearchRecyclerViewAdapter(new ArrayList<CourseSearchModel>());
    }

    public void search(String query) {