diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 6564d52..94a25f7 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 2aa4118..24d5ad2 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,7 +1,10 @@
-
+
+
+
+
+
+
+
+
diff --git a/app/src/main/java/com/amine/myterio/app/DetailsActivity.java b/app/src/main/java/com/amine/myterio/app/DetailsActivity.java
new file mode 100644
index 0000000..6972cd6
--- /dev/null
+++ b/app/src/main/java/com/amine/myterio/app/DetailsActivity.java
@@ -0,0 +1,39 @@
+package com.amine.myterio.app;
+
+import android.os.Bundle;
+import android.support.v7.app.ActionBarActivity;
+import android.view.Menu;
+import android.view.MenuItem;
+
+
+public class DetailsActivity extends ActionBarActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_details);
+ }
+
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_details, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/app/src/main/java/com/amine/myterio/app/MainActivity.java b/app/src/main/java/com/amine/myterio/app/MainActivity.java
index 2b0951e..c0820c3 100644
--- a/app/src/main/java/com/amine/myterio/app/MainActivity.java
+++ b/app/src/main/java/com/amine/myterio/app/MainActivity.java
@@ -1,5 +1,6 @@
package com.amine.myterio.app;
+import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
@@ -8,6 +9,8 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.View;
+import com.amine.myterio.app.adapters.CitiesAdapter;
import com.amine.myterio.app.db.CityDAO;
import com.amine.myterio.app.model.City;
import com.melnykov.fab.FloatingActionButton;
@@ -76,7 +79,13 @@ public class MainActivity extends AppCompatActivity {
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.attachToRecyclerView(mRecyclerView);
-
+ fab.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent(MainActivity.this, SearchActivity.class);
+ startActivity(intent);
+ }
+ });
}
diff --git a/app/src/main/java/com/amine/myterio/app/SearchActivity.java b/app/src/main/java/com/amine/myterio/app/SearchActivity.java
new file mode 100644
index 0000000..331c043
--- /dev/null
+++ b/app/src/main/java/com/amine/myterio/app/SearchActivity.java
@@ -0,0 +1,102 @@
+package com.amine.myterio.app;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.*;
+import com.amine.myterio.app.api.CitiesAdapters;
+import com.amine.myterio.app.api.CitiesApi;
+import com.amine.myterio.app.api.Predictions;
+import com.amine.myterio.app.config.Config;
+import com.amine.myterio.app.model.Countries;
+import retrofit.Callback;
+import retrofit.RetrofitError;
+import retrofit.client.Response;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class SearchActivity extends AppCompatActivity {
+ private final List citiesArray = new ArrayList();
+ private Countries countries;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_search);
+
+ final SearchView s = (SearchView) findViewById(R.id.searchView);
+ ListView l = (ListView) findViewById(R.id.listView2);
+
+ final ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, citiesArray);
+ l.setAdapter(adapter);
+
+ l.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ TextView t = (TextView) view;
+ s.setQuery(t.getText(), true);
+ }
+ });
+
+ s.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
+ @Override
+ public boolean onQueryTextSubmit(String query) {
+ Intent intent = new Intent(SearchActivity.this, DetailsActivity.class);
+ startActivity(intent);
+ return false;
+ }
+
+ @Override
+ public boolean onQueryTextChange(String newText) {
+ final boolean[] found = {false};
+
+ CitiesAdapters adapters = new CitiesAdapters();
+ CitiesApi.AutocompleteApi s = adapters.getCitiesForAutocomplete();
+ s.autocompletePlace(newText, Config.placesApiKey, new Callback() {
+ @Override
+ public void success(Predictions predictions, Response response) {
+ List cities = predictions.getCities();
+ citiesArray.clear();
+ found[0] = !cities.isEmpty();
+ citiesArray.addAll(cities);
+ adapter.notifyDataSetChanged();
+ }
+
+ @Override
+ public void failure(RetrofitError error) {
+ Toast.makeText(getApplicationContext(), "Erreur lors de la récupération des pays", Toast.LENGTH_SHORT).show();
+ }
+ });
+ return found[0];
+ }
+ });
+ }
+
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_search, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/app/src/main/java/com/amine/myterio/app/CitiesAdapter.java b/app/src/main/java/com/amine/myterio/app/adapters/CitiesAdapter.java
similarity index 92%
rename from app/src/main/java/com/amine/myterio/app/CitiesAdapter.java
rename to app/src/main/java/com/amine/myterio/app/adapters/CitiesAdapter.java
index 263a31b..0dc2e83 100644
--- a/app/src/main/java/com/amine/myterio/app/CitiesAdapter.java
+++ b/app/src/main/java/com/amine/myterio/app/adapters/CitiesAdapter.java
@@ -1,4 +1,4 @@
-package com.amine.myterio.app;
+package com.amine.myterio.app.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
@@ -8,6 +8,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
+import com.amine.myterio.app.R;
import com.amine.myterio.app.api.WeatherAdapters;
import com.amine.myterio.app.api.WeatherApis;
import com.amine.myterio.app.model.City;
@@ -21,21 +22,6 @@ public class CitiesAdapter extends RecyclerView.Adapter mDataset;
private static Context c;
- public class ViewHolder extends RecyclerView.ViewHolder implements RecyclerView.OnClickListener{
- public View mCardView;
-
- public ViewHolder(View itemView) {
- super(itemView);
- mCardView = itemView;
- itemView.setOnClickListener(this);
- }
-
- @Override
- public void onClick(View v) {
- // Go to details activity
- }
- }
-
public CitiesAdapter(ArrayList cities, Context c) {
mDataset = cities;
this.c = c;
@@ -62,6 +48,9 @@ public class CitiesAdapter extends RecyclerView.Adapter cb);
+ }
+}
diff --git a/app/src/main/java/com/amine/myterio/app/api/PredictionCities.java b/app/src/main/java/com/amine/myterio/app/api/PredictionCities.java
new file mode 100644
index 0000000..71c4545
--- /dev/null
+++ b/app/src/main/java/com/amine/myterio/app/api/PredictionCities.java
@@ -0,0 +1,19 @@
+package com.amine.myterio.app.api;
+
+import com.amine.myterio.app.model.City;
+
+public class PredictionCities {
+ public String description;
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public City toCity() {
+ return new City(this.description);
+ }
+}
diff --git a/app/src/main/java/com/amine/myterio/app/api/Predictions.java b/app/src/main/java/com/amine/myterio/app/api/Predictions.java
new file mode 100644
index 0000000..ba66bf8
--- /dev/null
+++ b/app/src/main/java/com/amine/myterio/app/api/Predictions.java
@@ -0,0 +1,24 @@
+package com.amine.myterio.app.api;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Predictions {
+ public List predictions;
+
+ public List getPredictions() {
+ return predictions;
+ }
+
+ public void setPredictions(List predictions) {
+ this.predictions = predictions;
+ }
+
+ public ArrayList getCities() {
+ ArrayList cities = new ArrayList();
+ for (PredictionCities city : predictions) {
+ cities.add(city.toCity().getName());
+ }
+ return cities;
+ }
+}
diff --git a/app/src/main/java/com/amine/myterio/app/config/Config.java b/app/src/main/java/com/amine/myterio/app/config/Config.java
new file mode 100644
index 0000000..75a9183
--- /dev/null
+++ b/app/src/main/java/com/amine/myterio/app/config/Config.java
@@ -0,0 +1,5 @@
+package com.amine.myterio.app.config;
+
+public class Config {
+ public static String placesApiKey = "AIzaSyDxSXMcZK1Ybjkz-IuN2EhhFCwRSbaianE";
+}
diff --git a/app/src/main/java/com/amine/myterio/app/model/City.java b/app/src/main/java/com/amine/myterio/app/model/City.java
index b8ee008..76de724 100644
--- a/app/src/main/java/com/amine/myterio/app/model/City.java
+++ b/app/src/main/java/com/amine/myterio/app/model/City.java
@@ -20,6 +20,10 @@ public class City {
}
+ public City(String description) {
+ this.name = description;
+ }
+
public String getName() {
return name;
diff --git a/app/src/main/java/com/amine/myterio/app/model/Countries.java b/app/src/main/java/com/amine/myterio/app/model/Countries.java
new file mode 100644
index 0000000..643f259
--- /dev/null
+++ b/app/src/main/java/com/amine/myterio/app/model/Countries.java
@@ -0,0 +1,20 @@
+package com.amine.myterio.app.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Countries {
+ public List countries;
+
+ public Countries() {
+ countries = new ArrayList();
+ }
+
+ public List getCountries() {
+ return countries;
+ }
+
+ public void setCountries(List countries) {
+ this.countries = countries;
+ }
+}
diff --git a/app/src/main/java/com/amine/myterio/app/model/Country.java b/app/src/main/java/com/amine/myterio/app/model/Country.java
new file mode 100644
index 0000000..bfac350
--- /dev/null
+++ b/app/src/main/java/com/amine/myterio/app/model/Country.java
@@ -0,0 +1,29 @@
+package com.amine.myterio.app.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Country {
+ public String name;
+ public List cities;
+
+ public Country() {
+ cities = new ArrayList();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List getCities() {
+ return cities;
+ }
+
+ public void setCities(List cities) {
+ this.cities = cities;
+ }
+}
diff --git a/app/src/main/java/com/amine/myterio/app/model/MainInfo.java b/app/src/main/java/com/amine/myterio/app/model/MainInfo.java
index a44826b..75698bc 100644
--- a/app/src/main/java/com/amine/myterio/app/model/MainInfo.java
+++ b/app/src/main/java/com/amine/myterio/app/model/MainInfo.java
@@ -5,24 +5,24 @@ public class MainInfo {
public float temp_max;
public float temp_min;
- public float getTemp() {
- return temp;
+ public int getTemp() {
+ return Math.round(temp);
}
public void setTemp(float temp) {
this.temp = temp;
}
- public float getTemp_max() {
- return temp_max;
+ public int getTemp_max() {
+ return Math.round(temp_max);
}
public void setTemp_max(float temp_max) {
this.temp_max = temp_max;
}
- public float getTemp_min() {
- return temp_min;
+ public int getTemp_min() {
+ return Math.round(temp_min);
}
public void setTemp_min(float temp_min) {
diff --git a/app/src/main/res/layout/activity_details.xml b/app/src/main/res/layout/activity_details.xml
new file mode 100644
index 0000000..4fffdc8
--- /dev/null
+++ b/app/src/main/res/layout/activity_details.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml
new file mode 100644
index 0000000..b691300
--- /dev/null
+++ b/app/src/main/res/layout/activity_search.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/city_card_view.xml b/app/src/main/res/layout/city_card_view.xml
index 20487c3..c5e9b4e 100644
--- a/app/src/main/res/layout/city_card_view.xml
+++ b/app/src/main/res/layout/city_card_view.xml
@@ -1,94 +1,144 @@
+ card_view:cardElevation="2dp"
+ card_view:cardUseCompatPadding="true">
+ android:layout_gravity="center_horizontal"
+ android:orientation="horizontal">
+ android:layout_weight=".5">
+ android:layout_alignParentTop="true"
+ android:layout_marginTop="25dp"
+ android:text="Large Text"
+ android:textAppearance="?android:attr/textAppearanceLarge"/>
+
+
+
+
+
+
+ android:layout_marginBottom="5dp"
+ android:src="@mipmap/ic_min"
+ android:tint="#0091ea"/>
-
-
+ android:textAppearance="?android:attr/textAppearanceMedium"/>
+
+
+
+
+ android:layout_centerHorizontal="true"
+ android:layout_centerVertical="true"/>
+ android:layout_marginTop="25dp"
+ android:text="Small Text"
+ android:textAppearance="?android:attr/textAppearanceSmall"/>
+ android:layout_marginBottom="25dp"
+ android:text="Medium Text"
+ android:textAppearance="?android:attr/textAppearanceMedium"/>
+
+
diff --git a/app/src/main/res/menu/menu_details.xml b/app/src/main/res/menu/menu_details.xml
new file mode 100644
index 0000000..9c10812
--- /dev/null
+++ b/app/src/main/res/menu/menu_details.xml
@@ -0,0 +1,10 @@
+
diff --git a/app/src/main/res/menu/menu_search.xml b/app/src/main/res/menu/menu_search.xml
new file mode 100644
index 0000000..9ef21e9
--- /dev/null
+++ b/app/src/main/res/menu/menu_search.xml
@@ -0,0 +1,10 @@
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b37a377..267c85c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -2,4 +2,6 @@
Myterio
Hello world!
Settings
+ SearchActivity
+ DetailsActivity