aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/ui
diff options
context:
space:
mode:
authorChristian Schneppe <christian.schneppe@pix-art.de>2019-11-03 19:41:16 +0100
committerChristian Schneppe <christian.schneppe@pix-art.de>2019-11-03 19:41:16 +0100
commitad75ab3f683391c26c2a99242210747c0bf881c2 (patch)
tree03cb3f2d2eb80e5a19a72315e09da0619f322316 /src/main/java/de/pixart/messenger/ui
parent6a672b4aacfd62fcbbbe3ea031bf53c0daace132 (diff)
optionally search local muc rooms instead of jabber.network
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ChannelDiscoveryActivity.java58
-rw-r--r--src/main/java/de/pixart/messenger/ui/EditAccountActivity.java16
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java32
3 files changed, 63 insertions, 43 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ChannelDiscoveryActivity.java b/src/main/java/de/pixart/messenger/ui/ChannelDiscoveryActivity.java
index 1dee03021..77892c16e 100644
--- a/src/main/java/de/pixart/messenger/ui/ChannelDiscoveryActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ChannelDiscoveryActivity.java
@@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.Html;
import android.view.KeyEvent;
import android.view.Menu;
@@ -28,21 +29,27 @@ import de.pixart.messenger.databinding.ActivityChannelDiscoveryBinding;
import de.pixart.messenger.entities.Account;
import de.pixart.messenger.entities.Bookmark;
import de.pixart.messenger.entities.Conversation;
-import de.pixart.messenger.http.services.MuclumbusService;
+import de.pixart.messenger.entities.Room;
import de.pixart.messenger.services.ChannelDiscoveryService;
import de.pixart.messenger.ui.adapter.ChannelSearchResultAdapter;
import de.pixart.messenger.ui.util.PendingItem;
import de.pixart.messenger.ui.util.SoftKeyboardUtils;
+import de.pixart.messenger.ui.util.StyledAttributes;
import de.pixart.messenger.utils.AccountUtils;
import rocks.xmpp.addr.Jid;
public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.OnActionExpandListener, TextView.OnEditorActionListener, ChannelDiscoveryService.OnChannelSearchResultsFound, ChannelSearchResultAdapter.OnChannelSearchResultSelected {
+
private static final String CHANNEL_DISCOVERY_OPT_IN = "channel_discovery_opt_in";
+
private final ChannelSearchResultAdapter adapter = new ChannelSearchResultAdapter();
private final PendingItem<String> mInitialSearchValue = new PendingItem<>();
private ActivityChannelDiscoveryBinding binding;
private MenuItem mMenuSearchView;
private EditText mSearchEditText;
+
+ private ChannelDiscoveryService.Method method = ChannelDiscoveryService.Method.LOCAL_SERVER;
+
private boolean optedIn = false;
@Override
@@ -52,14 +59,15 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
@Override
void onBackendConnected() {
- if (optedIn) {
- String query;
+ if (optedIn || method == ChannelDiscoveryService.Method.LOCAL_SERVER) {
+ final String query;
if (mMenuSearchView != null && mMenuSearchView.isActionViewExpanded()) {
query = mSearchEditText.getText().toString();
} else {
query = mInitialSearchValue.peek();
}
- xmppConnectionService.discoverChannels(query, this);
+ toggleLoadingScreen();
+ xmppConnectionService.discoverChannels(query, this.method, this);
}
}
@@ -71,7 +79,7 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
configureActionBar(getSupportActionBar(), true);
binding.list.setAdapter(this.adapter);
this.adapter.setOnChannelSearchResultSelectedListener(this);
- optedIn = getPreferences().getBoolean(CHANNEL_DISCOVERY_OPT_IN, false);
+ this.optedIn = getPreferences().getBoolean(CHANNEL_DISCOVERY_OPT_IN, false);
final String search = savedInstanceState == null ? null : savedInstanceState.getString("search");
if (search != null) {
@@ -79,20 +87,30 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
}
}
+ private static ChannelDiscoveryService.Method getMethod(final Context c) {
+ final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(c);
+ final String m = p.getString("channel_discovery_method", c.getString(R.string.default_channel_discovery));
+ try {
+ return ChannelDiscoveryService.Method.valueOf(m);
+ } catch (IllegalArgumentException e) {
+ return ChannelDiscoveryService.Method.JABBER_NETWORK;
+ }
+ }
+
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
- getMenuInflater().inflate(R.menu.muc_users_activity, menu);
+ getMenuInflater().inflate(R.menu.channel_discovery_activity, menu);
mMenuSearchView = menu.findItem(R.id.action_search);
final View mSearchView = mMenuSearchView.getActionView();
mSearchEditText = mSearchView.findViewById(R.id.search_field);
mSearchEditText.setHint(R.string.search_channels);
- String initialSearchValue = mInitialSearchValue.pop();
+ final String initialSearchValue = mInitialSearchValue.pop();
if (initialSearchValue != null) {
mMenuSearchView.expandActionView();
mSearchEditText.append(initialSearchValue);
mSearchEditText.requestFocus();
- if (optedIn && xmppConnectionService != null) {
- xmppConnectionService.discoverChannels(initialSearchValue, this);
+ if ((optedIn || method == ChannelDiscoveryService.Method.LOCAL_SERVER) && xmppConnectionService != null) {
+ xmppConnectionService.discoverChannels(initialSearchValue, this.method, this);
}
}
mSearchEditText.setOnEditorActionListener(this);
@@ -116,8 +134,8 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
imm.hideSoftInputFromWindow(mSearchEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
mSearchEditText.setText("");
toggleLoadingScreen();
- if (optedIn) {
- xmppConnectionService.discoverChannels(null, this);
+ if (optedIn || method == ChannelDiscoveryService.Method.LOCAL_SERVER) {
+ xmppConnectionService.discoverChannels(null, this.method, this);
}
return true;
}
@@ -125,12 +143,14 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
private void toggleLoadingScreen() {
adapter.submitList(Collections.emptyList());
binding.progressBar.setVisibility(View.VISIBLE);
+ binding.list.setBackgroundColor(StyledAttributes.getColor(this, R.attr.color_background_primary));
}
@Override
public void onStart() {
super.onStart();
- if (!optedIn) {
+ this.method = getMethod(this);
+ if (!optedIn && method == ChannelDiscoveryService.Method.JABBER_NETWORK) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.channel_discovery_opt_in_title);
builder.setMessage(Html.fromHtml(getString(R.string.channel_discover_opt_in_message)));
@@ -155,21 +175,21 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
SharedPreferences preferences = getPreferences();
preferences.edit().putBoolean(CHANNEL_DISCOVERY_OPT_IN, true).apply();
optedIn = true;
- xmppConnectionService.discoverChannels(null, this);
+ xmppConnectionService.discoverChannels(null, this.method, this);
}
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- if (optedIn) {
+ if (optedIn || method == ChannelDiscoveryService.Method.LOCAL_SERVER) {
toggleLoadingScreen();
SoftKeyboardUtils.hideSoftKeyboard(this);
- xmppConnectionService.discoverChannels(v.getText().toString(), this);
+ xmppConnectionService.discoverChannels(v.getText().toString(), this.method, this);
}
return true;
}
@Override
- public void onChannelSearchResultsFound(final List<MuclumbusService.Room> results) {
+ public void onChannelSearchResultsFound(final List<Room> results) {
runOnUiThread(() -> {
adapter.submitList(results);
if (results.size() > 0) {
@@ -185,7 +205,7 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
}
@Override
- public void onChannelSearchResult(final MuclumbusService.Room result) {
+ public void onChannelSearchResult(final Room result) {
List<String> accounts = AccountUtils.getEnabledAccounts(xmppConnectionService);
if (accounts.size() == 1) {
joinChannelSearchResult(accounts.get(0), result);
@@ -202,7 +222,7 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
@Override
public boolean onContextItemSelected(MenuItem item) {
- final MuclumbusService.Room room = adapter.getCurrent();
+ final Room room = adapter.getCurrent();
if (room != null) {
switch (item.getItemId()) {
case R.id.share_with:
@@ -220,7 +240,7 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
return false;
}
- public void joinChannelSearchResult(String selectedAccount, MuclumbusService.Room result) {
+ public void joinChannelSearchResult(String selectedAccount, Room result) {
final Jid jid = Config.DOMAIN_LOCK == null ? Jid.of(selectedAccount) : Jid.of(selectedAccount, Config.DOMAIN_LOCK, null);
final boolean syncAutoJoin = getBooleanPreference("autojoin", R.bool.autojoin);
final Account account = xmppConnectionService.findAccountByJid(jid);
diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
index f3488a3fc..801dc3767 100644
--- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
@@ -7,7 +7,6 @@ import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.IntentSender;
import android.content.SharedPreferences;
-import androidx.databinding.DataBindingUtil;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
@@ -16,12 +15,6 @@ import android.preference.PreferenceManager;
import android.provider.Settings;
import android.security.KeyChain;
import android.security.KeyChainAliasCallback;
-import androidx.annotation.NonNull;
-import com.google.android.material.textfield.TextInputLayout;
-import androidx.core.content.ContextCompat;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.AlertDialog;
-import androidx.appcompat.widget.Toolbar;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
@@ -36,6 +29,15 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AlertDialog;
+import androidx.appcompat.widget.Toolbar;
+import androidx.core.content.ContextCompat;
+import androidx.databinding.DataBindingUtil;
+
+import com.google.android.material.textfield.TextInputLayout;
+
import org.openintents.openpgp.util.OpenPgpUtils;
import java.net.URL;
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java
index 7e5fd4b3e..4094a0168 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java
@@ -17,29 +17,27 @@ import java.util.Locale;
import de.pixart.messenger.R;
import de.pixart.messenger.databinding.SearchResultItemBinding;
-import de.pixart.messenger.http.services.MuclumbusService;
+import de.pixart.messenger.entities.Room;
import de.pixart.messenger.ui.XmppActivity;
import de.pixart.messenger.ui.util.AvatarWorkerTask;
import rocks.xmpp.addr.Jid;
-public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Room, ChannelSearchResultAdapter.ViewHolder> implements View.OnCreateContextMenuListener {
+public class ChannelSearchResultAdapter extends ListAdapter<Room, ChannelSearchResultAdapter.ViewHolder> implements View.OnCreateContextMenuListener {
-
- private static final DiffUtil.ItemCallback<MuclumbusService.Room> DIFF = new DiffUtil.ItemCallback<MuclumbusService.Room>() {
+ private static final DiffUtil.ItemCallback<Room> DIFF = new DiffUtil.ItemCallback<Room>() {
@Override
- public boolean areItemsTheSame(@NonNull MuclumbusService.Room a, @NonNull MuclumbusService.Room b) {
+ public boolean areItemsTheSame(@NonNull Room a, @NonNull Room b) {
return a.address != null && a.address.equals(b.address);
}
@Override
- public boolean areContentsTheSame(@NonNull MuclumbusService.Room a, @NonNull MuclumbusService.Room b) {
+ public boolean areContentsTheSame(@NonNull Room a, @NonNull Room b) {
return a.equals(b);
}
};
-
private OnChannelSearchResultSelected listener;
- private MuclumbusService.Room current;
+ private Room current;
public ChannelSearchResultAdapter() {
super(DIFF);
@@ -53,7 +51,7 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
- final MuclumbusService.Room searchResult = getItem(position);
+ final Room searchResult = getItem(position);
viewHolder.binding.name.setText(searchResult.getName());
final String description = searchResult.getDescription();
final String language = searchResult.getLanguage();
@@ -66,7 +64,7 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
if (language == null || language.length() != 2) {
viewHolder.binding.language.setVisibility(View.GONE);
} else {
- viewHolder.binding.language.setText("(" + language.toUpperCase(Locale.ENGLISH) + ")");
+ viewHolder.binding.language.setText(language.toUpperCase(Locale.ENGLISH));
viewHolder.binding.language.setVisibility(View.VISIBLE);
}
final Jid room = searchResult.getRoom();
@@ -82,7 +80,7 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
this.listener = listener;
}
- public MuclumbusService.Room getCurrent() {
+ public Room getCurrent() {
return this.current;
}
@@ -90,12 +88,16 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
final Activity activity = XmppActivity.find(v);
final Object tag = v.getTag();
- if (activity != null && tag instanceof MuclumbusService.Room) {
+ if (activity != null && tag instanceof Room) {
activity.getMenuInflater().inflate(R.menu.channel_item_context, menu);
- this.current = (MuclumbusService.Room) tag;
+ this.current = (Room) tag;
}
}
+ public interface OnChannelSearchResultSelected {
+ void onChannelSearchResult(Room result);
+ }
+
public static class ViewHolder extends RecyclerView.ViewHolder {
private final SearchResultItemBinding binding;
@@ -105,8 +107,4 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
this.binding = binding;
}
}
-
- public interface OnChannelSearchResultSelected {
- void onChannelSearchResult(MuclumbusService.Room result);
- }
} \ No newline at end of file