DT @22.10.2015: Top10 Profile Function implemented
This commit is contained in:
@@ -1,9 +1,13 @@
|
|||||||
package org.deke.risk.riskahead;
|
package org.deke.risk.riskahead;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.widget.TableLayout;
|
||||||
|
import android.widget.TableRow;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -15,6 +19,7 @@ import com.android.volley.toolbox.StringRequest;
|
|||||||
import org.deke.risk.riskahead.helper.AppConfig;
|
import org.deke.risk.riskahead.helper.AppConfig;
|
||||||
import org.deke.risk.riskahead.helper.AppController;
|
import org.deke.risk.riskahead.helper.AppController;
|
||||||
import org.deke.risk.riskahead.helper.BaseActivity;
|
import org.deke.risk.riskahead.helper.BaseActivity;
|
||||||
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@@ -38,6 +43,11 @@ public class ProfileActivity extends BaseActivity {
|
|||||||
StringRequest strReq = getStringRequestProfileStats();
|
StringRequest strReq = getStringRequestProfileStats();
|
||||||
String tag_string_req = "req_profilestats";
|
String tag_string_req = "req_profilestats";
|
||||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||||
|
|
||||||
|
StringRequest strReq2 = getStringRequestTop10();
|
||||||
|
String tag_string_req2 = "req_top10";
|
||||||
|
AppController.getInstance().addToRequestQueue(strReq2, tag_string_req2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -113,4 +123,78 @@ public class ProfileActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private StringRequest getStringRequestTop10() {
|
||||||
|
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(String response) {
|
||||||
|
Log.d(TAG, "Top 10 stats: " + response);
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONObject jObj = new JSONObject(response);
|
||||||
|
boolean error = jObj.getBoolean("error");
|
||||||
|
if (!error) {
|
||||||
|
TableLayout tbltop10 = (TableLayout) findViewById(R.id.tableTop10);
|
||||||
|
JSONArray listitems = jObj.getJSONArray("msg");
|
||||||
|
for(int i=0;i<listitems.length();i++){
|
||||||
|
JSONObject listitem = listitems.getJSONObject(i);
|
||||||
|
|
||||||
|
TableRow row = new TableRow(getApplication());
|
||||||
|
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
|
||||||
|
lp.setMargins(3,3,3,3);
|
||||||
|
row.setLayoutParams(lp);
|
||||||
|
|
||||||
|
TextView rank = new TextView(getApplication());
|
||||||
|
rank.setText(listitem.getString("rank"));
|
||||||
|
rank.setTextColor(Color.BLACK);
|
||||||
|
|
||||||
|
TextView username = new TextView(getApplication());
|
||||||
|
username.setText(listitem.getString("username"));
|
||||||
|
username.setTextColor(Color.BLACK);
|
||||||
|
|
||||||
|
TextView points = new TextView(getApplication());
|
||||||
|
points.setText(listitem.getString("points"));
|
||||||
|
points.setTextColor(Color.BLACK);
|
||||||
|
|
||||||
|
row.addView(rank);
|
||||||
|
row.addView(username);
|
||||||
|
row.addView(points);
|
||||||
|
|
||||||
|
tbltop10.addView(row,i+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} 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 top 10 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", "gettop10");
|
||||||
|
params.put("uid", user.get("uid"));
|
||||||
|
params.put("token", user.get("token"));
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,53 @@
|
|||||||
android:layout_below="@+id/tableLayout"
|
android:layout_below="@+id/tableLayout"
|
||||||
android:layout_marginTop="31dp" />
|
android:layout_marginTop="31dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/lbl_profile_top10"
|
||||||
|
android:text="@string/lbl_profile_top10"
|
||||||
|
android:layout_below="@+id/btn_profile_viewposts"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:textColor="#000000"/>
|
||||||
|
|
||||||
|
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/lbl_profile_top10"
|
||||||
|
android:stretchColumns="1"
|
||||||
|
android:id="@+id/tableTop10">
|
||||||
|
|
||||||
|
<TableRow>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/lbl_ranking"
|
||||||
|
android:text="Ranking"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:padding="3dip"
|
||||||
|
android:textColor="#007197"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txt_name"
|
||||||
|
android:text="Name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:padding="3dip"
|
||||||
|
android:textColor="#007197"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txt_points"
|
||||||
|
android:text="Points"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:padding="3dip"
|
||||||
|
android:textColor="#007197"/>
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
</TableLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
|
|||||||
@@ -77,6 +77,7 @@
|
|||||||
<string name="lbl_profile_ranking">ranking</string>
|
<string name="lbl_profile_ranking">ranking</string>
|
||||||
<string name="lbl_profile_numberposts">number of posts</string>
|
<string name="lbl_profile_numberposts">number of posts</string>
|
||||||
<string name="btn_profile_viewposts">{fa_search} View posts</string>
|
<string name="btn_profile_viewposts">{fa_search} View posts</string>
|
||||||
|
<string name="lbl_profile_top10">Top10</string>
|
||||||
|
|
||||||
<string name="lbl_settings_password">Confirm Password</string>
|
<string name="lbl_settings_password">Confirm Password</string>
|
||||||
<string name="btn_settings_req_password">{fa_paint_brush} Change password</string>
|
<string name="btn_settings_req_password">{fa_paint_brush} Change password</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user