Внедрение апи
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
<option name="previewFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("com.android.application")
|
id("com.android.application")
|
||||||
kotlin("android")
|
kotlin("android")
|
||||||
|
kotlin("kapt")
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@@ -64,14 +65,6 @@ dependencies {
|
|||||||
|
|
||||||
//std lib
|
//std lib
|
||||||
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
|
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
|
||||||
/* //app libs
|
|
||||||
implementation(AppDependencies.appLibraries)
|
|
||||||
//test libs
|
|
||||||
testImplementation(AppDependencies.testLibraries)
|
|
||||||
androidTestImplementation(AppDependencies.androidTestLibraries)
|
|
||||||
|
|
||||||
coreLibraryDesugaring(AppDependencies.desugaringLibraries)
|
|
||||||
debugImplementation(AppDependencies.debugLibraries)*/
|
|
||||||
|
|
||||||
//app libs
|
//app libs
|
||||||
implementation(AppLibraries)
|
implementation(AppLibraries)
|
||||||
@@ -79,6 +72,8 @@ dependencies {
|
|||||||
testImplementation(TestLibraries)
|
testImplementation(TestLibraries)
|
||||||
androidTestImplementation(AndroidTestLibraries)
|
androidTestImplementation(AndroidTestLibraries)
|
||||||
|
|
||||||
|
kapt(KaptLibraries)
|
||||||
|
|
||||||
coreLibraryDesugaring(DesugaringLibraries)
|
coreLibraryDesugaring(DesugaringLibraries)
|
||||||
debugImplementation(DebugLibraries)
|
debugImplementation(DebugLibraries)
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
android:roundIcon="@drawable/icon_rounded"
|
android:roundIcon="@drawable/icon_rounded"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.MyDnevnik"
|
android:theme="@style/Theme.MyDnevnik"
|
||||||
|
android:name=".App"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package ru.megboyzz.dnevnik
|
||||||
|
|
||||||
|
import android.accounts.Account
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.room.Room
|
||||||
|
import ru.megboyzz.dnevnik.db.CredentialsDataBase
|
||||||
|
|
||||||
|
class App : Application() {
|
||||||
|
var database: CredentialsDataBase? = null
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
|
||||||
|
super.onCreate()
|
||||||
|
instance = this
|
||||||
|
database = Room.databaseBuilder(this, CredentialsDataBase::class.java, "database")
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
var instance: App? = null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,16 +3,52 @@ package ru.megboyzz.dnevnik
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.material.*
|
import androidx.compose.material.Surface
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.lifecycle.ReportFragment.Companion.reportFragment
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import okhttp3.*
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
|
import org.jsoup.Jsoup
|
||||||
import ru.megboyzz.dnevnik.navigation.AppNavHost
|
import ru.megboyzz.dnevnik.navigation.AppNavHost
|
||||||
import ru.megboyzz.dnevnik.ui.theme.*
|
import ru.megboyzz.dnevnik.ui.theme.lightGray
|
||||||
|
import java.io.IOException
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
val login = "kitsekaterina"
|
||||||
|
val password = "k12345"
|
||||||
|
val returnUrl =
|
||||||
|
"https://login.dnevnik.ru/oauth2?response_type=token&client_id=bb97b3e445a340b9b9cab4b9ea0dbd6f&scope=CommonInfo,ContactInfo,FriendsAndRelatives,EducationalInfo"
|
||||||
|
|
||||||
|
val baseUrl = "https://login.dnevnik.ru/login/"
|
||||||
|
|
||||||
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
|
val execute: org.jsoup.Connection.Response = Jsoup
|
||||||
|
.connect(baseUrl)
|
||||||
|
.method(org.jsoup.Connection.Method.POST)
|
||||||
|
.data("ReturnUrl", returnUrl)
|
||||||
|
.data("login", login)
|
||||||
|
.data("password", password)
|
||||||
|
.followRedirects(true).execute()
|
||||||
|
val url: URL = execute.url()
|
||||||
|
|
||||||
|
val httpUrl = url.toString().toHttpUrlOrNull()
|
||||||
|
|
||||||
|
val queryParameter = httpUrl?.queryParameter("result")
|
||||||
|
|
||||||
|
println("$httpUrl $queryParameter")
|
||||||
|
}
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
|
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
color = lightGray
|
color = lightGray
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ import com.kizitonwose.calendar.compose.weekcalendar.WeekCalendarLayoutInfo
|
|||||||
import com.kizitonwose.calendar.compose.weekcalendar.WeekCalendarState
|
import com.kizitonwose.calendar.compose.weekcalendar.WeekCalendarState
|
||||||
import com.kizitonwose.calendar.core.*
|
import com.kizitonwose.calendar.core.*
|
||||||
import kotlinx.coroutines.flow.filterNotNull
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import ru.megboyzz.dnevnik.navigation.AppNavRoute
|
|
||||||
import ru.megboyzz.dnevnik.navigation.BaseNavRote
|
import ru.megboyzz.dnevnik.navigation.BaseNavRote
|
||||||
import ru.megboyzz.dnevnik.ui.theme.dark
|
import ru.megboyzz.dnevnik.ui.theme.dark
|
||||||
import java.time.DayOfWeek
|
import java.time.DayOfWeek
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package ru.megboyzz.dnevnik.db
|
||||||
|
|
||||||
|
import androidx.room.Database
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
import ru.megboyzz.dnevnik.db.dao.CredentialsDao
|
||||||
|
import ru.megboyzz.dnevnik.entities.db.Credentials
|
||||||
|
|
||||||
|
@Database(
|
||||||
|
entities = [Credentials::class],
|
||||||
|
version = 1
|
||||||
|
)
|
||||||
|
abstract class CredentialsDataBase: RoomDatabase() {
|
||||||
|
|
||||||
|
abstract fun credentialsDao(): CredentialsDao
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package ru.megboyzz.dnevnik.db.dao
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
import ru.megboyzz.dnevnik.entities.db.Credentials
|
||||||
|
|
||||||
|
interface CredentialsDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM Credentials WHERE id = 1")
|
||||||
|
fun getCredentials(): LiveData<Credentials>
|
||||||
|
|
||||||
|
@Query("DELETE FROM Credentials WHERE id = 1")
|
||||||
|
fun deleteCredentials()
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun setCredentials(profile: Credentials)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package ru.megboyzz.dnevnik.entities.context
|
||||||
|
|
||||||
|
data class GroupInfo(
|
||||||
|
val id: Long,
|
||||||
|
val name: String
|
||||||
|
)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package ru.megboyzz.dnevnik.entities.context
|
||||||
|
|
||||||
|
data class PeriodGroup(
|
||||||
|
val id: Long,
|
||||||
|
val type: String, //Обычно равен "Quarter", то есть Четверть, но как будет семестр у них????
|
||||||
|
val periods: List<PeriodInfo>
|
||||||
|
)
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package ru.megboyzz.dnevnik.entities.context
|
||||||
|
|
||||||
|
data class PeriodInfo(
|
||||||
|
val id: Long,
|
||||||
|
val number: Short,
|
||||||
|
val type: String,
|
||||||
|
val dateStart: Long,
|
||||||
|
val dateFinish: Long,
|
||||||
|
val studyYear: Short,
|
||||||
|
val isCurrent: Boolean
|
||||||
|
)
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package ru.megboyzz.dnevnik.entities.context
|
||||||
|
|
||||||
|
data class PersonContext(
|
||||||
|
val sex: String,
|
||||||
|
val userId: Long,
|
||||||
|
val personId: Long,
|
||||||
|
val firstName: String,
|
||||||
|
val middleName: String,
|
||||||
|
val lastName: String,
|
||||||
|
val avatarUrl: String,
|
||||||
|
val schoolInfo: SchoolInfo,
|
||||||
|
val group: GroupInfo,
|
||||||
|
val reportingPeriodGroup: PeriodGroup
|
||||||
|
)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package ru.megboyzz.dnevnik.entities.context
|
||||||
|
|
||||||
|
data class SchoolInfo(
|
||||||
|
val id: Long,
|
||||||
|
val name: String,
|
||||||
|
val avatarUrl: String
|
||||||
|
)
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package ru.megboyzz.dnevnik.entities.context
|
||||||
|
|
||||||
|
data class UserInfo(
|
||||||
|
val sex: String,
|
||||||
|
val roles: List<String>,
|
||||||
|
val userId: Long,
|
||||||
|
val personId: Long,
|
||||||
|
val firstName: String,
|
||||||
|
val middleName: String,
|
||||||
|
val lastName: String,
|
||||||
|
val avatarUrl: String,
|
||||||
|
)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package ru.megboyzz.dnevnik.entities.db
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
data class Credentials(
|
||||||
|
val token: String,
|
||||||
|
val cookies: Map<String, String>
|
||||||
|
)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package ru.megboyzz.dnevnik.entities.response
|
||||||
|
|
||||||
|
data class TokenResponse(
|
||||||
|
val login: String,
|
||||||
|
val password: String
|
||||||
|
)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package ru.megboyzz.dnevnik.entities.response
|
||||||
|
|
||||||
|
import ru.megboyzz.dnevnik.entities.context.PersonContext
|
||||||
|
import ru.megboyzz.dnevnik.entities.context.UserInfo
|
||||||
|
|
||||||
|
data class UserContext(
|
||||||
|
val info: UserInfo,
|
||||||
|
val contextPersons: List<PersonContext>
|
||||||
|
)
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package ru.megboyzz.dnevnik.repository
|
||||||
|
|
||||||
|
class AuthorizationRepository() {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package ru.megboyzz.dnevnik.service
|
||||||
|
|
||||||
|
enum class AuthorizationStatus {
|
||||||
|
WRONG_CREDENTIALS,
|
||||||
|
NO_INTERNET,
|
||||||
|
MAINTAIN
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package ru.megboyzz.dnevnik.service
|
||||||
|
|
||||||
|
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import org.jsoup.Jsoup
|
||||||
|
import retrofit2.http.POST
|
||||||
|
import retrofit2.http.Query
|
||||||
|
|
||||||
|
interface TokenService{
|
||||||
|
|
||||||
|
@POST("/")
|
||||||
|
suspend fun getToken(
|
||||||
|
@Query("login") login: String,
|
||||||
|
@Query("password") password: String,
|
||||||
|
@Query("ReturnUrl") returnUrl: String = "https://login.dnevnik.ru/oauth2?response_type=token&client_id=bb97b3e445a340b9b9cab4b9ea0dbd6f&scope=CommonInfo,ContactInfo,FriendsAndRelatives,EducationalInfo"
|
||||||
|
): retrofit2.Call<ResponseBody>
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package ru.megboyzz.dnevnik.viewmodel
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.lifecycle.AndroidViewModel
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import java.lang.IllegalArgumentException
|
||||||
|
|
||||||
|
//Если есть попадание в этот вьюмодел то нам нужна авторизация
|
||||||
|
class AuthorizationViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
|
|
||||||
|
val login = MutableStateFlow("")
|
||||||
|
val password = MutableStateFlow("")
|
||||||
|
val isLogged = MutableStateFlow(false)
|
||||||
|
|
||||||
|
init {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun login(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AuthorizationViewModelFactory(private val application: Application) : ViewModelProvider.Factory {
|
||||||
|
|
||||||
|
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||||
|
if (modelClass.isAssignableFrom(AuthorizationViewModel::class.java))
|
||||||
|
return AuthorizationViewModel(application) as T
|
||||||
|
throw IllegalArgumentException("Unknown ViewModel Class")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import core.DependencyList
|
||||||
import org.gradle.api.artifacts.dsl.DependencyHandler
|
import org.gradle.api.artifacts.dsl.DependencyHandler
|
||||||
|
|
||||||
object AppLibraries: DependencyList() {
|
object AppLibraries: DependencyList() {
|
||||||
@@ -32,6 +33,11 @@ object AppLibraries: DependencyList() {
|
|||||||
val calendar = "com.kizitonwose.calendar:compose:2.1.1"
|
val calendar = "com.kizitonwose.calendar:compose:2.1.1"
|
||||||
val asyncImage = "io.coil-kt:coil-compose:2.2.0"
|
val asyncImage = "io.coil-kt:coil-compose:2.2.0"
|
||||||
|
|
||||||
|
val roomRuntime = "androidx.room:room-runtime:${Versions.room}"
|
||||||
|
val roomKtx = "androidx.room:room-ktx:${Versions.room}"
|
||||||
|
|
||||||
|
val jsoup = "org.jsoup:jsoup:1.15.4"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object DebugLibraries: DependencyList() {
|
object DebugLibraries: DependencyList() {
|
||||||
@@ -58,7 +64,12 @@ object AndroidTestLibraries: DependencyList() {
|
|||||||
|
|
||||||
object TestLibraries: DependencyList() {
|
object TestLibraries: DependencyList() {
|
||||||
//test libs
|
//test libs
|
||||||
private val junit = "junit:junit:${Versions.junit}"
|
val junit = "junit:junit:${Versions.junit}"
|
||||||
|
}
|
||||||
|
|
||||||
|
object KaptLibraries: DependencyList(){
|
||||||
|
|
||||||
|
val compiler = "androidx.room:room-compiler:${Versions.room}"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ object Versions {
|
|||||||
val constraintLayout = "2.0.0-beta8"
|
val constraintLayout = "2.0.0-beta8"
|
||||||
|
|
||||||
val compose = "1.4.1"
|
val compose = "1.4.1"
|
||||||
|
val room = "2.2.6"
|
||||||
|
|
||||||
//test
|
//test
|
||||||
val junit = "4.12"
|
val junit = "4.12"
|
||||||
|
|||||||
+2
@@ -1,3 +1,5 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
open class DependencyList {
|
open class DependencyList {
|
||||||
|
|
||||||
fun list(): List<String>{
|
fun list(): List<String>{
|
||||||
Reference in New Issue
Block a user