diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java b/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java index ef0eb2f..e8842e3 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java @@ -9,7 +9,6 @@ import android.support.design.widget.Snackbar; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AlertDialog; -import android.util.Log; import android.view.*; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; @@ -18,6 +17,7 @@ import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.widget.EditText; +import gq.yigit.mycity.tools.FileActions; import gq.yigit.mycity.voteFragment.VoteFragment; import gq.yigit.mycity.votesFragment.VotesContent; import gq.yigit.mycity.votesFragment.VotesFragment; @@ -91,7 +91,7 @@ public class MainActivity extends AppCompatActivity alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { FileActions file_manager = new FileActions(); - file_manager.writeToFile(input.getText().toString(),cntxt,"server.config"); + file_manager.writeToFile("http://" + input.getText().toString()+":5000",cntxt,"server.config"); } }); @@ -120,6 +120,7 @@ public class MainActivity extends AppCompatActivity VotesFragment fragment = new VotesFragment(); fragmentTransaction.replace(R.id.app_bar_main, fragment); fragmentTransaction.commit(); + fragmentTransaction.addToBackStack(null); } else if (id == R.id.parking) { @@ -139,11 +140,11 @@ public class MainActivity extends AppCompatActivity } public void onListFragmentInteraction(VotesContent.VoteItem vote){ - VoteFragment fragment = new VoteFragment(); + VoteFragment fragment = VoteFragment.newInstance(vote.id); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.app_bar_main, fragment); - transaction.addToBackStack(null); transaction.commit(); + transaction.addToBackStack(null); } public void onFragmentInteraction(Uri uri){ diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/FileActions.java b/MyCity/app/src/main/java/gq/yigit/mycity/tools/FileActions.java similarity index 97% rename from MyCity/app/src/main/java/gq/yigit/mycity/FileActions.java rename to MyCity/app/src/main/java/gq/yigit/mycity/tools/FileActions.java index a872fec..647a2c4 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/FileActions.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/tools/FileActions.java @@ -1,4 +1,4 @@ -package gq.yigit.mycity; +package gq.yigit.mycity.tools; import android.content.Context; import android.util.Log; diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/ImageDownload.java b/MyCity/app/src/main/java/gq/yigit/mycity/tools/ImageDownload.java similarity index 96% rename from MyCity/app/src/main/java/gq/yigit/mycity/ImageDownload.java rename to MyCity/app/src/main/java/gq/yigit/mycity/tools/ImageDownload.java index 43a9e7f..054c563 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/ImageDownload.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/tools/ImageDownload.java @@ -1,4 +1,4 @@ -package gq.yigit.mycity; +package gq.yigit.mycity.tools; import android.graphics.Bitmap; import android.graphics.BitmapFactory; diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/WebRequest.java b/MyCity/app/src/main/java/gq/yigit/mycity/tools/WebRequest.java similarity index 98% rename from MyCity/app/src/main/java/gq/yigit/mycity/WebRequest.java rename to MyCity/app/src/main/java/gq/yigit/mycity/tools/WebRequest.java index f446766..bcee042 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/WebRequest.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/tools/WebRequest.java @@ -1,4 +1,4 @@ -package gq.yigit.mycity; +package gq.yigit.mycity.tools; import android.os.AsyncTask; import android.util.Log; diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/imageListener.java b/MyCity/app/src/main/java/gq/yigit/mycity/tools/imageListener.java similarity index 78% rename from MyCity/app/src/main/java/gq/yigit/mycity/imageListener.java rename to MyCity/app/src/main/java/gq/yigit/mycity/tools/imageListener.java index 005ffd9..7ab9b08 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/imageListener.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/tools/imageListener.java @@ -1,4 +1,4 @@ -package gq.yigit.mycity; +package gq.yigit.mycity.tools; import android.graphics.Bitmap; diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/responseListener.java b/MyCity/app/src/main/java/gq/yigit/mycity/tools/responseListener.java similarity index 74% rename from MyCity/app/src/main/java/gq/yigit/mycity/responseListener.java rename to MyCity/app/src/main/java/gq/yigit/mycity/tools/responseListener.java index 2810e2c..515102c 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/responseListener.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/tools/responseListener.java @@ -1,4 +1,4 @@ -package gq.yigit.mycity; +package gq.yigit.mycity.tools; public interface responseListener { void receivedResponse(boolean success, String response); diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/voteFragment/VoteFragment.java b/MyCity/app/src/main/java/gq/yigit/mycity/voteFragment/VoteFragment.java index 8a61147..875a314 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/voteFragment/VoteFragment.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/voteFragment/VoteFragment.java @@ -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()); + 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. - *

- * See the Android Training lesson Communicating with Other Fragments 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); + } } diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/votesFragment/VotesFragment.java b/MyCity/app/src/main/java/gq/yigit/mycity/votesFragment/VotesFragment.java index 7da64b3..699415c 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/votesFragment/VotesFragment.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/votesFragment/VotesFragment.java @@ -11,11 +11,11 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import gq.yigit.mycity.*; +import gq.yigit.mycity.R; +import gq.yigit.mycity.tools.*; import gq.yigit.mycity.votesFragment.VotesContent.VoteItem; import org.json.JSONArray; import org.json.JSONObject; - import java.util.HashMap; diff --git a/MyCity/app/src/main/res/layout/fragment_vote.xml b/MyCity/app/src/main/res/layout/fragment_vote.xml index fb676dd..6c79ff9 100644 --- a/MyCity/app/src/main/res/layout/fragment_vote.xml +++ b/MyCity/app/src/main/res/layout/fragment_vote.xml @@ -1,14 +1,44 @@ - + - + android:layout_height="236dp" android:id="@+id/header" android:layout_weight="1"/> + + + +