mirror of
https://codeberg.org/Mercury-IM/Mercury-IM
synced 2024-11-15 20:22:05 +01:00
Add 'not yet implemented' warnings and implement message search in chat
This commit is contained in:
parent
de39e356f0
commit
1468ad4dfa
8 changed files with 104 additions and 7 deletions
|
@ -3,9 +3,12 @@ package org.mercury_im.messenger.ui.chat;
|
|||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
@ -25,7 +28,8 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
public class ChatActivity extends AppCompatActivity implements ChatInputFragment.OnChatInputActionListener {
|
||||
public class ChatActivity extends AppCompatActivity
|
||||
implements ChatInputFragment.OnChatInputActionListener, SearchView.OnQueryTextListener {
|
||||
|
||||
public static final String EXTRA_JID = "JID";
|
||||
public static final String EXTRA_ACCOUNT = "ACCOUNT";
|
||||
|
@ -98,9 +102,27 @@ public class ChatActivity extends AppCompatActivity implements ChatInputFragment
|
|||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_chat, menu);
|
||||
|
||||
final MenuItem searchItem = menu.findItem(R.id.action_search);
|
||||
final SearchView searchView = (SearchView) searchItem.getActionView();
|
||||
searchView.setOnQueryTextListener(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_call:
|
||||
case R.id.action_clear_history:
|
||||
case R.id.action_mute:
|
||||
case R.id.action_delete_chat:
|
||||
Toast.makeText(this, R.string.not_yet_implemented, Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
outState.putString(EXTRA_JID, jid.toString());
|
||||
|
@ -109,8 +131,13 @@ public class ChatActivity extends AppCompatActivity implements ChatInputFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onButtonMediaClicked() {
|
||||
public void onButtonEmojiClicked() {
|
||||
Toast.makeText(this, R.string.not_yet_implemented, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onButtonMediaClicked() {
|
||||
Toast.makeText(this, R.string.not_yet_implemented, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -140,4 +167,16 @@ public class ChatActivity extends AppCompatActivity implements ChatInputFragment
|
|||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
// Ignore. Logic is in onQueryTextChange.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String query) {
|
||||
chatViewModel.queryTextChanged(query);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ public class ChatInputFragment extends Fragment implements View.OnClickListener
|
|||
}
|
||||
|
||||
@Override
|
||||
@OnClick({R.id.btn_send, R.id.btn_media})
|
||||
@OnClick({R.id.btn_send, R.id.btn_media, R.id.btn_emoji})
|
||||
public void onClick(View view) {
|
||||
Log.d(TAG, "onClick!");
|
||||
switch (view.getId()) {
|
||||
|
@ -106,7 +106,6 @@ public class ChatInputFragment extends Fragment implements View.OnClickListener
|
|||
if (actionListener != null) {
|
||||
actionListener.onButtonMediaClicked();
|
||||
}
|
||||
Toast.makeText(getContext(), R.string.not_yet_implemented, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
|
||||
// Send message
|
||||
|
@ -118,7 +117,9 @@ public class ChatInputFragment extends Fragment implements View.OnClickListener
|
|||
break;
|
||||
|
||||
case R.id.btn_emoji:
|
||||
Toast.makeText(getContext(), "Not yet implemented!", Toast.LENGTH_SHORT).show();
|
||||
if (actionListener != null) {
|
||||
actionListener.onButtonEmojiClicked();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -127,6 +128,8 @@ public class ChatInputFragment extends Fragment implements View.OnClickListener
|
|||
|
||||
void onButtonMediaClicked();
|
||||
|
||||
void onButtonEmojiClicked();
|
||||
|
||||
void onComposingBodyChanged(String body);
|
||||
|
||||
void onComposingBodySend(String body);
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.util.List;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
|
@ -30,6 +31,9 @@ public class ChatViewModel extends ViewModel {
|
|||
@Inject
|
||||
RosterRepository rosterRepository;
|
||||
|
||||
private long accountId;
|
||||
private EntityBareJid jid;
|
||||
|
||||
private MutableLiveData<ContactModel> contact = new MutableLiveData<>();
|
||||
private MutableLiveData<List<MessageModel>> messages = new MutableLiveData<>();
|
||||
private MutableLiveData<String> contactDisplayName = new MutableLiveData<>();
|
||||
|
@ -40,6 +44,9 @@ public class ChatViewModel extends ViewModel {
|
|||
}
|
||||
|
||||
public void init(long accountId, EntityBareJid jid) {
|
||||
this.accountId = accountId;
|
||||
this.jid = jid;
|
||||
|
||||
disposable.add(rosterRepository.getContact(accountId, jid)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -78,4 +85,20 @@ public class ChatViewModel extends ViewModel {
|
|||
public LiveData<String> getContactDisplayName() {
|
||||
return contactDisplayName;
|
||||
}
|
||||
|
||||
public void queryTextChanged(String query) {
|
||||
if (query.isEmpty()) {
|
||||
disposable.add(messageRepository.getAllMessagesOfChat(accountId, jid)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe((Consumer<List<MessageModel>>)
|
||||
messages -> ChatViewModel.this.messages.setValue(messages)));
|
||||
}
|
||||
disposable.add(messageRepository.findMessageByQuery(accountId, jid, query)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe((Consumer<List<MessageModel>>) o -> {
|
||||
messages.setValue(o);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
android:layout_marginBottom="8dp"
|
||||
android:background="@null"
|
||||
android:tint="@color/tint_compose"
|
||||
android:contentDescription="@string/description_add_emoji"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:srcCompat="@drawable/ic_insert_emoticon_white_24dp" />
|
||||
|
@ -40,7 +41,7 @@
|
|||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:background="@null"
|
||||
android:hint="Type your message"
|
||||
android:hint="@string/hint_type_your_message"
|
||||
android:inputType="textMultiLine|textAutoCorrect|textCapSentences"
|
||||
android:maxLines="6"
|
||||
android:padding="8dp"
|
||||
|
@ -57,6 +58,7 @@
|
|||
android:layout_marginBottom="8dp"
|
||||
android:background="@null"
|
||||
android:tint="@color/tint_compose"
|
||||
android:contentDescription="@string/description_add_attachment"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:srcCompat="@drawable/ic_attach_file_white_24dp" />
|
||||
|
@ -73,6 +75,7 @@
|
|||
android:background="@drawable/circle"
|
||||
android:elevation="15dp"
|
||||
android:tint="@color/tint_compose"
|
||||
android:contentDescription="@string/description_send_message"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:srcCompat="@drawable/ic_send_black_24dp" />
|
||||
|
|
|
@ -105,5 +105,9 @@
|
|||
<string name="action_delete_history">Delete History</string>
|
||||
<string name="action_mute">Mute</string>
|
||||
<string name="action_delete_chat">Delete Chat</string>
|
||||
<string name="hint_type_your_message">Type your message</string>
|
||||
<string name="description_add_emoji">Add emoji</string>
|
||||
<string name="description_add_attachment">Add attachment</string>
|
||||
<string name="description_send_message">Send Message</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -25,4 +25,15 @@ public interface MessageDao extends BaseDao<RoomMessageModel> {
|
|||
@Query("SELECT * FROM messages WHERE fk_account_id = :accountId AND (`from` = :peer OR `to` = :peer) ORDER BY send_date ASC")
|
||||
Observable<List<RoomMessageModel>> getAllMessagesInConversation(long accountId, EntityBareJid peer);
|
||||
|
||||
@Query("SELECT * FROM messages WHERE body LIKE :query COLLATE utf8_general_ci")
|
||||
Observable<List<RoomMessageModel>> findMessageByQuery(String query);
|
||||
|
||||
@Query("SELECT * FROM messages WHERE fk_account_id = :accountId AND body LIKE :query COLLATE utf8_general_ci")
|
||||
Observable<List<RoomMessageModel>> findMessageByQuery(long accountId, String query);
|
||||
|
||||
@Query("SELECT * FROM messages " +
|
||||
"WHERE fk_account_id = :accountId " +
|
||||
"AND (`from` = :peer OR `to` = :peer) " +
|
||||
"AND body LIKE :query COLLATE utf8_general_ci")
|
||||
Observable<List<RoomMessageModel>> findMessageByQuery(long accountId, EntityBareJid peer, String query);
|
||||
}
|
||||
|
|
|
@ -54,6 +54,16 @@ public class IMessageRepository implements MessageRepository<RoomMessageModel> {
|
|||
|
||||
@Override
|
||||
public Observable<List<RoomMessageModel>> findMessageByQuery(String query) {
|
||||
return null;
|
||||
return messageDao.findMessageByQuery("%" + query + "%");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<RoomMessageModel>> findMessageByQuery(long accountId, String query) {
|
||||
return messageDao.findMessageByQuery(accountId, "%" + query + "%");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<RoomMessageModel>> findMessageByQuery(long accountId, EntityBareJid peer, String query) {
|
||||
return messageDao.findMessageByQuery(accountId, peer, "%" + query + "%");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,4 +24,8 @@ public interface MessageRepository<E extends MessageModel> {
|
|||
Observable<List<E>> getAllMessagesFrom(long accountId, EntityBareJid contact);
|
||||
|
||||
Observable<List<E>> findMessageByQuery(String query);
|
||||
|
||||
Observable<List<E>> findMessageByQuery(long accountId, String query);
|
||||
|
||||
Observable<List<E>> findMessageByQuery(long accountId, EntityBareJid peer, String query);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue