Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MenuActivity extends AppCompatActivity implements
- GoogleApiClient.ConnectionCallbacks, LocationListener {
- @Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_menu);
- iniciadorComponente(savedInstanceState);
- iniciadorDados();
- swipeListaAtendimento.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
- @Override
- public void onRefresh() {
- requisicaoWsListaAtendimento(true);
- }
- });
- }
- private void iniciadorComponente(Bundle savedInstanceState) {
- swipeListaAtendimento = (SwipeRefreshLayout) findViewById(R.id.swipeListaAtendimento);
- listaAtendimentos = (ListView) findViewById(R.id.listaAtendimentos);
- progressListaAtendimentos = (ProgressBar) findViewById(R.id.progressListaAtendimentos);
- chaveIntegracaoClasse = new ChaveIntegracao();
- databaseHelper = new DatabaseHelper(MenuActivity.this);
- atendimentosDAO = new AtendimentosDAO();
- if (savedInstanceState != null) {
- atendimentos = (ArrayList<Atendimento>) savedInstanceState.getSerializable("listaAtendimento");
- } else {
- atendimentos = new ArrayList<>();
- }
- }
- private void iniciadorDados() {
- SharedPreferences preferences = getSharedPreferences("USER_INFORMATION", MODE_PRIVATE);
- urlBase = preferences.getString("urlBase", null);
- intervaloCoordenadas = preferences.getString("intervaloCoordenadas", null);
- }
- @Override
- public void onResume() {
- super.onResume();
- requisicaoWsListaAtendimento(false);
- carregaListaAtendimentos();
- }
- public void carregaListaAtendimentos(){
- atendimentos = atendimentosDAO.listarAtendimento(databaseHelper);
- atendimentoAdapter = new MenuAdapter(atendimentos, MenuActivity.this, posicaoAtualDoUsuario, carregaSpinner);
- listaAtendimentos.setAdapter(atendimentoAdapter);
- }
- private void requisicaoWsListaAtendimento(boolean queroCarregarListaPeloSwipe){
- if (queroCarregarListaPeloSwipe){
- SharedPreferences preferences = getSharedPreferences("USER_INFORMATION", MODE_PRIVATE);
- Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(getResources().getString(R.string.cnpjTeste))); // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
- DadosAtendimento dadosAtendimento = new DadosAtendimento("guilherme");
- ListaAtendimentos listaAtendimentos1 = new ListaAtendimentos(autenticacao, dadosAtendimento);
- EnvelopeAtendimento envelopeAtendimento = new EnvelopeAtendimento(listaAtendimentos1);
- //chama o retrofit para fazer a requisição no webservice
- EnviarDadosListaAtendimentosCallback enviarDadosListaAtendimentosCallback = new EnviarDadosListaAtendimentosCallback(
- MenuActivity.this,
- progressListaAtendimentos,
- listaAtendimentos,
- urlBase,
- swipeListaAtendimento);
- enviarDadosListaAtendimentosCallback.enviarDadosLista(envelopeAtendimento);
- } else {
- progressListaAtendimentos.setVisibility(View.VISIBLE);
- listaAtendimentos.setVisibility(View.GONE);
- SharedPreferences preferences = getSharedPreferences("USER_INFORMATION", MODE_PRIVATE);
- Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(getResources().getString(R.string.cnpjTeste))); // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
- DadosAtendimento dadosAtendimento = new DadosAtendimento("guilherme");
- ListaAtendimentos listaAtendimentos1 = new ListaAtendimentos(autenticacao, dadosAtendimento);
- EnvelopeAtendimento envelopeAtendimento = new EnvelopeAtendimento(listaAtendimentos1);
- //chama o retrofit para fazer a requisição no webservice
- EnviarDadosListaAtendimentosCallback enviarDadosListaAtendimentosCallback = new EnviarDadosListaAtendimentosCallback(
- MenuActivity.this,
- progressListaAtendimentos,
- listaAtendimentos,
- urlBase,
- swipeListaAtendimento);
- enviarDadosListaAtendimentosCallback.enviarDadosLista(envelopeAtendimento);
- }
- }
- public class MenuAdapter extends BaseAdapter {
- public MenuAdapter(List<Atendimento> atendimentos, Activity activity, String posicaoAtualDoUsuario, boolean carregaSpinner) {
- this.atendimentos = atendimentos;
- this.activity = activity;
- this.posicaoAtualDoUsuario = posicaoAtualDoUsuario;
- this.carregaSpinner = carregaSpinner;
- }
- @Override
- public int getCount() {
- return atendimentos.size();
- }
- @Override
- public Object getItem(int position) {
- return atendimentos.get(position);
- }
- @Override
- public long getItemId(int position) {
- return position;
- }
- @Override
- public View getView(final int position, View convertView, ViewGroup parent) {
- final LayoutInflater inflater = activity.getLayoutInflater();
- final View linha = inflater.inflate(R.layout.item_atendimento, null);
- final Atendimento atendimentos1 = atendimentos.get(position);
- iniciadorComponente(linha);
- iniciadorDados(atendimentos1, linha);
- if (atendimentos1.getSituacaoOS().equals("Na fila")) {
- spnSituacaoItem.setSelection(0);
- } else if (atendimentos1.getSituacaoOS().equals("A caminho")) {
- spnSituacaoItem.setSelection(1);
- } else if (atendimentos1.getSituacaoOS().equals("Em execução")) {
- spnSituacaoItem.setSelection(2);
- } else if (atendimentos1.getSituacaoOS().equals("Pausado")) {
- spnSituacaoItem.setSelection(3);
- } else if (atendimentos1.getSituacaoOS().equals("Concluído")) {
- spnSituacaoItem.setSelection(4);
- } else if (atendimentos1.getSituacaoOS().equals("Abortado")) {
- spnSituacaoItem.setSelection(5);
- }
- // Verificação tempo
- if (atendimentos1.getDuracao().equals("")) {
- imgTempoItem.setVisibility(View.GONE);
- txtTempoItem.setVisibility(View.GONE);
- }
- // Verificação agendamento
- if (atendimentos1.getAgendamento().equals("")) {
- imgAgendamentoItem.setVisibility(View.GONE);
- txtAgendamentoItem.setVisibility(View.GONE);
- }
- // Verificação sla restante
- if (atendimentos1.getSlaFormatado().equals("")) {
- imgSlaItem.setVisibility(View.GONE);
- txtSlaItem.setVisibility(View.GONE);
- txtSlaRestanteItem.setVisibility(View.GONE);
- progressSlaRestante.setVisibility(View.GONE);
- }
- // Verificação progress bar
- if (progressSlaRestante.getProgress() <= 25) {
- progressSlaRestante.setProgressDrawable(linha.getResources().getDrawable(R.drawable.progress_bar_state_green));
- } else if (progressSlaRestante.getProgress() > 25 && progressSlaRestante.getProgress() <= 50) {
- progressSlaRestante.setProgressDrawable(linha.getResources().getDrawable(R.drawable.progress_bar_state_yellow));
- } else if (progressSlaRestante.getProgress() > 50 && progressSlaRestante.getProgress() <= 75) {
- progressSlaRestante.setProgressDrawable(linha.getResources().getDrawable(R.drawable.progress_bar_state_orange));
- } else if (progressSlaRestante.getProgress() > 75) {
- progressSlaRestante.setProgressDrawable(linha.getResources().getDrawable(R.drawable.progress_bar_state_red));
- }
- spnSituacaoItem.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- if (carregaSpinner) {
- if (position == 0) {
- progressDialog = ProgressDialog.show(
- linha.getContext(),
- linha.getResources().getString(R.string.aguarde),
- linha.getResources().getString(R.string.enviandoDados),
- false,
- true
- );
- progressDialog.setCanceledOnTouchOutside(false);
- progressDialog.setCancelable(false);
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- Thread.sleep(1000);
- handler.post(new Runnable() {
- @Override
- public void run() {
- Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(linha.getResources().getString(R.string.cnpjTeste)));
- // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
- DadosOS dadosOS = new DadosOS(atendimentos1.getNumero(), usuario, situacaoAnterior, "A", dataFormatada);
- AlteraSituacaoOs alteraSituacaoOs = new AlteraSituacaoOs(autenticacao, dadosOS);
- EnvelopeSituacaoOs envelopeSituacaoOs = new EnvelopeSituacaoOs(alteraSituacaoOs);
- //chama o retrofit para fazer a requisição no webservice
- EnviarSituacaoOsCallback enviarSituacaoOsCallback = new EnviarSituacaoOsCallback(
- linha.getContext(),
- progressDialog,
- urlBase);
- enviarSituacaoOsCallback.enviarDadosOs(envelopeSituacaoOs);
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- progressDialog.dismiss();
- }
- }
- }).start();
- carregaSpinner = false;
- } else if (position == 1) {
- progressDialog = ProgressDialog.show(
- linha.getContext(),
- linha.getResources().getString(R.string.aguarde),
- linha.getResources().getString(R.string.enviandoDados),
- false,
- true
- );
- progressDialog.setCanceledOnTouchOutside(false);
- progressDialog.setCancelable(false);
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- Thread.sleep(1000);
- handler.post(new Runnable() {
- @Override
- public void run() {
- Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(linha.getResources().getString(R.string.cnpjTeste)));
- // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
- DadosOS dadosOS = new DadosOS(atendimentos1.getNumero(), usuario, situacaoAnterior, "A", dataFormatada);
- AlteraSituacaoOs alteraSituacaoOs = new AlteraSituacaoOs(autenticacao, dadosOS);
- EnvelopeSituacaoOs envelopeSituacaoOs = new EnvelopeSituacaoOs(alteraSituacaoOs);
- //chama o retrofit para fazer a requisição no webservice
- EnviarSituacaoOsCallback enviarSituacaoOsCallback = new EnviarSituacaoOsCallback(
- linha.getContext(),
- progressDialog,
- urlBase);
- enviarSituacaoOsCallback.enviarDadosOs(envelopeSituacaoOs);
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- progressDialog.dismiss();
- }
- }
- }).start();
- } else if (position == 2) {
- progressDialog = ProgressDialog.show(
- linha.getContext(),
- linha.getResources().getString(R.string.aguarde),
- linha.getResources().getString(R.string.enviandoDados),
- false,
- true
- );
- progressDialog.setCanceledOnTouchOutside(false);
- progressDialog.setCancelable(false);
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- Thread.sleep(1000);
- handler.post(new Runnable() {
- @Override
- public void run() {
- Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(linha.getResources().getString(R.string.cnpjTeste)));
- // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
- DadosOS dadosOS = new DadosOS(atendimentos1.getNumero(), usuario, situacaoAnterior, "E", dataFormatada);
- AlteraSituacaoOs alteraSituacaoOs = new AlteraSituacaoOs(autenticacao, dadosOS);
- EnvelopeSituacaoOs envelopeSituacaoOs = new EnvelopeSituacaoOs(alteraSituacaoOs);
- //chama o retrofit para fazer a requisição no webservice
- EnviarSituacaoOsCallback enviarSituacaoOsCallback = new EnviarSituacaoOsCallback(
- linha.getContext(),
- progressDialog,
- urlBase);
- enviarSituacaoOsCallback.enviarDadosOs(envelopeSituacaoOs);
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- progressDialog.dismiss();
- }
- }
- }).start();
- } else if (position == 3) {
- progressDialog = ProgressDialog.show(
- linha.getContext(),
- linha.getResources().getString(R.string.aguarde),
- linha.getResources().getString(R.string.enviandoDados),
- false,
- true
- );
- progressDialog.setCanceledOnTouchOutside(false);
- progressDialog.setCancelable(false);
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- Thread.sleep(1000);
- handler.post(new Runnable() {
- @Override
- public void run() {
- Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(linha.getResources().getString(R.string.cnpjTeste)));
- // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
- DadosOS dadosOS = new DadosOS(atendimentos1.getNumero(), usuario, situacaoAnterior, "P", dataFormatada);
- AlteraSituacaoOs alteraSituacaoOs = new AlteraSituacaoOs(autenticacao, dadosOS);
- EnvelopeSituacaoOs envelopeSituacaoOs = new EnvelopeSituacaoOs(alteraSituacaoOs);
- //chama o retrofit para fazer a requisição no webservice
- EnviarSituacaoOsCallback enviarSituacaoOsCallback = new EnviarSituacaoOsCallback(
- linha.getContext(),
- progressDialog,
- urlBase);
- enviarSituacaoOsCallback.enviarDadosOs(envelopeSituacaoOs);
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- progressDialog.dismiss();
- }
- }
- }).start();
- } else if (position == 4) {
- progressDialog = ProgressDialog.show(
- linha.getContext(),
- linha.getResources().getString(R.string.aguarde),
- linha.getResources().getString(R.string.enviandoDados),
- false,
- true
- );
- progressDialog.setCanceledOnTouchOutside(false);
- progressDialog.setCancelable(false);
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- Thread.sleep(1000);
- handler.post(new Runnable() {
- @Override
- public void run() {
- Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(linha.getResources().getString(R.string.cnpjTeste)));
- // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
- DadosOS dadosOS = new DadosOS(atendimentos1.getNumero(), usuario, situacaoAnterior, "C", dataFormatada);
- AlteraSituacaoOs alteraSituacaoOs = new AlteraSituacaoOs(autenticacao, dadosOS);
- EnvelopeSituacaoOs envelopeSituacaoOs = new EnvelopeSituacaoOs(alteraSituacaoOs);
- //chama o retrofit para fazer a requisição no webservice
- EnviarSituacaoOsCallback enviarSituacaoOsCallback = new EnviarSituacaoOsCallback(
- linha.getContext(),
- progressDialog,
- urlBase);
- enviarSituacaoOsCallback.enviarDadosOs(envelopeSituacaoOs);
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- progressDialog.dismiss();
- }
- }
- }).start();
- }
- } else {
- if (spnSituacaoItem.isInEditMode()){
- carregaSpinner = true;
- }
- }
- }
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- }
- });
- linha.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent itDetalheAtendimento = new Intent(v.getContext(), DetalheAtendimentoActivity.class);
- itDetalheAtendimento.putExtra("atendimento", atendimentos1);
- itDetalheAtendimento.putExtra("posicaoAtualUsuario", posicaoAtualDoUsuario);
- v.getContext().startActivity(itDetalheAtendimento);
- }
- });
- return linha;
- }
- private void iniciadorComponente(View linha) {
- txtPrioridadeItem = (TextView) linha.findViewById(R.id.txtPrioridadeItem);
- txtNomeItem = (TextView) linha.findViewById(R.id.txtNomeItem);
- txtSituacaoClienteItem = (TextView) linha.findViewById(R.id.txtSituacaoClienteItem);
- txtProtocoloItem = (TextView) linha.findViewById(R.id.txtProtocoloItem);
- imgEnderecoItem = (ImageView) linha.findViewById(R.id.imgEnderecoItem);
- txtEnderecoItem = (TextView) linha.findViewById(R.id.txtEnderecoItem);
- imgTopicoItem = (ImageView) linha.findViewById(R.id.imgTopicoItem);
- txtTopicoItem = (TextView) linha.findViewById(R.id.txtTopicoItem);
- imgTempoItem = (ImageView) linha.findViewById(R.id.imgTempoItem);
- txtTempoItem = (TextView) linha.findViewById(R.id.txtTempoItem);
- imgAgendamentoItem = (ImageView) linha.findViewById(R.id.imgAgendamentoItem);
- txtAgendamentoItem = (TextView) linha.findViewById(R.id.txtAgendamentoItem);
- imgSlaItem = (ImageView) linha.findViewById(R.id.imgSlaItem);
- txtSlaItem = (TextView) linha.findViewById(R.id.txtSlaItem);
- txtSlaRestanteItem = (TextView) linha.findViewById(R.id.txtSlaRestanteItem);
- progressSlaRestante = (ProgressBar) linha.findViewById(R.id.progressSlaRestante);
- spnSituacaoItem = (Spinner) linha.findViewById(R.id.spnSituacaoItem);
- }
- private void iniciadorDados(Atendimento atendimentos1, View linha){
- SharedPreferences preferences = linha.getContext().getSharedPreferences("USER_INFORMATION", linha.getContext().MODE_PRIVATE);
- long prioridade = atendimentos1.getOrdemPrioridade();
- long protocolo = atendimentos1.getProtocolo();
- String em = "em ";
- String hrs = " hrs";
- urlBase = preferences.getString("urlBase", null);
- usuario = preferences.getString("usuario", null);
- dataFormatada = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date());
- txtPrioridadeItem.setText(String.valueOf(prioridade));
- txtNomeItem.setText(atendimentos1.getCliente());
- txtSituacaoClienteItem.setText(atendimentos1.getSituacaoCliente());
- txtProtocoloItem.setText(String.valueOf(protocolo));
- txtEnderecoItem.setText(atendimentos1.getEndereco());
- txtTopicoItem.setText(atendimentos1.getTopico());
- txtTempoItem.setText(em + atendimentos1.getDuracao() + hrs);
- txtAgendamentoItem.setText(atendimentos1.getAgendamento());
- txtSlaRestanteItem.setText(atendimentos1. getSlaFormatado());
- progressSlaRestante.setMax(100);
- progressSlaRestante.setProgress(60);
- progressSlaRestante.setProgressDrawable(linha.getResources().getDrawable(R.drawable.progress_bar_states));
- SpinnerAdapter spinnerAdapter = new SpinnerAdapter(linha.getContext(),icImagem, situacoes);
- spnSituacaoItem.setAdapter(spinnerAdapter);
- }
- }
- @Override
- public View getView(final int position, View convertView, ViewGroup parent) {
- ....
- ....
- } else if (progressSlaRestante.getProgress() > 75) {
- progressSlaRestante.setProgressDrawable(linha.getResources().getDrawable(R.drawable.progress_bar_state_red));
- }
- //Se houver algum listener atribuído anula-o
- spnSituacaoItemsetOnItemSelectedListener(null);
- //Coloca o setOnItemSelectedListener na pilha
- spnSituacaoItem.post(new Runnable() {
- @Override
- public void run() {
- //Coloque aqui todo o código do spnSituacaoItem.setOnItemSelectedListener
- spnSituacaoItem.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- if (carregaSpinner) {
- ....
- ....
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- }
- });
- }
- });
- ....
- ....
- return linha;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement