DT @12.10.2015: Profile function implemented
This commit is contained in:
@@ -88,7 +88,7 @@ public class MainActivity extends BaseActivity{
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
StringRequest strReq = getStringRequestIncidentCount(user.get("uid"),user.get("token"));
|
||||
StringRequest strReq = getStringRequestIncidentCount();
|
||||
String tag_string_req = "req_incidents";
|
||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||
mHandler.postDelayed(mHandlerTask, INTERVAL);
|
||||
@@ -105,7 +105,7 @@ public class MainActivity extends BaseActivity{
|
||||
mHandler.removeCallbacks(mHandlerTask);
|
||||
}
|
||||
|
||||
private StringRequest getStringRequestIncidentCount(final String uid, final String token) {
|
||||
private StringRequest getStringRequestIncidentCount() {
|
||||
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||
|
||||
@Override
|
||||
@@ -144,8 +144,8 @@ public class MainActivity extends BaseActivity{
|
||||
// Posting params to register url
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("tag", "getincidentcount");
|
||||
params.put("uid", uid);
|
||||
params.put("token", token);
|
||||
params.put("uid", user.get("uid"));
|
||||
params.put("token", user.get("token"));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,25 @@
|
||||
package org.deke.risk.riskahead;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.toolbox.StringRequest;
|
||||
|
||||
import org.deke.risk.riskahead.helper.AppConfig;
|
||||
import org.deke.risk.riskahead.helper.AppController;
|
||||
import org.deke.risk.riskahead.helper.BaseActivity;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProfileActivity extends BaseActivity {
|
||||
|
||||
@@ -20,6 +34,10 @@ public class ProfileActivity extends BaseActivity {
|
||||
|
||||
txtMemberSince = (TextView) findViewById(R.id.txt_profile_membersince);
|
||||
txtMemberSince.setText(user.get("created_at"));
|
||||
|
||||
StringRequest strReq = getStringRequestProfileStats();
|
||||
String tag_string_req = "req_profilestats";
|
||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,4 +62,55 @@ public class ProfileActivity extends BaseActivity {
|
||||
protected String getActivityName() {
|
||||
return mActivityTitle;
|
||||
}
|
||||
|
||||
private StringRequest getStringRequestProfileStats() {
|
||||
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
Log.d(TAG, "User stats: " + response);
|
||||
|
||||
try {
|
||||
JSONObject jObj = new JSONObject(response);
|
||||
boolean error = jObj.getBoolean("error");
|
||||
if (!error) {
|
||||
TextView points = (TextView) findViewById(R.id.txt_profile_points);
|
||||
TextView ranking = (TextView) findViewById(R.id.txt_profile_ranking);
|
||||
TextView posts = (TextView) findViewById(R.id.txt_profile_numberposts);
|
||||
|
||||
points.setText(jObj.getString("points"));
|
||||
ranking.setText(jObj.getString("rank"));
|
||||
posts.setText(jObj.getString("posts"));
|
||||
} else {
|
||||
String errorMsg = jObj.getString("error_msg");
|
||||
Toast.makeText(getApplicationContext(),
|
||||
errorMsg, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Log.e(TAG, "Error getting user stats: " + error.getMessage());
|
||||
Toast.makeText(getApplicationContext(),
|
||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}) {
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getParams() {
|
||||
// Posting params to register url
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("tag", "getuserstats");
|
||||
params.put("uid", user.get("uid"));
|
||||
params.put("token", user.get("token"));
|
||||
|
||||
return params;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user