Search in sources :

Example 1 with DrawerGarment

use of com.github.eddieringle.android.libs.undergarment.widgets.DrawerGarment in project hubroid by EddieRingle.

the class BaseDashboardActivity method onCreate.

@Override
protected void onCreate(Bundle icicle, int layout) {
    super.onCreate(icicle, layout);
    if (icicle != null) {
        mShowingDash = icicle.getBoolean(EXTRA_SHOWING_DASH, false);
    }
    mDrawerGarment = new DrawerGarment(this, R.layout.dashboard);
    mDrawerGarment.setDrawerMaxWidth(Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics())));
    mDrawerGarment.setSlideTarget(DrawerGarment.SLIDE_TARGET_CONTENT);
    mDrawerGarment.setDrawerCallbacks(new DrawerGarment.IDrawerCallbacks() {

        @Override
        public void onDrawerOpened() {
            mShowingDash = true;
            supportInvalidateOptionsMenu();
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        @Override
        public void onDrawerClosed() {
            if (mTargetIntent == null) {
                mShowingDash = false;
                supportInvalidateOptionsMenu();
                getSupportActionBar().setDisplayHomeAsUpEnabled(false);
            } else {
                startActivity(mTargetIntent);
                overridePendingTransition(0, 0);
                finish();
            }
        }
    });
    if (getIntent() != null) {
        mFromDashboard = getIntent().getBooleanExtra(ARG_FROM_DASHBOARD, false);
        if (!mFromDashboard) {
            getDrawerGarment().setDrawerEnabled(false);
            mShowingDash = false;
        } else if (getIntent().hasExtra(EXTRA_SHOWING_DASH)) {
            mShowingDash = getIntent().getBooleanExtra(EXTRA_SHOWING_DASH, mShowingDash);
        }
    }
    mTargetIntent = null;
    final ArrayList<DashboardListAdapter.DashboardEntry> dashboardEntries = new ArrayList<DashboardListAdapter.DashboardEntry>();
    DashboardListAdapter.DashboardEntry entry = new DashboardListAdapter.DashboardEntry();
    entry.label = getString(R.string.dash_events);
    entry.icon = (new OcticonView(this)).setOcticon(OcticonView.IC_FEED).setGlyphColor(Color.parseColor("#2c2c2c")).setGlyphSize(72.0f).toDrawable();
    entry.selected = false;
    if (this instanceof EventsActivity) {
        entry.selected = true;
    }
    entry.onEntryClickListener = new DashboardListAdapter.DashboardEntry.OnEntryClickListener() {

        @Override
        public void onClick(DashboardListAdapter.DashboardEntry entry, int i) {
            final Intent eventsIntent = new Intent(BaseDashboardActivity.this, EventsActivity.class);
            eventsIntent.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_NEW_TASK);
            eventsIntent.putExtra(ARG_FROM_DASHBOARD, true);
            eventsIntent.putExtra(ARG_TARGET_USER, GsonUtils.toJson(new User().setLogin(getCurrentContextLogin())));
            eventsIntent.putExtra(ARG_EVENT_LIST_TYPE, LIST_USER_PRIVATE);
            mTargetIntent = eventsIntent;
            getDrawerGarment().closeDrawer();
        }
    };
    dashboardEntries.add(entry);
    entry = new DashboardListAdapter.DashboardEntry();
    entry.label = getString(R.string.dash_profile);
    entry.icon = (new OcticonView(this)).setOcticon(OcticonView.IC_PERSON).setGlyphColor(Color.parseColor("#2c2c2c")).setGlyphSize(72.0f).toDrawable();
    entry.selected = false;
    if (this instanceof ProfileActivity) {
        entry.selected = true;
    }
    entry.onEntryClickListener = new DashboardListAdapter.DashboardEntry.OnEntryClickListener() {

        @Override
        public void onClick(DashboardListAdapter.DashboardEntry entry, int i) {
            final Intent profileIntent = new Intent(BaseDashboardActivity.this, ProfileActivity.class);
            profileIntent.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_NEW_TASK);
            profileIntent.putExtra(ARG_FROM_DASHBOARD, true);
            profileIntent.putExtra(ARG_TARGET_USER, GsonUtils.toJson(new User().setLogin(getCurrentContextLogin())));
            mTargetIntent = profileIntent;
            getDrawerGarment().closeDrawer();
        }
    };
    dashboardEntries.add(entry);
    mDashboardListAdapter = new DashboardListAdapter(this);
    mDashboardListAdapter.fillWithItems(dashboardEntries);
    final LinearLayout headerLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.dashboard_account_header, null);
    mContextSpinner = (Spinner) headerLayout.findViewById(R.id.context_spinner);
    mContextSpinner.setEnabled(false);
    mOnContextItemSelectedListener = new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (mReadyForContext) {
                /* Remove the listener so we don't handle any more events */
                mContextSpinner.setOnItemSelectedListener(null);
                /*
                     * Reboot the app with the new context loaded
                     */
                final User target = mContextListAdapter.getItem(i);
                setCurrentContextLogin(target.getLogin());
                final Intent rebootIntent = new Intent(BaseDashboardActivity.this, HomeActivity.class);
                rebootIntent.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_NEW_TASK);
                startActivity(rebootIntent);
                finish();
            } else {
                mReadyForContext = true;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    };
    mDashboardListView = (ListView) mDrawerGarment.findViewById(R.id.list);
    if (isLoggedIn()) {
        mDashboardListView.addHeaderView(headerLayout);
    }
    mDashboardListView.setAdapter(mDashboardListAdapter);
    mDashboardListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (isLoggedIn()) {
                if (i == 0) {
                    return;
                } else {
                    i--;
                }
            }
            final DashboardListAdapter.DashboardEntry entry = mDashboardListAdapter.getItem(i);
            if (entry != null) {
                if (entry.onEntryClickListener != null) {
                    entry.onEntryClickListener.onClick(entry, i);
                }
            }
        }
    });
    if (isLoggedIn()) {
        final IntentFilter contextFilter = new IntentFilter(ACTION_ORGS_SELF_MEMBERSHIPS);
        registerReceiver(mContextReceiver, contextFilter);
        if (icicle == null) {
            final Intent getContextsIntent = new Intent(this, GitHubApiService.class);
            getContextsIntent.setAction(ACTION_ORGS_SELF_MEMBERSHIPS);
            getContextsIntent.putExtra(ARG_ACCOUNT, getCurrentUserAccount());
            startService(getContextsIntent);
        } else {
            if (icicle.containsKey(EXTRA_CONTEXTS)) {
                final String contextsJson = icicle.getString(EXTRA_CONTEXTS);
                if (contextsJson != null) {
                    TypeToken<List<User>> token = new TypeToken<List<User>>() {
                    };
                    List<User> contexts = GsonUtils.fromJson(contextsJson, token.getType());
                    /*
                         * Loop through the list of users/organizations to find the
                         * current context the user is browsing as and rearrange the
                         * list so that it's at the top.
                         */
                    int len = contexts.size();
                    for (int i = 0; i < len; i++) {
                        if (contexts.get(i).getLogin().equals(getCurrentContextLogin())) {
                            Collections.swap(contexts, i, 0);
                            break;
                        }
                    }
                    mContextListAdapter = new ContextListAdapter(BaseDashboardActivity.this);
                    mContextListAdapter.fillWithItems(contexts);
                    mContextSpinner.setAdapter(mContextListAdapter);
                    mContextSpinner.setOnItemSelectedListener(mOnContextItemSelectedListener);
                    mContextSpinner.setEnabled(true);
                }
            }
        }
    }
}
Also used : User(org.eclipse.egit.github.core.User) ArrayList(java.util.ArrayList) ContextListAdapter(net.idlesoft.android.apps.github.ui.adapters.ContextListAdapter) EventsActivity(net.idlesoft.android.apps.github.ui.activities.app.EventsActivity) ArrayList(java.util.ArrayList) List(java.util.List) IntentFilter(android.content.IntentFilter) ProfileActivity(net.idlesoft.android.apps.github.ui.activities.app.ProfileActivity) HomeActivity(net.idlesoft.android.apps.github.ui.activities.app.HomeActivity) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) OcticonView(net.idlesoft.android.apps.github.ui.widgets.OcticonView) ListView(android.widget.ListView) DrawerGarment(com.github.eddieringle.android.libs.undergarment.widgets.DrawerGarment) TypeToken(com.google.gson.reflect.TypeToken) DashboardListAdapter(net.idlesoft.android.apps.github.ui.adapters.DashboardListAdapter) AdapterView(android.widget.AdapterView) LinearLayout(android.widget.LinearLayout) OcticonView(net.idlesoft.android.apps.github.ui.widgets.OcticonView)

Aggregations

Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 DrawerGarment (com.github.eddieringle.android.libs.undergarment.widgets.DrawerGarment)1 TypeToken (com.google.gson.reflect.TypeToken)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EventsActivity (net.idlesoft.android.apps.github.ui.activities.app.EventsActivity)1 HomeActivity (net.idlesoft.android.apps.github.ui.activities.app.HomeActivity)1 ProfileActivity (net.idlesoft.android.apps.github.ui.activities.app.ProfileActivity)1 ContextListAdapter (net.idlesoft.android.apps.github.ui.adapters.ContextListAdapter)1 DashboardListAdapter (net.idlesoft.android.apps.github.ui.adapters.DashboardListAdapter)1 OcticonView (net.idlesoft.android.apps.github.ui.widgets.OcticonView)1 User (org.eclipse.egit.github.core.User)1