Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Commit 62ed9da

Browse files
committed
update: Recycling top headline code
1 parent e40ba66 commit 62ed9da

11 files changed

Lines changed: 67 additions & 460 deletions

File tree

app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ dependencies {
3232
implementation 'androidx.core:core-ktx:1.2.0'
3333
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
3434
testImplementation 'junit:junit:4.12'
35+
36+
implementation project(':frogonewsapi')
37+
3538
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
3639
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
3740
}
Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
package com.frogobox.newsapi
22

3-
import androidx.appcompat.app.AppCompatActivity
43
import android.os.Bundle
4+
import androidx.appcompat.app.AppCompatActivity
5+
import com.frogobox.frogonewsapi.ConsumeNewsApi
6+
import com.frogobox.frogonewsapi.callback.NewsResultCallback
7+
import com.frogobox.frogonewsapi.data.response.ArticleResponse
8+
import com.frogobox.frogonewsapi.util.NewsUrl
59

610
class MainActivity : AppCompatActivity() {
711

812
override fun onCreate(savedInstanceState: Bundle?) {
913
super.onCreate(savedInstanceState)
1014
setContentView(R.layout.activity_main)
15+
16+
val consumeNewsApi = ConsumeNewsApi(NewsUrl.NEWS_API_KEY)
17+
consumeNewsApi.usingChuckInterceptor(this)
18+
consumeNewsApi.getTopHeadline(
19+
null,
20+
null,
21+
null,
22+
"id",
23+
object : NewsResultCallback<ArticleResponse> {
24+
override fun getResultData(data: ArticleResponse) {
25+
26+
}
27+
28+
override fun failedResult(statusCode: Int, errorMessage: String?) {
29+
TODO("Not yet implemented")
30+
}
31+
32+
override fun onShowProgress() {
33+
TODO("Not yet implemented")
34+
}
35+
36+
override fun onHideProgress() {
37+
TODO("Not yet implemented")
38+
}
39+
})
40+
41+
1142
}
1243
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.frogobox.frogonewsapi" />
2+
package="com.frogobox.frogonewsapi" >
3+
4+
<uses-permission android:name="android.permission.INTERNET"/>
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6+
7+
</manifest>

frogonewsapi/src/main/java/com/frogobox/frogonewsapi/ConsumeNewsApi.kt

Lines changed: 9 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -32,147 +32,7 @@ class ConsumeNewsApi(private val apiKey: String) : ConsumeNewsApiView {
3232
newsRepository.usingChuckInterceptor(context)
3333
}
3434

35-
override fun getTopHeadlineByCountry(
36-
apiKey: String,
37-
country: String,
38-
callback: NewsResultCallback<ArticleResponse>
39-
) {
40-
newsRepository.getTopHeadlineByCountry(
41-
apiKey,
42-
country,
43-
object : NewsDataSource.GetRemoteCallback<ArticleResponse> {
44-
override fun onSuccess(data: ArticleResponse) {
45-
callback.getResultData(data)
46-
}
47-
48-
override fun onFailed(statusCode: Int, errorMessage: String?) {
49-
callback.failedResult(statusCode, errorMessage)
50-
}
51-
})
52-
}
53-
54-
override fun getTopHeadlineByCountry(
55-
apiKey: String,
56-
country: String,
57-
category: String,
58-
callback: NewsResultCallback<ArticleResponse>
59-
) {
60-
newsRepository.getTopHeadlineByCountry(
61-
apiKey,
62-
country,
63-
category,
64-
object : NewsDataSource.GetRemoteCallback<ArticleResponse> {
65-
override fun onSuccess(data: ArticleResponse) {
66-
callback.getResultData(data)
67-
}
68-
69-
override fun onFailed(statusCode: Int, errorMessage: String?) {
70-
callback.failedResult(statusCode, errorMessage)
71-
}
72-
})
73-
}
74-
75-
override fun getTopHeadlineBySource(
76-
apiKey: String,
77-
sources: String,
78-
callback: NewsResultCallback<ArticleResponse>
79-
) {
80-
newsRepository.getTopHeadlineBySource(
81-
apiKey,
82-
sources,
83-
object : NewsDataSource.GetRemoteCallback<ArticleResponse> {
84-
override fun onSuccess(data: ArticleResponse) {
85-
callback.getResultData(data)
86-
}
87-
88-
override fun onFailed(statusCode: Int, errorMessage: String?) {
89-
callback.failedResult(statusCode, errorMessage)
90-
}
91-
})
92-
}
93-
94-
override fun getTopHeadlineBySource(
95-
apiKey: String,
96-
sources: String,
97-
category: String,
98-
callback: NewsResultCallback<ArticleResponse>
99-
) {
100-
newsRepository.getTopHeadlineBySource(
101-
apiKey,
102-
sources,
103-
category,
104-
object : NewsDataSource.GetRemoteCallback<ArticleResponse> {
105-
override fun onSuccess(data: ArticleResponse) {
106-
callback.getResultData(data)
107-
}
108-
109-
override fun onFailed(statusCode: Int, errorMessage: String?) {
110-
callback.failedResult(statusCode, errorMessage)
111-
}
112-
})
113-
}
114-
115-
override fun getTopHeadlineByQ(
116-
apiKey: String,
117-
q: String,
118-
callback: NewsResultCallback<ArticleResponse>
119-
) {
120-
newsRepository.getTopHeadlineByQ(
121-
apiKey,
122-
q,
123-
object : NewsDataSource.GetRemoteCallback<ArticleResponse> {
124-
override fun onSuccess(data: ArticleResponse) {
125-
callback.getResultData(data)
126-
}
127-
128-
override fun onFailed(statusCode: Int, errorMessage: String?) {
129-
callback.failedResult(statusCode, errorMessage)
130-
}
131-
})
132-
}
133-
134-
override fun getTopHeadlineByQ(
135-
apiKey: String,
136-
q: String,
137-
category: String,
138-
callback: NewsResultCallback<ArticleResponse>
139-
) {
140-
newsRepository.getTopHeadlineByQ(
141-
apiKey,
142-
q,
143-
category,
144-
object : NewsDataSource.GetRemoteCallback<ArticleResponse> {
145-
override fun onSuccess(data: ArticleResponse) {
146-
callback.getResultData(data)
147-
}
148-
149-
override fun onFailed(statusCode: Int, errorMessage: String?) {
150-
callback.failedResult(statusCode, errorMessage)
151-
}
152-
})
153-
}
154-
155-
override fun getTopHeadlineByCategory(
156-
apiKey: String,
157-
category: String,
158-
callback: NewsResultCallback<ArticleResponse>
159-
) {
160-
newsRepository.getTopHeadlineByCategory(
161-
apiKey,
162-
category,
163-
object : NewsDataSource.GetRemoteCallback<ArticleResponse> {
164-
override fun onSuccess(data: ArticleResponse) {
165-
callback.getResultData(data)
166-
}
167-
168-
override fun onFailed(statusCode: Int, errorMessage: String?) {
169-
callback.failedResult(statusCode, errorMessage)
170-
}
171-
})
172-
}
173-
17435
override fun getTopHeadline(
175-
apiKey: String,
17636
q: String?,
17737
sources: String?,
17838
category: String?,
@@ -193,6 +53,15 @@ class ConsumeNewsApi(private val apiKey: String) : ConsumeNewsApiView {
19353
override fun onFailed(statusCode: Int, errorMessage: String?) {
19454
callback.failedResult(statusCode, errorMessage)
19555
}
56+
57+
override fun onShowProgress() {
58+
callback.onShowProgress()
59+
}
60+
61+
override fun onHideProgress() {
62+
callback.onHideProgress()
63+
}
64+
19665
})
19766
}
19867
}

frogonewsapi/src/main/java/com/frogobox/frogonewsapi/ConsumeNewsApiView.kt

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,57 +26,8 @@ interface ConsumeNewsApiView {
2626
// Switch For Using Chuck Interceptor
2727
fun usingChuckInterceptor(context: Context)
2828

29-
// Get Top Headline From Country
30-
fun getTopHeadlineByCountry(
31-
apiKey: String,
32-
country: String,
33-
callback: NewsResultCallback<ArticleResponse>
34-
)
35-
36-
// Get Top Headline From Country and Category
37-
fun getTopHeadlineByCountry(
38-
apiKey: String,
39-
country: String,
40-
category: String,
41-
callback: NewsResultCallback<ArticleResponse>
42-
)
43-
44-
// Get Top Headline From Source
45-
fun getTopHeadlineBySource(
46-
apiKey: String,
47-
sources: String,
48-
callback: NewsResultCallback<ArticleResponse>
49-
)
50-
51-
// Get Top Headline From Source and Category
52-
fun getTopHeadlineBySource(
53-
apiKey: String,
54-
sources: String,
55-
category: String,
56-
callback: NewsResultCallback<ArticleResponse>
57-
)
58-
59-
// Get Top Headline From q
60-
fun getTopHeadlineByQ(apiKey: String, q: String, callback: NewsResultCallback<ArticleResponse>)
61-
62-
// Get Top Headline From q
63-
fun getTopHeadlineByQ(
64-
apiKey: String,
65-
q: String,
66-
category: String,
67-
callback: NewsResultCallback<ArticleResponse>
68-
)
69-
70-
// Get Top Headline From Category
71-
fun getTopHeadlineByCategory(
72-
apiKey: String,
73-
category: String,
74-
callback: NewsResultCallback<ArticleResponse>
75-
)
76-
7729
// Get Top Headline
7830
fun getTopHeadline(
79-
apiKey: String,
8031
q: String?,
8132
sources: String?,
8233
category: String?,

frogonewsapi/src/main/java/com/frogobox/frogonewsapi/base/BaseNewsDataSource.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ interface BaseNewsDataSource {
2626

2727
// If failed fetching data from API
2828
fun onFailed(statusCode: Int, errorMessage: String? = "")
29+
30+
// Do on subscribe
31+
fun onShowProgress()
32+
33+
// Do on Terminate
34+
fun onHideProgress()
2935
}
3036

3137
}

frogonewsapi/src/main/java/com/frogobox/frogonewsapi/callback/NewsResultCallback.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ interface NewsResultCallback<T> {
2525
// Failed Meesage
2626
fun failedResult(statusCode: Int, errorMessage: String?)
2727

28+
// Do on subscribe
29+
fun onShowProgress()
30+
31+
// Do on Terminate
32+
fun onHideProgress()
33+
2834
}

frogonewsapi/src/main/java/com/frogobox/frogonewsapi/data/model/Source.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ data class Source(
2727
@SerializedName("name")
2828
var name: String? = null,
2929

30-
@SerializedName("id")
30+
@SerializedName("description")
3131
var description: String? = null,
3232

33-
@SerializedName("id")
33+
@SerializedName("url")
3434
var url: String? = null,
3535

36-
@SerializedName("id")
36+
@SerializedName("category")
3737
var category: String? = null,
3838

39-
@SerializedName("id")
39+
@SerializedName("language")
4040
var language: String? = null,
4141

42-
@SerializedName("id")
42+
@SerializedName("country")
4343
var country: String? = null
4444

4545
)

frogonewsapi/src/main/java/com/frogobox/frogonewsapi/data/source/NewsDataSource.kt

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,54 +26,6 @@ interface NewsDataSource {
2626
// Switch For Using Chuck Interceptor
2727
fun usingChuckInterceptor(context: Context)
2828

29-
// Get Top Headline From Country
30-
fun getTopHeadlineByCountry(
31-
apiKey: String,
32-
country: String,
33-
callback: GetRemoteCallback<ArticleResponse>
34-
)
35-
36-
// Get Top Headline From Country and Category
37-
fun getTopHeadlineByCountry(
38-
apiKey: String,
39-
country: String,
40-
category: String,
41-
callback: GetRemoteCallback<ArticleResponse>
42-
)
43-
44-
// Get Top Headline From Source
45-
fun getTopHeadlineBySource(
46-
apiKey: String,
47-
sources: String,
48-
callback: GetRemoteCallback<ArticleResponse>
49-
)
50-
51-
// Get Top Headline From Source and Category
52-
fun getTopHeadlineBySource(
53-
apiKey: String,
54-
sources: String,
55-
category: String,
56-
callback: GetRemoteCallback<ArticleResponse>
57-
)
58-
59-
// Get Top Headline From q
60-
fun getTopHeadlineByQ(apiKey: String, q: String, callback: GetRemoteCallback<ArticleResponse>)
61-
62-
// Get Top Headline From q
63-
fun getTopHeadlineByQ(
64-
apiKey: String,
65-
q: String,
66-
category: String,
67-
callback: GetRemoteCallback<ArticleResponse>
68-
)
69-
70-
// Get Top Headline From Category
71-
fun getTopHeadlineByCategory(
72-
apiKey: String,
73-
category: String,
74-
callback: GetRemoteCallback<ArticleResponse>
75-
)
76-
7729
// Get Top Headline
7830
fun getTopHeadline(
7931
apiKey: String,

0 commit comments

Comments
 (0)