Ethosa před 3 roky
rodič
revize
e86ed8d270

+ 6 - 0
.idea/misc.xml

@@ -46,6 +46,7 @@
         <entry key="..\:/android projects/KTC/app/src/main/res/layout/fragment_gallery.xml" value="0.371875" />
         <entry key="..\:/android projects/KTC/app/src/main/res/layout/fragment_home.xml" value="0.5" />
         <entry key="..\:/android projects/KTC/app/src/main/res/layout/fragment_news.xml" value="0.3052586575459598" />
+        <entry key="..\:/android projects/KTC/app/src/main/res/layout/fragment_pro_college.xml" value="0.33" />
         <entry key="..\:/android projects/KTC/app/src/main/res/layout/fragment_settings.xml" value="0.371875" />
         <entry key="..\:/android projects/KTC/app/src/main/res/layout/fragment_timetable.xml" value="0.5" />
         <entry key="..\:/android projects/KTC/app/src/main/res/layout/layout_album_image.xml" value="0.371875" />
@@ -71,6 +72,11 @@
       </map>
     </option>
   </component>
+  <component name="EntryPointsManager">
+    <list size="1">
+      <item index="0" class="java.lang.String" itemvalue="android.webkit.JavascriptInterface" />
+    </list>
+  </component>
   <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>

+ 2 - 2
app/build.gradle

