mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 13:59:29 +00:00
Improved a few things
This commit is contained in:
parent
8a309dd508
commit
0eed4d1f6e
@ -1,6 +1,7 @@
|
|||||||
package org.communiquons.android.comunic.client.data.helpers;
|
package org.communiquons.android.comunic.client.data.helpers;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
@ -23,7 +24,7 @@ class ConversationMessagesDbHelper {
|
|||||||
/**
|
/**
|
||||||
* Debug tag
|
* Debug tag
|
||||||
*/
|
*/
|
||||||
private static final String TAG = "ConversationMessagesDbH";
|
private static final String TAG = ConversationMessagesDbHelper.class.getSimpleName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database helper object
|
* Database helper object
|
||||||
@ -50,10 +51,10 @@ class ConversationMessagesDbHelper {
|
|||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param dbHelper Database helper
|
* @param context Application context
|
||||||
*/
|
*/
|
||||||
ConversationMessagesDbHelper(@NonNull DatabaseHelper dbHelper){
|
ConversationMessagesDbHelper(@NonNull Context context){
|
||||||
this.dbHelper = dbHelper;
|
this.dbHelper = DatabaseHelper.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,42 +23,28 @@ import java.util.ArrayList;
|
|||||||
* Created by pierre on 12/16/17.
|
* Created by pierre on 12/16/17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ConversationMessagesHelper {
|
public class ConversationMessagesHelper extends BaseHelper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug tag
|
* Debug tag
|
||||||
*/
|
*/
|
||||||
private static final String TAG = "ConversationMessagesHel";
|
private static final String TAG = ConversationMessagesHelper.class.getSimpleName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conversations messages database helper
|
* Conversations messages database helper
|
||||||
*/
|
*/
|
||||||
private ConversationMessagesDbHelper mDbHelper;
|
private ConversationMessagesDbHelper mDbHelper;
|
||||||
|
|
||||||
/**
|
|
||||||
* Context of execution of the application
|
|
||||||
*/
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of the helper
|
* Constructor of the helper
|
||||||
*
|
*
|
||||||
* @param context The context of the application
|
* @param context The context of the application
|
||||||
*/
|
*/
|
||||||
public ConversationMessagesHelper(Context context){
|
public ConversationMessagesHelper(Context context){
|
||||||
this(context.getApplicationContext(), DatabaseHelper.getInstance(context));
|
super(context);
|
||||||
}
|
mDbHelper = new ConversationMessagesDbHelper(context);
|
||||||
|
|
||||||
/**
|
|
||||||
* Public constructor of the helper
|
|
||||||
*
|
|
||||||
* @param context The context of execution of the application
|
|
||||||
* @param dbHelper Database helper associated with the context
|
|
||||||
*/
|
|
||||||
public ConversationMessagesHelper(Context context, DatabaseHelper dbHelper){
|
|
||||||
mContext = context;
|
|
||||||
mDbHelper = new ConversationMessagesDbHelper(dbHelper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the latest messages of a conversation
|
* Get the latest messages of a conversation
|
||||||
@ -98,7 +84,7 @@ public class ConversationMessagesHelper {
|
|||||||
public boolean sendMessage(NewConversationMessage message){
|
public boolean sendMessage(NewConversationMessage message){
|
||||||
|
|
||||||
//Make an API request
|
//Make an API request
|
||||||
APIFileRequest params = new APIFileRequest(mContext,
|
APIFileRequest params = new APIFileRequest(getContext(),
|
||||||
"conversations/sendMessage");
|
"conversations/sendMessage");
|
||||||
params.addInt("conversationID", message.getConversationID());
|
params.addInt("conversationID", message.getConversationID());
|
||||||
params.addString("message", message.getMessage());
|
params.addString("message", message.getMessage());
|
||||||
@ -209,7 +195,7 @@ public class ConversationMessagesHelper {
|
|||||||
private ArrayList<ConversationMessage> downloadNew(int conversationID, int last_message_id){
|
private ArrayList<ConversationMessage> downloadNew(int conversationID, int last_message_id){
|
||||||
|
|
||||||
//Prepare a request on the API
|
//Prepare a request on the API
|
||||||
APIRequest params = new APIRequest(mContext,
|
APIRequest params = new APIRequest(getContext(),
|
||||||
"conversations/refresh_single");
|
"conversations/refresh_single");
|
||||||
params.addString("conversationID", ""+conversationID);
|
params.addString("conversationID", ""+conversationID);
|
||||||
params.addString("last_message_id", ""+last_message_id);
|
params.addString("last_message_id", ""+last_message_id);
|
||||||
@ -254,7 +240,7 @@ public class ConversationMessagesHelper {
|
|||||||
ArrayList<ConversationMessage> list = new ArrayList<>();
|
ArrayList<ConversationMessage> list = new ArrayList<>();
|
||||||
|
|
||||||
//Prepare a request over the server
|
//Prepare a request over the server
|
||||||
APIRequest req = new APIRequest(mContext, "conversations/get_older_messages");
|
APIRequest req = new APIRequest(getContext(), "conversations/get_older_messages");
|
||||||
req.addInt("conversationID", conversationID);
|
req.addInt("conversationID", conversationID);
|
||||||
req.addInt("oldest_message_id", oldestMessageID);
|
req.addInt("oldest_message_id", oldestMessageID);
|
||||||
req.addInt("limit", limit);
|
req.addInt("limit", limit);
|
||||||
@ -291,7 +277,7 @@ public class ConversationMessagesHelper {
|
|||||||
public boolean updateMessage(ConversationMessage message){
|
public boolean updateMessage(ConversationMessage message){
|
||||||
|
|
||||||
//Perform the request over the API
|
//Perform the request over the API
|
||||||
APIRequest request = new APIRequest(mContext, "conversations/updateMessage");
|
APIRequest request = new APIRequest(getContext(), "conversations/updateMessage");
|
||||||
request.addInt("messageID", message.getId());
|
request.addInt("messageID", message.getId());
|
||||||
|
|
||||||
if(message.hasContent())
|
if(message.hasContent())
|
||||||
@ -317,7 +303,7 @@ public class ConversationMessagesHelper {
|
|||||||
public boolean deleteMessage(int messageID){
|
public boolean deleteMessage(int messageID){
|
||||||
|
|
||||||
//Make a request on the server
|
//Make a request on the server
|
||||||
APIRequest request = new APIRequest(mContext, "conversations/deleteMessage");
|
APIRequest request = new APIRequest(getContext(), "conversations/deleteMessage");
|
||||||
request.addInt("messageID", messageID);
|
request.addInt("messageID", messageID);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -212,7 +212,7 @@ public class ConversationFragment extends Fragment
|
|||||||
DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity());
|
DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity());
|
||||||
|
|
||||||
//Set conversation message helper
|
//Set conversation message helper
|
||||||
convMessHelper = new ConversationMessagesHelper(getActivity(), dbHelper);
|
convMessHelper = new ConversationMessagesHelper(getActivity());
|
||||||
|
|
||||||
//Set conversation list helper
|
//Set conversation list helper
|
||||||
convListHelper = new ConversationsListHelper(getActivity(), dbHelper);
|
convListHelper = new ConversationsListHelper(getActivity(), dbHelper);
|
||||||
@ -270,19 +270,11 @@ public class ConversationFragment extends Fragment
|
|||||||
userID = AccountUtils.getID(getActivity());
|
userID = AccountUtils.getID(getActivity());
|
||||||
|
|
||||||
//Initialize toolbar
|
//Initialize toolbar
|
||||||
mAppBar.addBackButton(new View.OnClickListener() {
|
mAppBar.addBackButton(v -> MainActivity.goBackward(Objects.requireNonNull(getActivity())));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
MainActivity.goBackward(getActivity());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mAppBar.addButton(R.drawable.ic_settings, new View.OnClickListener() {
|
mAppBar.addButton(R.drawable.ic_settings,
|
||||||
@Override
|
v -> ((MainActivity)Objects.requireNonNull(getActivity()))
|
||||||
public void onClick(View v) {
|
.updateConversation(conversation_id));
|
||||||
((MainActivity)getActivity()).updateConversation(conversation_id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
//Create the adapter
|
//Create the adapter
|
||||||
@ -304,41 +296,25 @@ public class ConversationFragment extends Fragment
|
|||||||
new_message_progress_bar = view.findViewById(R.id.fragment_conversation_newmessage_loading);
|
new_message_progress_bar = view.findViewById(R.id.fragment_conversation_newmessage_loading);
|
||||||
|
|
||||||
//Make send button lives
|
//Make send button lives
|
||||||
send_button.setOnClickListener(new View.OnClickListener() {
|
send_button.setOnClickListener(v -> send_message());
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
send_message();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Make message input act like send button on enter key press
|
//Make message input act like send button on enter key press
|
||||||
new_message_content.setOnKeyListener(new View.OnKeyListener() {
|
new_message_content.setOnKeyListener((v, keyCode, event) -> {
|
||||||
@Override
|
|
||||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
||||||
|
|
||||||
if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
|
|
||||||
send_message();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
|
||||||
|
send_message();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
//Make pick image button lives
|
//Make pick image button lives
|
||||||
pick_image_button.setOnClickListener(new View.OnClickListener() {
|
pick_image_button.setOnClickListener(v -> pick_image());
|
||||||
@Override
|
pick_image_button.setOnLongClickListener(v -> {
|
||||||
public void onClick(View v) {
|
confirm_remove_picked_image();
|
||||||
pick_image();
|
return true;
|
||||||
}
|
|
||||||
});
|
|
||||||
pick_image_button.setOnLongClickListener(new View.OnLongClickListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onLongClick(View v) {
|
|
||||||
confirm_remove_picked_image();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Hide new message sending wheel
|
//Hide new message sending wheel
|
||||||
@ -360,7 +336,8 @@ public class ConversationFragment extends Fragment
|
|||||||
new Thread(refreshRunnable).start();
|
new Thread(refreshRunnable).start();
|
||||||
|
|
||||||
//Update conversation title
|
//Update conversation title
|
||||||
setTitle(UiUtils.getString(getActivity(), R.string.fragment_conversation_title));
|
setTitle(UiUtils.getString(Objects
|
||||||
|
.requireNonNull(getActivity()), R.string.fragment_conversation_title));
|
||||||
MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_conversations);
|
MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_conversations);
|
||||||
|
|
||||||
|
|
||||||
@ -533,13 +510,9 @@ public class ConversationFragment extends Fragment
|
|||||||
|
|
||||||
mHasCallButton = true;
|
mHasCallButton = true;
|
||||||
|
|
||||||
mAppBar.addButton(R.drawable.ic_call, new View.OnClickListener() {
|
mAppBar.addButton(R.drawable.ic_call,
|
||||||
@Override
|
v -> ((OnOpenCallListener)Objects.requireNonNull(getActivity()))
|
||||||
public void onClick(View v) {
|
.createCallForConversation(conversation_id));
|
||||||
((OnOpenCallListener)Objects.requireNonNull(getActivity()))
|
|
||||||
.createCallForConversation(conversation_id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -563,13 +536,7 @@ public class ConversationFragment extends Fragment
|
|||||||
|
|
||||||
.setNegativeButton(R.string.conversation_message_remove_image_popup_cancel, null)
|
.setNegativeButton(R.string.conversation_message_remove_image_popup_cancel, null)
|
||||||
|
|
||||||
.setPositiveButton(R.string.conversation_message_remove_image_popup_confirm,
|
.setPositiveButton(R.string.conversation_message_remove_image_popup_confirm, (dialog, which) -> remove_picked_image())
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
remove_picked_image();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
@ -586,7 +553,8 @@ public class ConversationFragment extends Fragment
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
//Get new message bitmap
|
//Get new message bitmap
|
||||||
new_message_bitmap = BitmapUtils.IntentResultToBitmap(getActivity(), data);
|
new_message_bitmap = BitmapUtils.IntentResultToBitmap(
|
||||||
|
Objects.requireNonNull(getActivity()), data);
|
||||||
|
|
||||||
//Check for errors
|
//Check for errors
|
||||||
if(new_message_bitmap == null){
|
if(new_message_bitmap == null){
|
||||||
@ -617,8 +585,8 @@ public class ConversationFragment extends Fragment
|
|||||||
|
|
||||||
//Reset image button
|
//Reset image button
|
||||||
pick_image_button.setImageBitmap(null);
|
pick_image_button.setImageBitmap(null);
|
||||||
pick_image_button.setImageDrawable(UiUtils.getDrawable(getActivity(),
|
pick_image_button.setImageDrawable(UiUtils.getDrawable(
|
||||||
android.R.drawable.ic_menu_gallery));
|
Objects.requireNonNull(getActivity()), android.R.drawable.ic_menu_gallery));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -651,12 +619,7 @@ public class ConversationFragment extends Fragment
|
|||||||
//Send the message
|
//Send the message
|
||||||
unsetSendMessageTask();
|
unsetSendMessageTask();
|
||||||
mSendConversationMessageTask = new SendConversationMessageTask(getActivity());
|
mSendConversationMessageTask = new SendConversationMessageTask(getActivity());
|
||||||
mSendConversationMessageTask.setOnPostExecuteListener(new SafeAsyncTask.OnPostExecuteListener<Boolean>() {
|
mSendConversationMessageTask.setOnPostExecuteListener(this::send_callback);
|
||||||
@Override
|
|
||||||
public void OnPostExecute(Boolean success) {
|
|
||||||
send_callback(success);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mSendConversationMessageTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, newMessage);
|
mSendConversationMessageTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, newMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -845,13 +808,7 @@ public class ConversationFragment extends Fragment
|
|||||||
.setMessage(R.string.dialog_delete_conversation_message_message)
|
.setMessage(R.string.dialog_delete_conversation_message_message)
|
||||||
.setNegativeButton(R.string.dialog_delete_conversation_message_cancel, null)
|
.setNegativeButton(R.string.dialog_delete_conversation_message_cancel, null)
|
||||||
|
|
||||||
.setPositiveButton(R.string.dialog_delete_conversation_message_confirm,
|
.setPositiveButton(R.string.dialog_delete_conversation_message_confirm, (dialog, which) -> deleteConversationMessage(pos))
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
deleteConversationMessage(pos);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
@ -868,12 +825,9 @@ public class ConversationFragment extends Fragment
|
|||||||
.setTitle(R.string.dialog_edit_conversation_message_content_title)
|
.setTitle(R.string.dialog_edit_conversation_message_content_title)
|
||||||
.setView(view)
|
.setView(view)
|
||||||
.setNegativeButton(R.string.dialog_edit_conversation_message_content_cancel, null)
|
.setNegativeButton(R.string.dialog_edit_conversation_message_content_cancel, null)
|
||||||
.setPositiveButton(R.string.dialog_edit_conversation_message_content_update, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.dialog_edit_conversation_message_content_update,
|
||||||
@Override
|
(dialog, which) ->
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
update_conversation_message(pos, ""+input.getText())).show();
|
||||||
update_conversation_message(pos, ""+input.getText());
|
|
||||||
}
|
|
||||||
}).show();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -888,12 +842,8 @@ public class ConversationFragment extends Fragment
|
|||||||
unsetPendingDeleteTasksCallback();
|
unsetPendingDeleteTasksCallback();
|
||||||
|
|
||||||
mDeleteMessageAsyncTask = new DeleteConversationMessageTask(getActivity());
|
mDeleteMessageAsyncTask = new DeleteConversationMessageTask(getActivity());
|
||||||
mDeleteMessageAsyncTask.setOnPostExecuteListener(new SafeAsyncTask.OnPostExecuteListener<Boolean>() {
|
mDeleteMessageAsyncTask.setOnPostExecuteListener(
|
||||||
@Override
|
result -> deleteConversationMessagesCallback(pos, result));
|
||||||
public void OnPostExecute(Boolean result) {
|
|
||||||
deleteConversationMessagesCallback(pos, result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
mDeleteMessageAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
mDeleteMessageAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
||||||
@ -950,12 +900,9 @@ public class ConversationFragment extends Fragment
|
|||||||
message.setContent(content);
|
message.setContent(content);
|
||||||
|
|
||||||
mUpdateConversationMessageContentTask = new UpdateConversationMessageContentTask(getActivity());
|
mUpdateConversationMessageContentTask = new UpdateConversationMessageContentTask(getActivity());
|
||||||
mUpdateConversationMessageContentTask.setOnPostExecuteListener(new SafeAsyncTask.OnPostExecuteListener<Boolean>() {
|
mUpdateConversationMessageContentTask.setOnPostExecuteListener(success -> {
|
||||||
@Override
|
if(getActivity() != null)
|
||||||
public void OnPostExecute(Boolean aBoolean) {
|
updateConversationMessageCallback(success);
|
||||||
if(getActivity() != null)
|
|
||||||
updateConversationMessageCallback(aBoolean);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
mUpdateConversationMessageContentTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, message);
|
mUpdateConversationMessageContentTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, message);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user