don't display 'enter password' message if OpenKeychain is not installed. made status messages in chat not selectable

This commit is contained in:
iNPUTmice 2014-06-09 21:25:01 +02:00
parent d0a338f814
commit 28b7a6c92a
7 changed files with 131 additions and 89 deletions

View File

@ -6,7 +6,7 @@
android:padding="8dp" > android:padding="8dp" >
<LinearLayout <LinearLayout
android:id="@+id/linearLayout1" android:id="@+id/message_box"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"

View File

@ -6,6 +6,7 @@
android:padding="8dp" > android:padding="8dp" >
<LinearLayout <LinearLayout
android:id="@+id/message_box"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"

View File

@ -241,4 +241,5 @@
<string name="last_seen_hours">last seen %d hours ago</string> <string name="last_seen_hours">last seen %d hours ago</string>
<string name="last_seen_days">last seen %d days ago</string> <string name="last_seen_days">last seen %d days ago</string>
<string name="never_seen">never seen</string> <string name="never_seen">never seen</string>
<string name="install_openkeychain">Encrypted message. Please install OpenKeychain to decrypt.</string>
</resources> </resources>

View File

@ -434,6 +434,8 @@ public class ConversationActivity extends XmppActivity {
}); });
} }
} }
} else {
showInstallPgpDialog();
} }
} else if (getSelectedConversation().getNextEncryption() == Message.ENCRYPTION_NONE) { } else if (getSelectedConversation().getNextEncryption() == Message.ENCRYPTION_NONE) {
selectPresenceToAttachFile(attachmentChoice); selectPresenceToAttachFile(attachmentChoice);
@ -568,6 +570,8 @@ public class ConversationActivity extends XmppActivity {
announcePgp(conversation.getAccount(), announcePgp(conversation.getAccount(),
conversation); conversation);
} }
} else {
showInstallPgpDialog();
} }
break; break;
default: default:

View File

