Advertisement
Eplayer

Customer Adapter No Grey

Jul 23rd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.29 KB | None | 0 0
  1. package id.co.acc.www.amos.adapter;
  2.  
  3. import android.app.Dialog;
  4. import android.content.Context;
  5. import android.content.DialogInterface;
  6. import android.content.Intent;
  7. import android.support.v7.widget.RecyclerView;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.widget.LinearLayout;
  12. import android.widget.TextView;
  13.  
  14. import com.google.gson.Gson;
  15. import com.raizlabs.android.dbflow.sql.language.SQLite;
  16.  
  17. import java.text.DateFormat;
  18. import java.text.SimpleDateFormat;
  19. import java.util.Date;
  20. import java.util.List;
  21.  
  22. import id.co.acc.www.amos.R;
  23. import id.co.acc.www.amos.activity.CustomerDetailActivity;
  24. import id.co.acc.www.amos.activity.HomeActivity;
  25. import id.co.acc.www.amos.model.TGprs.DataObject;
  26. import id.co.acc.www.amos.model.TGprs.DataObject_Table;
  27. import id.co.acc.www.amos.util.GlobalParam;
  28. import id.co.acc.www.amos.util.ItemAnimation;
  29. import id.co.acc.www.amos.util.SharedPreferenceUtils;
  30. import id.co.acc.www.amos.util.StringConverter;
  31. import id.co.acc.www.amos.util.UpdateSurveyUtil;
  32.  
  33. public class CustomerListAdapter extends RecyclerView.Adapter<CustomerListAdapter.ViewHolder> {
  34.  
  35. private Context context;
  36. private List<DataObject> tgprs;
  37. private String activePage;
  38.  
  39. public CustomerListAdapter(Context context, List<DataObject> tgprs, String activePage) {
  40.  
  41. this.context = context;
  42. this.tgprs = tgprs;
  43. this.activePage = activePage;
  44. }
  45.  
  46. @Override
  47. public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  48. if(activePage.equalsIgnoreCase(context.getString(R.string.pendingSurvey))){
  49. View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.lst_customer, parent, false);
  50. LinearLayout a = v.findViewById(R.id.lytCustomerList);
  51. a.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));
  52. ViewHolder holder = new ViewHolder(v);
  53. return holder;
  54. }else{
  55. View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.lst_customer, parent, false);
  56. ViewHolder holder = new ViewHolder(v);
  57. return holder;
  58. }
  59. }
  60.  
  61. @Override
  62. public void onBindViewHolder(ViewHolder holder, final int position) {
  63. final DataObject value = tgprs.get(position);
  64.  
  65.  
  66. String namepass[] = value.getMessage().split(";");
  67. String address = namepass[10];
  68. String dokumen="";
  69. String grading = namepass[0];
  70. try
  71. {
  72. if(!namepass[34].equals(" "))
  73. dokumen = namepass[34];
  74. }
  75. catch (Exception e)
  76. {
  77.  
  78. }
  79. holder.txtCustomerNameList.setText(value.getCustName());
  80. // holder.txtLogDateCorrection.setText(value.getLogDate());
  81. holder.txtAddressList.setText(address);
  82. holder.txtOrderNoList.setText(value.getOrderNo()+" ("+grading+")");
  83.  
  84. if(!dokumen.isEmpty())
  85. {
  86. holder.txtDoc.setVisibility(View.VISIBLE);
  87. }
  88. else
  89. holder.txtDoc.setVisibility(View.GONE);
  90.  
  91. String lockStatus = GlobalParam.getValue("LockSurvey");
  92. Date date=new Date();
  93. DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
  94. DateFormat timeFormat = new SimpleDateFormat("HH:mm");
  95. final String dateOpen=dateFormat.format(date);
  96. final String timeOpen=timeFormat.format(date);
  97. if(lockStatus.equalsIgnoreCase("no"))
  98. {
  99. if(activePage.equalsIgnoreCase(context.getString(R.string.new_survey)))
  100. {
  101. if(SQLite.select().from(DataObject.class)
  102. .where(DataObject_Table.processFlag.eq("1")).queryList().size()==0)
  103. {
  104. if(position>0)
  105. {
  106. /*holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));*/
  107. holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
  108. }
  109. else
  110. {
  111. holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
  112. }
  113.  
  114. holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
  115. @Override
  116. public void onClick(View view) {
  117. updateOpenDate(dateOpen, timeOpen, value);
  118. goToCustomerDetail(value, position);
  119. }
  120. });
  121. holder.lytCustomerList.setOnLongClickListener(new View.OnLongClickListener() {
  122. @Override
  123. public boolean onLongClick(View v) {
  124. //show pop up
  125. /*DialogAdapter.showDialogOneBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
  126. , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
  127. @Override
  128. public void onClick(DialogInterface dialog, int which) {
  129.  
  130. }
  131. });*/
  132.  
  133. DialogAdapter.showDialogTwoBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
  134. , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
  135. @Override
  136. public void onClick(DialogInterface dialogInterface, int i) {
  137. new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
  138. value.delete();
  139. Intent intention = new Intent(context, HomeActivity.class);
  140. context.startActivity(intention);
  141.  
  142. }
  143. }, context.getString(R.string.no), new DialogInterface.OnClickListener() {
  144. @Override
  145. public void onClick(DialogInterface dialogInterface, int i) {
  146.  
  147. }
  148. }
  149. );
  150. return true;
  151. }
  152. });
  153. }
  154. else
  155. {
  156. /*holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));*/
  157. holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
  158. holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
  159. @Override
  160. public void onClick(View view) {
  161. updateOpenDate(dateOpen, timeOpen, value);
  162. goToCustomerDetail(value, position);
  163. }
  164. });
  165. holder.lytCustomerList.setOnLongClickListener(new View.OnLongClickListener() {
  166. @Override
  167. public boolean onLongClick(View v) {
  168. //show pop up
  169. DialogAdapter.showDialogTwoBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
  170. , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
  171. @Override
  172. public void onClick(DialogInterface dialogInterface, int i) {
  173. new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
  174. value.delete();
  175. Intent intention = new Intent(context, HomeActivity.class);
  176. context.startActivity(intention);
  177. }
  178. }, context.getString(R.string.no), new DialogInterface.OnClickListener() {
  179. @Override
  180. public void onClick(DialogInterface dialogInterface, int i) {
  181.  
  182. }
  183. }
  184. );
  185. return true;
  186. }
  187. });
  188. }
  189. }
  190. else if(activePage.equalsIgnoreCase(context.getString(R.string.active_survey)))
  191. {
  192. if(position>0)
  193. {
  194. /*holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));*/
  195. holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
  196. }
  197.  
  198. holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
  199. @Override
  200. public void onClick(View view) {
  201. goToCustomerDetail(value, position);
  202. }
  203. });
  204. holder.lytCustomerList.setOnLongClickListener(new View.OnLongClickListener() {
  205. @Override
  206. public boolean onLongClick(View v) {
  207. //show pop up
  208. DialogAdapter.showDialogTwoBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
  209. , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
  210. @Override
  211. public void onClick(DialogInterface dialogInterface, int i) {
  212. new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
  213. value.delete();
  214. Intent intention = new Intent(context, HomeActivity.class);
  215. context.startActivity(intention);
  216. }
  217. }, context.getString(R.string.no), new DialogInterface.OnClickListener() {
  218. @Override
  219. public void onClick(DialogInterface dialogInterface, int i) {
  220.  
  221. }
  222. }
  223. );
  224. return true;
  225. }
  226. });
  227. }else if(activePage.equalsIgnoreCase(context.getString(R.string.pendingSurvey))){
  228. holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
  229. @Override
  230. public void onClick(View v) {
  231. DialogAdapter.showDialogOneBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
  232. , "Maaf anda tidak bisa mengedit data ini lagi", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
  233. @Override
  234. public void onClick(DialogInterface dialog, int which) {
  235. new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
  236. value.delete();
  237. Intent intention = new Intent(context, HomeActivity.class);
  238. context.startActivity(intention);
  239. }
  240. });
  241. }
  242. });
  243. }
  244. }
  245. else
  246. {
  247. if(activePage.equals(context.getString(R.string.new_survey)))
  248. {
  249. if(SQLite.select().from(DataObject.class)
  250. .where(DataObject_Table.processFlag.eq("1")).queryList().size()==0) {
  251. holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
  252. @Override
  253. public void onClick(View view) {
  254. updateOpenDate(dateOpen, timeOpen, value);
  255. goToCustomerDetail(value, position);
  256. }
  257. });
  258. holder.lytCustomerList.setOnLongClickListener(new View.OnLongClickListener() {
  259. @Override
  260. public boolean onLongClick(View v) {
  261. //show pop up
  262. DialogAdapter.showDialogTwoBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
  263. , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
  264. @Override
  265. public void onClick(DialogInterface dialogInterface, int i) {
  266. new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
  267. value.delete();
  268. Intent intention = new Intent(context, HomeActivity.class);
  269. context.startActivity(intention);
  270. }
  271. }, context.getString(R.string.no), new DialogInterface.OnClickListener() {
  272. @Override
  273. public void onClick(DialogInterface dialogInterface, int i) {
  274.  
  275. }
  276. }
  277. );
  278. return true;
  279. }
  280. });
  281. }
  282. else
  283. {
  284. /*holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));*/
  285. holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
  286. holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
  287. @Override
  288. public void onClick(View view) {
  289. updateOpenDate(dateOpen, timeOpen, value);
  290. goToCustomerDetail(value, position);
  291. }
  292. });
  293. holder.lytCustomerList.setOnLongClickListener(new View.OnLongClickListener() {
  294. @Override
  295. public boolean onLongClick(View v) {
  296. //show pop up
  297. DialogAdapter.showDialogTwoBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
  298. , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
  299. @Override
  300. public void onClick(DialogInterface dialogInterface, int i) {
  301. new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
  302. value.delete();
  303. Intent intention = new Intent(context, HomeActivity.class);
  304. context.startActivity(intention);
  305. }
  306. }, context.getString(R.string.no), new DialogInterface.OnClickListener() {
  307. @Override
  308. public void onClick(DialogInterface dialogInterface, int i) {
  309.  
  310. }
  311. }
  312. );
  313. return true;
  314. }
  315. });
  316. }
  317. }
  318. else if(activePage.equalsIgnoreCase(context.getString(R.string.active_survey)))
  319. {
  320. if(position>0)
  321. {
  322. /*holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));*/
  323. holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
  324. }
  325.  
  326. holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
  327. @Override
  328. public void onClick(View view) {
  329. goToCustomerDetail(value, position);
  330. }
  331. });
  332. holder.lytCustomerList.setOnLongClickListener(new View.OnLongClickListener() {
  333. @Override
  334. public boolean onLongClick(View v) {
  335. //show pop up
  336. DialogAdapter.showDialogTwoBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
  337. , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
  338. @Override
  339. public void onClick(DialogInterface dialogInterface, int i) {
  340. new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
  341. value.delete();
  342. Intent intention = new Intent(context, HomeActivity.class);
  343. context.startActivity(intention);
  344.  
  345. }
  346. }, context.getString(R.string.no), new DialogInterface.OnClickListener() {
  347. @Override
  348. public void onClick(DialogInterface dialogInterface, int i) {
  349.  
  350. }
  351. }
  352. );
  353. return true;
  354. }
  355. });
  356. }
  357. else if(activePage.equalsIgnoreCase(context.getString(R.string.pendingSurvey)))
  358. {
  359. /*holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));*/
  360. holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
  361. holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
  362. @Override
  363. public void onClick(View v) {
  364. DialogAdapter.showDialogOneBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
  365. , "Maaf anda tidak bisa mengedit data ini lagi", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
  366. @Override
  367. public void onClick(DialogInterface dialog, int which) {
  368.  
  369. }
  370. });
  371. }
  372. });
  373. }
  374. }
  375. setAnimation(holder.itemView, position);
  376. }
  377.  
  378. private int lastPosition = -1;
  379. private boolean on_attach = true;
  380.  
  381. private void setAnimation(View view, int position) {
  382. if (position > lastPosition) {
  383. ItemAnimation.animate(view, on_attach ? position : -1, ItemAnimation.FADE_IN);
  384. lastPosition = position;
  385. }
  386. }
  387.  
  388. private void updateOpenDate(String dateOpen, String timeOpen, DataObject value)
  389. {
  390. DataObject dataObject = SQLite.select().from(DataObject.class).where(DataObject_Table.orderNo.eq(value.getOrderNo())).querySingle();
  391. if(dataObject.getOpenDate()==null || dataObject.getOpenTime()==null)
  392. {
  393. // dataObject.setOpenDate(dateOpen);
  394. // dataObject.setOpenTime(timeOpen);
  395. // dataObject.save();
  396. SQLite.update(DataObject.class).set(
  397. DataObject_Table.openDate.eq(dateOpen),
  398. DataObject_Table.openTime.eq(timeOpen)
  399. ).where(DataObject_Table.orderNo.eq(value.getOrderNo())).execute();
  400. }
  401. }
  402.  
  403. private void goToCustomerDetail(DataObject value, int position)
  404. {
  405. Intent intent = new Intent(context, CustomerDetailActivity.class);
  406. Gson gson = new Gson();
  407. // intent.putExtra("customerSelected", gson.toJson(value));
  408. SharedPreferenceUtils.setSetting(context, "customerSelected", gson.toJson(value));
  409. // intent.putExtra("activePage", activePage);
  410. SharedPreferenceUtils.setSetting(context, "activePage", activePage);
  411. SharedPreferenceUtils.setSetting(context, "customerPosition", position+"");
  412. context.startActivity(intent);
  413. }
  414.  
  415. @Override
  416. public int getItemCount() {
  417. return tgprs.size();
  418. }
  419.  
  420. public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  421.  
  422. TextView txtCustomerNameList, txtAddressList, txtDoc, txtOrderNoList;
  423. LinearLayout lytCustomerList;
  424.  
  425. public ViewHolder(View itemView) {
  426. super(itemView);
  427. txtCustomerNameList = (TextView) itemView.findViewById(R.id.txtCustomerNameList);
  428. txtAddressList = (TextView) itemView.findViewById(R.id.txtAddressList);
  429. txtOrderNoList = (TextView) itemView.findViewById(R.id.txtOrderNoList);
  430. lytCustomerList = (LinearLayout) itemView.findViewById(R.id.lytCustomerList);
  431. txtDoc= (TextView) itemView.findViewById(R.id.txtDoc);
  432.  
  433. itemView.setOnClickListener(this);
  434. }
  435.  
  436. @Override
  437. public void onClick(View v) {
  438.  
  439. }
  440.  
  441. public void deleteConfirm(){
  442.  
  443. }
  444. }
  445. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement