Browse Source

Merge remote-tracking branch 'origin/yigit' into yigit

pull/2/head
Yiğit Çolakoğlu 6 years ago
parent
commit
1e080e9589
21 changed files with 342 additions and 184 deletions
  1. +5
    -4
      MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java
  2. +1
    -1
      MyCity/app/src/main/java/gq/yigit/mycity/tools/FileActions.java
  3. +1
    -1
      MyCity/app/src/main/java/gq/yigit/mycity/tools/ImageDownload.java
  4. +1
    -1
      MyCity/app/src/main/java/gq/yigit/mycity/tools/WebRequest.java
  5. +1
    -1
      MyCity/app/src/main/java/gq/yigit/mycity/tools/imageListener.java
  6. +1
    -1
      MyCity/app/src/main/java/gq/yigit/mycity/tools/responseListener.java
  7. +51
    -30
      MyCity/app/src/main/java/gq/yigit/mycity/voteFragment/VoteFragment.java
  8. +2
    -2
      MyCity/app/src/main/java/gq/yigit/mycity/votesFragment/VotesFragment.java
  9. +39
    -9
      MyCity/app/src/main/res/layout/fragment_vote.xml
  10. +0
    -0
      server_side/api/__init__.py
  11. BIN
      server_side/api/__pycache__/__init__.cpython-37.pyc
  12. +0
    -0
      server_side/api/rating_system/__init__.py
  13. BIN
      server_side/api/rating_system/__pycache__/__init__.cpython-37.pyc
  14. BIN
      server_side/api/rating_system/__pycache__/rating_system.cpython-37.pyc
  15. +8
    -0
      server_side/api/rating_system/rating_system.py
  16. +0
    -0
      server_side/api/voting_system/__init__.py
  17. BIN
      server_side/api/voting_system/__pycache__/__init__.cpython-37.pyc
  18. BIN
      server_side/api/voting_system/__pycache__/voting_system.cpython-37.pyc
  19. +101
    -0
      server_side/api/voting_system/voting_system.py~HEAD
  20. +93
    -93
      server_side/api/voting_system/voting_system.py~efe
  21. +38
    -41
      server_side/api/voting_system/votings.json

+ 5
- 4
MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java View File

@ -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){


MyCity/app/src/main/java/gq/yigit/mycity/FileActions.java → MyCity/app/src/main/java/gq/yigit/mycity/tools/FileActions.java View File


MyCity/app/src/main/java/gq/yigit/mycity/ImageDownload.java → MyCity/app/src/main/java/gq/yigit/mycity/tools/ImageDownload.java View File


MyCity/app/src/main/java/gq/yigit/mycity/WebRequest.java → MyCity/app/src/main/java/gq/yigit/mycity/tools/WebRequest.java View File


MyCity/app/src/main/java/gq/yigit/mycity/imageListener.java → MyCity/app/src/main/java/gq/yigit/mycity/tools/imageListener.java View File


MyCity/app/src/main/java/gq/yigit/mycity/responseListener.java → MyCity/app/src/main/java/gq/yigit/mycity/tools/responseListener.java View File


+ 51
- 30
MyCity/app/src/main/java/gq/yigit/mycity/voteFragment/VoteFragment.java View File

@ -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);
}
}

+ 2
- 2
MyCity/app/src/main/java/gq/yigit/mycity/votesFragment/VotesFragment.java View File

@ -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;


+ 39
- 9
MyCity/app/src/main/res/layout/fragment_vote.xml View File

@ -1,14 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".voteFragment.VoteFragment">
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".voteFragment.VoteFragment" android:orientation="vertical">
<!-- TODO: Update blank fragment layout -->
<TextView
<ImageView
android:src="@android:color/background_dark"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment"/>
android:layout_height="236dp" android:id="@+id/header" android:layout_weight="1"/>
<Spinner
android:layout_width="199dp"
android:layout_height="24dp" android:id="@+id/vote"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
app:layout_constraintHorizontal_bias="0.503" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/description"/>
<TextView
android:text="TextView"
android:layout_width="282dp"
android:layout_height="wrap_content"
android:id="@+id/name"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="16dp"
android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/header"
android:textSize="16sp" android:textColor="#000000"/>
<TextView
android:text="TextView"
android:layout_width="299dp"
android:layout_height="wrap_content"
android:id="@+id/description"
app:layout_constraintStart_toStartOf="@+id/name" android:layout_marginStart="28dp"
android:layout_marginTop="12dp" app:layout_constraintTop_toBottomOf="@+id/name"/>
<Button
android:text="Submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/submit" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/vote" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"/>
</FrameLayout>
</android.support.constraint.ConstraintLayout>

+ 0
- 0
server_side/api/__init__.py View File


BIN
server_side/api/__pycache__/__init__.cpython-37.pyc View File


+ 0
- 0
server_side/api/rating_system/__init__.py View File


BIN
server_side/api/rating_system/__pycache__/__init__.cpython-37.pyc View File


