Search in sources :

Example 1 with BaseFragmentActivity

use of org.edx.mobile.base.BaseFragmentActivity in project edx-app-android by edx.

the class NavigationFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    drawerNavigationBinding = DataBindingUtil.inflate(inflater, R.layout.drawer_navigation, container, false);
    if (config.isUserProfilesEnabled()) {
        if (null != profileImage) {
            loadProfileImage(profileImage, drawerNavigationBinding.profileImage);
        }
        if (profile != null && profile.username != null) {
            drawerNavigationBinding.profileImage.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    final BaseFragmentActivity act = (BaseFragmentActivity) getActivity();
                    act.closeDrawer();
                    if (!(act instanceof UserProfileActivity)) {
                        environment.getRouter().showUserProfileWithNavigationDrawer(getActivity(), profile.username);
                        if (!(act instanceof MyCoursesListActivity)) {
                            act.finish();
                        }
                    }
                }
            });
        }
    } else {
        drawerNavigationBinding.profileImage.setVisibility(View.GONE);
        drawerNavigationBinding.navigationHeaderLayout.setClickable(false);
        drawerNavigationBinding.navigationHeaderLayout.setForeground(null);
    }
    drawerNavigationBinding.drawerOptionMyCourses.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Activity act = getActivity();
            ((BaseFragmentActivity) act).closeDrawer();
            if (!(act instanceof MyCoursesListActivity)) {
                environment.getRouter().showMyCourses(act);
                act.finish();
            }
        }
    });
    if (environment.getConfig().getCourseDiscoveryConfig().isCourseDiscoveryEnabled()) {
        drawerNavigationBinding.drawerOptionFindCourses.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                AnalyticsRegistry analyticsRegistry = environment.getAnalyticsRegistry();
                analyticsRegistry.trackUserFindsCourses();
                FragmentActivity act = getActivity();
                ((BaseFragmentActivity) act).closeDrawer();
                if (!(act instanceof WebViewFindCoursesActivity || act instanceof NativeFindCoursesActivity)) {
                    environment.getRouter().showFindCourses(act);
                    // the student should be returned to the MyCourses screen
                    if (!(act instanceof MyCoursesListActivity)) {
                        act.finish();
                    }
                }
            }
        });
        if (config.getCourseDiscoveryConfig().isWebviewCourseDiscoveryEnabled()) {
            drawerNavigationBinding.drawerOptionFindCourses.setText(R.string.label_discover);
        } else {
            drawerNavigationBinding.drawerOptionFindCourses.setText(R.string.label_find_courses);
        }
    } else {
        drawerNavigationBinding.drawerOptionFindCourses.setVisibility(View.GONE);
    }
    drawerNavigationBinding.drawerOptionAccount.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            Activity act = getActivity();
            ((BaseFragmentActivity) act).closeDrawer();
            if (!(act instanceof AccountActivity)) {
                environment.getRouter().showAccountActivity(act);
                if (!(act instanceof MyCoursesListActivity)) {
                    act.finish();
                }
            }
        }
    });
    if (profile != null) {
        if (profile.name != null) {
            drawerNavigationBinding.nameTv.setText(profile.name);
            drawerNavigationBinding.nameTv.setContentDescription(ResourceUtil.getFormattedString(getResources(), R.string.navigation_header, "username", profile.name));
        }
    }
    return drawerNavigationBinding.getRoot();
}
Also used : BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) FragmentActivity(android.support.v4.app.FragmentActivity) BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) OnClickListener(android.view.View.OnClickListener) UserProfileActivity(org.edx.mobile.profiles.UserProfileActivity) BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) FragmentActivity(android.support.v4.app.FragmentActivity) Activity(android.app.Activity) AnalyticsRegistry(org.edx.mobile.module.analytics.AnalyticsRegistry) ImageView(android.widget.ImageView) View(android.view.View) UserProfileActivity(org.edx.mobile.profiles.UserProfileActivity)

Example 2 with BaseFragmentActivity

use of org.edx.mobile.base.BaseFragmentActivity in project edx-app-android by edx.

the class BaseFragmentActivityTest method setTitleTest.

/**
 * Testing title setup
 */
@Test
public void setTitleTest() {
    BaseFragmentActivity activity = Robolectric.buildActivity(getActivityClass()).withIntent(getIntent()).create().get();
    CharSequence title = "test";
    activity.setTitle(title);
    assertTitle(activity, title);
}
Also used : BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) Test(org.junit.Test)

Example 3 with BaseFragmentActivity

use of org.edx.mobile.base.BaseFragmentActivity in project edx-app-android by edx.

the class BaseFragmentActivityTest method animateLayoutsTest.

