Advertisement
Guest User

Untitled

a guest
May 27th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.13 KB | None | 0 0
  1. Index: app/src/main/java/project/isi/octaneo/activities/GasStationInfoActivity.java
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- app/src/main/java/project/isi/octaneo/activities/GasStationInfoActivity.java (revision 4d392dad7980837ac6a511ec539006ebc074fa03)
  7. +++ app/src/main/java/project/isi/octaneo/activities/GasStationInfoActivity.java (date 1527415097138)
  8. @@ -5,15 +5,16 @@
  9. import android.support.annotation.Nullable;
  10. import android.support.v7.widget.LinearLayoutManager;
  11. import android.support.v7.widget.RecyclerView;
  12. +import android.view.View;
  13. import android.widget.CheckBox;
  14. import android.widget.EditText;
  15. import android.widget.RatingBar;
  16. import android.widget.TextView;
  17. -import android.view.View;
  18.  
  19. import project.isi.octaneo.R;
  20. import project.isi.octaneo.adapters.GasStationCommentsAdapter;
  21. import project.isi.octaneo.adapters.GasStationFuelsAdapter;
  22. +import project.isi.octaneo.adapters.GasStationPaymentMethodsAdapter;
  23. import project.isi.octaneo.controllers.GasStationInfoController;
  24. import project.isi.octaneo.data.GasStation;
  25. import project.isi.octaneo.enums.IntentKey;
  26. @@ -33,6 +34,7 @@
  27. private CheckBox isForElectricCars;
  28. private RecyclerView gasStationFuels;
  29. private RecyclerView gasStationComments;
  30. + private RecyclerView gasStationPaymentMethods;
  31. private EditText commentBody;
  32. private RatingBar commentRate;
  33.  
  34. @@ -50,6 +52,7 @@
  35. controller = new GasStationInfoController(this, new AsyncConnectionTaskFactory());
  36. controller.loadGasStationFuels(gasStation.id);
  37. controller.loadGasStationComments(gasStation.id);
  38. + controller.loadGasStationPaymentMethods(gasStation.id);
  39. }
  40.  
  41. public void handleSubmitCommentClick(View view){
  42. @@ -68,6 +71,10 @@
  43. gasStationComments.setAdapter(adapter);
  44. }
  45.  
  46. + public void setGasStationPaymentMethodsAdapter(GasStationPaymentMethodsAdapter adapter) {
  47. + gasStationComments.setAdapter(adapter);
  48. + }
  49. +
  50. private void initializeGui() {
  51. gasStationName = findViewById(R.id.gasStationName);
  52. gasStationAddress = findViewById(R.id.gasStationAddress);
  53. @@ -89,6 +96,10 @@
  54. gasStationComments = findViewById(R.id.gasStationOpinions);
  55. gasStationComments.setHasFixedSize(true);
  56. gasStationComments.setLayoutManager(new LinearLayoutManager(this));
  57. +
  58. + gasStationPaymentMethods = findViewById(R.id.gasStationPaymentMethods);
  59. + gasStationPaymentMethods.setHasFixedSize(true);
  60. + gasStationPaymentMethods.setLayoutManager(new LinearLayoutManager(this));
  61. }
  62.  
  63. @SuppressLint("SetTextI18n")
  64. Index: app/src/main/java/project/isi/octaneo/adapters/GasStationPaymentMethodsAdapter.java
  65. IDEA additional info:
  66. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  67. <+>UTF-8
  68. ===================================================================
  69. --- app/src/main/java/project/isi/octaneo/adapters/GasStationPaymentMethodsAdapter.java (date 1527341448673)
  70. +++ app/src/main/java/project/isi/octaneo/adapters/GasStationPaymentMethodsAdapter.java (date 1527341448673)
  71. @@ -0,0 +1,55 @@
  72. +package project.isi.octaneo.adapters;
  73. +
  74. +import android.content.Context;
  75. +import android.support.annotation.NonNull;
  76. +import android.support.v7.widget.RecyclerView;
  77. +import android.view.LayoutInflater;
  78. +import android.view.View;
  79. +import android.view.ViewGroup;
  80. +import android.widget.TextView;
  81. +
  82. +import java.util.List;
  83. +
  84. +import project.isi.octaneo.R;
  85. +
  86. +public class GasStationPaymentMethodsAdapter extends RecyclerView.Adapter<GasStationPaymentMethodsAdapter.ViewHolder> {
  87. + private Context context;
  88. + private List<String> paymentMethods;
  89. +
  90. + public GasStationPaymentMethodsAdapter(@NonNull Context context, List<String> paymentMethods) {
  91. + this.context = context;
  92. + this.paymentMethods = paymentMethods;
  93. + }
  94. +
  95. + @NonNull
  96. + @Override
  97. + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  98. + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fuel_item, parent, false);
  99. + return new ViewHolder(view);
  100. + }
  101. +
  102. + @Override
  103. + public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
  104. + String paymentType = this.paymentMethods.get(position);
  105. + holder.paymentType.setText(paymentType);
  106. + }
  107. +
  108. + @Override
  109. + public int getItemCount() {
  110. + return paymentMethods.size();
  111. + }
  112. +
  113. + public void addPaymentMethods(List<String> paymentMethods) {
  114. + this.paymentMethods.addAll(paymentMethods);
  115. + notifyDataSetChanged();
  116. + }
  117. +
  118. + public class ViewHolder extends RecyclerView.ViewHolder {
  119. + private TextView paymentType;
  120. +
  121. + ViewHolder(View itemView) {
  122. + super(itemView);
  123. + paymentType = itemView.findViewById(R.id.paymentType);
  124. + }
  125. + }
  126. +}
  127. Index: app/src/main/java/project/isi/octaneo/controllers/GasStationInfoController.java
  128. IDEA additional info:
  129. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  130. <+>UTF-8
  131. ===================================================================
  132. --- app/src/main/java/project/isi/octaneo/controllers/GasStationInfoController.java (revision 4d392dad7980837ac6a511ec539006ebc074fa03)
  133. +++ app/src/main/java/project/isi/octaneo/controllers/GasStationInfoController.java (date 1527341495188)
  134. @@ -14,6 +14,7 @@
  135. import project.isi.octaneo.activities.GasStationInfoActivity;
  136. import project.isi.octaneo.adapters.GasStationCommentsAdapter;
  137. import project.isi.octaneo.adapters.GasStationFuelsAdapter;
  138. +import project.isi.octaneo.adapters.GasStationPaymentMethodsAdapter;
  139. import project.isi.octaneo.data.Comment;
  140. import project.isi.octaneo.data.Fuel;
  141. import project.isi.octaneo.data.Response;
  142. @@ -32,8 +33,10 @@
  143.  
  144. private List<Fuel> fuels;
  145. private List<Comment> comments;
  146. + private List<String> paymentMethods;
  147. private GasStationFuelsAdapter fuelsAdapter;
  148. private GasStationCommentsAdapter commentsAdapter;
  149. + private GasStationPaymentMethodsAdapter paymentAdapter;
  150.  
  151. public GasStationInfoController(GasStationInfoActivity activity, AsyncConnectionTaskFactory taskFactory) {
  152. this.activity = activity;
  153. @@ -46,6 +49,10 @@
  154. this.comments = new ArrayList<>();
  155. this.commentsAdapter = new GasStationCommentsAdapter(activity, comments);
  156. this.activity.setGasStationCommentsAdapter(commentsAdapter);
  157. +
  158. + this.paymentMethods = new ArrayList<>();
  159. + this.paymentAdapter = new GasStationPaymentMethodsAdapter(activity, paymentMethods);
  160. + this.activity.setGasStationPaymentMethodsAdapter(paymentAdapter);
  161. }
  162.  
  163. @Override
  164. @@ -63,6 +70,9 @@
  165. case SUBMIT_COMMENT:
  166. handleCommentSubmitResponse(response.responseContent);
  167. break;
  168. + case RETRIEVE_PAYMENT_METHODS:
  169. + handleReceivedGasStationPaymentMethods(response.responseContent);
  170. + break;
  171. }
  172. }
  173.  
  174. @@ -90,6 +100,13 @@
  175. .execute(requestBuilder.build());
  176. }
  177.  
  178. + public void loadGasStationPaymentMethods(long gasStationId) {
  179. + RequestBuilder requestBuilder = new RequestBuilder(activity.getString(R.string.retrievePaymentMethods));
  180. + requestBuilder.putParameter("stationId", String.valueOf(gasStationId));
  181. + connectionTaskFactory.create(this, AsyncConnectionTask.RequestType.RETRIEVE_PAYMENT_METHODS)
  182. + .execute(requestBuilder.build());
  183. + }
  184. +
  185. public void processSaveFuelPriceRequest(String fuelId, String price) {
  186. RequestBuilder requestBuilder = new RequestBuilder(activity.getString(R.string.fuelPriceUrl));
  187. requestBuilder.putParameter("fuelId", fuelId);
  188. @@ -149,6 +166,18 @@
  189. e.printStackTrace();
  190. }
  191. }
  192. +
  193. + private void handleReceivedGasStationPaymentMethods(String responseContent) {
  194. + try {
  195. + JSONObject responseJson = new JSONObject(responseContent);
  196. + int status = responseJson.getInt(ResponseStatus.Key.STATUS);
  197. + if (status == ResponseStatus.General.SUCCESS) {
  198. + handleSuccessfulRetrieveGasStationsPaymentMethod(responseJson.getString(ResponseStatus.Key.CONTENT));
  199. + }
  200. + } catch (JSONException e) {
  201. + e.printStackTrace();
  202. + }
  203. + }
  204.  
  205. private void handleSuccessfulRetrieveGasStationsFuels(String responseContent) {
  206. Type listType = new TypeToken<List<Fuel>>() {
  207. @@ -156,6 +185,7 @@
  208. List<Fuel> fuels = new Gson().fromJson(responseContent, listType);
  209. fuelsAdapter.addFuels(fuels);
  210. }
  211. +
  212. private void handleSuccessfulRetrieveGasStationsComments(String responseContent) {
  213. Type listType = new TypeToken<List<Comment>>() {
  214. }.getType();
  215. @@ -163,6 +193,13 @@
  216. commentsAdapter.addComments(comments);
  217. }
  218.  
  219. + private void handleSuccessfulRetrieveGasStationsPaymentMethod(String responseContent) {
  220. + Type listType = new TypeToken<List<String>>() {
  221. + }.getType();
  222. + List<String> paymentMethods = new Gson().fromJson(responseContent, listType);
  223. + paymentAdapter.addPaymentMethods(paymentMethods);
  224. + }
  225. +
  226. private void handleReceivedFuelPriceConfirm(String responseContent) {
  227. try {
  228. JSONObject jsonResponse = new JSONObject(responseContent);
  229. Index: app/src/main/java/project/isi/octaneo/source/AsyncConnectionTask.java
  230. IDEA additional info:
  231. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  232. <+>UTF-8
  233. ===================================================================
  234. --- app/src/main/java/project/isi/octaneo/source/AsyncConnectionTask.java (revision 4d392dad7980837ac6a511ec539006ebc074fa03)
  235. +++ app/src/main/java/project/isi/octaneo/source/AsyncConnectionTask.java (date 1527341031671)
  236. @@ -105,5 +105,6 @@
  237. SAVE_FUEL_PRICE,
  238. SUBMIT_COMMENT,
  239. UPDATE_STATION_DESC,
  240. + RETRIEVE_PAYMENT_METHODS
  241. }
  242. }
  243. \ No newline at end of file
  244. Index: app/src/main/res/layout/activity_info_gas_station.xml
  245. IDEA additional info:
  246. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  247. <+>UTF-8
  248. ===================================================================
  249. --- app/src/main/res/layout/activity_info_gas_station.xml (revision 4d392dad7980837ac6a511ec539006ebc074fa03)
  250. +++ app/src/main/res/layout/activity_info_gas_station.xml (date 1527415097117)
  251. @@ -1,6 +1,5 @@
  252. <?xml version="1.0" encoding="utf-8"?>
  253. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  254. - xmlns:tools="http://schemas.android.com/tools"
  255. android:layout_width="match_parent"
  256. android:layout_height="match_parent"
  257. android:orientation="vertical"
  258. @@ -78,6 +77,17 @@
  259. android:id="@+id/gasStationFuels"
  260. android:layout_width="match_parent"
  261. android:layout_height="match_parent" />
  262. +
  263. + <View
  264. + android:layout_width="match_parent"
  265. + android:layout_height="1dp"
  266. + android:layout_margin="@dimen/space5"
  267. + android:background="@color/colorDivider" />
  268. +
  269. + <android.support.v7.widget.RecyclerView
  270. + android:id="@+id/gasStationPaymentMethods"
  271. + android:layout_width="match_parent"
  272. + android:layout_height="match_parent" />
  273.  
  274. <View
  275. android:layout_width="match_parent"
  276. Index: app/src/main/res/layout/payment_item.xml
  277. IDEA additional info:
  278. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  279. <+>UTF-8
  280. ===================================================================
  281. --- app/src/main/res/layout/payment_item.xml (date 1527340614575)
  282. +++ app/src/main/res/layout/payment_item.xml (date 1527340614575)
  283. @@ -0,0 +1,14 @@
  284. +<?xml version="1.0" encoding="utf-8"?>
  285. +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  286. + android:layout_width="match_parent"
  287. + android:layout_height="wrap_content"
  288. + android:orientation="horizontal">
  289. +
  290. + <TextView
  291. + android:id="@+id/paymentType"
  292. + android:layout_width="wrap_content"
  293. + android:layout_height="wrap_content"
  294. + android:layout_marginEnd="@dimen/space10"
  295. + android:textSize="@dimen/h1" />
  296. +
  297. +</LinearLayout>
  298. \ No newline at end of file
  299. Index: app/src/main/res/values/strings.xml
  300. IDEA additional info:
  301. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  302. <+>UTF-8
  303. ===================================================================
  304. --- app/src/main/res/values/strings.xml (revision 4d392dad7980837ac6a511ec539006ebc074fa03)
  305. +++ app/src/main/res/values/strings.xml (date 1527341081649)
  306. @@ -100,6 +100,7 @@
  307. <string name="fuelPriceUrl">http://&serverIP;:8000/addFuelPrice</string>
  308. <string name="addCommentUrl">http://&serverIP;:8000/addComment</string>
  309. <string name="stationDescriptionChangeUrl">http://&serverIP;:8000/updateDescription</string>
  310. + <string name="retrievePaymentMethods">http://&serverIP;:8000/getPaymentMethods</string>
  311.  
  312. <!--Tags-->
  313. <string name="mapFragmentTag">MAP_FRAGMENT</string>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement