diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1a679f0..81d652c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,7 +10,9 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme.ColorBlind"> - + @@ -19,10 +21,13 @@ - + \ No newline at end of file diff --git a/app/src/main/java/edu/umd/cmsc436/mstestsuite/MainActivity.java b/app/src/main/java/edu/umd/cmsc436/mstestsuite/MainActivity.java index dd05c51..132cddf 100644 --- a/app/src/main/java/edu/umd/cmsc436/mstestsuite/MainActivity.java +++ b/app/src/main/java/edu/umd/cmsc436/mstestsuite/MainActivity.java @@ -40,6 +40,7 @@ import java.util.Comparator; import edu.umd.cmsc436.mstestsuite.data.ActionsAdapter; +import edu.umd.cmsc436.mstestsuite.ui.CoordinatorActivity; import edu.umd.cmsc436.sheets.Sheets; public class MainActivity extends AppCompatActivity implements MainContract.View, Sheets.Host { @@ -308,6 +309,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { mPresenter.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_INSTALL) { mPresenter.onPackageInstalled(); + } else if (requestCode == CoordinatorActivity.REQUEST_CODE) { + mPresenter.onCoordinatorDone(); } } @@ -341,6 +344,12 @@ public Activity getActivity() { @Override public void installPackage(File f) throws IOException { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + mInstallCache = f; + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_PERMISSION); + return; + } + FileChannel inChannel = new FileInputStream(f).getChannel(); File downloadsFolder = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); @@ -354,13 +363,6 @@ public void installPackage(File f) throws IOException { FileChannel outChannel = new FileOutputStream(outFile).getChannel(); - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - mInstallCache = f; - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_PERMISSION); - return; - } - - try { inChannel.transferTo(0, inChannel.size(), outChannel); } finally { diff --git a/app/src/main/java/edu/umd/cmsc436/mstestsuite/MainContract.java b/app/src/main/java/edu/umd/cmsc436/mstestsuite/MainContract.java index f84bbb4..d730ff0 100644 --- a/app/src/main/java/edu/umd/cmsc436/mstestsuite/MainContract.java +++ b/app/src/main/java/edu/umd/cmsc436/mstestsuite/MainContract.java @@ -48,5 +48,6 @@ interface Presenter { void onActivityResult(int requestCode, int resultCode, Intent data); void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults); void onPackageInstalled (); + void onCoordinatorDone (); } } diff --git a/app/src/main/java/edu/umd/cmsc436/mstestsuite/MainPresenter.java b/app/src/main/java/edu/umd/cmsc436/mstestsuite/MainPresenter.java index 6a9835f..8f5782f 100644 --- a/app/src/main/java/edu/umd/cmsc436/mstestsuite/MainPresenter.java +++ b/app/src/main/java/edu/umd/cmsc436/mstestsuite/MainPresenter.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.design.widget.BottomSheetBehavior; import android.util.Log; import java.io.File; @@ -52,11 +53,19 @@ public void run() { } }), new Action("Feedback", R.drawable.ic_feedback, null), + new Action("Refresh", R.drawable.ic_refresh_prescription, new Runnable() { + @Override + public void run() { + mMainAdapter.setEnabled(0, false); + mSheet.fetchPrescription(mUserManager.getCurUserID(), MainPresenter.this); + } + }) }; private MainContract.View mView; private boolean isPractice; + private boolean isBottomSheetExpanded; private Map mToInstall; private UserManager mUserManager; @@ -73,6 +82,7 @@ public void run() { mView.hideBottomSheet(); isPractice = false; + isBottomSheetExpanded = false; mUserManager = new UserManager(mView.getContext()); if (mUserManager.getCurUserID() == null) { @@ -100,12 +110,13 @@ public void run() { @Override public void onDailyStart() { - CoordinatorActivity.start(mView.getContext(), mUserManager.getCurUserID(), mAllDifficulties, mNumTrials); + CoordinatorActivity.start(mView.getActivity(), mUserManager.getCurUserID(), mAllDifficulties, mNumTrials); } @Override public void onCloseBottomSheet() { mView.collapseBottomSheet(); + isBottomSheetExpanded = false; } @Override @@ -115,12 +126,16 @@ public void onBottomSheetSlide() { @Override public void onBottomSheetStateChange(int newState) { - // nothing + isBottomSheetExpanded = newState == BottomSheetBehavior.STATE_EXPANDED; } @Override public boolean onBackPressed() { - if (isPractice) { + if (isBottomSheetExpanded) { + isBottomSheetExpanded = false; + mView.collapseBottomSheet(); + return false; + } else if (isPractice) { isPractice = false; mView.loadActions(mMainAdapter); return false; @@ -161,6 +176,12 @@ public void onPackageInstalled() { installFirst(); } + @Override + public void onCoordinatorDone() { + mView.hideBottomSheet(); + isBottomSheetExpanded = false; + } + @Override public void onAppSelected(TestApp app) { try { @@ -271,6 +292,7 @@ public void onCheckFinished(Map versionMap) { public void run() { mMainAdapter.setEnabled(0, true); mView.expandBottomSheet(); + isBottomSheetExpanded = true; } }); } diff --git a/app/src/main/java/edu/umd/cmsc436/mstestsuite/ui/CoordinatorActivity.java b/app/src/main/java/edu/umd/cmsc436/mstestsuite/ui/CoordinatorActivity.java index 1ac697f..6cdba9d 100644 --- a/app/src/main/java/edu/umd/cmsc436/mstestsuite/ui/CoordinatorActivity.java +++ b/app/src/main/java/edu/umd/cmsc436/mstestsuite/ui/CoordinatorActivity.java @@ -1,7 +1,7 @@ package edu.umd.cmsc436.mstestsuite.ui; import android.annotation.SuppressLint; -import android.content.Context; +import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; @@ -24,13 +24,14 @@ public class CoordinatorActivity extends AppCompatActivity implements Sheets.Hos private static final String KEY_PID = "patient id"; private static final String KEY_DIFFICULTIES = "difficulties"; private static final String KEY_N_TRIALS = "number of trials"; + public static final int REQUEST_CODE = 789; - public static void start(Context context, String patientId, int[] difficulties, int n_trials) { - Intent starter = new Intent(context, CoordinatorActivity.class); + public static void start(Activity activity, String patientId, int[] difficulties, int n_trials) { + Intent starter = new Intent(activity, CoordinatorActivity.class); starter.putExtra(KEY_PID, patientId); starter.putExtra(KEY_DIFFICULTIES, difficulties); starter.putExtra(KEY_N_TRIALS, n_trials); - context.startActivity(starter); + activity.startActivityForResult(starter, REQUEST_CODE); } private String mCurPatient; diff --git a/app/src/main/res/drawable/ic_refresh_prescription.xml b/app/src/main/res/drawable/ic_refresh_prescription.xml new file mode 100644 index 0000000..1783fbb --- /dev/null +++ b/app/src/main/res/drawable/ic_refresh_prescription.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_intro_1.xml b/app/src/main/res/layout/activity_intro_1.xml index 927c84d..8f36444 100644 --- a/app/src/main/res/layout/activity_intro_1.xml +++ b/app/src/main/res/layout/activity_intro_1.xml @@ -1,10 +1,10 @@ + android:id="@+id/linearLayout2" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:padding="@dimen/fab_margin"> + android:textStyle="bold"/> + android:textAppearance="?android:textAppearanceLarge" + android:textColor="@android:color/black"/> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9d43abd..0d4f9e3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,10 +12,7 @@ Welcome, %s Icon for current test - This application is designed to … \n\n There will be a - number of tests that you will complete on a given day. When you do not have a selection - of tests to perform for a day, you can practice these tests through this app as well. - \n\n You also are able to track your progress among each test. + This application is designed to track your performance on various tests.\n\nEach time you open this application, if you have tests assigned by your doctor, there will be a pop-up asking you to complete them. If you choose not to complete them in that given moment, you can come back to them by clicking the DAILY button. You also have the option to practice the various tests prescribed. You are also able to track your progress within each test.\n\nIf there are problems when completing your test, you can go to the feedback section to report the problems, which will be sent to your doctor. ENTER NEXT Welcome to the Test Suite