kGank
介绍
用gank
提供的api制作的app
摸索着使用了MVP模式
功能
-
提供gank网上的数据
-
点击单项可进入对应页面
-
收藏页面
-
搜索界面
未完成功能
- 暂无
记录
- listview的简单使用(弃)
// Creat a list of HashMap to get the datas shows on listview
ArrayList> mArrayList = new ArrayList>();
int mId = 0;
for(result mResult : fList_result){
HashMap map = new HashMap();
map.put("Desc",mResult.getDesc());
map.put("Date",mResult.getPublishedAt());
map.put("Who",mResult.getWho());
map.put("Id",(++mId) +"");
mArrayList.add(map);
}
mSimpleAdapter = new SimpleAdapter(
getContext(),
mArrayList,
R.layout.listview_dataitem,
new String[] {"Desc","Date","Who","Id"},
new int[] {R.id.listview_dataitem_descText,
R.id.listview_dataitem_datetext,
R.id.listview_dataitem_whotext,
R.id.listview_dataitem_IdText});
mListView.setAdapter(mSimpleAdapter);
mListView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView p1, View p2, int p3, long p4)
{
LinearLayout l = (LinearLayout) p2;
TextView t = (TextView)l.findViewById(R.id.listview_dataitem_descText);
for(result resultb :fList_result){
if(resultb.getDesc().equals(t.getText().toString()))
openWebWindow(resultb.getUrl());
}
// TODO: Implement this method
}
});
-
sugar的简单使用
-
okhttp3的简单使用
-
DialogFragment
-
recyclerview的简单使用
- 导包:
compile 'com.squareup.okhttp3:okhttp:3.6.0'
//用于转化实例
compile 'com.google.code.gson:gson:2.2.4'
- 获取Call
@Override
public Call getGankArticle(String type, int page)
{
//new a Call by using okhttp3
//and return it.
String mBaseUrl = "http://gank.io/api/";
final String NUM_PER_PAGE = "10";
OkHttpClient mOkHttpClient = new OkHttpClient();
Request.Builder builder = new Request.Builder().url(mBaseUrl +"data/" + type +"/" + NUM_PER_PAGE + "/" + page);
final Request request =builder.build();
Call mCall = mOkHttpClient.newCall(request);
// TODO: Implement this method
return mCall;
}
- 额..不知道怎么分
@Override
public void loadArticle(String type, int page)
{
Call mCall = mModelImpl.getGankArticle(type,page);
mCall.enqueue(new Callback(){
@Override
public void onFailure(Call p1, IOException p2)
{
// TODO: Implement this method
}
@Override
public void onResponse(Call p1, Response p2) throws IOException
{
DataEntity mDE = new Gson().fromJson(p2.body().string(),DataEntity.class);
Log.i("test",""+mDE.getResults().size());
mView.addViews(mDE.getResults());
// TODO: Implement this method
}
});
- Navigation的简单使用
在activity 中实现:
package com.kfdykme.view.navigationview;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.*;
import android.support.v4.view.*;
import android.support.v7.app.*;
public class Main extends AppCompatActivity
{
private DrawerLayout mDrawerLayout;
private NavigationView mNavigationView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mDrawerLayout = (DrawerLayout) findViewById(R.id.id_drawer_layout);
mNavigationView = (NavigationView) findViewById(R.id.id_nv_menu);
setupDrawerContent(mNavigationView);
}
private void setupDrawerContent(NavigationView navigationView)
{
navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener()
{
@Override
public boolean onNavigationItemSelected(MenuItem menuItem)
{
menuItem.setChecked(true);
mDrawerLayout.closeDrawers();
return true;
}
});
}
}
备注1
AIDE 无法使用引入了注解的库
有机会弄明白原因并尝试使用
greenDao & retrofit & maybe others need it
备注2
使用mvp模式和网络请求时,之前一直纠结于如何在model或presenter 中onResponse后再在得到返回后在view中刷新
后来发现其实可以返回一个call 然后在别处使用它
还是有点纠结,难以说清
备注3
mvp模式看了这个博客后感觉有点清晰起来了。
3.12
- 重写KGankMainActivity的onKeyDown()方法 :打开WebDow时按返回键判断goback。
3.13
- Use SwipeRefreshLayout implements "Pull down refresh"
- Implements "Pull up load more" by rewriting RecyclerView's adapter . Not so good.
网友评论