Archived
Minor interface redesign, including First Time activity
This commit is contained in:
@@ -45,27 +45,22 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(mContext)
|
||||
private val edit = prefs.edit()
|
||||
private lateinit var pullToRefresh: SwipeRefreshLayout
|
||||
private lateinit var progressBar: ProgressBar
|
||||
private val fadeOut = AnimationUtils.loadAnimation(mContext, R.anim.fade_out)
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
var currentTime = ""
|
||||
val substUrl = "https://djd4rkn355.github.io/subst_test.html"
|
||||
val foodUrl = "https://djd4rkn355.github.io/food_test.html"
|
||||
|
||||
override fun doInBackground(vararg params: Void?): Void? {
|
||||
try {
|
||||
mView?.let { v: View ->
|
||||
pullToRefresh = v.findViewById(R.id.pullToRefresh)
|
||||
progressBar = v.findViewById(R.id.progressBar)
|
||||
progressBar.progress = 0
|
||||
}
|
||||
if (menu) {
|
||||
val foodViewModel = FoodViewModel(mApplication)
|
||||
val docFood = Jsoup.connect("https://djd4rkn355.github.io/food.html").get()
|
||||
val docFood = Jsoup.connect(foodUrl).get()
|
||||
val foodElements = docFood.select("th")
|
||||
|
||||
mView?.let {
|
||||
progressBar.max = foodElements.size
|
||||
}
|
||||
|
||||
var foodInt = 0
|
||||
var priority = 0
|
||||
foodViewModel.deleteAll()
|
||||
@@ -115,27 +110,12 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
}
|
||||
foodInt++
|
||||
priority++
|
||||
mView?.let {
|
||||
progressBar.progress = foodInt
|
||||
}
|
||||
}
|
||||
|
||||
mView?.let {
|
||||
progressBar.progress = 100
|
||||
handler.postDelayed({ progressBar.startAnimation(fadeOut) }, 200)
|
||||
fadeOut.setAnimationListener(object: Animation.AnimationListener {
|
||||
override fun onAnimationStart(arg0: Animation) {}
|
||||
override fun onAnimationRepeat(arg0: Animation) {}
|
||||
override fun onAnimationEnd(arg0: Animation) {
|
||||
progressBar.progress = 0
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (plan) {
|
||||
val substViewModel = SubstViewModel(mApplication)
|
||||
val doc = Jsoup.connect("https://djd4rkn355.github.io/subst.html").get()
|
||||
val doc = Jsoup.connect(substUrl).get()
|
||||
currentTime = doc.select("h1")[0].text()
|
||||
if (currentTime != prefs.getString("time", "")) {
|
||||
val rows = doc.select("tr")
|
||||
@@ -148,10 +128,6 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
val roomS = ArrayList<String>()
|
||||
val additionalS = ArrayList<String>()
|
||||
|
||||
mView?.let {
|
||||
progressBar.max = rows.size
|
||||
}
|
||||
|
||||
for (i in 0 until paragraphs.size) {
|
||||
if (i == 0) {
|
||||
informational = paragraphs[i].text()
|
||||
@@ -173,11 +149,6 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
courseS.add(cols[3].text())
|
||||
roomS.add(cols[4].text())
|
||||
additionalS.add(cols[5].text())
|
||||
if (!jobservice) {
|
||||
mView?.let {
|
||||
progressBar.incrementProgressBy(1)
|
||||
}
|
||||
}
|
||||
|
||||
val drawable = MiscData.getIcon(courseS[i])
|
||||
val subst = Subst(drawable, groupS[i], dateS[i], timeS[i], courseS[i],
|
||||
@@ -255,14 +226,6 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
}
|
||||
if (plan || menu) {
|
||||
mView?.let { v: View ->
|
||||
handler.postDelayed({ progressBar.startAnimation(fadeOut) }, 200)
|
||||
fadeOut.setAnimationListener(object: Animation.AnimationListener {
|
||||
override fun onAnimationStart(arg0: Animation) {}
|
||||
override fun onAnimationRepeat(arg0: Animation) {}
|
||||
override fun onAnimationEnd(arg0: Animation) {
|
||||
progressBar.progress = 0
|
||||
}
|
||||
})
|
||||
pullToRefresh.isRefreshing = false
|
||||
if (plan) {
|
||||
val snackBarView = v.findViewById<View>(R.id.coordination)
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package com.denizd.substitutionplan
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.graphics.drawable.AnimatedVectorDrawable
|
||||
import android.graphics.drawable.AnimationDrawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
@@ -15,15 +11,16 @@ import android.preference.PreferenceManager
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewAnimationUtils
|
||||
import android.view.WindowManager
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
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.core.content.ContextCompat
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import java.util.*
|
||||
|
||||
class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
|
||||
@@ -35,25 +32,28 @@ class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val window = this.window
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
||||
window.navigationBarColor = ContextCompat.getColor(this, R.color.background)
|
||||
when (AppCompatDelegate.getDefaultNightMode()) {
|
||||
AppCompatDelegate.MODE_NIGHT_NO -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
||||
window.navigationBarColor = ContextCompat.getColor(this, R.color.background)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
window.navigationBarColor = ContextCompat.getColor(this, R.color.background)
|
||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
|
||||
}
|
||||
}
|
||||
val bm = BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher)
|
||||
val taskDesc = ActivityManager.TaskDescription(getString(R.string.app_name), bm, ContextCompat.getColor(this, R.color.background))
|
||||
setTaskDescription(taskDesc)
|
||||
|
||||
context = this
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(context) as SharedPreferences
|
||||
val edit = prefs.edit()
|
||||
val fab = findViewById<ExtendedFloatingActionButton>(R.id.efab)
|
||||
val start = Intent(this, Main::class.java)
|
||||
val name = findViewById<EditText>(R.id.txtName)
|
||||
val grade = findViewById<EditText>(R.id.txtClasses)
|
||||
val courses = findViewById<EditText>(R.id.txtCourses)
|
||||
val name = findViewById<TextInputEditText>(R.id.txtName)
|
||||
val grade = findViewById<TextInputEditText>(R.id.txtClasses)
|
||||
val courses = findViewById<TextInputEditText>(R.id.txtCourses)
|
||||
val notif = findViewById<CheckBox>(R.id.cbNotif)
|
||||
val dark = findViewById<CheckBox>(R.id.cbDark)
|
||||
val pers = findViewById<CheckBox>(R.id.cbPersonalised)
|
||||
@@ -100,6 +100,7 @@ class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
|
||||
val colour = findViewById<LinearLayout>(R.id.colourLayout)
|
||||
linearInflation.visibility = View.VISIBLE
|
||||
anim.start()
|
||||
fab.hide(true)
|
||||
|
||||
handler.postDelayed({
|
||||
colour.startAnimation(animOut)
|
||||
|
||||
@@ -11,8 +11,6 @@ import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.preference.PreferenceManager
|
||||
import android.view.*
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@@ -24,7 +22,6 @@ import androidx.fragment.app.FragmentTransaction
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.jaredrummler.android.device.DeviceName
|
||||
@@ -33,7 +30,6 @@ import java.util.*
|
||||
|
||||
class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
|
||||
private lateinit var bottomSheetBehaviour: BottomSheetBehavior<*>
|
||||
private lateinit var context: Context
|
||||
private lateinit var prefs: SharedPreferences
|
||||
|
||||
@@ -45,6 +41,7 @@ class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
val firstTime = Intent(context, FirstTime::class.java)
|
||||
|
||||
if (prefs.getBoolean("firstTime", true)) {
|
||||
// if (true) {
|
||||
startActivity(firstTime)
|
||||
finish()
|
||||
} else {
|
||||
@@ -126,70 +123,47 @@ class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
}
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("greeting", false)) {
|
||||
val textViewGreeting = findViewById<TextView>(R.id.text_greeting)
|
||||
if (prefs.getBoolean("greeting", true)) {
|
||||
if ((prefs.getString("username", "") ?: "").isNotEmpty()) {
|
||||
val animationIn = AnimationUtils.loadAnimation(context, R.anim.chip_slide_in)
|
||||
val animationOut = AnimationUtils.loadAnimation(context, R.anim.chip_slide_out)
|
||||
val generator = Random()
|
||||
val greetings = resources.getStringArray(R.array.greeting8_array)
|
||||
val rightNow = Calendar.getInstance()
|
||||
val currentHour = rightNow.get(Calendar.HOUR_OF_DAY)
|
||||
|
||||
chip.text = when (generator.nextInt(9)) {
|
||||
0 -> getString(R.string.greeting0, prefs.getString("username", ""))
|
||||
1 -> getString(R.string.greeting1, prefs.getString("username", ""))
|
||||
2 -> getString(R.string.greeting2, prefs.getString("username", ""))
|
||||
3 -> getString(R.string.greeting3, prefs.getString("username", ""))
|
||||
4 -> getString(R.string.greeting4, prefs.getString("username", ""))
|
||||
5 -> getString(R.string.greeting5, prefs.getString("username", ""))
|
||||
6 -> getString(R.string.greeting6, prefs.getString("username", ""))
|
||||
7 -> getString(R.string.greeting7, prefs.getString("username", ""))
|
||||
8 -> {
|
||||
when {
|
||||
currentHour < 11 -> greetings[0] + prefs.getString("username", "") + "."
|
||||
currentHour in 11..17 -> greetings[1] + prefs.getString("username", "") + "."
|
||||
else -> greetings[1] + prefs.getString("username", "") + "."
|
||||
}
|
||||
}
|
||||
else -> ";)" // getString(R.string.error)
|
||||
}
|
||||
|
||||
handler.postDelayed({
|
||||
chip.visibility = View.VISIBLE
|
||||
chip.startAnimation(animationIn)
|
||||
}, 500)
|
||||
|
||||
handler.postDelayed({
|
||||
chip.startAnimation(animationOut)
|
||||
}, 3000)
|
||||
|
||||
animationOut.setAnimationListener(object: Animation.AnimationListener {
|
||||
override fun onAnimationStart(animation: Animation?) {}
|
||||
override fun onAnimationRepeat(animation: Animation?) {}
|
||||
override fun onAnimationEnd(animation: Animation?) {
|
||||
chip.visibility = View.GONE
|
||||
}
|
||||
})
|
||||
textViewGreeting.text = getGreetingString()
|
||||
// val generator = Random()
|
||||
// val greetings = resources.getStringArray(R.array.greeting8_array)
|
||||
// val rightNow = Calendar.getInstance()
|
||||
// val currentHour = rightNow.get(Calendar.HOUR_OF_DAY)
|
||||
//
|
||||
// textViewGreeting.text = when (generator.nextInt(9)) {
|
||||
// 0 -> getString(R.string.greeting0, prefs.getString("username", ""))
|
||||
// 1 -> getString(R.string.greeting1, prefs.getString("username", ""))
|
||||
// 2 -> getString(R.string.greeting2, prefs.getString("username", ""))
|
||||
// 3 -> getString(R.string.greeting3, prefs.getString("username", ""))
|
||||
// 4 -> getString(R.string.greeting4, prefs.getString("username", ""))
|
||||
// 5 -> getString(R.string.greeting5, prefs.getString("username", ""))
|
||||
// 6 -> getString(R.string.greeting6, prefs.getString("username", ""))
|
||||
// 7 -> getString(R.string.greeting7, prefs.getString("username", ""))
|
||||
// 8 -> {
|
||||
// when {
|
||||
// currentHour < 11 -> greetings[0] + prefs.getString("username", "") + "."
|
||||
// currentHour in 11..17 -> greetings[1] + prefs.getString("username", "") + "."
|
||||
// else -> greetings[1] + prefs.getString("username", "") + "."
|
||||
// }
|
||||
// }
|
||||
// else -> ";)" // getString(R.string.error)
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
textViewGreeting.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (prefs.getInt("firstTimeOpening", 0) == 0) {
|
||||
edit.putInt("firstTimeOpening", prefs.getInt("firstTimeOpening", 0) + 1).apply()
|
||||
}
|
||||
|
||||
val userPlan: String = if ((prefs.getString("username", "") ?: "").toString().isNotEmpty()) {
|
||||
when ((prefs.getString("username", "") ?: "")[(prefs.getString("username", "") ?: "").length - 1].toString().toLowerCase()) {
|
||||
"s", "x", "z" -> (prefs.getString("username", "") ?: "") + getString(R.string.nosplan)
|
||||
else -> (prefs.getString("username", "") ?: "") + getString(R.string.splan)
|
||||
}
|
||||
} else {
|
||||
getString(R.string.personalplan)
|
||||
}
|
||||
lateinit var defaultFragment: Fragment
|
||||
if (prefs.getBoolean("defaultPersonalised", false)) {
|
||||
defaultFragment = PersonalPlanFragment()
|
||||
bottomNav.selectedItemId = R.id.personal
|
||||
toolbarTxt.text = userPlan
|
||||
toolbarTxt.text = getString(R.string.yourplan)
|
||||
} else {
|
||||
defaultFragment = GeneralPlanFragment()
|
||||
bottomNav.selectedItemId = R.id.plan
|
||||
@@ -207,7 +181,7 @@ class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
}
|
||||
R.id.personal -> {
|
||||
fragment = PersonalPlanFragment()
|
||||
toolbarTxt.text = userPlan
|
||||
toolbarTxt.text = getString(R.string.yourplan)
|
||||
}
|
||||
R.id.menu -> {
|
||||
fragment = FoodFragment()
|
||||
@@ -264,6 +238,17 @@ class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getGreetingString(): String {
|
||||
val gen = Random()
|
||||
|
||||
val greetingArray = when (Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) {
|
||||
in 5..10 -> resources.getStringArray(R.array.greetings_morning)
|
||||
in 11..17 -> resources.getStringArray(R.array.greetings_noon)
|
||||
else -> resources.getStringArray(R.array.greetings_evening)
|
||||
}
|
||||
return String.format(greetingArray[gen.nextInt(7)], prefs.getString("username", ""))
|
||||
}
|
||||
|
||||
private fun openInfoDialog() {
|
||||
val dialog = AlertDialog.Builder(context)
|
||||
val dialogView = LayoutInflater.from(context).inflate(R.layout.simple_dialog, null)
|
||||
|
||||
@@ -39,7 +39,6 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
private var cs: Int = 7
|
||||
private var window: Window? = null
|
||||
private lateinit var colourRecycler: RecyclerView
|
||||
private lateinit var colourAdapter: ColourAdapter
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
|
||||
Reference in New Issue
Block a user