Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

fix: using app without odk collect installed #338

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class MainActivity extends FormListActivity implements LoaderManager.Load
private static final String FORM_CHOOSER_LIST_SORTING_ORDER = "formChooserListSortingOrder";
private static final String COLLECT_PACKAGE = "org.odk.collect.android";
private static final int STORAGE_PERMISSION_REQUEST_CODE = 101;
private static final int COLLECT_INSTALL_REQUEST_CODE = 102;
private static final int FORM_LOADER = 2;

@BindView(R.id.toolbar)
Expand Down Expand Up @@ -213,9 +214,12 @@ private void showAlertDialog() {

builder.setPositiveButton(getString(R.string.install), (DialogInterface dialog, int which) -> {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + COLLECT_PACKAGE)));
startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + COLLECT_PACKAGE)),
COLLECT_INSTALL_REQUEST_CODE);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + COLLECT_PACKAGE)));
startActivityForResult(new Intent(Intent.ACTION_VIEW,
naman653 marked this conversation as resolved.
Show resolved Hide resolved
Uri.parse("https://play.google.com/store/apps/details?id=" + COLLECT_PACKAGE)),
COLLECT_INSTALL_REQUEST_CODE);
}
});

Expand Down Expand Up @@ -277,6 +281,11 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
setUpLoader();
}
}
if (requestCode == COLLECT_INSTALL_REQUEST_CODE) {
if (!isCollectInstalled()) {
setUpLoader();
}
}
}

private void setUpLoader() {
Expand Down