/**
 * Testing view animation methods
 */
@Test
public void animateLayoutsTest() {
    final BaseFragmentActivity activity = Robolectric.buildActivity(getActivityClass()).withIntent(getIntent()).setup().get();
    final View view = new View(activity);
    view.setVisibility(View.GONE);
    activity.addContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    assertAnimateLayouts(view, new Runnable() {

        @Override
        public void run() {
            activity.animateLayouts(view);
        }
    });
    activity.stopAnimation(view);
    assertThat(view).hasAnimation(null);
}
Also used : BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) ViewGroup(android.view.ViewGroup) View(android.view.View) TextView(android.widget.TextView) Test(org.junit.Test)

Example 4 with BaseFragmentActivity

use of org.edx.mobile.base.BaseFragmentActivity in project edx-app-android by edx.

the class BaseFragmentActivityTest method tryToSetUIInteractionTest.

/**
 * Testing method for enabling and disabling UI interaction
 */
@Test
public void tryToSetUIInteractionTest() {
    BaseFragmentActivity activity = Robolectric.buildActivity(getActivityClass()).withIntent(getIntent()).setup().get();
    assertFalse(activity.tryToSetUIInteraction(true));
    assertFalse(activity.tryToSetUIInteraction(false));
}
Also used : BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) Test(org.junit.Test)

Example 5 with BaseFragmentActivity

use of org.edx.mobile.base.BaseFragmentActivity in project edx-app-android by edx.

the class VideoDownloadHelper method startDownloadVideos.

private void startDownloadVideos(List<? extends HasDownloadEntry> model, FragmentActivity activity, DownloadManagerCallback callback) {
    long downloadSize = 0;
    ArrayList<DownloadEntry> downloadList = new ArrayList<>();
    int downloadCount = 0;
    for (HasDownloadEntry v : model) {
        DownloadEntry de = v.getDownloadEntry(storage);
        if (!TextUtils.isEmpty(v.getDownloadUrl())) {
            // Prefer download url to download
            de.url = v.getDownloadUrl();
        }
        if (null == de || de.downloaded == DownloadEntry.DownloadedState.DOWNLOADING || de.downloaded == DownloadEntry.DownloadedState.DOWNLOADED || de.isVideoForWebOnly) {
            continue;
        } else {
            downloadSize = downloadSize + de.getSize();
            downloadList.add(de);
            downloadCount++;
        }
    }
    if (downloadSize > MemoryUtil.getAvailableExternalMemory(activity)) {
        ((BaseFragmentActivity) activity).showInfoMessage(activity.getString(R.string.file_size_exceeded));
        callback.updateListUI();
        EventBus.getDefault().post(new BulkVideosDownloadCancelledEvent());
    } else {
        if (isDownloadSizeWithinLimit(downloadSize, MemoryUtil.GB) && !downloadList.isEmpty()) {
            startDownload(downloadList, activity, callback);
            final DownloadEntry downloadEntry = downloadList.get(0);
            analyticsRegistry.trackSubSectionBulkVideoDownload(downloadEntry.getSectionName(), downloadEntry.getChapterName(), downloadEntry.getEnrollmentId(), downloadCount);
        } else {
            showDownloadSizeExceedDialog(downloadList, downloadCount, activity, callback);
        }
    }
}
Also used : BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) ArrayList(java.util.ArrayList) BulkVideosDownloadCancelledEvent(org.edx.mobile.module.storage.BulkVideosDownloadCancelledEvent) HasDownloadEntry(org.edx.mobile.model.course.HasDownloadEntry) DownloadEntry(org.edx.mobile.model.db.DownloadEntry) HasDownloadEntry(org.edx.mobile.model.course.HasDownloadEntry)

Aggregations

BaseFragmentActivity (org.edx.mobile.base.BaseFragmentActivity)7 Test (org.junit.Test)5 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 TextView (android.widget.TextView)2 Activity (android.app.Activity)1 Configuration (android.content.res.Configuration)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 FragmentManager (android.support.v4.app.FragmentManager)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBar (android.support.v7.app.ActionBar)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 ArrayList (java.util.ArrayList)1 HasDownloadEntry (org.edx.mobile.model.course.HasDownloadEntry)1 DownloadEntry (org.edx.mobile.model.db.DownloadEntry)1 AnalyticsRegistry (org.edx.mobile.module.analytics.AnalyticsRegistry)1 BulkVideosDownloadCancelledEvent (org.edx.mobile.module.storage.BulkVideosDownloadCancelledEvent)1 UserProfileActivity (org.edx.mobile.profiles.UserProfileActivity)1 ShadowActivity (org.robolectric.shadows.ShadowActivity)1