public class ChatActivity extends android.support.v7.app.AppCompatActivity implements MessageAdapter.ChatMessageClickListener, com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener
Modifier and Type | Class and Description |
---|---|
private class |
ChatActivity.UiCallback
Manages the callbacks for the upload of a photo
|
Modifier and Type | Field and Description |
---|---|
private ChatActivity |
ca |
private EditText |
chatEditText |
private java.io.File |
chosenFile |
static int |
FILE_PICK |
private java.util.Locale |
format |
private boolean |
isScrolled |
private android.support.v7.widget.RecyclerView.LayoutManager |
layoutManager |
private MessageAdapter |
messageAdapter |
private BroadcastReceiver |
messageReceiver
Receives the notification from the ChatService that some message has been sent, so it updates the view
|
private Menu |
mMenu |
private BroadcastReceiver |
mMessageReceiver
Receiver for the event of deletion of the square that shows an appropriate alert
and prevents the user from sending other messages.
|
private InSquareProfile |
mProfile
The InSquareProfile of the current user
|
private com.github.nkzawa.socketio.client.Socket |
mSocket |
private Square |
mSquare |
private java.lang.String |
mSquareId |
private java.lang.String |
mSquareName |
private com.google.android.gms.analytics.Tracker |
mTracker |
private java.lang.String |
mUserId |
private java.lang.String |
mUsername |
private com.github.nkzawa.emitter.Emitter.Listener |
onConnectError
Notifies if the connection to the socket has failed
|
private com.github.nkzawa.emitter.Emitter.Listener |
onNewMessage
Receives the event from socket for a new message to display and it displays it
|
private com.github.nkzawa.emitter.Emitter.Listener |
onPing
Receives an event from socket to keep the connection alive(to not let it timeout)
|
private com.github.nkzawa.emitter.Emitter.Listener |
onSendMessage
Receives the event from socket for a new message sent and it displays it
|
private java.util.HashMap<java.lang.String,java.util.ArrayList<Message>> |
outgoingMessages |
private java.util.LinkedList<java.lang.Integer> |
positions |
static int |
RECENT_MESSAGES_NUM |
private android.support.v7.widget.RecyclerView |
recyclerView |
private static int |
REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS |
private ImageButton |
sendButton |
private static java.lang.String |
TAG |
private android.support.v7.widget.Toolbar |
toolbar |
private ImageView |
toolbarCircle |
private int |
toolbarCircleColor |
private TextView |
toolbarCircleInitials |
private java.lang.String |
toolbarInitials |
private TextView |
toolbarName |
private static long |
TYPING_TIMER_LENGTH |
private Upload |
upload |
Constructor and Description |
---|
ChatActivity() |
Modifier and Type | Method and Description |
---|---|
private void |
addMessage(Message m)
Adds a message to the view
|
private boolean |
addPermission(java.util.List<java.lang.String> permissionsList,
java.lang.String permission) |
private void |
attemptSend()
Attempts to send a message through ChatService, if the message is valid
|
private void |
attemptSendFoto(java.lang.String fotoURL)
Attempts to send a message through ChatService, if the message is valid
|
private void |
chooseFileIntent()
Opens a dialog to let the user choose the image to send
|
private void |
clearInput() |
private void |
createUpload(java.io.File image)
Creates an Upload object out of a File one
|
void |
favouriteSquare(int method,
Square square)
Creates a Volley request to put/remove a square in/from the favourite squares list, then calls updateList
|
private void |
getRecentMessages(int quantity)
Creates a Volley request to download the messages present in a particular square, then it adds the results to the
view
|
private void |
insertPhotoWrapper()
Checks if the app has permissions.
|
protected void |
onActivityResult(int requestCode,
int resultCode,
Intent data)
If the user has correctly chosen an image, calls uploadImage() to upload it
|
void |
onConnectionFailed(com.google.android.gms.common.ConnectionResult connectionResult) |
protected void |
onCreate(Bundle savedInstanceState)
Initializes the socket.io components, downloads the messages present in the chat, tries to send messages in the outgoing list and eventually puts to zero the
notification counter for this chat
|
boolean |
onCreateOptionsMenu(Menu menu) |
protected void |
onDestroy() |
void |
onItemClick(int position,
View v) |
boolean |
onOptionsItemSelected(MenuItem item)
Manages the option menu items
|
protected void |
onPause()
Turns off the connection to socket
|
void |
onRequestPermissionsResult(int requestCode,
java.lang.String[] permissions,
int[] grantResults) |
protected void |
onResume() |
protected void |
onStart()
Initializes some values and emits an event so the server knows the user is connected to the chat
|
protected void |
onStop() |
private void |
setupToolbar()
Sets up the toolbar for the ChatActivity
|
private void |
showMessageOKCancel(java.lang.String message,
DialogInterface.OnClickListener okListener)
Shows a certain message on the screen with an OK and a Cancel buttons.
|
void |
uploadImage()
Uploads the image on Imgur
|
addContentView, dispatchKeyEvent, findViewById, getDelegate, getDrawerToggleDelegate, getMenuInflater, getSupportActionBar, getSupportParentActivityIntent, invalidateOptionsMenu, onConfigurationChanged, onContentChanged, onCreateSupportNavigateUpTaskStack, onMenuItemSelected, onMenuOpened, onPanelClosed, onPostCreate, onPostResume, onPrepareSupportNavigateUpTaskStack, onSaveInstanceState, onSupportActionModeFinished, onSupportActionModeStarted, onSupportContentChanged, onSupportNavigateUp, onTitleChanged, onWindowStartingSupportActionMode, setContentView, setContentView, setContentView, setSupportActionBar, setSupportProgress, setSupportProgressBarIndeterminate, setSupportProgressBarIndeterminateVisibility, setSupportProgressBarVisibility, setTheme, startSupportActionMode, supportInvalidateOptionsMenu, supportNavigateUpTo, supportRequestWindowFeature, supportShouldUpRecreateTask
dump, getLastCustomNonConfigurationInstance, getSupportFragmentManager, getSupportLoaderManager, getSupportMediaController, onAttachFragment, onBackPressed, onCreatePanelMenu, onKeyDown, onLowMemory, onNewIntent, onPrepareOptionsPanel, onPreparePanel, onResumeFragments, onRetainCustomNonConfigurationInstance, onRetainNonConfigurationInstance, onStateNotSaved, setEnterSharedElementCallback, setExitSharedElementCallback, setSupportMediaController, startActivityForResult, startActivityFromFragment, startActivityFromFragment, supportFinishAfterTransition, supportPostponeEnterTransition, supportStartPostponedEnterTransition, validateRequestPermissionsRequestCode
private static final java.lang.String TAG
private static final long TYPING_TIMER_LENGTH
public static final int RECENT_MESSAGES_NUM
private android.support.v7.widget.RecyclerView recyclerView
private MessageAdapter messageAdapter
private android.support.v7.widget.RecyclerView.LayoutManager layoutManager
private EditText chatEditText
private com.github.nkzawa.socketio.client.Socket mSocket
private InSquareProfile mProfile
InSquareProfile
private Menu mMenu
private Square mSquare
private java.lang.String mSquareId
private java.lang.String mSquareName
private java.lang.String mUsername
private java.lang.String mUserId
private android.support.v7.widget.Toolbar toolbar
private TextView toolbarName
private TextView toolbarCircleInitials
private ImageView toolbarCircle
private int toolbarCircleColor
private java.lang.String toolbarInitials
private boolean isScrolled
private com.google.android.gms.analytics.Tracker mTracker
private java.util.Locale format
private java.util.HashMap<java.lang.String,java.util.ArrayList<Message>> outgoingMessages
private Upload upload
private java.io.File chosenFile
private ChatActivity ca
public static final int FILE_PICK
private java.util.LinkedList<java.lang.Integer> positions
private static final int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS
private BroadcastReceiver messageReceiver
ChatService
private ImageButton sendButton
private BroadcastReceiver mMessageReceiver
private com.github.nkzawa.emitter.Emitter.Listener onConnectError
private com.github.nkzawa.emitter.Emitter.Listener onNewMessage
addMessage(Message)
private com.github.nkzawa.emitter.Emitter.Listener onSendMessage
addMessage(Message)
private com.github.nkzawa.emitter.Emitter.Listener onPing
protected void onCreate(Bundle savedInstanceState)
onCreate
in class android.support.v7.app.AppCompatActivity
savedInstanceState
- private void setupToolbar()
private void insertPhotoWrapper()
private void chooseFileIntent()
private void showMessageOKCancel(java.lang.String message, DialogInterface.OnClickListener okListener)
message
- the message to showokListener
- the listener for the OK buttonprotected void onActivityResult(int requestCode, int resultCode, Intent data)
onActivityResult
in class android.support.v4.app.FragmentActivity
uploadImage()
private boolean addPermission(java.util.List<java.lang.String> permissionsList, java.lang.String permission)
public void onRequestPermissionsResult(int requestCode, java.lang.String[] permissions, int[] grantResults)
onRequestPermissionsResult
in interface android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback
onRequestPermissionsResult
in class android.support.v4.app.FragmentActivity
private void getRecentMessages(int quantity)
quantity
- protected void onStart()
onStart
in class android.support.v4.app.FragmentActivity
protected void onResume()
onResume
in class android.support.v4.app.FragmentActivity
protected void onPause()
onPause
in class android.support.v4.app.FragmentActivity
protected void onStop()
onStop
in class android.support.v7.app.AppCompatActivity
protected void onDestroy()
onDestroy
in class android.support.v7.app.AppCompatActivity
private void addMessage(Message m)
m
- The message you want to addprivate void attemptSend()
ChatService
private void attemptSendFoto(java.lang.String fotoURL)
ChatService
public boolean onCreateOptionsMenu(Menu menu)
public boolean onOptionsItemSelected(MenuItem item)
item
- The item selectedfavouriteSquare(int, Square)
,
VolleyManager
public void favouriteSquare(int method, Square square)
method
- The volley method you want to use(POST to add, DELETE to removesquare
- The square you want to add/removepublic void onItemClick(int position, View v)
onItemClick
in interface MessageAdapter.ChatMessageClickListener
public void uploadImage()
createUpload(File)
,
UploadService
private void createUpload(java.io.File image)
image
- The image the user wants to uploadprivate void clearInput()
public void onConnectionFailed(com.google.android.gms.common.ConnectionResult connectionResult)
onConnectionFailed
in interface com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener