mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #3367 from deltachat/adb/issue-3385
improve "show QR" screen
This commit is contained in:
@@ -12,10 +12,10 @@ import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.view.MenuCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
@@ -42,7 +42,7 @@ import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class QrActivity extends BaseActionBarActivity {
|
||||
public class QrActivity extends BaseActionBarActivity implements View.OnClickListener {
|
||||
|
||||
private final static String TAG = QrActivity.class.getSimpleName();
|
||||
private final static int REQUEST_CODE_IMAGE = 46243;
|
||||
@@ -64,7 +64,7 @@ public class QrActivity extends BaseActionBarActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_qr);
|
||||
qrShowFragment = new QrShowFragment();
|
||||
qrShowFragment = new QrShowFragment(this);
|
||||
tabLayout = ViewUtil.findById(this, R.id.tab_layout);
|
||||
viewPager = ViewUtil.findById(this, R.id.pager);
|
||||
ProfilePagerAdapter adapter = new ProfilePagerAdapter(this, getSupportFragmentManager());
|
||||
@@ -115,7 +115,6 @@ public class QrActivity extends BaseActionBarActivity {
|
||||
menu.findItem(R.id.new_classic_contact).setVisible(!DcHelper.getContext(this).isChatmail());
|
||||
if(tabLayout.getSelectedTabPosition() == TAB_SCAN) {
|
||||
menu.findItem(R.id.withdraw).setVisible(false);
|
||||
menu.findItem(R.id.copy).setVisible(false);
|
||||
}
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
@@ -131,12 +130,6 @@ public class QrActivity extends BaseActionBarActivity {
|
||||
case R.id.new_classic_contact:
|
||||
this.startActivity(new Intent(this, NewContactActivity.class));
|
||||
break;
|
||||
case R.id.share:
|
||||
qrShowFragment.shareInviteURL();
|
||||
break;
|
||||
case R.id.copy:
|
||||
qrShowFragment.copyQrData();
|
||||
break;
|
||||
case R.id.withdraw:
|
||||
qrShowFragment.withdrawQr();
|
||||
break;
|
||||
@@ -206,6 +199,11 @@ public class QrActivity extends BaseActionBarActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
viewPager.setCurrentItem(TAB_SCAN);
|
||||
}
|
||||
|
||||
private class ProfilePagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
private final QrActivity activity;
|
||||
|
||||
@@ -85,12 +85,6 @@ public class QrShowActivity extends AppCompatActivity {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.share:
|
||||
fragment.shareInviteURL();
|
||||
break;
|
||||
case R.id.copy:
|
||||
fragment.copyQrData();
|
||||
break;
|
||||
case R.id.withdraw:
|
||||
fragment.withdrawQr();
|
||||
break;
|
||||
|
||||
@@ -9,6 +9,8 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -46,6 +48,17 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
|
||||
|
||||
private DcContext dcContext;
|
||||
|
||||
private View.OnClickListener scanClicklistener;
|
||||
|
||||
public QrShowFragment() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public QrShowFragment(View.OnClickListener scanClicklistener) {
|
||||
super();
|
||||
this.scanClicklistener = scanClicklistener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
@@ -86,7 +99,14 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
view.findViewById(R.id.share_link_button).setOnClickListener((v) -> shareInviteURL());
|
||||
view.findViewById(R.id.share_link_button).setOnClickListener((v) -> showInviteLinkDialog());
|
||||
Button scanBtn = view.findViewById(R.id.scan_qr_button);
|
||||
if (scanClicklistener != null) {
|
||||
scanBtn.setVisibility(View.VISIBLE);
|
||||
scanBtn.setOnClickListener(scanClicklistener);
|
||||
} else {
|
||||
scanBtn.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
@@ -129,6 +149,19 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
|
||||
builder.create().show();
|
||||
}
|
||||
|
||||
public void showInviteLinkDialog() {
|
||||
View view = View.inflate(getActivity(), R.layout.dialog_share_invite_link, null);
|
||||
String inviteURL = Util.QrDataToInviteURL(dcContext.getSecurejoinQr(chatId));
|
||||
((TextView)view.findViewById(R.id.invite_link)).setText(inviteURL);
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setView(view)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setNeutralButton(R.string.menu_copy_to_clipboard, (d, b) -> copyQrData())
|
||||
.setPositiveButton(R.string.menu_share, (d, b) -> shareInviteURL())
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Reference in New Issue
Block a user