Commit e3c90c3d authored by Grigory Fedorov's avatar Grigory Fedorov

Chat: security menu moved from options submenu to Security button popup menu.

parent 946308f8
...@@ -32,7 +32,6 @@ import android.widget.LinearLayout; ...@@ -32,7 +32,6 @@ import android.widget.LinearLayout;
import com.xabber.android.data.ActivityManager; import com.xabber.android.data.ActivityManager;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException; import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.OnAccountChangedListener; import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.entity.BaseEntity; import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.archive.MessageArchiveManager; import com.xabber.android.data.extension.archive.MessageArchiveManager;
...@@ -40,8 +39,6 @@ import com.xabber.android.data.extension.attention.AttentionManager; ...@@ -40,8 +39,6 @@ import com.xabber.android.data.extension.attention.AttentionManager;
import com.xabber.android.data.extension.muc.MUCManager; import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.extension.muc.RoomChat; import com.xabber.android.data.extension.muc.RoomChat;
import com.xabber.android.data.extension.muc.RoomState; import com.xabber.android.data.extension.muc.RoomState;
import com.xabber.android.data.extension.otr.OTRManager;
import com.xabber.android.data.extension.otr.SecurityLevel;
import com.xabber.android.data.intent.EntityIntentBuilder; import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.message.AbstractChat; import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.data.message.MessageManager; import com.xabber.android.data.message.MessageManager;
...@@ -222,22 +219,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -222,22 +219,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
if (abstractChat instanceof RegularChat) { if (abstractChat instanceof RegularChat) {
menu.findItem(R.id.action_view_contact).setVisible(true); menu.findItem(R.id.action_view_contact).setVisible(true);
menu.findItem(R.id.action_close_chat).setVisible(true); menu.findItem(R.id.action_close_chat).setVisible(true);
SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);
if (securityLevel == SecurityLevel.plain) {
menu.findItem(R.id.action_start_encryption).setVisible(true)
.setEnabled(SettingsManager.securityOtrMode() != SettingsManager.SecurityOtrMode.disabled);
} else {
menu.findItem(R.id.action_restart_encryption).setVisible(true);
}
boolean isEncrypted = securityLevel != SecurityLevel.plain;
menu.findItem(R.id.action_stop_encryption).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_fingerprint).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_question).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_shared_secret).setEnabled(isEncrypted);
} }
} }
...@@ -370,32 +351,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -370,32 +351,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
startActivity(OccupantList.createIntent(this, account, user)); startActivity(OccupantList.createIntent(this, account, user));
return true; return true;
/* encryption */
case R.id.action_start_encryption:
startEncryption(account, user);
return true;
case R.id.action_restart_encryption:
restartEncryption(account, user);
return true;
case R.id.action_stop_encryption:
stopEncryption(account, user);
return true;
case R.id.action_verify_with_fingerprint:
startActivity(FingerprintViewer.createIntent(this, account, user));
return true;
case R.id.action_verify_with_question:
startActivity(QuestionViewer.createIntent(this, account, user, true, false, null));
return true;
case R.id.action_verify_with_shared_secret:
startActivity(QuestionViewer.createIntent(this, account, user, false, false, null));
return true;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
...@@ -409,30 +364,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -409,30 +364,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
} }
} }
private void stopEncryption(String account, String user) {
try {
OTRManager.getInstance().endSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void restartEncryption(String account, String user) {
try {
OTRManager.getInstance().refreshSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void startEncryption(String account, String user) {
try {
OTRManager.getInstance().startSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void callAttention(String account, String user) { private void callAttention(String account, String user) {
try { try {
AttentionManager.getInstance().sendAttention(account, user); AttentionManager.getInstance().sendAttention(account, user);
......
...@@ -10,6 +10,7 @@ import android.text.TextWatcher; ...@@ -10,6 +10,7 @@ import android.text.TextWatcher;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
...@@ -18,20 +19,25 @@ import android.widget.AdapterView; ...@@ -18,20 +19,25 @@ import android.widget.AdapterView;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ListView; import android.widget.ListView;
import android.widget.PopupMenu;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager; import com.xabber.android.data.LogManager;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.extension.cs.ChatStateManager; import com.xabber.android.data.extension.cs.ChatStateManager;
import com.xabber.android.data.extension.otr.OTRManager; import com.xabber.android.data.extension.otr.OTRManager;
import com.xabber.android.data.extension.otr.SecurityLevel; import com.xabber.android.data.extension.otr.SecurityLevel;
import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.data.message.MessageItem; import com.xabber.android.data.message.MessageItem;
import com.xabber.android.data.message.MessageManager; import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.message.RegularChat;
import com.xabber.android.data.message.chat.ChatManager; import com.xabber.android.data.message.chat.ChatManager;
import com.xabber.android.ui.adapter.ChatMessageAdapter; import com.xabber.android.ui.adapter.ChatMessageAdapter;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class ChatViewerFragment extends Fragment implements AdapterView.OnItemClickListener { public class ChatViewerFragment extends Fragment implements AdapterView.OnItemClickListener, PopupMenu.OnMenuItemClickListener {
public static final String ARGUMENT_ACCOUNT = "ARGUMENT_ACCOUNT"; public static final String ARGUMENT_ACCOUNT = "ARGUMENT_ACCOUNT";
public static final String ARGUMENT_USER = "ARGUMENT_USER"; public static final String ARGUMENT_USER = "ARGUMENT_USER";
...@@ -77,7 +83,19 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -77,7 +83,19 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
sendButton = (ImageButton) view.findViewById(R.id.button_send_message); sendButton = (ImageButton) view.findViewById(R.id.button_send_message);
sendButton.setImageResource(R.drawable.ic_button_send_inactive_24dp); sendButton.setImageResource(R.drawable.ic_button_send_inactive_24dp);
AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
securityButton = (ImageButton) view.findViewById(R.id.button_security); securityButton = (ImageButton) view.findViewById(R.id.button_security);
if (abstractChat instanceof RegularChat) {
securityButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showSecurityMenu();
}
});
} else {
securityButton.setVisibility(View.GONE);
}
chatMessageAdapter = new ChatMessageAdapter(getActivity(), account, user); chatMessageAdapter = new ChatMessageAdapter(getActivity(), account, user);
...@@ -148,6 +166,32 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -148,6 +166,32 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
} }
private void showSecurityMenu() {
PopupMenu popup = new PopupMenu(getActivity(), securityButton);
popup.inflate(R.menu.security);
popup.setOnMenuItemClickListener(this);
Menu menu = popup.getMenu();
SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);
if (securityLevel == SecurityLevel.plain) {
menu.findItem(R.id.action_start_encryption).setVisible(true)
.setEnabled(SettingsManager.securityOtrMode() != SettingsManager.SecurityOtrMode.disabled);
} else {
menu.findItem(R.id.action_restart_encryption).setVisible(true);
}
boolean isEncrypted = securityLevel != SecurityLevel.plain;
menu.findItem(R.id.action_stop_encryption).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_fingerprint).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_question).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_shared_secret).setEnabled(isEncrypted);
popup.show();
}
private void setSendButtonColor() { private void setSendButtonColor() {
boolean empty = inputView.getText().toString().isEmpty(); boolean empty = inputView.getText().toString().isEmpty();
...@@ -285,17 +329,8 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -285,17 +329,8 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
private void updateSecurityButton() { private void updateSecurityButton() {
SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user); SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);
SettingsManager.SecurityOtrMode securityOtrMode = SettingsManager.securityOtrMode();
if (securityLevel == SecurityLevel.plain
&& (securityOtrMode == SettingsManager.SecurityOtrMode.disabled
|| securityOtrMode == SettingsManager.SecurityOtrMode.manual)) {
securityButton.setVisibility(View.GONE);
} else {
securityButton.setVisibility(View.VISIBLE);
securityButton.setImageLevel(securityLevel.getImageLevel()); securityButton.setImageLevel(securityLevel.getImageLevel());
} }
}
public boolean isEqual(String account, String user) { public boolean isEqual(String account, String user) {
return this.account.equals(account) && this.user.equals(user); return this.account.equals(account) && this.user.equals(user);
...@@ -335,4 +370,60 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -335,4 +370,60 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
listView.showContextMenuForChild(view); listView.showContextMenuForChild(view);
unregisterForContextMenu(listView); unregisterForContextMenu(listView);
} }
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_start_encryption:
startEncryption(account, user);
return true;
case R.id.action_restart_encryption:
restartEncryption(account, user);
return true;
case R.id.action_stop_encryption:
stopEncryption(account, user);
return true;
case R.id.action_verify_with_fingerprint:
startActivity(FingerprintViewer.createIntent(getActivity(), account, user));
return true;
case R.id.action_verify_with_question:
startActivity(QuestionViewer.createIntent(getActivity(), account, user, true, false, null));
return true;
case R.id.action_verify_with_shared_secret:
startActivity(QuestionViewer.createIntent(getActivity(), account, user, false, false, null));
return true;
default:
return false;
}
}
private void stopEncryption(String account, String user) {
try {
OTRManager.getInstance().endSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void restartEncryption(String account, String user) {
try {
OTRManager.getInstance().refreshSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void startEncryption(String account, String user) {
try {
OTRManager.getInstance().startSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
} }
...@@ -53,7 +53,6 @@ ...@@ -53,7 +53,6 @@
android:background="@null" android:background="@null"
android:contentDescription="@string/otr_encryption" android:contentDescription="@string/otr_encryption"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:visibility="gone"
/> />
<EditText <EditText
......
...@@ -91,53 +91,6 @@ ...@@ -91,53 +91,6 @@
android:orderInCategory="180" android:orderInCategory="180"
/> />
<item android:id="@+id/action_otr_encryption"
android:title="@string/otr_encryption"
app:showAsAction="never"
android:orderInCategory="190">
<menu>
<item android:id="@+id/action_start_encryption"
android:title="@string/otr_start"
app:showAsAction="never"
android:orderInCategory="100"
android:visible="false"
/>
<item android:id="@+id/action_restart_encryption"
android:title="@string/otr_refresh"
app:showAsAction="never"
android:orderInCategory="105"
android:visible="false"
/>
<item android:id="@+id/action_stop_encryption"
android:title="@string/otr_end"
app:showAsAction="never"
android:orderInCategory="110"
/>
<item android:id="@+id/action_verify_with_fingerprint"
android:title="@string/otr_verify_fingerprint"
app:showAsAction="never"
android:orderInCategory="120"
/>
<item android:id="@+id/action_verify_with_question"
android:title="@string/otr_verify_question"
app:showAsAction="never"
android:orderInCategory="130"
/>
<item android:id="@+id/action_verify_with_shared_secret"
android:title="@string/otr_verify_secret"
app:showAsAction="never"
android:orderInCategory="140"
/>
</menu>
</item>
<item android:id="@+id/action_list_of_occupants" <item android:id="@+id/action_list_of_occupants"
android:title="@string/occupant_list" android:title="@string/occupant_list"
app:showAsAction="never" app:showAsAction="never"
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_start_encryption"
android:title="@string/otr_start"
android:orderInCategory="100"
android:visible="false"
/>
<item android:id="@+id/action_restart_encryption"
android:title="@string/otr_refresh"
android:orderInCategory="105"
android:visible="false"
/>
<item android:id="@+id/action_stop_encryption"
android:title="@string/otr_end"
android:orderInCategory="110"
/>
<item android:id="@+id/action_verify_with_fingerprint"
android:title="@string/otr_verify_fingerprint"
android:orderInCategory="120"
/>
<item android:id="@+id/action_verify_with_question"
android:title="@string/otr_verify_question"
android:orderInCategory="130"
/>
<item android:id="@+id/action_verify_with_shared_secret"
android:title="@string/otr_verify_secret"
android:orderInCategory="140"
/>
</menu>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment