This commit is contained in:
aminecmi 2015-07-15 13:46:45 +02:00
parent 60aa5a9c98
commit ee03c91cb9
16 changed files with 86 additions and 61 deletions

View File

@ -1,12 +1,9 @@
package com.amine.myterio.app;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@ -15,25 +12,6 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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

View File

@ -1,8 +1,13 @@
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.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
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.config.Config;
import com.amine.myterio.app.db.CityDAO;
import com.amine.myterio.app.fragments.DetailsFragment;
import com.amine.myterio.app.model.City;
import retrofit.Callback;
import retrofit.RetrofitError;
@ -27,10 +33,12 @@ import java.util.ArrayList;
public class CitiesAdapter extends RecyclerView.Adapter<CitiesAdapter.ViewHolder> {
private ArrayList<City> mDataset;
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.c = c;
this.activity = a;
}
@Override
@ -102,12 +110,33 @@ public class CitiesAdapter extends RecyclerView.Adapter<CitiesAdapter.ViewHolder
@Override
public void onClick(View v) {
// Go to details activity
final int position = getLayoutPosition();
int a = (c.getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK);
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
public boolean onLongClick(View v) {

View File

@ -32,7 +32,7 @@ public class ForecastAdapter extends RecyclerView.Adapter<ForecastAdapter.ViewHo
@Override
public void onBindViewHolder(ForecastAdapter.ViewHolder holder, int position) {
ForecastWeather fw = this.forecast.getList().get(position);
// MARCHE PAS
Date date = new Date((long) fw.getDt() * 1000);
DateFormat format = new SimpleDateFormat("EEEE");
String finalDay = format.format(date);

View File

@ -8,11 +8,11 @@ import retrofit.http.Query;
public class WeatherApis {
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);
}
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);
}
public interface WeatherDailyForecastApi {

View File

@ -4,9 +4,7 @@ import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.telephony.TelephonyManager;
@ -53,15 +51,8 @@ public class CitiesListFragment extends Fragment {
private void handleView() {
saveUserCountry();
// Google way to test is tablet
boolean isTablet = ((this.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE);
RecyclerView.LayoutManager layoutManager;
if (isTablet) {
layoutManager = new GridLayoutManager(mActivity, 2);
} else {
layoutManager = new LinearLayoutManager(mActivity);
}
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setHasFixedSize(true);
@ -71,7 +62,7 @@ public class CitiesListFragment extends Fragment {
CityDAO dao = CityDAO.getInstance(mActivity);
cities = dao.getAllCities();
RecyclerView.Adapter mAdapter = new CitiesAdapter(cities, mActivity);
RecyclerView.Adapter mAdapter = new CitiesAdapter(cities, mActivity, this.getActivity());
mRecyclerView.setAdapter(mAdapter);
fab.attachToRecyclerView(mRecyclerView);

View File

@ -38,7 +38,17 @@ public class DetailsFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
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();
final Forecast[] f = {null};
@ -81,7 +91,6 @@ public class DetailsFragment extends Fragment {
}
});
} else {
City city = getActivity().getIntent().getExtras().getParcelable("city");
cityName = city.getName();
isFav = dao.getCity(city.getCityIdentifier()) != null;
WeatherApis.WeatherDailyForecastApi s = adapters.getWeatherForecastAdapter();

View File

@ -1,4 +1,6 @@
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -9,8 +11,15 @@
android:name="com.amine.myterio.app.fragments.CitiesListFragment"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_weight=".4"
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>

View File

@ -11,7 +11,7 @@
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<com.melnykov.fab.FloatingActionButton
<com.melnykov.fab.x
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -10,7 +10,7 @@
<SearchView
android:id="@+id/searchView"
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"

View File

@ -10,7 +10,7 @@
<SearchView
android:id="@+id/searchView"
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"

View File

@ -10,7 +10,7 @@
<SearchView
android:id="@+id/searchView"
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"

View File

@ -1,4 +1,6 @@
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -9,8 +11,15 @@
android:name="com.amine.myterio.app.fragments.CitiesListFragment"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_weight=".4"
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>

View File

@ -10,7 +10,7 @@
<SearchView
android:id="@+id/searchView"
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"

View File

@ -10,7 +10,7 @@
<SearchView
android:id="@+id/searchView"
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"

View File

@ -2,8 +2,8 @@
<string name="app_name">Myterio</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="title_activity_search">SearchActivity</string>
<string name="title_activity_details">DetailsActivity</string>
<string name="title_activity_search">Search</string>
<string name="title_activity_details">Details</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="cancel">Cancel</string>

View File

@ -1,9 +1,9 @@
<resources>
<string name="app_name" translatable="false">Myterio</string>
<string name="app_name">Myterio</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="title_activity_search" translatable="false">SearchActivity</string>
<string name="title_activity_details" translatable="false">DetailsActivity</string>
<string name="action_settings">Paramètres</string>
<string name="title_activity_search">Rechercher</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_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>