Skip to content

Commit

Permalink
Merge pull request #15 from cmsc436/coordinator
Browse files Browse the repository at this point in the history
Coordinator
  • Loading branch information
0queue authored May 2, 2017
2 parents 23ed951 + 87baebd commit fcc1894
Show file tree
Hide file tree
Showing 12 changed files with 377 additions and 38 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':frontendhelper')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.3.1'
compile project(':frontendhelper')
testCompile 'junit:junit:4.12'
}
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".ui.CoordinatorActivity"
android:theme="@style/AppTheme.Fullscreen">
</activity>

<activity android:name=".MainActivity"/>
</application>
Expand Down
16 changes: 13 additions & 3 deletions app/src/main/java/edu/umd/cmsc436/mstestsuite/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class MainActivity extends AppCompatActivity implements MainContract.View
private Button mPeekButton;
private BottomSheetBehavior mBottomSheet;
private ImageView mCloseButton;
private View mSpacer;

private MainContract.Presenter mPresenter;

Expand All @@ -66,6 +67,9 @@ protected void onCreate(Bundle savedInstanceState) {

setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

mSpacer = findViewById(R.id.spacer);
findViewById(R.id.bottom_sheet).setNestedScrollingEnabled(false);

mInstallCache = null;

mPeekButton = (Button) findViewById(R.id.peeked_begin_button);
Expand Down Expand Up @@ -95,6 +99,13 @@ public void onClick(View v) {
}
});

findViewById(R.id.expanded_daily_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPresenter.onDailyStart();
}
});

mBottomSheet = BottomSheetBehavior.from(findViewById(R.id.bottom_sheet));
mBottomSheet.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
Expand Down Expand Up @@ -151,7 +162,6 @@ public void expandBottomSheet() {
runOnUiThread(new Runnable() {
@Override
public void run() {
mBottomSheet.setHideable(false);
mBottomSheet.setState(BottomSheetBehavior.STATE_EXPANDED);
}
});
Expand All @@ -162,8 +172,8 @@ public void collapseBottomSheet() {
runOnUiThread(new Runnable() {
@Override
public void run() {
mBottomSheet.setHideable(false);
mBottomSheet.setState(BottomSheetBehavior.STATE_COLLAPSED);
mSpacer.setVisibility(View.VISIBLE);
}
});
}
Expand All @@ -173,8 +183,8 @@ public void hideBottomSheet() {
runOnUiThread(new Runnable() {
@Override
public void run() {
mBottomSheet.setHideable(true);
mBottomSheet.setState(BottomSheetBehavior.STATE_HIDDEN);
mSpacer.setVisibility(View.GONE);
}
});
}
Expand Down
41 changes: 14 additions & 27 deletions app/src/main/java/edu/umd/cmsc436/mstestsuite/MainPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
Expand All @@ -19,6 +17,7 @@
import edu.umd.cmsc436.mstestsuite.data.ActionsAdapter;
import edu.umd.cmsc436.mstestsuite.data.TestApp;
import edu.umd.cmsc436.mstestsuite.model.UserManager;
import edu.umd.cmsc436.mstestsuite.ui.CoordinatorActivity;
import edu.umd.cmsc436.mstestsuite.util.PackageChecker;
import edu.umd.cmsc436.mstestsuite.util.PackageUtil;
import edu.umd.cmsc436.sheets.DriveApkTask;
Expand Down Expand Up @@ -65,6 +64,8 @@ public void run() {
private ActionsAdapter mPracticeModeAdapter;
private Sheets mSheet;
private TestApp[] mAllApps;
private int[] mAllDifficulties;
private int mNumTrials;
private ArrayList<TestApp> mDesiredApps;

MainPresenter(MainContract.View v) {
Expand All @@ -79,7 +80,7 @@ public void run() {
mUserManager = new UserManager(mView.getContext());
}

mAllApps = loadAppInfo();
mAllApps = PackageUtil.loadAppInfo(mView.getContext(), this);
mToInstall = new HashMap<>();

mMainAdapter = new ActionsAdapter(actions, mView.getContext().getString(R.string.main_actions_header, mUserManager.getCurUserID()));
Expand All @@ -97,32 +98,9 @@ public void run() {
mSheet.fetchPrescription(mUserManager.getCurUserID(), this);
}

private TestApp[] loadAppInfo() {
Resources res = mView.getContext().getResources();
TypedArray package_names = res.obtainTypedArray(R.array.test_prefixes);
TypedArray display_names = res.obtainTypedArray(R.array.display_names);
TypedArray icons = res.obtainTypedArray(R.array.icons);

TestApp[] apps = new TestApp[package_names.length()];
if (package_names.length() == display_names.length() && display_names.length() == icons.length()) {
for (int i = 0; i < package_names.length(); i++) {
apps[i] = new TestApp(package_names.getString(i), display_names.getString(i), icons.getResourceId(i, R.mipmap.ic_launcher), this);
}
} else {
Log.e(getClass().getCanonicalName(), "XML resource arrays not same length");
apps = new TestApp[0];
}

package_names.recycle();
display_names.recycle();
icons.recycle();

return apps;
}

@Override
public void onDailyStart() {
// TODO
CoordinatorActivity.start(mView.getContext(), mUserManager.getCurUserID(), mAllDifficulties, mNumTrials);
}

@Override
Expand Down Expand Up @@ -205,10 +183,18 @@ public void onPrescriptionFetched(@Nullable List<String> list) {
return;
}

try {
mNumTrials = Integer.parseInt(list.get(2));
} catch (NumberFormatException nfe) {
mNumTrials = 1;
}

mDesiredApps = new ArrayList<>();
mAllDifficulties = new int[mAllApps.length];
for (int i = 0; i < mAllApps.length; i++) {
try {
int difficulty = Integer.parseInt(list.get(i + 4));
mAllDifficulties[i] = difficulty;
if (difficulty > 0) {
mDesiredApps.add(mAllApps[i]);
}
Expand Down Expand Up @@ -284,6 +270,7 @@ public void onCheckFinished(Map<String, Float> versionMap) {
@Override
public void run() {
mMainAdapter.setEnabled(0, true);
mView.expandBottomSheet();
}
});
}
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/edu/umd/cmsc436/mstestsuite/data/TestApp.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package edu.umd.cmsc436.mstestsuite.data;

import edu.umd.cmsc436.sheets.Sheets;

/**
* Hold app information, not prescription info
*/

public class TestApp extends Action {
private String packageName;
private Sheets.TestType[] supportedAppendages;

public TestApp(final String packageName, String displayName, int iconResource, final Events callback) {
public TestApp(final String packageName, String displayName, int iconResource, CharSequence[] textArray, final Events callback) {
super(displayName, iconResource, null);
setAction(new Runnable() {
@Override
Expand All @@ -17,12 +20,20 @@ public void run() {
});
this.packageName = packageName;

supportedAppendages = new Sheets.TestType[textArray.length];
for (int i = 0; i < textArray.length; i++) {
supportedAppendages[i] = Sheets.TestType.valueOf(textArray[i].toString());
}
}

public String getPackageName() {
return packageName;
}

public Sheets.TestType[] getSupportedAppendages() {
return supportedAppendages;
}

public interface Events {
void onAppSelected (TestApp app);
}
Expand Down
Loading

0 comments on commit fcc1894

Please sign in to comment.