-
Notifications
You must be signed in to change notification settings - Fork 1
Prepare client to work with back-end api #14
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
Open
mik629
wants to merge
30
commits into
Android-Academy-Global:develop
Choose a base branch
from
mik629:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
d6752ab
Prepare client to work with back-end api
8525fa2
Fix broken CI
mik629 ad0aa61
Remove fragments
mik629 05548a3
Extracted dependencies declaration into buildSrc/Config
mik629 65f88b2
Added gradlew
mik629 e963a03
NewsScreen re-written in compose
mik629 3e7233a
[NewsScreen] Fixed tabs behaviour
mik629 78ff650
Compose Theming
mik629 e7073cc
Fixed up profile screen icons
mik629 a0fc7d7
Added Profile Screen
mik629 9eee289
Organise code by layers
mik629 6faa9fc
Fixed profile/discard changes
mik629 d1a904a
Fixed profile/edit
mik629 33da48f
Added draft implementation of VideoScreen
mik629 1dc3746
Added draft implementation of VideoScreen
mik629 64f4cf7
Added draft implementation of VideoScreen
mik629 84d73dd
Refactoring
mik629 54386b3
Clean up
mik629 e91c5cd
Refactoring
mik629 e60ac6c
LogIn screen
mik629 ec4cc7e
Changed statusBar, bottomBar and tabs background to comply with main …
mik629 02dcaec
Added splash screen and fixed up the navigation
mik629 4e249a4
Added Academy label
mik629 adcbdb7
[AuthOptionsScreen] Improve UX
mik629 9b95caa
[AuthOptionsScreen] Refactoring
mik629 d70c610
[AuthOptionsScreen] Auth via back-end
mik629 67ebef3
Update README.md
mik629 173bd93
[ProfileScreen] Clear focus on cancel/done
mik629 933884d
[CI] Fix CI
mik629 4b62655
Merge pull request #1 from mik629/compose
mik629 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,39 +1,24 @@ | ||
| package com.academy.android | ||
|
|
||
| import android.os.Bundle | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import androidx.navigation.NavController | ||
| import androidx.navigation.findNavController | ||
| import androidx.navigation.ui.AppBarConfiguration | ||
| import androidx.navigation.ui.NavigationUI | ||
| import androidx.navigation.ui.setupActionBarWithNavController | ||
| import androidx.navigation.ui.setupWithNavController | ||
| import com.google.android.material.bottomnavigation.BottomNavigationView | ||
| import androidx.activity.ComponentActivity | ||
| import androidx.activity.compose.setContent | ||
| import androidx.navigation.compose.rememberNavController | ||
| import com.academy.android.ui.AcademyTheme | ||
| import com.academy.android.ui.StartNavigation | ||
| import dagger.hilt.android.AndroidEntryPoint | ||
|
|
||
| @AndroidEntryPoint | ||
| class MainActivity : AppCompatActivity() { | ||
|
|
||
| private val navController: NavController by lazy { | ||
| findNavController(R.id.nav_host_fragment) | ||
| } | ||
| class MainActivity : ComponentActivity() { | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_main) | ||
| val navView: BottomNavigationView = findViewById(R.id.nav_view) | ||
| // Passing each menu ID as a set of Ids because each | ||
| // menu should be considered as top level destinations. | ||
| val appBarConfiguration = AppBarConfiguration( | ||
| setOf( | ||
| R.id.navigation_videos, R.id.navigation_news, R.id.navigation_profile | ||
| ) | ||
| ) | ||
| setupActionBarWithNavController(navController, appBarConfiguration) | ||
| navView.setupWithNavController(navController) | ||
| } | ||
| setContent { | ||
| val navController = rememberNavController() | ||
|
|
||
| override fun onSupportNavigateUp(): Boolean { | ||
| return NavigationUI.navigateUp(navController, null) | ||
| AcademyTheme { | ||
| StartNavigation(navController = navController) | ||
| } | ||
| } | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
app/src/main/java/com/academy/android/data/PrefsStorage.kt
This file contains hidden or 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,59 @@ | ||
| package com.academy.android.data | ||
|
|
||
| import android.content.Context | ||
| import androidx.datastore.preferences.core.Preferences | ||
| import androidx.datastore.preferences.core.edit | ||
| import androidx.datastore.preferences.core.stringPreferencesKey | ||
| import androidx.datastore.preferences.preferencesDataStore | ||
| import com.academy.android.domain.OperationResult | ||
| import com.academy.android.domain.models.UserProfile | ||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.map | ||
| import kotlinx.serialization.json.Json | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class PrefsStorage @Inject constructor( | ||
| @ApplicationContext private val appContext: Context | ||
| ) { | ||
| private val Context.dataStore by preferencesDataStore("settings") | ||
|
|
||
| suspend fun writeString(key: Preferences.Key<String>, value: String) { | ||
| appContext.dataStore.edit { prefs -> | ||
| prefs[key] = value | ||
| } | ||
| } | ||
|
|
||
| fun readString(key: Preferences.Key<String>, default: String): Flow<String> = | ||
| appContext.dataStore.data | ||
| .map { prefs -> | ||
| prefs[key] ?: default | ||
| } | ||
|
|
||
| suspend fun saveProfile(profile: UserProfile) { | ||
| val serializedProfile = Json.encodeToString(UserProfile.serializer(), profile) | ||
| appContext.dataStore.edit { prefs -> | ||
| prefs[PROFILE_KEY] = serializedProfile | ||
| } | ||
| } | ||
|
|
||
| fun loadProfile(): Flow<OperationResult<UserProfile, Throwable?>> = | ||
| appContext.dataStore | ||
| .data | ||
| .map { prefs -> | ||
| val profile = prefs[PROFILE_KEY] | ||
| OperationResult.Success( | ||
| data = if (profile != null) { | ||
| Json.decodeFromString(UserProfile.serializer(), profile) | ||
| } else { | ||
| UserProfile.UNKNOWN | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| companion object { | ||
| private val PROFILE_KEY = stringPreferencesKey("user_profile") | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/academy/android/data/network/ServerApi.kt
This file contains hidden or 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,56 @@ | ||
| package com.academy.android.data.network | ||
|
|
||
| import com.academy.android.data.network.models.CourseDTO | ||
| import com.academy.android.data.network.models.LectureDTO | ||
| import com.academy.android.data.network.models.LoginRequestDTO | ||
| import com.academy.android.data.network.models.LoginResponseDTO | ||
| import com.academy.android.data.network.models.RegisterRequestDTO | ||
| import com.academy.android.data.network.models.UpdateCourseRequestDTO | ||
| import com.academy.android.data.network.models.UpdateLectureRequestDTO | ||
| import retrofit2.http.Body | ||
| import retrofit2.http.GET | ||
| import retrofit2.http.POST | ||
| import retrofit2.http.Query | ||
|
|
||
| interface ServerApi { | ||
| @POST("login") | ||
| suspend fun login( | ||
| @Body loginRequest: LoginRequestDTO | ||
| ): LoginResponseDTO | ||
|
|
||
| @POST("register") | ||
| suspend fun register( | ||
| @Body registerRequestDTO: RegisterRequestDTO | ||
| ): LoginResponseDTO | ||
|
|
||
| @GET("courses/favorite") | ||
| suspend fun getFavouriteCourses(): List<CourseDTO> | ||
|
|
||
| @GET("courses/all") | ||
| suspend fun getAllCourses(): List<CourseDTO> | ||
|
|
||
| @POST("courses/update") | ||
| suspend fun updateCourse( | ||
| @Body updateCourseRequestDTO: UpdateCourseRequestDTO | ||
| ) | ||
|
|
||
| @POST("lectures/update") | ||
| suspend fun updateLecture( | ||
| @Body updateLectureRequestDTO: UpdateLectureRequestDTO | ||
| ) | ||
|
|
||
| @GET("lectures/all") | ||
| suspend fun getAllLectures( | ||
| @Query(value = "courseId") courseId: Long | ||
| ): List<LectureDTO> | ||
|
|
||
| @GET("lectures/by-id") | ||
| suspend fun getLectureById( | ||
| @Query(value = "lectureId") lectureId: Long | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use a path variable, I think |
||
| ): LectureDTO | ||
|
|
||
| @POST("user/update-fcm-token") | ||
| suspend fun updateFcmToken( | ||
| @Body fcmToken: String | ||
| ) | ||
| } | ||
36 changes: 36 additions & 0 deletions
36
app/src/main/java/com/academy/android/data/network/TokenAuthenticator.kt
This file contains hidden or 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,36 @@ | ||
| package com.academy.android.data.network | ||
|
|
||
| import okhttp3.Authenticator | ||
| import okhttp3.Request | ||
| import okhttp3.Response | ||
| import okhttp3.Route | ||
| import javax.inject.Inject | ||
|
|
||
| // fixme: fix user auth | ||
| class TokenAuthenticator @Inject constructor( | ||
| // private val prefsStorage: PrefsStorage | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a PrefsStorage having DataStore under the hood |
||
| ) : Authenticator { | ||
| override fun authenticate(route: Route?, response: Response): Request? = | ||
| if (responseCount(response) < MAX_ATTEMPTS) { | ||
| response.request | ||
| .newBuilder() | ||
| // .header(AUTH_HEADER, prefsStorage.loadUser()?.token.orEmpty()) | ||
| .build() | ||
| } else { | ||
| null | ||
| } | ||
|
|
||
| private fun responseCount(response: Response): Int { | ||
| var result = 1 | ||
| var r: Response? = response | ||
| while (true) { | ||
| r = r?.priorResponse ?: return result | ||
| result++ | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| const val MAX_ATTEMPTS = 3 | ||
| const val AUTH_HEADER = "Token" | ||
| } | ||
| } | ||
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/academy/android/data/network/models/AdditionalMaterialDTO.kt
This file contains hidden or 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 com.academy.android.data.network.models | ||
|
|
||
| import com.academy.android.domain.models.AdditionalMaterial | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class AdditionalMaterialDTO( | ||
| val topicName: String, | ||
| val url: String | ||
| ) | ||
|
|
||
| fun AdditionalMaterialDTO.toAdditionalMaterial(): AdditionalMaterial = | ||
| AdditionalMaterial(topicName = topicName, url = url) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Better to use path variable, like:
{courseId}/lectures