Search in sources :

Example 1 with AccountHeader

use of com.mikepenz.materialdrawer.AccountHeader in project ocreader by schaal.

the class ListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = DataBindingUtil.setContentView(this, R.layout.activity_list);
    setSupportActionBar(binding.toolbarLayout.toolbar);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    binding.swipeRefreshLayout.setColorSchemeResources(R.color.primary);
    binding.swipeRefreshLayout.setOnRefreshListener(this);
    profileDrawerItem = new ProfileDrawerItem().withName(preferences.getString(Preferences.USERNAME.getKey(), getString(R.string.app_name))).withEmail(Preferences.URL.getString(preferences));
    updateUserProfile();
    IProfile profileSettingsItem = new ProfileSettingDrawerItem().withName(getString(R.string.account_settings)).withIconTinted(true).withIcon(R.drawable.ic_settings).withTag((Runnable) () -> {
        Intent loginIntent = new Intent(ListActivity.this, LoginActivity.class);
        startActivityForResult(loginIntent, LoginActivity.REQUEST_CODE);
    });
    accountHeader = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header_background).addProfiles(profileDrawerItem, profileSettingsItem).withCurrentProfileHiddenInList(true).withProfileImagesClickable(false).withSavedInstance(savedInstanceState).withOnAccountHeaderListener((view, profile, current) -> {
        if (profile instanceof Tagable) {
            Tagable tagable = (Tagable) profile;
            if (tagable.getTag() instanceof Runnable) {
                ((Runnable) tagable.getTag()).run();
                return false;
            }
        }
        return true;
    }).build();
    refreshDrawerItem = new PrimaryDrawerItem().withName(getString(R.string.action_sync)).withSelectable(false).withIconTintingEnabled(true).withIcon(R.drawable.ic_refresh).withIdentifier(REFRESH_DRAWER_ITEM_ID).withTag((Runnable) () -> SyncService.startSync(ListActivity.this));
    IDrawerItem settingsDrawerItem = new PrimaryDrawerItem().withName(R.string.settings).withIcon(R.drawable.ic_settings).withIconTintingEnabled(true).withSelectable(false).withTag((Runnable) () -> {
        startDrawer.closeDrawer();
        Intent settingsIntent = new Intent(ListActivity.this, SettingsActivity.class);
        startActivity(settingsIntent);
    });
    DrawerBuilder startDrawerBuilder = new DrawerBuilder().withActivity(this).withAccountHeader(accountHeader).addStickyDrawerItems(settingsDrawerItem, refreshDrawerItem).withOnDrawerListener(new Drawer.OnDrawerListener() {

        @Override
        public void onDrawerOpened(View drawerView) {
            drawerManager.getStartAdapter().updateUnreadCount(getRealm(), isShowOnlyUnread());
        }

        @Override
        public void onDrawerClosed(View drawerView) {
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
        }
    }).withOnDrawerItemClickListener((view, position, drawerItem) -> {
        if (drawerItem.getTag() instanceof TreeItem) {
            TreeItem item = (TreeItem) drawerItem.getTag();
            onStartDrawerItemClicked(item);
            return false;
        } else if (drawerItem.getTag() instanceof Runnable) {
            ((Runnable) drawerItem.getTag()).run();
        }
        return true;
    }).withSavedInstance(savedInstanceState);
    DrawerBuilder endDrawerBuilder = new DrawerBuilder().withActivity(this).withDrawerGravity(Gravity.END).withSavedInstance(savedInstanceState).withShowDrawerOnFirstLaunch(true).withOnDrawerListener(new Drawer.OnDrawerListener() {

        @Override
        public void onDrawerOpened(View drawerView) {
            drawerManager.getEndAdapter().updateUnreadCount(getRealm(), isShowOnlyUnread());
        }

        @Override
        public void onDrawerClosed(View drawerView) {
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
        }
    }).withOnDrawerItemClickListener((view, position, drawerItem) -> {
        if (drawerItem.getTag() instanceof Feed) {
            Feed feed = (Feed) drawerItem.getTag();
            onEndDrawerItemClicked(feed);
            return false;
        }
        return true;
    });
    startDrawerBuilder.withToolbar(binding.toolbarLayout.toolbar);
    startDrawer = startDrawerBuilder.build();
    drawerManager = new DrawerManager(this, startDrawer, endDrawerBuilder.append(startDrawer), unreadSwitchListener);
    layoutManager = new LinearLayoutManager(this);
    adapter = new ErrorAdapter(this, getRealm(), drawerManager.getState(), this, this);
    binding.fabMarkAllAsRead.setOnClickListener(new View.OnClickListener() {

        private void onCompletion(View view) {
            adapter.updateItems(false);
            view.setEnabled(true);
            binding.fabMarkAllAsRead.toggleSync();
        }

        @Override
        public void onClick(final View view) {
            if (binding.fabMarkAllAsRead.isSync()) {
                SyncService.startSync(ListActivity.this);
                binding.fabMarkAllAsRead.toggleSync();
            } else {
                Queries.markTemporaryFeedAsRead(getRealm(), () -> onCompletion(view), error -> {
                    Log.e(TAG, "Failed to mark temporary feed as read", error);
                    onCompletion(view);
                });
            }
        }
    });
    binding.fabMarkAllAsRead.setOnLongClickListener(v -> {
        Toast.makeText(ListActivity.this, R.string.mark_all_as_read, Toast.LENGTH_SHORT).show();
        return true;
    });
    binding.itemsRecyclerview.setAdapter(adapter);
    binding.itemsRecyclerview.setLayoutManager(layoutManager);
    if (savedInstanceState == null && getIntent().hasExtra(SyncService.EXTRA_ID)) {
        drawerManager.getState().restore(getRealm(), getIntent().getIntExtra(SyncService.EXTRA_ID, -10), null, false);
    } else {
        drawerManager.getState().restoreInstanceState(getRealm(), getPreferences(MODE_PRIVATE));
    }
    binding.itemsRecyclerview.addItemDecoration(new DividerItemDecoration(this, R.dimen.divider_inset));
    adapter.updateItems(false);
    if (savedInstanceState != null) {
        layoutManager.onRestoreInstanceState(savedInstanceState.getParcelable(LAYOUT_MANAGER_STATE));
        adapter.onRestoreInstanceState(savedInstanceState);
        if (adapter.getSelectedItemsCount() > 0) {
            actionMode = startActionMode(this);
        }
    }
    drawerManager.reloadAdapters(getRealm(), isShowOnlyUnread());
    // noinspection ConstantConditions
    getSupportActionBar().setTitle(drawerManager.getState().getTreeItem().getName());
}
Also used : ActionMode(android.view.ActionMode) Bundle(android.os.Bundle) OnCheckedChangeListener(com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener) Libs(com.mikepenz.aboutlibraries.Libs) DividerItemDecoration(email.schaal.ocreader.view.DividerItemDecoration) Nameable(com.mikepenz.materialdrawer.model.interfaces.Nameable) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) ActivityListBinding(email.schaal.ocreader.databinding.ActivityListBinding) Tagable(com.mikepenz.materialdrawer.model.interfaces.Tagable) Base64InputStream(android.util.Base64InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Item(email.schaal.ocreader.database.model.Item) TemporaryFeed(email.schaal.ocreader.database.model.TemporaryFeed) View(android.view.View) ProfileSettingDrawerItem(com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem) PreferenceManager(android.preference.PreferenceManager) SyncType(email.schaal.ocreader.service.SyncType) Log(android.util.Log) AccountHeader(com.mikepenz.materialdrawer.AccountHeader) ContextCompat(android.support.v4.content.ContextCompat) AllUnreadFolder(email.schaal.ocreader.database.model.AllUnreadFolder) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) BroadcastReceiver(android.content.BroadcastReceiver) Queries(email.schaal.ocreader.database.Queries) ErrorAdapter(email.schaal.ocreader.view.ErrorAdapter) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) Nullable(android.support.annotation.Nullable) Snackbar(android.support.design.widget.Snackbar) Context(android.content.Context) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) NonNull(android.support.annotation.NonNull) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) TreeItem(email.schaal.ocreader.database.model.TreeItem) MenuItem(android.view.MenuItem) SyncService(email.schaal.ocreader.service.SyncService) Drawer(com.mikepenz.materialdrawer.Drawer) Toast(android.widget.Toast) Menu(android.view.Menu) User(email.schaal.ocreader.database.model.User) DrawerManager(email.schaal.ocreader.view.drawer.DrawerManager) DrawerLayout(android.support.v4.widget.DrawerLayout) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) LibsBuilder(com.mikepenz.aboutlibraries.LibsBuilder) Feed(email.schaal.ocreader.database.model.Feed) LoadMoreAdapter(email.schaal.ocreader.view.LoadMoreAdapter) CompoundButton(android.widget.CompoundButton) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) Bitmap(android.graphics.Bitmap) DataBindingUtil(android.databinding.DataBindingUtil) Base64(android.util.Base64) ItemViewHolder(email.schaal.ocreader.view.ItemViewHolder) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) Activity(android.app.Activity) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) ProfileSettingDrawerItem(com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem) ErrorAdapter(email.schaal.ocreader.view.ErrorAdapter) TreeItem(email.schaal.ocreader.database.model.TreeItem) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) TemporaryFeed(email.schaal.ocreader.database.model.TemporaryFeed) Feed(email.schaal.ocreader.database.model.Feed) DrawerManager(email.schaal.ocreader.view.drawer.DrawerManager) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) Drawer(com.mikepenz.materialdrawer.Drawer) DividerItemDecoration(email.schaal.ocreader.view.DividerItemDecoration) View(android.view.View) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) Tagable(com.mikepenz.materialdrawer.model.interfaces.Tagable)

