Ethosa пре 3 година
родитељ
комит
824f500fb1

+ 5 - 0
app/src/main/java/com/ethosa/ktc/Constants.kt

@@ -19,5 +19,10 @@ sealed class Constants {
         const val GOOGLE_PLAY_PACKAGE = "com.android.vending"
         // When google services isn't available on phone
         const val GITHUB_RELEASES_URL = "https://github.com/Ethosa/KTC/releases"
+        const val GITHUB_REPO_URL = "https://github.com/Ethosa/KTC"
+
+        // Pro college
+        const val LOGIN_USERNAME = "username"
+        const val LOGIN_PASSWORD = "password"
     }
 }

+ 45 - 0
app/src/main/java/com/ethosa/ktc/Preferences.kt

@@ -7,6 +7,7 @@ import com.ethosa.ktc.college.timetable.Group
 
 /**
  * Provides working with SharedPreferences
+ * @param context app context
  */
 class Preferences(
     context: Context
@@ -24,6 +25,10 @@ class Preferences(
         var isStudent = true
         var week = 0
         var timetableState = 0
+
+        // Pro college
+        var proCollegeUsername = ""
+        var proCollegePassword = ""
     }
 
     /**
@@ -41,8 +46,38 @@ class Preferences(
         )
         week = preferences.getInt(Constants.TIMETABLE_WEEK, 0)
         isStudent = preferences.getBoolean(Constants.TIMETABLE_IS_STUDENT, true)
+
+        proCollegeUsername = preferences.getString(Constants.LOGIN_USERNAME, "")!!
+        proCollegePassword = preferences.getString(Constants.LOGIN_PASSWORD, "")!!
+    }
+
+    /**
+     * Clears current timetable state
+     */
+    fun clearTimetable() {
+        preferences.edit()
+            .putInt(Constants.TIMETABLE_STATE, 0)
+            .putString(Constants.TIMETABLE_GROUP_TITLE, "")
+            .putInt(Constants.TIMETABLE_GROUP, 0)
+            .putBoolean(Constants.TIMETABLE_IS_STUDENT, true)
+            .putInt(Constants.TIMETABLE_BRANCH, 0)
+            .putInt(Constants.TIMETABLE_WEEK, 0)
+            .apply()
+    }
+
+    /**
+     * Clears current pro college state
+     */
+    fun clearProCollege() {
+        preferences.edit()
+            .putString(Constants.LOGIN_USERNAME, "")
+            .putString(Constants.LOGIN_PASSWORD, "")
+            .apply()
     }
 
+    /**
+     * Saves current timetable state
+     */
     fun saveTimetable() {
         preferences.edit()
             .putInt(Constants.TIMETABLE_STATE, timetableState)
@@ -53,4 +88,14 @@ class Preferences(
             .putInt(Constants.TIMETABLE_WEEK, week)
             .apply()
     }
+
+    /**
+     * Saves current pro college state
+     */
+    fun saveProCollege() {
+        preferences.edit()
+            .putString(Constants.LOGIN_USERNAME, proCollegeUsername)
+            .putString(Constants.LOGIN_PASSWORD, proCollegePassword)
+            .apply()
+    }
 }

+ 2 - 2
app/src/main/java/com/ethosa/ktc/ui/fragments/AboutAppFragment.kt

@@ -7,6 +7,7 @@ import androidx.fragment.app.Fragment
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import com.ethosa.ktc.Constants
 import com.ethosa.ktc.databinding.FragmentAboutAppBinding
 import com.ethosa.ktc.ui.dialog.AppUpdater
 
@@ -25,11 +26,10 @@ class AboutAppFragment : Fragment() {
         _binding = FragmentAboutAppBinding.inflate(inflater, container, false)
 
         binding.appVersion.text = AppUpdater.version
-
         binding.authorGithub.setOnClickListener {
             // Go to Github repo
             val intent = Intent(Intent.ACTION_VIEW)
-            intent.data = Uri.parse("https://github.com/ethosa/ktc")
+            intent.data = Uri.parse(Constants.GITHUB_REPO_URL)
             startActivity(intent)
         }
 

+ 0 - 1
app/src/main/java/com/ethosa/ktc/ui/fragments/ContactInfoFragment.kt

@@ -5,7 +5,6 @@ import androidx.fragment.app.Fragment
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
-import com.ethosa.ktc.R
 import com.ethosa.ktc.databinding.FragmentContactInfoBinding
 
 

+ 1 - 2
app/src/main/java/com/ethosa/ktc/ui/fragments/GalleryFragment.kt

@@ -68,8 +68,7 @@ class GalleryFragment(
             _binding?.progressLoad, "alpha",
             1f,
             0f
-        )
-        animate.duration = 500
+        ).setDuration(500)
         activity?.runOnUiThread {
             _binding?.albumsList?.adapter = AlbumsPreviewAdapter(albums)
             animate.start()

+ 1 - 2
app/src/main/java/com/ethosa/ktc/ui/fragments/NewsFragment.kt

@@ -61,8 +61,7 @@ class NewsFragment : Fragment(), CollegeCallback {
         val animate = ObjectAnimator.ofFloat(
             _binding?.progressLoad, "alpha",
             1f, 0f
-        )
-        animate.duration = 500
+        ).setDuration(500)
         activity?.runOnUiThread {
             animate.start()
             _binding?.newsContainer?.adapter = NewsAdapter(news.anonce + news.news)

+ 6 - 14
app/src/main/java/com/ethosa/ktc/ui/fragments/ProCollegeFragment.kt

@@ -1,7 +1,5 @@
 package com.ethosa.ktc.ui.fragments
 
-import android.content.Context
-import android.content.SharedPreferences
 import android.content.res.Configuration
 import android.os.Bundle
 import androidx.fragment.app.Fragment
@@ -14,6 +12,7 @@ import androidx.webkit.WebSettingsCompat
 import androidx.webkit.WebSettingsCompat.FORCE_DARK_OFF
 import androidx.webkit.WebSettingsCompat.FORCE_DARK_ON
 import androidx.webkit.WebViewFeature
+import com.ethosa.ktc.Preferences
 import com.ethosa.ktc.college.ProCollege
 import com.ethosa.ktc.databinding.FragmentProCollegeBinding
 
@@ -25,12 +24,7 @@ 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"
-    }
+    private lateinit var preferences: Preferences
 
     override fun onCreateView(
         inflater: LayoutInflater,
@@ -40,12 +34,11 @@ class ProCollegeFragment : Fragment() {
         _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, ""))
+        preferences = Preferences(requireContext())
+        preferences.load()
 
         // Auto dark mode ...
+        // Require API Q+
         if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
             when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
                 Configuration.UI_MODE_NIGHT_YES -> {
@@ -73,8 +66,7 @@ class ProCollegeFragment : Fragment() {
             // 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()
+            preferences.saveProCollege()
             proCollege.auth(
                 binding.username.editText?.text.toString(),
                 binding.password.editText?.text.toString()