mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-30 09:16:36 +00:00
Update APIRequestParameters
This commit is contained in:
parent
5ab8575c40
commit
59e8240ad8
@ -120,8 +120,8 @@ public class APIRequest {
|
||||
* @param params The request parametres to update
|
||||
*/
|
||||
private void addAPItokens(APIRequestParameters params){
|
||||
params.addParameter("serviceName", BuildConfig.api_service_name);
|
||||
params.addParameter("serviceToken", BuildConfig.api_service_token);
|
||||
params.addString("serviceName", BuildConfig.api_service_name);
|
||||
params.addString("serviceToken", BuildConfig.api_service_token);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,8 +145,8 @@ public class APIRequest {
|
||||
return; //Not enough tokens
|
||||
|
||||
//Add them to the request
|
||||
params.addParameter("userToken1", tokens.get(0));
|
||||
params.addParameter("userToken2", tokens.get(1));
|
||||
params.addString("userToken1", tokens.get(0));
|
||||
params.addString("userToken2", tokens.get(1));
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,6 @@ package org.communiquons.android.comunic.client.api;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.communiquons.android.comunic.client.api.APIPostData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@ -54,7 +52,7 @@ public class APIRequestParameters {
|
||||
* @param name The name of the new key
|
||||
* @param value The value of the new key
|
||||
*/
|
||||
public void addParameter(String name, String value){
|
||||
public void addString(String name, String value){
|
||||
parameters.add(new APIPostData(name, value));
|
||||
}
|
||||
|
||||
@ -64,8 +62,8 @@ public class APIRequestParameters {
|
||||
* @param name The name of the new key
|
||||
* @param value The value of the new key (int)
|
||||
*/
|
||||
public void addParameter(String name, int value){
|
||||
this.addParameter(name, ""+value);
|
||||
public void addInt(String name, int value){
|
||||
this.addString(name, ""+value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,8 +72,8 @@ public class APIRequestParameters {
|
||||
* @param name The name of the new key
|
||||
* @param value The value of the new key (boolean)
|
||||
*/
|
||||
public void addParameter(String name, boolean value){
|
||||
this.addParameter(name, value ? "true" : "false");
|
||||
public void addBoolean(String name, boolean value){
|
||||
this.addString(name, value ? "true" : "false");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,7 +120,7 @@ public class GetUsersHelper {
|
||||
//Perform an API request
|
||||
APIRequestParameters params = new APIRequestParameters(mContext,
|
||||
"user/getAdvancedUserInfos");
|
||||
params.addParameter("userID", userID);
|
||||
params.addInt("userID", userID);
|
||||
|
||||
//Perform the request
|
||||
try {
|
||||
@ -237,8 +237,8 @@ public class GetUsersHelper {
|
||||
|
||||
//Make an API request
|
||||
APIRequestParameters params = new APIRequestParameters(mContext, "search/user");
|
||||
params.addParameter("query", query);
|
||||
params.addParameter("searchLimit", ""+limit);
|
||||
params.addString("query", query);
|
||||
params.addString("searchLimit", ""+limit);
|
||||
|
||||
try {
|
||||
|
||||
@ -281,7 +281,7 @@ public class GetUsersHelper {
|
||||
for(int id : IDs) {
|
||||
id_string += id + ",";
|
||||
}
|
||||
requestParameters.addParameter("usersID", id_string);
|
||||
requestParameters.addString("usersID", id_string);
|
||||
|
||||
|
||||
try {
|
||||
|
@ -91,12 +91,12 @@ public class ConversationMessagesHelper {
|
||||
//Make an API request
|
||||
APIRequestParameters params = new APIRequestParameters(mContext,
|
||||
"conversations/sendMessage");
|
||||
params.addParameter("conversationID", ""+convID);
|
||||
params.addParameter("message", message);
|
||||
params.addString("conversationID", ""+convID);
|
||||
params.addString("message", message);
|
||||
|
||||
//Include image (if any)
|
||||
if(image != null)
|
||||
params.addParameter("image", "data:image/png;base64," + image);
|
||||
params.addString("image", "data:image/png;base64," + image);
|
||||
|
||||
try {
|
||||
new APIRequest().exec(params);
|
||||
@ -156,8 +156,8 @@ public class ConversationMessagesHelper {
|
||||
//Prepare a request on the API
|
||||
APIRequestParameters params = new APIRequestParameters(mContext,
|
||||
"conversations/refresh_single");
|
||||
params.addParameter("conversationID", ""+conversationID);
|
||||
params.addParameter("last_message_id", ""+last_message_id);
|
||||
params.addString("conversationID", ""+conversationID);
|
||||
params.addString("last_message_id", ""+last_message_id);
|
||||
|
||||
ArrayList<ConversationMessage> list = new ArrayList<>();
|
||||
|
||||
|
@ -117,8 +117,8 @@ public class ConversationsListHelper {
|
||||
//Prepare an API request
|
||||
APIRequestParameters params = new APIRequestParameters(mContext,
|
||||
"conversations/getPrivate");
|
||||
params.addParameter("otherUser", userID);
|
||||
params.addParameter("allowCreate", allowCreate);
|
||||
params.addInt("otherUser", userID);
|
||||
params.addBoolean("allowCreate", allowCreate);
|
||||
|
||||
//Try to perform request
|
||||
try {
|
||||
@ -215,7 +215,7 @@ public class ConversationsListHelper {
|
||||
|
||||
//Delete the conversation on the API
|
||||
APIRequestParameters params = new APIRequestParameters(mContext, "conversations/delete");
|
||||
params.addParameter("conversationID", ""+convID);
|
||||
params.addString("conversationID", ""+convID);
|
||||
|
||||
try {
|
||||
new APIRequest().exec(params);
|
||||
@ -246,9 +246,9 @@ public class ConversationsListHelper {
|
||||
|
||||
//Make an API request
|
||||
APIRequestParameters params = new APIRequestParameters(mContext, "conversations/create");
|
||||
params.addParameter("name", name.equals("") ? "false" : name);
|
||||
params.addParameter("follow", follow ? "true" : "false");
|
||||
params.addParameter("users", members_str);
|
||||
params.addString("name", name.equals("") ? "false" : name);
|
||||
params.addString("follow", follow ? "true" : "false");
|
||||
params.addString("users", members_str);
|
||||
|
||||
//Perform the request
|
||||
try {
|
||||
@ -290,18 +290,18 @@ public class ConversationsListHelper {
|
||||
//Prepare a request on the database
|
||||
APIRequestParameters params = new APIRequestParameters(mContext,
|
||||
"conversations/updateSettings");
|
||||
params.addParameter("conversationID", ""+convID);
|
||||
params.addString("conversationID", ""+convID);
|
||||
|
||||
//Add the name (if any)
|
||||
if(name != null)
|
||||
params.addParameter("name", name.equals("") ? "false" : name);
|
||||
params.addString("name", name.equals("") ? "false" : name);
|
||||
|
||||
//Add the members (if any)
|
||||
if(members != null)
|
||||
params.addParameter("members", ArrayUtils.int_array_to_string(members, ","));
|
||||
params.addString("members", ArrayUtils.int_array_to_string(members, ","));
|
||||
|
||||
//Add following state
|
||||
params.addParameter("following", following ? "true" : "false");
|
||||
params.addString("following", following ? "true" : "false");
|
||||
|
||||
//Perform the request
|
||||
try {
|
||||
@ -370,7 +370,7 @@ public class ConversationsListHelper {
|
||||
//Perform an API request
|
||||
APIRequestParameters params = new APIRequestParameters(mContext,
|
||||
"conversations/getInfosOne");
|
||||
params.addParameter("conversationID", ""+convID);
|
||||
params.addString("conversationID", ""+convID);
|
||||
|
||||
try {
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class FriendsListHelper {
|
||||
|
||||
//Prepare the API request
|
||||
APIRequestParameters params = new APIRequestParameters(mContext, "friends/getList");
|
||||
params.addParameter("complete", true);
|
||||
params.addBoolean("complete", true);
|
||||
|
||||
//Prepare the result
|
||||
ArrayList<Friend> friends = new ArrayList<>();
|
||||
@ -122,7 +122,7 @@ public class FriendsListHelper {
|
||||
try {
|
||||
//Remove the friend online
|
||||
APIRequestParameters delparams = new APIRequestParameters(mContext, "friends/remove");
|
||||
delparams.addParameter("friendID", ""+friend.getId());
|
||||
delparams.addString("friendID", ""+friend.getId());
|
||||
new APIRequest().exec(delparams);
|
||||
|
||||
//Remove the friend from the local database
|
||||
@ -146,8 +146,8 @@ public class FriendsListHelper {
|
||||
//Perform a request to update the satus online
|
||||
APIRequestParameters reqParams = new APIRequestParameters(mContext,
|
||||
"friends/respondRequest");
|
||||
reqParams.addParameter("friendID", ""+friend.getId());
|
||||
reqParams.addParameter("accept", accept ? "true" : "false");
|
||||
reqParams.addInt("friendID", friend.getId());
|
||||
reqParams.addString("accept", accept ? "true" : "false");
|
||||
new APIRequest().exec(reqParams);
|
||||
|
||||
//Update the friend in the local database
|
||||
|
@ -47,7 +47,7 @@ public class PostsHelper {
|
||||
|
||||
//Perform a request on the API
|
||||
APIRequestParameters params = new APIRequestParameters(mContext, "posts/get_user");
|
||||
params.addParameter("userID", userID);
|
||||
params.addInt("userID", userID);
|
||||
|
||||
//Perform the request
|
||||
try {
|
||||
|
@ -0,0 +1,28 @@
|
||||
package org.communiquons.android.comunic.client.data.utils;
|
||||
|
||||
/**
|
||||
* Strings utilities
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
* Created by pierre on 3/12/18.
|
||||
*/
|
||||
|
||||
public class StringsUtils {
|
||||
|
||||
/**
|
||||
* Check the validity of a string to be send to the server
|
||||
*
|
||||
* @param string The string to check
|
||||
* @return Depends of the validity of the string
|
||||
*/
|
||||
public static boolean isValidForContent(String string){
|
||||
|
||||
//Check the length of the string
|
||||
if(string.length() < 5)
|
||||
return false;
|
||||
|
||||
//The string appears to be valid
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -110,8 +110,8 @@ public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
//Perform a request on the API to check user credentials and get login tokens
|
||||
APIRequestParameters params = new APIRequestParameters(this, "user/connectUSER");
|
||||
params.addParameter("userMail", ""+login_mail.getText());
|
||||
params.addParameter("userPassword", ""+login_password.getText());
|
||||
params.addString("userMail", ""+login_mail.getText());
|
||||
params.addString("userPassword", ""+login_password.getText());
|
||||
|
||||
//Create Request
|
||||
new APIRequestTask(){
|
||||
|
@ -1,18 +1,22 @@
|
||||
package org.communiquons.android.comunic.client.ui.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.data.ImageLoad.ImageLoadManager;
|
||||
@ -21,8 +25,10 @@ import org.communiquons.android.comunic.client.data.comments.Comment;
|
||||
import org.communiquons.android.comunic.client.data.posts.Post;
|
||||
import org.communiquons.android.comunic.client.data.posts.PostTypes;
|
||||
import org.communiquons.android.comunic.client.data.posts.PostsList;
|
||||
import org.communiquons.android.comunic.client.data.utils.StringsUtils;
|
||||
import org.communiquons.android.comunic.client.data.utils.UiUtils;
|
||||
import org.communiquons.android.comunic.client.data.utils.Utilities;
|
||||
import org.communiquons.android.comunic.client.ui.views.EditCommentContentView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -69,7 +75,8 @@ public class PostsAdapter extends ArrayAdapter<Post>{
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
public View getView(final int position, @Nullable View convertView,
|
||||
@NonNull ViewGroup parent) {
|
||||
|
||||
//Check if the view has to be inflated
|
||||
if(convertView == null)
|
||||
@ -167,6 +174,81 @@ public class PostsAdapter extends ArrayAdapter<Post>{
|
||||
convertView.findViewById(R.id.comments_list).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
//Update comment creation form
|
||||
View commentCreationForm = convertView.findViewById(R.id.create_comment_form);
|
||||
EditCommentContentView input_comment = convertView.findViewById(R.id.input_comment_content);
|
||||
if(comments == null){
|
||||
|
||||
//Hide comment creation form
|
||||
commentCreationForm.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
//Display comment creation form
|
||||
commentCreationForm.setVisibility(View.VISIBLE);
|
||||
|
||||
//Make sure the form is correctly set up
|
||||
if(input_comment.getPostID() != post.getId()){
|
||||
|
||||
//Reset input comment
|
||||
input_comment.setPostID(post.getId());
|
||||
input_comment.setText("");
|
||||
|
||||
//Make the send button lives
|
||||
final View finalConvertView = convertView;
|
||||
convertView.findViewById(R.id.comment_send_button)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
sendComment(position, finalConvertView);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Intend to send a new comment to the server
|
||||
*
|
||||
* @param pos The position of the post to update
|
||||
* @param container The container of the post item
|
||||
*/
|
||||
private void sendComment(int pos, View container){
|
||||
|
||||
//Get post informations
|
||||
Post post = getItem(pos);
|
||||
if(post==null)
|
||||
return;
|
||||
|
||||
//Get informations about the comment
|
||||
int postID = post.getId();
|
||||
String content = ((EditText) container.findViewById(R.id.input_comment_content)).getText()+"";
|
||||
|
||||
//Check the comment's validity
|
||||
if(!StringsUtils.isValidForContent(content)){
|
||||
Toast.makeText(getContext(), R.string.err_invalid_comment_content,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
//Submit the comment in a separate thread
|
||||
new AsyncTask<Void, Void, Pair<UserInfo, Comment>>(){
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Pair<UserInfo, Comment> doInBackground(Void... params) {
|
||||
|
||||
//Try to create the comment
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package org.communiquons.android.comunic.client.ui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
/**
|
||||
* Comments creation input view
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
* Created by pierre on 3/12/18.
|
||||
*/
|
||||
|
||||
public class EditCommentContentView extends android.support.v7.widget.AppCompatEditText {
|
||||
|
||||
/**
|
||||
* The ID of the target post
|
||||
*/
|
||||
private int postID;
|
||||
|
||||
public EditCommentContentView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public EditCommentContentView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public EditCommentContentView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ID of the related post
|
||||
*
|
||||
* @param postID The ID of the post
|
||||
*/
|
||||
public void setPostID(int postID) {
|
||||
this.postID = postID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of the related post
|
||||
*
|
||||
* @return The ID of the related post
|
||||
*/
|
||||
public int getPostID() {
|
||||
return postID;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user