diff --git a/app/src/main/java/io/github/emanual/app/entity/InterviewInfoEntity.java b/app/src/main/java/io/github/emanual/app/entity/InterviewInfoEntity.java new file mode 100644 index 0000000..315c2ab --- /dev/null +++ b/app/src/main/java/io/github/emanual/app/entity/InterviewInfoEntity.java @@ -0,0 +1,96 @@ +package io.github.emanual.app.entity; + +import java.util.List; + +/** + * Author: jayin + * Date: 2/25/16 + */ +public class InterviewInfoEntity extends BaseEntity{ + + private String name; + private String name_cn; + private String md5; + private String icon_url; + private String url; + private String author; + private String homepage; + private List maintainers; + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getHomepage() { + return homepage; + } + + public void setHomepage(String homepage) { + this.homepage = homepage; + } + + public String getIcon_url() { + return icon_url; + } + + public void setIcon_url(String icon_url) { + this.icon_url = icon_url; + } + + public List getMaintainers() { + return maintainers; + } + + public void setMaintainers(List maintainers) { + this.maintainers = maintainers; + } + + public String getMd5() { + return md5; + } + + public void setMd5(String md5) { + this.md5 = md5; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getName_cn() { + return name_cn; + } + + public void setName_cn(String name_cn) { + this.name_cn = name_cn; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + @Override public String toString() { + return "InterviewInfoEntity{" + + "author='" + author + '\'' + + ", homepage='" + homepage + '\'' + + ", icon_url='" + icon_url + '\'' + + ", maintainers=" + maintainers + + ", md5='" + md5 + '\'' + + ", name='" + name + '\'' + + ", name_cn='" + name_cn + '\'' + + ", url='" + url + '\'' + + '}'; + } +} diff --git a/app/src/main/java/io/github/emanual/app/entity/InterviewJSONEntity.java b/app/src/main/java/io/github/emanual/app/entity/InterviewJSONEntity.java new file mode 100644 index 0000000..7b396f9 --- /dev/null +++ b/app/src/main/java/io/github/emanual/app/entity/InterviewJSONEntity.java @@ -0,0 +1,27 @@ +package io.github.emanual.app.entity; + +/** + * Author: jayin + * Date: 2/25/16 + */ +public class InterviewJSONEntity extends BaseEntity { + + private String title; + private InterviewInfoEntity info; + + public InterviewInfoEntity getInfo() { + return info; + } + + public void setInfo(InterviewInfoEntity info) { + this.info = info; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/app/src/main/java/io/github/emanual/app/ui/MainActivity.java b/app/src/main/java/io/github/emanual/app/ui/MainActivity.java index 058a20f..88512bd 100644 --- a/app/src/main/java/io/github/emanual/app/ui/MainActivity.java +++ b/app/src/main/java/io/github/emanual/app/ui/MainActivity.java @@ -20,6 +20,7 @@ import io.github.emanual.app.ui.base.activity.BaseActivity; import io.github.emanual.app.ui.fragment.BookListFragment; import io.github.emanual.app.ui.fragment.ExploreFragment; +import io.github.emanual.app.ui.fragment.InterviewListFragment; import io.github.emanual.app.ui.fragment.NewFeedsFragment; import io.github.emanual.app.widget.NewVersionDialog; @@ -57,6 +58,7 @@ protected void initLayout(Bundle savedInstanceState) { fragments.add(new NewFeedsFragment()); fragments.add(new BookListFragment()); + fragments.add(new InterviewListFragment()); fragments.add(new ExploreFragment()); viewPager.setAdapter(new MainFragmentPagerAdapter( getSupportFragmentManager(), fragments, titles)); diff --git a/app/src/main/java/io/github/emanual/app/ui/adapter/InterviewListAdapter.java b/app/src/main/java/io/github/emanual/app/ui/adapter/InterviewListAdapter.java new file mode 100644 index 0000000..4893e41 --- /dev/null +++ b/app/src/main/java/io/github/emanual/app/ui/adapter/InterviewListAdapter.java @@ -0,0 +1,75 @@ +package io.github.emanual.app.ui.adapter; + +import android.content.Context; +import android.net.Uri; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import android.widget.Toast; + +import com.facebook.drawee.view.SimpleDraweeView; + +import java.util.List; + +import butterknife.Bind; +import butterknife.ButterKnife; +import io.github.emanual.app.R; +import io.github.emanual.app.entity.InterviewJSONEntity; + +/** + * Author: jayin + * Date: 2/25/16 + */ +public class InterviewListAdapter extends RecyclerView.Adapter{ + Context context; + List data; + + public InterviewListAdapter(Context context, List data){ + this.context = context; + this.data = data; + } + + public Context getContext() { + return context; + } + + public List getData() { + return data; + } + + @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.adapter_interviewlist, parent, false)); + } + + @Override public void onBindViewHolder(ViewHolder holder, int position) { + final InterviewJSONEntity item = data.get(position); + holder.tv_name.setText(item.getInfo().getName_cn()); + holder.iv_icon.setImageURI(Uri.parse(item.getInfo().getIcon_url())); + holder.layout_container.setOnClickListener(new View.OnClickListener() { + @Override public void onClick(View v) { + Toast.makeText(getContext(), item.getInfo().getName_cn(), Toast.LENGTH_SHORT).show(); +// Intent intent = new Intent(getContext(), BrowserActivity.class); +// //can be custom the index.html +// intent.putExtra(BrowserActivity.EXTRA_URL, AppPath.getBookIndexURL(getContext(), item.getInfo().getName())); +// getContext().startActivity(intent); + } + }); + } + + @Override public int getItemCount() { + return data.size(); + } + + public static class ViewHolder extends RecyclerView.ViewHolder { + @Bind(R.id.layout_container) View layout_container; + @Bind(R.id.tv_name) TextView tv_name; + @Bind(R.id.iv_icon) SimpleDraweeView iv_icon; + + public ViewHolder(View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + } + } +} diff --git a/app/src/main/java/io/github/emanual/app/ui/event/FinishQueryInterviewListEvent.java b/app/src/main/java/io/github/emanual/app/ui/event/FinishQueryInterviewListEvent.java new file mode 100644 index 0000000..a0a19db --- /dev/null +++ b/app/src/main/java/io/github/emanual/app/ui/event/FinishQueryInterviewListEvent.java @@ -0,0 +1,31 @@ +package io.github.emanual.app.ui.event; + +import java.util.List; + +import io.github.emanual.app.entity.InterviewJSONEntity; + +/** + * Author: jayin + * Date: 2/25/16 + */ +public class FinishQueryInterviewListEvent extends BaseEvent { + List data; + + public FinishQueryInterviewListEvent(List data) { + this.data = data; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + @Override public String toString() { + return "FinishQueryInterviewListEvent{" + + "data=" + data + + '}'; + } +} diff --git a/app/src/main/java/io/github/emanual/app/ui/event/QueryInterviewListEvent.java b/app/src/main/java/io/github/emanual/app/ui/event/QueryInterviewListEvent.java new file mode 100644 index 0000000..41a576a --- /dev/null +++ b/app/src/main/java/io/github/emanual/app/ui/event/QueryInterviewListEvent.java @@ -0,0 +1,8 @@ +package io.github.emanual.app.ui.event; + +/** + * Author: jayin + * Date: 2/25/16 + */ +public class QueryInterviewListEvent extends BaseEvent{ +} diff --git a/app/src/main/java/io/github/emanual/app/ui/fragment/InterviewListFragment.java b/app/src/main/java/io/github/emanual/app/ui/fragment/InterviewListFragment.java new file mode 100644 index 0000000..a618d98 --- /dev/null +++ b/app/src/main/java/io/github/emanual/app/ui/fragment/InterviewListFragment.java @@ -0,0 +1,66 @@ +package io.github.emanual.app.ui.fragment; + +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; + +import java.util.List; + +import butterknife.Bind; +import de.greenrobot.event.EventBus; +import de.greenrobot.event.Subscribe; +import de.greenrobot.event.ThreadMode; +import io.github.emanual.app.R; +import io.github.emanual.app.entity.InterviewJSONEntity; +import io.github.emanual.app.ui.adapter.InterviewListAdapter; +import io.github.emanual.app.ui.base.fragment.BaseFragment; +import io.github.emanual.app.ui.event.FinishQueryInterviewListEvent; +import io.github.emanual.app.ui.event.QueryInterviewListEvent; +import io.github.emanual.app.ui.event.UnPackFinishEvent; +import io.github.emanual.app.utils.InterviewResource; +import timber.log.Timber; + +/** + * 面试笔试列表 + * Author: jayin + * Date: 2/24/16 + */ +public class InterviewListFragment extends BaseFragment{ + + @Bind(R.id.recyclerView) RecyclerView recyclerView; + + @Override protected void initData(Bundle savedInstanceState) { + + } + + @Override protected void initLayout(Bundle savedInstanceState) { + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + EventBus.getDefault().post(new QueryInterviewListEvent()); + } + + @Override protected int getContentViewId() { + return R.layout.fragment_interview_list; + } + + /** + * 新书下载解压完成后更新书本列表 + * @param event + */ + @Subscribe(threadMode = ThreadMode.MainThread) + public void onUnPackFinish(UnPackFinishEvent event){ + EventBus.getDefault().post(new QueryInterviewListEvent()); + } + + @Subscribe(threadMode = ThreadMode.Async) + public void onQueryInterviewList(QueryInterviewListEvent event) { + List interviewJSONEntities = InterviewResource.getInterviewJSONList(getContext()); + EventBus.getDefault().post(new FinishQueryInterviewListEvent(interviewJSONEntities)); + } + + @Subscribe(threadMode = ThreadMode.MainThread) + public void onFinishQueryInterviewList(FinishQueryInterviewListEvent event) { + Timber.d(event.getData().toString()); + recyclerView.setAdapter(new InterviewListAdapter(getContext(), event.getData())); + } + +} diff --git a/app/src/main/java/io/github/emanual/app/utils/AppPath.java b/app/src/main/java/io/github/emanual/app/utils/AppPath.java index a3fb7a6..9f679c4 100644 --- a/app/src/main/java/io/github/emanual/app/utils/AppPath.java +++ b/app/src/main/java/io/github/emanual/app/utils/AppPath.java @@ -43,7 +43,7 @@ public static String getInterviewsPath(Context context){ return getAppFilesPath(context) + File.separator + "interviews"; } - + //========Book /** * 获取教程的根目录/data/data//files/books/ @@ -73,6 +73,38 @@ public static String getBookJSONFilePath(Context context, String bookName){ return getBookPath(context, bookName) + File.separator + "book.json"; } + //=========== Interview + + /** + * 获取Interview的根目录/data/data//files/interviews/ + * @param context + * @param interviewName + * @return + */ + public static String getInterviewRootPath(Context context, String interviewName){ + return getInterviewsPath(context) + File.separator + interviewName; + } + + /** + * 获取Interview的Interview目录:/data/data//files/books//interview + * @param context + * @param interviewName + * @return + */ + public static String getInterviewPath(Context context, String interviewName) { + return getInterviewRootPath(context, interviewName) + File.separator + "interview"; + } + /** + * 获取教程的interview.json /data/data//files/books//interview/interview.json + * @param context + * @param interviewName + * @return + */ + public static String getInterviewJSONFilePath(Context context, String interviewName){ + return getInterviewPath(context, interviewName) + File.separator + "interview.json"; + } + + /** * 获取教程的入口文件(index.html) * @param context diff --git a/app/src/main/java/io/github/emanual/app/utils/BookResource.java b/app/src/main/java/io/github/emanual/app/utils/BookResource.java index 65aa7d8..da08d32 100644 --- a/app/src/main/java/io/github/emanual/app/utils/BookResource.java +++ b/app/src/main/java/io/github/emanual/app/utils/BookResource.java @@ -30,7 +30,7 @@ public static List getBookNameList(Context context) { } /** - * 获取所有books//book.json + * 获取所有books//book/book.json * @param context * @return */ diff --git a/app/src/main/java/io/github/emanual/app/utils/InterviewResource.java b/app/src/main/java/io/github/emanual/app/utils/InterviewResource.java new file mode 100644 index 0000000..e69a587 --- /dev/null +++ b/app/src/main/java/io/github/emanual/app/utils/InterviewResource.java @@ -0,0 +1,50 @@ +package io.github.emanual.app.utils; + +import android.content.Context; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import io.github.emanual.app.entity.InterviewJSONEntity; + +/** + * Author: jayin + * Date: 2/25/16 + */ +public class InterviewResource { + /** + * 获取所有interviews/* 所有文件名(英文书名)列表 + * @param context + * @return + */ + public static List getInterviewNameList(Context context) { + List books = new ArrayList<>(); + File bookDir = new File(AppPath.getInterviewsPath(context)); + if (!bookDir.exists()) { + bookDir.mkdirs(); + } + books.addAll(Arrays.asList(bookDir.list())); + return books; + } + + /** + * 获取所有interviews//interview/interview.json + * @param context + * @return + */ + public static List getInterviewJSONList(Context context) { + List interviewJSONEntities = new ArrayList<>(); + File interviewDir = new File(AppPath.getInterviewsPath(context)); + if (!interviewDir.exists()) { + interviewDir.mkdirs(); + } + for (String interviewName : interviewDir.list()) { + String json = _.readFile(AppPath.getInterviewJSONFilePath(context, interviewName)); + InterviewJSONEntity interviewJSONEntity = InterviewJSONEntity.createByJSON(json, InterviewJSONEntity.class); + interviewJSONEntities.add(interviewJSONEntity); + } + return interviewJSONEntities; + } +} diff --git a/app/src/main/res/layout/adapter_interviewlist.xml b/app/src/main/res/layout/adapter_interviewlist.xml new file mode 100644 index 0000000..86cc36e --- /dev/null +++ b/app/src/main/res/layout/adapter_interviewlist.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_interview_list.xml b/app/src/main/res/layout/fragment_interview_list.xml new file mode 100644 index 0000000..3888941 --- /dev/null +++ b/app/src/main/res/layout/fragment_interview_list.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9674d89..5e9e8f9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,6 +14,7 @@ 新鲜事 学习库 + 应试宝典 发 现