Visual bugfixes: first time screen now shows status bar icons in dark mode, long names now don't cut off anymore in toolbar, status bar colour corrected on some devices. First time screen hides dark mode toggle and defaults to "conform to system setting" on Android 10 and above

This commit is contained in:
Deniz Düzgören
2019-09-11 20:59:55 +02:00
parent 48ec7f8829
commit 0398b846e5
12 changed files with 160 additions and 256 deletions
@@ -1,5 +1,6 @@
package com.denizd.substitutionplan.activities
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
@@ -35,38 +36,24 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
super.onCreate(savedInstanceState)
val window = this.window
context = this
when (AppCompatDelegate.getDefaultNightMode()) {
AppCompatDelegate.MODE_NIGHT_NO, AppCompatDelegate.MODE_NIGHT_UNSPECIFIED -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
window.statusBarColor = ContextCompat.getColor(this,
R.color.colorBackground
)
window.navigationBarColor = ContextCompat.getColor(this,
R.color.colorBackground
)
} else {
window.statusBarColor = ContextCompat.getColor(this,
R.color.legacyBlack
)
window.navigationBarColor = ContextCompat.getColor(this,
R.color.legacyBlack
)
}
}
else -> {
window.navigationBarColor = ContextCompat.getColor(this,
R.color.colorBackground
)
window.statusBarColor = ContextCompat.getColor(this,
R.color.colorBackground
)
// window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
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)
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
}
}
context = this
prefs = PreferenceManager.getDefaultSharedPreferences(context) as SharedPreferences
val edit = prefs.edit()
val fab = findViewById<ExtendedFloatingActionButton>(R.id.efab)
@@ -81,6 +68,10 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
val helpCourses = findViewById<ImageButton>(R.id.chipHelpCourses)
val greeting = findViewById<CheckBox>(R.id.cbGreetings)
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
dark.visibility = View.GONE
}
helpClasses.setOnClickListener {
createDialog(getString(R.string.enterGradeHelpTitle), getString(
R.string.enterGradeHelp
@@ -94,23 +85,6 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
val inflater = this.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
// findViewById<MaterialButton>(R.id.btnRestoreFromFile).setOnClickListener {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 42)
// }
// HelperFunctions.readPrefsFromXml(prefs)
// name.setText(prefs.getString("username", ""))
// grade.setText(prefs.getString("classes", ""))
// courses.setText(prefs.getString("courses", ""))
// notif.isChecked = prefs.getBoolean("notif", false)
// dark.isChecked = when (prefs.getInt("themeInt", 0)) {
// 0 -> true
// else -> false
// }
// greeting.isChecked = prefs.getBoolean("greeting", false)
// pers.isChecked = prefs.getBoolean("defaultPersonalised", false)
// }
fab.setOnClickListener {
fab.isClickable = false
@@ -118,11 +92,16 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
.putString("username", name.text.toString())
.putString("classes", grade.text.toString())
.putString("courses", courses.text.toString())
if (dark.isChecked) {
edit.putInt("themeInt", 1)
val themeInt = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
2
} else {
edit.putInt("themeInt", 0)
if (dark.isChecked) {
1
} else {
0
}
}
edit.putInt("themeInt", themeInt)
edit.putBoolean("notif", notif.isChecked)
.putBoolean("greeting", greeting.isChecked)
.putBoolean("defaultPersonalised", pers.isChecked)
@@ -146,7 +125,7 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
val colour = findViewById<LinearLayout>(R.id.colourLayout)
linearInflation.visibility = View.VISIBLE
anim.start()
fab.hide(true)
fab.hide()
handler.postDelayed({
colour.startAnimation(animOut)
@@ -1,5 +1,6 @@
package com.denizd.substitutionplan.activities
import android.annotation.SuppressLint
import android.app.job.JobInfo
import android.app.job.JobScheduler
import android.content.ComponentName
@@ -31,7 +32,6 @@ import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.FirebaseApp
import com.jaredrummler.android.device.DeviceName
import java.lang.IllegalArgumentException
import java.util.*
@@ -73,21 +73,22 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
setTheme(R.style.AppTheme0)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
window.statusBarColor = ContextCompat.getColor(this,
R.color.legacyBlack
)
window.navigationBarColor = ContextCompat.getColor(this,
R.color.legacyBlack
)
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)
else -> 0
}
if (barColour != 0) {
window.navigationBarColor = barColour
window.statusBarColor = barColour
}
when (prefs.getInt("themeInt", 0)) {
0 -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
if (Build.VERSION.SDK_INT in 23..28) {
@SuppressLint("InlinedApi")
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
window.navigationBarColor = ContextCompat.getColor(context, R.color.colorBackground)
}
}
2 -> {
@@ -95,9 +96,6 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
}
else -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
window.navigationBarColor = ContextCompat.getColor(context, R.color.colorBackground)
}
}
}
@@ -107,24 +105,6 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
} catch (e: IllegalArgumentException) {}
}
if (prefs.getBoolean("huaweiDeviceDialog", true)) {
DeviceName.with(context).request { info, _ ->
if (info.manufacturer.contains("Huawei") ||
info.manufacturer.contains("Honor") ||
info.manufacturer.contains("Xiaomi")) {
val alertDialog = AlertDialog.Builder(context, R.style.AlertDialog)
val dialogView = LayoutInflater.from(context).inflate(R.layout.secret_dialog, null)
val title = dialogView.findViewById<TextView>(R.id.textviewtitle)
title.text = getString(R.string.chineseDevicesTitle)
val dialogText = dialogView.findViewById<TextView>(R.id.dialogtext)
dialogText.text = getString(R.string.chineseDevicesHelp)
alertDialog.setView(dialogView).show()
edit.putBoolean("huaweiDeviceDialog", false).apply()
}
}
}
val textViewGreeting = findViewById<TextView>(R.id.text_greeting)
if (prefs.getBoolean("greeting", true)) {
if ((prefs.getString("username", "") ?: "").isNotEmpty()) {
@@ -1,8 +1,8 @@
package com.denizd.substitutionplan.adapters
import android.content.ActivityNotFoundException
import android.content.SharedPreferences
import android.net.Uri
import android.preference.PreferenceManager
import android.text.SpannableString
import android.text.style.StrikethroughSpan
import android.view.LayoutInflater
@@ -20,7 +20,7 @@ import com.denizd.substitutionplan.models.Subst
import com.google.android.material.card.MaterialCardView
import java.util.*
internal class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapter<CardAdapter.CardViewHolder>() {
internal class CardAdapter(private var mSubst: List<Subst>, private val prefs: SharedPreferences) : RecyclerView.Adapter<CardAdapter.CardViewHolder>() {
private var colour = 0
private var colourString = ""
@@ -28,25 +28,25 @@ internal class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapt
class CardViewHolder(view: View) : RecyclerView.ViewHolder(view), View.OnClickListener {
var mImageView: ImageView = view.findViewById(R.id.iconView)
var mGroup: TextView = view.findViewById(R.id.group)
var mDate: TextView = view.findViewById(R.id.date)
var mTime: TextView = view.findViewById(R.id.time)
var mCourse: TextView = view.findViewById(R.id.course)
var mRoom: TextView = view.findViewById(R.id.room)
var mAdditional: TextView = view.findViewById(R.id.additional)
var spacer: TextView = view.findViewById(R.id.spacer)
var iconView: ImageView = view.findViewById(R.id.iconView)
var group: TextView = view.findViewById(R.id.group)
var date: TextView = view.findViewById(R.id.date)
var time: TextView = view.findViewById(R.id.time)
var course: TextView = view.findViewById(R.id.course)
var room: TextView = view.findViewById(R.id.room)
var additional: TextView = view.findViewById(R.id.additional)
var teacher: TextView = view.findViewById(R.id.teacher)
var spacer: TextView = view.findViewById(R.id.spacer)
var mCard: MaterialCardView = view.findViewById(R.id.planCard)
var card: MaterialCardView = view.findViewById(R.id.planCard)
init { view.setOnClickListener(this) }
override fun onClick(v: View?) {
if (mDate.text.toString().length > 7 && mDate.text.toString().substring(3, 7) == "http") {
if (date.text.toString().length > 7 && date.text.toString().substring(3, 7) == "http") {
try {
CustomTabsIntent.Builder().build().launchUrl(mCard.context,
Uri.parse(mDate.text.toString().substring(3)))
CustomTabsIntent.Builder().build().launchUrl(card.context,
Uri.parse(date.text.toString().substring(3)))
} catch (e: ActivityNotFoundException) {
Toast.makeText(mCard.context, mCard.context.getString(R.string.chromeCompatibleNotFound), Toast.LENGTH_LONG).show()
Toast.makeText(card.context, card.context.getString(R.string.chromeCompatibleNotFound), Toast.LENGTH_LONG).show()
}
}
}
@@ -59,70 +59,60 @@ internal class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapt
override fun onBindViewHolder(holder: CardViewHolder, position: Int) {
val currentItem = mSubst[position]
val prefs = PreferenceManager.getDefaultSharedPreferences(holder.mImageView.context)
var psa = false
val strings = arrayOf(SpannableString(currentItem.group), SpannableString(currentItem.time),
SpannableString(currentItem.course), SpannableString(currentItem.room), SpannableString(currentItem.teacher))
for (item in strings) {
val qmark = item.indexOf("?")
if (qmark != -1) {
item.setSpan(StrikethroughSpan(), 0, qmark, 0)
var cardBackgroundColour = 0
for (string in strings) {
val questionMarkIndex = string.indexOf("?")
if (questionMarkIndex != -1) {
string.setSpan(StrikethroughSpan(), 0, questionMarkIndex, 0)
}
}
with (currentItem.additional.toLowerCase(Locale.ROOT)) {
if (contains("eigenverantwortliches arbeiten") || contains("entfall") || contains("fällt aus")) {
strings[2].setSpan(StrikethroughSpan(), 0, strings[2].length, 0)
strings[3].setSpan(StrikethroughSpan(), 0, strings[3].length, 0)
strings[4].setSpan(StrikethroughSpan(), 0, strings[4].length, 0)
for (i in 2..4) { strings[i].setSpan(StrikethroughSpan(), 0, strings[i].length, 0) }
}
}
holder.mImageView.setImageResource(HelperFunctions.getIconForCourse(currentItem.course))
holder.mGroup.setText(strings[0], TextView.BufferType.SPANNABLE)
holder.mTime.setText(strings[1], TextView.BufferType.SPANNABLE)
holder.mCourse.setText(strings[2], TextView.BufferType.SPANNABLE)
holder.mRoom.setText(strings[3], TextView.BufferType.SPANNABLE)
var icon = HelperFunctions.getIconForCourse(currentItem.course)
holder.group.setText(strings[0], TextView.BufferType.SPANNABLE)
holder.time.setText(strings[1], TextView.BufferType.SPANNABLE)
holder.course.setText(strings[2], TextView.BufferType.SPANNABLE)
holder.room.setText(strings[3], TextView.BufferType.SPANNABLE)
holder.teacher.setText(strings[4], TextView.BufferType.SPANNABLE)
holder.mAdditional.text = currentItem.additional
holder.additional.text = currentItem.additional
if (currentItem.date.isNotEmpty() && currentItem.date.substring(0, 3) == "psa") {
holder.date.visibility = if (currentItem.date.isNotEmpty() && currentItem.date.substring(0, 3) == "psa") {
psa = true
holder.mDate.visibility = View.GONE
holder.mDate.text = currentItem.date
holder.mTime.text = " "
holder.mImageView.setImageResource(R.drawable.ic_idea)
holder.mCard.setCardBackgroundColor(ContextCompat.getColor(holder.mImageView.context,
R.color.colorAccent
))
holder.time.text = " "
icon = R.drawable.ic_idea
cardBackgroundColour = R.color.colorAccent
View.GONE
} else {
holder.mDate.visibility = View.VISIBLE
holder.mDate.text = currentItem.date
}
if (!psa) {
colourString = getColourString(holder.mCourse.text.toString())
colourString = getColourString(holder.course.text.toString())
val colourPrefsInt = if (colourString.isNotEmpty()) {
prefs.getString("card$colourString", "") ?: ""
} else {
""
}
colour = HelperFunctions.getColourForString(colourPrefsInt)
if (colour != 0) {
holder.mCard.setCardBackgroundColor(ContextCompat.getColor(holder.mCourse.context, colour))
cardBackgroundColour = if (colour != 0) {
colour
} else {
holder.mCard.setCardBackgroundColor(ContextCompat.getColor(holder.mCourse.context,
R.color.colorBackgroundLight
))
R.color.colorBackgroundLight
}
View.VISIBLE
}
holder.date.text = currentItem.date
holder.spacer.visibility = if (strings[2].isEmpty() || strings[4].isEmpty()) {
View.GONE
} else {
View.VISIBLE
}
val textColor = ContextCompat.getColor(holder.mImageView.context, if (psa) {
val textColor = ContextCompat.getColor(holder.iconView.context, if (psa) {
R.color.colorBackground
} else {
when (colour) {
@@ -131,13 +121,15 @@ internal class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapt
else -> R.color.colorText
}
})
holder.mImageView.setColorFilter(textColor)
holder.mGroup.setTextColor(textColor)
holder.mDate.setTextColor(textColor)
holder.mTime.setTextColor(textColor)
holder.mCourse.setTextColor(textColor)
holder.mRoom.setTextColor(textColor)
holder.mAdditional.setTextColor(textColor)
holder.card.setCardBackgroundColor(ContextCompat.getColor(holder.iconView.context, cardBackgroundColour))
holder.iconView.setImageResource(icon)
holder.iconView.setColorFilter(textColor)
holder.group.setTextColor(textColor)
holder.date.setTextColor(textColor)
holder.time.setTextColor(textColor)
holder.course.setTextColor(textColor)
holder.room.setTextColor(textColor)
holder.additional.setTextColor(textColor)
holder.spacer.setTextColor(textColor)
holder.teacher.setTextColor(textColor)
}
@@ -9,9 +9,7 @@ import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.graphics.Color
import android.os.Environment
import android.util.Log
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.core.app.ActivityCompat.requestPermissions
import androidx.core.content.ContextCompat.checkSelfPermission
import androidx.fragment.app.FragmentActivity
@@ -31,7 +29,8 @@ internal object HelperFunctions {
val colourNames = arrayOf("default", "red", "orange", "yellow", "green", "teal", "cyan", "blue", "purple", "pink",
"brown", "grey", "pureWhite", "salmon", "tangerine", "banana", "flora", "spindrift", "sky", "orchid",
"lavender", "carnation", "brown2", "pureBlack")
private val colourIntegers = intArrayOf(0,
private val colourIntegers = intArrayOf(
0,
R.color.bgRed,
R.color.bgOrange,
R.color.bgYellow,
@@ -250,7 +249,6 @@ internal object HelperFunctions {
for (i in localPrefTypes.indices) {
val key = document.getElementsByTagName("key").item(i).textContent
val value = document.getElementsByTagName("value").item(i).textContent
Log.d("VALUES", "$key $value")
setPrefValue(prefs, key, value, localPrefTypes[i])
}
Toast.makeText(context, context.getString(R.string.success), Toast.LENGTH_LONG).show()
@@ -19,8 +19,7 @@ internal abstract class SubstDatabase : RoomDatabase() {
private var instance: SubstDatabase? = null
private val addTeacherColumn = object : Migration(5, 6) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
"ALTER TABLE subst_table ADD COLUMN teacher TEXT NOT NULL DEFAULT ''")
database.execSQL("ALTER TABLE subst_table ADD COLUMN teacher TEXT NOT NULL DEFAULT ''")
}
}
@@ -57,7 +57,7 @@ internal open class PlanFragment : Fragment(R.layout.plan) {
layoutManager = GridLayoutManager(mContext, getGridColumnCount(resources.configuration))
recyclerView.layoutManager = layoutManager
mAdapter = CardAdapter(planCardList)
mAdapter = CardAdapter(planCardList, prefs)
recyclerView.adapter = mAdapter
if (prefs.getInt("firstTimeOpening", 0) == 1) {
@@ -45,9 +45,6 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
ColourAdapter.OnClickListener,
RingtoneAdapter.OnClickListener {
private var name = ""
private var model = ""
private lateinit var mContext: Context
private lateinit var prefs: SharedPreferences
private lateinit var edit: SharedPreferences.Editor
@@ -490,11 +487,6 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
}
private fun debugMenu(): Boolean {
DeviceName.with(mContext).request { deviceInfo, _ ->
name = deviceInfo.marketName
model = deviceInfo.model
}
val alertDialog = AlertDialog.Builder(mContext,
R.style.AlertDialog
)
@@ -593,8 +585,8 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
return "First Launch: ${prefs.getString("firstTimeDev", "")}" +
"\n\nApp launched: ${prefs.getInt("launchDev", 0)}" +
"\n\nFirebase ping service fired: ${prefs.getInt("pingFB", 0)}" +
"\n\nDevice Name: $name" +
"\n\nDevice Model: $model" +
"\n\nDevice Name: ${Build.DEVICE}" +
"\n\nDevice Model: ${Build.MODEL}" +
"\n\nAndroid Version: ${Build.VERSION.RELEASE}" +
"\n\nSubscribed to notification channel: ${prefs.getBoolean("notif", false)}" +
"\n\nSubscribed to dev channel: ${prefs.getBoolean("subscribedToFBDebugChannel", false)}"