BulletinDetails.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package com.cygnusa.hyperm;
  2. import android.annotation.SuppressLint;
  3. import android.graphics.PorterDuff;
  4. import android.graphics.drawable.Drawable;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.MenuItem;
  8. import android.view.View;
  9. import android.widget.ImageView;
  10. import android.widget.TextView;
  11. import androidx.appcompat.app.AppCompatActivity;
  12. import androidx.appcompat.widget.Toolbar;
  13. import com.bumptech.glide.Glide;
  14. import com.bumptech.glide.load.engine.DiskCacheStrategy;
  15. import com.bumptech.glide.request.RequestOptions;
  16. import com.cygnusa.hyperm.util.ApiService;
  17. import com.cygnusa.hyperm.util.MainApplication;
  18. import com.cygnusa.hyperm.wrappers.Bulletin;
  19. import com.cygnusa.hyperm.wrappers.CommonResponse;
  20. import java.text.ParseException;
  21. import java.text.SimpleDateFormat;
  22. import java.util.Date;
  23. import retrofit2.Call;
  24. import retrofit2.Callback;
  25. import retrofit2.Response;
  26. public class BulletinDetails extends AppCompatActivity {
  27. public static Bulletin CONTENT = new Bulletin();
  28. TextView title, desc, publishedDate, headtitle;
  29. ImageView image;
  30. private String bulletinId;
  31. private ApiService apiService;
  32. @Override
  33. protected void onCreate(Bundle savedInstanceState) {
  34. super.onCreate(savedInstanceState);
  35. setContentView(R.layout.activity_bulletin_details);
  36. setupWindowAnimations();
  37. headtitle = findViewById(R.id.title);
  38. title = findViewById(R.id.bulletinTitle);
  39. desc = findViewById(R.id.bulletinDescription);
  40. publishedDate = findViewById(R.id.publishedDate);
  41. image = findViewById(R.id.myImage);
  42. // mImageLangSelection = findViewById(R.id.imgLanguage);
  43. publishedDate.setText("Published On: " + dateFormate(CONTENT.getPublished_date()));
  44. title.setText(CONTENT.getBulletin_title());
  45. headtitle.setText("Bulletin");
  46. desc.setText(CONTENT.getBulletin_desc());
  47. Toolbar toolbar = findViewById(R.id.toolbar);
  48. setSupportActionBar(toolbar);
  49. toolbar.setNavigationIcon(R.mipmap.back);
  50. toolbar.setContentInsetStartWithNavigation(0);
  51. toolbar.setTitle("");
  52. getSupportActionBar().setTitle("");
  53. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  54. getSupportActionBar().setDisplayShowHomeEnabled(true);
  55. @SuppressLint("PrivateResource")
  56. Drawable backArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_material);
  57. backArrow.setColorFilter(getResources().getColor(R.color.btn_bg_color), PorterDuff.Mode.SRC_ATOP);
  58. getSupportActionBar().setHomeAsUpIndicator(backArrow);
  59. apiService = ((MainApplication) getApplication()).getClient();
  60. Bundle bundle = getIntent().getExtras();
  61. if (bundle != null) {
  62. bulletinId = bundle.getString("bulletinId");
  63. }
  64. sendBulletinIdUpdate();
  65. findViewById(R.id.helpIcon).setOnClickListener(new View.OnClickListener() {
  66. @Override
  67. public void onClick(View v) {
  68. }
  69. });
  70. Glide.with(this).load(CONTENT.getImage_url())
  71. .thumbnail(Glide.with(this).load(R.drawable.gif_loader))
  72. .apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL).centerCrop()
  73. .placeholder(R.drawable.placeholder)).into(image);
  74. }
  75. private void sendBulletinIdUpdate() {
  76. apiService.sendBulletinUpdate(bulletinId).enqueue(new Callback<CommonResponse>() {
  77. @Override
  78. public void onResponse(Call<CommonResponse> call, Response<CommonResponse> response) {
  79. if (response.body() != null) {
  80. Log.e("BulletinResponse", response.body().getMessage());
  81. }
  82. }
  83. @Override
  84. public void onFailure(Call<CommonResponse> call, Throwable t) {
  85. if (t.getMessage() != null)
  86. Log.e("BulletinFailedResponse", t.getMessage());
  87. }
  88. });
  89. }
  90. private void setupWindowAnimations() {
  91. this.overridePendingTransition(R.anim.animation_enter,
  92. R.anim.animation_leave);
  93. }
  94. @Override
  95. public boolean onOptionsItemSelected(MenuItem item) {
  96. if (item.getItemId() == android.R.id.home) {
  97. confirmClose();
  98. }
  99. return super.onOptionsItemSelected(item);
  100. }
  101. private void confirmClose() {
  102. finish();
  103. BulletinDetails.this.overridePendingTransition(R.anim.animation_f_enter,
  104. R.anim.animation_f_leave);
  105. }
  106. @Override
  107. public void onBackPressed() {
  108. super.onBackPressed();
  109. this.overridePendingTransition(R.anim.animation_f_enter,
  110. R.anim.animation_f_leave);
  111. }
  112. public String dateFormate(String dte) {
  113. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  114. Date newDate = null;
  115. try {
  116. newDate = format.parse(dte);
  117. } catch (ParseException e) {
  118. e.printStackTrace();
  119. }
  120. format = new SimpleDateFormat("dd-MMM-yyyy");
  121. String date = format.format(newDate);
  122. return date;
  123. }
  124. }