Parcourir la source

update working with ProCollege

Ethosa il y a 3 ans
Parent
commit
30398cddb2

+ 2 - 2
.idea/deploymentTargetDropDown.xml

@@ -7,11 +7,11 @@
         <deviceKey>
           <Key>
             <type value="VIRTUAL_DEVICE_PATH" />
-            <value value="C:\Users\79833\.android\avd\Pixel_XL_API_32.avd" />
+            <value value="C:\Users\79833\.android\avd\Pixel_5_API_30.avd" />
           </Key>
         </deviceKey>
       </Target>
     </targetSelectedWithDropDown>
-    <timeTargetWasSelectedWithDropDown value="2022-04-13T01:49:35.141812600Z" />
+    <timeTargetWasSelectedWithDropDown value="2022-04-14T10:46:25.721790400Z" />
   </component>
 </project>

+ 3 - 2
.idea/misc.xml

@@ -24,6 +24,7 @@
         <entry key="..\:/android projects/KTC/app/src/main/res/drawable/ic_mode_landscape.xml" value="0.144" />
         <entry key="..\:/android projects/KTC/app/src/main/res/drawable/ic_portrait.xml" value="0.144" />
         <entry key="..\:/android projects/KTC/app/src/main/res/drawable/ic_reload.xml" value="0.112" />
+        <entry key="..\:/android projects/KTC/app/src/main/res/drawable/ic_search.xml" value="0.177" />
         <entry key="..\:/android projects/KTC/app/src/main/res/drawable/ic_settings.xml" value="0.144" />
         <entry key="..\:/android projects/KTC/app/src/main/res/drawable/item.xml" value="0.1" />
         <entry key="..\:/android projects/KTC/app/src/main/res/drawable/navigation.xml" value="0.1185" />
@@ -58,9 +59,9 @@
         <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.5" />
+        <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.33" />
+        <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" />
         <entry key="..\:/android projects/KTC/app/src/main/res/layout/layout_album_photo.xml" value="0.371875" />
         <entry key="..\:/android projects/KTC/app/src/main/res/layout/layout_album_preview.xml" value="0.1573321932449765" />

+ 16 - 4
app/src/main/java/com/ethosa/ktc/college/ProCollege.kt

@@ -51,11 +51,13 @@ class ProCollege(
                             document.getElementsByName("username")[0].value = "$username";
                             document.getElementsByName("password")[0].value = "$password";
                             authButton.click();
+                        } else {
+                            window.Android.showWebView();
                         }
                         
                         if (authErrors != undefined && authErrors.length != 0) {
                             window.Android.processErrors(
-                                authErrors[0].getElementsByTagName("a")[0].innerHTML
+                                authErrors.getElementsByTagName("a")[0].innerHTML
                             );
                         }
                         
@@ -104,7 +106,7 @@ class ProCollege(
     }
 
     /**
-     *
+     * Calls on sign out from pro college.
      */
     @JavascriptInterface
     fun onSignOut() {
@@ -115,10 +117,20 @@ class ProCollege(
                 content.webViewClient = WebViewClient()
                 content.clearHistory()
                 content.stopLoading()
-                content.visibility = View.GONE
+                webviewContainer.visibility = View.GONE
                 login.visibility = View.VISIBLE
-                contentProgress.visibility = View.GONE
             }
         }
     }
+
+    /**
+     * Shows WebView on authorized in account.
+     */
+    @JavascriptInterface
+    fun showWebView() {
+        fragment.requireActivity().runOnUiThread {
+            fragment.binding.webviewContainer.visibility = View.VISIBLE
+            fragment.binding.login.visibility = View.GONE
+        }
+    }
 }

+ 3 - 1
app/src/main/java/com/ethosa/ktc/ui/fragments/ProCollegeFragment.kt

