fixed bug in intent filter. cleaned share with activity

This commit is contained in:
iNPUTmice 2014-06-15 12:01:46 +02:00
parent 0102032fc5
commit 30a0be2998
2 changed files with 44 additions and 15 deletions

View File

@ -93,6 +93,10 @@
<action android:name="android.intent.action.SEND" /> <action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" /> <data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" /> <data android:mimeType="image/*" />
</intent-filter> </intent-filter>
</activity> </activity>

View File

@ -11,7 +11,9 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import android.app.PendingIntent;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -29,6 +31,27 @@ public class ShareWithActivity extends XmppActivity {
private LinearLayout conversations; private LinearLayout conversations;
private LinearLayout contacts; private LinearLayout contacts;
private boolean isImage = false;
private UiCallback<Message> attachImageCallback = new UiCallback<Message>() {
@Override
public void userInputRequried(PendingIntent pi, Message object) {
// TODO Auto-generated method stub
}
@Override
public void success(Message message) {
xmppConnectionService.sendMessage(message);
}
@Override
public void error(int errorCode, Message object) {
// TODO Auto-generated method stub
}
};
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -58,7 +81,7 @@ public class ShareWithActivity extends XmppActivity {
@Override @Override
void onBackendConnected() { void onBackendConnected() {
final boolean isImage = (getIntent().getType() != null && getIntent() this.isImage = (getIntent().getType() != null && getIntent()
.getType().startsWith("image/")); .getType().startsWith("image/"));
SharedPreferences preferences = PreferenceManager SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(this); .getDefaultSharedPreferences(this);
@ -85,16 +108,7 @@ public class ShareWithActivity extends XmppActivity {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
String sharedText = null; share(conversation);
if (isImage) {
Uri uri = (Uri) getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
Log.d(LOGTAG,uri.toString());
} else {
sharedText = getIntent().getStringExtra(
Intent.EXTRA_TEXT);
}
switchToConversation(conversation, sharedText, true);
finish();
} }
}); });
conversations.addView(view); conversations.addView(view);
@ -131,17 +145,28 @@ public class ShareWithActivity extends XmppActivity {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
String sharedText = getIntent().getStringExtra(
Intent.EXTRA_TEXT);
Conversation conversation = xmppConnectionService Conversation conversation = xmppConnectionService
.findOrCreateConversation(con.getAccount(), .findOrCreateConversation(con.getAccount(),
con.getJid(), false); con.getJid(), false);
switchToConversation(conversation, sharedText, true); share(conversation);
finish();
} }
}); });
contacts.addView(view); contacts.addView(view);
} }
} }
private void share(Conversation conversation) {
String sharedText = null;
if (isImage) {
Uri uri = (Uri) getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
Log.d(LOGTAG,uri.toString());
ShareWithActivity.this.xmppConnectionService.attachImageToConversation(conversation, uri,attachImageCallback);
} else {
sharedText = getIntent().getStringExtra(
Intent.EXTRA_TEXT);
}
switchToConversation(conversation, sharedText, true);
finish();
}
} }