unified share with menu. fixes #2630
This commit is contained in:
		
							parent
							
								
									dbd489cbcb
								
							
						
					
					
						commit
						acc78145db
					
				|  | @ -291,8 +291,11 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers | ||||||
| 							this.onSubjectEdited); | 							this.onSubjectEdited); | ||||||
| 				} | 				} | ||||||
| 				break; | 				break; | ||||||
| 			case R.id.action_share: | 			case R.id.action_share_http: | ||||||
| 				shareUri(); | 				shareLink(true); | ||||||
|  | 				break; | ||||||
|  | 			case R.id.action_share_uri: | ||||||
|  | 				shareLink(false); | ||||||
| 				break; | 				break; | ||||||
| 			case R.id.action_save_as_bookmark: | 			case R.id.action_save_as_bookmark: | ||||||
| 				saveAsBookmark(); | 				saveAsBookmark(); | ||||||
|  | @ -313,11 +316,15 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	protected String getShareableUri() { | 	protected String getShareableUri(boolean http) { | ||||||
| 		if (mConversation != null) { | 		if (mConversation != null) { | ||||||
| 			return "xmpp:" + mConversation.getJid().toBareJid().toString() + "?join"; | 			if (http) { | ||||||
|  | 				return "https://conversations.im/j/"+ mConversation.getJid().toBareJid(); | ||||||
|  | 			} else { | ||||||
|  | 				return "xmpp:"+mConversation.getJid().toBareJid()+"?join"; | ||||||
|  | 			} | ||||||
| 		} else { | 		} else { | ||||||
| 			return ""; | 			return null; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -180,9 +180,10 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	protected String getShareableUri() { | 	protected String getShareableUri(boolean http) { | ||||||
|  | 		final String prefix = http ? "https://conversations.im/i/" : "xmpp:"; | ||||||
| 		if (contact != null) { | 		if (contact != null) { | ||||||
| 			return "xmpp:"+contact.getJid().toBareJid().toString(); | 			return prefix+contact.getJid().toBareJid().toString(); | ||||||
| 		} else { | 		} else { | ||||||
| 			return ""; | 			return ""; | ||||||
| 		} | 		} | ||||||
|  | @ -263,8 +264,11 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp | ||||||
| 			case android.R.id.home: | 			case android.R.id.home: | ||||||
| 				finish(); | 				finish(); | ||||||
| 				break; | 				break; | ||||||
| 			case R.id.action_share: | 			case R.id.action_share_http: | ||||||
| 				shareUri(); | 				shareLink(true); | ||||||
|  | 				break; | ||||||
|  | 			case R.id.action_share_uri: | ||||||
|  | 				shareLink(false); | ||||||
| 				break; | 				break; | ||||||
| 			case R.id.action_delete_contact: | 			case R.id.action_delete_contact: | ||||||
| 				builder.setTitle(getString(R.string.action_delete_contact)) | 				builder.setTitle(getString(R.string.action_delete_contact)) | ||||||
|  |  | ||||||
|  | @ -492,11 +492,11 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	protected String getShareableUri() { | 	protected String getShareableUri(boolean http) { | ||||||
| 		if (mAccount != null) { | 		if (mAccount != null) { | ||||||
| 			return mAccount.getShareableUri(); | 			return http ? mAccount.getShareableLink() : mAccount.getShareableUri(); | ||||||
| 		} else { | 		} else { | ||||||
| 			return ""; | 			return null; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -590,7 +590,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat | ||||||
| 	public boolean onCreateOptionsMenu(final Menu menu) { | 	public boolean onCreateOptionsMenu(final Menu menu) { | ||||||
| 		super.onCreateOptionsMenu(menu); | 		super.onCreateOptionsMenu(menu); | ||||||
| 		getMenuInflater().inflate(R.menu.editaccount, menu); | 		getMenuInflater().inflate(R.menu.editaccount, menu); | ||||||
| 		final MenuItem showQrCode = menu.findItem(R.id.action_show_qr_code); |  | ||||||
| 		final MenuItem showBlocklist = menu.findItem(R.id.action_show_block_list); | 		final MenuItem showBlocklist = menu.findItem(R.id.action_show_block_list); | ||||||
| 		final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more); | 		final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more); | ||||||
| 		final MenuItem changePassword = menu.findItem(R.id.action_change_password_on_server); | 		final MenuItem changePassword = menu.findItem(R.id.action_change_password_on_server); | ||||||
|  | @ -614,7 +613,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat | ||||||
| 			mamPrefs.setVisible(mAccount.getXmppConnection().getFeatures().mam()); | 			mamPrefs.setVisible(mAccount.getXmppConnection().getFeatures().mam()); | ||||||
| 			changePresence.setVisible(manuallyChangePresence()); | 			changePresence.setVisible(manuallyChangePresence()); | ||||||
| 		} else { | 		} else { | ||||||
| 			showQrCode.setVisible(false); |  | ||||||
| 			showBlocklist.setVisible(false); | 			showBlocklist.setVisible(false); | ||||||
| 			showMoreInfo.setVisible(false); | 			showMoreInfo.setVisible(false); | ||||||
| 			changePassword.setVisible(false); | 			changePassword.setVisible(false); | ||||||
|  | @ -785,19 +783,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat | ||||||
| 		return super.onOptionsItemSelected(item); | 		return super.onOptionsItemSelected(item); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private void shareLink(boolean http) { |  | ||||||
| 		Intent intent = new Intent(Intent.ACTION_SEND); |  | ||||||
| 		intent.setType("text/plain"); |  | ||||||
| 		String text; |  | ||||||
| 		if (http) { |  | ||||||
| 			text = mAccount.getShareableLink(); |  | ||||||
| 		} else { |  | ||||||
| 			text = mAccount.getShareableUri(); |  | ||||||
| 		} |  | ||||||
| 		intent.putExtra(Intent.EXTRA_TEXT,text); |  | ||||||
| 		startActivity(Intent.createChooser(intent, getText(R.string.share_with))); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	private void shareBarcode() { | 	private void shareBarcode() { | ||||||
| 		Intent intent = new Intent(Intent.ACTION_SEND); | 		Intent intent = new Intent(Intent.ACTION_SEND); | ||||||
| 		intent.putExtra(Intent.EXTRA_STREAM,BarcodeProvider.getUriForAccount(this,mAccount)); | 		intent.putExtra(Intent.EXTRA_STREAM,BarcodeProvider.getUriForAccount(this,mAccount)); | ||||||
|  |  | ||||||
|  | @ -998,20 +998,23 @@ public abstract class XmppActivity extends Activity { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	protected String getShareableUri() { | 	protected String getShareableUri() { | ||||||
|  | 		return getShareableUri(false); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	protected String getShareableUri(boolean http) { | ||||||
| 		return null; | 		return null; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	protected void shareUri() { | 	protected void shareLink(boolean http) { | ||||||
| 		String uri = getShareableUri(); | 		String uri = getShareableUri(http); | ||||||
| 		if (uri == null || uri.isEmpty()) { | 		if (uri == null || uri.isEmpty()) { | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		Intent shareIntent = new Intent(); | 		Intent intent = new Intent(Intent.ACTION_SEND); | ||||||
| 		shareIntent.setAction(Intent.ACTION_SEND); | 		intent.setType("text/plain"); | ||||||
| 		shareIntent.putExtra(Intent.EXTRA_TEXT, getShareableUri()); | 		intent.putExtra(Intent.EXTRA_TEXT,getShareableUri(http)); | ||||||
| 		shareIntent.setType("text/plain"); |  | ||||||
| 		try { | 		try { | ||||||
| 			startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with))); | 			startActivity(Intent.createChooser(intent, getText(R.string.share_uri_with))); | ||||||
| 		} catch (ActivityNotFoundException e) { | 		} catch (ActivityNotFoundException e) { | ||||||
| 			Toast.makeText(this, R.string.no_application_to_share_uri, Toast.LENGTH_SHORT).show(); | 			Toast.makeText(this, R.string.no_application_to_share_uri, Toast.LENGTH_SHORT).show(); | ||||||
| 		} | 		} | ||||||
|  | @ -1031,7 +1034,7 @@ public abstract class XmppActivity extends Activity { | ||||||
| 	@Override | 	@Override | ||||||
| 	public void onResume() { | 	public void onResume() { | ||||||
| 		super.onResume(); | 		super.onResume(); | ||||||
| 		if (this.getShareableUri()!=null) { | 		if (this.getShareableUri() != null) { | ||||||
| 			this.registerNdefPushMessageCallback(); | 			this.registerNdefPushMessageCallback(); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | @ -1060,19 +1063,20 @@ public abstract class XmppActivity extends Activity { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	protected void showQrCode() { | 	protected void showQrCode() { | ||||||
| 		String uri = getShareableUri(); | 		final String uri = getShareableUri(); | ||||||
| 		if (uri!=null) { | 		if (uri == null || uri.isEmpty()) { | ||||||
| 			Point size = new Point(); | 			return; | ||||||
| 			getWindowManager().getDefaultDisplay().getSize(size); |  | ||||||
| 			final int width = (size.x < size.y ? size.x : size.y); |  | ||||||
| 			Bitmap bitmap = BarcodeProvider.create2dBarcodeBitmap(uri, width); |  | ||||||
| 			ImageView view = new ImageView(this); |  | ||||||
| 			view.setBackgroundColor(Color.WHITE); |  | ||||||
| 			view.setImageBitmap(bitmap); |  | ||||||
| 			AlertDialog.Builder builder = new AlertDialog.Builder(this); |  | ||||||
| 			builder.setView(view); |  | ||||||
| 			builder.create().show(); |  | ||||||
| 		} | 		} | ||||||
|  | 		Point size = new Point(); | ||||||
|  | 		getWindowManager().getDefaultDisplay().getSize(size); | ||||||
|  | 		final int width = (size.x < size.y ? size.x : size.y); | ||||||
|  | 		Bitmap bitmap = BarcodeProvider.create2dBarcodeBitmap(uri, width); | ||||||
|  | 		ImageView view = new ImageView(this); | ||||||
|  | 		view.setBackgroundColor(Color.WHITE); | ||||||
|  | 		view.setImageBitmap(bitmap); | ||||||
|  | 		AlertDialog.Builder builder = new AlertDialog.Builder(this); | ||||||
|  | 		builder.setView(view); | ||||||
|  | 		builder.create().show(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	protected Account extractAccount(Intent intent) { | 	protected Account extractAccount(Intent intent) { | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| <?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||||
| <menu xmlns:android="http://schemas.android.com/apk/res/android" > | <menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||||||
| 
 | 
 | ||||||
|     <item |     <item | ||||||
|         android:id="@+id/action_edit_contact" |         android:id="@+id/action_edit_contact" | ||||||
|  | @ -11,9 +11,21 @@ | ||||||
|     <item |     <item | ||||||
|         android:id="@+id/action_share" |         android:id="@+id/action_share" | ||||||
|         android:icon="?attr/icon_share" |         android:icon="?attr/icon_share" | ||||||
|         android:showAsAction="always" |  | ||||||
|         android:orderInCategory="15" |         android:orderInCategory="15" | ||||||
|         android:title="@string/share_uri_with"/> |         android:showAsAction="always" | ||||||
|  |         android:title="@string/share_uri_with"> | ||||||
|  |         <menu> | ||||||
|  |             <item | ||||||
|  |                 android:id="@+id/action_share_uri" | ||||||
|  |                 android:title="@string/share_as_uri"/> | ||||||
|  |             <item | ||||||
|  |                 android:id="@+id/action_share_http" | ||||||
|  |                 android:title="@string/share_as_http"/> | ||||||
|  |             <item | ||||||
|  |                 android:id="@+id/action_show_qr_code" | ||||||
|  |                 android:title="@string/show_qr_code"/> | ||||||
|  |         </menu> | ||||||
|  |     </item> | ||||||
|     <item |     <item | ||||||
|         android:id="@+id/action_delete_contact" |         android:id="@+id/action_delete_contact" | ||||||
|         android:orderInCategory="10" |         android:orderInCategory="10" | ||||||
|  |  | ||||||
|  | @ -1,31 +1,31 @@ | ||||||
| <menu xmlns:android="http://schemas.android.com/apk/res/android"> | <menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||||||
| 
 | 
 | ||||||
|     <item android:id="@+id/action_share" |     <item | ||||||
|         android:title="@string/share_uri_with" |         android:id="@+id/action_share" | ||||||
|         android:icon="?attr/icon_share" |         android:icon="?attr/icon_share" | ||||||
|         android:showAsAction="always"> |         android:showAsAction="always" | ||||||
|  |         android:title="@string/share_uri_with"> | ||||||
|         <menu> |         <menu> | ||||||
|  |             <item | ||||||
|  |                 android:id="@+id/action_share_uri" | ||||||
|  |                 android:title="@string/share_as_uri"/> | ||||||
|  |             <item | ||||||
|  |                 android:id="@+id/action_share_http" | ||||||
|  |                 android:title="@string/share_as_http"/> | ||||||
|             <item |             <item | ||||||
|                 android:id="@+id/action_share_barcode" |                 android:id="@+id/action_share_barcode" | ||||||
|                 android:title="@string/share_as_barcode"/> |                 android:title="@string/share_as_barcode"/> | ||||||
|             <item |             <item | ||||||
|                 android:id="@+id/action_share_uri" |                 android:id="@+id/action_show_qr_code" | ||||||
|                 android:title="@string/share_as_uri"/> |                 android:title="@string/show_qr_code"/> | ||||||
|             <item android:id="@+id/action_share_http" |  | ||||||
|                 android:title="@string/share_as_http"/> |  | ||||||
|         </menu> |         </menu> | ||||||
|     </item> |     </item> | ||||||
| 
 | 
 | ||||||
|     <item |     <item | ||||||
|         android:id="@+id/action_change_presence" |         android:id="@+id/action_change_presence" | ||||||
|  |         android:icon="@drawable/ic_announcement_white_24dp" | ||||||
|         android:showAsAction="always" |         android:showAsAction="always" | ||||||
|         android:title="@string/change_presence" |         android:title="@string/change_presence"/> | ||||||
|         android:icon="@drawable/ic_announcement_white_24dp"/> |  | ||||||
| 
 |  | ||||||
|     <item |  | ||||||
|         android:id="@+id/action_show_qr_code" |  | ||||||
|         android:showAsAction="never" |  | ||||||
|         android:title="@string/show_qr_code"/> |  | ||||||
| 
 | 
 | ||||||
|     <item |     <item | ||||||
|         android:id="@+id/action_show_block_list" |         android:id="@+id/action_show_block_list" | ||||||
|  |  | ||||||
|  | @ -7,12 +7,25 @@ | ||||||
|         android:orderInCategory="10" |         android:orderInCategory="10" | ||||||
|         android:showAsAction="always" |         android:showAsAction="always" | ||||||
|         android:title="@string/action_edit_subject"/> |         android:title="@string/action_edit_subject"/> | ||||||
|  | 
 | ||||||
|     <item |     <item | ||||||
|         android:id="@+id/action_share" |         android:id="@+id/action_share" | ||||||
|         android:icon="?attr/icon_share" |         android:icon="?attr/icon_share" | ||||||
|         android:showAsAction="always" |  | ||||||
|         android:orderInCategory="15" |         android:orderInCategory="15" | ||||||
|         android:title="@string/share_uri_with"/> |         android:showAsAction="always" | ||||||
|  |         android:title="@string/share_uri_with"> | ||||||
|  |         <menu> | ||||||
|  |             <item | ||||||
|  |                 android:id="@+id/action_share_uri" | ||||||
|  |                 android:title="@string/share_as_uri"/> | ||||||
|  |             <item | ||||||
|  |                 android:id="@+id/action_share_http" | ||||||
|  |                 android:title="@string/share_as_http"/> | ||||||
|  |             <item | ||||||
|  |                 android:id="@+id/action_show_qr_code" | ||||||
|  |                 android:title="@string/show_qr_code"/> | ||||||
|  |         </menu> | ||||||
|  |     </item> | ||||||
| 
 | 
 | ||||||
|     <item |     <item | ||||||
|         android:id="@+id/action_save_as_bookmark" |         android:id="@+id/action_save_as_bookmark" | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue