-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем две одинаковых зависимости?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Наверное, не заметил, что name был разный
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Может стоит как то обезопасить этот момент? Хотя бы бросить эксепшен, если попытаться его заново инициализировать
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему такие поля не приватные?
There was a problem hiding this comment.
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>>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я думаю, что лучше не запрашивать обзервер, а предоставлять обсервабл, чтобы они решали, где им подписываться
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так ещё получается, что этот подписчик никогда не отпишется и будет меморилик
1790da8
to
6590144
Compare
* @return [Observable] <[Pair] <String, String >> when subscribing to which it will be possible | ||
* to handle the session change. | ||
*/ | ||
fun getObservableSession(): Observable<Pair<String, String>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почему Pair? может нам стоит возвращать Session или просто Token
data class Session(val token:Token,val time:Long) | ||
data class Token(val accessToken: String, val refreshToken: String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добавь документацию
class HawkApp: Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
SessionKeeper.init(applicationContext) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И сюда тоже документацию добавь
app/build.gradle
Outdated
// 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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сделай над общим коммитом и чтобы выглядело однообразно
// 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' |
There was a problem hiding this 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
пробел после , поставь и после :
0bda22e
to
d47a5a7
Compare
val value = pref.getString(key, "")!! | ||
prefSubject.onNext(Token(value, "")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почему мы должны отправлять только accessToken, если у нас изменились все данные?
мы ведь знаем, что уведомлять слушателей будут уже после того, как все указанные данные изменятся в файле
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
думаю, что тут можно будет воспользоваться методом restoreSessionFromPref
и после него отправить данные в сабджект
43c80a0
to
b29f2f4
Compare
b29f2f4
to
f30146c
Compare
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