Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#8/create a class for savind session #22

Merged
merged 1 commit into from
Nov 12, 2020

Conversation

temnik15
Copy link
Collaborator

@temnik15 temnik15 commented Nov 8, 2020

A class has been created to persist the session while the application is running and for long-term storage.
Set the initialization of this class when starting the application

@temnik15 temnik15 linked an issue Nov 8, 2020 that may be closed by this pull request
5 tasks
app/build.gradle Outdated
@@ -33,5 +33,8 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

// https://mvnrepository.com/artifact/io.reactivex.rxjava3/rxjava
implementation group: 'io.reactivex.rxjava3', name: 'rxjava', version: '3.0.0-RC1'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем две одинаковых зависимости?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shiplayer разве они одинаковые? без второй с name 'android' становятся не доступны возможности RxJava для android (Например AndroidSchedulers.mainThread() из io.reactivex.rxjava3.android.schedulers.AndroidSchedulers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Наверное, не заметил, что name был разный

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Подними лучше у rxjava до 3.0.7

* @param context Must be an applicationContext to avoid memory leaks.
*/
fun init(context: Context) {
this.context = context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может стоит как то обезопасить этот момент? Хотя бы бросить эксепшен, если попытаться его заново инициализировать

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я тут думаю, может лучше не исключение кидать, а просто проверять через if что поле уже инициализировано? и все последующие вызовы не будут никак влиять

* @param preferences sharedPreferences saved on the device.
* @see init
*/
private fun getSessionFromPref(preferences: SharedPreferences) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не похоже, чтобы он что-то возвращал

/**
* @property KEY_ACCESS_TOKEN The key to get the access token value stored on the device.
*/
const val KEY_ACCESS_TOKEN = "ACCESS_TOKEN"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему такие поля не приватные?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это как раз то о чем я хотел рассказать при созвоне) Есть один нюанс с пробросом обновления сессии подписчикам

* the observer will receive the last session update and will continue
* to receive updates until the observable sends an .onComplete().
*/
fun subscribeToSessionUpdate(observer: Observer<Pair<String, String>>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я думаю, что лучше не запрашивать обзервер, а предоставлять обсервабл, чтобы они решали, где им подписываться

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так ещё получается, что этот подписчик никогда не отпишется и будет меморилик

@temnik15 temnik15 force-pushed the #8/create-a-class-for-savind-session branch from 1790da8 to 6590144 Compare November 8, 2020 15:08
* @return [Observable] <[Pair] <String, String >> when subscribing to which it will be possible
* to handle the session change.
*/
fun getObservableSession(): Observable<Pair<String, String>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему Pair? может нам стоит возвращать Session или просто Token

Comment on lines 3 to 4
data class Session(val token:Token,val time:Long)
data class Token(val accessToken: String, val refreshToken: String)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавь документацию

Comment on lines 5 to 19
class HawkApp: Application() {

override fun onCreate() {
super.onCreate()
SessionKeeper.init(applicationContext)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И сюда тоже документацию добавь

app/build.gradle Outdated
Comment on lines 36 to 39
// https://mvnrepository.com/artifact/io.reactivex.rxjava3/rxjava
implementation group: 'io.reactivex.rxjava3', name: 'rxjava', version: '3.0.7'
// https://mvnrepository.com/artifact/io.reactivex.rxjava3/rxandroid
implementation group: 'io.reactivex.rxjava3', name: 'rxandroid', version: '3.0.0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделай над общим коммитом и чтобы выглядело однообразно

Suggested change
// https://mvnrepository.com/artifact/io.reactivex.rxjava3/rxjava
implementation group: 'io.reactivex.rxjava3', name: 'rxjava', version: '3.0.7'
// https://mvnrepository.com/artifact/io.reactivex.rxjava3/rxandroid
implementation group: 'io.reactivex.rxjava3', name: 'rxandroid', version: '3.0.0'
// RxJava 3
implementation 'io.reactivex.rxjava3:rxjava:3.0.7'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'

Copy link
Contributor

@Shiplayer Shiplayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

отформатируй код

@@ -0,0 +1,4 @@
package so.codex.hawk.entity

data class Session(val token:Token,val time:Long)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пробел после , поставь и после :

@temnik15 temnik15 force-pushed the #8/create-a-class-for-savind-session branch 4 times, most recently from 0bda22e to d47a5a7 Compare November 11, 2020 11:12
Comment on lines 75 to 76
val value = pref.getString(key, "")!!
prefSubject.onNext(Token(value, ""))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему мы должны отправлять только accessToken, если у нас изменились все данные?
мы ведь знаем, что уведомлять слушателей будут уже после того, как все указанные данные изменятся в файле

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

думаю, что тут можно будет воспользоваться методом restoreSessionFromPref и после него отправить данные в сабджект

@temnik15 temnik15 force-pushed the #8/create-a-class-for-savind-session branch 2 times, most recently from 43c80a0 to b29f2f4 Compare November 11, 2020 18:39
@temnik15 temnik15 force-pushed the #8/create-a-class-for-savind-session branch from b29f2f4 to f30146c Compare November 12, 2020 22:11
@temnik15 temnik15 merged commit 995b37e into main Nov 12, 2020
@temnik15 temnik15 deleted the #8/create-a-class-for-savind-session branch November 12, 2020 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Создать класс для сохранения сессии
3 participants