Skip to content

Commit 262fb37

Browse files
Aryan Dhankar
0 parents  commit 262fb37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1005
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

.idea/compiler.xml

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.3"
6+
defaultConfig {
7+
applicationId "com.demotrying.elite_novice.retrofitwithviewmodel"
8+
minSdkVersion 16
9+
targetSdkVersion 25
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
jackOptions {
14+
enabled true
15+
}
16+
compileOptions {
17+
sourceCompatibility JavaVersion.VERSION_1_8
18+
targetCompatibility JavaVersion.VERSION_1_8
19+
}
20+
21+
}
22+
buildTypes {
23+
release {
24+
minifyEnabled false
25+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26+
}
27+
}
28+
}
29+
30+
dependencies {
31+
compile fileTree(dir: 'libs', include: ['*.jar'])
32+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
33+
exclude group: 'com.android.support', module: 'support-annotations'
34+
})
35+
compile 'com.android.support:appcompat-v7:25.3.1'
36+
compile 'com.android.support.constraint:constraint-layout:1.0.2'
37+
testCompile 'junit:junit:4.12'
38+
compile "android.arch.lifecycle:runtime:1.0.0-alpha1"
39+
compile "android.arch.lifecycle:extensions:1.0.0-alpha1"
40+
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"
41+
compile 'com.squareup.retrofit2:retrofit:2.1.0'
42+
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
43+
compile 'io.reactivex.rxjava2:rxjava:2.0.1'
44+
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
45+
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
46+
47+
}

app/proguard-rules.pro

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in D:\sdk1/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.demotrying.elite_novice.retrofitwithviewmodel;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.demotrying.elite_novice.retrofitwithviewmodel", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.demotrying.elite_novice.retrofitwithviewmodel">
4+
<uses-permission android:name="android.permission.INTERNET"/>
5+
<application
6+
android:name=".AppController"
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
<activity android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.demotrying.elite_novice.retrofitwithviewmodel;
2+
3+
import android.app.Application;
4+
5+
import com.demotrying.elite_novice.retrofitwithviewmodel.adapter.DataAdapter;
6+
import com.demotrying.elite_novice.retrofitwithviewmodel.network.RequestInterface;
7+
import com.google.gson.Gson;
8+
import com.google.gson.GsonBuilder;
9+
10+
import java.util.List;
11+
12+
import retrofit2.Retrofit;
13+
import retrofit2.converter.gson.GsonConverterFactory;
14+
15+
public class AppController extends Application {
16+
private static AppController mInstance;
17+
String BASE_URL="http://api.football-data.org/";
18+
RequestInterface requestInterface;
19+
@Override
20+
public void onCreate() {
21+
super.onCreate();
22+
mInstance=this;
23+
24+
Gson gson = new GsonBuilder().registerTypeAdapter(List.class, new DataAdapter(getApplicationContext())).create();
25+
26+
requestInterface = new Retrofit.Builder()
27+
.baseUrl(BASE_URL)
28+
.addConverterFactory(GsonConverterFactory.create(gson))
29+
.build().create(RequestInterface.class);
30+
31+
32+
}
33+
public RequestInterface getInterface(){
34+
return requestInterface;
35+
}
36+
public static synchronized AppController getInstance() {
37+
return mInstance;
38+
}
39+
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.demotrying.elite_novice.retrofitwithviewmodel;
2+
3+
import android.arch.lifecycle.LiveData;
4+
import android.arch.lifecycle.MutableLiveData;
5+
import android.arch.lifecycle.ViewModel;
6+
7+
import com.demotrying.elite_novice.retrofitwithviewmodel.model.Fixtures;
8+
import com.demotrying.elite_novice.retrofitwithviewmodel.network.RequestInterface;
9+
10+
import java.util.List;
11+
12+
import retrofit2.Call;
13+
import retrofit2.Callback;
14+
import retrofit2.Response;
15+
16+
17+
public class GetData extends ViewModel {
18+
private MutableLiveData<List<Fixtures>> fixtures;
19+
AppController Obj;
20+
public LiveData<List<Fixtures>> getUsers() {
21+
if (fixtures == null) {
22+
fixtures = new MutableLiveData<List<Fixtures>>();
23+
loadUsers();
24+
}
25+
return fixtures;
26+
}
27+
private void loadUsers() {
28+
// do async operation to fetch users
29+
Obj=AppController.getInstance();
30+
RequestInterface requestInterface=Obj.getInterface();
31+
Call<List<Fixtures>> call =requestInterface.fixtures();
32+
call.enqueue(new Callback<List<Fixtures>>() {
33+
@Override
34+
public void onResponse(Call<List<Fixtures>> call, Response<List<Fixtures>> response) {
35+
List<Fixtures> studentData = response.body();
36+
fixtures.setValue(studentData);
37+
}
38+
39+
@Override
40+
public void onFailure(Call<List<Fixtures>> call, Throwable t) {
41+
42+
}
43+
});
44+
}
45+
}

0 commit comments

Comments
 (0)