Skip to content

Commit

Permalink
更换成第一种createUser的方法
Browse files Browse the repository at this point in the history
  • Loading branch information
adohe committed Jul 10, 2012
1 parent 3b9f67e commit bc40790
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
24 changes: 22 additions & 2 deletions WeTongji/src/com/wetongji/ActivityLogin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.wetongji;

import org.json.JSONException;
import org.json.JSONObject;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuItem;
import com.google.gson.Gson;
import com.j256.ormlite.dao.RuntimeExceptionDao;
import com.wetongji.daofactory.UserFactory;
import com.wetongji.data.DbHelper;
Expand Down Expand Up @@ -146,6 +150,21 @@ private void stopProgressDialog(){
progressDialog = null;
}
}

public void createUser(String jsonStr) throws Exception
{
JSONObject data = new JSONObject(jsonStr);
JSONObject userStr = data.getJSONObject("User");

Gson gson = new Gson();

User user = gson.fromJson(userStr.toString(), User.class);

dbHelper=new DbHelper(getApplicationContext());
RuntimeExceptionDao<User, String> userDao=dbHelper.getUserDao();
userDao.createIfNotExists(user);

}
public class LoginTask extends AsyncTask<Integer, String, Integer>
{
private WTClient wTClient;
Expand All @@ -166,13 +185,14 @@ protected Integer doInBackground(Integer... arg0)

if(!this.wTClient.isHasError())
{
dbHelper=new DbHelper(getApplicationContext());
/*dbHelper=new DbHelper(getApplicationContext());
UserFactory userFactory=new UserFactory();
//userFactory.create(jsonObject);
//我没找到你要写入数据库的user对应的json啊???
User user=userFactory.getUser();
RuntimeExceptionDao<User, String> userDao=dbHelper.getUserDao();
userDao.createIfNotExists(user);
userDao.createIfNotExists(user);*/
ActivityLogin.this.createUser(this.wTClient.getResponseStr());
//在这里添加数据层的部分,entityfactory是个抽象的接口,调用userfactory的getUser()可以返回user对象
Intent intent = new Intent(getApplicationContext(), ActivityMainViewpager.class);
startActivity(intent);
Expand Down
4 changes: 2 additions & 2 deletions WeTongji/src/com/wetongji/data/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ public void setSinaWeibo(String sinaWeibo) {



String getNO() {
public String getNO() {
return NO;
}



void setNO(String nO) {
public void setNO(String nO) {
NO = nO;
}

Expand Down
6 changes: 3 additions & 3 deletions WeTongji/src/com/wetongji/net/WTClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void login(String name, String password) throws Exception
params.put("Password", password);
this.executeRequest();

this.userService();
//this.userService();
}

//修改用户密码
Expand Down Expand Up @@ -471,11 +471,11 @@ public void setCurrentUserIdRequired(boolean currentUserIdRequired)
{
this.currentUserIdRequired = currentUserIdRequired;
}
private String getResponseStr()
public String getResponseStr()
{
return responseStr;
}
private void setResponseStr(String responseStr)
public void setResponseStr(String responseStr)
{
this.responseStr = responseStr;
}
Expand Down

0 comments on commit bc40790

Please sign in to comment.