Search in sources :

Example 1 with Scenario

use of org.sitcon.ccip.model.Scenario in project CCIP-Android by CCIP-App.

the class CountdownActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_countdown);
    final TextView attrText = (TextView) findViewById(R.id.attr);
    final TextView countdownText = (TextView) findViewById(R.id.countdown);
    final TextView currentTimeText = (TextView) findViewById(R.id.current_time);
    final RelativeLayout countdownLayot = (RelativeLayout) findViewById(R.id.countdown_layout);
    final Button button = (Button) findViewById(R.id.button);
    final Scenario scenario = JsonUtil.fromJson(getIntent().getStringExtra(INTENT_EXTRA_SCENARIO), Scenario.class);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            finish();
        }
    });
    JsonObject attr = scenario.getAttr().getAsJsonObject();
    JsonElement elemDiet = attr.get("diet");
    if (elemDiet != null) {
        String diet = elemDiet.getAsString();
        if (diet.equals("meat")) {
            countdownLayot.setBackgroundColor(getResources().getColor(R.color.colorDietMeat));
            attrText.setText(R.string.meal);
        } else {
            countdownLayot.setBackgroundColor(getResources().getColor(R.color.colorDietVegetarian));
            attrText.setText(R.string.vegan);
        }
    } else {
        Set<Map.Entry<String, JsonElement>> entries = attr.entrySet();
        for (Map.Entry<String, JsonElement> entry : entries) {
            attrText.append(entry.getValue() + "\n");
        }
    }
    long countdown;
    if (scenario.getUsed() == null) {
        countdown = scenario.getCountdown() * 1000L;
    } else {
        countdown = (scenario.getUsed() + scenario.getCountdown()) * 1000L - new Date().getTime();
    }
    new CountDownTimer(countdown, 1000L) {

        @Override
        public void onTick(long l) {
            countdownText.setText(l / 1000 + "");
            currentTimeText.setText(SDF.format(new Date().getTime()));
        }

        @Override
        public void onFinish() {
            countdownText.setText("0");
            currentTimeText.setVisibility(View.GONE);
            countdownLayot.setBackgroundColor(Color.RED);
        }
    }.start();
}
Also used : CountDownTimer(android.os.CountDownTimer) JsonObject(com.google.gson.JsonObject) TextView(android.widget.TextView) View(android.view.View) Date(java.util.Date) Scenario(org.sitcon.ccip.model.Scenario) Button(android.widget.Button) JsonElement(com.google.gson.JsonElement) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) Map(java.util.Map)

Example 2 with Scenario

use of org.sitcon.ccip.model.Scenario in project CCIP-Android by CCIP-App.

the class ScenarioAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
    final ViewHolder holder = ((ViewHolder) viewHolder);
    final Scenario scenario = mScenarioList.get(position);
    try {
        int iconResId = mContext.getResources().getIdentifier(scenario.getId().indexOf("lunch") > 0 ? "lunch" : scenario.getId(), "drawable", mContext.getPackageName());
        holder.scenarioIcon.setImageDrawable(ContextCompat.getDrawable(mContext, iconResId));
    } catch (Resources.NotFoundException e) {
        holder.scenarioIcon.setImageResource(R.drawable.ic_event_black_24dp);
    }
    holder.scenarioIcon.setAlpha(1f);
    if (LocaleUtil.getCurrentLocale(mContext).toString().startsWith(Locale.TAIWAN.toString())) {
        holder.scenarioName.setText(scenario.getDisplayText().getZhTW());
    } else {
        holder.scenarioName.setText(scenario.getDisplayText().getEnUS());
    }
    holder.scenarioName.setTextColor(mContext.getResources().getColor(android.R.color.black));
    holder.allowTimeRange.setText(String.format(FORMAT_TIMERANGE, SDF.format(new Date(scenario.getAvailableTime() * 1000L)), SDF.format(new Date(scenario.getExpireTime() * 1000L))));
    if (scenario.getDisabled() != null) {
        setCardDisabled(holder, scenario.getDisabled());
        return;
    }
    if (scenario.getUsed() == null) {
        holder.card.setClickable(true);
        holder.card.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (scenario.getCountdown() > 0) {
                    showConfirmDialog(scenario);
                } else {
                    use(scenario);
                }
            }
        });
    } else {
        if (new Date().getTime() / 1000 - scenario.getUsed() < scenario.getCountdown()) {
            holder.card.setClickable(true);
            holder.card.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    startCountdownActivity(scenario);
                }
            });
        } else {
            setCardUsed(holder);
        }
    }
}
Also used : ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) Resources(android.content.res.Resources) ImageView(android.widget.ImageView) View(android.view.View) CardView(android.support.v7.widget.CardView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Date(java.util.Date) Scenario(org.sitcon.ccip.model.Scenario)

Aggregations

View (android.view.View)2 TextView (android.widget.TextView)2 Date (java.util.Date)2 Scenario (org.sitcon.ccip.model.Scenario)2 Resources (android.content.res.Resources)1 CountDownTimer (android.os.CountDownTimer)1 CardView (android.support.v7.widget.CardView)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ViewHolder (android.support.v7.widget.RecyclerView.ViewHolder)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 RelativeLayout (android.widget.RelativeLayout)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Map (java.util.Map)1