mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
add "add transport" floating button
This commit is contained in:
@@ -44,6 +44,8 @@ import java.io.InputStream;
|
||||
public class QrActivity extends BaseActionBarActivity implements View.OnClickListener {
|
||||
|
||||
private final static String TAG = QrActivity.class.getSimpleName();
|
||||
public final static String EXTRA_SCAN_RELAY = "scan_relay";
|
||||
|
||||
private final static int REQUEST_CODE_IMAGE = 46243;
|
||||
private final static int TAB_SHOW = 0;
|
||||
private final static int TAB_SCAN = 1;
|
||||
@@ -51,6 +53,7 @@ public class QrActivity extends BaseActionBarActivity implements View.OnClickLis
|
||||
private TabLayout tabLayout;
|
||||
private ViewPager viewPager;
|
||||
private QrShowFragment qrShowFragment;
|
||||
private boolean scanRelay;
|
||||
|
||||
@Override
|
||||
protected void onPreCreate() {
|
||||
@@ -61,8 +64,10 @@ public class QrActivity extends BaseActionBarActivity implements View.OnClickLis
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_qr);
|
||||
|
||||
scanRelay = getIntent().getBooleanExtra(EXTRA_SCAN_RELAY, false);
|
||||
|
||||
qrShowFragment = new QrShowFragment(this);
|
||||
tabLayout = ViewUtil.findById(this, R.id.tab_layout);
|
||||
viewPager = ViewUtil.findById(this, R.id.pager);
|
||||
@@ -71,10 +76,11 @@ public class QrActivity extends BaseActionBarActivity implements View.OnClickLis
|
||||
|
||||
setSupportActionBar(ViewUtil.findById(this, R.id.toolbar));
|
||||
assert getSupportActionBar() != null;
|
||||
getSupportActionBar().setTitle(R.string.menu_new_contact);
|
||||
getSupportActionBar().setTitle(scanRelay? R.string.add_transport : R.string.menu_new_contact);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
viewPager.setCurrentItem(TAB_SHOW);
|
||||
viewPager.setCurrentItem(scanRelay? TAB_SCAN : TAB_SHOW);
|
||||
if (scanRelay) tabLayout.setVisibility(View.GONE);
|
||||
|
||||
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
@@ -102,7 +108,13 @@ public class QrActivity extends BaseActionBarActivity implements View.OnClickLis
|
||||
.ifNecessary()
|
||||
.withPermanentDenialDialog(getString(R.string.perm_explain_access_to_camera_denied))
|
||||
.onAllGranted(() -> ((QrScanFragment) adapter.getItem(TAB_SCAN)).handleQrScanWithPermissions(QrActivity.this))
|
||||
.onAnyDenied(() -> viewPager.setCurrentItem(TAB_SHOW))
|
||||
.onAnyDenied(() -> {
|
||||
if (scanRelay) {
|
||||
finish();
|
||||
} else {
|
||||
viewPager.setCurrentItem(TAB_SHOW);
|
||||
}
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
@@ -149,7 +161,11 @@ public class QrActivity extends BaseActionBarActivity implements View.OnClickLis
|
||||
if (permissions.length > 0
|
||||
&& Manifest.permission.CAMERA.equals(permissions[0])
|
||||
&& grantResults[0] == PackageManager.PERMISSION_DENIED) {
|
||||
viewPager.setCurrentItem(TAB_SHOW);
|
||||
if (scanRelay) {
|
||||
finish();
|
||||
} else {
|
||||
viewPager.setCurrentItem(TAB_SHOW);
|
||||
}
|
||||
// Workaround because sometimes something else requested the permissions before this class
|
||||
// (probably the CameraView) and then this class didn't notice when it was denied
|
||||
}
|
||||
|
||||
@@ -12,9 +12,18 @@ import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcEvent;
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
import org.thoughtcrime.securesms.BaseActionBarActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.registration.PulsingFloatingActionButton;
|
||||
import org.thoughtcrime.securesms.connect.DcEventCenter;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.qr.QrActivity;
|
||||
import org.thoughtcrime.securesms.qr.QrCodeHandler;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
@@ -25,7 +34,7 @@ import chat.delta.rpc.RpcException;
|
||||
import chat.delta.rpc.types.EnteredLoginParam;
|
||||
|
||||
public class RelayListActivity extends BaseActionBarActivity
|
||||
implements RelayListAdapter.OnRelayClickListener {
|
||||
implements RelayListAdapter.OnRelayClickListener, DcEventCenter.DcEventDelegate {
|
||||
|
||||
private static final String TAG = RelayListActivity.class.getSimpleName();
|
||||
|
||||
@@ -48,9 +57,16 @@ public class RelayListActivity extends BaseActionBarActivity
|
||||
}
|
||||
|
||||
RecyclerView recyclerView = findViewById(R.id.relay_list);
|
||||
PulsingFloatingActionButton fabAdd = findViewById(R.id.fab_add_relay);
|
||||
|
||||
// add padding to avoid content hidden behind system bars
|
||||
ViewUtil.applyWindowInsets(recyclerView);
|
||||
// Apply insets to prevent fab from being covered by system bars
|
||||
ViewUtil.applyWindowInsetsAsMargin(fabAdd);
|
||||
|
||||
fabAdd.setOnClickListener(v -> {
|
||||
new IntentIntegrator(this).setCaptureActivity(QrActivity.class).addExtra(QrActivity.EXTRA_SCAN_RELAY, true).initiateScan();
|
||||
});
|
||||
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
// Add the default divider (uses the theme’s `android.R.attr.listDivider`)
|
||||
@@ -64,6 +80,15 @@ public class RelayListActivity extends BaseActionBarActivity
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
loadRelays();
|
||||
|
||||
DcEventCenter eventCenter = DcHelper.getEventCenter(this);
|
||||
eventCenter.addObserver(DcContext.DC_EVENT_CONFIGURE_PROGRESS, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
DcHelper.getEventCenter(this).removeObservers(this);
|
||||
}
|
||||
|
||||
private void loadRelays() {
|
||||
@@ -134,4 +159,22 @@ public class RelayListActivity extends BaseActionBarActivity
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == IntentIntegrator.REQUEST_CODE) {
|
||||
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||
QrCodeHandler qrCodeHandler = new QrCodeHandler(this);
|
||||
qrCodeHandler.onScanPerformed(scanResult);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEvent(@NonNull DcEvent event) {
|
||||
int eventId = event.getId();
|
||||
if (eventId == DcContext.DC_EVENT_CONFIGURE_PROGRESS && event.getData1Int() == 1000) {
|
||||
loadRelays();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user