Skip to content

Commit

Permalink
Update V1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
GcsSloop committed Apr 2, 2016
1 parent ae01628 commit db2d478
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 37 deletions.
33 changes: 25 additions & 8 deletions library/src/main/java/com/sloop/adapter/utils/CommonAdapter.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.sloop.adapter.utils;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
* ListView 的通用适配器
* Author: Sloop
* Version: v1.0
* Version: v1.1
* Date: 2015/11/17
* <ul type="disc">
* <li><a href="http://www.sloop.icoc.cc" target="_blank">作者网站</a> </li>
Expand All @@ -23,19 +25,35 @@ public abstract class CommonAdapter<T> extends BaseAdapter {

private LayoutInflater mInflater;
private Context mContext;
private List<T> mDatas;
private List<T> mDatas = new ArrayList<>();
private int mLayoutId;

/**
* @param context 上下文
* @param datas 数据集
* @param layoutId 布局ID
*/
public CommonAdapter(Context context, List<T> datas, int layoutId) {
public CommonAdapter(@NonNull Context context, List<T> datas, @NonNull int layoutId) {
mInflater = LayoutInflater.from(context);
this.mContext = context;
this.mDatas = datas;
this.mLayoutId = layoutId;
if(datas!=null){
this.mDatas = datas;
}
}

public void addDatas(List<T> datas){
this.mDatas.addAll(datas);
notifyDataSetChanged();
}

public void clearDatas(){
this.mDatas.clear();
notifyDataSetChanged();
}

public T getDataById(int position){
return mDatas.get(position);
}

@Override
Expand All @@ -58,7 +76,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
//实例化一个ViewHolder
ViewHolder holder = ViewHolder.getInstance(mContext, convertView, parent, mLayoutId, position);
//需要自定义的部分
convert(holder, getItem(position));
convert(position, holder, getItem(position));

return holder.getConvertView();
}
Expand All @@ -69,6 +87,5 @@ public View getView(int position, View convertView, ViewGroup parent) {
* @param holder ViewHolder
* @param bean 数据集
*/
public abstract void convert(ViewHolder holder, T bean);
}

public abstract void convert(int position, ViewHolder holder, T bean);
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ public <T extends View> T getView(int resId) {
public View getConvertView() {
return mConvertView;
}
}
}
41 changes: 41 additions & 0 deletions library/src/main/java/com/sloop/net/utils/NetUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.sloop.net.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
* <ul type="disc">
* <li>Author: Sloop</li>
* <li>Version: v1.0.0</li>
* <li>Date: 2016/3/8</li>
* <li>Copyright (c) 2015 GcsSloop</li>
* <li><a href="http://weibo.com/GcsSloop" target="_blank">WeiBo</a> </li>
* <li><a href="https://github.com/GcsSloop" target="_blank">GitHub</a> </li>
* </ul>
*/
public class NetUtils {

/**
* 用户是否连接网络
* @param context Context
*/
public static boolean isNetConnection(Context context) {
final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
return (networkInfo != null && networkInfo.isAvailable());
}

/**
* 是否连接Wifi
* @param context Context
*/
public static boolean isWifiConnection(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (wifiNetworkInfo.isConnected()) {
return true;
}
return false;
}
}
28 changes: 0 additions & 28 deletions library/src/main/java/com/sloop/net/utils/WiFiUtils.java

This file was deleted.

0 comments on commit db2d478

Please sign in to comment.