Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.villvatharisan.tmapp;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.MotionEvent;
- import android.view.View;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.ProgressBar;
- import android.widget.TextView;
- import com.bumptech.glide.Glide;
- import com.bumptech.glide.request.RequestOptions;
- import com.example.villvatharisan.tmapp.Handler.HttpHandler;
- import com.example.villvatharisan.tmapp.Handler.link;
- import com.facebook.login.LoginManager;
- import com.google.android.gms.auth.api.Auth;
- import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
- import com.google.android.gms.common.api.GoogleApiClient;
- import com.google.android.gms.common.api.ResultCallback;
- import com.google.android.gms.common.api.Status;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.IOException;
- import java.io.InputStream;
- import java.lang.ref.WeakReference;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.net.URLConnection;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import com.daimajia.slider.library.Animations.DescriptionAnimation;
- import com.daimajia.slider.library.Indicators.PagerIndicator;
- import com.daimajia.slider.library.SliderLayout;
- import com.daimajia.slider.library.SliderTypes.BaseSliderView;
- import com.daimajia.slider.library.SliderTypes.TextSliderView;
- import com.daimajia.slider.library.Tricks.ViewPagerEx;
- /**
- * Created by villvatharisan on 06/06/2018.
- */
- public class organization extends Activity {
- public GoogleApiClient mGoogleApiClient;
- ProgressDialog pro;
- SharedPreferences sharedPreferences;
- SharedPreferences.Editor editor;
- private static final String PREF_NAME = "Activtiy";
- private static final String KEY_STATUS = "status";
- private static final String KEY_PROGRAM_ID = "program";
- private static final String KEY_RECIPIENT_ID = "recipient";
- TextView org_name, short_desc, long_desc, category, start_date, target, funded, days_leftOrg;
- TextView pro_owner, contact, email, web_link, funds;
- Button plus, minus;
- ProgressBar progressBar;
- ImageView logo, image;
- ImageView favourite;
- Button signout;
- SliderLayout sliderShow;
- String strDate;
- Calendar calendar_from_date, calendar_to_date;
- int year_from, month_from, day_from;
- int year_to, month_to, day_to;
- long one, two;
- boolean swap = false;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.organization_detail);
- // image = (ImageView) findViewById(R.id.img);
- sliderShow = (SliderLayout) findViewById(R.id.img);
- logo = (ImageView) findViewById(R.id.logoOrg);
- start_date = findViewById(R.id.created_dateOrg);
- target = findViewById(R.id.targetOrg);
- funded = findViewById(R.id.fundedOrg);
- days_leftOrg = findViewById(R.id.days_leftOrg);
- org_name = findViewById(R.id.orgName);
- short_desc = findViewById(R.id.short_descOrg);
- category = findViewById(R.id.categoryOrg);
- pro_owner = findViewById(R.id.nameOrg);
- contact = findViewById(R.id.contactOrg);
- email = findViewById(R.id.emailOrg);
- // web_link = findViewById(R.id.socialMediaOrg);
- funds = findViewById(R.id.per_funded);
- progressBar = findViewById(R.id.progress_bar);
- long_desc = findViewById(R.id.description_text);
- plus = findViewById(R.id.plus);
- minus = findViewById(R.id.minus);
- favourite = findViewById(R.id.fav_off);
- signout = findViewById(R.id.signout);
- signout.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- AlertDialog.Builder alertDialog = new AlertDialog.Builder(organization.this);
- alertDialog.setMessage("Are you sure you want to quit?")
- .setPositiveButton("QUIT", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- pro = new ProgressDialog(organization.this, R.style.AppCompatAlertDialogStyle);
- pro.setMessage("Signing Out...");
- pro.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- pro.show();
- pro.setCancelable(false);
- getSharedPreferences(PREF_NAME, 0).edit().clear().apply();
- LoginManager.getInstance().logOut(); // Facebook logout
- Auth.GoogleSignInApi.signOut(mGoogleApiClient);
- new Thread(new Runnable() {
- public void run() {
- try {
- Thread.sleep(1500);
- Intent intent = new Intent(getApplicationContext(), MainActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(intent);
- } catch (Exception e) {
- e.printStackTrace();
- }
- pro.dismiss();
- }
- }).start();
- }
- })
- .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- }
- });
- alertDialog.show();
- }
- });
- final ImageView back = findViewById(R.id.back);
- back.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View view, MotionEvent motionEvent) {
- back();
- return false;
- }
- });
- favourite();
- Button donate = (Button) findViewById(R.id.donate);
- donate.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- sharedPreferences = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
- String log_stat = sharedPreferences.getString(KEY_STATUS,"");
- Log.i("log_stat","log_stat : " + log_stat);
- if (!log_stat.isEmpty()) {
- Intent intent = new Intent(getApplicationContext(), donate_payment.class);
- startActivity(intent);
- } else if (log_stat.isEmpty()) {
- Intent intent = new Intent(getApplicationContext(), tempLog.class);
- startActivity(intent);
- }
- }
- });
- expand_collapse();
- new getProgramEventData().execute();
- }
- protected void onStart() {
- GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
- .requestEmail()
- .build();
- mGoogleApiClient = new GoogleApiClient.Builder(this)
- .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
- .build();
- mGoogleApiClient.connect();
- super.onStart();
- }
- private void favourite(){
- favourite.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (swap) {
- swap=false;
- favourite.setImageResource(R.drawable.blue_default);
- UpdateTwo(organization.this);
- } else {
- swap=true;
- favourite.setImageResource(R.drawable.blue_active);
- Update(organization.this);
- }
- }
- });
- }
- private void back(){
- Intent intent = new Intent(getApplicationContext(), MainActivity.class);
- startActivity(intent);
- }
- public void expand_collapse(){ // expand and collapse text description
- plus.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- plus.setVisibility(View.GONE);
- minus.setVisibility(View.VISIBLE);
- long_desc.setMaxLines(Integer.MAX_VALUE);
- }
- });
- minus.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- minus.setVisibility(View.GONE);
- plus.setVisibility(View.VISIBLE);
- long_desc.setMaxLines(10);
- }
- });
- }
- protected class getProgramEventData extends AsyncTask<Void, Void, String> {
- @Override
- protected void onPreExecute() {
- pro = new ProgressDialog(organization.this, R.style.AppCompatAlertDialogStyle);
- pro.setMessage("Retrieving Details...");
- pro.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- pro.show();
- pro.setCancelable(false);
- }
- @Override
- protected String doInBackground(Void... params) {
- sharedPreferences = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
- String recipient = sharedPreferences.getString(KEY_RECIPIENT_ID,"");
- Log.i("OrgEventData Shared","recipient : " + recipient);
- sharedPreferences = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
- String program = sharedPreferences.getString(KEY_PROGRAM_ID,"");
- Log.i("OrgEventData Shared","program : " + program);
- HttpHandler httpHandler = new HttpHandler();
- String s = httpHandler.sendGetRequest(link.getProgramEventData + recipient + "&id=" + program);
- return s;
- }
- @Override
- protected void onPostExecute(String response) {
- pro.dismiss();
- try {
- Log.i("Response","Response PED : " + response);
- JSONObject jsonObject = new JSONObject(response);
- if (jsonObject.getInt("status") != 0) {
- String getData = jsonObject.getString("data");
- JSONObject Object = new JSONObject(getData);
- //for (int i = 0; i < jsonArray.length(); i++) {
- // JSONObject Object = jsonArray.getJSONObject(i);
- String path = Object.getString("logo");
- String url = link.site_url+path;
- String test;
- Log.i("logo", "logo : " + url);
- if (url.equals(link.site_url+"null")) {
- test = link.site_url;
- } else {
- test = url;
- if (logo != null) {
- //new organization.BitmapWorkerTask(logo).execute(test);
- Glide.with(organization.this).load(url).into(logo);
- Glide.with(organization.this).load(url).apply(new RequestOptions().circleCrop()).into(logo);
- }
- }
- // if (image != null) {
- //new project.BitmapWorkerTask(image).execute(test1);
- //Glide.with(project.this).load(url+"?w=50&h=50").into(image);
- //}
- /*
- String pathTwo = Object.getString("img");
- String urlTwo = link.site_url+pathTwo;
- String test1;
- Log.i("img", "img : " + urlTwo);
- if (urlTwo.equals(link.site_url+"null")) {
- test1 = link.site_url;
- } else {
- test1 = urlTwo;
- if (image != null) {
- //new organization.BitmapWorkerTask(image).execute(test1);
- Glide.with(organization.this).load(urlTwo+"?w=50&h=50").into(image);
- }
- }
- */
- String pathTwo = Object.getString("img");
- String urlTwo = link.site_url+pathTwo;
- String test1;
- Log.i("img", "img : " + urlTwo);
- JSONArray images = Object.getJSONArray("images");
- for(int n=0; n<images.length(); n++) {
- TextSliderView textSliderView = new TextSliderView(getApplicationContext());
- textSliderView
- .description("")
- .image(link.site_url+images.getString(n));
- sliderShow.addSlider(textSliderView);
- }
- Integer favourit = Object.getInt("favourites");
- if (favourit.equals(1)){
- favourite.setImageResource(R.drawable.blue_active);
- }else{
- favourite.setImageResource(R.drawable.blue_default);
- }
- String event_name = Object.getString("rn");
- org_name.setText(event_name);
- String short_text = Object.getString("name");
- short_desc.setText(short_text);
- String category_text = Object.getString("category");
- category.setText(category_text);
- String start_date_text = Object.getString("start_date");
- start_date.setText(start_date_text);
- String target_text = Object.getString("target");
- target.setText(target_text);
- String funded_text = Object.getString("total_donation");
- funded.setText(funded_text);
- String long_text = Object.getString("description");
- long_desc.setText(long_text);
- String owner = Object.getString("contact_person");
- pro_owner.setText(owner);
- String contact_text = Object.getString("contact_phone");
- contact.setText(contact_text);
- String email_text = Object.getString("email");
- email.setText(email_text);
- // final String web = Object.getString("social_media");
- // web_link.setOnClickListener(new View.OnClickListener() {
- // @Override
- // public void onClick(View view) {
- // Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(web));
- // startActivity(browser);
- // }
- // });
- String days_left = Object.getString("end_date");
- Log.i("days_left", "days_left: " + days_left);
- Calendar calendar = null;
- SimpleDateFormat mdformat = null;
- calendar_from_date = Calendar.getInstance();
- calendar_to_date = Calendar.getInstance();
- calendar = Calendar.getInstance();
- mdformat = new SimpleDateFormat("yyyy-MM-dd");
- strDate = mdformat.format(calendar.getTime());
- Log.i("Date", "date: " + strDate);
- String input = strDate;
- String []out = input.split("-");
- year_from = Integer.parseInt(out[0]);
- month_from = Integer.parseInt(out[1]);
- day_from = Integer.parseInt(out[2]);
- String input2 = days_left;
- String []out2 = input2.split("-");
- year_to = Integer.parseInt(out2[0]);
- month_to = Integer.parseInt(out2[1]);
- day_to = Integer.parseInt(out2[2]);
- calendar_from_date.set(year_from,month_from,day_from);
- calendar_to_date.set(year_to,month_to,day_to);
- one = calendar_from_date.getTimeInMillis();
- Log.i("one", "one: " + one);
- two = calendar_to_date.getTimeInMillis();
- Log.i("two", "two: " + two);
- long diff = two - one;
- long days = diff / (24 * 60 * 60 * 1000);
- Log.i("Days", "days: " + days);
- Log.i("Days", "days: " + String.valueOf(days)+" days");
- days_leftOrg.setText(String.valueOf(days)+" days");
- String target = Object.getString("target");
- String funded = Object.getString("total_donation");
- double tar = Double.parseDouble(target);
- Log.i("per","target: "+target);
- double fun = Double.parseDouble(funded);
- Log.i("per","funded: "+funded);
- double per = (fun/tar)*100;
- Log.i("per","per: "+per);
- funds.setText((int) per+"% funded");
- progressBar.setProgress((int) per);
- // }
- } else {
- Log.i("Error","Status is 0 : Something went wrong!");
- }
- } catch (JSONException ex) {
- Log.e("App", "Failure", ex);
- } catch (Exception e){
- System.out.print(e.getMessage());
- }
- }
- }
- public void Update(final Activity activity) {
- class Update extends AsyncTask<Void, Void, String> {
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
- @Override
- protected String doInBackground(Void... params) {
- HttpHandler httpHandler = new HttpHandler();
- sharedPreferences = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
- String program = sharedPreferences.getString(KEY_PROGRAM_ID,"");
- String s = httpHandler.sendGetRequest(link.UpdateFavouriteOn + program);
- return s;
- }
- @Override
- protected void onPostExecute(String s) {
- super.onPostExecute(s);
- try {
- JSONObject jsonObject = new JSONObject(s);
- Integer status = jsonObject.getInt("status");
- Log.i("status","status: " + status);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- new Update().execute();
- }
- public void UpdateTwo(final Activity activity) {
- class UpdateTwo extends AsyncTask<Void, Void, String> {
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
- @Override
- protected String doInBackground(Void... params) {
- HttpHandler httpHandler = new HttpHandler();
- sharedPreferences = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
- String program = sharedPreferences.getString(KEY_PROGRAM_ID,"");
- String s = httpHandler.sendGetRequest(link.UpdateFavouriteOff + program);
- return s;
- }
- @Override
- protected void onPostExecute(String s) {
- super.onPostExecute(s);
- try {
- JSONObject jsonObject = new JSONObject(s);
- Integer status = jsonObject.getInt("status");
- Log.i("status","status: " + status);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- new UpdateTwo().execute();
- }
- class BitmapWorkerTask extends AsyncTask<String, Void, Bitmap> {
- private final WeakReference<ImageView> imageViewReference;
- private String imageUrl;
- public BitmapWorkerTask(ImageView imageView) {
- // Use a WeakReference to ensure the ImageView can be garbage
- // collected
- imageViewReference = new WeakReference<ImageView>(imageView);
- }
- // Decode image in background.
- @Override
- protected Bitmap doInBackground(String... params) {
- imageUrl = params[0];
- return LoadImage(imageUrl);
- }
- // Once complete, see if ImageView is still around and set bitmap.
- @Override
- protected void onPostExecute(Bitmap bitmap) {
- if (imageViewReference != null && bitmap != null) {
- final ImageView imageView = imageViewReference.get();
- if (imageView != null) {
- imageView.setImageBitmap(bitmap);
- }
- }
- }
- private Bitmap LoadImage(String URL) {
- Bitmap bitmap = null;
- InputStream in = null;
- try {
- in = OpenHttpConnection(URL);
- bitmap = BitmapFactory.decodeStream(in);
- in.close();
- } catch (IOException e1) {
- }
- return bitmap;
- }
- private InputStream OpenHttpConnection(String strURL) throws IOException {
- InputStream inputStream = null;
- URL url = new URL(strURL);
- URLConnection conn = url.openConnection();
- try {
- HttpURLConnection httpConn = (HttpURLConnection) conn;
- httpConn.setRequestMethod("GET");
- httpConn.connect();
- if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
- inputStream = httpConn.getInputStream();
- }
- } catch (Exception ex) {
- }
- return inputStream;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement