Advertisement
Guest User

organization.java

a guest
Jul 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.44 KB | None | 0 0
  1. package com.example.villvatharisan.tmapp;
  2.  
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. import android.app.ProgressDialog;
  6. import android.content.Context;
  7. import android.content.DialogInterface;
  8. import android.content.Intent;
  9. import android.content.SharedPreferences;
  10. import android.graphics.Bitmap;
  11. import android.graphics.BitmapFactory;
  12. import android.os.AsyncTask;
  13. import android.os.Bundle;
  14. import android.util.Log;
  15. import android.view.MotionEvent;
  16. import android.view.View;
  17. import android.widget.Button;
  18. import android.widget.ImageView;
  19. import android.widget.ProgressBar;
  20. import android.widget.TextView;
  21.  
  22. import com.bumptech.glide.Glide;
  23. import com.bumptech.glide.request.RequestOptions;
  24. import com.example.villvatharisan.tmapp.Handler.HttpHandler;
  25. import com.example.villvatharisan.tmapp.Handler.link;
  26. import com.facebook.login.LoginManager;
  27. import com.google.android.gms.auth.api.Auth;
  28. import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
  29. import com.google.android.gms.common.api.GoogleApiClient;
  30. import com.google.android.gms.common.api.ResultCallback;
  31. import com.google.android.gms.common.api.Status;
  32.  
  33. import org.json.JSONArray;
  34. import org.json.JSONException;
  35. import org.json.JSONObject;
  36.  
  37. import java.io.IOException;
  38. import java.io.InputStream;
  39. import java.lang.ref.WeakReference;
  40. import java.net.HttpURLConnection;
  41. import java.net.URL;
  42. import java.net.URLConnection;
  43. import java.text.SimpleDateFormat;
  44. import java.util.Calendar;
  45.  
  46.  
  47. import com.daimajia.slider.library.Animations.DescriptionAnimation;
  48. import com.daimajia.slider.library.Indicators.PagerIndicator;
  49. import com.daimajia.slider.library.SliderLayout;
  50. import com.daimajia.slider.library.SliderTypes.BaseSliderView;
  51. import com.daimajia.slider.library.SliderTypes.TextSliderView;
  52. import com.daimajia.slider.library.Tricks.ViewPagerEx;
  53.  
  54. /**
  55. * Created by villvatharisan on 06/06/2018.
  56. */
  57.  
  58. public class organization extends Activity {
  59.  
  60. public GoogleApiClient mGoogleApiClient;
  61.  
  62. ProgressDialog pro;
  63.  
  64. SharedPreferences sharedPreferences;
  65. SharedPreferences.Editor editor;
  66. private static final String PREF_NAME = "Activtiy";
  67. private static final String KEY_STATUS = "status";
  68.  
  69. private static final String KEY_PROGRAM_ID = "program";
  70. private static final String KEY_RECIPIENT_ID = "recipient";
  71.  
  72. TextView org_name, short_desc, long_desc, category, start_date, target, funded, days_leftOrg;
  73. TextView pro_owner, contact, email, web_link, funds;
  74. Button plus, minus;
  75. ProgressBar progressBar;
  76. ImageView logo, image;
  77. ImageView favourite;
  78. Button signout;
  79. SliderLayout sliderShow;
  80.  
  81. String strDate;
  82.  
  83. Calendar calendar_from_date, calendar_to_date;
  84.  
  85. int year_from, month_from, day_from;
  86. int year_to, month_to, day_to;
  87. long one, two;
  88. boolean swap = false;
  89.  
  90. @Override
  91. protected void onCreate(Bundle savedInstanceState) {
  92. super.onCreate(savedInstanceState);
  93. setContentView(R.layout.organization_detail);
  94.  
  95. // image = (ImageView) findViewById(R.id.img);
  96. sliderShow = (SliderLayout) findViewById(R.id.img);
  97. logo = (ImageView) findViewById(R.id.logoOrg);
  98. start_date = findViewById(R.id.created_dateOrg);
  99. target = findViewById(R.id.targetOrg);
  100. funded = findViewById(R.id.fundedOrg);
  101. days_leftOrg = findViewById(R.id.days_leftOrg);
  102. org_name = findViewById(R.id.orgName);
  103. short_desc = findViewById(R.id.short_descOrg);
  104. category = findViewById(R.id.categoryOrg);
  105. pro_owner = findViewById(R.id.nameOrg);
  106. contact = findViewById(R.id.contactOrg);
  107. email = findViewById(R.id.emailOrg);
  108. // web_link = findViewById(R.id.socialMediaOrg);
  109. funds = findViewById(R.id.per_funded);
  110. progressBar = findViewById(R.id.progress_bar);
  111. long_desc = findViewById(R.id.description_text);
  112. plus = findViewById(R.id.plus);
  113. minus = findViewById(R.id.minus);
  114. favourite = findViewById(R.id.fav_off);
  115. signout = findViewById(R.id.signout);
  116.  
  117. signout.setOnClickListener(new View.OnClickListener() {
  118. @Override
  119. public void onClick(View v) {
  120. AlertDialog.Builder alertDialog = new AlertDialog.Builder(organization.this);
  121. alertDialog.setMessage("Are you sure you want to quit?")
  122. .setPositiveButton("QUIT", new DialogInterface.OnClickListener() {
  123. @Override
  124. public void onClick(DialogInterface dialogInterface, int i) {
  125.  
  126. pro = new ProgressDialog(organization.this, R.style.AppCompatAlertDialogStyle);
  127. pro.setMessage("Signing Out...");
  128. pro.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  129. pro.show();
  130. pro.setCancelable(false);
  131.  
  132. getSharedPreferences(PREF_NAME, 0).edit().clear().apply();
  133. LoginManager.getInstance().logOut(); // Facebook logout
  134.  
  135. Auth.GoogleSignInApi.signOut(mGoogleApiClient);
  136.  
  137. new Thread(new Runnable() {
  138. public void run() {
  139. try {
  140. Thread.sleep(1500);
  141. Intent intent = new Intent(getApplicationContext(), MainActivity.class);
  142. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  143. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  144. startActivity(intent);
  145. } catch (Exception e) {
  146. e.printStackTrace();
  147. }
  148. pro.dismiss();
  149. }
  150. }).start();
  151.  
  152. }
  153. })
  154. .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
  155. @Override
  156. public void onClick(DialogInterface dialogInterface, int i) {
  157.  
  158. dialogInterface.dismiss();
  159.  
  160. }
  161. });
  162. alertDialog.show();
  163. }
  164. });
  165.  
  166. final ImageView back = findViewById(R.id.back);
  167. back.setOnTouchListener(new View.OnTouchListener() {
  168. @Override
  169. public boolean onTouch(View view, MotionEvent motionEvent) {
  170.  
  171. back();
  172.  
  173. return false;
  174. }
  175. });
  176.  
  177. favourite();
  178.  
  179. Button donate = (Button) findViewById(R.id.donate);
  180. donate.setOnClickListener(new View.OnClickListener() {
  181. public void onClick(View view) {
  182.  
  183. sharedPreferences = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
  184. String log_stat = sharedPreferences.getString(KEY_STATUS,"");
  185. Log.i("log_stat","log_stat : " + log_stat);
  186.  
  187. if (!log_stat.isEmpty()) {
  188.  
  189. Intent intent = new Intent(getApplicationContext(), donate_payment.class);
  190. startActivity(intent);
  191.  
  192. } else if (log_stat.isEmpty()) {
  193.  
  194. Intent intent = new Intent(getApplicationContext(), tempLog.class);
  195. startActivity(intent);
  196.  
  197. }
  198. }
  199. });
  200.  
  201. expand_collapse();
  202. new getProgramEventData().execute();
  203. }
  204.  
  205. protected void onStart() {
  206. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
  207. .requestEmail()
  208. .build();
  209. mGoogleApiClient = new GoogleApiClient.Builder(this)
  210. .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
  211. .build();
  212. mGoogleApiClient.connect();
  213. super.onStart();
  214. }
  215.  
  216. private void favourite(){
  217.  
  218. favourite.setOnClickListener(new View.OnClickListener() {
  219. @Override
  220. public void onClick(View view) {
  221.  
  222. if (swap) {
  223.  
  224. swap=false;
  225. favourite.setImageResource(R.drawable.blue_default);
  226. UpdateTwo(organization.this);
  227.  
  228. } else {
  229.  
  230. swap=true;
  231. favourite.setImageResource(R.drawable.blue_active);
  232. Update(organization.this);
  233. }
  234. }
  235. });
  236. }
  237.  
  238. private void back(){
  239.  
  240. Intent intent = new Intent(getApplicationContext(), MainActivity.class);
  241. startActivity(intent);
  242.  
  243. }
  244.  
  245. public void expand_collapse(){ // expand and collapse text description
  246.  
  247. plus.setOnClickListener(new View.OnClickListener() {
  248.  
  249. @Override
  250. public void onClick(View v) {
  251.  
  252. plus.setVisibility(View.GONE);
  253. minus.setVisibility(View.VISIBLE);
  254. long_desc.setMaxLines(Integer.MAX_VALUE);
  255.  
  256. }
  257. });
  258.  
  259. minus.setOnClickListener(new View.OnClickListener() {
  260.  
  261. @Override
  262. public void onClick(View v) {
  263.  
  264. minus.setVisibility(View.GONE);
  265. plus.setVisibility(View.VISIBLE);
  266. long_desc.setMaxLines(10);
  267.  
  268. }
  269. });
  270.  
  271. }
  272.  
  273. protected class getProgramEventData extends AsyncTask<Void, Void, String> {
  274.  
  275. @Override
  276. protected void onPreExecute() {
  277.  
  278. pro = new ProgressDialog(organization.this, R.style.AppCompatAlertDialogStyle);
  279. pro.setMessage("Retrieving Details...");
  280. pro.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  281. pro.show();
  282. pro.setCancelable(false);
  283.  
  284. }
  285.  
  286. @Override
  287. protected String doInBackground(Void... params) {
  288.  
  289. sharedPreferences = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
  290. String recipient = sharedPreferences.getString(KEY_RECIPIENT_ID,"");
  291. Log.i("OrgEventData Shared","recipient : " + recipient);
  292.  
  293. sharedPreferences = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
  294. String program = sharedPreferences.getString(KEY_PROGRAM_ID,"");
  295. Log.i("OrgEventData Shared","program : " + program);
  296.  
  297. HttpHandler httpHandler = new HttpHandler();
  298.  
  299. String s = httpHandler.sendGetRequest(link.getProgramEventData + recipient + "&id=" + program);
  300.  
  301. return s;
  302.  
  303. }
  304.  
  305. @Override
  306. protected void onPostExecute(String response) {
  307. pro.dismiss();
  308.  
  309. try {
  310.  
  311. Log.i("Response","Response PED : " + response);
  312. JSONObject jsonObject = new JSONObject(response);
  313. if (jsonObject.getInt("status") != 0) {
  314.  
  315. String getData = jsonObject.getString("data");
  316. JSONObject Object = new JSONObject(getData);
  317. //for (int i = 0; i < jsonArray.length(); i++) {
  318.  
  319. // JSONObject Object = jsonArray.getJSONObject(i);
  320.  
  321. String path = Object.getString("logo");
  322. String url = link.site_url+path;
  323.  
  324. String test;
  325. Log.i("logo", "logo : " + url);
  326. if (url.equals(link.site_url+"null")) {
  327.  
  328. test = link.site_url;
  329.  
  330. } else {
  331.  
  332. test = url;
  333. if (logo != null) {
  334.  
  335. //new organization.BitmapWorkerTask(logo).execute(test);
  336. Glide.with(organization.this).load(url).into(logo);
  337. Glide.with(organization.this).load(url).apply(new RequestOptions().circleCrop()).into(logo);
  338.  
  339. }
  340. }
  341.  
  342.  
  343. // if (image != null) {
  344.  
  345. //new project.BitmapWorkerTask(image).execute(test1);
  346. //Glide.with(project.this).load(url+"?w=50&h=50").into(image);
  347.  
  348.  
  349. //}
  350. /*
  351. String pathTwo = Object.getString("img");
  352. String urlTwo = link.site_url+pathTwo;
  353.  
  354. String test1;
  355. Log.i("img", "img : " + urlTwo);
  356. if (urlTwo.equals(link.site_url+"null")) {
  357.  
  358. test1 = link.site_url;
  359.  
  360. } else {
  361.  
  362. test1 = urlTwo;
  363. if (image != null) {
  364.  
  365. //new organization.BitmapWorkerTask(image).execute(test1);
  366. Glide.with(organization.this).load(urlTwo+"?w=50&h=50").into(image);
  367. }
  368. }
  369. */
  370.  
  371. String pathTwo = Object.getString("img");
  372. String urlTwo = link.site_url+pathTwo;
  373.  
  374. String test1;
  375. Log.i("img", "img : " + urlTwo);
  376.  
  377. JSONArray images = Object.getJSONArray("images");
  378.  
  379. for(int n=0; n<images.length(); n++) {
  380.  
  381. TextSliderView textSliderView = new TextSliderView(getApplicationContext());
  382. textSliderView
  383. .description("")
  384. .image(link.site_url+images.getString(n));
  385.  
  386. sliderShow.addSlider(textSliderView);
  387. }
  388.  
  389.  
  390. Integer favourit = Object.getInt("favourites");
  391. if (favourit.equals(1)){
  392. favourite.setImageResource(R.drawable.blue_active);
  393. }else{
  394. favourite.setImageResource(R.drawable.blue_default);
  395. }
  396.  
  397. String event_name = Object.getString("rn");
  398. org_name.setText(event_name);
  399.  
  400. String short_text = Object.getString("name");
  401. short_desc.setText(short_text);
  402.  
  403. String category_text = Object.getString("category");
  404. category.setText(category_text);
  405.  
  406. String start_date_text = Object.getString("start_date");
  407. start_date.setText(start_date_text);
  408.  
  409. String target_text = Object.getString("target");
  410. target.setText(target_text);
  411.  
  412. String funded_text = Object.getString("total_donation");
  413. funded.setText(funded_text);
  414.  
  415. String long_text = Object.getString("description");
  416. long_desc.setText(long_text);
  417.  
  418. String owner = Object.getString("contact_person");
  419. pro_owner.setText(owner);
  420.  
  421. String contact_text = Object.getString("contact_phone");
  422. contact.setText(contact_text);
  423.  
  424.  
  425. String email_text = Object.getString("email");
  426. email.setText(email_text);
  427.  
  428.  
  429. // final String web = Object.getString("social_media");
  430. // web_link.setOnClickListener(new View.OnClickListener() {
  431. // @Override
  432. // public void onClick(View view) {
  433. // Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(web));
  434. // startActivity(browser);
  435. // }
  436. // });
  437.  
  438. String days_left = Object.getString("end_date");
  439. Log.i("days_left", "days_left: " + days_left);
  440.  
  441. Calendar calendar = null;
  442. SimpleDateFormat mdformat = null;
  443.  
  444. calendar_from_date = Calendar.getInstance();
  445. calendar_to_date = Calendar.getInstance();
  446. calendar = Calendar.getInstance();
  447. mdformat = new SimpleDateFormat("yyyy-MM-dd");
  448. strDate = mdformat.format(calendar.getTime());
  449. Log.i("Date", "date: " + strDate);
  450.  
  451. String input = strDate;
  452. String []out = input.split("-");
  453. year_from = Integer.parseInt(out[0]);
  454. month_from = Integer.parseInt(out[1]);
  455. day_from = Integer.parseInt(out[2]);
  456.  
  457. String input2 = days_left;
  458. String []out2 = input2.split("-");
  459. year_to = Integer.parseInt(out2[0]);
  460. month_to = Integer.parseInt(out2[1]);
  461. day_to = Integer.parseInt(out2[2]);
  462.  
  463. calendar_from_date.set(year_from,month_from,day_from);
  464. calendar_to_date.set(year_to,month_to,day_to);
  465. one = calendar_from_date.getTimeInMillis();
  466. Log.i("one", "one: " + one);
  467. two = calendar_to_date.getTimeInMillis();
  468. Log.i("two", "two: " + two);
  469.  
  470. long diff = two - one;
  471. long days = diff / (24 * 60 * 60 * 1000);
  472. Log.i("Days", "days: " + days);
  473. Log.i("Days", "days: " + String.valueOf(days)+" days");
  474. days_leftOrg.setText(String.valueOf(days)+" days");
  475.  
  476. String target = Object.getString("target");
  477. String funded = Object.getString("total_donation");
  478.  
  479. double tar = Double.parseDouble(target);
  480. Log.i("per","target: "+target);
  481. double fun = Double.parseDouble(funded);
  482. Log.i("per","funded: "+funded);
  483.  
  484. double per = (fun/tar)*100;
  485. Log.i("per","per: "+per);
  486.  
  487. funds.setText((int) per+"% funded");
  488. progressBar.setProgress((int) per);
  489. // }
  490. } else {
  491.  
  492. Log.i("Error","Status is 0 : Something went wrong!");
  493. }
  494. } catch (JSONException ex) {
  495. Log.e("App", "Failure", ex);
  496. } catch (Exception e){
  497. System.out.print(e.getMessage());
  498. }
  499. }
  500. }
  501.  
  502. public void Update(final Activity activity) {
  503.  
  504. class Update extends AsyncTask<Void, Void, String> {
  505.  
  506. @Override
  507. protected void onPreExecute() {
  508. super.onPreExecute();
  509. }
  510.  
  511. @Override
  512. protected String doInBackground(Void... params) {
  513.  
  514. HttpHandler httpHandler = new HttpHandler();
  515.  
  516. sharedPreferences = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
  517. String program = sharedPreferences.getString(KEY_PROGRAM_ID,"");
  518.  
  519. String s = httpHandler.sendGetRequest(link.UpdateFavouriteOn + program);
  520. return s;
  521.  
  522. }
  523.  
  524. @Override
  525. protected void onPostExecute(String s) {
  526. super.onPostExecute(s);
  527.  
  528. try {
  529. JSONObject jsonObject = new JSONObject(s);
  530. Integer status = jsonObject.getInt("status");
  531. Log.i("status","status: " + status);
  532. } catch (Exception e) {
  533. e.printStackTrace();
  534. }
  535.  
  536. }
  537.  
  538. }
  539. new Update().execute();
  540. }
  541.  
  542. public void UpdateTwo(final Activity activity) {
  543.  
  544. class UpdateTwo extends AsyncTask<Void, Void, String> {
  545.  
  546. @Override
  547. protected void onPreExecute() {
  548. super.onPreExecute();
  549. }
  550.  
  551. @Override
  552. protected String doInBackground(Void... params) {
  553.  
  554. HttpHandler httpHandler = new HttpHandler();
  555.  
  556. sharedPreferences = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
  557. String program = sharedPreferences.getString(KEY_PROGRAM_ID,"");
  558.  
  559. String s = httpHandler.sendGetRequest(link.UpdateFavouriteOff + program);
  560. return s;
  561.  
  562. }
  563.  
  564. @Override
  565. protected void onPostExecute(String s) {
  566. super.onPostExecute(s);
  567.  
  568. try {
  569.  
  570. JSONObject jsonObject = new JSONObject(s);
  571. Integer status = jsonObject.getInt("status");
  572. Log.i("status","status: " + status);
  573.  
  574. } catch (Exception e) {
  575. e.printStackTrace();
  576. }
  577.  
  578. }
  579.  
  580. }
  581. new UpdateTwo().execute();
  582. }
  583.  
  584. class BitmapWorkerTask extends AsyncTask<String, Void, Bitmap> {
  585.  
  586. private final WeakReference<ImageView> imageViewReference;
  587. private String imageUrl;
  588.  
  589. public BitmapWorkerTask(ImageView imageView) {
  590. // Use a WeakReference to ensure the ImageView can be garbage
  591. // collected
  592. imageViewReference = new WeakReference<ImageView>(imageView);
  593. }
  594.  
  595. // Decode image in background.
  596. @Override
  597. protected Bitmap doInBackground(String... params) {
  598.  
  599. imageUrl = params[0];
  600. return LoadImage(imageUrl);
  601. }
  602.  
  603. // Once complete, see if ImageView is still around and set bitmap.
  604. @Override
  605. protected void onPostExecute(Bitmap bitmap) {
  606.  
  607. if (imageViewReference != null && bitmap != null) {
  608.  
  609. final ImageView imageView = imageViewReference.get();
  610. if (imageView != null) {
  611. imageView.setImageBitmap(bitmap);
  612. }
  613.  
  614. }
  615.  
  616. }
  617.  
  618. private Bitmap LoadImage(String URL) {
  619.  
  620. Bitmap bitmap = null;
  621. InputStream in = null;
  622.  
  623. try {
  624.  
  625. in = OpenHttpConnection(URL);
  626. bitmap = BitmapFactory.decodeStream(in);
  627. in.close();
  628.  
  629. } catch (IOException e1) {
  630. }
  631.  
  632. return bitmap;
  633. }
  634.  
  635. private InputStream OpenHttpConnection(String strURL) throws IOException {
  636.  
  637. InputStream inputStream = null;
  638. URL url = new URL(strURL);
  639. URLConnection conn = url.openConnection();
  640.  
  641. try {
  642.  
  643. HttpURLConnection httpConn = (HttpURLConnection) conn;
  644. httpConn.setRequestMethod("GET");
  645. httpConn.connect();
  646.  
  647. if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
  648.  
  649. inputStream = httpConn.getInputStream();
  650. }
  651.  
  652. } catch (Exception ex) {
  653. }
  654.  
  655. return inputStream;
  656. }
  657.  
  658. }
  659.  
  660. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement