Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 51010fa

Browse files
author
Sabari
committed
base api service classes added.
1 parent 1ef0607 commit 51010fa

File tree

17 files changed

+160
-29
lines changed

17 files changed

+160
-29
lines changed

‎app/build.gradle‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ dependencies {
7373
annotationProcessor 'com.google.dagger:dagger-android-processor:2.16'
7474
annotationProcessor 'com.google.dagger:dagger-compiler:2.16'
7575

76+
// Auto value dependencies
77+
compileOnly 'com.google.auto.value:auto-value:1.5.2'
78+
annotationProcessor 'com.google.auto.value:auto-value:1.5.2'
79+
api 'com.ryanharter.auto.value:auto-value-parcel-adapter:0.2.5'
80+
annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
81+
82+
// Moshi dependencies
83+
api 'com.squareup.moshi:moshi:1.5.0'
84+
annotationProcessor 'com.ryanharter.auto.value:auto-value-moshi:0.4.4'
85+
compileOnly 'com.ryanharter.auto.value:auto-value-moshi-annotations:0.4.4'
86+
7687
testImplementation 'junit:junit:4.12'
7788
androidTestImplementation 'com.android.support.test:runner:1.0.2'
7889
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

‎app/src/main/AndroidManifest.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<uses-permission android:name="android.permission.INTERNET" />
66

77
<application
8-
android:name=".StackAndroidApp"
8+
android:name=".StackQueryApp"
99
android:allowBackup="true"
1010
android:icon="@mipmap/ic_launcher"
1111
android:label="@string/app_name"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.nathansdev.stack;
2+
3+
import android.app.Application;
4+
import android.content.Context;
5+
import android.content.SharedPreferences;
6+
7+
/**
8+
* Application preferences backed by shared preference.
9+
*/
10+
public class AppPreferences {
11+
private static final String PREFS_NAME = "app-prefs";
12+
private final SharedPreferences prefs;
13+
14+
public AppPreferences(Application app) {
15+
this.prefs = app.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
16+
}
17+
}

‎app/src/main/java/com/nathansdev/stack/StackAndroidApp.java‎ renamed to ‎app/src/main/java/com/nathansdev/stack/StackQueryApp.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import dagger.android.HasActivityInjector;
1515
import timber.log.Timber;
1616

17-
public class StackAndroidApp extends Application implements HasActivityInjector {
17+
public class StackQueryApp extends Application implements HasActivityInjector {
1818
@Inject
1919
DispatchingAndroidInjector<Activity> activityDispatchingAndroidInjector;
2020

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.nathansdev.stack.adapter;
2+
3+
import android.support.annotation.NonNull;
4+
import android.support.v7.widget.RecyclerView;
5+
import android.view.ViewGroup;
6+
7+
public class QuestionsAdapter extends RecyclerView.Adapter {
8+
@NonNull
9+
@Override
10+
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
11+
return null;
12+
}
13+
14+
@Override
15+
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
16+
17+
}
18+
19+
@Override
20+
public int getItemCount() {
21+
return 0;
22+
}
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.nathansdev.stack.data.api;
2+
3+
import com.nathansdev.stack.BuildConfig;
4+
5+
import okhttp3.OkHttpClient;
6+
import okhttp3.logging.HttpLoggingInterceptor;
7+
import retrofit2.Retrofit;
8+
import retrofit2.converter.moshi.MoshiConverterFactory;
9+
10+
public class RetrofitClient {
11+
private static Retrofit retrofit;
12+
private static final String BASE_URL = "https://api.stackexchange.com";
13+
14+
public static Retrofit getRetrofitInstance() {
15+
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
16+
if (BuildConfig.DEBUG) {
17+
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
18+
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
19+
httpClient.addInterceptor(loggingInterceptor);
20+
}
21+
if (retrofit == null) {
22+
retrofit = new Retrofit.Builder()
23+
.baseUrl(BASE_URL)
24+
.addConverterFactory(MoshiConverterFactory.create())
25+
.client(httpClient.build())
26+
.build();
27+
}
28+
return retrofit;
29+
}
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.nathansdev.stack.data.api;
2+
3+
public interface StackExchangeApi {
4+
String API_V1_QUESTIONS_JSON = "/api/v1/events/search.json";
5+
String SORT = "sort";
6+
String ORDER = "order";
7+
String VOTES = "votes";
8+
String ACTIVITY = "activity";
9+
String HOT = "hot";
10+
String WEEK = "week";
11+
String MONTH = "month";
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.nathansdev.stack.data.model;
2+
3+
import android.os.Parcelable;
4+
5+
import com.google.auto.value.AutoValue;
6+
7+
@AutoValue
8+
public abstract class Owner implements Parcelable {
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.nathansdev.stack.data.model;
2+
3+
import android.os.Parcelable;
4+
5+
import com.google.auto.value.AutoValue;
6+
7+
@AutoValue
8+
public abstract class Question implements Parcelable {
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.nathansdev.stack.data.model;
2+
3+
import android.os.Parcelable;
4+
5+
import com.google.auto.value.AutoValue;
6+
7+
@AutoValue
8+
public abstract class QuestionsResponse implements Parcelable {
9+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /