Browse Source

Ratings page in progress

old
Yiğit Çolakoğlu 6 years ago
parent
commit
fa0b30ff01
9 changed files with 225 additions and 33 deletions
  1. +1
    -0
      MyCity/app/src/main/AndroidManifest.xml
  2. +17
    -5
      MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java
  3. +146
    -0
      MyCity/app/src/main/java/gq/yigit/mycity/RateFragment.java
  4. +0
    -1
      MyCity/app/src/main/java/gq/yigit/mycity/votesFragment/VoteFragment.java
  5. +50
    -0
      MyCity/app/src/main/res/layout/fragment_rate.xml
  6. +2
    -1
      MyCity/app/src/main/res/layout/fragment_vote.xml
  7. BIN
      server_side/api/modules/__pycache__/rating_system.cpython-37.pyc
  8. +6
    -0
      server_side/api/modules/databases/ratings.json
  9. +3
    -26
      server_side/api/modules/rating_system.py

+ 1
- 0
MyCity/app/src/main/AndroidManifest.xml View File

@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gq.yigit.mycity">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"


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

@ -1,5 +1,6 @@
package gq.yigit.mycity;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
@ -23,6 +24,7 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import gq.yigit.mycity.navigation.MapsFragment;
import gq.yigit.mycity.tools.*;
import gq.yigit.mycity.tools.WebRequest.responseListener;
import gq.yigit.mycity.votesFragment.VoteFragment;
@ -42,16 +44,19 @@ public class MainActivity extends AppCompatActivity
OnNavigationItemSelectedListener,
OnListFragmentInteractionListener,
MainFragment.OnFragmentInteractionListener,
RateFragment.OnFragmentInteractionListener,
MapsFragment.OnFragmentInteractionListener,
OnFragmentInteractionListener,
responseListener,
imageListener {
private Context cntxt;
public static Context cntxt;
public static JSONObject userData;
public static Bitmap userAvatar;
private String url;
private ImageView avatarView;
private TextView userName;
public static Activity mainActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("[BOOKMARK]","Started creating activity");
@ -92,7 +97,7 @@ public class MainActivity extends AppCompatActivity
avatarView = header.findViewById(R.id.avatar);
userName = header.findViewById(R.id.uname);
mainActivity = this;
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.app_bar_main, fragment);
transaction.addToBackStack(null);
@ -163,19 +168,26 @@ public class MainActivity extends AppCompatActivity
fragmentTransaction.replace(R.id.app_bar_main, fragment);
fragmentTransaction.commit();
fragmentTransaction.addToBackStack(null);
} else if (id == R.id.parking) {
} else if (id == R.id.transit) {
} else if (id == R.id.navigation) {
MapsFragment fragment = new MapsFragment();
fragmentTransaction.replace(R.id.app_bar_main, fragment);
fragmentTransaction.commit();
fragmentTransaction.addToBackStack(null);
} else if (id == R.id.rating) {
RateFragment fragment = new RateFragment();
fragmentTransaction.replace(R.id.app_bar_main, fragment);
fragmentTransaction.commit();
fragmentTransaction.addToBackStack(null);
} else if (id == R.id.utilities) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;


+ 146
- 0
MyCity/app/src/main/java/gq/yigit/mycity/RateFragment.java View File

@ -0,0 +1,146 @@
package gq.yigit.mycity;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.location.*;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import gq.yigit.mycity.tools.FileActions;
import gq.yigit.mycity.tools.ImageDownload;
import gq.yigit.mycity.tools.WebRequest;
import org.json.JSONArray;
import org.json.JSONException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import static android.content.Context.CONTEXT_IGNORE_SECURITY;
import static gq.yigit.mycity.MainActivity.cntxt;
public class RateFragment extends Fragment implements WebRequest.responseListener, ImageDownload.imageListener,LocationListener {
private OnFragmentInteractionListener mListener;
private String url;
private int i = 0;
private JSONArray ratings;
public RateFragment() {
// Required empty public constructor
}
public static RateFragment newInstance(String param1, String param2) {
RateFragment fragment = new RateFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LocationManager locationManager = (LocationManager)
cntxt.getSystemService(cntxt.LOCATION_SERVICE);
LocationListener locationListener = this;
if ( ContextCompat.checkSelfPermission( cntxt, android.Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions(MainActivity.mainActivity, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },1);
}
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 10, locationListener);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_rate, container, false);
}
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
@Override
public void receivedResponse(boolean success, String response) {
if(success){
try {
ratings = new JSONArray(response);
ratings.get(i);
}catch (JSONException e){
Log.i("[ERROR]","Received an invalid response");
}
}
}
@Override
public void imageDownloaded(Bitmap img){
}
@Override
public void onLocationChanged(Location loc) {
String longitude = "Longitude: " + loc.getLongitude();
String latitude = "Latitude: " + loc.getLatitude();
FileActions file_manager = new FileActions();
url = file_manager.readFromFile(cntxt,"server.config").trim();
HashMap<String,String> request = new HashMap<>();
request.put("longitude",longitude);
request.put("latitude","latitude");
WebRequest web_manager = new WebRequest(url + "/ratings",false,request);
web_manager.addListener(this);
web_manager.execute();
}
@Override
public void onProviderDisabled(String provider) {}
@Override
public void onProviderEnabled(String provider) {
Log.i("[INFO]",provider);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
}

