Archived
Added empty plan/food menu cards to replace the previous "No substitutions for you" presentation and gain feature parity with the iOS version
This commit is contained in:
@@ -21,6 +21,7 @@ import androidx.core.content.ContextCompat.checkSelfPermission
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import com.denizd.substitutionplan.R
|
||||
import com.denizd.substitutionplan.models.Colour
|
||||
import com.denizd.substitutionplan.models.Food
|
||||
import com.denizd.substitutionplan.models.Substitution
|
||||
import java.util.*
|
||||
import java.io.File
|
||||
@@ -80,6 +81,17 @@ internal object HelperFunctions {
|
||||
|
||||
const val notificationChannelId = "general"
|
||||
|
||||
fun getEmptyGeneralSubstitution(context: Context) = arrayOf(
|
||||
Substitution("", "", "", context.getString(R.string.plan_empty), "", "", "", "", 0, 0, 0)
|
||||
).toList()
|
||||
|
||||
fun getEmptyPersonalSubstitution(context: Context) =
|
||||
Substitution("", "", "", context.getString(R.string.personal_plan_empty), "", "", "", "", 0, 0, 0)
|
||||
|
||||
fun getEmptyFoodMenu(context: Context) = arrayOf(
|
||||
Food("\n${context.getString(R.string.food_menu_empty)}\n", 0)
|
||||
).toList()
|
||||
|
||||
/**
|
||||
* This function returns an array that contains all data relevant to tinting individual entries
|
||||
* on the substitution plan
|
||||
|
||||
@@ -12,14 +12,14 @@ import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.denizd.substitutionplan.adapters.FoodAdapter
|
||||
import com.denizd.substitutionplan.data.HelperFunctions
|
||||
import com.denizd.substitutionplan.database.FoodViewModel
|
||||
import com.denizd.substitutionplan.databinding.FoodLayoutBinding
|
||||
import com.denizd.substitutionplan.models.Food
|
||||
|
||||
internal class FoodFragment : Fragment() {
|
||||
|
||||
private val foodArrayList = ArrayList<Food>()
|
||||
private val mAdapter = FoodAdapter(foodArrayList)
|
||||
private val mAdapter = FoodAdapter(ArrayList())
|
||||
private lateinit var mContext: Context
|
||||
private lateinit var prefs: SharedPreferences
|
||||
private lateinit var foodViewModel: FoodViewModel
|
||||
@@ -48,12 +48,12 @@ internal class FoodFragment : Fragment() {
|
||||
|
||||
foodViewModel = ViewModelProviders.of(this).get(FoodViewModel::class.java)
|
||||
foodViewModel.allFoods?.observe(this, Observer<List<Food>> { foodList ->
|
||||
foodArrayList.clear()
|
||||
for (item in foodList) {
|
||||
foodArrayList.add(item)
|
||||
}
|
||||
binding.recyclerView.scheduleLayoutAnimation()
|
||||
mAdapter.setFood(foodArrayList)
|
||||
mAdapter.setFood(if (foodList.isEmpty()) {
|
||||
HelperFunctions.getEmptyFoodMenu(mContext)
|
||||
} else {
|
||||
foodList
|
||||
})
|
||||
})
|
||||
|
||||
if (prefs.getBoolean("autoRefresh", false)) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.denizd.substitutionplan.fragments
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.lifecycle.Observer
|
||||
import com.denizd.substitutionplan.data.HelperFunctions
|
||||
import com.denizd.substitutionplan.models.Substitution
|
||||
|
||||
internal class GeneralPlanFragment : PlanFragment() {
|
||||
@@ -11,7 +12,11 @@ internal class GeneralPlanFragment : PlanFragment() {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
substitutionPlan?.observe(this, Observer<List<Substitution>> { substitutions ->
|
||||
mAdapter.setSubst(substitutions)
|
||||
mAdapter.setSubst(if (substitutions.isEmpty()) {
|
||||
HelperFunctions.getEmptyGeneralSubstitution(mContext)
|
||||
} else {
|
||||
substitutions
|
||||
})
|
||||
binding.recyclerView.scheduleLayoutAnimation()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@ internal class PersonalPlanFragment : PlanFragment() {
|
||||
|
||||
substitutionPlan?.observe(this, Observer<List<Substitution>> { substitutions ->
|
||||
planCardList.clear()
|
||||
binding.emptyPlanEmoticon.visibility = View.GONE
|
||||
binding.emptyPlanText.visibility = View.GONE
|
||||
binding.emptyPlanLayout.visibility = View.GONE
|
||||
isPersonalPlanEmpty = true
|
||||
binding.recyclerView.visibility = View.VISIBLE
|
||||
|
||||
@@ -33,17 +30,11 @@ internal class PersonalPlanFragment : PlanFragment() {
|
||||
planCardList.add(substItem)
|
||||
}
|
||||
isPersonalPlanEmpty = (planCardList.size == 1 && planCardList[0].date.substring(0, 3) == "psa") || planCardList.isEmpty()
|
||||
if (isPersonalPlanEmpty) {
|
||||
planCardList.add(HelperFunctions.getEmptyPersonalSubstitution(mContext))
|
||||
}
|
||||
binding.recyclerView.scheduleLayoutAnimation()
|
||||
mAdapter.setSubst(planCardList)
|
||||
|
||||
handler.postDelayed({
|
||||
if (isPersonalPlanEmpty) {
|
||||
binding.emptyPlanEmoticon.visibility = View.VISIBLE
|
||||
binding.emptyPlanText.visibility = View.VISIBLE
|
||||
binding.emptyPlanLayout.visibility = View.VISIBLE
|
||||
binding.emptyPlanLayout.scheduleLayoutAnimation()
|
||||
}
|
||||
}, 64)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ internal open class PlanFragment : Fragment() {
|
||||
internal lateinit var mAdapter: SubstitutionAdapter
|
||||
internal var planCardList = ArrayList<Substitution>()
|
||||
private lateinit var substViewModel: SubstViewModel
|
||||
private lateinit var mContext: Context
|
||||
internal lateinit var mContext: Context
|
||||
internal lateinit var prefs: SharedPreferences
|
||||
|
||||
internal var isPersonalPlanEmpty: Boolean = true
|
||||
|
||||
@@ -6,42 +6,6 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/empty_plan_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layoutAnimation="@anim/layout_animation_fall_down">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/empty_plan_emoticon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=":("
|
||||
android:textSize="60dp"
|
||||
android:layout_gravity="center"
|
||||
android:textColor="@color/colorHint"
|
||||
android:visibility="gone"
|
||||
tools:ignore="HardcodedText,SpUsage" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/empty_plan_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/no_personal_substitutions"
|
||||
app:layout_anchor="@+id/smileydown"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:textColor="@color/colorHint"
|
||||
android:visibility="gone"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
@@ -49,6 +13,4 @@
|
||||
android:layoutAnimation="@anim/layout_animation_fall_down"
|
||||
android:scrollbars="vertical"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
@@ -50,7 +50,9 @@
|
||||
<string name="experimental_menu_dialog_title">Testmenü</string>
|
||||
<string name="statistics_dialog_title">Statistikmenü</string>
|
||||
<string name="enable_course_notifications">Kursbenachrichtigungen aktivieren</string>
|
||||
<string name="no_personal_substitutions">Kein Entfall für dich</string>
|
||||
<string name="plan_empty">Der Vertretungsplan ist leer</string>
|
||||
<string name="personal_plan_empty">Dein Plan ist leer :(</string>
|
||||
<string name="food_menu_empty">Der Speiseplan ist leer</string>
|
||||
<string name="customise_colours_title">Benutzerdefinierte Farben</string>
|
||||
<string name="customise_colours_desc">Farben für jedes Fach einstellen</string>
|
||||
<string name="course_deu">Deutsch (+ DAZ)</string>
|
||||
|
||||
@@ -59,7 +59,9 @@
|
||||
<string name="experimental_menu_dialog_text">This menu is intended for testing only.</string>
|
||||
<string name="apply">Apply</string>
|
||||
<string name="invalid_code">Invalid code</string>
|
||||
<string name="no_personal_substitutions">No substitutions for you</string>
|
||||
<string name="plan_empty">The substitution plan is empty</string>
|
||||
<string name="personal_plan_empty">Your plan is empty :(</string>
|
||||
<string name="food_menu_empty">The food menu is empty</string>
|
||||
|
||||
<string name="customise_colours_title">Customize colors</string>
|
||||
<string name="customise_colours_desc">Customize every subject individually</string>
|
||||
|
||||
Reference in New Issue
Block a user