diff --git a/.idea/misc.xml b/.idea/misc.xml
index fc2f074..812be18 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -22,31 +22,4 @@
-
-
-
-
- 1.6
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/app.iml b/app/app.iml
index 7b13054..426fa7b 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -85,8 +85,8 @@
-
+
diff --git a/app/build.gradle b/app/build.gradle
index 9a6aab6..cd9af95 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -14,7 +14,7 @@ repositories {
android {
compileSdkVersion 22
- buildToolsVersion "23.0.0 rc2"
+ buildToolsVersion "23.0.0 rc3"
defaultConfig {
applicationId "com.amine.myterio.app"
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 b1b4a3d..45ba3cf 100644
--- a/app/src/main/java/com/amine/myterio/app/MainActivity.java
+++ b/app/src/main/java/com/amine/myterio/app/MainActivity.java
@@ -1,24 +1,9 @@
package com.amine.myterio.app;
-import android.content.Context;
-import android.content.Intent;
-import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.GridLayoutManager;
-import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.RecyclerView;
-import android.telephony.TelephonyManager;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.View;
-import com.amine.myterio.app.adapters.CitiesAdapter;
-import com.amine.myterio.app.config.Config;
-import com.amine.myterio.app.db.CityDAO;
-import com.amine.myterio.app.model.City;
-import com.melnykov.fab.FloatingActionButton;
-
-import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
@@ -26,62 +11,9 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- handleView();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- handleView();
- }
-
- private void saveUserCountry() {
- TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
- Config.country = tm.getSimCountryIso().toLowerCase();
- if (Config.country == null || Config.country.equals("") || Config.country.isEmpty())
- Config.country = MainActivity.this.getResources().getConfiguration().locale.getCountry().toLowerCase();
- }
-
- private void handleView() {
setContentView(R.layout.activity_main);
- RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.list);
- saveUserCountry();
-
- // Google way to test is tablet
- boolean isTablet = ((this.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE);
-
- final RecyclerView.LayoutManager layoutManager;
- if (isTablet) {
- layoutManager = new GridLayoutManager(this, 2);
- }
- else {
- layoutManager = new LinearLayoutManager(this);
- }
-
- mRecyclerView.setLayoutManager(layoutManager);
- mRecyclerView.setHasFixedSize(true);
-
- ArrayList cities;
-
- CityDAO dao = CityDAO.getInstance(this);
- cities = dao.getAllCities();
-
- RecyclerView.Adapter mAdapter = new CitiesAdapter(cities, this);
- mRecyclerView.setAdapter(mAdapter);
-
- 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);
- }
- });
}
-
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
diff --git a/app/src/main/java/com/amine/myterio/app/fragments/CitiesListFragment.java b/app/src/main/java/com/amine/myterio/app/fragments/CitiesListFragment.java
new file mode 100644
index 0000000..1cafa83
--- /dev/null
+++ b/app/src/main/java/com/amine/myterio/app/fragments/CitiesListFragment.java
@@ -0,0 +1,95 @@
+package com.amine.myterio.app.fragments;
+
+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;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import com.amine.myterio.app.R;
+import com.amine.myterio.app.SearchActivity;
+import com.amine.myterio.app.adapters.CitiesAdapter;
+import com.amine.myterio.app.config.Config;
+import com.amine.myterio.app.db.CityDAO;
+import com.amine.myterio.app.model.City;
+import com.melnykov.fab.FloatingActionButton;
+
+import java.util.ArrayList;
+
+public class CitiesListFragment extends Fragment {
+
+ RecyclerView mRecyclerView;
+ FloatingActionButton fab;
+ private Activity mActivity;
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ mActivity = activity;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View fragView = inflater.inflate(R.layout.cities_list_fragment, null, false);
+ mRecyclerView = (RecyclerView) fragView.findViewById(R.id.list);
+ fab = (FloatingActionButton) fragView.findViewById(R.id.fab);
+ handleView();
+ return fragView;
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ handleView();
+ }
+
+ 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);
+
+ ArrayList cities;
+
+ CityDAO dao = CityDAO.getInstance(mActivity);
+ cities = dao.getAllCities();
+
+ RecyclerView.Adapter mAdapter = new CitiesAdapter(cities, mActivity);
+ mRecyclerView.setAdapter(mAdapter);
+
+ fab.attachToRecyclerView(mRecyclerView);
+
+ fab.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent(mActivity, SearchActivity.class);
+ startActivity(intent);
+ }
+ });
+ }
+
+
+ private void saveUserCountry() {
+ TelephonyManager tm = (TelephonyManager) mActivity.getSystemService(Context.TELEPHONY_SERVICE);
+ Config.country = tm.getSimCountryIso().toLowerCase();
+ if (Config.country == null || Config.country.equals("") || Config.country.isEmpty())
+ Config.country = mActivity.getResources().getConfiguration().locale.getCountry().toLowerCase();
+ }
+}
diff --git a/app/src/main/res/layout-large/activity_main.xml b/app/src/main/res/layout-large/activity_main.xml
index 5f346aa..ab6a4e6 100644
--- a/app/src/main/res/layout-large/activity_main.xml
+++ b/app/src/main/res/layout-large/activity_main.xml
@@ -1,25 +1,16 @@
-
-
-
-
+ android:layout_weight="1"
+ tools:layout="@layout/cities_list_fragment"/>
-
+
diff --git a/app/src/main/res/layout-large/cities_list_fragment.xml b/app/src/main/res/layout-large/cities_list_fragment.xml
new file mode 100644
index 0000000..5f346aa
--- /dev/null
+++ b/app/src/main/res/layout-large/cities_list_fragment.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout-normal/activity_main.xml b/app/src/main/res/layout-normal/activity_main.xml
index 5f346aa..ab6a4e6 100644
--- a/app/src/main/res/layout-normal/activity_main.xml
+++ b/app/src/main/res/layout-normal/activity_main.xml
@@ -1,25 +1,16 @@
-
-
-
-
+ android:layout_weight="1"
+ tools:layout="@layout/cities_list_fragment"/>
-
+
diff --git a/app/src/main/res/layout-normal/cities_list_fragment.xml b/app/src/main/res/layout-normal/cities_list_fragment.xml
new file mode 100644
index 0000000..5f346aa
--- /dev/null
+++ b/app/src/main/res/layout-normal/cities_list_fragment.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout-small/activity_main.xml b/app/src/main/res/layout-small/activity_main.xml
index 5f346aa..ab6a4e6 100644
--- a/app/src/main/res/layout-small/activity_main.xml
+++ b/app/src/main/res/layout-small/activity_main.xml
@@ -1,25 +1,16 @@
-
-
-
-
+ android:layout_weight="1"
+ tools:layout="@layout/cities_list_fragment"/>
-
+
diff --git a/app/src/main/res/layout-small/cities_list_fragment.xml b/app/src/main/res/layout-small/cities_list_fragment.xml
new file mode 100644
index 0000000..5f346aa
--- /dev/null
+++ b/app/src/main/res/layout-small/cities_list_fragment.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout-xlarge/activity_main.xml b/app/src/main/res/layout-xlarge/activity_main.xml
index 5f346aa..ab6a4e6 100644
--- a/app/src/main/res/layout-xlarge/activity_main.xml
+++ b/app/src/main/res/layout-xlarge/activity_main.xml
@@ -1,25 +1,16 @@
-
-
-
-
+ android:layout_weight="1"
+ tools:layout="@layout/cities_list_fragment"/>
-
+
diff --git a/app/src/main/res/layout-xlarge/cities_list_fragment.xml b/app/src/main/res/layout-xlarge/cities_list_fragment.xml
new file mode 100644
index 0000000..5f346aa
--- /dev/null
+++ b/app/src/main/res/layout-xlarge/cities_list_fragment.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 4d4ab3e..ab6a4e6 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,25 +1,16 @@
-
-
-
-
+ android:layout_weight="1"
+ tools:layout="@layout/cities_list_fragment"/>
-
+
diff --git a/app/src/main/res/layout/cities_list_fragment.xml b/app/src/main/res/layout/cities_list_fragment.xml
new file mode 100644
index 0000000..5f346aa
--- /dev/null
+++ b/app/src/main/res/layout/cities_list_fragment.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+