Skip to content
Snippets Groups Projects
Commit 3146c76c authored by Thibault Wittemberg's avatar Thibault Wittemberg Committed by gerrit2
Browse files

share: public username should be provided

- When it is available, the "Share my contact" feature should
also provide the blockchain username
- Prevent crash when this is no connected account

Change-Id: Idbc8edcf2194563ed59a8224c196f3c0fc12a5ab
Tuleap: #1185
parent 1443480d
No related branches found
No related tags found
No related merge requests found
......@@ -603,8 +603,10 @@ public class HomeActivity extends AppCompatActivity implements LocalService.Call
}
Bundle args = new Bundle();
args.putString(ShareFragment.ARG_URI, fMenuHead.getSelectedAccount().getShareURI());
fContent.setArguments(args);
if (fMenuHead.getSelectedAccount() != null) {
args.putString(ShareFragment.ARG_URI, fMenuHead.getSelectedAccount().getShareURI());
fContent.setArguments(args);
}
getFragmentManager().beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.replace(R.id.main_frame, fContent, SHARE_TAG)
......
......@@ -24,12 +24,13 @@ import android.app.Fragment;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.widget.AppCompatButton;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindString;
import butterknife.BindView;
......@@ -45,11 +46,17 @@ public class ShareFragment extends Fragment implements MenuHeaderView.MenuHeader
public static final String ARG_URI = "ShareFragment.URI";
@BindView(R.id.share_instruction)
TextView mShareInstruction;
@BindView(R.id.qr_image)
ImageView mQrImage;
@BindView(R.id.share_button)
Button mShareButton;
@BindString(R.string.share_message)
String mShareMessage;
@BindString(R.string.share_message_no_account)
String mShareMessageNoAccount;
@BindString(R.string.account_contact_me)
String mAccountCountactMe;
......@@ -57,7 +64,11 @@ public class ShareFragment extends Fragment implements MenuHeaderView.MenuHeader
@BindString(R.string.share_via)
String mShareVia;
@BindView(R.id.share_button)
AppCompatButton mShareButton;
String mUriToShow;
String mBlockchainUsername;
@Override
public void onResume() {
......@@ -68,9 +79,12 @@ public class ShareFragment extends Fragment implements MenuHeaderView.MenuHeader
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
final View inflatedView = inflater.inflate(R.layout.frag_share, parent, false);
ButterKnife.bind(this, inflatedView);
mUriToShow = getArguments().getString(ARG_URI);
if (getArguments() != null) {
mUriToShow = getArguments().getString(ARG_URI);
}
mQrImage.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
......@@ -83,9 +97,21 @@ public class ShareFragment extends Fragment implements MenuHeaderView.MenuHeader
}
private void updateView() {
if (!TextUtils.isEmpty(mUriToShow) && mQrImage != null) {
if (mQrImage == null || mShareButton == null || mShareInstruction == null) {
return;
}
if (!TextUtils.isEmpty(mUriToShow)) {
Bitmap qrBitmap = QRCodeUtils.encodeStringAsQrBitmap(mUriToShow, mQrImage.getMeasuredWidth());
mQrImage.setImageBitmap(qrBitmap);
mQrImage.setVisibility(View.VISIBLE);
mShareButton.setEnabled(true);
mShareInstruction.setText(mShareMessage);
} else {
mShareButton.setEnabled(false);
mShareInstruction.setText(mShareMessageNoAccount);
mQrImage.setVisibility(View.INVISIBLE);
}
}
......@@ -94,16 +120,22 @@ public class ShareFragment extends Fragment implements MenuHeaderView.MenuHeader
if (!TextUtils.isEmpty(mUriToShow)) {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = getString(R.string.account_share_body, mUriToShow);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mAccountCountactMe);
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
if (!TextUtils.isEmpty(mBlockchainUsername)) {
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, getString(R.string.account_share_body_with_username, mUriToShow, mBlockchainUsername));
} else {
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, getString(R.string.account_share_body, mUriToShow));
}
startActivity(Intent.createChooser(sharingIntent, mShareVia));
}
}
@Override
public void accountSelected(Account account) {
mUriToShow = account.getShareURI();
updateView();
if (account != null) {
mUriToShow = account.getShareURI();
mBlockchainUsername = account.getRegisteredName();
updateView();
}
}
}
......@@ -4,7 +4,7 @@
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:id="@+id/share_instruction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/qr_image_panel"
......
......@@ -192,6 +192,7 @@ along with this program; if not, write to the Free Software
<!-- Share fragment -->
<string name="share_label">Click on the Ring id to share</string>
<string name="share_message">Scan this QRCode with the embedded scanner of the Ring application that wants to communicate with you.</string>
<string name="share_message_no_account">Please select an account to share.</string>
<string name="share_your_account_information">Share my contact information</string>
</resources>
......@@ -170,7 +170,8 @@ along with this program; if not, write to the Free Software
<string name="account_export_end_error_title">Error</string>
<string name="account_export_end_error_message">Couldn\'t export account. An unknown error occurred.</string>
<string name="account_enter_password">Enter password</string>
<string name="account_share_body">Contact me using %1$s on the Ring distributed communication platform: http://ring.cx</string>
<string name="account_share_body">Contact me using \'%1$s\' on the Ring distributed communication platform: http://ring.cx</string>
<string name="account_share_body_with_username">Contact me using \'%1$s\' or my public username \'%2$s\' on the Ring distributed communication platform: http://ring.cx</string>
<string name="account_contact_me">Contact me on Ring !</string>
<string name="update_account">Update account</string>
<string name="account_migration">Your Ring account can now be shared between all your devices. All you need to do is provide a password.</string>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment