Search in sources :

Example 1 with Prefs

use of com.instructure.pandautils.utils.Prefs in project instructure-android by instructure.

the class BaseParentActivity method handleError.

public void handleError(int code, String error) {
    if (code == 418) {
        // Parse the message from the response body
        Gson gson = new Gson();
        JsonParser parser = new JsonParser();
        JsonElement mJson = parser.parse(error);
        RevokedTokenResponse revokedTokenResponse = gson.fromJson(mJson, RevokedTokenResponse.class);
        showRevokedTokenDialog(revokedTokenResponse, this);
    }
    if (code == 403) {
        // Parse the message from the response body
        Gson gson = new Gson();
        JsonParser parser = new JsonParser();
        JsonElement mJson = parser.parse(error);
        BlockedStudentResponse blockedStudentResponse = gson.fromJson(mJson, BlockedStudentResponse.class);
        if (blockedStudentResponse.code.equals("studentBlocked")) {
            Prefs prefs = new Prefs(this, getString(R.string.app_name_parent));
            String parentId = prefs.load(Const.ID, "");
            // We want to refresh cache so the main activity can load quickly with accurate information
            UserManager.getStudentsForParentAirwolf(ApiPrefs.getAirwolfDomain(), parentId, new StatusCallback<List<Student>>() {

                @Override
                public void onResponse(@NonNull Response<List<Student>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                    if (response.body() != null && !response.body().isEmpty()) {
                        // They have students that they are observing, take them to that activity
                        startActivity(StudentViewActivity.createIntent(BaseParentActivity.this, response.body()));
                        overridePendingTransition(0, 0);
                        finish();
                    } else {
                        // Take the parent to the add user page.
                        FindSchoolActivity.Companion.createIntent(BaseParentActivity.this, true);
                        finish();
                    }
                }
            });
        }
    }
    if (code == 451) {
        // Parse the message from the response body
        Gson gson = new Gson();
        JsonParser parser = new JsonParser();
        JsonElement mJson = parser.parse(error);
        MismatchedRegionResponse mismatchedRegionResponse = gson.fromJson(mJson, MismatchedRegionResponse.class);
        showMismatchedRegionDialog(mismatchedRegionResponse.getStudentRegion(), this);
    }
}
Also used : BlockedStudentResponse(com.instructure.canvasapi2.models.BlockedStudentResponse) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Gson(com.google.gson.Gson) Prefs(com.instructure.pandautils.utils.Prefs) ApiPrefs(com.instructure.canvasapi2.utils.ApiPrefs) MismatchedRegionResponse(com.instructure.canvasapi2.models.MismatchedRegionResponse) RevokedTokenResponse(com.instructure.canvasapi2.models.RevokedTokenResponse) JsonElement(com.google.gson.JsonElement) ApiType(com.instructure.canvasapi2.utils.ApiType) List(java.util.List) JsonParser(com.google.gson.JsonParser)

Example 2 with Prefs

use of com.instructure.pandautils.utils.Prefs in project instructure-android by instructure.

the class BaseParentActivity method showMismatchedRegionDialog.

