Archived
Implemented login functionality at the school's request
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.denizd.substitutionplan.activities
|
||||
|
||||
import android.animation.LayoutTransition
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
@@ -18,7 +19,7 @@ import android.widget.*
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
||||
import com.denizd.substitutionplan.R
|
||||
@@ -38,6 +39,9 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
|
||||
val window = this.window
|
||||
context = this
|
||||
|
||||
val parentLayout = findViewById<ConstraintLayout>(R.id.coordinatorLayout)
|
||||
parentLayout.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
|
||||
|
||||
val barColour = when {
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.M -> ContextCompat.getColor(context, R.color.legacyBlack)
|
||||
Build.VERSION.SDK_INT <= Build.VERSION_CODES.P -> ContextCompat.getColor(context, R.color.colorBackground)
|
||||
@@ -111,12 +115,11 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
|
||||
.putBoolean("colourTransferred", true)
|
||||
.apply()
|
||||
|
||||
val cLayout = findViewById<CoordinatorLayout>(R.id.coordinatorLayout)
|
||||
val linearInflation = findViewById<LinearLayout>(R.id.linearInflation)
|
||||
|
||||
val x: Int = fab.right - fab.width / 2
|
||||
val y: Int = fab.bottom- fab.height / 2
|
||||
val endRadius = hypot(cLayout.width.toDouble(), cLayout.height.toDouble()).toInt()
|
||||
val y: Int = fab.bottom - fab.height / 2
|
||||
val endRadius = hypot(parentLayout.width.toDouble(), parentLayout.height.toDouble()).toInt()
|
||||
inflater.inflate(R.layout.welcome_screen, linearInflation, true)
|
||||
val anim = ViewAnimationUtils.createCircularReveal(linearInflation, x, y, 0F, endRadius.toFloat())
|
||||
val handler = Handler()
|
||||
@@ -147,11 +150,11 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
|
||||
val mImgCheck = findViewById<ImageView>(R.id.imageView).drawable as AnimatedVectorDrawableCompat
|
||||
mImgCheck.start()
|
||||
}
|
||||
}, 1000)
|
||||
}, 600)
|
||||
handler.postDelayed({
|
||||
startActivity(mainActivity)
|
||||
finish()
|
||||
}, 2000)
|
||||
}, 3000)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.denizd.substitutionplan.activities
|
||||
|
||||
import android.animation.LayoutTransition
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.drawable.AnimatedVectorDrawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.preference.PreferenceManager
|
||||
import android.view.View
|
||||
import android.view.ViewAnimationUtils
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
import android.webkit.WebView
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
||||
import com.denizd.substitutionplan.R
|
||||
import com.denizd.substitutionplan.data.LoginWebViewClient
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
import kotlin.math.hypot
|
||||
|
||||
internal class Login : AppCompatActivity(R.layout.activity_login_webview), LoginWebViewClient.OnLoginSuccessListener {
|
||||
|
||||
private lateinit var prefs: SharedPreferences
|
||||
private lateinit var parentLayout: ConstraintLayout
|
||||
private lateinit var logInButton: ExtendedFloatingActionButton
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setTheme(R.style.AppTheme0)
|
||||
parentLayout = findViewById(R.id.constraintLayout)
|
||||
parentLayout.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
|
||||
val title = findViewById<TextView>(R.id.txtWelcome)
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
val barColour = when {
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.M -> ContextCompat.getColor(this, R.color.legacyBlack)
|
||||
Build.VERSION.SDK_INT <= Build.VERSION_CODES.P -> ContextCompat.getColor(this, R.color.colorBackground)
|
||||
else -> 0
|
||||
}
|
||||
if (barColour != 0) {
|
||||
window.navigationBarColor = barColour
|
||||
window.statusBarColor = barColour
|
||||
}
|
||||
if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_NO) {
|
||||
if (Build.VERSION.SDK_INT in 23..28) {
|
||||
@SuppressLint("InlinedApi")
|
||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
||||
}
|
||||
}
|
||||
|
||||
logInButton = findViewById(R.id.loginFab)
|
||||
logInButton.setOnClickListener {
|
||||
findViewById<LinearLayout>(R.id.linearLayout).apply {
|
||||
logInButton.hide()
|
||||
removeAllViews()
|
||||
title.text = getString(R.string.logging_in)
|
||||
val view = View.inflate(this@Login, R.layout.webview, null)
|
||||
addView(view)
|
||||
val webView = view.findViewById<WebView>(R.id.webView)
|
||||
webView.webViewClient = LoginWebViewClient(this@Login)
|
||||
openLoginPage(webView)
|
||||
handler.postDelayed({
|
||||
webView.scrollY = -4000
|
||||
}, 2000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLoginSucceeded(success: Boolean) {
|
||||
if (success) {
|
||||
success()
|
||||
}
|
||||
}
|
||||
|
||||
private fun openLoginPage(webView: WebView) {
|
||||
webView.loadUrl("https://307.joomla.schule.bremen.de/index.php/component/users/#top")
|
||||
}
|
||||
|
||||
private fun success() {
|
||||
prefs.edit().putBoolean("successful_login", true).apply()
|
||||
|
||||
val layoutAfterCircleReveal = findViewById<LinearLayout>(R.id.layoutAfterCircleReveal)
|
||||
|
||||
val x: Int = logInButton.right - logInButton.width / 2
|
||||
val y: Int = logInButton.bottom - logInButton.height / 2
|
||||
val endRadius = hypot(parentLayout.width.toDouble(), parentLayout.height.toDouble()).toInt()
|
||||
View.inflate(this, R.layout.unlock_screen, layoutAfterCircleReveal)
|
||||
val anim = ViewAnimationUtils.createCircularReveal(layoutAfterCircleReveal, x, y, 0F, endRadius.toFloat())
|
||||
val handler = Handler()
|
||||
val animOut = AnimationUtils.loadAnimation(this, R.anim.fade_out_short)
|
||||
anim.duration = 600
|
||||
val colour = findViewById<LinearLayout>(R.id.colourLayout)
|
||||
layoutAfterCircleReveal.visibility = View.VISIBLE
|
||||
anim.start()
|
||||
logInButton.hide()
|
||||
|
||||
handler.postDelayed({
|
||||
colour.startAnimation(animOut)
|
||||
}, 400)
|
||||
animOut.setAnimationListener(object: Animation.AnimationListener {
|
||||
override fun onAnimationStart(arg0: Animation) {}
|
||||
override fun onAnimationRepeat(arg0: Animation) {}
|
||||
override fun onAnimationEnd(arg0: Animation) {
|
||||
colour.visibility = View.GONE
|
||||
}
|
||||
})
|
||||
handler.postDelayed({
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
|
||||
val mImgCheck = findViewById<ImageView>(R.id.imageView).drawable as AnimatedVectorDrawable
|
||||
mImgCheck.start()
|
||||
} else {
|
||||
val mImgCheck = findViewById<ImageView>(R.id.imageView).drawable as AnimatedVectorDrawableCompat
|
||||
mImgCheck.start()
|
||||
}
|
||||
}, 600)
|
||||
handler.postDelayed({
|
||||
val main = Intent(this, Main::class.java)
|
||||
startActivity(main)
|
||||
finish()
|
||||
}, 3000)
|
||||
}
|
||||
}
|
||||
@@ -43,13 +43,17 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
context = this
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(context) as SharedPreferences
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val edit = prefs.edit()
|
||||
val firstTime = Intent(context, FirstTime::class.java)
|
||||
val login = Intent(context, Login::class.java)
|
||||
Crashlytics.setUserIdentifier(prefs.getString("username", "") ?: "")
|
||||
|
||||
if (prefs.getBoolean("firstTime", true)) {
|
||||
// if (true) {
|
||||
if (!prefs.getBoolean("successful_login", false)) {
|
||||
startActivity(login)
|
||||
finish()
|
||||
} else if (prefs.getBoolean("firstTime", true)) {
|
||||
// } else if (true) {
|
||||
startActivity(firstTime)
|
||||
finish()
|
||||
} else {
|
||||
@@ -238,10 +242,10 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
}
|
||||
|
||||
private fun personalPlanTitle(): String {
|
||||
return if (prefs.getBoolean("greeting", true)) {
|
||||
val user = prefs.getString("username", "") ?: ""
|
||||
return if (prefs.getBoolean("greeting", true) || user.isEmpty()) {
|
||||
getString(R.string.yourPlan)
|
||||
} else {
|
||||
val user = prefs.getString("username", "") ?: ""
|
||||
if (user.endsWith("s", true) || user.endsWith("x", true) || user.endsWith("z", true)) {
|
||||
"$user${getString(R.string.noSPlan)}"
|
||||
} else {
|
||||
|
||||
@@ -29,10 +29,7 @@ internal class ColourAdapter(private var mColours: List<Colour>, onClickListener
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ColourViewHolder {
|
||||
val v = LayoutInflater.from(parent.context).inflate(R.layout.list_item, parent, false)
|
||||
return ColourViewHolder(
|
||||
v,
|
||||
mOnClickListener
|
||||
)
|
||||
return ColourViewHolder(v, mOnClickListener)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ColourViewHolder, position: Int) {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.denizd.substitutionplan.data
|
||||
|
||||
import android.webkit.CookieManager
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
|
||||
/**
|
||||
* class that extends WebViewClient to provide a function that checks the webpage's cookies to
|
||||
* verify a login
|
||||
*
|
||||
* @param successListener a reference to the OnLoginSuccessListener implemented in an activity
|
||||
*/
|
||||
internal class LoginWebViewClient(successListener: OnLoginSuccessListener) : WebViewClient() {
|
||||
|
||||
private val mSuccessListener = successListener
|
||||
|
||||
/**
|
||||
* onPageFinished has been overridden to check if the cookie "joomla_user_state=logged_in"
|
||||
* exists, and returns true to the OnLoginSuccessListener
|
||||
*
|
||||
* @param view a reference to the WebView
|
||||
* @param url a reference to the url of the WebView
|
||||
*/
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
super.onPageFinished(view, url)
|
||||
val cookies = CookieManager.getInstance().getCookie(url)
|
||||
|
||||
if (cookies.contains("joomla_user_state=logged_in")) {
|
||||
mSuccessListener.onLoginSucceeded(true)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* the interface that provides onLoginSucceeded to the activity or fragment that implements it
|
||||
*/
|
||||
internal interface OnLoginSuccessListener {
|
||||
|
||||
/**
|
||||
* the function that can be overridden to check whether a successful login has occurred
|
||||
*
|
||||
* @param success boolean value that returns true if the cookie could be found,
|
||||
* false otherwise
|
||||
*/
|
||||
fun onLoginSucceeded(success: Boolean)
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,6 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
|
||||
private lateinit var prefs: SharedPreferences
|
||||
private val builder = CustomTabsIntent.Builder()
|
||||
private val customTabsIntent = builder.build() as CustomTabsIntent
|
||||
private var cs: Int = 7
|
||||
private var window: Window? = null
|
||||
private lateinit var colourRecycler: RecyclerView
|
||||
private lateinit var ringtoneCustomiserDialog: AlertDialog
|
||||
@@ -253,19 +252,6 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
|
||||
"\n---\n" +
|
||||
"\nThis privacy policy was modified upon the template provided by privacypolicytemplate.net and App Privacy Policy Generator. These services are in no way affiliated with AvH Plan or the developer.")
|
||||
}
|
||||
R.id.btnVersion -> {
|
||||
if (cs > 0) {
|
||||
cs--
|
||||
} else {
|
||||
try {
|
||||
cs = 7
|
||||
customTabsIntent.launchUrl(mContext, Uri.parse("http://www.flussufer.de/gerd/person.htm"))
|
||||
makeToast(getString(R.string.dontTellHim))
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
makeToast(getString(R.string.chromeCompatibleNotFound))
|
||||
}
|
||||
}
|
||||
}
|
||||
R.id.btnForceRefresh -> {
|
||||
DataFetcher(
|
||||
isPlan = true,
|
||||
|
||||
@@ -25,28 +25,30 @@ internal class FBPingService : JobService() {
|
||||
private fun doBackgroundWork(params: JobParameters) {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
FirebaseApp.initializeApp(context)
|
||||
FirebaseMessaging.getInstance().apply {
|
||||
if (prefs.getBoolean("notif", true)) {
|
||||
subscribeToTopic(Topic.ANDROID.tag)
|
||||
} else {
|
||||
unsubscribeFromTopic(Topic.ANDROID.tag)
|
||||
if (!prefs.getBoolean("firstTime", true)) {
|
||||
FirebaseMessaging.getInstance().apply {
|
||||
if (prefs.getBoolean("notif", true)) {
|
||||
subscribeToTopic(Topic.ANDROID.tag)
|
||||
} else {
|
||||
unsubscribeFromTopic(Topic.ANDROID.tag)
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("subscribedToFBDebugChannel", false)) {
|
||||
subscribeToTopic(Topic.DEVELOPMENT.tag)
|
||||
} else {
|
||||
unsubscribeFromTopic(Topic.DEVELOPMENT.tag)
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("subscribedToiOSChannel", false)) {
|
||||
subscribeToTopic(Topic.IOS.tag)
|
||||
} else {
|
||||
unsubscribeFromTopic(Topic.IOS.tag)
|
||||
}
|
||||
|
||||
subscribeToTopic(Topic.BROADCAST.tag)
|
||||
|
||||
prefs.edit().putInt("pingFB", prefs.getInt("pingFB", 0) + 1).apply()
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("subscribedToFBDebugChannel", false)) {
|
||||
subscribeToTopic(Topic.DEVELOPMENT.tag)
|
||||
} else {
|
||||
unsubscribeFromTopic(Topic.DEVELOPMENT.tag)
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("subscribedToiOSChannel", false)) {
|
||||
subscribeToTopic(Topic.IOS.tag)
|
||||
} else {
|
||||
unsubscribeFromTopic(Topic.IOS.tag)
|
||||
}
|
||||
|
||||
subscribeToTopic(Topic.BROADCAST.tag)
|
||||
|
||||
prefs.edit().putInt("pingFB", prefs.getInt("pingFB", 0) + 1).apply()
|
||||
}
|
||||
jobFinished(params, false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user