@ -276,6 +276,7 @@ public class ConversationFragment extends Fragment {
viewHolder.messageBody.setText(getString(r)); viewHolder.messageBody.setText(getString(r));
viewHolder.messageBody.setTextColor(0xff33B5E5); viewHolder.messageBody.setTextColor(0xff33B5E5);
viewHolder.messageBody.setTypeface(null, Typeface.ITALIC); viewHolder.messageBody.setTypeface(null, Typeface.ITALIC);
viewHolder.messageBody.setTextIsSelectable(false);
} }
private void displayDecryptionFailed(ViewHolder viewHolder) { private void displayDecryptionFailed(ViewHolder viewHolder) {
@ -286,6 +287,7 @@ public class ConversationFragment extends Fragment {
.setText(getString(R.string.decryption_failed)); .setText(getString(R.string.decryption_failed));
viewHolder.messageBody.setTextColor(0xFFe92727); viewHolder.messageBody.setTextColor(0xFFe92727);
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
viewHolder.messageBody.setTextIsSelectable(false);
} }
private void displayTextMessage(ViewHolder viewHolder, String text) { private void displayTextMessage(ViewHolder viewHolder, String text) {
@ -301,6 +303,7 @@ public class ConversationFragment extends Fragment {
} }
viewHolder.messageBody.setTextColor(0xff333333); viewHolder.messageBody.setTextColor(0xff333333);
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
viewHolder.messageBody.setTextIsSelectable(true);
} }
private void displayImageMessage(ViewHolder viewHolder, private void displayImageMessage(ViewHolder viewHolder,
@ -367,6 +370,8 @@ public class ConversationFragment extends Fragment {
case SENT: case SENT:
view = (View) inflater.inflate(R.layout.message_sent, view = (View) inflater.inflate(R.layout.message_sent,
null); null);
viewHolder.message_box = (LinearLayout) view
.findViewById(R.id.message_box);
viewHolder.contact_picture = (ImageView) view viewHolder.contact_picture = (ImageView) view
.findViewById(R.id.message_photo); .findViewById(R.id.message_photo);
viewHolder.contact_picture.setImageBitmap(selfBitmap); viewHolder.contact_picture.setImageBitmap(selfBitmap);
@ -383,6 +388,8 @@ public class ConversationFragment extends Fragment {
case RECIEVED: case RECIEVED:
view = (View) inflater.inflate( view = (View) inflater.inflate(
R.layout.message_recieved, null); R.layout.message_recieved, null);
viewHolder.message_box = (LinearLayout) view
.findViewById(R.id.message_box);
viewHolder.contact_picture = (ImageView) view viewHolder.contact_picture = (ImageView) view
.findViewById(R.id.message_photo); .findViewById(R.id.message_photo);
@ -492,8 +499,20 @@ public class ConversationFragment extends Fragment {
} }
} else { } else {
if (item.getEncryption() == Message.ENCRYPTION_PGP) { if (item.getEncryption() == Message.ENCRYPTION_PGP) {
displayInfoMessage(viewHolder, if (activity.hasPgp()) {
R.string.encrypted_message); displayInfoMessage(viewHolder,
R.string.encrypted_message);
} else {
displayInfoMessage(viewHolder,
R.string.install_openkeychain);
viewHolder.message_box.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
activity.showInstallPgpDialog();
}
});
}
} else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { } else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
displayDecryptionFailed(viewHolder); displayDecryptionFailed(viewHolder);
} else { } else {
@ -646,7 +665,7 @@ public class ConversationFragment extends Fragment {
} }
}); });
} else { } else {
pgpInfo.setVisibility(View.VISIBLE); pgpInfo.setVisibility(View.GONE);
} }
} }
@ -666,7 +685,8 @@ public class ConversationFragment extends Fragment {
} }
if (activity.showLastseen()) { if (activity.showLastseen()) {
Contact contact = conversation.getContact(); Contact contact = conversation.getContact();
lastSeenText.setText(UIHelper.lastseen(getActivity(), contact.lastseen.time)); lastSeenText.setText(UIHelper.lastseen(getActivity(),
contact.lastseen.time));
} }
this.messageList.clear(); this.messageList.clear();
this.messageList.addAll(this.conversation.getMessages()); this.messageList.addAll(this.conversation.getMessages());
@ -762,7 +782,8 @@ public class ConversationFragment extends Fragment {
new UiCallback<Contact>() { new UiCallback<Contact>() {
@Override @Override
public void userInputRequried(PendingIntent pi,Contact contact) { public void userInputRequried(PendingIntent pi,
Contact contact) {
activity.runIntent( activity.runIntent(
pi, pi,
ConversationActivity.REQUEST_ENCRYPT_MESSAGE); ConversationActivity.REQUEST_ENCRYPT_MESSAGE);
@ -822,6 +843,8 @@ public class ConversationFragment extends Fragment {
}); });
} }
} }
} else {
activity.showInstallPgpDialog();
} }
} }
@ -873,6 +896,7 @@ public class ConversationFragment extends Fragment {
private static class ViewHolder { private static class ViewHolder {
protected LinearLayout message_box;
protected Button download_button; protected Button download_button;
protected ImageView image; protected ImageView image;
protected ImageView indicator; protected ImageView indicator;

View File

@ -279,6 +279,8 @@ public class ManageAccountActivity extends XmppActivity {
if (activity.hasPgp()) { if (activity.hasPgp()) {
mode.finish(); mode.finish();
announcePgp(selectedAccountForActionMode,null); announcePgp(selectedAccountForActionMode,null);
} else {
activity.showInstallPgpDialog();
} }
} else if (item.getItemId() == R.id.mgmt_otr_key) { } else if (item.getItemId() == R.id.mgmt_otr_key) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity); AlertDialog.Builder builder = new AlertDialog.Builder(activity);

View File

@ -27,15 +27,15 @@ import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
public abstract class XmppActivity extends Activity { public abstract class XmppActivity extends Activity {
public static final int REQUEST_ANNOUNCE_PGP = 0x73731; public static final int REQUEST_ANNOUNCE_PGP = 0x73731;
protected final static String LOGTAG = "xmppService"; protected final static String LOGTAG = "xmppService";
public XmppConnectionService xmppConnectionService; public XmppConnectionService xmppConnectionService;
public boolean xmppConnectionServiceBound = false; public boolean xmppConnectionServiceBound = false;
protected boolean handledViewIntent = false; protected boolean handledViewIntent = false;
protected ServiceConnection mConnection = new ServiceConnection() { protected ServiceConnection mConnection = new ServiceConnection() {
@Override @Override
@ -51,7 +51,7 @@ public abstract class XmppActivity extends Activity {
xmppConnectionServiceBound = false; xmppConnectionServiceBound = false;
} }
}; };
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
@ -59,14 +59,14 @@ public abstract class XmppActivity extends Activity {
connectToBackend(); connectToBackend();
} }
} }
public void connectToBackend() { public void connectToBackend() {
Intent intent = new Intent(this, XmppConnectionService.class); Intent intent = new Intent(this, XmppConnectionService.class);
intent.setAction("ui"); intent.setAction("ui");
startService(intent); startService(intent);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE); bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
} }
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
@ -75,7 +75,7 @@ public abstract class XmppActivity extends Activity {
xmppConnectionServiceBound = false; xmppConnectionServiceBound = false;
} }
} }
protected void hideKeyboard() { protected void hideKeyboard() {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
@ -83,50 +83,52 @@ public abstract class XmppActivity extends Activity {
if (focus != null) { if (focus != null) {
inputManager.hideSoftInputFromWindow( inputManager.hideSoftInputFromWindow(focus.getWindowToken(),
focus.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS); InputMethodManager.HIDE_NOT_ALWAYS);
} }
} }
public boolean hasPgp() { public boolean hasPgp() {
if (xmppConnectionService.getPgpEngine()!=null) { return xmppConnectionService.getPgpEngine() != null;
return true;
} else {
Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.openkeychain_required));
builder.setIconAttribute(android.R.attr.alertDialogIcon);
builder.setMessage(getText(R.string.openkeychain_required_long));
builder.setNegativeButton(getString(R.string.cancel), null);
builder.setNeutralButton(getString(R.string.restart), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (xmppConnectionServiceBound) {
unbindService(mConnection);
xmppConnectionServiceBound = false;
}
stopService(new Intent(XmppActivity.this, XmppConnectionService.class));
finish();
}
});
builder.setPositiveButton(getString(R.string.install), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Uri uri = Uri.parse("market://details?id=org.sufficientlysecure.keychain");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
finish();
}
});
builder.create().show();
return false;
}
} }
public void showInstallPgpDialog() {
Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.openkeychain_required));
builder.setIconAttribute(android.R.attr.alertDialogIcon);
builder.setMessage(getText(R.string.openkeychain_required_long));
builder.setNegativeButton(getString(R.string.cancel), null);
builder.setNeutralButton(getString(R.string.restart),
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (xmppConnectionServiceBound) {
unbindService(mConnection);
xmppConnectionServiceBound = false;
}
stopService(new Intent(XmppActivity.this,
XmppConnectionService.class));
finish();
}
});
builder.setPositiveButton(getString(R.string.install),
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Uri uri = Uri
.parse("market://details?id=org.sufficientlysecure.keychain");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
finish();
}
});
builder.create().show();
}
abstract void onBackendConnected(); abstract void onBackendConnected();
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_settings: case R.id.action_settings:
@ -138,68 +140,76 @@ public abstract class XmppActivity extends Activity {
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ExceptionHelper.init(getApplicationContext()); ExceptionHelper.init(getApplicationContext());
} }
public void switchToConversation(Conversation conversation, String text, boolean newTask) { public void switchToConversation(Conversation conversation, String text,
boolean newTask) {
Intent viewConversationIntent = new Intent(this, Intent viewConversationIntent = new Intent(this,
ConversationActivity.class); ConversationActivity.class);
viewConversationIntent.setAction(Intent.ACTION_VIEW); viewConversationIntent.setAction(Intent.ACTION_VIEW);
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
conversation.getUuid()); conversation.getUuid());
if (text!=null) { if (text != null) {
viewConversationIntent.putExtra(ConversationActivity.TEXT, text); viewConversationIntent.putExtra(ConversationActivity.TEXT, text);
} }
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION); viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
if (newTask) { if (newTask) {
viewConversationIntent.setFlags(viewConversationIntent.getFlags() viewConversationIntent.setFlags(viewConversationIntent.getFlags()
| Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP); | Intent.FLAG_ACTIVITY_SINGLE_TOP);
} else { } else {
viewConversationIntent.setFlags(viewConversationIntent.getFlags() viewConversationIntent.setFlags(viewConversationIntent.getFlags()
| Intent.FLAG_ACTIVITY_CLEAR_TOP); | Intent.FLAG_ACTIVITY_CLEAR_TOP);
} }
startActivity(viewConversationIntent); startActivity(viewConversationIntent);
} }
protected void announcePgp(Account account, final Conversation conversation) { protected void announcePgp(Account account, final Conversation conversation) {
xmppConnectionService.getPgpEngine().generateSignature(account, "online", new UiCallback<Account>() { xmppConnectionService.getPgpEngine().generateSignature(account,
"online", new UiCallback<Account>() {
@Override
public void userInputRequried(PendingIntent pi, Account account) { @Override
try { public void userInputRequried(PendingIntent pi,
startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); Account account) {
} catch (SendIntentException e) { try {
Log.d("xmppService","coulnd start intent for pgp anncouncment"); startIntentSenderForResult(pi.getIntentSender(),
} REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
} } catch (SendIntentException e) {
Log.d("xmppService",
@Override "coulnd start intent for pgp anncouncment");
public void success(Account account) { }
xmppConnectionService.databaseBackend.updateAccount(account); }
xmppConnectionService.sendPresence(account);
if (conversation!=null) { @Override
conversation.setNextEncryption(Message.ENCRYPTION_PGP); public void success(Account account) {
} xmppConnectionService.databaseBackend
} .updateAccount(account);
xmppConnectionService.sendPresence(account);
@Override if (conversation != null) {
public void error(int error, Account account) { conversation
displayErrorDialog(error); .setNextEncryption(Message.ENCRYPTION_PGP);
} }
}); }
@Override
public void error(int error, Account account) {
displayErrorDialog(error);
}
});
} }
protected void displayErrorDialog(final int errorCode) { protected void displayErrorDialog(final int errorCode) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(XmppActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(
XmppActivity.this);
builder.setIconAttribute(android.R.attr.alertDialogIcon); builder.setIconAttribute(android.R.attr.alertDialogIcon);
builder.setTitle(getString(R.string.error)); builder.setTitle(getString(R.string.error));
builder.setMessage(errorCode); builder.setMessage(errorCode);
@ -207,6 +217,6 @@ public abstract class XmppActivity extends Activity {
builder.create().show(); builder.create().show();
} }
}); });
} }
} }