private void showMismatchedRegionDialog(final String regionString, final Context context) {
    new AlertDialog.Builder(context).setTitle(R.string.unauthorizedRegion).setMessage(getString(R.string.mismatchedRegionMessage, getReadableRegion(this, regionString))).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Prefs prefs = new Prefs(BaseParentActivity.this, getString(R.string.app_name_parent));
            String parentId = prefs.load(Const.ID, "");
            UserManager.getStudentsForParentAirwolf(ApiPrefs.getAirwolfDomain(), parentId, new StatusCallback<List<Student>>() {

                @Override
                public void onResponse(@NonNull Response<List<Student>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                    if (response.body() != null && !response.body().isEmpty()) {
                        // They have students that they are observing, take them to that activity
                        startActivity(StudentViewActivity.createIntent(BaseParentActivity.this, response.body()));
                        overridePendingTransition(0, 0);
                        finish();
                    } else {
                        // Log the user out
                        new LogoutAsyncTask(BaseParentActivity.this, "").execute();
                    }
                }
            });
        }
    }).setCancelable(false).show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) StatusCallback(com.instructure.canvasapi2.StatusCallback) Prefs(com.instructure.pandautils.utils.Prefs) ApiPrefs(com.instructure.canvasapi2.utils.ApiPrefs) Student(com.instructure.canvasapi2.models.Student) RevokedTokenResponse(com.instructure.canvasapi2.models.RevokedTokenResponse) Response(retrofit2.Response) MismatchedRegionResponse(com.instructure.canvasapi2.models.MismatchedRegionResponse) BlockedStudentResponse(com.instructure.canvasapi2.models.BlockedStudentResponse) LogoutAsyncTask(com.instructure.parentapp.asynctask.LogoutAsyncTask) NonNull(android.support.annotation.NonNull) ApiType(com.instructure.canvasapi2.utils.ApiType)

Example 3 with Prefs

use of com.instructure.pandautils.utils.Prefs in project instructure-android by instructure.

the class HelpActivity method setupViews.

private void setupViews() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_close_white);
    toolbar.setNavigationContentDescription(R.string.close);
    toolbar.setTitle(R.string.help);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    // Will be empty for observers, still used for cached email for airwolf parent accounts
    Prefs prefs = new Prefs(HelpActivity.this, com.instructure.parentapp.util.Const.CANVAS_PARENT_SP);
    mEmailAddress = prefs.load(Const.NAME, "");
    mSearchGuides = (LinearLayout) findViewById(R.id.search_guides);
    mReportProblem = (LinearLayout) findViewById(R.id.report_problem);
    mRequestFeature = (LinearLayout) findViewById(R.id.request_feature);
    mShowLove = (LinearLayout) findViewById(R.id.share_love);
    mOpenSource = (LinearLayout) findViewById(R.id.open_source);
}
Also used : Prefs(com.instructure.pandautils.utils.Prefs) ApiPrefs(com.instructure.canvasapi2.utils.ApiPrefs) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 4 with Prefs

use of com.instructure.pandautils.utils.Prefs in project instructure-android by instructure.

the class StudentViewActivity method setupViews.

