channel discovery screen code clean up
This commit is contained in:
parent
3e333eb972
commit
400cbd8eee
|
@ -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:
|
}
|
||||||
StartConversationActivity.shareAsChannel(this, room.address);
|
final int itemId = item.getItemId();
|
||||||
return true;
|
if (itemId == R.id.share_with) {
|
||||||
case R.id.open_join_dialog:
|
StartConversationActivity.shareAsChannel(this, room.address);
|
||||||
final Intent intent = new Intent(this, StartConversationActivity.class);
|
return true;
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
} else if (itemId == R.id.open_join_dialog) {
|
||||||
intent.putExtra("force_dialog", true);
|
final Intent intent = new Intent(this, StartConversationActivity.class);
|
||||||
intent.setData(Uri.parse(String.format("xmpp:%s?join", room.address)));
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
startActivity(intent);
|
intent.putExtra("force_dialog", true);
|
||||||
return true;
|
intent.setData(Uri.parse(String.format("xmpp:%s?join", room.address)));
|
||||||
}
|
startActivity(intent);
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue