Guest User

cash

a guest
Oct 16th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. package com.mytradebox.flashsales.activity;
  2.  
  3. import android.os.AsyncTask;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.text.TextUtils;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.Toast;
  11.  
  12. import com.google.firebase.database.DatabaseReference;
  13. import com.google.firebase.database.FirebaseDatabase;
  14. import com.mytradebox.flashsales.R;
  15.  
  16. import java.util.HashMap;
  17. import java.util.Properties;
  18.  
  19. import javax.mail.Authenticator;
  20. import javax.mail.Message;
  21. import javax.mail.MessagingException;
  22. import javax.mail.PasswordAuthentication;
  23. import javax.mail.Session;
  24. import javax.mail.Transport;
  25. import javax.mail.internet.InternetAddress;
  26. import javax.mail.internet.MimeMessage;
  27.  
  28. public class CashActivity extends AppCompatActivity
  29. {
  30.  
  31. private EditText edtName , edtMail , edtNumber ,edtAmount ,edtIncome;
  32. private Button btnSubmit;
  33. private DatabaseReference mCashDatabase;
  34. String name,email,phone,income,amount;
  35.  
  36. Session session=null;
  37.  
  38. @Override
  39. protected void onCreate(Bundle savedInstanceState)
  40. {
  41. super.onCreate(savedInstanceState);
  42. setContentView(R.layout.activity_cash);
  43.  
  44. edtName = (EditText)findViewById(R.id.cash_name);
  45. edtMail = (EditText)findViewById(R.id.cash_email);
  46. edtNumber = (EditText)findViewById(R.id.cash_phone);
  47. edtIncome = (EditText)findViewById(R.id.cash_income);
  48. edtAmount = (EditText)findViewById(R.id.cash_amount);
  49. btnSubmit = (Button)findViewById(R.id.cash_submit);
  50.  
  51. // base url database
  52. mCashDatabase = FirebaseDatabase.getInstance().getReference();
  53.  
  54. btnSubmit.setOnClickListener(new View.OnClickListener() {
  55. @Override
  56. public void onClick(View v) {
  57. //posting the query to database
  58. submitQuery();
  59. }
  60. });
  61.  
  62. }
  63.  
  64. private void submitQuery()
  65. {
  66. // getting all the inputs by the user
  67. name = edtName.getText().toString();
  68. email = edtMail.getText().toString();
  69. phone = edtNumber.getText().toString();
  70. income = edtIncome.getText().toString();
  71. amount = edtAmount.getText().toString();
  72.  
  73. //using for posting the data
  74. DatabaseReference LoanPost = mCashDatabase.child("Loan");
  75.  
  76. // applying validation
  77. if(!TextUtils.isEmpty(name) && !TextUtils.isEmpty(email) && !TextUtils.isEmpty(phone)
  78. && !TextUtils.isEmpty(income) && !TextUtils.isEmpty(amount)) {
  79. if (phone.length() != 10) {
  80. Toast.makeText(this, "Please Enter your phone number Correctly", Toast.LENGTH_SHORT).show();
  81. }
  82. else if (!email.contains("@")) {
  83. Toast.makeText(this, "Please enter a valid email", Toast.LENGTH_SHORT).show();
  84. }
  85. else {
  86. HashMap loanMap = new HashMap();
  87. loanMap.put("name", name);
  88. loanMap.put("email", email);
  89. loanMap.put("phone number", phone);
  90. loanMap.put("monthly income", income);
  91. loanMap.put("loan amount", amount);
  92.  
  93. LoanPost.push().setValue(loanMap);
  94.  
  95. Properties props=new Properties();
  96. props.put("mail.smtp.host","smtp.gmail.com");
  97. props.put("mail.smtp.socketFactory.port","465");
  98. props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
  99. props.put("mail.smtp.auth","true");
  100. props.put("mail.smtp.port","465");
  101.  
  102. session=Session.getDefaultInstance(props, new Authenticator() {
  103. @Override
  104. protected PasswordAuthentication getPasswordAuthentication() {
  105. return new PasswordAuthentication("pradumn2323@gmail.com","thebetterlawyer1");
  106.  
  107. }
  108. });
  109.  
  110. RetreiveFeedTask task=new RetreiveFeedTask();
  111. task.execute();
  112.  
  113.  
  114.  
  115. Toast.makeText(this, "Query Posted Successfully", Toast.LENGTH_SHORT).show();
  116. }
  117.  
  118. }
  119. else
  120. {
  121. Toast.makeText(this, "Please Enter All The Details", Toast.LENGTH_LONG).show();
  122. }
  123.  
  124. }
  125.  
  126. class RetreiveFeedTask extends AsyncTask<String,Void,String>{
  127.  
  128. @Override
  129. protected String doInBackground(String... strings) {
  130. try{
  131. Message message=new MimeMessage(session);
  132. message.setFrom(new InternetAddress("pradumn2323@gmail.com"));
  133. message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("gargcheenu57@gmail.com"));
  134.  
  135. message.setSubject("Need Cash");
  136. message.setContent(name+phone+amount+income,"text/html; charset=utf-8");
  137.  
  138. Transport.send(message);
  139.  
  140.  
  141. }catch(MessagingException e)
  142. {
  143. e.printStackTrace();
  144.  
  145. }catch(Exception e)
  146. {
  147. e.printStackTrace();
  148. }
  149. return null;
  150. }
  151.  
  152. @Override
  153. protected void onPostExecute(String aVoid) {
  154. super.onPostExecute(aVoid);
  155.  
  156. Toast.makeText(CashActivity.this, "Sent the message", Toast.LENGTH_SHORT).show();
  157. }
  158. }
  159.  
  160. }
Add Comment
Please, Sign In to add comment