Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.animation.Animator;
- import android.animation.AnimatorListenerAdapter;
- import android.annotation.TargetApi;
- import android.app.ListActivity;
- import android.app.ProgressDialog;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.os.Build;
- import android.os.Bundle;
- import android.support.annotation.Nullable;
- import android.support.v4.app.Fragment;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.AbsListView;
- import android.widget.AdapterView;
- import android.widget.ListView;
- import android.widget.ProgressBar;
- import android.widget.TextView;
- import android.widget.Toast;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.HashMap;
- /**
- * Created by Arshad on 09-06-2017.
- */
- public class Tab1 extends Fragment {
- SharedPreference pref;
- ListView listView;
- ListItemAdapter listItemAdapter;
- //String[] names = {"Hrithik","Ranbir","AkshayKumar","Amir Khan","Shahidi Kapoor"};
- //int[] images = {R.drawable.index1,R.drawable.index2,R.drawable.index3,R.drawable.index4,R.drawable.index5};
- //int[] eventImages = {R.drawable.ev1,R.drawable.ev2,R.drawable.ev3,R.drawable.ev4,R.drawable.ev5};
- public String JSON_STRING;
- int offset = 0;
- int[] eventId;
- String[] startTime;
- String[] eventImage;
- String[] artistName;
- String[] propic;
- String[] eventName;
- boolean[] follow;
- private View mProgressView;
- private View mLoginFormView;
- ProgressBar loadingProgress;
- private boolean loading = true;
- @Nullable
- @Override
- public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
- return inflater.inflate(R.layout.tab1,container,false);
- }
- @Override
- public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
- pref = new SharedPreference(getActivity());
- listView = (ListView)view.findViewById(R.id.listView);
- loadingProgress = new ProgressBar(getContext());
- listView.addFooterView(loadingProgress);
- mProgressView = view.findViewById(R.id.login_progress);
- mLoginFormView = view.findViewById(R.id.listView);
- getContents();
- listView.setOnScrollListener(new AbsListView.OnScrollListener() {
- @Override
- public void onScrollStateChanged(AbsListView absListView, int i) {
- }
- @Override
- public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
- if(firstVisibleItem+visibleItemCount == totalItemCount && totalItemCount != 0){
- if(loading==true){
- loading = false;
- getContents();
- }
- }
- }
- });
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- Toast.makeText(getActivity (), "you can view the profile of :"+eventName[position], Toast.LENGTH_SHORT).show();
- String eventId = ((TextView) view.findViewById(R.id.eventId)).getText().toString();
- Intent intent = new Intent(getContext(),ViewEventActivity.class);
- intent.putExtra("eventId",eventId);
- startActivity(intent);
- }
- });
- }
- public void getContents(){
- class GetContents extends AsyncTask<Void,Void,String>{
- //ProgressDialog loading;
- @Override
- protected void onPreExecute() {
- //loading = ProgressDialog.show(getActivity(),"Loading..","Please wait",false,false);
- showProgress(true);
- super.onPreExecute();
- }
- @Override
- protected String doInBackground(Void... voids) {
- RequestHandler rh = new RequestHandler();
- String s = rh.sendGetRequest(Config.KEY_URL_GET_TIMELINE+offset,pref.getApiKey());
- offset = offset+7;
- return s;
- }
- @Override
- protected void onPostExecute(String s) {
- if(isAdded()){
- getResources().getString(R.string.app_name);
- }
- super.onPostExecute(s);
- //loading.dismiss();
- showProgress(false);
- JSON_STRING = s;
- Log.v("RESPONSE:","response for timeline:"+JSON_STRING.toString());
- showResults();
- }
- }
- GetContents g = new GetContents();
- g.execute();
- }
- public void showResults(){
- try{
- JSONObject json = new JSONObject(JSON_STRING);
- boolean error = json.getBoolean("error");
- if(error==false){
- //listView.removeFooterView(loadingProgress);
- JSONArray items = json.getJSONArray("events");
- eventId = new int[items.length()];
- eventName = new String[items.length()];
- startTime = new String[items.length()];
- eventImage = new String[items.length()];
- artistName = new String[items.length()];
- propic = new String[items.length()];
- follow = new boolean[items.length()];
- for(int i=0;i<items.length();i++){
- JSONObject c = items.getJSONObject(i);
- eventId[i] = c.getInt("eventId");
- eventName[i] = c.getString("eventName");
- startTime[i] = c.getString("startTime");
- eventImage[i] = c.getString("image");
- artistName[i] = c.getString("artistName");
- propic[i] = c.getString("proPic");
- follow[i] = c.getBoolean("follow");
- }
- listItemAdapter = new ListItemAdapter(getActivity(),eventId,eventName,startTime,eventImage,artistName,propic,follow);
- listView.setAdapter(listItemAdapter);
- listItemAdapter.notifyDataSetChanged();
- }else{
- Toast.makeText(getActivity(), "Sorry, there is technical problem, please contact system admins", Toast.LENGTH_SHORT).show();
- }
- }catch(JSONException e){
- e.printStackTrace();
- }
- }
- @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
- private void showProgress(final boolean show) {
- // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
- // for very easy animations. If available, use these APIs to fade-in
- // the progress spinner.
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
- int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
- mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
- mLoginFormView.animate().setDuration(shortAnimTime).alpha(
- show ? 0 : 1).setListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
- }
- });
- mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
- mProgressView.animate().setDuration(shortAnimTime).alpha(
- show ? 1 : 0).setListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
- }
- });
- } else {
- // The ViewPropertyAnimator APIs are not available, so simply show
- // and hide the relevant UI components.
- mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
- mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
- }
- }
- }
- import android.app.Activity;
- import android.content.Context;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.os.AsyncTask;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.squareup.picasso.Picasso;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.InputStream;
- import java.util.HashMap;
- /**
- * Created by Arshad on 25-05-2017.
- */
- public class ListItemAdapter extends BaseAdapter {
- int[] eventId;
- String[] eventNames;
- String[] startTime;
- String[] eventImage;
- String[] artistName;
- String[] propic;
- boolean[] follow;
- Context context;
- ImageView imageViewLike;
- // ImageView imageView;
- // TextView textView;
- ImageView imageViewPropic;
- ImageView imageViewEvent;
- TextView textViewEventId,textViewEventName,textViewStartTime,textViewArtistName;
- public ListItemAdapter(Context context, int[] evetid, String[] eventnames, String[] starttime, String[] eventImage, String[] artistName, String[] propic, boolean[] follow){
- this.context = context;
- this.eventId = evetid;
- this.eventNames = eventnames;
- this.startTime = starttime;
- this.eventImage = eventImage;
- this.artistName = artistName;
- this.propic = propic;
- this.follow = follow;
- }
- @Override
- public int getCount() {
- return eventId.length;
- }
- @Override
- public Object getItem(int i) {
- return null;
- }
- @Override
- public long getItemId(int i) {
- return i;
- }
- @Override
- public View getView(final int i, View view, ViewGroup viewGroup) {
- LayoutInflater inflater = (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
- view = inflater.inflate(R.layout.list_items_announcements,null);
- // imageView = (ImageView)view.findViewById(R.id.proImage);
- //imageViewEvent = (ImageView)view.findViewById(R.id.eventImage);
- //textView = (TextView)view.findViewById(R.id.aname);
- imageViewEvent = (ImageView) view.findViewById(R.id.eventImage);
- imageViewPropic = (ImageView)view.findViewById(R.id.proImage);
- textViewEventId = (TextView)view.findViewById(R.id.eventId);
- textViewEventName = (TextView)view.findViewById(R.id.eventName);
- textViewStartTime = (TextView)view.findViewById(R.id.textViewStarts);
- textViewArtistName = (TextView)view.findViewById(R.id.aname);
- imageViewLike = (ImageView) view.findViewById(R.id.likeImageView);
- //
- // if(!eventImage[i].equals("") || eventImage[i]!=null) {
- // new DownloadImageTask().execute(eventImage[i]);
- // }
- String eveImage = "http://"+Config.IP_ADDRESS+"/"+eventImage[i];
- Picasso.with(context)
- .load(eveImage)
- .fit()
- .placeholder(R.drawable.loader)
- .error(R.drawable.default1)
- .into(imageViewEvent);
- //if(!propic[i].equals(""))
- //new DownloadImageTask2().execute(propic[i]);
- //new DownloadImageTask(R.id.profileImage,view).execute(propic[i]);
- String profilePic = "someimage";
- if(propic[i]!=null) {
- if (propic[i].length() < Config.DIRECTORY_IMAGE_MAX_SIZE)
- profilePic = "http://" + Config.IP_ADDRESS + "/" + propic[i];
- else
- profilePic = propic[i];
- }
- Picasso.with(context)
- .load(profilePic)
- .placeholder(R.drawable.default2)
- .error(R.drawable.default2)
- .into(imageViewPropic);
- textViewEventId.setText(String.valueOf(eventId[i]));
- textViewArtistName.setText(artistName[i]);
- textViewEventName.setText(eventNames[i]);
- textViewStartTime.setText(startTime[i]);
- boolean following = follow[i];
- if(following==false) {
- imageViewLike.setTag(R.drawable.ic_like);
- imageViewLike.setImageResource(R.drawable.ic_like);
- }else{
- imageViewLike.setTag(R.drawable.ic_liked);
- imageViewLike.setImageResource(R.drawable.ic_liked);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement