record voice and attachment refactor

This commit is contained in:
Daniel Gultsch 2015-01-03 16:06:59 +01:00
parent 960b7343d3
commit be7de054be
5 changed files with 73 additions and 74 deletions

View File

@ -56,7 +56,8 @@ public class DownloadableFile extends File {
public String getMimeType() { public String getMimeType() {
String path = this.getAbsolutePath(); String path = this.getAbsolutePath();
String mime = URLConnection.guessContentTypeFromName(path); try {
String mime = URLConnection.guessContentTypeFromName(path.replace("#",""));
if (mime != null) { if (mime != null) {
return mime; return mime;
} else if (mime == null && path.endsWith(".webp")) { } else if (mime == null && path.endsWith(".webp")) {
@ -64,6 +65,9 @@ public class DownloadableFile extends File {
} else { } else {
return ""; return "";
} }
} catch (final StringIndexOutOfBoundsException e) {
return "";
}
} }
public void setExpectedSize(long size) { public void setExpectedSize(long size) {

View File

@ -9,6 +9,7 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.content.IntentSender.SendIntentException; import android.content.IntentSender.SendIntentException;
import android.media.MediaActionSound;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock; import android.os.SystemClock;
@ -52,19 +53,14 @@ public class ConversationActivity extends XmppActivity
public static final String CONVERSATION = "conversationUuid"; public static final String CONVERSATION = "conversationUuid";
public static final String TEXT = "text"; public static final String TEXT = "text";
public static final String NICK = "nick"; public static final String NICK = "nick";
public static final String PRESENCE = "eu.siacs.conversations.presence";
public static final int REQUEST_SEND_MESSAGE = 0x0201; public static final int REQUEST_SEND_MESSAGE = 0x0201;
public static final int REQUEST_DECRYPT_PGP = 0x0202; public static final int REQUEST_DECRYPT_PGP = 0x0202;
public static final int REQUEST_ENCRYPT_MESSAGE = 0x0207; public static final int REQUEST_ENCRYPT_MESSAGE = 0x0207;
private static final int REQUEST_ATTACH_IMAGE_DIALOG = 0x0203;
private static final int REQUEST_IMAGE_CAPTURE = 0x0204;
private static final int REQUEST_RECORD_AUDIO = 0x0205;
private static final int REQUEST_SEND_PGP_IMAGE = 0x0206;
private static final int REQUEST_ATTACH_FILE_DIALOG = 0x0208;
private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301; private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301;
private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302; private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302;
private static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303; private static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303;
private static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0304;
private static final String STATE_OPEN_CONVERSATION = "state_open_conversation"; private static final String STATE_OPEN_CONVERSATION = "state_open_conversation";
private static final String STATE_PANEL_OPEN = "state_panel_open"; private static final String STATE_PANEL_OPEN = "state_panel_open";
private static final String STATE_PENDING_URI = "state_pending_uri"; private static final String STATE_PENDING_URI = "state_pending_uri";
@ -100,10 +96,6 @@ public class ConversationActivity extends XmppActivity
this.mSelectedConversation = conversation; this.mSelectedConversation = conversation;
} }
public ListView getConversationListView() {
return this.listView;
}
public void showConversationsOverview() { public void showConversationsOverview() {
if (mContentView instanceof SlidingPaneLayout) { if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView; SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
@ -346,33 +338,37 @@ public class ConversationActivity extends XmppActivity
@Override @Override
public void onPresenceSelected() { public void onPresenceSelected() {
if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_PHOTO) { Intent intent = new Intent();
mPendingImageUri = xmppConnectionService.getFileBackend() boolean chooser = false;
.getTakePhotoUri(); switch (attachmentChoice) {
Intent takePictureIntent = new Intent( case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
MediaStore.ACTION_IMAGE_CAPTURE); intent.setAction(Intent.ACTION_GET_CONTENT);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, intent.setType("image/*");
mPendingImageUri); chooser = true;
if (takePictureIntent.resolveActivity(getPackageManager()) != null) { break;
startActivityForResult(takePictureIntent, case ATTACHMENT_CHOICE_TAKE_PHOTO:
REQUEST_IMAGE_CAPTURE); mPendingImageUri = xmppConnectionService.getFileBackend().getTakePhotoUri();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,mPendingImageUri);
break;
case ATTACHMENT_CHOICE_CHOOSE_FILE:
chooser = true;
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setAction(Intent.ACTION_GET_CONTENT);
break;
case ATTACHMENT_CHOICE_RECORD_VOICE:
intent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
break;
}
if (intent.resolveActivity(getPackageManager()) != null) {
if (chooser) {
startActivityForResult(
Intent.createChooser(intent,getString(R.string.perform_action_with)),
attachmentChoice);
} else {
startActivityForResult(intent, attachmentChoice);
} }
} else if (attachmentChoice == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
Intent attachFileIntent = new Intent();
attachFileIntent.setType("image/*");
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
Intent chooser = Intent.createChooser(attachFileIntent,
getString(R.string.attach_file));
startActivityForResult(chooser, REQUEST_ATTACH_IMAGE_DIALOG);
} else if (attachmentChoice == ATTACHMENT_CHOICE_CHOOSE_FILE) {
Intent attachFileIntent = new Intent();
//attachFileIntent.setType("file/*");
attachFileIntent.setType("*/*");
attachFileIntent.addCategory(Intent.CATEGORY_OPENABLE);
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
Intent chooser = Intent.createChooser(attachFileIntent,
getString(R.string.attach_file));
startActivityForResult(chooser, REQUEST_ATTACH_FILE_DIALOG);
} }
} }
}); });
@ -541,8 +537,10 @@ public class ConversationActivity extends XmppActivity
} }
PopupMenu attachFilePopup = new PopupMenu(this, menuAttachFile); PopupMenu attachFilePopup = new PopupMenu(this, menuAttachFile);
attachFilePopup.inflate(R.menu.attachment_choices); attachFilePopup.inflate(R.menu.attachment_choices);
attachFilePopup if (new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION).resolveActivity(getPackageManager()) == null) {
.setOnMenuItemClickListener(new OnMenuItemClickListener() { attachFilePopup.getMenu().findItem(R.id.attach_record_voice).setVisible(false);
}
attachFilePopup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
@ -553,9 +551,12 @@ public class ConversationActivity extends XmppActivity
case R.id.attach_take_picture: case R.id.attach_take_picture:
attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO); attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
break; break;
case R.id.attach_record_voice: case R.id.attach_choose_file:
attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE); attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE);
break; break;
case R.id.attach_record_voice:
attachFile(ATTACHMENT_CHOICE_RECORD_VOICE);
break;
} }
return false; return false;
} }
@ -864,44 +865,29 @@ public class ConversationActivity extends XmppActivity
if (requestCode == REQUEST_DECRYPT_PGP) { if (requestCode == REQUEST_DECRYPT_PGP) {
mConversationFragment.hideSnackbar(); mConversationFragment.hideSnackbar();
mConversationFragment.updateMessages(); mConversationFragment.updateMessages();
} else if (requestCode == REQUEST_ATTACH_IMAGE_DIALOG) { } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
mPendingImageUri = data.getData(); mPendingImageUri = data.getData();
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
attachImageToConversation(getSelectedConversation(), attachImageToConversation(getSelectedConversation(),mPendingImageUri);
mPendingImageUri);
mPendingImageUri = null; mPendingImageUri = null;
} }
} else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) { } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_FILE || requestCode == ATTACHMENT_CHOICE_RECORD_VOICE) {
mPendingFileUri = data.getData(); mPendingFileUri = data.getData();
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
attachFileToConversation(getSelectedConversation(), attachFileToConversation(getSelectedConversation(),mPendingFileUri);
mPendingFileUri);
mPendingFileUri = null; mPendingFileUri = null;
} }
} else if (requestCode == REQUEST_SEND_PGP_IMAGE) { } else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO && mPendingImageUri != null) {
} else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE);
} else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) {
attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
} else if (requestCode == REQUEST_ANNOUNCE_PGP) {
announcePgp(getSelectedConversation().getAccount(),
getSelectedConversation());
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
// encryptTextMessage();
} else if (requestCode == REQUEST_IMAGE_CAPTURE && mPendingImageUri != null) {
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
attachImageToConversation(getSelectedConversation(), attachImageToConversation(getSelectedConversation(),mPendingImageUri);
mPendingImageUri);
mPendingImageUri = null; mPendingImageUri = null;
} }
Intent intent = new Intent( Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(mPendingImageUri); intent.setData(mPendingImageUri);
sendBroadcast(intent); sendBroadcast(intent);
} }
} else { } else {
if (requestCode == REQUEST_IMAGE_CAPTURE) { if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) {
mPendingImageUri = null; mPendingImageUri = null;
} }
} }
@ -941,8 +927,6 @@ public class ConversationActivity extends XmppActivity
public void userInputRequried(PendingIntent pi, public void userInputRequried(PendingIntent pi,
Message object) { Message object) {
hidePrepareFileToast(); hidePrepareFileToast();
ConversationActivity.this.runIntent(pi,
ConversationActivity.REQUEST_SEND_PGP_IMAGE);
} }
@Override @Override

