-
Notifications
You must be signed in to change notification settings - Fork 0
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 #6 from EvgenyTerebenin/release_v0.1
Minor release v0.1
- Loading branch information
Showing
77 changed files
with
1,592 additions
and
320 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
6 changes: 2 additions & 4 deletions
6
app/src/androidTest/java/com/terebenin/durov_return_the_wall/ExampleInstrumentedTest.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
19 changes: 0 additions & 19 deletions
19
app/src/main/java/com/terebenin/durov_return_the_wall/MainActivity.kt
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/terebenin/durov_return_the_wall/data/datasource/network/VkApi.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,15 @@ | ||
package com.terebenin.durov_return_the_wall.data.datasource.network | ||
|
||
import com.terebenin.durov_return_the_wall.data.newsfeed.response.NewsfeedResponse | ||
import retrofit2.Response | ||
import retrofit2.http.GET | ||
|
||
interface VkApi { | ||
|
||
companion object { | ||
const val METHOD_PATH = "method" | ||
} | ||
|
||
@GET("$METHOD_PATH/newsfeed.get") | ||
suspend fun getNewsfeed(): Response<NewsfeedResponse> | ||
} |
49 changes: 49 additions & 0 deletions
49
...src/main/java/com/terebenin/durov_return_the_wall/data/datasource/network/VkApiFactory.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,49 @@ | ||
package com.terebenin.durov_return_the_wall.data.datasource.network | ||
|
||
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory | ||
import com.terebenin.durov_return_the_wall.BuildConfig | ||
import com.terebenin.durov_return_the_wall.presentation.global.VkApplication.Companion.prefs | ||
import okhttp3.Interceptor | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
|
||
object VkApiFactory { | ||
|
||
private val authInterceptor = Interceptor { chain -> | ||
val newUrl = chain.request().url | ||
.newBuilder() | ||
.addQueryParameter("access_token", prefs.accessToken.token) | ||
.addQueryParameter("v", BuildConfig.API_VERSION) | ||
.build() | ||
|
||
val newRequest = chain.request() | ||
.newBuilder() | ||
.url(newUrl) | ||
.build() | ||
|
||
chain.proceed(newRequest) | ||
} | ||
|
||
private fun initOkHttpClient(): OkHttpClient { | ||
val okHttpClientBuilder = OkHttpClient.Builder().apply { | ||
addInterceptor(authInterceptor) | ||
val logInterceptor = HttpLoggingInterceptor() | ||
logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY) | ||
addInterceptor(logInterceptor) | ||
} | ||
return okHttpClientBuilder.build() | ||
} | ||
|
||
private fun retrofit(): Retrofit = Retrofit.Builder() | ||
.client(initOkHttpClient()) | ||
.baseUrl(BuildConfig.BASE_API_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.addCallAdapterFactory(CoroutineCallAdapterFactory()) | ||
.build() | ||
|
||
val vkApi: VkApi = retrofit().create(VkApi::class.java) | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/terebenin/durov_return_the_wall/data/datasource/storage/Prefs.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,31 @@ | ||
package com.terebenin.durov_return_the_wall.data.datasource.storage | ||
|
||
import android.content.Context | ||
import com.google.gson.Gson | ||
import com.google.gson.reflect.TypeToken | ||
import com.terebenin.durov_return_the_wall.domain.global.AccessToken | ||
|
||
class Prefs( | ||
private val context: Context, | ||
private val gson: Gson | ||
) { | ||
private fun getSharedPreferences(prefsName: String) = | ||
context.getSharedPreferences(prefsName, Context.MODE_PRIVATE) | ||
|
||
private val AUTH_DATA = "auth_data" | ||
private val ACCESS_TOKEN = "access_token" | ||
private val authPrefs by lazy { getSharedPreferences(AUTH_DATA) } | ||
|
||
private val accessTokenType = object : TypeToken<AccessToken>() {}.type | ||
|
||
var accessToken: AccessToken | ||
get() { | ||
return gson.fromJson(authPrefs.getString(ACCESS_TOKEN, ""), accessTokenType) | ||
} | ||
set(value) { | ||
authPrefs.edit().putString(ACCESS_TOKEN, gson.toJson(value)).apply() | ||
|
||
} | ||
|
||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...src/main/java/com/terebenin/durov_return_the_wall/data/newsfeed/NewsfeedRepositoryImpl.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 com.terebenin.durov_return_the_wall.data.newsfeed | ||
|
||
import com.terebenin.durov_return_the_wall.data.datasource.network.VkApi | ||
import com.terebenin.durov_return_the_wall.data.newsfeed.response.toDomainModel | ||
import com.terebenin.durov_return_the_wall.domain.newsfeed.NewsfeedRepository | ||
import com.terebenin.durov_return_the_wall.domain.newsfeed.model.NewsfeedResponseDomainModel | ||
|
||
class NewsfeedRepositoryImpl(private val vkApi: VkApi) : NewsfeedRepository { | ||
override suspend fun getNewsfeed(): NewsfeedResponseDomainModel? { | ||
return vkApi.getNewsfeed().body()?.response?.toDomainModel() | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/terebenin/durov_return_the_wall/data/newsfeed/response/Attachments.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,19 @@ | ||
package com.terebenin.durov_return_the_wall.data.newsfeed.response | ||
|
||
|
||
import android.os.Parcelable | ||
import com.google.gson.annotations.SerializedName | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
@Parcelize | ||
data class Attachments( | ||
|
||
@field:SerializedName("photo") | ||
val photo: Photo? = null, | ||
|
||
@field:SerializedName("type") | ||
val type: String? = null, | ||
|
||
@field:SerializedName("video") | ||
val video: Video? = null | ||
) : Parcelable |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/terebenin/durov_return_the_wall/data/newsfeed/response/Comments.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,16 @@ | ||
package com.terebenin.durov_return_the_wall.data.newsfeed.response | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
|
||
data class Comments( | ||
|
||
@field:SerializedName("count") | ||
val count: Int? = null, | ||
|
||
@field:SerializedName("groups_can_post") | ||
val groupsCanPost: Boolean? = null, | ||
|
||
@field:SerializedName("can_post") | ||
val canPost: Int? = null | ||
) |
Oops, something went wrong.