truc
This commit is contained in:
parent
60aa5a9c98
commit
ee03c91cb9
@ -1,12 +1,9 @@
|
|||||||
package com.amine.myterio.app;
|
package com.amine.myterio.app;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
@ -15,25 +12,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
Toast.makeText(getApplicationContext(), getSizeName(this), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getSizeName(Context context) {
|
|
||||||
int screenLayout = context.getResources().getConfiguration().screenLayout;
|
|
||||||
screenLayout &= Configuration.SCREENLAYOUT_SIZE_MASK;
|
|
||||||
|
|
||||||
switch (screenLayout) {
|
|
||||||
case Configuration.SCREENLAYOUT_SIZE_SMALL:
|
|
||||||
return "small";
|
|
||||||
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
|
|
||||||
return "normal";
|
|
||||||
case Configuration.SCREENLAYOUT_SIZE_LARGE:
|
|
||||||
return "large";
|
|
||||||
case 4: // Configuration.SCREENLAYOUT_SIZE_XLARGE is API >= 9
|
|
||||||
return "xlarge";
|
|
||||||
default:
|
|
||||||
return "undefined";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
package com.amine.myterio.app.adapters;
|
package com.amine.myterio.app.adapters;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.FragmentManager;
|
||||||
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -17,6 +22,7 @@ import com.amine.myterio.app.api.WeatherAdapters;
|
|||||||
import com.amine.myterio.app.api.WeatherApis;
|
import com.amine.myterio.app.api.WeatherApis;
|
||||||
import com.amine.myterio.app.config.Config;
|
import com.amine.myterio.app.config.Config;
|
||||||
import com.amine.myterio.app.db.CityDAO;
|
import com.amine.myterio.app.db.CityDAO;
|
||||||
|
import com.amine.myterio.app.fragments.DetailsFragment;
|
||||||
import com.amine.myterio.app.model.City;
|
import com.amine.myterio.app.model.City;
|
||||||
import retrofit.Callback;
|
import retrofit.Callback;
|
||||||
import retrofit.RetrofitError;
|
import retrofit.RetrofitError;
|
||||||
@ -27,10 +33,12 @@ import java.util.ArrayList;
|
|||||||
public class CitiesAdapter extends RecyclerView.Adapter<CitiesAdapter.ViewHolder> {
|
public class CitiesAdapter extends RecyclerView.Adapter<CitiesAdapter.ViewHolder> {
|
||||||
private ArrayList<City> mDataset;
|
private ArrayList<City> mDataset;
|
||||||
private Context c;
|
private Context c;
|
||||||
|
private Activity activity;
|
||||||
|
|
||||||
public CitiesAdapter(ArrayList<City> cities, Context c) {
|
public CitiesAdapter(ArrayList<City> cities, Context c, Activity a) {
|
||||||
this.mDataset = cities;
|
this.mDataset = cities;
|
||||||
this.c = c;
|
this.c = c;
|
||||||
|
this.activity = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -102,11 +110,32 @@ public class CitiesAdapter extends RecyclerView.Adapter<CitiesAdapter.ViewHolder
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// Go to details activity
|
|
||||||
final int position = getLayoutPosition();
|
final int position = getLayoutPosition();
|
||||||
Intent intent = new Intent(c, DetailsActivity.class);
|
int a = (c.getResources().getConfiguration().screenLayout &
|
||||||
intent.putExtra("city", mDataset.get(position));
|
Configuration.SCREENLAYOUT_SIZE_MASK);
|
||||||
c.startActivity(intent);
|
|
||||||
|
if (((c.getResources().getConfiguration().screenLayout &
|
||||||
|
Configuration.SCREENLAYOUT_SIZE_MASK) ==
|
||||||
|
Configuration.SCREENLAYOUT_SIZE_LARGE) || ((c.getResources().getConfiguration().screenLayout &
|
||||||
|
Configuration.SCREENLAYOUT_SIZE_MASK) ==
|
||||||
|
Configuration.SCREENLAYOUT_SIZE_XLARGE) || ((c.getResources().getConfiguration().screenLayout &
|
||||||
|
Configuration.SCREENLAYOUT_SIZE_MASK) ==
|
||||||
|
4)) {
|
||||||
|
FragmentManager fragmentManager = activity.getFragmentManager();
|
||||||
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||||
|
DetailsFragment fragment = new DetailsFragment();
|
||||||
|
fragmentTransaction.replace(R.id.details, fragment);
|
||||||
|
|
||||||
|
fragmentTransaction.commit();
|
||||||
|
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable("city", mDataset.get(position));
|
||||||
|
fragment.setArguments(bundle);
|
||||||
|
} else {
|
||||||
|
Intent intent = new Intent(c, DetailsActivity.class);
|
||||||
|
intent.putExtra("city", mDataset.get(position));
|
||||||
|
c.startActivity(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,7 +32,7 @@ public class ForecastAdapter extends RecyclerView.Adapter<ForecastAdapter.ViewHo
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ForecastAdapter.ViewHolder holder, int position) {
|
public void onBindViewHolder(ForecastAdapter.ViewHolder holder, int position) {
|
||||||
ForecastWeather fw = this.forecast.getList().get(position);
|
ForecastWeather fw = this.forecast.getList().get(position);
|
||||||
// MARCHE PAS
|
|
||||||
Date date = new Date((long) fw.getDt() * 1000);
|
Date date = new Date((long) fw.getDt() * 1000);
|
||||||
DateFormat format = new SimpleDateFormat("EEEE");
|
DateFormat format = new SimpleDateFormat("EEEE");
|
||||||
String finalDay = format.format(date);
|
String finalDay = format.format(date);
|
||||||
|
@ -8,11 +8,11 @@ import retrofit.http.Query;
|
|||||||
|
|
||||||
public class WeatherApis {
|
public class WeatherApis {
|
||||||
public interface WeatherLocationApi {
|
public interface WeatherLocationApi {
|
||||||
@GET("/data/2.5/weather")
|
@GET("/data/2.5/weather?units=metric")
|
||||||
void locationWeather(@Query("q") String location, @Query("lang") String lang, Callback<City> cb);
|
void locationWeather(@Query("q") String location, @Query("lang") String lang, Callback<City> cb);
|
||||||
}
|
}
|
||||||
public interface WeatherCityApi {
|
public interface WeatherCityApi {
|
||||||
@GET("/data/2.5/weather")
|
@GET("/data/2.5/weather?units=metric")
|
||||||
void cityWeather(@Query("id") int city, @Query("lang") String lang, Callback<City> cb);
|
void cityWeather(@Query("id") int city, @Query("lang") String lang, Callback<City> cb);
|
||||||
}
|
}
|
||||||
public interface WeatherDailyForecastApi {
|
public interface WeatherDailyForecastApi {
|
||||||
|
@ -4,9 +4,7 @@ import android.app.Activity;
|
|||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
@ -53,15 +51,8 @@ public class CitiesListFragment extends Fragment {
|
|||||||
private void handleView() {
|
private void handleView() {
|
||||||
saveUserCountry();
|
saveUserCountry();
|
||||||
|
|
||||||
// Google way to test is tablet
|
|
||||||
boolean isTablet = ((this.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE);
|
|
||||||
|
|
||||||
RecyclerView.LayoutManager layoutManager;
|
RecyclerView.LayoutManager layoutManager;
|
||||||
if (isTablet) {
|
layoutManager = new LinearLayoutManager(mActivity);
|
||||||
layoutManager = new GridLayoutManager(mActivity, 2);
|
|
||||||
} else {
|
|
||||||
layoutManager = new LinearLayoutManager(mActivity);
|
|
||||||
}
|
|
||||||
|
|
||||||
mRecyclerView.setLayoutManager(layoutManager);
|
mRecyclerView.setLayoutManager(layoutManager);
|
||||||
mRecyclerView.setHasFixedSize(true);
|
mRecyclerView.setHasFixedSize(true);
|
||||||
@ -71,7 +62,7 @@ public class CitiesListFragment extends Fragment {
|
|||||||
CityDAO dao = CityDAO.getInstance(mActivity);
|
CityDAO dao = CityDAO.getInstance(mActivity);
|
||||||
cities = dao.getAllCities();
|
cities = dao.getAllCities();
|
||||||
|
|
||||||
RecyclerView.Adapter mAdapter = new CitiesAdapter(cities, mActivity);
|
RecyclerView.Adapter mAdapter = new CitiesAdapter(cities, mActivity, this.getActivity());
|
||||||
mRecyclerView.setAdapter(mAdapter);
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
fab.attachToRecyclerView(mRecyclerView);
|
fab.attachToRecyclerView(mRecyclerView);
|
||||||
|
@ -38,7 +38,17 @@ public class DetailsFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
final View fragView = inflater.inflate(R.layout.details_fragment, null, false);
|
final View fragView = inflater.inflate(R.layout.details_fragment, null, false);
|
||||||
String cityName = getActivity().getIntent().getExtras().getString("city_name");
|
String cityName = null;
|
||||||
|
City city = null;
|
||||||
|
if (this.getArguments() != null) {
|
||||||
|
Bundle bundle = this.getArguments();
|
||||||
|
city = bundle.getParcelable("city");
|
||||||
|
} else {
|
||||||
|
cityName = getActivity().getIntent().getExtras().getString("city_name");
|
||||||
|
if (cityName == null) {
|
||||||
|
city = getActivity().getIntent().getExtras().getParcelable("city");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WeatherAdapters adapters = new WeatherAdapters();
|
WeatherAdapters adapters = new WeatherAdapters();
|
||||||
final Forecast[] f = {null};
|
final Forecast[] f = {null};
|
||||||
@ -81,7 +91,6 @@ public class DetailsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
City city = getActivity().getIntent().getExtras().getParcelable("city");
|
|
||||||
cityName = city.getName();
|
cityName = city.getName();
|
||||||
isFav = dao.getCity(city.getCityIdentifier()) != null;
|
isFav = dao.getCity(city.getCityIdentifier()) != null;
|
||||||
WeatherApis.WeatherDailyForecastApi s = adapters.getWeatherForecastAdapter();
|
WeatherApis.WeatherDailyForecastApi s = adapters.getWeatherForecastAdapter();
|
||||||
|
@ -1,16 +1,25 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout
|
||||||
|
android:id="@+id/main"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/cities_list_frag"
|
android:id="@+id/cities_list_frag"
|
||||||
android:name="com.amine.myterio.app.fragments.CitiesListFragment"
|
android:name="com.amine.myterio.app.fragments.CitiesListFragment"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight=".4"
|
||||||
tools:layout="@layout/cities_list_fragment"/>
|
tools:layout="@layout/cities_list_fragment"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/details"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_weight=".6"
|
||||||
|
android:orientation="horizontal"></LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentStart="true"/>
|
android:layout_alignParentStart="true"/>
|
||||||
|
|
||||||
<com.melnykov.fab.FloatingActionButton
|
<com.melnykov.fab.x
|
||||||
android:id="@+id/fab"
|
android:id="@+id/fab"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<SearchView
|
<SearchView
|
||||||
android:id="@+id/searchView"
|
android:id="@+id/searchView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="100dp"
|
android:layout_height="100dp"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<SearchView
|
<SearchView
|
||||||
android:id="@+id/searchView"
|
android:id="@+id/searchView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<SearchView
|
<SearchView
|
||||||
android:id="@+id/searchView"
|
android:id="@+id/searchView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
@ -1,16 +1,25 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout
|
||||||
|
android:id="@+id/main"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/cities_list_frag"
|
android:id="@+id/cities_list_frag"
|
||||||
android:name="com.amine.myterio.app.fragments.CitiesListFragment"
|
android:name="com.amine.myterio.app.fragments.CitiesListFragment"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight=".4"
|
||||||
tools:layout="@layout/cities_list_fragment"/>
|
tools:layout="@layout/cities_list_fragment"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/details"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_weight=".6"
|
||||||
|
android:orientation="horizontal"></LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<SearchView
|
<SearchView
|
||||||
android:id="@+id/searchView"
|
android:id="@+id/searchView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<SearchView
|
<SearchView
|
||||||
android:id="@+id/searchView"
|
android:id="@+id/searchView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
<string name="app_name">Myterio</string>
|
<string name="app_name">Myterio</string>
|
||||||
<string name="hello_world">Hello world!</string>
|
<string name="hello_world">Hello world!</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="title_activity_search">SearchActivity</string>
|
<string name="title_activity_search">Search</string>
|
||||||
<string name="title_activity_details">DetailsActivity</string>
|
<string name="title_activity_details">Details</string>
|
||||||
<string name="weather_not_available">This location dosn\'t have any weather.</string>
|
<string name="weather_not_available">This location dosn\'t have any weather.</string>
|
||||||
<string name="weather_get_error">Can\'t get the weather from the API.</string>
|
<string name="weather_get_error">Can\'t get the weather from the API.</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name" translatable="false">Myterio</string>
|
<string name="app_name">Myterio</string>
|
||||||
<string name="hello_world">Hello world!</string>
|
<string name="hello_world">Hello world!</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Paramètres</string>
|
||||||
<string name="title_activity_search" translatable="false">SearchActivity</string>
|
<string name="title_activity_search">Rechercher</string>
|
||||||
<string name="title_activity_details" translatable="false">DetailsActivity</string>
|
<string name="title_activity_details">Détails</string>
|
||||||
<string name="weather_not_available">Pas de prévisions pour cette ville.</string>
|
<string name="weather_not_available">Pas de prévisions pour cette ville.</string>
|
||||||
<string name="weather_get_error">Erreur lors de la récupération des prévisions</string>
|
<string name="weather_get_error">Erreur lors de la récupération des prévisions</string>
|
||||||
<string name="message_remove_from_favs">Voulez-vous vraiment supprimer cette ville ?</string>
|
<string name="message_remove_from_favs">Voulez-vous vraiment supprimer cette ville ?</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user