Skip to content

Commit

Permalink
Interview: 完成Interview列表
Browse files Browse the repository at this point in the history
rel #67
  • Loading branch information
Jayin committed Feb 25, 2016
1 parent c336e68 commit eee5a90
Show file tree
Hide file tree
Showing 13 changed files with 461 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<MaintainerEntity> 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<MaintainerEntity> getMaintainers() {
return maintainers;
}

public void setMaintainers(List<MaintainerEntity> 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 + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/io/github/emanual/app/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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<InterviewListAdapter.ViewHolder>{
Context context;
List<InterviewJSONEntity> data;

public InterviewListAdapter(Context context, List<InterviewJSONEntity> data){
this.context = context;
this.data = data;
}

public Context getContext() {
return context;
}

public List<InterviewJSONEntity> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<InterviewJSONEntity> data;

public FinishQueryInterviewListEvent(List<InterviewJSONEntity> data) {
this.data = data;
}

public List<InterviewJSONEntity> getData() {
return data;
}

public void setData(List<InterviewJSONEntity> data) {
this.data = data;
}

@Override public String toString() {
return "FinishQueryInterviewListEvent{" +
"data=" + data +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.github.emanual.app.ui.event;

/**
* Author: jayin
* Date: 2/25/16
*/
public class QueryInterviewListEvent extends BaseEvent{
}
Original file line number Diff line number Diff line change
@@ -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<InterviewJSONEntity> 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()));
}

}
34 changes: 33 additions & 1 deletion app/src/main/java/io/github/emanual/app/utils/AppPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static String getInterviewsPath(Context context){
return getAppFilesPath(context) + File.separator + "interviews";
}


//========Book

/**
* 获取教程的根目录/data/data/<App Name>/files/books/<bookName>
Expand Down Expand Up @@ -73,6 +73,38 @@ public static String getBookJSONFilePath(Context context, String bookName){
return getBookPath(context, bookName) + File.separator + "book.json";
}

//=========== Interview

/**
* 获取Interview的根目录/data/data/<App Name>/files/interviews/<interviewName>
* @param context
* @param interviewName
* @return
*/
public static String getInterviewRootPath(Context context, String interviewName){
return getInterviewsPath(context) + File.separator + interviewName;
}

/**
* 获取Interview的Interview目录:/data/data/<App Name>/files/books/<bookName>/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/<App Name>/files/books/<bookName>/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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static List<String> getBookNameList(Context context) {
}

/**
* 获取所有books/<bookName>/book.json
* 获取所有books/<bookName>/book/book.json
* @param context
* @return
*/
Expand Down
Loading

0 comments on commit eee5a90

Please sign in to comment.