+ 0
- 1
MyCity/app/src/main/java/gq/yigit/mycity/votesFragment/VoteFragment.java View File

@ -45,7 +45,6 @@ public class VoteFragment extends Fragment implements responseListener, imageLis
// Required empty public constructor
}
// TODO: Rename and change types and number of parameters
public static VoteFragment newInstance(String voteid) {
VoteFragment fragment = new VoteFragment();
Bundle args = new Bundle();


+ 50
- 0
MyCity/app/src/main/res/layout/fragment_rate.xml View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<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=".RateFragment" android:layout_marginTop="60dp">
<!-- TODO: Update blank fragment layout -->
<Spinner
android:layout_width="368dp"
android:layout_height="wrap_content"
android:id="@+id/rate_spinner" app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="8dp"
android:layout_marginEnd="8dp" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"/>
<ImageView
android:src="@color/colorAccent"
android:layout_width="0dp"
android:layout_height="182dp"
android:id="@+id/rate_img" app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/rate_spinner"/>
<RatingBar
android:layout_width="240dp"
android:layout_height="46dp"
android:id="@+id/rate_star"
style="@style/Widget.AppCompat.RatingBar" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/rate_img" app:layout_constraintEnd_toEndOf="@+id/rate_img"
android:layout_marginEnd="8dp" app:layout_constraintStart_toStartOf="@+id/rate_img"
android:layout_marginStart="8dp" app:layout_constraintHorizontal_bias="0.0"/>
<EditText
android:layout_width="0dp"
android:layout_height="126dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/rate_note"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
android:layout_marginTop="20dp" app:layout_constraintTop_toBottomOf="@+id/rate_star"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp" app:layout_constraintVertical_bias="0.0"/>
<Button
android:text="Submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rate_submit" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/rate_note" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"/>
</android.support.constraint.ConstraintLayout>

+ 2
- 1
MyCity/app/src/main/res/layout/fragment_vote.xml View File

@ -3,7 +3,8 @@
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=".votesFragment.VoteFragment" android:orientation="vertical">
tools:context=".votesFragment.VoteFragment" android:orientation="vertical"
android:layout_marginTop="60dp">
<!-- TODO: Update blank fragment layout -->
<ImageView


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


+ 6
- 0
server_side/api/modules/databases/ratings.json View File

@ -33,6 +33,12 @@
"rater": "9vard12ty0ad2yvwp3q53rsf3h43r2vq",
"score": 3,
"note": "Not bad boiii"
},
{
"id": 5,
"rater": "9vard12ty0ad2yvwp3q53rsf3h43r2vq",
"score": 3,
"note": "Not bad boiii"
}
]
}

+ 3
- 26
server_side/api/modules/rating_system.py View File

@ -19,14 +19,14 @@ with open(user_db, 'r') as f:
users = json.load(f)
class Ratings(Resource):
def get(self):
def post(self):
"""
Example URL Query:
latitude=<latitude>&
longitude=<longitude>
"""
latitude = float(request.args['latitude'])
longitude = float(request.args['longitude'])
latitude = float(request.form['latitude'])
longitude = float(request.form['longitude'])
ret_data = []
for rating in ratings:
@ -45,29 +45,6 @@ class Ratings(Resource):
return ret_data
def post(self):
"""
Example POST Data:
name=<rating_name>&
desc=<rating_desc>& # OPTIONAL
img=<rating_img>& # OPTIONAL
"""
args = request.form
rating_id = len(ratings) + 1
rating = {
'id': rating_id,
'name': args['name'],
'desc': args.get('desc'),
'img' : args.get('img'),
'rates': []
}
ratings.append(rating)
with open(db_path, 'w') as f:
json.dump(ratings, f, indent=4)
return rating
class Rating(Resource):
def get(self, rating_id):


Loading…
Cancel
Save