Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wimsonevel committed Jul 22, 2016
0 parents commit 9bf8d3b
Show file tree
Hide file tree
Showing 58 changed files with 1,978 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
36 changes: 36 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "example.wim.androidretrofit"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"


buildConfigField("String", "BASE_URL", "\"http://ibacor.com/\"")
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'

compile 'com.squareup.picasso:picasso:2.5.2'

}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/docotel/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package example.wim.androidretrofit;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
31 changes: 31 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.wim.androidretrofit">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".MovieActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait" />

<activity android:name=".ShowtimeActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait" />

</application>

</manifest>
116 changes: 116 additions & 0 deletions app/src/main/java/example/wim/androidretrofit/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package example.wim.androidretrofit;

import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import java.net.SocketTimeoutException;

import example.wim.androidretrofit.adapter.CityListAdapter;
import example.wim.androidretrofit.listener.RecyclerViewItemClickListener;
import example.wim.androidretrofit.model.City;
import example.wim.androidretrofit.service.ApiService;
import example.wim.androidretrofit.util.DividerItemDecoration;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity implements RecyclerViewItemClickListener {

private RecyclerView rvCity;
private SwipeRefreshLayout swipeRefreshLayout;

private LinearLayoutManager linearLayoutManager;
private CityListAdapter cityListAdapter;

private ApiService apiService;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

rvCity = (RecyclerView) findViewById(R.id.rv_city);
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);

linearLayoutManager = new LinearLayoutManager(this);
cityListAdapter = new CityListAdapter(this);
cityListAdapter.setRecyclerViewItemClickListener(this);

rvCity.setLayoutManager(linearLayoutManager);
rvCity.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
rvCity.setAdapter(cityListAdapter);

swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshData();
}
});

loadData();
}

private void loadData(){
if (swipeRefreshLayout != null)
swipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(true);
}
});

apiService = new ApiService();
apiService.getCityList(new Callback() {
@Override
public void onResponse(Call call, Response response) {
City city = (City) response.body();

if(city != null) {
cityListAdapter.addAll(city.getData());
Log.i("STATUS", city.getStatus());
}else{
Toast.makeText(MainActivity.this, "No Data!", Toast.LENGTH_LONG).show();
}

if (swipeRefreshLayout != null)
swipeRefreshLayout.setRefreshing(false);
}

@Override
public void onFailure(Call call, Throwable t) {
if(t instanceof SocketTimeoutException) {
Toast.makeText(MainActivity.this, "Request Timeout. Please try again!", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(MainActivity.this, "Connection Error!", Toast.LENGTH_LONG).show();
}
Log.i("FAILURE", t.toString());

if (swipeRefreshLayout != null)
swipeRefreshLayout.setRefreshing(false);
}
});
}

private void refreshData(){
new Handler().post(new Runnable() {
@Override
public void run() {
cityListAdapter.clear();
loadData();
}
});
}

@Override
public void onItemClick(int position, View view) {
MovieActivity.start(this, cityListAdapter.getItem(position).getId());
}
}
Loading

0 comments on commit 9bf8d3b

Please sign in to comment.