Mercury-IM/app/src/main/java/org/mercury_im/messenger/ui/chat/ChatInputFragment.java

77 lines
2.6 KiB
Java

package org.mercury_im.messenger.ui.chat;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
import org.mercury_im.messenger.R;
public class ChatInputFragment extends Fragment implements View.OnClickListener {
private EditText textInput;
private FloatingActionButton addAttachement;
private ImageButton buttonSend;
private ChatInputViewModel mViewModel;
public static ChatInputFragment newInstance() {
return new ChatInputFragment();
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_chat, container, false);
textInput = view.findViewById(R.id.chat_field__text_input);
addAttachement = view.findViewById(R.id.chat_field__fab_add);
buttonSend = view.findViewById(R.id.chat_field__button_send);
addAttachement.setOnClickListener(this);
buttonSend.setOnClickListener(this);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mViewModel = ViewModelProviders.of(this).get(ChatInputViewModel.class);
// observeViewModel(mViewModel);
}
private void observeViewModel(ChatInputViewModel viewModel) {
viewModel.getDraft().observe(ChatInputFragment.this, new Observer<String>() {
@Override
public void onChanged(@Nullable String draft) {
textInput.setText(draft);
}
});
}
@Override
public void onClick(View view) {
switch (view.getId()) {
// Add media
case R.id.chat_field__fab_add:
Toast.makeText(getContext(), R.string.not_yet_implemented, Toast.LENGTH_SHORT).show();
break;
// Send message
case R.id.chat_field__button_send:
textInput.setText(null);
Toast.makeText(getContext(), "Send message clicked", Toast.LENGTH_SHORT).show();
break;
}
}
}