-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
iMeiji
committed
Nov 25, 2016
1 parent
8a50aca
commit 0671b6e
Showing
91 changed files
with
537 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.meiji.daily.dao; | ||
|
||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteDatabase; | ||
|
||
import com.meiji.daily.db.ZhuanlanHelper; | ||
import com.meiji.daily.mvp.zhuanlan.ZhuanlanBean; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_AVATARId; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_AVATARURL; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_FOLLOWERSCOUNT; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_INTRO; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_NAME; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_POSTSCOUNT; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_SLUG; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_TYPE; | ||
|
||
/** | ||
* Created by Meiji on 2016/11/25. | ||
*/ | ||
|
||
public class ZhuanlanDao { | ||
|
||
private Context mContext; | ||
|
||
public ZhuanlanDao(Context mContext) { | ||
this.mContext = mContext; | ||
} | ||
|
||
public boolean add( | ||
String type, | ||
String avatarUrl, | ||
String avatarId, | ||
String name, | ||
String followersCount, | ||
String postsCount, | ||
String intro, | ||
String slug) { | ||
ZhuanlanHelper helper = new ZhuanlanHelper(mContext, 1); | ||
SQLiteDatabase db = helper.getWritableDatabase(); | ||
ContentValues values = new ContentValues(); | ||
values.put(ZHUANLANBEAN_TYPE, type); | ||
values.put(ZHUANLANBEAN_AVATARURL, avatarUrl); | ||
values.put(ZHUANLANBEAN_AVATARId, avatarId); | ||
values.put(ZHUANLANBEAN_NAME, name); | ||
values.put(ZHUANLANBEAN_FOLLOWERSCOUNT, followersCount); | ||
values.put(ZHUANLANBEAN_POSTSCOUNT, postsCount); | ||
values.put(ZHUANLANBEAN_INTRO, intro); | ||
values.put(ZHUANLANBEAN_SLUG, slug); | ||
long id = db.insert("zhuanlan", null, values); | ||
db.close(); | ||
return id != -1; | ||
} | ||
|
||
public List<ZhuanlanBean> query(int type) { | ||
ZhuanlanHelper helper = new ZhuanlanHelper(mContext, 1); | ||
SQLiteDatabase db = helper.getReadableDatabase(); | ||
Cursor cursor = db.query("zhuanlan", null, "type=?", new String[]{type + ""}, null, null, null); | ||
List<ZhuanlanBean> list = new ArrayList<>(); | ||
while (cursor.moveToNext()) { | ||
ZhuanlanBean bean = new ZhuanlanBean(); | ||
ZhuanlanBean.AvatarBeanX avatarBeanX = new ZhuanlanBean.AvatarBeanX(); | ||
avatarBeanX.setTemplate(cursor.getString(2)); | ||
avatarBeanX.setId(cursor.getString(3)); | ||
bean.setAvatar(avatarBeanX); | ||
bean.setName(cursor.getString(4)); | ||
bean.setFollowersCount(Integer.parseInt(cursor.getString(5))); | ||
bean.setPostsCount(Integer.parseInt(cursor.getString(6))); | ||
bean.setIntro(cursor.getString(7)); | ||
bean.setSlug(cursor.getString(8)); | ||
list.add(bean); | ||
} | ||
cursor.close(); | ||
db.close(); | ||
return list; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.meiji.daily.db; | ||
|
||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_AVATARId; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_AVATARURL; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_FOLLOWERSCOUNT; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_INTRO; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_NAME; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_POSTSCOUNT; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_SLUG; | ||
import static com.meiji.daily.mvp.zhuanlan.ZhuanlanBean.ZHUANLANBEAN_TYPE; | ||
|
||
/** | ||
* Created by Meiji on 2016/11/25. | ||
*/ | ||
|
||
public class ZhuanlanHelper extends SQLiteOpenHelper { | ||
|
||
public static final String ZHUANLAN_TABLE = "zhuanlan"; | ||
private static final String BDNAME = "zhuanlan.db"; | ||
private static String createTable = "create table zhuanlan" + | ||
"(" + | ||
"id integer primary key autoincrement," + | ||
ZHUANLANBEAN_TYPE + " varcher(10)," + | ||
ZHUANLANBEAN_AVATARURL + " varcher(50)," + | ||
ZHUANLANBEAN_AVATARId + " varcher(30)," + | ||
ZHUANLANBEAN_NAME + " varcher(20)," + | ||
ZHUANLANBEAN_FOLLOWERSCOUNT + " varcher(10)," + | ||
ZHUANLANBEAN_POSTSCOUNT + " varcher(10)," + | ||
ZHUANLANBEAN_INTRO + " varcher(30)," + | ||
ZHUANLANBEAN_SLUG + " varcher(20)" + | ||
")"; | ||
|
||
public ZhuanlanHelper(Context context, int version) { | ||
super(context, BDNAME, null, version); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase sqLiteDatabase) { | ||
sqLiteDatabase.execSQL(createTable); | ||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.