add return activity
This commit is contained in:
parent
f7a527ed42
commit
42bd4e7890
4 changed files with 139 additions and 1 deletions
|
|
@ -31,6 +31,12 @@
|
|||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".MainActivity" />
|
||||
</activity>
|
||||
<activity android:name=".ReturnActivity"
|
||||
android:label="@string/title_activity_return">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".MainActivity" />
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -17,6 +17,7 @@ import android.widget.ArrayAdapter;
|
|||
import android.widget.ListView;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -101,6 +102,8 @@ public class MainActivity extends AppCompatActivity implements AsyncTaskCallback
|
|||
|
||||
@Override
|
||||
public void onTaskComplete(String response) {
|
||||
final Context context = this;
|
||||
|
||||
if (!response.isEmpty()) {
|
||||
final ArrayList<String> list = new ArrayList<>();
|
||||
try {
|
||||
|
|
@ -122,13 +125,31 @@ public class MainActivity extends AppCompatActivity implements AsyncTaskCallback
|
|||
final ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_list_item_1, list);
|
||||
listview.setAdapter(adapter);
|
||||
|
||||
try {
|
||||
final JSONObject jObject = new JSONObject(response);
|
||||
final JSONArray bikesArray = jObject.getJSONArray("rentalCollection");
|
||||
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
|
||||
//TODO: Return bike
|
||||
Intent intent = new Intent(context, ReturnActivity.class);
|
||||
try {
|
||||
JSONObject bike = bikesArray.getJSONObject(position);
|
||||
String bID = bike.getString("bike");
|
||||
String stID = bike.getString("start_place");
|
||||
String[] bikeArray = {bID, stID};
|
||||
intent.putExtra("bike", bikeArray);
|
||||
startActivity(intent);
|
||||
}
|
||||
catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
//TODO: implement error handling
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
package com.example.hochi.nextcompanion;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ReturnActivity extends AppCompatActivity implements AsyncTaskCallbacks<String> {
|
||||
private RequestHandler returnRequestTask = null;
|
||||
private String[] bikeArray;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_return);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
|
||||
Intent intent = getIntent();
|
||||
bikeArray = intent.getStringArrayExtra("bike");
|
||||
|
||||
Button mReturnSubmitButton = findViewById(R.id.return_submit_button);
|
||||
mReturnSubmitButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
returnRequest();
|
||||
}
|
||||
});
|
||||
}
|
||||
void returnRequest() {
|
||||
TextView mStationInput;
|
||||
mStationInput = findViewById(R.id.return_station_id);
|
||||
String stationID = mStationInput.getText().toString();
|
||||
//get loginkey
|
||||
SharedPreferences sharedPref = getSharedPreferences("persistence", MODE_PRIVATE);
|
||||
String defaultValue = "nokey";
|
||||
String loginKey = sharedPref.getString("loginKey", defaultValue);
|
||||
|
||||
String[] params = {
|
||||
"apikey=", getString(R.string.apikey),
|
||||
"bike=", bikeArray[0],
|
||||
"loginkey=", loginKey,
|
||||
"station=", stationID,
|
||||
"comment=", "return bike"
|
||||
};
|
||||
returnRequestTask = new RequestHandler(this, "POST",
|
||||
"api/return.json", params);
|
||||
returnRequestTask.execute((Void) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskComplete(String response) {
|
||||
Log.d("DEBUG", response);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
50
app/src/main/res/layout/activity_return.xml
Normal file
50
app/src/main/res/layout/activity_return.xml
Normal 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"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".ReturnActivity">
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/rent_form"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/return_station_id"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/prompt_return_station_id"
|
||||
android:inputType="number"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true" />
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/return_submit_button"
|
||||
style="?android:textAppearanceSmall"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/action_return_submit"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue