give RentActivity real functionality
This commit is contained in:
parent
d83312bc4d
commit
f7a527ed42
1 changed files with 39 additions and 2 deletions
|
|
@ -1,14 +1,51 @@
|
||||||
package com.example.hochi.nextcompanion;
|
package com.example.hochi.nextcompanion;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class RentActivity extends AppCompatActivity {
|
public class RentActivity extends AppCompatActivity implements AsyncTaskCallbacks<String> {
|
||||||
|
private RequestHandler rentRequestTask = null;
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_rent);
|
setContentView(R.layout.activity_rent);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
Button mRentSubmitButton = findViewById(R.id.rent_submit_button);
|
||||||
|
mRentSubmitButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
rentRequest();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void rentRequest() {
|
||||||
|
TextView mBikeInput;
|
||||||
|
mBikeInput = findViewById(R.id.bike_id);
|
||||||
|
String bikeID = mBikeInput.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),
|
||||||
|
"loginkey=", loginKey,
|
||||||
|
"bike=", bikeID
|
||||||
|
};
|
||||||
|
|
||||||
|
rentRequestTask = new RequestHandler(this, "POST",
|
||||||
|
"api/rent.json", params);
|
||||||
|
rentRequestTask.execute((Void) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTaskComplete(String response) {
|
||||||
|
//TODO: *any* response handling
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue