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" >
<LinearLayout
android:id="@+id/linearLayout1"
android:id="@+id/message_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"

View File

@ -6,6 +6,7 @@
android:padding="8dp" >
<LinearLayout
android:id="@+id/message_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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_days">last seen %d days ago</string>
<string name="never_seen">never seen</string>
<string name="install_openkeychain">Encrypted message. Please install OpenKeychain to decrypt.</string>
</resources>

View File

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

View File

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

View File

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

View File

@ -83,46 +83,48 @@ public abstract class XmppActivity extends Activity {
if (focus != null) {
inputManager.hideSoftInputFromWindow(
focus.getWindowToken(),
inputManager.hideSoftInputFromWindow(focus.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
public boolean hasPgp() {
if (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() {
return xmppConnectionService.getPgpEngine() != null;
}
@Override
public void onClick(DialogInterface dialog, int which) {
if (xmppConnectionServiceBound) {
unbindService(mConnection);
xmppConnectionServiceBound = 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();
}
stopService(new Intent(XmppActivity.this, XmppConnectionService.class));
finish();
}
});
builder.setPositiveButton(getString(R.string.install), new OnClickListener() {
});
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;
}
@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();
@ -145,53 +147,60 @@ public abstract class XmppActivity extends Activity {
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,
ConversationActivity.class);
viewConversationIntent.setAction(Intent.ACTION_VIEW);
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
conversation.getUuid());
if (text!=null) {
if (text != null) {
viewConversationIntent.putExtra(ConversationActivity.TEXT, text);
}
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
if (newTask) {
viewConversationIntent.setFlags(viewConversationIntent.getFlags()
| Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
| Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
} else {
viewConversationIntent.setFlags(viewConversationIntent.getFlags()
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
startActivity(viewConversationIntent);
}
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) {
try {
startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
} catch (SendIntentException e) {
Log.d("xmppService","coulnd start intent for pgp anncouncment");
}
}
@Override
public void userInputRequried(PendingIntent pi,
Account account) {
try {
startIntentSenderForResult(pi.getIntentSender(),
REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
} catch (SendIntentException e) {
Log.d("xmppService",
"coulnd start intent for pgp anncouncment");
}
}
@Override
public void success(Account account) {
xmppConnectionService.databaseBackend.updateAccount(account);
xmppConnectionService.sendPresence(account);
if (conversation!=null) {
conversation.setNextEncryption(Message.ENCRYPTION_PGP);
}
}
@Override
public void success(Account account) {
xmppConnectionService.databaseBackend
.updateAccount(account);
xmppConnectionService.sendPresence(account);
if (conversation != null) {
conversation
.setNextEncryption(Message.ENCRYPTION_PGP);
}
}
@Override
public void error(int error, Account account) {
displayErrorDialog(error);
}
});
@Override
public void error(int error, Account account) {
displayErrorDialog(error);
}
});
}
protected void displayErrorDialog(final int errorCode) {
@ -199,7 +208,8 @@ public abstract class XmppActivity extends Activity {
@Override
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.setTitle(getString(R.string.error));
builder.setMessage(errorCode);