Android Open Source - NerdRoll Die Screen






From Project

Back to project page NerdRoll.

License

The source code is released under:

Apache License

If you think the Android project NerdRoll listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.bignerdranch.android.nerdroll.screen;
//w w  w  .  ja  va  2s. c  om
import android.os.Bundle;
import android.view.MenuItem;

import com.bignerdranch.android.nerdroll.R;
import com.bignerdranch.android.nerdroll.android.ActionBarOwner;
import com.bignerdranch.android.nerdroll.model.DieList;
import com.bignerdranch.android.nerdroll.model.Die;
import com.bignerdranch.android.nerdroll.util.MainScope;
import com.bignerdranch.android.nerdroll.view.DieView;

import javax.inject.Inject;
import javax.inject.Singleton;

import dagger.Provides;
import flow.Flow;
import flow.HasParent;
import flow.Layout;
import mortar.Blueprint;
import mortar.ViewPresenter;
import rx.functions.Action0;

@Layout(R.layout.view_die)
public class DieScreen implements HasParent<DieListScreen>, Blueprint {

    @Inject DieList mDieList;
    private final int mDieIndex;

    public DieScreen(int mDieIndex) {
        this.mDieIndex = mDieIndex;
    }

    @Override
    public String getMortarScopeName() {
        return "DieScreen{" + "mDieIndex=" + mDieIndex + '}';
    }

    @Override
    public Object getDaggerModule() {
        return new Module();
    }

    @Override
    public DieListScreen getParent() {
        return new DieListScreen();
    }

    @dagger.Module(injects = DieView.class, addsTo = MainScreen.Module.class)
    public class Module {
        @Provides
        Die provideDie() {
            return mDieList.get(mDieIndex);
        }
    }

    @Singleton
    public static class Presenter extends ViewPresenter<DieView> {

        private final ActionBarOwner mActionBarOwner;
        private final Flow mFlow;

        private final Die mDie;

        @Inject
        public Presenter(Die mDie, @MainScope Flow flow, ActionBarOwner actionBarOwner) {
            this.mDie = mDie;
            this.mFlow = flow;
            this.mActionBarOwner = actionBarOwner;
        }

        @Override
        public void onLoad(Bundle savedInstanceState) {
            DieView v = getView();
            if (v == null) {
                return;
            }

            ActionBarOwner.Config actionBarConfig = mActionBarOwner.getConfig();
            actionBarConfig = actionBarConfig.withAction(new ActionBarOwner.MenuAction(R.string.roll, android.R.drawable.ic_menu_compass, MenuItem.SHOW_AS_ACTION_NEVER, new Action0() {
                @Override
                public void call() {
                    v.roll(mDie.getSides());
                }
            }));
            mActionBarOwner.setConfig(actionBarConfig);

            v.setOnClickListener(v1 -> v.roll(mDie.getSides()));
            v.updateRandomText(mDie.toString());
        }

    }

}




Java Source Code List

com.bignerdranch.android.nerdroll.ApplicationTest.java
com.bignerdranch.android.nerdroll.ApplicationTest.java
com.bignerdranch.android.nerdroll.MainActivity.java
com.bignerdranch.android.nerdroll.MainActivity.java
com.bignerdranch.android.nerdroll.MainApplicationModule.java
com.bignerdranch.android.nerdroll.MainApplicationModule.java
com.bignerdranch.android.nerdroll.MainApplication.java
com.bignerdranch.android.nerdroll.MainApplication.java
com.bignerdranch.android.nerdroll.android.ActionBarModule.java
com.bignerdranch.android.nerdroll.android.ActionBarOwner.java
com.bignerdranch.android.nerdroll.controller.DieFragment.java
com.bignerdranch.android.nerdroll.controller.DieListFragment.java
com.bignerdranch.android.nerdroll.model.DieList.java
com.bignerdranch.android.nerdroll.model.DieList.java
com.bignerdranch.android.nerdroll.model.Die.java
com.bignerdranch.android.nerdroll.model.Die.java
com.bignerdranch.android.nerdroll.screen.DieListScreen.java
com.bignerdranch.android.nerdroll.screen.DieScreen.java
com.bignerdranch.android.nerdroll.screen.MainScreen.java
com.bignerdranch.android.nerdroll.util.CanShowScreen.java
com.bignerdranch.android.nerdroll.util.FlowOwner.java
com.bignerdranch.android.nerdroll.util.GsonParcer.java
com.bignerdranch.android.nerdroll.util.MainScope.java
com.bignerdranch.android.nerdroll.util.ScreenConductor.java
com.bignerdranch.android.nerdroll.view.DieListView.java
com.bignerdranch.android.nerdroll.view.DieView.java
com.bignerdranch.android.nerdroll.view.MainView.java