View File

@ -13,7 +13,10 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
import java.io.UnsupportedEncodingException;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLDecoder;
import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -133,13 +136,17 @@ public class ShareWithActivity extends XmppActivity {
final String type = getIntent().getType(); final String type = getIntent().getType();
if (type != null && !type.startsWith("text/")) { if (type != null && !type.startsWith("text/")) {
this.share.uri = (Uri) getIntent().getParcelableExtra(Intent.EXTRA_STREAM); this.share.uri = (Uri) getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
this.share.image = type.startsWith("image/") || URLConnection.guessContentTypeFromName(share.uri.getPath()).startsWith("image/"); try {
this.share.image = type.startsWith("image/")
|| URLConnection.guessContentTypeFromName(this.share.uri.toString()).startsWith("image/");
} catch (final StringIndexOutOfBoundsException ignored) {
this.share.image = false;
}
} else { } else {
this.share.text = getIntent().getStringExtra(Intent.EXTRA_TEXT); this.share.text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
} }
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
xmppConnectionService.populateWithOrderedConversations( xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.uri == null);
mConversations, this.share.uri == null);
} }
super.onStart(); super.onStart();
} }

View File

@ -9,6 +9,9 @@
android:title="@string/attach_take_picture"/> android:title="@string/attach_take_picture"/>
<item <item
android:id="@+id/attach_record_voice" android:id="@+id/attach_record_voice"
android:title="@string/attach_record_voice"/>
<item
android:id="@+id/attach_choose_file"
android:title="@string/choose_file"/> android:title="@string/choose_file"/>
</menu> </menu>

View File

@ -405,4 +405,5 @@
<string name="password_should_not_be_empty">Password should not be empty</string> <string name="password_should_not_be_empty">Password should not be empty</string>
<string name="enable_all_accounts">Enable all accounts</string> <string name="enable_all_accounts">Enable all accounts</string>
<string name="disable_all_accounts">Disable all accounts</string> <string name="disable_all_accounts">Disable all accounts</string>
<string name="perform_action_with">Perform action with</string>
</resources> </resources>