This commit is contained in:
aminecmi 2015-07-12 17:28:29 +02:00
parent 896978ac28
commit 550a3e8fce
15 changed files with 262 additions and 182 deletions

View File

@ -22,31 +22,4 @@
<component name="ProjectType"> <component name="ProjectType">
<option name="id" value="Android" /> <option name="id" value="Android" />
</component> </component>
<component name="masterDetails">
<states>
<state key="ProjectJDKs.UI">
<settings>
<last-edited>1.6</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ScopeChooserConfigurable.UI">
<settings>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project> </project>

View File

@ -85,8 +85,8 @@
</content> </content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" /> <orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" /> <orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.0" level="project" /> <orderEntry type="library" exported="" name="recyclerview-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" /> <orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" /> <orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />

View File

@ -14,7 +14,7 @@ repositories {
android { android {
compileSdkVersion 22 compileSdkVersion 22
buildToolsVersion "23.0.0 rc2" buildToolsVersion "23.0.0 rc3"
defaultConfig { defaultConfig {
applicationId "com.amine.myterio.app" applicationId "com.amine.myterio.app"

View File

@ -1,24 +1,9 @@
package com.amine.myterio.app; package com.amine.myterio.app;
import android.content.Context;
import android.content.Intent;
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.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.Menu;
import android.view.MenuItem; 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 { public class MainActivity extends AppCompatActivity {
@ -26,61 +11,8 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(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); 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<City> 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 @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {

View File

@ -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<City> 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();
}
}

View File

@ -1,25 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout 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">
<android.support.v7.widget.RecyclerView <fragment
android:id="@+id/list" android:id="@+id/cities_list_frag"
android:layout_width="fill_parent" android:name="com.amine.myterio.app.fragments.CitiesListFragment"
android:layout_width="0dp"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_alignParentLeft="true" android:layout_weight="1"
android:layout_alignParentStart="true"/> tools:layout="@layout/cities_list_fragment"/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@mipmap/ic_search_white_24dp"/>
</RelativeLayout> </LinearLayout>

View File

@ -0,0 +1,25 @@
<RelativeLayout 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"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@mipmap/ic_search_white_24dp"/>
</RelativeLayout>

View File

@ -1,25 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout 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">
<android.support.v7.widget.RecyclerView <fragment
android:id="@+id/list" android:id="@+id/cities_list_frag"
android:layout_width="fill_parent" android:name="com.amine.myterio.app.fragments.CitiesListFragment"
android:layout_width="0dp"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_alignParentLeft="true" android:layout_weight="1"
android:layout_alignParentStart="true"/> tools:layout="@layout/cities_list_fragment"/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@mipmap/ic_search_white_24dp"/>
</RelativeLayout> </LinearLayout>

View File

@ -0,0 +1,25 @@
<RelativeLayout 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"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@mipmap/ic_search_white_24dp"/>
</RelativeLayout>

View File

@ -1,25 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout 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">
<android.support.v7.widget.RecyclerView <fragment
android:id="@+id/list" android:id="@+id/cities_list_frag"
android:layout_width="fill_parent" android:name="com.amine.myterio.app.fragments.CitiesListFragment"
android:layout_width="0dp"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_alignParentLeft="true" android:layout_weight="1"
android:layout_alignParentStart="true"/> tools:layout="@layout/cities_list_fragment"/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@mipmap/ic_search_white_24dp"/>
</RelativeLayout> </LinearLayout>

View File

@ -0,0 +1,25 @@
<RelativeLayout 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"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@mipmap/ic_search_white_24dp"/>
</RelativeLayout>

View File

@ -1,25 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout 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">
<android.support.v7.widget.RecyclerView <fragment
android:id="@+id/list" android:id="@+id/cities_list_frag"
android:layout_width="fill_parent" android:name="com.amine.myterio.app.fragments.CitiesListFragment"
android:layout_width="0dp"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_alignParentLeft="true" android:layout_weight="1"
android:layout_alignParentStart="true"/> tools:layout="@layout/cities_list_fragment"/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@mipmap/ic_search_white_24dp"/>
</RelativeLayout> </LinearLayout>

View File

@ -0,0 +1,25 @@
<RelativeLayout 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"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@mipmap/ic_search_white_24dp"/>
</RelativeLayout>

View File

@ -1,25 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout 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">
<android.support.v7.widget.RecyclerView <fragment
android:layout_width="fill_parent" android:id="@+id/cities_list_frag"
android:name="com.amine.myterio.app.fragments.CitiesListFragment"
android:layout_width="0dp"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:id="@+id/list" android:layout_weight="1"
android:layout_alignParentLeft="true" tools:layout="@layout/cities_list_fragment"/>
android:layout_alignParentStart="true"/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@mipmap/ic_search_white_24dp"/>
</RelativeLayout> </LinearLayout>

View File

@ -0,0 +1,25 @@
<RelativeLayout 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"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@mipmap/ic_search_white_24dp"/>
</RelativeLayout>