Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.88 KB | None | 0 0
  1. public class MenuActivity extends AppCompatActivity implements
  2. GoogleApiClient.ConnectionCallbacks, LocationListener {
  3.  
  4. @Override
  5. public void onCreate(@Nullable Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.activity_menu);
  8. iniciadorComponente(savedInstanceState);
  9. iniciadorDados();
  10.  
  11. swipeListaAtendimento.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
  12. @Override
  13. public void onRefresh() {
  14. requisicaoWsListaAtendimento(true);
  15. }
  16. });
  17. }
  18.  
  19.  
  20. private void iniciadorComponente(Bundle savedInstanceState) {
  21. swipeListaAtendimento = (SwipeRefreshLayout) findViewById(R.id.swipeListaAtendimento);
  22. listaAtendimentos = (ListView) findViewById(R.id.listaAtendimentos);
  23. progressListaAtendimentos = (ProgressBar) findViewById(R.id.progressListaAtendimentos);
  24. chaveIntegracaoClasse = new ChaveIntegracao();
  25. databaseHelper = new DatabaseHelper(MenuActivity.this);
  26. atendimentosDAO = new AtendimentosDAO();
  27.  
  28. if (savedInstanceState != null) {
  29. atendimentos = (ArrayList<Atendimento>) savedInstanceState.getSerializable("listaAtendimento");
  30. } else {
  31. atendimentos = new ArrayList<>();
  32. }
  33. }
  34.  
  35. private void iniciadorDados() {
  36. SharedPreferences preferences = getSharedPreferences("USER_INFORMATION", MODE_PRIVATE);
  37. urlBase = preferences.getString("urlBase", null);
  38. intervaloCoordenadas = preferences.getString("intervaloCoordenadas", null);
  39.  
  40.  
  41. }
  42.  
  43. @Override
  44. public void onResume() {
  45. super.onResume();
  46. requisicaoWsListaAtendimento(false);
  47. carregaListaAtendimentos();
  48. }
  49.  
  50. public void carregaListaAtendimentos(){
  51. atendimentos = atendimentosDAO.listarAtendimento(databaseHelper);
  52. atendimentoAdapter = new MenuAdapter(atendimentos, MenuActivity.this, posicaoAtualDoUsuario, carregaSpinner);
  53. listaAtendimentos.setAdapter(atendimentoAdapter);
  54. }
  55.  
  56. private void requisicaoWsListaAtendimento(boolean queroCarregarListaPeloSwipe){
  57. if (queroCarregarListaPeloSwipe){
  58. SharedPreferences preferences = getSharedPreferences("USER_INFORMATION", MODE_PRIVATE);
  59. Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(getResources().getString(R.string.cnpjTeste))); // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
  60.  
  61. DadosAtendimento dadosAtendimento = new DadosAtendimento("guilherme");
  62.  
  63. ListaAtendimentos listaAtendimentos1 = new ListaAtendimentos(autenticacao, dadosAtendimento);
  64. EnvelopeAtendimento envelopeAtendimento = new EnvelopeAtendimento(listaAtendimentos1);
  65.  
  66. //chama o retrofit para fazer a requisição no webservice
  67. EnviarDadosListaAtendimentosCallback enviarDadosListaAtendimentosCallback = new EnviarDadosListaAtendimentosCallback(
  68. MenuActivity.this,
  69. progressListaAtendimentos,
  70. listaAtendimentos,
  71. urlBase,
  72. swipeListaAtendimento);
  73. enviarDadosListaAtendimentosCallback.enviarDadosLista(envelopeAtendimento);
  74. } else {
  75. progressListaAtendimentos.setVisibility(View.VISIBLE);
  76. listaAtendimentos.setVisibility(View.GONE);
  77. SharedPreferences preferences = getSharedPreferences("USER_INFORMATION", MODE_PRIVATE);
  78. Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(getResources().getString(R.string.cnpjTeste))); // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
  79.  
  80. DadosAtendimento dadosAtendimento = new DadosAtendimento("guilherme");
  81.  
  82. ListaAtendimentos listaAtendimentos1 = new ListaAtendimentos(autenticacao, dadosAtendimento);
  83. EnvelopeAtendimento envelopeAtendimento = new EnvelopeAtendimento(listaAtendimentos1);
  84.  
  85. //chama o retrofit para fazer a requisição no webservice
  86. EnviarDadosListaAtendimentosCallback enviarDadosListaAtendimentosCallback = new EnviarDadosListaAtendimentosCallback(
  87. MenuActivity.this,
  88. progressListaAtendimentos,
  89. listaAtendimentos,
  90. urlBase,
  91. swipeListaAtendimento);
  92. enviarDadosListaAtendimentosCallback.enviarDadosLista(envelopeAtendimento);
  93. }
  94. }
  95.  
  96. public class MenuAdapter extends BaseAdapter {
  97.  
  98.  
  99. public MenuAdapter(List<Atendimento> atendimentos, Activity activity, String posicaoAtualDoUsuario, boolean carregaSpinner) {
  100. this.atendimentos = atendimentos;
  101. this.activity = activity;
  102. this.posicaoAtualDoUsuario = posicaoAtualDoUsuario;
  103. this.carregaSpinner = carregaSpinner;
  104. }
  105.  
  106.  
  107. @Override
  108. public int getCount() {
  109. return atendimentos.size();
  110. }
  111.  
  112. @Override
  113. public Object getItem(int position) {
  114. return atendimentos.get(position);
  115. }
  116.  
  117. @Override
  118. public long getItemId(int position) {
  119. return position;
  120. }
  121.  
  122. @Override
  123. public View getView(final int position, View convertView, ViewGroup parent) {
  124. final LayoutInflater inflater = activity.getLayoutInflater();
  125. final View linha = inflater.inflate(R.layout.item_atendimento, null);
  126.  
  127. final Atendimento atendimentos1 = atendimentos.get(position);
  128. iniciadorComponente(linha);
  129. iniciadorDados(atendimentos1, linha);
  130.  
  131.  
  132. if (atendimentos1.getSituacaoOS().equals("Na fila")) {
  133. spnSituacaoItem.setSelection(0);
  134. } else if (atendimentos1.getSituacaoOS().equals("A caminho")) {
  135. spnSituacaoItem.setSelection(1);
  136. } else if (atendimentos1.getSituacaoOS().equals("Em execução")) {
  137. spnSituacaoItem.setSelection(2);
  138. } else if (atendimentos1.getSituacaoOS().equals("Pausado")) {
  139. spnSituacaoItem.setSelection(3);
  140. } else if (atendimentos1.getSituacaoOS().equals("Concluído")) {
  141. spnSituacaoItem.setSelection(4);
  142. } else if (atendimentos1.getSituacaoOS().equals("Abortado")) {
  143. spnSituacaoItem.setSelection(5);
  144. }
  145.  
  146. // Verificação tempo
  147. if (atendimentos1.getDuracao().equals("")) {
  148. imgTempoItem.setVisibility(View.GONE);
  149. txtTempoItem.setVisibility(View.GONE);
  150. }
  151.  
  152. // Verificação agendamento
  153. if (atendimentos1.getAgendamento().equals("")) {
  154. imgAgendamentoItem.setVisibility(View.GONE);
  155. txtAgendamentoItem.setVisibility(View.GONE);
  156. }
  157.  
  158. // Verificação sla restante
  159. if (atendimentos1.getSlaFormatado().equals("")) {
  160. imgSlaItem.setVisibility(View.GONE);
  161. txtSlaItem.setVisibility(View.GONE);
  162. txtSlaRestanteItem.setVisibility(View.GONE);
  163. progressSlaRestante.setVisibility(View.GONE);
  164. }
  165.  
  166. // Verificação progress bar
  167. if (progressSlaRestante.getProgress() <= 25) {
  168. progressSlaRestante.setProgressDrawable(linha.getResources().getDrawable(R.drawable.progress_bar_state_green));
  169. } else if (progressSlaRestante.getProgress() > 25 && progressSlaRestante.getProgress() <= 50) {
  170. progressSlaRestante.setProgressDrawable(linha.getResources().getDrawable(R.drawable.progress_bar_state_yellow));
  171. } else if (progressSlaRestante.getProgress() > 50 && progressSlaRestante.getProgress() <= 75) {
  172. progressSlaRestante.setProgressDrawable(linha.getResources().getDrawable(R.drawable.progress_bar_state_orange));
  173. } else if (progressSlaRestante.getProgress() > 75) {
  174. progressSlaRestante.setProgressDrawable(linha.getResources().getDrawable(R.drawable.progress_bar_state_red));
  175. }
  176.  
  177.  
  178. spnSituacaoItem.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  179. @Override
  180. public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  181. if (carregaSpinner) {
  182. if (position == 0) {
  183. progressDialog = ProgressDialog.show(
  184. linha.getContext(),
  185. linha.getResources().getString(R.string.aguarde),
  186. linha.getResources().getString(R.string.enviandoDados),
  187. false,
  188. true
  189. );
  190. progressDialog.setCanceledOnTouchOutside(false);
  191. progressDialog.setCancelable(false);
  192.  
  193.  
  194. new Thread(new Runnable() {
  195. @Override
  196. public void run() {
  197. try {
  198. Thread.sleep(1000);
  199.  
  200. handler.post(new Runnable() {
  201. @Override
  202. public void run() {
  203. Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(linha.getResources().getString(R.string.cnpjTeste)));
  204. // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
  205.  
  206. DadosOS dadosOS = new DadosOS(atendimentos1.getNumero(), usuario, situacaoAnterior, "A", dataFormatada);
  207.  
  208. AlteraSituacaoOs alteraSituacaoOs = new AlteraSituacaoOs(autenticacao, dadosOS);
  209. EnvelopeSituacaoOs envelopeSituacaoOs = new EnvelopeSituacaoOs(alteraSituacaoOs);
  210.  
  211. //chama o retrofit para fazer a requisição no webservice
  212. EnviarSituacaoOsCallback enviarSituacaoOsCallback = new EnviarSituacaoOsCallback(
  213. linha.getContext(),
  214. progressDialog,
  215. urlBase);
  216. enviarSituacaoOsCallback.enviarDadosOs(envelopeSituacaoOs);
  217. }
  218. });
  219. } catch (Exception e) {
  220. e.printStackTrace();
  221. } finally {
  222. progressDialog.dismiss();
  223. }
  224. }
  225. }).start();
  226. carregaSpinner = false;
  227. } else if (position == 1) {
  228. progressDialog = ProgressDialog.show(
  229. linha.getContext(),
  230. linha.getResources().getString(R.string.aguarde),
  231. linha.getResources().getString(R.string.enviandoDados),
  232. false,
  233. true
  234. );
  235. progressDialog.setCanceledOnTouchOutside(false);
  236. progressDialog.setCancelable(false);
  237.  
  238.  
  239. new Thread(new Runnable() {
  240. @Override
  241. public void run() {
  242. try {
  243. Thread.sleep(1000);
  244.  
  245. handler.post(new Runnable() {
  246. @Override
  247. public void run() {
  248. Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(linha.getResources().getString(R.string.cnpjTeste)));
  249. // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
  250.  
  251. DadosOS dadosOS = new DadosOS(atendimentos1.getNumero(), usuario, situacaoAnterior, "A", dataFormatada);
  252.  
  253. AlteraSituacaoOs alteraSituacaoOs = new AlteraSituacaoOs(autenticacao, dadosOS);
  254. EnvelopeSituacaoOs envelopeSituacaoOs = new EnvelopeSituacaoOs(alteraSituacaoOs);
  255.  
  256. //chama o retrofit para fazer a requisição no webservice
  257. EnviarSituacaoOsCallback enviarSituacaoOsCallback = new EnviarSituacaoOsCallback(
  258. linha.getContext(),
  259. progressDialog,
  260. urlBase);
  261. enviarSituacaoOsCallback.enviarDadosOs(envelopeSituacaoOs);
  262. }
  263. });
  264. } catch (Exception e) {
  265. e.printStackTrace();
  266. } finally {
  267. progressDialog.dismiss();
  268. }
  269. }
  270. }).start();
  271. } else if (position == 2) {
  272. progressDialog = ProgressDialog.show(
  273. linha.getContext(),
  274. linha.getResources().getString(R.string.aguarde),
  275. linha.getResources().getString(R.string.enviandoDados),
  276. false,
  277. true
  278. );
  279. progressDialog.setCanceledOnTouchOutside(false);
  280. progressDialog.setCancelable(false);
  281.  
  282.  
  283. new Thread(new Runnable() {
  284. @Override
  285. public void run() {
  286. try {
  287. Thread.sleep(1000);
  288.  
  289. handler.post(new Runnable() {
  290. @Override
  291. public void run() {
  292. Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(linha.getResources().getString(R.string.cnpjTeste)));
  293. // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
  294.  
  295. DadosOS dadosOS = new DadosOS(atendimentos1.getNumero(), usuario, situacaoAnterior, "E", dataFormatada);
  296.  
  297. AlteraSituacaoOs alteraSituacaoOs = new AlteraSituacaoOs(autenticacao, dadosOS);
  298. EnvelopeSituacaoOs envelopeSituacaoOs = new EnvelopeSituacaoOs(alteraSituacaoOs);
  299.  
  300. //chama o retrofit para fazer a requisição no webservice
  301. EnviarSituacaoOsCallback enviarSituacaoOsCallback = new EnviarSituacaoOsCallback(
  302. linha.getContext(),
  303. progressDialog,
  304. urlBase);
  305. enviarSituacaoOsCallback.enviarDadosOs(envelopeSituacaoOs);
  306. }
  307. });
  308. } catch (Exception e) {
  309. e.printStackTrace();
  310. } finally {
  311. progressDialog.dismiss();
  312. }
  313. }
  314. }).start();
  315. } else if (position == 3) {
  316. progressDialog = ProgressDialog.show(
  317. linha.getContext(),
  318. linha.getResources().getString(R.string.aguarde),
  319. linha.getResources().getString(R.string.enviandoDados),
  320. false,
  321. true
  322. );
  323. progressDialog.setCanceledOnTouchOutside(false);
  324. progressDialog.setCancelable(false);
  325.  
  326.  
  327. new Thread(new Runnable() {
  328. @Override
  329. public void run() {
  330. try {
  331. Thread.sleep(1000);
  332.  
  333. handler.post(new Runnable() {
  334. @Override
  335. public void run() {
  336. Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(linha.getResources().getString(R.string.cnpjTeste)));
  337. // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
  338.  
  339. DadosOS dadosOS = new DadosOS(atendimentos1.getNumero(), usuario, situacaoAnterior, "P", dataFormatada);
  340.  
  341. AlteraSituacaoOs alteraSituacaoOs = new AlteraSituacaoOs(autenticacao, dadosOS);
  342. EnvelopeSituacaoOs envelopeSituacaoOs = new EnvelopeSituacaoOs(alteraSituacaoOs);
  343.  
  344. //chama o retrofit para fazer a requisição no webservice
  345. EnviarSituacaoOsCallback enviarSituacaoOsCallback = new EnviarSituacaoOsCallback(
  346. linha.getContext(),
  347. progressDialog,
  348. urlBase);
  349. enviarSituacaoOsCallback.enviarDadosOs(envelopeSituacaoOs);
  350. }
  351. });
  352. } catch (Exception e) {
  353. e.printStackTrace();
  354. } finally {
  355. progressDialog.dismiss();
  356. }
  357. }
  358. }).start();
  359.  
  360. } else if (position == 4) {
  361. progressDialog = ProgressDialog.show(
  362. linha.getContext(),
  363. linha.getResources().getString(R.string.aguarde),
  364. linha.getResources().getString(R.string.enviandoDados),
  365. false,
  366. true
  367. );
  368. progressDialog.setCanceledOnTouchOutside(false);
  369. progressDialog.setCancelable(false);
  370.  
  371.  
  372. new Thread(new Runnable() {
  373. @Override
  374. public void run() {
  375. try {
  376. Thread.sleep(1000);
  377.  
  378. handler.post(new Runnable() {
  379. @Override
  380. public void run() {
  381. Autenticacao autenticacao = new Autenticacao(chaveIntegracaoClasse.criarChaveIntegracao(linha.getResources().getString(R.string.cnpjTeste)));
  382. // DadosAtendimento dadosAtendimento = new DadosAtendimento(preferences.getString("nome", null));
  383.  
  384. DadosOS dadosOS = new DadosOS(atendimentos1.getNumero(), usuario, situacaoAnterior, "C", dataFormatada);
  385.  
  386. AlteraSituacaoOs alteraSituacaoOs = new AlteraSituacaoOs(autenticacao, dadosOS);
  387. EnvelopeSituacaoOs envelopeSituacaoOs = new EnvelopeSituacaoOs(alteraSituacaoOs);
  388.  
  389. //chama o retrofit para fazer a requisição no webservice
  390. EnviarSituacaoOsCallback enviarSituacaoOsCallback = new EnviarSituacaoOsCallback(
  391. linha.getContext(),
  392. progressDialog,
  393. urlBase);
  394. enviarSituacaoOsCallback.enviarDadosOs(envelopeSituacaoOs);
  395. }
  396. });
  397. } catch (Exception e) {
  398. e.printStackTrace();
  399. } finally {
  400. progressDialog.dismiss();
  401. }
  402. }
  403. }).start();
  404.  
  405. }
  406. } else {
  407. if (spnSituacaoItem.isInEditMode()){
  408. carregaSpinner = true;
  409. }
  410. }
  411. }
  412.  
  413. @Override
  414. public void onNothingSelected(AdapterView<?> parent) {
  415.  
  416. }
  417. });
  418.  
  419.  
  420. linha.setOnClickListener(new View.OnClickListener() {
  421. @Override
  422. public void onClick(View v) {
  423. Intent itDetalheAtendimento = new Intent(v.getContext(), DetalheAtendimentoActivity.class);
  424. itDetalheAtendimento.putExtra("atendimento", atendimentos1);
  425. itDetalheAtendimento.putExtra("posicaoAtualUsuario", posicaoAtualDoUsuario);
  426. v.getContext().startActivity(itDetalheAtendimento);
  427. }
  428. });
  429.  
  430. return linha;
  431. }
  432.  
  433. private void iniciadorComponente(View linha) {
  434. txtPrioridadeItem = (TextView) linha.findViewById(R.id.txtPrioridadeItem);
  435. txtNomeItem = (TextView) linha.findViewById(R.id.txtNomeItem);
  436. txtSituacaoClienteItem = (TextView) linha.findViewById(R.id.txtSituacaoClienteItem);
  437. txtProtocoloItem = (TextView) linha.findViewById(R.id.txtProtocoloItem);
  438. imgEnderecoItem = (ImageView) linha.findViewById(R.id.imgEnderecoItem);
  439. txtEnderecoItem = (TextView) linha.findViewById(R.id.txtEnderecoItem);
  440. imgTopicoItem = (ImageView) linha.findViewById(R.id.imgTopicoItem);
  441. txtTopicoItem = (TextView) linha.findViewById(R.id.txtTopicoItem);
  442. imgTempoItem = (ImageView) linha.findViewById(R.id.imgTempoItem);
  443. txtTempoItem = (TextView) linha.findViewById(R.id.txtTempoItem);
  444. imgAgendamentoItem = (ImageView) linha.findViewById(R.id.imgAgendamentoItem);
  445. txtAgendamentoItem = (TextView) linha.findViewById(R.id.txtAgendamentoItem);
  446. imgSlaItem = (ImageView) linha.findViewById(R.id.imgSlaItem);
  447. txtSlaItem = (TextView) linha.findViewById(R.id.txtSlaItem);
  448. txtSlaRestanteItem = (TextView) linha.findViewById(R.id.txtSlaRestanteItem);
  449. progressSlaRestante = (ProgressBar) linha.findViewById(R.id.progressSlaRestante);
  450. spnSituacaoItem = (Spinner) linha.findViewById(R.id.spnSituacaoItem);
  451. }
  452.  
  453. private void iniciadorDados(Atendimento atendimentos1, View linha){
  454. SharedPreferences preferences = linha.getContext().getSharedPreferences("USER_INFORMATION", linha.getContext().MODE_PRIVATE);
  455. long prioridade = atendimentos1.getOrdemPrioridade();
  456. long protocolo = atendimentos1.getProtocolo();
  457. String em = "em ";
  458. String hrs = " hrs";
  459.  
  460. urlBase = preferences.getString("urlBase", null);
  461. usuario = preferences.getString("usuario", null);
  462. dataFormatada = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date());
  463.  
  464. txtPrioridadeItem.setText(String.valueOf(prioridade));
  465. txtNomeItem.setText(atendimentos1.getCliente());
  466. txtSituacaoClienteItem.setText(atendimentos1.getSituacaoCliente());
  467. txtProtocoloItem.setText(String.valueOf(protocolo));
  468. txtEnderecoItem.setText(atendimentos1.getEndereco());
  469. txtTopicoItem.setText(atendimentos1.getTopico());
  470. txtTempoItem.setText(em + atendimentos1.getDuracao() + hrs);
  471. txtAgendamentoItem.setText(atendimentos1.getAgendamento());
  472. txtSlaRestanteItem.setText(atendimentos1. getSlaFormatado());
  473. progressSlaRestante.setMax(100);
  474. progressSlaRestante.setProgress(60);
  475. progressSlaRestante.setProgressDrawable(linha.getResources().getDrawable(R.drawable.progress_bar_states));
  476. SpinnerAdapter spinnerAdapter = new SpinnerAdapter(linha.getContext(),icImagem, situacoes);
  477. spnSituacaoItem.setAdapter(spinnerAdapter);
  478. }
  479. }
  480.  
  481. @Override
  482. public View getView(final int position, View convertView, ViewGroup parent) {
  483. ....
  484. ....
  485. } else if (progressSlaRestante.getProgress() > 75) {
  486. progressSlaRestante.setProgressDrawable(linha.getResources().getDrawable(R.drawable.progress_bar_state_red));
  487. }
  488.  
  489. //Se houver algum listener atribuído anula-o
  490. spnSituacaoItemsetOnItemSelectedListener(null);
  491. //Coloca o setOnItemSelectedListener na pilha
  492. spnSituacaoItem.post(new Runnable() {
  493. @Override
  494. public void run() {
  495.  
  496. //Coloque aqui todo o código do spnSituacaoItem.setOnItemSelectedListener
  497.  
  498. spnSituacaoItem.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  499. @Override
  500. public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  501. if (carregaSpinner) {
  502. ....
  503. ....
  504. @Override
  505. public void onNothingSelected(AdapterView<?> parent) {
  506.  
  507. }
  508. });
  509. }
  510. });
  511. ....
  512. ....
  513. return linha;
  514. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement