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();
}
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);
}
}
}
Aggregations