private void setupViews() {
    if (statusBarHeightId > 0) {
        // else it uses the default dimens in XML
        // Configure views to slide under status bar, will only effect > API 21
        int statusBarHeight = getResources().getDimensionPixelSize(statusBarHeightId);
        RelativeLayout root = (RelativeLayout) findViewById(R.id.rootView);
        RelativeLayout navigationWrapper = (RelativeLayout) findViewById(R.id.navigationWrapper);
        FrameLayout.LayoutParams rootParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
        rootParams.setMargins(0, -statusBarHeight, 0, 0);
        root.setLayoutParams(rootParams);
        navigationWrapper.setPadding(0, statusBarHeight, 0, 0);
    } else {
        RelativeLayout root = (RelativeLayout) findViewById(R.id.rootView);
        RelativeLayout navigationWrapper = (RelativeLayout) findViewById(R.id.navigationWrapper);
        FrameLayout.LayoutParams rootParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
        rootParams.setMargins(0, 0, 0, 0);
        root.setLayoutParams(rootParams);
        navigationWrapper.setPadding(0, 0, 0, 0);
    }
    mSettingsButton = (ImageButton) findViewById(R.id.settings);
    mStudentName = (TextView) findViewById(R.id.studentName);
    // Get the ViewPager and set it's PagerAdapter so that it can display items
    final ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    if (mPagerAdapter == null) {
        mPagerAdapter = new StudentActivityFragmentPagerAdapter(getSupportFragmentManager(), StudentViewActivity.this);
    }
    viewPager.setAdapter(mPagerAdapter);
    // When loading course page, alert page will need to be updated so we need to be sure to
    // keep all fragments in memory
    viewPager.setOffscreenPageLimit(2);
    // Give the TabLayout the ViewPager
    mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
    mTabLayout.setupWithViewPager(viewPager);
    mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            if (tab.getCustomView() != null) {
                tab.getCustomView().setAlpha(1f);
            }
            viewPager.setCurrentItem(tab.getPosition());
            // set the tab content description to the title of the tab, for a11y/testing
            tab.setContentDescription(tab.getText());
            onPageScrolled(mCarouselViewPager.getCurrentItem(), 0, 0);
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            if (tab.getCustomView() != null) {
                tab.getCustomView().setAlpha(.30f);
            }
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });
    // Iterate over all tabs and set the custom view
    for (int i = 0; i < mTabLayout.getTabCount(); i++) {
        TabLayout.Tab tab = mTabLayout.getTabAt(i);
        tab.setCustomView(mPagerAdapter.getTabView(i));
        if (i != viewPager.getCurrentItem()) {
            tab.getCustomView().setAlpha(.30f);
        }
    }
    configureUserCarousel();
    Prefs prefs = new Prefs(StudentViewActivity.this, com.instructure.parentapp.util.Const.CANVAS_PARENT_SP);
    int pos = prefs.load(Const.TAB, 0);
    if (pos != 0) {
        viewPager.setCurrentItem(pos);
    }
    // update unread count
    mPagerAdapter.setAlertFragmentUnreadCount(mUnreadAlertCount);
}
Also used : TabLayout(android.support.design.widget.TabLayout) FrameLayout(android.widget.FrameLayout) RelativeLayout(android.widget.RelativeLayout) StudentActivityFragmentPagerAdapter(com.instructure.parentapp.adapter.StudentActivityFragmentPagerAdapter) ApiPrefs(com.instructure.canvasapi2.utils.ApiPrefs) Prefs(com.instructure.pandautils.utils.Prefs) ViewPager(android.support.v4.view.ViewPager)

Example 5 with Prefs

use of com.instructure.pandautils.utils.Prefs in project instructure-android by instructure.

the class StudentViewActivity method onPause.

@Override
protected void onPause() {
    super.onPause();
    // save the position so when the parent comes back to this page it will load the student they were on last
    Prefs prefs = new Prefs(this, com.instructure.parentapp.util.Const.CANVAS_PARENT_SP);
    prefs.save(Const.POSITION, mCarouselViewPager.getCurrentItem());
    prefs.save(Const.TAB, mTabLayout.getSelectedTabPosition());
}
Also used : ApiPrefs(com.instructure.canvasapi2.utils.ApiPrefs) Prefs(com.instructure.pandautils.utils.Prefs)

Aggregations

Prefs (com.instructure.pandautils.utils.Prefs)12 ApiPrefs (com.instructure.canvasapi2.utils.ApiPrefs)9 View (android.view.View)6 TextView (android.widget.TextView)4 BindView (butterknife.BindView)2 BlockedStudentResponse (com.instructure.canvasapi2.models.BlockedStudentResponse)2 MismatchedRegionResponse (com.instructure.canvasapi2.models.MismatchedRegionResponse)2 RevokedTokenResponse (com.instructure.canvasapi2.models.RevokedTokenResponse)2 Student (com.instructure.canvasapi2.models.Student)2 ApiType (com.instructure.canvasapi2.utils.ApiType)2 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)2 ArgbEvaluator (android.animation.ArgbEvaluator)1 DialogInterface (android.content.DialogInterface)1 LayerDrawable (android.graphics.drawable.LayerDrawable)1 NonNull (android.support.annotation.NonNull)1 TabLayout (android.support.design.widget.TabLayout)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 ViewPager (android.support.v4.view.ViewPager)1 AlertDialog (android.support.v7.app.AlertDialog)1 RecyclerView (android.support.v7.widget.RecyclerView)1