|
|
@ -1,14 +1,23 @@ |
|
|
|
package gq.yigit.mycity.voteFragment; |
|
|
|
|
|
|
|
import android.content.Context; |
|
|
|
import android.graphics.Bitmap; |
|
|
|
import android.net.Uri; |
|
|
|
import android.os.Bundle; |
|
|
|
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.Button; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.TextView; |
|
|
|
import gq.yigit.mycity.R; |
|
|
|
import gq.yigit.mycity.tools.*; |
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
/** |
|
|
|
* A simple {@link Fragment} subclass. |
|
|
@ -18,36 +27,29 @@ import gq.yigit.mycity.R; |
|
|
|
* Use the {@link VoteFragment#newInstance} factory method to |
|
|
|
* create an instance of this fragment. |
|
|
|
*/ |
|
|
|
public class VoteFragment extends Fragment { |
|
|
|
public class VoteFragment extends Fragment implements responseListener, imageListener { |
|
|
|
// TODO: Rename parameter arguments, choose names that match |
|
|
|
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER |
|
|
|
private static final String ARG_PARAM1 = "param1"; |
|
|
|
private static final String ARG_PARAM2 = "param2"; |
|
|
|
|
|
|
|
// TODO: Rename and change types of parameters |
|
|
|
private String mParam1; |
|
|
|
private String mParam2; |
|
|
|
private String url; |
|
|
|
private String vote_id; |
|
|
|
|
|
|
|
private OnFragmentInteractionListener mListener; |
|
|
|
|
|
|
|
private ImageView header_img; |
|
|
|
private TextView title; |
|
|
|
private TextView desc; |
|
|
|
private Button submit; |
|
|
|
|
|
|
|
public VoteFragment() { |
|
|
|
// Required empty public constructor |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Use this factory method to create a new instance of |
|
|
|
* this fragment using the provided parameters. |
|
|
|
* |
|
|
|
* @param param1 Parameter 1. |
|
|
|
* @param param2 Parameter 2. |
|
|
|
* @return A new instance of fragment VoteFragment. |
|
|
|
*/ |
|
|
|
// TODO: Rename and change types and number of parameters |
|
|
|
public static VoteFragment newInstance(String param1, String param2) { |
|
|
|
public static VoteFragment newInstance(String voteid) { |
|
|
|
VoteFragment fragment = new VoteFragment(); |
|
|
|
Bundle args = new Bundle(); |
|
|
|
args.putString(ARG_PARAM1, param1); |
|
|
|
args.putString(ARG_PARAM2, param2); |
|
|
|
args.putString(ARG_PARAM1, voteid); |
|
|
|
fragment.setArguments(args); |
|
|
|
return fragment; |
|
|
|
} |
|
|
@ -56,15 +58,25 @@ public class VoteFragment extends Fragment { |
|
|
|
public void onCreate(Bundle savedInstanceState) { |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
if (getArguments() != null) { |
|
|
|
mParam1 = getArguments().getString(ARG_PARAM1); |
|
|
|
mParam2 = getArguments().getString(ARG_PARAM2); |
|
|
|
vote_id = getArguments().getString(ARG_PARAM1); |
|
|
|
} |
|
|
|
Log.i("[INFO]","Voting right now"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, |
|
|
|
Bundle savedInstanceState) { |
|
|
|
// Inflate the layout for this fragment |
|
|
|
header_img = container.findViewById(R.id.header); |
|
|
|
title = container.findViewById(R.id.name); |
|
|
|
desc = container.findViewById(R.id.description); |
|
|
|
submit = container.findViewById(R.id.submit); |
|
|
|
|
|
|
|
FileActions file_manager = new FileActions(); |
|
|
|
url = file_manager.readFromFile(getContext(),"server.config").trim(); |
|
|
|
String url_vote = url + "/votings/" + vote_id; |
|
|
|
WebRequest request_manager = new WebRequest(url_vote,true,new HashMap<String, String>()); |
|
|
|
request_manager.addListener(this); |
|
|
|
request_manager.execute(); |
|
|
|
return inflater.inflate(R.layout.fragment_vote, container, false); |
|
|
|
} |
|
|
|
|
|
|
@ -92,18 +104,27 @@ public class VoteFragment extends Fragment { |
|
|
|
mListener = null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* This interface must be implemented by activities that contain this |
|
|
|
* fragment to allow an interaction in this fragment to be communicated |
|
|
|
* to the activity and potentially other fragments contained in that |
|
|
|
* activity. |
|
|
|
* <p> |
|
|
|
* See the Android Training lesson <a href= |
|
|
|
* "http://developer.android.com/training/basics/fragments/communicating.html" |
|
|
|
* >Communicating with Other Fragments</a> for more information. |
|
|
|
*/ |
|
|
|
public interface OnFragmentInteractionListener { |
|
|
|
// TODO: Update argument type and name |
|
|
|
void onFragmentInteraction(Uri uri); |
|
|
|
} |
|
|
|
|
|
|
|
public void receivedResponse(boolean success,String response){ |
|
|
|
if(success){ |
|
|
|
try{ |
|
|
|
JSONObject vote_data = new JSONObject(response); |
|
|
|
title.setText((String)vote_data.get("name")); |
|
|
|
desc.setText((String)vote_data.get("desc")); |
|
|
|
ImageDownload img_manager = new ImageDownload(); |
|
|
|
img_manager.addListener(this); |
|
|
|
img_manager.execute(url+(String)vote_data.get("img")); |
|
|
|
}catch (Exception e){ |
|
|
|
Log.e("[ERROR]",e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void imageDownloaded(Bitmap img){ |
|
|
|
header_img.setImageBitmap(img); |
|
|
|
} |
|
|
|
} |