BIN
server_side/api/rating_system/__pycache__/rating_system.cpython-37.pyc View File


+ 8
- 0
server_side/api/rating_system/rating_system.py View File

@ -2,7 +2,15 @@ import os
import json
from flask import Flask, request
<<<<<<< HEAD
from flask_restful import Resource, Api, abort
=======
<<<<<<< HEAD
from flask_restful import Resource, Api
=======
from flask_restful import Resource, Api, abort
>>>>>>> efe
>>>>>>> yigit
app = Flask(__name__)
api = Api(app)


+ 0
- 0
server_side/api/voting_system/__init__.py View File


BIN
server_side/api/voting_system/__pycache__/__init__.cpython-37.pyc View File


BIN
server_side/api/voting_system/__pycache__/voting_system.cpython-37.pyc View File


+ 101
- 0
server_side/api/voting_system/voting_system.py~HEAD View File

@ -0,0 +1,101 @@
import os
import json
from flask import Flask, request
from flask_restful import Resource, Api, abort
app = Flask(__name__)
api = Api(app)
with open(os.path.join(app.root_path, 'votings.json'), 'r') as f:
votings = json.load(f)
class Votings(Resource):
def get(self):
voting = [
{
'id' : v['id'],
'name': v['name'],
'desc': v['desc'],
'img' : v['img']
}
for v in votings
]
return voting
def post(self):
"""
Example POST Data:
name=<voting_name>&
desc=<voting_desc>& # OPTIONAL
img=<voting_img>& # OPTIONAL
votes=[
{
"name": "<vote_name>",
"desc": "<vote_desc>" # OPTIONAL
},
(...)
]
"""
args = request.form
voting_id = len(votings) + 1
voting = {
'id': voting_id,
'name': args['name'],
'desc': args.get('desc'),
'img' : args.get('img'),
'votes': [
{
'id' : k + 1,
'name': vote['name'],
'desc': vote.get('desc'),
'votes': 0
}
for k, vote in enumerate(json.loads(args['votes']))
]
}
votings.append(voting)
with open(os.path.join(app.root_path, 'votings.json'), 'w') as f:
json.dump(votings, f, indent=4)
return voting
class Voting(Resource):
def get(self, voting_id):
try:
return votings[voting_id - 1]
except:
abort(404, error="Voting {} doesn't exist".format(voting_id))
class Vote(Resource):
def get(self):
"""
Example URL Query:
/vote?voting_id=<voting_id>&vote_id=<vote_id>&voter_id=<voter_id>
"""
voting_id = int(request.args['voting_id'])
vote_id = int(request.args['vote_id'])
voter_id = int(request.args['voter_id'])
error = False
for i in range(votings[voting_id]["votes"]):
if(voter_id in votings[voting_id]["votes"][i]["votes"]):
error = True
if error:
return "An error occured"
votings[voting_id]["votes"][vote_id]["votes"].append(voter_id)
with open(os.path.join(app.root_path, 'votings.json'), 'w') as f:
json.dump(votings, f, indent=4)
return votings[voting_id - 1]
if __name__ == '__main__':
api.add_resource(Votings, '/votings', '/votings/')
api.add_resource(Voting, '/votings/<int:voting_id>', '/votings/<int:voting_id>/')
api.add_resource(Vote, '/vote', '/vote/')
app.run(host='0.0.0.0', port=5000)

server_side/api/voting_system/voting_system.py → server_side/api/voting_system/voting_system.py~efe View File


+ 38
- 41
server_side/api/voting_system/votings.json View File

@ -1,42 +1,39 @@
[
{
"id": 1,
"name": "Test Voting",
"desc": "Sample voting description",
"img": "/img/voting.jpg",
"votes": [
{
"id": 1,
"name": "Sample Vote 1",
"desc": "Sample description",
"votes": 5
},
{
"id": 2,
"name": "Sample Vote 2",
"desc": "Sample description",
"votes": 8
}
]
},
{
"id": 2,
"name": "wooting",
"desc": "wooting desc",
"img": "/img/voting.jpg",
"votes": [
{
"id": 0,
"name": "woote 1",
"desc": "woote desc",
"votes": 0
},
{
"id": 1,
"name": "woote 2",
"desc": "woote 3",
"votes": 0
}
]
}
[
{
"id": 1,
"name": "Test Voting",
"desc": "Sample voting description",
"img": "/img/voting.jpg",
"votes": {
"1": {
"name": "Sample Vote 1",
"desc": "Sample description",
"votes": []
},
"2": {
"name": "Sample Vote 2",
"desc": "Sample description",
"votes": []
}
}
},
{
"id": 2,
"name": "wooting",
"desc": "wooting desc",
"img": "/img/voting.jpg",
"votes": {
"1":{
"name": "woote 1",
"desc": "woote desc",
"votes": []
},
"2":{
"id": 1,
"name": "woote 2",
"desc": "woote 3",
"votes": []
}
}
}
]

Loading…
Cancel
Save