Newer
Older
package com.eyecreate.miceandmystics.miceandmystics;
import android.app.AlertDialog;
Kevin Whitaker
committed
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.widget.LinearLayoutManager;
Kevin Whitaker
committed
import android.view.*;
import android.widget.ArrayAdapter;
import android.widget.EditText;
Kevin Whitaker
committed
import android.widget.Spinner;
Kevin Whitaker
committed
import android.widget.Toast;
Kevin Whitaker
committed
import com.alertdialogpro.AlertDialogPro;
import com.eyecreate.miceandmystics.miceandmystics.adapters.CampaignAdapter;
Kevin Whitaker
committed
import com.eyecreate.miceandmystics.miceandmystics.model.Enums.CampaignType;
public class CampaignActivity extends RecyclerViewActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.mipmap.ic_launcher);
Kevin Whitaker
committed
setTitle(getString(R.string.campaign_activity));
setLayoutManager(new LinearLayoutManager(this));
setAdapter(new CampaignAdapter());
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_campaign, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
Kevin Whitaker
committed
newCampaignDialog();
return true;
}
return super.onOptionsItemSelected(item);
}
Kevin Whitaker
committed
public void newCampaignDialog() {
LayoutInflater inflator = (LayoutInflater)(new ContextThemeWrapper(this, R.style.dialogTheme)).getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View dialogView = inflator.inflate(R.layout.dialog_new_campaign, null, false);
final Spinner typeSpinner = ((Spinner)dialogView.findViewById(R.id.campaign_type));
typeSpinner.setAdapter(new ArrayAdapter<CampaignType>(this, R.layout.simple_spinner_item, CampaignType.values()));
typeSpinner.setSelection(0);
Kevin Whitaker
committed
AlertDialog addDialog = new AlertDialogPro.Builder(this,R.style.dialogTheme)
Kevin Whitaker
committed
.setMessage(getString(R.string.campaign_name_request))
Kevin Whitaker
committed
.setView(dialogView)
Kevin Whitaker
committed
.setPositiveButton(getString(R.string.dialog_confirm), new DialogInterface.OnClickListener() {
Kevin Whitaker
committed
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Kevin Whitaker
committed
if (((EditText) dialogView.findViewById(R.id.campaign_name)).getText().length() > 0) {
((CampaignAdapter) getAdapter()).addItem(((EditText) dialogView.findViewById(R.id.campaign_name)).getText().toString(), CampaignType.valueOf(((CampaignType) typeSpinner.getSelectedItem()).name()));
Kevin Whitaker
committed
} else {
Kevin Whitaker
committed
Toast.makeText(CampaignActivity.this, R.string.campaign_name_blank, Toast.LENGTH_LONG).show();
Kevin Whitaker
committed
}
}
})
.create();
addDialog.show();
}