daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ebnrdwan.io.parentalApp.ChildApp.TasksChild.TaskDetails;
  2.  
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.v4.text.TextUtilsCompat;
  6. import android.text.TextUtils;
  7. import android.util.LayoutDirection;
  8. import android.view.View;
  9. import android.widget.FrameLayout;
  10. import android.widget.LinearLayout;
  11. import android.widget.TextView;
  12.  
  13. import com.daimajia.slider.library.SliderTypes.BaseSliderView;
  14. import com.daimajia.slider.library.SliderTypes.TextSliderView;
  15. import com.google.gson.Gson;
  16.  
  17. import java.util.ArrayList;
  18. import java.util.HashMap;
  19. import java.util.Locale;
  20.  
  21. import butterknife.BindView;
  22. import butterknife.ButterKnife;
  23. import butterknife.OnClick;
  24. import butterknife.Unbinder;
  25. import ebnrdwan.io.parentalApp.ChildApp.TasksChild.EditTask.EditTaskActivity;
  26. import ebnrdwan.io.parentalApp.R;
  27. import ebnrdwan.io.parentalApp.Repository.Models.ApiResponse.TaskModelResponse;
  28. import ebnrdwan.io.parentalApp.Repository.Remote.Api.ApiClientConfig;
  29. import ebnrdwan.io.parentalApp.Utilities.BaseActivity;
  30. import ebnrdwan.io.parentalApp.Utilities.Constants;
  31. import ebnrdwan.io.parentalApp.Utilities.CustomWidgets.ChildAnimationExample;
  32. import ebnrdwan.io.parentalApp.Utilities.CustomWidgets.SliderLayout;
  33. import ebnrdwan.io.parentalApp.Utilities.RealmGsonBuilder;
  34. import ebnrdwan.io.parentalApp.Utilities.SharedPrefrences.SessionManager;
  35.  
  36. import static maes.tech.intentanim.CustomIntent.customType;
  37.  
  38. public class TaskDetailsActivity extends BaseActivity implements BaseSliderView.OnSliderClickListener {
  39.     @BindView(R.id.slider)
  40.     public SliderLayout pagerSlider;
  41.     @BindView(R.id.btn_edit_task)
  42.     FrameLayout btnEditTask;
  43.     @BindView(R.id.view_task_label_pending)
  44.     LinearLayout pendingTask;
  45.     @BindView(R.id.view_task_label_compelete)
  46.     LinearLayout completeTask;
  47.     @BindView(R.id.view_task_label_pending_conf)
  48.     LinearLayout pendingConfirm;
  49.     @BindView(R.id.task_start_time)
  50.     TextView startTime;
  51.     @BindView(R.id.task_end_time)
  52.     TextView endTime;
  53.     @BindView(R.id.task_title)
  54.     TextView taskTitle;
  55.     @BindView(R.id.tv_repeat)
  56.     TextView repeat;
  57.     @BindView(R.id.reward_browsing)
  58.     TextView rewardBrowsing;
  59.     @BindView(R.id.reward_application)
  60.     TextView rewardApplication;
  61.     @BindView(R.id.reward_internet)
  62.     TextView rewardInternet;
  63.     TaskModelResponse.TaskList model;
  64.     Unbinder unbinder;
  65.  
  66.     @Override
  67.     protected void onCreate(Bundle savedInstanceState) {
  68.         super.onCreate(savedInstanceState);
  69.  
  70.         unbinder = ButterKnife
  71.                 .bind(this);
  72.         if (getIntent().hasExtra("task")) {
  73.             model = new Gson().fromJson(getIntent().getExtras().getString("task"), TaskModelResponse.TaskList.class);
  74.             if (Constants.TASK_PENDING_CONFIRM.equals(model.getTask_status()))
  75.                 btnEditTask.setVisibility(View.VISIBLE);
  76.             fillData();
  77.         }
  78.         if (SessionManager.getInstance().getUserData().getUser_role() == Constants.CHILD_TYPE) {
  79.             if (!Constants.TASK_PENDING_CONFIRM.equals(model.getTask_status()) && !Constants.TASK_COMPLETE.equals(model.getTask_status()))
  80.                 btnEditTask.setVisibility(View.VISIBLE);
  81.             else btnEditTask.setVisibility(View.GONE);
  82.         } else {
  83.             if (Constants.TASK_PENDING_CONFIRM.equals(model.getTask_status()))
  84.                 btnEditTask.setVisibility(View.VISIBLE);
  85.             else btnEditTask.setVisibility(View.GONE);
  86.         }
  87.  
  88.         if (TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == LayoutDirection.RTL)
  89.             btnEditTask.setScaleX(-1);
  90.         else btnEditTask.setScaleX(1);
  91.         initSlider();
  92.  
  93.  
  94.     }
  95.  
  96.     void fillData() {
  97.         if (model != null) {
  98.             taskTitle.setText(model.getTask_name());
  99.             startTime.setText(model.getTask_time_from());
  100.             endTime.setText(model.getTask_time_to());
  101.             handleTaskStatus(model.getTask_status(), "");
  102. //            if (!TextUtils.isEmpty(model.getTast_repeat_type()))
  103. //                repeat.setText(model.getTast_repeat_type() + "");
  104. //            else repeat.setText(R.string.not_repeat);
  105.             fillTextView(repeat, model.getTast_repeat_type(), getResources().getString(R.string.not_repeat), false);
  106.             fillTextView(rewardInternet, model.getAward_usage_internet() + "", "0", true);
  107.             fillTextView(rewardBrowsing, model.getAward_usage_browser() + "", "0", true);
  108.             fillTextView(rewardApplication, model.getAward_usage_package() + "", "non", true);
  109.         }
  110.     }
  111.  
  112.     void fillTextView(TextView view, String fill, String error, boolean hideIfEmpty) {
  113.         if (!TextUtils.isEmpty(fill)) {
  114.             view.setText(fill);
  115.         } else {
  116.             if (hideIfEmpty) view.setVisibility(View.GONE);
  117.             else view.setText(error);
  118.         }
  119.     }
  120.  
  121.     void handleTaskStatus(String state, String confirmation) {
  122.         if (Constants.TASK_COMPLETE.equals(state)) {
  123.             pendingTask.setVisibility(View.GONE);
  124.             pendingConfirm.setVisibility(View.GONE);
  125.             completeTask.setVisibility(View.VISIBLE);
  126.  
  127.         } else if (Constants.TASK_PENDING_CONFIRM.equals(state)) {
  128.             completeTask.setVisibility(View.GONE);
  129.             pendingTask.setVisibility(View.GONE);
  130.             pendingConfirm.setVisibility(View.VISIBLE);
  131.         } else {
  132.             completeTask.setVisibility(View.GONE);
  133.             pendingTask.setVisibility(View.VISIBLE);
  134.             pendingConfirm.setVisibility(View.GONE);
  135.         }
  136.  
  137.     }
  138.  
  139.     @Override
  140.     protected int getLayoutId() {
  141.         return R.layout.activity_task_details;
  142.     }
  143.  
  144.     // TODO: 18/03/2018 1- when pending ---> adding button to submit   , ---> hide image slider
  145.     // TODO: 18/03/2018 2- adding the confirmer person and the gift
  146.  
  147.     private void initSlider() {
  148.  
  149.         if (model.getTask_image() != null)
  150.             if (model.getTask_image().size() > 0) {
  151.                 HashMap<String, String> file_maps2 = new HashMap<String, String>();
  152.                 file_maps2.put("1", ApiClientConfig.IMAGE_URL + model.getTask_image().get(0).getTask_url_image());
  153.                 if (model.getTask_image().size() > 1)
  154.                     file_maps2.put("2", ApiClientConfig.IMAGE_URL + model.getTask_image().get(1).getTask_url_image());
  155.                 if (model.getTask_image().size() > 2)
  156.                     file_maps2.put("3", ApiClientConfig.IMAGE_URL + model.getTask_image().get(2).getTask_url_image());
  157.                 for (String name : file_maps2.keySet()) {
  158.                     TextSliderView textSliderView = new TextSliderView(this);
  159.                     // initialize a SliderLayout
  160.                     textSliderView
  161.                             //  .description(name)
  162.                             .image(file_maps2.get(name))
  163.                             .setScaleType(BaseSliderView.ScaleType.CenterCrop)
  164.                             .setOnSliderClickListener(this);
  165.                     textSliderView.bundle(new Bundle());
  166.                     textSliderView.getBundle().putString("extra", name);
  167.                     pagerSlider.addSlider(textSliderView);
  168.  
  169.                     pagerSlider.setPresetTransformer(SliderLayout.Transformer.Default);
  170.                     pagerSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
  171.                     pagerSlider.setCustomAnimation(new ChildAnimationExample());
  172.                     pagerSlider.setDuration(4000);
  173.                     pagerSlider.addOnPageChangeListener(this);
  174.                     return;
  175.                 }
  176.             }
  177.         HashMap<String, Integer> file_maps = new HashMap<String, Integer>();
  178.         file_maps.put("1", R.drawable.task2);
  179.         file_maps.put("2", R.drawable.task2);
  180.         file_maps.put("3", R.drawable.task3);
  181.         for (String name : file_maps.keySet()) {
  182.             TextSliderView textSliderView = new TextSliderView(this);
  183.             // initialize a SliderLayout
  184.             textSliderView
  185.                     .image(file_maps.get(name))
  186.                     .setScaleType(BaseSliderView.ScaleType.CenterCrop)
  187.                     .setOnSliderClickListener(this);
  188.             textSliderView.bundle(new Bundle());
  189.             textSliderView.getBundle().putString("extra", name);
  190.             pagerSlider.addSlider(textSliderView);
  191.         }
  192.  
  193.         pagerSlider.setPresetTransformer(SliderLayout.Transformer.Default);
  194.         pagerSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
  195.         pagerSlider.setCustomAnimation(new ChildAnimationExample());
  196.         pagerSlider.setDuration(4000);
  197.         pagerSlider.addOnPageChangeListener(this);
  198.  
  199.  
  200.     }
  201.  
  202.     @OnClick(R.id.btn_edit_task)
  203.     void openEditActivity() {
  204.         Intent intent = new Intent(TaskDetailsActivity.this, EditTaskActivity.class);
  205.         String modelString = "";
  206.         modelString = RealmGsonBuilder.getInstance().toJson(model);
  207.         intent.putExtra("task", modelString);
  208.         startActivity(intent);
  209.         customType(TaskDetailsActivity.this, Constants.BOTTOM_TO_UP);
  210.     }
  211.  
  212.     @Override
  213.     protected void onDestroy() {
  214.         super.onDestroy();
  215.         unbinder.unbind();
  216.     }
  217.  
  218.     @Override
  219.     public void onSliderClick(BaseSliderView slider) {
  220.  
  221.     }
  222.  
  223.     @Override
  224.     public void onPermissionGranted() {
  225.  
  226.     }
  227.  
  228.     @Override
  229.     public void onPermissionDenied(ArrayList<String> deniedPermissions) {
  230.  
  231.     }
  232. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top