@@ -10,8 +10,8 @@ android {
         applicationId "com.ethosa.ktc"
         minSdk 21
         targetSdk 32
-        versionCode 6
-        versionName "0.4.2"
+        versionCode 7
+        versionName "0.5.0"
         ndk {
             abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
         }

+ 22 - 0
app/src/main/java/com/ethosa/ktc/college/AuthInterface.kt

@@ -0,0 +1,22 @@
+package com.ethosa.ktc.college
+
+import android.webkit.JavascriptInterface
+import android.webkit.WebView
+
+/**
+ * Provides HTML processing
+ */
+class AuthInterface {
+    var webView: WebView? = null
+
+    /**
+     * Processes HTML text
+     */
+    @JavascriptInterface
+    fun processHtml(html: String) {
+    }
+
+    @JavascriptInterface
+    fun getCookies(cookies: String) {
+    }
+}

+ 47 - 0
app/src/main/java/com/ethosa/ktc/college/ProCollege.kt

@@ -0,0 +1,47 @@
+package com.ethosa.ktc.college
+
+import android.annotation.SuppressLint
+import android.content.Context
+import android.webkit.WebView
+import android.webkit.WebViewClient
+
+/**
+ * Provides work with pro college.
+ */
+class ProCollege(
+    private val wb: WebView
+) {
+    private val authInterface = AuthInterface()
+
+    companion object {
+        private const val LOGIN_PAGE = "https://pro.kansk-tc.ru/login/index.php"
+    }
+
+    /**
+     * Authorization in pro college using WebView.
+     */
+    @SuppressLint("SetJavaScriptEnabled")
+    fun auth(username: String, password: String) {
+        authInterface.webView = wb
+        // Setup WebView ..
+        wb.settings.javaScriptEnabled = true
+        wb.settings.userAgentString = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
+        wb.addJavascriptInterface(authInterface, "Android")
+        wb.webViewClient = object : WebViewClient() {
+            override fun onPageFinished(view: WebView?, url: String?) {
+                view?.evaluateJavascript("") {
+                    wb.loadUrl("""
+                        javascript:
+                        document.getElementsByName("username")[0].value = "$username";
+                        document.getElementsByName("password")[0].value = "$password";
+                        document.getElementsByClassName("btn-login")[0].click();
+                        window.Android.processHtml('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');
+                        window.Android.sendCookies(document.cookie);
+                    """.trimIndent())
+                }
+            }
+        }
+
+        wb.loadUrl(LOGIN_PAGE)
+    }
+}

+ 55 - 0
app/src/main/java/com/ethosa/ktc/ui/fragments/ProCollegeFragment.kt

@@ -0,0 +1,55 @@
+package com.ethosa.ktc.ui.fragments
+
+import android.content.Context
+import android.content.SharedPreferences
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import com.ethosa.ktc.college.ProCollege
+import com.ethosa.ktc.databinding.FragmentProCollegeBinding
+
+
+/**
+ * Fragment which provides working with ProCollege.
+ */
+class ProCollegeFragment : Fragment() {
+    private var _binding: FragmentProCollegeBinding? = null
+    private val binding get() = _binding!!
+    private lateinit var proCollege: ProCollege
+    private lateinit var preferences: SharedPreferences
+
+    companion object {
+        private const val USERNAME = "username"
+        private const val PASSWORD = "password"
+    }
+
+    override fun onCreateView(
+        inflater: LayoutInflater,
+        container: ViewGroup?,
+        savedInstanceState: Bundle?
+    ): View {
+        _binding = FragmentProCollegeBinding.inflate(inflater, container, false)
+
+        proCollege = ProCollege(binding.content)
+        preferences = requireActivity().getPreferences(Context.MODE_PRIVATE)
+
+        binding.username.editText?.setText(preferences.getString(USERNAME, ""))
+        binding.password.editText?.setText(preferences.getString(PASSWORD, ""))
+
+        binding.auth.setOnClickListener {
+            // Auth in ProCollege
+            binding.login.visibility = View.GONE
+            binding.content.visibility = View.VISIBLE
+            preferences.edit().putString(USERNAME, binding.username.editText?.text.toString()).apply()
+            preferences.edit().putString(PASSWORD, binding.password.editText?.text.toString()).apply()
+            proCollege.auth(
+                binding.username.editText?.text.toString(),
+                binding.password.editText?.text.toString()
+            )
+        }
+
+        return binding.root
+    }
+}

+ 95 - 0
app/src/main/res/layout/fragment_pro_college.xml

@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/frameLayout"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".ui.fragments.ProCollegeFragment">
+
+    <WebView
+        android:id="@+id/content"
+        android:layout_width="0dp"
+        android:layout_height="0dp"
+        android:visibility="gone"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/login"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:padding="16dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="1.0"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent">
+
+        <com.google.android.material.textfield.TextInputLayout
+            android:id="@+id/username"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="24dp"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/textView2">
+
+            <com.google.android.material.textfield.TextInputEditText
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:backgroundTint="@color/background_secondary"
+                android:hint="@string/username"
+                android:textColor="@color/text"
+                tools:ignore="TextContrastCheck" />
+        </com.google.android.material.textfield.TextInputLayout>
+
+        <com.google.android.material.textfield.TextInputLayout
+            android:id="@+id/password"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="8dp"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/username"
+            app:passwordToggleEnabled="true"
+            app:passwordToggleTint="@color/primary">
+
+            <com.google.android.material.textfield.TextInputEditText
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:backgroundTint="@color/background_secondary"
+                android:hint="@string/password"
+                android:inputType="textPassword"
+                android:textColor="@color/text"
+                tools:ignore="TextContrastCheck" />
+        </com.google.android.material.textfield.TextInputLayout>
+
+        <Button
+            android:id="@+id/auth"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="16dp"
+            android:text="@string/auth"
+            android:textColor="@color/btn_text"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/password"
+            tools:ignore="TextContrastCheck" />
+
+        <TextView
+            android:id="@+id/textView2"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/title_pro_college"
+            android:textColor="@color/text"
+            android:textSize="24sp"
+            android:textStyle="bold"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 12 - 0
app/src/main/res/navigation/mobile_navigation.xml

@@ -42,6 +42,11 @@
             app:destination="@id/navigation_contact_info"
             app:enterAnim="@anim/nav_default_enter_anim"
             app:exitAnim="@anim/nav_default_exit_anim" />
+        <action
+            android:id="@+id/action_navigation_settings_to_navigation_pro_college"
+            app:destination="@id/navigation_pro_college"
+            app:enterAnim="@anim/nav_default_enter_anim"
+            app:exitAnim="@anim/nav_default_exit_anim" />
     </fragment>
 
     <fragment
@@ -58,4 +63,11 @@
         android:label="@string/title_contact_info"
         tools:layout="@layout/fragment_contact_info" />
 
+    <fragment
+        android:id="@+id/navigation_pro_college"
+        android:tag="ProCollege"
+        android:name="com.ethosa.ktc.ui.fragments.ProCollegeFragment"
+        android:label="@string/title_pro_college"
+        tools:layout="@layout/fragment_pro_college" />
+
 </navigation>

+ 3 - 0
app/src/main/res/values/arrays.xml

@@ -1,16 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
     <string-array name="settings_titles">
+        <item>Личный кабинет</item>
         <item>Контактная информация</item>
         <item>О программе</item>
     </string-array>
 
     <array name="settings_icons">
+        <item>@drawable/ic_portrait</item>
         <item>@drawable/ic_headset</item>
         <item>@drawable/ic_info</item>
     </array>
 
     <array name="settings_actions">
+        <item>@id/action_navigation_settings_to_navigation_pro_college</item>
         <item>@id/action_navigation_settings_to_navigation_contact_info</item>
         <item>@id/action_navigation_settings_to_navigation_about_app</item>
     </array>

+ 6 - 0
app/src/main/res/values/strings.xml

@@ -10,14 +10,20 @@
     <string name="title_settings">Настройки</string>
     <string name="title_about">О приложении</string>
     <string name="title_contact_info">Контактная информация</string>
+    <string name="title_pro_college">ProCollege</string>
     <string name="title_activity_album">Альбом</string>
     <string name="title_activity_wall_post">Новость</string>
 
     <string name="news_title">Название поста</string>
     <string name="news_date">19 апр</string>
     <string name="news_description">Краткое описание поста</string>
+
     <string name="course_string">1 Курс</string>
 
+    <string name="username">Логин</string>
+    <string name="password">Пароль</string>
+    <string name="auth">Войти</string>
+
     <string name="lesson_title">Проектирование и дизайн информационных систем</string>
     <string name="lesson_number">1</string>
     <string name="lesson_time">00:00</string>