Back to project page PlayTogether.
The source code is released under:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...
If you think the Android project PlayTogether listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.rockylearnstodevelop.playtogether; /*from w w w . j a v a 2s . co m*/ import java.util.List; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ListView; import com.parse.DeleteCallback; import com.parse.FindCallback; import com.parse.ParseException; import com.parse.ParseObject; import com.parse.ParseQuery; import com.parse.ParseUser; public class RequestFragment extends ListFragment { private static final String TAG = RequestFragment.class.getSimpleName(); private String currentUserName; protected List<ParseObject> mRequests; protected RequestAdapter adapter; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_request, container, false); return rootView; } @Override public void onResume() { super.onResume(); getActivity().setProgressBarIndeterminateVisibility(true); currentUserName = ParseUser.getCurrentUser().getUsername(); getActivity().setProgressBarIndeterminate(true); ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstants.CLASS_ACTIVITYREQUEST); query.whereEqualTo(ParseConstants.KEY_RECIPIENTNAME, currentUserName); //Reorder the result according to the time users shake the phone query.addDescendingOrder(ParseConstants.KEY_CREATEDAT); query.findInBackground(new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> requests, ParseException e) { getActivity().setProgressBarIndeterminateVisibility(false); if(e == null){ mRequests = requests; adapter = new RequestAdapter(getActivity(), mRequests); setListAdapter(adapter); } else{ Log.d(TAG, "no request"); } } }); } @Override public void onListItemClick(ListView l, View v, final int position, long id) { super.onListItemClick(l, v, position, id); final ParseObject request = mRequests.get(position); AlertDialog.Builder builder = new AlertDialog.Builder(getListView().getContext()); AlertDialog dialog = builder.create(); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getActivity().getString(R.string.dialog_delete_button_label), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mRequests.remove(position); adapter = new RequestAdapter(getListView().getContext(), mRequests); setListAdapter(adapter); request.deleteInBackground(new DeleteCallback() { @Override public void done(ParseException e) { if(e == null){} } }); } }); dialog.setButton(AlertDialog.BUTTON_NEUTRAL, getActivity().getString(R.string.view_request_button_label), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { Intent intent = new Intent(getListView().getContext(), UserInfoActivity.class); //add the user info to the intent String sport = request.getString(ParseConstants.KEY_SPORT); String time = request.getString(ParseConstants.KEY_TIME); String level = request.getString(ParseConstants.KEY_LEVEL); String name = request.getString(ParseConstants.KEY_SENDERNAME); String objectId = request.getObjectId(); intent.putExtra(ParseConstants.KEY_SPORT, sport); intent.putExtra(ParseConstants.KEY_TIME, time); intent.putExtra(ParseConstants.KEY_LEVEL, level); intent.putExtra(ParseConstants.KEY_SENDERNAME, name); intent.putExtra(ParseConstants.KEY_OBJECTID, objectId); startActivity(intent); } }); dialog.show(); } }