Example 2 with AccountHeader

use of com.mikepenz.materialdrawer.AccountHeader in project CryptoBuddy by Patchett.

the class CurrencyListTabsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_currency_list_tabs);
    context = this;
    mToolbar = findViewById(R.id.toolbar_currency_list);
    setSupportActionBar(mToolbar);
    TabLayout tabLayout = findViewById(R.id.currency_list_tabs);
    mViewPager = findViewById(R.id.currency_list_tabs_container);
    libsBuilder = new LibsBuilder().withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR).withAboutIconShown(true).withLicenseShown(true).withVersionShown(true).withAboutVersionShownName(true).withAboutVersionShownCode(true).withAboutVersionString("Version: " + BuildConfig.VERSION_NAME).withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR).withActivityTitle("CryptoBuddy").withLibraries("easyrest", "materialabout", "androiddevicenames", "customtabs", "togglebuttongroup", "materialfavoritebutton");
    TextDrawable t = new TextDrawable(this);
    t.setText("ART");
    t.setTextAlign(Layout.Alignment.ALIGN_CENTER);
    t.setTextColor(Color.BLACK);
    t.setTextSize(10);
    AccountHeader headerResult = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(t).build();
    drawer = new DrawerBuilder().withActivity(this).withToolbar(mToolbar).withSelectedItem(1).withAccountHeader(headerResult).addDrawerItems(new PrimaryDrawerItem().withIdentifier(1).withName(R.string.Home).withIcon(FontAwesome.Icon.faw_home), new PrimaryDrawerItem().withIdentifier(2).withName(R.string.News).withIcon(FontAwesome.Icon.faw_newspaper), new PrimaryDrawerItem().withIdentifier(3).withName("About").withIcon(FontAwesome.Icon.faw_question_circle), new PrimaryDrawerItem().withIdentifier(4).withName("Open Source").withIcon(FontAwesome.Icon.faw_github_square), new PrimaryDrawerItem().withIdentifier(5).withName("Rate on Google Play").withIcon(FontAwesome.Icon.faw_thumbs_up)).withTranslucentStatusBar(false).build();
    drawer.setOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            switch(position) {
                case 1:
                    drawer.closeDrawer();
                    return true;
                case 2:
                    drawer.closeDrawer();
                    drawer.setSelection(1);
                    startActivity(new Intent(context, NewsListActivity.class));
                    return true;
                case 3:
                    drawer.closeDrawer();
                    drawer.setSelection(1);
                    startActivity(new Intent(context, AboutTheDevActivity.class));
                    return true;
                case 4:
                    drawer.closeDrawer();
                    drawer.setSelection(1);
                    libsBuilder.start(context);
                default:
                    return true;
            }
        }
    });
    mSectionsPagerAdapter = new SectionsPagerAdapterCurrencyList(getSupportFragmentManager());
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.addOnPageChangeListener(this);
    tabLayout.setupWithViewPager(mViewPager);
    tabLayout.setSelectedTabIndicatorColor(Color.WHITE);
}
Also used : TextDrawable(com.cryptobuddy.ryanbridges.cryptobuddy.TextDrawable) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) Intent(android.content.Intent) Drawer(com.mikepenz.materialdrawer.Drawer) View(android.view.View) AccountHeader(com.mikepenz.materialdrawer.AccountHeader) TabLayout(android.support.design.widget.TabLayout) LibsBuilder(com.mikepenz.aboutlibraries.LibsBuilder) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder)

Example 3 with AccountHeader

use of com.mikepenz.materialdrawer.AccountHeader in project Weather by Sparker0i.

the class WeatherActivity method initDrawer.

public void initDrawer() {
    final IProfile profile = new ProfileDrawerItem().withName(getString(R.string.app_name)).withEmail("Version : " + BuildConfig.VERSION_NAME).withIcon(R.mipmap.ic_launcher_x);
    AccountHeader headerResult = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header).withTextColor(ContextCompat.getColor(this, R.color.md_amber_400)).addProfiles(profile).withSelectionListEnabled(false).withProfileImagesClickable(false).build();
    SecondaryDrawerItem item1 = new SecondaryDrawerItem().withName(R.string.drawer_item_home).withIcon(new IconicsDrawable(this).icon(WeatherIcons.Icon.wic_day_sunny)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            wf = new WeatherFragment();
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
            return true;
        }
    });
    SecondaryDrawerItem item2 = new SecondaryDrawerItem().withName(R.string.drawer_item_graph).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_trending_up)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (!(f instanceof GraphsFragment)) {
                GraphsFragment graphsFragment = newGraphInstance(new ArrayList<>(wf.getDailyJson()));
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, graphsFragment).commit();
            }
            return true;
        }
    });
    SecondaryDrawerItem item3 = new SecondaryDrawerItem().withName(R.string.drawer_item_map).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_map)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (!(f instanceof MapsFragment)) {
                MapsFragment mapsFragment = new MapsFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, mapsFragment).commit();
            }
            return true;
        }
    });
    SecondaryDrawerItem item4 = new SecondaryDrawerItem().withName(R.string.drawer_item_add_city).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_add_location)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            showCityDialog();
            return true;
        }
    }).withSelectable(false);
    SecondaryDrawerItem item8 = new SecondaryDrawerItem().withName(R.string.drawer_item_about).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_info)).withSelectable(false).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            startActivity(new Intent(WeatherActivity.this, AboutActivity.class));
            return true;
        }
    });
    SecondaryDrawerItem item9 = new SecondaryDrawerItem().withName(R.string.settings).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_settings)).withSelectable(false).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            startActivity(new Intent(WeatherActivity.this, SettingsActivity.class));
            return true;
        }
    });
    DrawerBuilder drawerBuilder = new DrawerBuilder();
    drawerBuilder.withActivity(this).withToolbar(toolbar).withTranslucentStatusBar(true).withAccountHeader(headerResult).withActionBarDrawerToggleAnimated(true).addDrawerItems(item1, item2, item3, new DividerDrawerItem(), item4).addStickyDrawerItems(item8, item9);
    List<String> cities = dbHelper.getCities();
    final ListIterator<String> listIterator = cities.listIterator(cities.size());
    while (listIterator.hasPrevious()) {
        final String city = listIterator.previous();
        drawerBuilder.addDrawerItems(new SecondaryDrawerItem().withName(city).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_place)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

            @Override
            public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                wf = new WeatherFragment().setCity(city);
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
                return true;
            }
        }));
    }
    drawer = drawerBuilder.build();
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) ArrayList(java.util.ArrayList) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) Intent(android.content.Intent) WeatherFragment(com.a5corp.weather.fragment.WeatherFragment) Drawer(com.mikepenz.materialdrawer.Drawer) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) View(android.view.View) AccountHeader(com.mikepenz.materialdrawer.AccountHeader) MapsFragment(com.a5corp.weather.fragment.MapsFragment) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) GraphsFragment(com.a5corp.weather.fragment.GraphsFragment)

Aggregations

Intent (android.content.Intent)3 View (android.view.View)3 AccountHeader (com.mikepenz.materialdrawer.AccountHeader)3 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)3 Drawer (com.mikepenz.materialdrawer.Drawer)3 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)3 IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)3 LibsBuilder (com.mikepenz.aboutlibraries.LibsBuilder)2 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)2 ProfileDrawerItem (com.mikepenz.materialdrawer.model.ProfileDrawerItem)2 Activity (android.app.Activity)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 DataBindingUtil (android.databinding.DataBindingUtil)1 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 Bundle (android.os.Bundle)1 PreferenceManager (android.preference.PreferenceManager)1 NonNull (android.support.annotation.NonNull)1