channel discovery screen code clean up

This commit is contained in:
Daniel Gultsch 2024-03-20 07:26:20 +01:00
parent 3e333eb972
commit 400cbd8eee
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2

View file

@ -18,6 +18,7 @@ import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import com.google.common.base.Strings; import com.google.common.base.Strings;
@ -130,7 +131,7 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
} }
@Override @Override
public boolean onMenuItemActionExpand(MenuItem item) { public boolean onMenuItemActionExpand(@NonNull MenuItem item) {
mSearchEditText.post(() -> { mSearchEditText.post(() -> {
mSearchEditText.requestFocus(); mSearchEditText.requestFocus();
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
@ -140,7 +141,7 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
} }
@Override @Override
public boolean onMenuItemActionCollapse(MenuItem item) { public boolean onMenuItemActionCollapse(@NonNull MenuItem item) {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mSearchEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); imm.hideSoftInputFromWindow(mSearchEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
mSearchEditText.setText(""); mSearchEditText.setText("");
@ -189,7 +190,7 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
} }
@Override @Override
public void onSaveInstanceState(Bundle savedInstanceState) { public void onSaveInstanceState(@NonNull Bundle savedInstanceState) {
if (mMenuSearchView != null && mMenuSearchView.isActionViewExpanded()) { if (mMenuSearchView != null && mMenuSearchView.isActionViewExpanded()) {
savedInstanceState.putString("search", mSearchEditText != null ? mSearchEditText.getText().toString() : null); savedInstanceState.putString("search", mSearchEditText != null ? mSearchEditText.getText().toString() : null);
} }
@ -248,40 +249,47 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
} }
@Override @Override
public boolean onContextItemSelected(MenuItem item) { public boolean onContextItemSelected(@NonNull MenuItem item) {
final Room room = adapter.getCurrent(); final Room room = adapter.getCurrent();
if (room != null) { if (room == null) {
switch (item.getItemId()) { return false;
case R.id.share_with: }
final int itemId = item.getItemId();
if (itemId == R.id.share_with) {
StartConversationActivity.shareAsChannel(this, room.address); StartConversationActivity.shareAsChannel(this, room.address);
return true; return true;
case R.id.open_join_dialog: } else if (itemId == R.id.open_join_dialog) {
final Intent intent = new Intent(this, StartConversationActivity.class); final Intent intent = new Intent(this, StartConversationActivity.class);
intent.setAction(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW);
intent.putExtra("force_dialog", true); intent.putExtra("force_dialog", true);
intent.setData(Uri.parse(String.format("xmpp:%s?join", room.address))); intent.setData(Uri.parse(String.format("xmpp:%s?join", room.address)));
startActivity(intent); startActivity(intent);
return true; return true;
} } else {
}
return false; return false;
} }
}
public void joinChannelSearchResult(String selectedAccount, Room result) { public void joinChannelSearchResult(final String selectedAccount, final Room result) {
final Jid jid = Config.DOMAIN_LOCK == null ? Jid.ofEscaped(selectedAccount) : Jid.ofLocalAndDomainEscaped(selectedAccount, Config.DOMAIN_LOCK); final Jid jid =
Config.DOMAIN_LOCK == null
? Jid.ofEscaped(selectedAccount)
: Jid.ofLocalAndDomainEscaped(selectedAccount, Config.DOMAIN_LOCK);
final boolean syncAutoJoin = getBooleanPreference("autojoin", R.bool.autojoin); final boolean syncAutoJoin = getBooleanPreference("autojoin", R.bool.autojoin);
final Account account = xmppConnectionService.findAccountByJid(jid); final Account account = xmppConnectionService.findAccountByJid(jid);
final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, result.getRoom(), true, true, true); final Conversation conversation =
Bookmark bookmark = conversation.getBookmark(); xmppConnectionService.findOrCreateConversation(
if (bookmark != null) { account, result.getRoom(), true, true, true);
if (!bookmark.autojoin() && syncAutoJoin) { final var existingBookmark = conversation.getBookmark();
bookmark.setAutojoin(true); if (existingBookmark == null) {
xmppConnectionService.createBookmark(account, bookmark); final var bookmark = new Bookmark(account, conversation.getJid().asBareJid());
}
} else {
bookmark = new Bookmark(account, conversation.getJid().asBareJid());
bookmark.setAutojoin(syncAutoJoin); bookmark.setAutojoin(syncAutoJoin);
xmppConnectionService.createBookmark(account, bookmark); xmppConnectionService.createBookmark(account, bookmark);
} else {
if (!existingBookmark.autojoin() && syncAutoJoin) {
existingBookmark.setAutojoin(true);
xmppConnectionService.createBookmark(account, existingBookmark);
}
} }
switchToConversation(conversation); switchToConversation(conversation);
} }