Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Button btnLogin = (Button) findViewById(R.id.loginBtn);
- btnLogin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- do_btnLogin_click();
- }
- });
- ___________________________________________________________________________________________________________
- private EditText txtUsername;
- txtUsername = (EditText) findViewById(R.id.usernameInput);
- ___________________________________________________________________________________________________________
- Toast.makeText(MainActivity.this, "Molimo popunite sva polja.", Toast.LENGTH_LONG).show();
- ___________________________________________________________________________________________________________
- ProgressDialog progressDialog;
- progressDialog = ProgressDialog.show(MainActivity.this, "Logiranje", "U toku");
- progressDialog.show();
- ___________________________________________________________________________________________________________
- new AsyncTask<Void, Void, AutentifikacijaProvjeraViewModel>() {
- ProgressDialog progressDialog;
- @Override
- protected void onPreExecute() {
- progressDialog = ProgressDialog.show(MainActivity.this, "Logiranje", "U toku");
- progressDialog.show();
- }
- @Override
- protected AutentifikacijaProvjeraViewModel doInBackground(Void... params) {
- return AutentifikacijaApi.Provjera(txtUsername.getText().toString(), txtPassword.getText().toString());
- }
- @Override
- protected void onPostExecute(AutentifikacijaProvjeraViewModel result) {
- if (result.Id == 0) {
- Toast.makeText(MainActivity.this, "Korisnik ne postoji!", Toast.LENGTH_LONG).show();
- } else {
- Toast.makeText(MainActivity.this, "Welcome back " + result.Ime, Toast.LENGTH_LONG).show();
- Global.isThisInitialLoad = true;
- Global.korisnik = result;
- Intent i = new Intent(getApplicationContext(), PocetniActivity.class);
- startActivity(i);
- }
- progressDialog.dismiss();
- }
- }.execute();
- ___________________________________________________________________________________________________________
- public static AutentifikacijaProvjeraViewModel Provjera(String username, String password)
- {
- String strJson= HttpManager.responseGet("http://192.168.0.15:21951/api/autentikacija/provjera",
- new BasicNameValuePair("email",username),
- new BasicNameValuePair("password",password)
- );
- //System.out.println("Ovo ispod je JSON string");
- //System.out.println(strJson);
- Gson gson= new Gson();
- AutentifikacijaProvjeraViewModel x = gson.fromJson(strJson, AutentifikacijaProvjeraViewModel.class);
- return x;
- }
- ___________________________________________________________________________________________________________
- public class HttpManager {
- public static String responseGet(String url, NameValuePair... inputParams) {
- String urlParams = URLEncodedUtils.format(Arrays.asList(inputParams), "utf-8");
- HttpGet httpGet = new HttpGet(url + "?" + urlParams);
- DefaultHttpClient client = new DefaultHttpClient();
- try {
- HttpResponse response = client.execute(httpGet);
- //InputStream stream= response.getEntity().getContent();
- HttpEntity entity = response.getEntity();
- InputStream stream = entity.getContent();
- String convertedFromStreamToJsonString = convertStreamToString(stream);
- //System.out.println(convertedFromStreamToJsonString);
- stream.close();
- //return convertStreamToString(stream);
- return convertedFromStreamToJsonString;
- } catch (IOException e) {
- Log.e("Error u HttpManageru", e.getMessage());
- return null;
- }
- }
- public static String convertStreamToString(InputStream inputStream) throws IOException {
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
- StringBuilder stringBuilder = new StringBuilder();
- String line = null;
- while ((line = bufferedReader.readLine()) != null) {
- stringBuilder.append(line + "\n");
- }
- return stringBuilder.toString();
- }
- }
- ___________________________________________________________________________________________________________
- private void do_btnOstaviUtisak_click(String utisak, int utisakBroj) {
- String message = "";
- final UtisakViewModel utisakForPost = new UtisakViewModel();
- utisakForPost.KorisnikId = Global.korisnik.Id;
- utisakForPost.Misljenje = utisak;
- utisakForPost.Rating = utisakBroj;
- utisakForPost.ProizvodId = Global.trenutnoSelektovaniProizvod.Id;
- //if (UtisciApi.PostUtisak(utisakForPost))
- // message = "Utisak uspjesno dodan";
- //else
- // message = "Greska! Utisak nije dodan.";
- RequestQueue MyRequestQueue = Volley.newRequestQueue(this);
- StringRequest MyStringRequest = new StringRequest(Request.Method.POST, "http://192.168.0.15:21951/api/Utisci/PostUtisak/", new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- //This code is executed if the server responds, whether or not the response contains data.
- //The String 'response' contains the server's response.
- Toast.makeText(OstaviUtisakActivity.this, "Utisak uspjesno ostavljen.", Toast.LENGTH_LONG).show();
- Intent i = new Intent(getApplicationContext(), ProizvodDetailjiActivity.class);
- i.putExtra("proizvodId", String.valueOf(Global.trenutnoSelektovaniProizvod.Id));
- startActivity(i);
- }
- }, new Response.ErrorListener() { //Create an error listener to handle errors appropriately.
- @Override
- public void onErrorResponse(VolleyError error) {
- //This code is executed if there is an error.
- Toast.makeText(OstaviUtisakActivity.this, "Greska! Utisak nije spasen, molimo pokusajte kasnije.", Toast.LENGTH_LONG).show();
- }
- }) {
- protected Map<String, String> getParams() {
- Map<String, String> MyData = new HashMap<String, String>();
- //MyData.put("Field", "Value"); //Add the data you'd like to send to the server.
- MyData.put("Id", "0");
- MyData.put("IsDeleted", "0");
- MyData.put("Misljenje", utisakForPost.Misljenje);
- MyData.put("Rating", String.valueOf(utisakForPost.Rating));
- MyData.put("KorisnikId", String.valueOf(utisakForPost.KorisnikId));
- MyData.put("ProizvodId", String.valueOf(utisakForPost.ProizvodId));
- return MyData;
- }
- };
- MyRequestQueue.add(MyStringRequest);
- }
- ___________________________________________________________________________________________________________
- LINKOVI:
- http://www.tutorialsbuzz.com/2014/06/android-dialogfragment-listview.html - za onaj dialog fragment sto je bio na prosloom roku
- http://www.androidhive.info/2011/08/how-to-switch-between-activities-in-android/ - Intent
- http://www.androidinterview.com/android-custom-listview-with-image-and-text-using-arrayadapter/ -listview sa slikama
- _______________________________VISE PARAMETARA U ROUTE NA API CONTROLERU___________________________________
- http://stackoverflow.com/questions/10937524/how-should-i-pass-multiple-parameters-to-an-asp-net-web-api-get
- --odgovor od Mark Pieszak
- -inace sam googlao ovako
- https://www.google.ba/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=set%20route%20for%20api%20controller%20with%202%20parameters
- ___________________________________________________________________________________________________________
- ___________________________________________________________________________________________________________
- ___________________________________________________________________________________________________________
- ___________________________________________________________________________________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement