-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create BoardApiService.kt by Retrofit and DI
- Loading branch information
Showing
32 changed files
with
189 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/src/main/java/tw/y_studio/ptt/api/board/BoardApiService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package tw.y_studio.ptt.api.board | ||
|
||
import retrofit2.http.GET | ||
import tw.y_studio.ptt.api.model.hot_board.HotBoard | ||
|
||
interface BoardApiService { | ||
@GET("api/boards/popular") | ||
suspend fun getPopularBoard(): HotBoard | ||
} |
2 changes: 1 addition & 1 deletion
2
...ain/java/tw/y_studio/ptt/model/Comment.kt → ...java/tw/y_studio/ptt/api/model/Comment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tw.y_studio.ptt.model | ||
package tw.y_studio.ptt.api.model | ||
|
||
data class Comment( | ||
val userid: String, | ||
|
2 changes: 1 addition & 1 deletion
2
...java/tw/y_studio/ptt/model/PartialPost.kt → .../tw/y_studio/ptt/api/model/PartialPost.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tw.y_studio.ptt.model | ||
package tw.y_studio.ptt.api.model | ||
|
||
data class PartialPost( | ||
val title: String = "", | ||
|
2 changes: 1 addition & 1 deletion
2
...c/main/java/tw/y_studio/ptt/model/Post.kt → ...in/java/tw/y_studio/ptt/api/model/Post.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tw.y_studio.ptt.model | ||
package tw.y_studio.ptt.api.model | ||
|
||
data class Post( | ||
val title: String, | ||
|
2 changes: 1 addition & 1 deletion
2
...in/java/tw/y_studio/ptt/model/PostRank.kt → ...ava/tw/y_studio/ptt/api/model/PostRank.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tw.y_studio.ptt.model | ||
package tw.y_studio.ptt.api.model | ||
|
||
data class PostRank( | ||
val board: String, | ||
|
39 changes: 39 additions & 0 deletions
39
app/src/main/java/tw/y_studio/ptt/api/model/hot_board/HotBoard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package tw.y_studio.ptt.api.model.hot_board | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class HotBoard( | ||
@SerializedName("list") | ||
val list: List<Board>, | ||
@SerializedName("next_idx") | ||
val nextId: String | ||
) | ||
|
||
data class Board( | ||
@SerializedName("bid") | ||
val boardId: String, | ||
@SerializedName("brdname") | ||
val boardName: String, | ||
@SerializedName("class") | ||
val boardClass: String, | ||
@SerializedName("flag") | ||
val boardAttributes: Int, | ||
@SerializedName("last_post_time") | ||
val lastPostTime: Int, | ||
@SerializedName("moderators") | ||
val moderators: List<String>, | ||
@SerializedName("nuser") | ||
val onlineUser: Int, | ||
@SerializedName("read") | ||
val read: Boolean, | ||
@SerializedName("reason") | ||
val reason: String, | ||
@SerializedName("stat_attr") | ||
val stateAttributes: Int, | ||
@SerializedName("title") | ||
val title: String, | ||
@SerializedName("total") | ||
val totalArticles: Int, | ||
@SerializedName("type") | ||
val type: String | ||
) |
4 changes: 2 additions & 2 deletions
4
...in/java/tw/y_studio/ptt/model/HotBoard.kt → ...o/ptt/api/model/hot_board/HotBoardTemp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...va/tw/y_studio/ptt/model/HotBoardsItem.kt → .../ptt/api/model/hot_board/HotBoardsItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,42 @@ | ||
package tw.y_studio.ptt.di | ||
|
||
import okhttp3.OkHttpClient | ||
import org.koin.dsl.module | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import tw.y_studio.ptt.BuildConfig | ||
import tw.y_studio.ptt.api.PopularBoardListAPI | ||
import tw.y_studio.ptt.api.PostAPI | ||
import tw.y_studio.ptt.api.SearchBoardAPI | ||
import tw.y_studio.ptt.api.board.BoardApiService | ||
import tw.y_studio.ptt.utils.OkHttpUtils | ||
import java.util.concurrent.TimeUnit | ||
|
||
val apiModules = module { | ||
factory { PopularBoardListAPI() } | ||
factory { SearchBoardAPI() } | ||
factory { PostAPI() } | ||
single { provideOkHttpClient() } | ||
single { provideRetrofit(get()) } | ||
factory { provideBoardApiService(get()) } | ||
} | ||
|
||
private fun provideRetrofit(client: OkHttpClient): Retrofit { | ||
return Retrofit.Builder() | ||
.baseUrl(BuildConfig.develop_domain) | ||
.client(client) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
} | ||
|
||
private fun provideOkHttpClient(): OkHttpClient { | ||
return OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS) | ||
.writeTimeout(30, TimeUnit.SECONDS) | ||
.readTimeout(30, TimeUnit.SECONDS) | ||
.addInterceptor(OkHttpUtils.GzipRequestInterceptor()) // TODO: 2021/1/31 add TokenInterceptor | ||
.build() | ||
} | ||
|
||
private fun provideBoardApiService(retrofit: Retrofit): BoardApiService { | ||
return retrofit.create(BoardApiService::class.java) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package tw.y_studio.ptt.di | ||
|
||
import org.koin.dsl.module | ||
import tw.y_studio.ptt.source.remote.popular.IPopularRemoteDataSource | ||
import tw.y_studio.ptt.source.remote.popular.PopularRemoteDataSourceImpl | ||
import tw.y_studio.ptt.source.remote.board.IPopularRemoteDataSource | ||
import tw.y_studio.ptt.source.remote.board.PopularRemoteDataSourceImpl | ||
import tw.y_studio.ptt.source.remote.post.IPostRemoteDataSource | ||
import tw.y_studio.ptt.source.remote.post.PostRemoteDataSourceImpl | ||
import tw.y_studio.ptt.source.remote.search.ISearchBoardRemoteDataSource | ||
import tw.y_studio.ptt.source.remote.search.SearchBoardRemoteDataSourceImpl | ||
|
||
val dataSourceModules = module { | ||
factory<IPopularRemoteDataSource> { PopularRemoteDataSourceImpl(get()) } | ||
factory<IPopularRemoteDataSource> { PopularRemoteDataSourceImpl(get(), get()) } | ||
factory<ISearchBoardRemoteDataSource> { SearchBoardRemoteDataSourceImpl(get()) } | ||
factory<IPostRemoteDataSource> { PostRemoteDataSourceImpl(get()) } | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/tw/y_studio/ptt/source/remote/board/IPopularRemoteDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package tw.y_studio.ptt.source.remote.board | ||
|
||
import tw.y_studio.ptt.api.model.hot_board.HotBoard | ||
import tw.y_studio.ptt.api.model.hot_board.HotBoardTemp | ||
|
||
interface IPopularRemoteDataSource { | ||
|
||
fun getPopularBoardData(page: Int, count: Int): MutableList<HotBoardTemp> | ||
|
||
suspend fun getPopularBoards(): HotBoard | ||
|
||
fun disposeAll() | ||
} |
13 changes: 10 additions & 3 deletions
13
...te/popular/PopularRemoteDataSourceImpl.kt → ...mote/board/PopularRemoteDataSourceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
app/src/main/java/tw/y_studio/ptt/source/remote/popular/IPopularRemoteDataSource.kt
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
app/src/main/java/tw/y_studio/ptt/source/remote/post/IPostRemoteDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.