refactoring. move functionality from activity to fragment
This commit is contained in:
		
							parent
							
								
									d55a3842d3
								
							
						
					
					
						commit
						c17f902be2
					
				|  | @ -59,8 +59,8 @@ import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdat | ||||||
| import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate; | import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate; | ||||||
| import eu.siacs.conversations.ui.adapter.ConversationAdapter; | import eu.siacs.conversations.ui.adapter.ConversationAdapter; | ||||||
| import eu.siacs.conversations.ui.service.EmojiService; | import eu.siacs.conversations.ui.service.EmojiService; | ||||||
|  | import eu.siacs.conversations.ui.util.SendButtonAction; | ||||||
| import eu.siacs.conversations.utils.ExceptionHelper; | import eu.siacs.conversations.utils.ExceptionHelper; | ||||||
| import eu.siacs.conversations.utils.UIHelper; |  | ||||||
| import eu.siacs.conversations.xmpp.OnUpdateBlocklist; | import eu.siacs.conversations.xmpp.OnUpdateBlocklist; | ||||||
| import eu.siacs.conversations.xmpp.XmppConnection; | import eu.siacs.conversations.xmpp.XmppConnection; | ||||||
| import eu.siacs.conversations.xmpp.jid.InvalidJidException; | import eu.siacs.conversations.xmpp.jid.InvalidJidException; | ||||||
|  | @ -556,29 +556,12 @@ public class ConversationActivity extends XmppActivity | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		final ConversationFragment.SendButtonAction action; | 		try { | ||||||
| 		switch (attachmentChoice) { | 			getPreferences().edit() | ||||||
| 			case ATTACHMENT_CHOICE_LOCATION: | 					.putString(RECENTLY_USED_QUICK_ACTION, SendButtonAction.of(attachmentChoice).toString()) | ||||||
| 				action = ConversationFragment.SendButtonAction.SEND_LOCATION; | 					.apply(); | ||||||
| 				break; | 		} catch (IllegalArgumentException e) { | ||||||
| 			case ATTACHMENT_CHOICE_RECORD_VOICE: | 			//just do not save | ||||||
| 				action = ConversationFragment.SendButtonAction.RECORD_VOICE; |  | ||||||
| 				break; |  | ||||||
| 			case ATTACHMENT_CHOICE_RECORD_VIDEO: |  | ||||||
| 				action = ConversationFragment.SendButtonAction.RECORD_VIDEO; |  | ||||||
| 				break; |  | ||||||
| 			case ATTACHMENT_CHOICE_TAKE_PHOTO: |  | ||||||
| 				action = ConversationFragment.SendButtonAction.TAKE_PHOTO; |  | ||||||
| 				break; |  | ||||||
| 			case ATTACHMENT_CHOICE_CHOOSE_IMAGE: |  | ||||||
| 				action = ConversationFragment.SendButtonAction.CHOOSE_PICTURE; |  | ||||||
| 				break; |  | ||||||
| 			default: |  | ||||||
| 				action = null; |  | ||||||
| 				break; |  | ||||||
| 		} |  | ||||||
| 		if (action != null) { |  | ||||||
| 			getPreferences().edit().putString(RECENTLY_USED_QUICK_ACTION,action.toString()).apply(); |  | ||||||
| 		} | 		} | ||||||
| 		final Conversation conversation = getSelectedConversation(); | 		final Conversation conversation = getSelectedConversation(); | ||||||
| 		final int encryption = conversation.getNextEncryption(); | 		final int encryption = conversation.getNextEncryption(); | ||||||
|  | @ -693,22 +676,12 @@ public class ConversationActivity extends XmppActivity | ||||||
| 					handleEncryptionSelection(item); | 					handleEncryptionSelection(item); | ||||||
| 					break; | 					break; | ||||||
| 				case R.id.attach_choose_picture: | 				case R.id.attach_choose_picture: | ||||||
| 					attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE); |  | ||||||
| 					break; |  | ||||||
| 				case R.id.attach_take_picture: | 				case R.id.attach_take_picture: | ||||||
| 					attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO); |  | ||||||
| 					break; |  | ||||||
| 				case R.id.attach_record_video: | 				case R.id.attach_record_video: | ||||||
| 					attachFile(ATTACHMENT_CHOICE_RECORD_VIDEO); |  | ||||||
| 					break; |  | ||||||
| 				case R.id.attach_choose_file: | 				case R.id.attach_choose_file: | ||||||
| 					attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE); |  | ||||||
| 					break; |  | ||||||
| 				case R.id.attach_record_voice: | 				case R.id.attach_record_voice: | ||||||
| 					attachFile(ATTACHMENT_CHOICE_RECORD_VOICE); |  | ||||||
| 					break; |  | ||||||
| 				case R.id.attach_location: | 				case R.id.attach_location: | ||||||
| 					attachFile(ATTACHMENT_CHOICE_LOCATION); | 					handleAttachmentSelection(item); | ||||||
| 					break; | 					break; | ||||||
| 				case R.id.action_archive: | 				case R.id.action_archive: | ||||||
| 					this.endConversation(getSelectedConversation()); | 					this.endConversation(getSelectedConversation()); | ||||||
|  | @ -783,8 +756,7 @@ public class ConversationActivity extends XmppActivity | ||||||
| 		final CheckBox endConversationCheckBox = dialogView.findViewById(R.id.end_conversation_checkbox); | 		final CheckBox endConversationCheckBox = dialogView.findViewById(R.id.end_conversation_checkbox); | ||||||
| 		builder.setView(dialogView); | 		builder.setView(dialogView); | ||||||
| 		builder.setNegativeButton(getString(R.string.cancel), null); | 		builder.setNegativeButton(getString(R.string.cancel), null); | ||||||
| 		builder.setPositiveButton(getString(R.string.delete_messages), | 		builder.setPositiveButton(getString(R.string.delete_messages), (dialog, which) -> { | ||||||
| 				(dialog, which) -> { |  | ||||||
| 			ConversationActivity.this.xmppConnectionService.clearConversationHistory(conversation); | 			ConversationActivity.this.xmppConnectionService.clearConversationHistory(conversation); | ||||||
| 			if (endConversationCheckBox.isChecked()) { | 			if (endConversationCheckBox.isChecked()) { | ||||||
| 				endConversation(conversation); | 				endConversation(conversation); | ||||||
|  | @ -796,6 +768,29 @@ public class ConversationActivity extends XmppActivity | ||||||
| 		builder.create().show(); | 		builder.create().show(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	private void handleAttachmentSelection(MenuItem item) { | ||||||
|  | 		switch (item.getItemId()) { | ||||||
|  | 			case R.id.attach_choose_picture: | ||||||
|  | 				attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE); | ||||||
|  | 				break; | ||||||
|  | 			case R.id.attach_take_picture: | ||||||
|  | 				attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO); | ||||||
|  | 				break; | ||||||
|  | 			case R.id.attach_record_video: | ||||||
|  | 				attachFile(ATTACHMENT_CHOICE_RECORD_VIDEO); | ||||||
|  | 				break; | ||||||
|  | 			case R.id.attach_choose_file: | ||||||
|  | 				attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE); | ||||||
|  | 				break; | ||||||
|  | 			case R.id.attach_record_voice: | ||||||
|  | 				attachFile(ATTACHMENT_CHOICE_RECORD_VOICE); | ||||||
|  | 				break; | ||||||
|  | 			case R.id.attach_location: | ||||||
|  | 				attachFile(ATTACHMENT_CHOICE_LOCATION); | ||||||
|  | 				break; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	private void handleEncryptionSelection(MenuItem item) { | 	private void handleEncryptionSelection(MenuItem item) { | ||||||
| 		Conversation conversation = getSelectedConversation(); | 		Conversation conversation = getSelectedConversation(); | ||||||
| 		if (conversation == null) { | 		if (conversation == null) { | ||||||
|  | @ -839,11 +834,7 @@ public class ConversationActivity extends XmppActivity | ||||||
| 		AlertDialog.Builder builder = new AlertDialog.Builder(this); | 		AlertDialog.Builder builder = new AlertDialog.Builder(this); | ||||||
| 		builder.setTitle(R.string.disable_notifications); | 		builder.setTitle(R.string.disable_notifications); | ||||||
| 		final int[] durations = getResources().getIntArray(R.array.mute_options_durations); | 		final int[] durations = getResources().getIntArray(R.array.mute_options_durations); | ||||||
| 		builder.setItems(R.array.mute_options_descriptions, | 		builder.setItems(R.array.mute_options_descriptions, (dialog, which) -> { | ||||||
| 				new OnClickListener() { |  | ||||||
| 
 |  | ||||||
| 					@Override |  | ||||||
| 					public void onClick(final DialogInterface dialog, final int which) { |  | ||||||
| 			final long till; | 			final long till; | ||||||
| 			if (durations[which] == -1) { | 			if (durations[which] == -1) { | ||||||
| 				till = Long.MAX_VALUE; | 				till = Long.MAX_VALUE; | ||||||
|  | @ -855,7 +846,6 @@ public class ConversationActivity extends XmppActivity | ||||||
| 			updateConversationList(); | 			updateConversationList(); | ||||||
| 			ConversationActivity.this.mConversationFragment.updateMessages(); | 			ConversationActivity.this.mConversationFragment.updateMessages(); | ||||||
| 			invalidateOptionsMenu(); | 			invalidateOptionsMenu(); | ||||||
| 					} |  | ||||||
| 		}); | 		}); | ||||||
| 		builder.create().show(); | 		builder.create().show(); | ||||||
| 	} | 	} | ||||||
|  | @ -1472,22 +1462,12 @@ public class ConversationActivity extends XmppActivity | ||||||
| 			@Override | 			@Override | ||||||
| 			public void inform(final String text) { | 			public void inform(final String text) { | ||||||
| 				hidePrepareFileToast(prepareFileToast); | 				hidePrepareFileToast(prepareFileToast); | ||||||
| 				runOnUiThread(new Runnable() { | 				runOnUiThread(() -> replaceToast(text)); | ||||||
| 					@Override |  | ||||||
| 					public void run() { |  | ||||||
| 						replaceToast(text); |  | ||||||
| 					} |  | ||||||
| 				}); |  | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			@Override | 			@Override | ||||||
| 			public void success(Message message) { | 			public void success(Message message) { | ||||||
| 				runOnUiThread(new Runnable() { | 				runOnUiThread(() -> hideToast()); | ||||||
| 					@Override |  | ||||||
| 					public void run() { |  | ||||||
| 						hideToast(); |  | ||||||
| 					} |  | ||||||
| 				}); |  | ||||||
| 				hidePrepareFileToast(prepareFileToast); | 				hidePrepareFileToast(prepareFileToast); | ||||||
| 				xmppConnectionService.sendMessage(message); | 				xmppConnectionService.sendMessage(message); | ||||||
| 			} | 			} | ||||||
|  | @ -1495,12 +1475,7 @@ public class ConversationActivity extends XmppActivity | ||||||
| 			@Override | 			@Override | ||||||
| 			public void error(final int errorCode, Message message) { | 			public void error(final int errorCode, Message message) { | ||||||
| 				hidePrepareFileToast(prepareFileToast); | 				hidePrepareFileToast(prepareFileToast); | ||||||
| 				runOnUiThread(new Runnable() { | 				runOnUiThread(() -> replaceToast(getString(errorCode))); | ||||||
| 					@Override |  | ||||||
| 					public void run() { |  | ||||||
| 						replaceToast(getString(errorCode)); |  | ||||||
| 					} |  | ||||||
| 				}); |  | ||||||
| 
 | 
 | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | @ -1551,13 +1526,7 @@ public class ConversationActivity extends XmppActivity | ||||||
| 
 | 
 | ||||||
| 	private void hidePrepareFileToast(final Toast prepareFileToast) { | 	private void hidePrepareFileToast(final Toast prepareFileToast) { | ||||||
| 		if (prepareFileToast != null) { | 		if (prepareFileToast != null) { | ||||||
| 			runOnUiThread(new Runnable() { | 			runOnUiThread(() -> prepareFileToast.cancel()); | ||||||
| 
 |  | ||||||
| 				@Override |  | ||||||
| 				public void run() { |  | ||||||
| 					prepareFileToast.cancel(); |  | ||||||
| 				} |  | ||||||
| 			}); |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -1716,12 +1685,7 @@ public class ConversationActivity extends XmppActivity | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public void onShowErrorToast(final int resId) { | 	public void onShowErrorToast(final int resId) { | ||||||
| 		runOnUiThread(new Runnable() { | 		runOnUiThread(() -> Toast.makeText(ConversationActivity.this, resId, Toast.LENGTH_SHORT).show()); | ||||||
| 			@Override |  | ||||||
| 			public void run() { |  | ||||||
| 				Toast.makeText(ConversationActivity.this,resId,Toast.LENGTH_SHORT).show(); |  | ||||||
| 			} |  | ||||||
| 		}); |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public boolean highlightSelectedConversations() { | 	public boolean highlightSelectedConversations() { | ||||||
|  |  | ||||||
|  | @ -71,8 +71,7 @@ import eu.siacs.conversations.services.XmppConnectionService; | ||||||
| import eu.siacs.conversations.ui.XmppActivity.OnPresenceSelected; | import eu.siacs.conversations.ui.XmppActivity.OnPresenceSelected; | ||||||
| import eu.siacs.conversations.ui.XmppActivity.OnValueEdited; | import eu.siacs.conversations.ui.XmppActivity.OnValueEdited; | ||||||
| import eu.siacs.conversations.ui.adapter.MessageAdapter; | import eu.siacs.conversations.ui.adapter.MessageAdapter; | ||||||
| import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked; | import eu.siacs.conversations.ui.util.SendButtonAction; | ||||||
| import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked; |  | ||||||
| import eu.siacs.conversations.ui.widget.EditMessage; | import eu.siacs.conversations.ui.widget.EditMessage; | ||||||
| import eu.siacs.conversations.utils.MessageUtils; | import eu.siacs.conversations.utils.MessageUtils; | ||||||
| import eu.siacs.conversations.utils.NickValidityChecker; | import eu.siacs.conversations.utils.NickValidityChecker; | ||||||
|  | @ -82,6 +81,12 @@ import eu.siacs.conversations.xmpp.XmppConnection; | ||||||
| import eu.siacs.conversations.xmpp.chatstate.ChatState; | import eu.siacs.conversations.xmpp.chatstate.ChatState; | ||||||
| import eu.siacs.conversations.xmpp.jid.Jid; | import eu.siacs.conversations.xmpp.jid.Jid; | ||||||
| 
 | 
 | ||||||
|  | import static eu.siacs.conversations.ui.ConversationActivity.ATTACHMENT_CHOICE_CHOOSE_IMAGE; | ||||||
|  | import static eu.siacs.conversations.ui.ConversationActivity.ATTACHMENT_CHOICE_LOCATION; | ||||||
|  | import static eu.siacs.conversations.ui.ConversationActivity.ATTACHMENT_CHOICE_RECORD_VIDEO; | ||||||
|  | import static eu.siacs.conversations.ui.ConversationActivity.ATTACHMENT_CHOICE_RECORD_VOICE; | ||||||
|  | import static eu.siacs.conversations.ui.ConversationActivity.ATTACHMENT_CHOICE_TAKE_PHOTO; | ||||||
|  | 
 | ||||||
| public class ConversationFragment extends Fragment implements EditMessage.KeyboardListener { | public class ConversationFragment extends Fragment implements EditMessage.KeyboardListener { | ||||||
| 
 | 
 | ||||||
| 	final protected List<Message> messageList = new ArrayList<>(); | 	final protected List<Message> messageList = new ArrayList<>(); | ||||||
|  | @ -357,19 +362,11 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa | ||||||
| 				SendButtonAction action = (SendButtonAction) tag; | 				SendButtonAction action = (SendButtonAction) tag; | ||||||
| 				switch (action) { | 				switch (action) { | ||||||
| 					case TAKE_PHOTO: | 					case TAKE_PHOTO: | ||||||
| 						activity.attachFile(ConversationActivity.ATTACHMENT_CHOICE_TAKE_PHOTO); |  | ||||||
| 						break; |  | ||||||
| 					case RECORD_VIDEO: | 					case RECORD_VIDEO: | ||||||
| 						activity.attachFile(ConversationActivity.ATTACHMENT_CHOICE_RECORD_VIDEO); |  | ||||||
| 						break; |  | ||||||
| 					case SEND_LOCATION: | 					case SEND_LOCATION: | ||||||
| 						activity.attachFile(ConversationActivity.ATTACHMENT_CHOICE_LOCATION); |  | ||||||
| 						break; |  | ||||||
| 					case RECORD_VOICE: | 					case RECORD_VOICE: | ||||||
| 						activity.attachFile(ConversationActivity.ATTACHMENT_CHOICE_RECORD_VOICE); |  | ||||||
| 						break; |  | ||||||
| 					case CHOOSE_PICTURE: | 					case CHOOSE_PICTURE: | ||||||
| 						activity.attachFile(ConversationActivity.ATTACHMENT_CHOICE_CHOOSE_IMAGE); | 						activity.attachFile(action.toChoice()); | ||||||
| 						break; | 						break; | ||||||
| 					case CANCEL: | 					case CANCEL: | ||||||
| 						if (conversation != null) { | 						if (conversation != null) { | ||||||
|  | @ -1674,8 +1671,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public void onActivityResult(int requestCode, int resultCode, | 	public void onActivityResult(int requestCode, int resultCode, final Intent data) { | ||||||
| 	                             final Intent data) { |  | ||||||
| 		if (resultCode == Activity.RESULT_OK) { | 		if (resultCode == Activity.RESULT_OK) { | ||||||
| 			if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) { | 			if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) { | ||||||
| 				activity.getSelectedConversation().getAccount().getPgpDecryptionService().continueDecryption(data); | 				activity.getSelectedConversation().getAccount().getPgpDecryptionService().continueDecryption(data); | ||||||
|  | @ -1695,16 +1691,4 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	enum SendButtonAction { |  | ||||||
| 		TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE, RECORD_VIDEO; |  | ||||||
| 
 |  | ||||||
| 		public static SendButtonAction valueOfOrDefault(String setting, SendButtonAction text) { |  | ||||||
| 			try { |  | ||||||
| 				return valueOf(setting); |  | ||||||
| 			} catch (IllegalArgumentException e) { |  | ||||||
| 				return TEXT; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -0,0 +1,82 @@ | ||||||
|  | /* | ||||||
|  |  * Copyright (c) 2018, Daniel Gultsch All rights reserved. | ||||||
|  |  * | ||||||
|  |  * Redistribution and use in source and binary forms, with or without modification, | ||||||
|  |  * are permitted provided that the following conditions are met: | ||||||
|  |  * | ||||||
|  |  * 1. Redistributions of source code must retain the above copyright notice, this | ||||||
|  |  * list of conditions and the following disclaimer. | ||||||
|  |  * | ||||||
|  |  * 2. Redistributions in binary form must reproduce the above copyright notice, | ||||||
|  |  * this list of conditions and the following disclaimer in the documentation and/or | ||||||
|  |  * other materials provided with the distribution. | ||||||
|  |  * | ||||||
|  |  * 3. Neither the name of the copyright holder nor the names of its contributors | ||||||
|  |  * may be used to endorse or promote products derived from this software without | ||||||
|  |  * specific prior written permission. | ||||||
|  |  * | ||||||
|  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||||||
|  |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||||||
|  |  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||||||
|  |  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||||||
|  |  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||||||
|  |  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||||||
|  |  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||||||
|  |  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||||
|  |  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||||||
|  |  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | package eu.siacs.conversations.ui.util; | ||||||
|  | 
 | ||||||
|  | import static eu.siacs.conversations.ui.ConversationActivity.ATTACHMENT_CHOICE_CHOOSE_IMAGE; | ||||||
|  | import static eu.siacs.conversations.ui.ConversationActivity.ATTACHMENT_CHOICE_LOCATION; | ||||||
|  | import static eu.siacs.conversations.ui.ConversationActivity.ATTACHMENT_CHOICE_RECORD_VIDEO; | ||||||
|  | import static eu.siacs.conversations.ui.ConversationActivity.ATTACHMENT_CHOICE_RECORD_VOICE; | ||||||
|  | import static eu.siacs.conversations.ui.ConversationActivity.ATTACHMENT_CHOICE_TAKE_PHOTO; | ||||||
|  | 
 | ||||||
|  | public enum SendButtonAction { | ||||||
|  | 	TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE, RECORD_VIDEO; | ||||||
|  | 
 | ||||||
|  | 	public static SendButtonAction valueOfOrDefault(String setting, SendButtonAction text) { | ||||||
|  | 		try { | ||||||
|  | 			return valueOf(setting); | ||||||
|  | 		} catch (IllegalArgumentException e) { | ||||||
|  | 			return TEXT; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public static SendButtonAction of(int attachmentChoice) { | ||||||
|  | 		switch (attachmentChoice) { | ||||||
|  | 			case ATTACHMENT_CHOICE_LOCATION: | ||||||
|  | 				return SEND_LOCATION; | ||||||
|  | 			case ATTACHMENT_CHOICE_RECORD_VOICE: | ||||||
|  | 				return RECORD_VOICE; | ||||||
|  | 			case ATTACHMENT_CHOICE_RECORD_VIDEO: | ||||||
|  | 				return RECORD_VIDEO; | ||||||
|  | 			case ATTACHMENT_CHOICE_TAKE_PHOTO: | ||||||
|  | 				return TAKE_PHOTO; | ||||||
|  | 			case ATTACHMENT_CHOICE_CHOOSE_IMAGE: | ||||||
|  | 				return CHOOSE_PICTURE; | ||||||
|  | 			default: | ||||||
|  | 				throw new IllegalArgumentException("Not a known attachment choice"); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public int toChoice() { | ||||||
|  | 		switch (this) { | ||||||
|  | 			case TAKE_PHOTO: | ||||||
|  | 				return ATTACHMENT_CHOICE_TAKE_PHOTO; | ||||||
|  | 			case SEND_LOCATION: | ||||||
|  | 				return ATTACHMENT_CHOICE_LOCATION; | ||||||
|  | 			case RECORD_VOICE: | ||||||
|  | 				return ATTACHMENT_CHOICE_RECORD_VOICE; | ||||||
|  | 			case CHOOSE_PICTURE: | ||||||
|  | 				return ATTACHMENT_CHOICE_CHOOSE_IMAGE; | ||||||
|  | 			case RECORD_VIDEO: | ||||||
|  | 				return ATTACHMENT_CHOICE_RECORD_VIDEO; | ||||||
|  | 			default: | ||||||
|  | 				return 0; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	 Daniel Gultsch
						Daniel Gultsch