Advertisement
ricky_yulianto

Untitled

Jul 11th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. package codelabs.ambarrukmo.activity;
  2.  
  3. import android.content.Intent;
  4. import android.support.design.widget.AppBarLayout;
  5. import android.support.design.widget.BottomSheetDialog;
  6. import android.support.design.widget.BottomSheetDialogFragment;
  7. import android.support.v4.widget.NestedScrollView;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.os.Bundle;
  10. import android.support.v7.widget.LinearLayoutManager;
  11. import android.view.View;
  12. import android.view.WindowManager;
  13. import android.widget.Button;
  14. import android.widget.ImageView;
  15. import android.widget.TextView;
  16.  
  17. import com.google.gson.Gson;
  18. import com.squareup.picasso.Picasso;
  19.  
  20. import butterknife.BindView;
  21. import butterknife.ButterKnife;
  22. import butterknife.OnClick;
  23. import codelabs.ambarrukmo.R;
  24. import codelabs.ambarrukmo.fragment.BarcodeMenuFragment;
  25. import codelabs.ambarrukmo.fragment.QrCodeVoucherFragment;
  26. import codelabs.ambarrukmo.model.CategoryListPromo;
  27. import codelabs.ambarrukmo.model.GetPromoList;
  28. import codelabs.ambarrukmo.utils.RecentUtils;
  29.  
  30. public class PromoCategoryDetailActivity extends BaseActivity implements View.OnClickListener {
  31.  
  32.  
  33. @BindView(R.id.iv_back)
  34. ImageView ivBack;
  35. @BindView(R.id.img_promo)
  36. ImageView imgPromo;
  37. @BindView(R.id.appbar)
  38. AppBarLayout appbar;
  39. @BindView(R.id.tv_promotitle)
  40. TextView tvPromoTitle;
  41. @BindView(R.id.nested_scroll)
  42. NestedScrollView nestedScroll;
  43. @BindView(R.id.tv_highlights1)
  44. TextView tvHighlights;
  45. @BindView(R.id.tv_notice2)
  46. TextView tvNotice;
  47. @BindView(R.id.btn_check_now)
  48. Button btnCheckNow;
  49. @BindView(R.id.btn_view_promo)
  50. TextView btnViewPromo;
  51. @BindView(R.id.viewMoreHighlight)
  52. Button viewMoreHighlight;
  53. @BindView(R.id.viewMoreNotice)
  54. Button viewMoreNotice;
  55.  
  56.  
  57.  
  58. CategoryListPromo.DATABean.Promotions getPromoList;
  59.  
  60.  
  61. LinearLayoutManager layoutManager;
  62. private int mMaxScrollSize;
  63. private boolean mIsElementHidden;
  64. private static final int PERCENTAGE_TO_SHOW_ELEMENT = 40;
  65.  
  66. @Override
  67. protected void onCreate(Bundle savedInstanceState) {
  68. super.onCreate(savedInstanceState);
  69. setContentView(R.layout.activity_promo_detail_category);
  70. getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //for transparant status bar
  71. ButterKnife.bind(this);
  72. initVariables();
  73. initListeners();
  74. callFunctions();
  75.  
  76.  
  77. }
  78.  
  79. private void initVariables(){
  80. getPromoList = new Gson().fromJson(getIntent().getStringExtra("promo"),CategoryListPromo.DATABean.Promotions.class);
  81. }
  82.  
  83. private void initListeners(){
  84. btnCheckNow.setOnClickListener(this);
  85. btnViewPromo.setOnClickListener(this);
  86. viewMoreHighlight.setOnClickListener(this);
  87. viewMoreNotice.setOnClickListener(this);
  88.  
  89. }
  90.  
  91. private void callFunctions(){
  92. setData();
  93.  
  94. }
  95.  
  96. public void showBottomSheetDialog() {
  97. BottomSheetDialogFragment bottomSheetDialogFragment = new QrCodeVoucherFragment();
  98. bottomSheetDialogFragment.show(getSupportFragmentManager(),bottomSheetDialogFragment.getTag());
  99. }
  100.  
  101. private void setData() {
  102.  
  103. Picasso.get()
  104. .load(getPromoList.getPromo_image())
  105. .placeholder(R.drawable.img_step2)
  106. .error(R.drawable.img_step2)
  107. .into(imgPromo);
  108.  
  109. tvPromoTitle.setText(getPromoList.getPromo_title());
  110. tvHighlights.setText(RecentUtils.fromHtml(getPromoList.getHighlight_txt()));
  111. tvNotice.setText(RecentUtils.fromHtml(getPromoList.getNotice_txt()));
  112. }
  113.  
  114. public void viewPromoDetail() {
  115. Intent intent = new Intent(PromoCategoryDetailActivity.this, ViewPromoDetailActivity.class);
  116. // intent.putExtra("promoimage", getPromoList.getPromo_image());
  117. // intent.putExtra("promo",getPromoList.getPromo_title());
  118. // intent.putExtra("promotitle", getPromoList.get());
  119.  
  120. startActivity(intent);
  121. }
  122.  
  123.  
  124. @Override
  125. public void onClick(View view) {
  126. if (view == btnCheckNow) {
  127. View sheetView= getLayoutInflater().inflate(R.layout.confirm_voucher_bottomdialog, null);
  128.  
  129.  
  130. BottomSheetDialog dialog = new BottomSheetDialog(this);
  131. dialog.setContentView(sheetView);
  132. dialog.show();
  133.  
  134.  
  135. Button buttoncancel = (Button)
  136. sheetView.findViewById(R.id.btn_cancel);
  137. Button buttonConf = (Button)
  138. sheetView.findViewById(R.id.btn_confirm);
  139.  
  140. buttoncancel.setOnClickListener(new View.OnClickListener() {
  141. @Override
  142. public void onClick(View v) {
  143. dialog.dismiss();
  144. }
  145. });
  146.  
  147. buttonConf.setOnClickListener(new View.OnClickListener() {
  148. @Override
  149. public void onClick(View v) {
  150. showBottomSheetDialog();
  151. }
  152. });
  153. }
  154. else if (view == btnViewPromo) {
  155. viewPromoDetail();
  156. }
  157. else if (view == viewMoreHighlight) {
  158. if (viewMoreHighlight.getText().toString().equals("View more")) {
  159. tvHighlights.setMaxLines(Integer.MAX_VALUE);
  160. viewMoreHighlight.setText("View less");
  161. } else {
  162. tvHighlights.setMaxLines(5);
  163. viewMoreHighlight.setText("View more");
  164. }
  165. } else if (view == viewMoreNotice) {
  166. if (viewMoreNotice.getText().toString().equals("View more")) {
  167. tvNotice.setMaxLines(Integer.MAX_VALUE);
  168. viewMoreNotice.setText("View less");
  169. } else {
  170. tvNotice.setMaxLines(5);
  171. viewMoreNotice.setText("View more");
  172. }
  173. }
  174.  
  175. }
  176.  
  177. @OnClick(R.id.iv_back)
  178. void closeactivity(){
  179. finish();
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement