Commit 5535b46e authored by Adrien Béraud's avatar Adrien Béraud

qr scan: open conversation on scan

Change-Id: Idcf0d32f8a5e92b437e7ad4822e49aa6e84c92a0
parent 1a5085f4
......@@ -361,6 +361,20 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
mDisposable.clear();
}
public void startConversation(String conversationId) {
mDisposable.add(mAccountService.getCurrentAccountSubject()
.firstElement()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(account -> startConversation(account.getAccountID(), new cx.ring.model.Uri(conversationId))));
}
public void startConversation(String accountId, cx.ring.model.Uri conversationId) {
if (!DeviceUtils.isTablet(this)) {
startActivity(new Intent(Intent.ACTION_VIEW, ConversationPath.toUri(accountId, conversationId.toString()), this, ConversationActivity.class));
} else {
startConversationTablet(ConversationPath.toBundle(accountId, conversationId.toString()));
}
}
public void startConversationTablet(Bundle bundle) {
fConversation = new ConversationFragment();
fConversation.setArguments(bundle);
......@@ -553,11 +567,7 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
intent.setAction(AccountConfig.ACCOUNT_TYPE_SIP);
}
startActivity(intent);
Account account = mAccountService.getCurrentAccount();
if (account != null) {
binding.spinnerToolbar.setSelection(mAccountService.getAccountList().indexOf(account.getAccountID()));
}
binding.spinnerToolbar.setSelection(mAccountService.getCurrentAccountIndex());
}
}
......
......@@ -197,7 +197,7 @@ public class DRingService extends Service {
@Override
public List<String> getAccountList() {
return mAccountService.getAccountList();
return mAccountService.getAccountList().blockingGet();
}
@Override
......
......@@ -50,6 +50,7 @@ import java.util.List;
import cx.ring.R;
import cx.ring.application.JamiApplication;
import cx.ring.client.HomeActivity;
import cx.ring.fragments.ConversationFragment;
import cx.ring.mvp.BaseSupportFragment;
......@@ -82,26 +83,14 @@ public class ScanFragment extends BaseSupportFragment {
return rootView;
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
mIsVisible = isVisibleToUser;
if (mIsVisible && mIsStarted) {
checkPermission();
}
}
@Override
public void onResume() {
super.onResume();
if (hasCameraPermission() && barcodeView != null) {
if (checkPermission() && barcodeView != null) {
barcodeView.resume();
}
}
@Override
public void onPause() {
super.onPause();
......@@ -175,7 +164,7 @@ public class ScanFragment extends BaseSupportFragment {
}
}
private BarcodeCallback callback = new BarcodeCallback() {
private final BarcodeCallback callback = new BarcodeCallback() {
@Override
public void barcodeResult(@NonNull BarcodeResult result) {
if (result.getText() != null) {
......@@ -192,20 +181,19 @@ public class ScanFragment extends BaseSupportFragment {
};
private void goToConversation(String contactId) {
Intent intent = new Intent().
putExtra(ConversationFragment.KEY_CONTACT_RING_ID, contactId);
getActivity().setResult(Activity.RESULT_OK, intent);
getActivity().finish();
((HomeActivity) requireActivity()).startConversation(contactId);
}
private void checkPermission() {
private boolean checkPermission() {
if (!hasCameraPermission()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.CAMERA}, JamiApplication.PERMISSIONS_REQUEST);
} else {
displayNoPermissionsError();
}
return false;
}
return true;
}
}
......@@ -502,6 +502,9 @@ public class AccountService {
public Account getCurrentAccount() {
return mCurrentAccount;
}
public int getCurrentAccountIndex() {
return mAccountList.indexOf(mCurrentAccount);
}
/**
* Sets the current Account in the local cache (also sends a ACCOUNTS_CHANGED event)
......@@ -653,16 +656,9 @@ public class AccountService {
/**
* @return Account Ids list from Daemon
*/
public List<String> getAccountList() {
try {
return mExecutor.submit(() -> {
Log.i(TAG, "getAccountList() running...");
return new ArrayList<>(Ringservice.getAccountList());
}).get();
} catch (Exception e) {
Log.e(TAG, "Error running getAccountList()", e);
}
return new ArrayList<>();
public Single<List<String>> getAccountList() {
return Single.fromCallable(() -> (List<String>)new ArrayList<>(Ringservice.getAccountList()))
.subscribeOn(Schedulers.from(mExecutor));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment