-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from ininmm/initial_board_api
Initial board api
- Loading branch information
Showing
37 changed files
with
403 additions
and
212 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
7 changes: 7 additions & 0 deletions
7
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,7 @@ | ||
package tw.y_studio.ptt.source.remote.board | ||
|
||
import tw.y_studio.ptt.api.model.hot_board.HotBoard | ||
|
||
interface IPopularRemoteDataSource { | ||
suspend fun getPopularBoards(): HotBoard | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/tw/y_studio/ptt/source/remote/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package tw.y_studio.ptt.source.remote.board | ||
|
||
import tw.y_studio.ptt.api.board.BoardApiService | ||
import tw.y_studio.ptt.api.model.hot_board.HotBoard | ||
|
||
class PopularRemoteDataSourceImpl( | ||
private val boardApiService: BoardApiService | ||
) : IPopularRemoteDataSource { | ||
override suspend fun getPopularBoards(): HotBoard { | ||
return boardApiService.getPopularBoard() | ||
} | ||
} |
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.
18 changes: 0 additions & 18 deletions
18
app/src/main/java/tw/y_studio/ptt/source/remote/popular/PopularRemoteDataSourceImpl.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
Oops, something went wrong.