@@ -39,6 +39,9 @@ class ProCollegeFragment : Fragment() {
         binding.username.editText?.setText(Preferences.proCollegeUsername)
         binding.password.editText?.setText(Preferences.proCollegePassword)
 
+        if (Preferences.proCollegeUsername != "" && Preferences.proCollegePassword != "")
+            auth()
+
         // Auto dark mode ...
         // Require API Q+
         if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
@@ -72,7 +75,6 @@ class ProCollegeFragment : Fragment() {
             preferences.saveProCollege()
             proCollege.auth(Preferences.proCollegeUsername, Preferences.proCollegePassword)
             binding.login.visibility = View.GONE
-            binding.content.visibility = View.VISIBLE
         } else {
             // Show errors
             if (username == "")

+ 9 - 0
app/src/main/res/drawable/ic_search.xml

@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="@dimen/default_img_width"
+    android:height="@dimen/default_img_width"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+  <path
+      android:fillColor="#FF000000"
+      android:pathData="M23.707,22.293l-5.969,-5.969a10.016,10.016 0,1 0,-1.414 1.414l5.969,5.969a1,1 0,0 0,1.414 -1.414ZM10,18a8,8 0,1 1,8 -8A8.009,8.009 0,0 1,10 18Z"/>
+</vector>

+ 34 - 19
app/src/main/res/layout/fragment_pro_college.xml

@@ -7,18 +7,6 @@
     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">
-
-    </WebView>
-
     <androidx.constraintlayout.widget.ConstraintLayout
         android:id="@+id/login"
         android:layout_width="0dp"
@@ -44,7 +32,8 @@
                 android:layout_height="wrap_content"
                 android:backgroundTint="?cardBackgroundColor"
                 android:hint="@string/username"
-                android:textColor="?android:textColor" />
+                android:textColor="?android:textColor"
+                tools:ignore="TextContrastCheck" />
         </com.google.android.material.textfield.TextInputLayout>
 
         <com.google.android.material.textfield.TextInputLayout
@@ -64,7 +53,8 @@
                 android:backgroundTint="?cardBackgroundColor"
                 android:hint="@string/password"
                 android:inputType="textPassword"
-                android:textColor="?android:textColor" />
+                android:textColor="?android:textColor"
+                tools:ignore="TextContrastCheck" />
         </com.google.android.material.textfield.TextInputLayout>
 
         <Button
@@ -93,14 +83,39 @@
             app:layout_constraintTop_toTopOf="parent" />
     </androidx.constraintlayout.widget.ConstraintLayout>
 
-    <ProgressBar
-        android:id="@+id/content_progress"
-        style="?android:progressBarStyleHorizontal"
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/webview_container"
         android:layout_width="0dp"
-        android:layout_height="wrap_content"
+        android:layout_height="0dp"
         android:visibility="gone"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent" />
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        tools:visibility="gone">
+
+        <WebView
+            android:id="@+id/content"
+            android:layout_width="0dp"
+            android:layout_height="0dp"
+            android:visibility="visible"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent">
+
+        </WebView>
+
+        <ProgressBar
+            android:id="@+id/content_progress"
+            style="?android:progressBarStyleHorizontal"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:visibility="gone"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            tools:visibility="visible" />
+    </androidx.constraintlayout.widget.ConstraintLayout>
 
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 9 - 4
app/src/main/res/layout/fragment_timetable.xml

@@ -12,8 +12,10 @@
         android:layout_height="0dp"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="1.0"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/timetable_toolbar">
+        app:layout_constraintTop_toBottomOf="@+id/timetable_toolbar"
+        app:layout_constraintVertical_bias="1.0">
 
     </androidx.recyclerview.widget.RecyclerView>
 
@@ -25,8 +27,10 @@
         android:elevation="4dp"
         android:visibility="gone"
         app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.0"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent">
+        app:layout_constraintTop_toTopOf="parent"
+        tools:visibility="visible">
 
         <ImageView
             android:id="@+id/back"
@@ -47,8 +51,8 @@
             android:id="@+id/timetable_title"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
-            android:layout_marginStart="32dp"
-            android:layout_marginEnd="32dp"
+            android:layout_marginStart="48dp"
+            android:layout_marginEnd="48dp"
             android:text="@string/placeholder"
             android:textAlignment="center"
             android:textSize="20sp"
@@ -97,6 +101,7 @@
             app:layout_constraintVertical_bias="1.0"
             app:tint="?colorPrimary"
             tools:ignore="ContentDescription" />
+
     </androidx.constraintlayout.widget.ConstraintLayout>
 
 </androidx.constraintlayout.widget.ConstraintLayout>