diff --git a/app/build.gradle b/app/build.gradle index f352203a24..331b558b59 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -229,3 +229,4 @@ protobuf { } apply plugin: 'com.google.gms.google-services' + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 884b459358..bd3cfcf53a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,38 +4,39 @@ package="de.tum.in.tumcampusapp" android:installLocation="auto" tools:ignore="UnusedAttribute"> - - - - - - - - - - - - - - + + + + android:required="false" /> + android:required="false" /> - - - - + android:required="false" /> + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + android:exported="true" + android:label="@string/app_name"> @@ -102,8 +77,8 @@ + android:exported="true" + android:launchMode="singleTop"> @@ -158,10 +133,10 @@ + android:parentActivityName=".component.ui.overview.MainActivity"> @@ -200,10 +175,10 @@ + android:parentActivityName=".component.ui.overview.MainActivity"> @@ -248,14 +223,12 @@ - + android:label="@string/person_information" /> - + android:theme="@style/AppTheme.NoDrawerLayout" /> - - - + android:exported="false" + android:label="NavigaTUM" /> - - + android:parentActivityName=".component.tumui.calendar.CalendarActivity" /> - - - - - - - - - - - - - - - - - - - - - + + android:taskAffinity=""> - - - - - - - - - - - - + android:name="android.app.searchable" + android:resource="@xml/searchable_mvv" /> + + android:theme="@style/AppTheme.NoDrawerLayout"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/feedback/FeedbackPresenter.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/feedback/FeedbackPresenter.kt index a8091f285b..c262b2986c 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/feedback/FeedbackPresenter.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/feedback/FeedbackPresenter.kt @@ -274,6 +274,7 @@ class FeedbackPresenter @Inject constructor( return true } + override fun onImageOptionSelected(option: Int) { if (option == 0) { if (SDK_INT < M || checkPermission(CAMERA)) { diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt index 4575948940..5b1e11b0ee 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt @@ -73,7 +73,7 @@ class CafeteriaMenuCard(context: Context, private val cafeteria: CafeteriaWithMe @JvmStatic fun inflateViewHolder(parent: ViewGroup, interactionListener: CardInteractionListener): CardViewHolder { val view = LayoutInflater.from(parent.context).inflate(R.layout.card_cafeteria_menu, parent, false) - return CafeteriaMenuViewHolder(view, interactionListener) + return CafeteriaMenuViewHolder(view, interactionListener)//,requireA) } } } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuViewHolder.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuViewHolder.kt index 72ba6eefa1..97e0a4643d 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuViewHolder.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuViewHolder.kt @@ -2,6 +2,8 @@ package de.tum.`in`.tumcampusapp.component.ui.cafeteria import android.view.View import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import androidx.fragment.app.Fragment import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -9,6 +11,7 @@ import de.tum.`in`.tumcampusapp.R import de.tum.`in`.tumcampusapp.component.ui.cafeteria.details.CafeteriaMenusAdapter import de.tum.`in`.tumcampusapp.component.ui.cafeteria.details.OpenHoursHelper import de.tum.`in`.tumcampusapp.component.ui.cafeteria.model.CafeteriaWithMenus +import de.tum.`in`.tumcampusapp.component.ui.cafeteria.rating.CreateCafeteriaRatingFragment import de.tum.`in`.tumcampusapp.component.ui.overview.CardInteractionListener import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder import org.joda.time.format.DateTimeFormat @@ -49,7 +52,20 @@ class CafeteriaMenuViewHolder( menusRecyclerView.layoutManager = LinearLayoutManager(context) menusRecyclerView.itemAnimator = DefaultItemAnimator() - adapter = CafeteriaMenusAdapter(context, false) { performClick() } + val lambda= { /*performClick()*/ + // val intent = Intent(requireContext, CreateCafeteriaRatingActivity::class.java) + // context.startActivity(intent) + val nextFrag = CreateCafeteriaRatingFragment() + val help= itemView.context + + (context as Fragment).requireActivity().supportFragmentManager.beginTransaction() + .replace(R.id.contentFrame, nextFrag, "cafeteriaRating") + .addToBackStack(null) + .commit() + } + + adapter = CafeteriaMenusAdapter(context, false)//,lambda) + menusRecyclerView.adapter = adapter } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/details/CafeteriaDetailsSectionFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/details/CafeteriaDetailsSectionFragment.kt index 648a5a8bc9..32d7193a74 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/details/CafeteriaDetailsSectionFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/details/CafeteriaDetailsSectionFragment.kt @@ -14,6 +14,8 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.zhuinden.fragmentviewbindingdelegatekt.viewBinding import de.tum.`in`.tumcampusapp.R import de.tum.`in`.tumcampusapp.component.ui.cafeteria.model.CafeteriaMenu +import de.tum.`in`.tumcampusapp.component.ui.cafeteria.rating.CreateCafeteriaRatingFragment +import de.tum.`in`.tumcampusapp.component.ui.cafeteria.rating.ShowCafeteriaRatingsFragment import de.tum.`in`.tumcampusapp.databinding.FragmentCafeteriadetailsSectionBinding import de.tum.`in`.tumcampusapp.di.ViewModelFactory import de.tum.`in`.tumcampusapp.di.injector @@ -85,7 +87,15 @@ class CafeteriaDetailsSectionFragment : Fragment() { menusRecyclerView.layoutManager = LinearLayoutManager(requireContext()) menusRecyclerView.itemAnimator = DefaultItemAnimator() - val adapter = CafeteriaMenusAdapter(requireContext(), true, null) + val adapter = CafeteriaMenusAdapter(requireContext(), true + ) { + val nextFrag = ShowCafeteriaRatingsFragment() + + requireActivity().supportFragmentManager.beginTransaction() + .replace(R.id.contentFrame, nextFrag, "cafeteriaRating") + .addToBackStack(null) + .commit() + } menusRecyclerView.adapter = adapter cafeteriaViewModel.cafeteriaMenus.observe( diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/details/CafeteriaMenuAdapterItem.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/details/CafeteriaMenuAdapterItem.kt index 23dfade118..e9b74d84a4 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/details/CafeteriaMenuAdapterItem.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/details/CafeteriaMenuAdapterItem.kt @@ -3,11 +3,13 @@ package de.tum.`in`.tumcampusapp.component.ui.cafeteria.details import android.view.View import android.widget.ImageView import android.widget.TextView +import androidx.fragment.app.Fragment import de.tum.`in`.tumcampusapp.R import de.tum.`in`.tumcampusapp.component.ui.cafeteria.CafeteriaMenuFormatter import de.tum.`in`.tumcampusapp.component.ui.cafeteria.FavoriteDishDao import de.tum.`in`.tumcampusapp.component.ui.cafeteria.model.CafeteriaMenu import de.tum.`in`.tumcampusapp.component.ui.cafeteria.model.FavoriteDish +import de.tum.`in`.tumcampusapp.component.ui.cafeteria.rating.CreateCafeteriaRatingFragment import org.joda.time.DateTime import org.joda.time.format.DateTimeFormat @@ -32,7 +34,16 @@ sealed class CafeteriaMenuAdapterItem { val headerTextView = findViewById(R.id.headerTextView) headerTextView.text = menu.typeLong.replace("[0-9]", "").trim() - setOnClickListener { listener?.invoke() } + setOnClickListener { + listener?.invoke() +/* val nextFrag = CreateCafeteriaRatingFragment() + val help= it.context + + (context as Fragment).requireActivity().supportFragmentManager.beginTransaction() + .replace(R.id.contentFrame, nextFrag, "cafeteriaRating") + .addToBackStack(null) + .commit()*/ + } } } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/details/CafeteriaMenusAdapter.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/details/CafeteriaMenusAdapter.kt index 7667d5b455..2588b74001 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/details/CafeteriaMenusAdapter.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/details/CafeteriaMenusAdapter.kt @@ -1,9 +1,12 @@ package de.tum.`in`.tumcampusapp.component.ui.cafeteria.details import android.content.Context +import android.content.Intent +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TextView import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import de.tum.`in`.tumcampusapp.R @@ -48,10 +51,10 @@ class CafeteriaMenusAdapter( fun update(menus: List) { val newItems = menus - .filter(this::shouldShowMenu) - .splitOnChanged { it.typeLong } - .map(this::createAdapterItemsForSection) - .flatten() + .filter(this::shouldShowMenu) + .splitOnChanged { it.typeLong } + .map(this::createAdapterItemsForSection) + .flatten() val diffResult = DiffUtil.calculateDiff(DiffUtilCallback(adapterItems, newItems)) @@ -63,9 +66,9 @@ class CafeteriaMenusAdapter( private fun shouldShowMenu(menu: CafeteriaMenu): Boolean { val shouldShowMenuType = Utils.getSettingBool( - context, - "card_cafeteria_${menu.typeShort}", - "tg" == menu.typeShort || "ae" == menu.typeShort + context, + "card_cafeteria_${menu.typeShort}", + "tg" == menu.typeShort || "ae" == menu.typeShort ) return shouldShowMenuType || isBigLayout } @@ -90,7 +93,15 @@ class CafeteriaMenusAdapter( } } - class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) + class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + init { + itemView.setBackgroundColor(0x80808) + itemView.setOnClickListener({ + // itemView.findViewById(R.id.nameTextView).text = "clicked" + Log.d("help", "test: ") + }) + } + } private class DiffUtilCallback( private val oldItems: List, diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/fragment/CafeteriaFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/fragment/CafeteriaFragment.kt index 63297ebe93..f58516e6be 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/fragment/CafeteriaFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/fragment/CafeteriaFragment.kt @@ -19,6 +19,7 @@ import de.tum.`in`.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManag import de.tum.`in`.tumcampusapp.component.ui.cafeteria.details.CafeteriaDetailsSectionsPagerAdapter import de.tum.`in`.tumcampusapp.component.ui.cafeteria.details.CafeteriaViewModel import de.tum.`in`.tumcampusapp.component.ui.cafeteria.model.Cafeteria +import de.tum.`in`.tumcampusapp.component.ui.cafeteria.rating.CreateCafeteriaRatingFragment import de.tum.`in`.tumcampusapp.databinding.FragmentCafeteriaBinding import de.tum.`in`.tumcampusapp.di.ViewModelFactory import de.tum.`in`.tumcampusapp.di.injector @@ -26,6 +27,7 @@ import de.tum.`in`.tumcampusapp.service.DownloadWorker import de.tum.`in`.tumcampusapp.utils.Const import de.tum.`in`.tumcampusapp.utils.Utils import de.tum.`in`.tumcampusapp.utils.observeNonNull +import org.jetbrains.anko.sdk27.coroutines.onClick import org.joda.time.DateTime import javax.inject.Inject import javax.inject.Provider @@ -84,6 +86,14 @@ class CafeteriaFragment : FragmentForDownloadingExternal( binding.spinnerToolbar.adapter = adapter binding.spinnerToolbar.onItemSelectedListener = this + binding.floatingActionButton.onClick { + val nextFrag = CreateCafeteriaRatingFragment() + requireActivity().supportFragmentManager.beginTransaction() + .replace(R.id.contentFrame, nextFrag, "cafeteriaRating") + .addToBackStack(null) + .commit() + } + cafeteriaViewModel.cafeterias.observeNonNull(this) { updateCafeterias(it) } cafeteriaViewModel.selectedCafeteria.observeNonNull(this) { onNewCafeteriaSelected(it) } cafeteriaViewModel.menuDates.observeNonNull(this) { updateSectionsPagerAdapter(it) } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/CreateCafeteriaRatingFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/CreateCafeteriaRatingFragment.kt new file mode 100644 index 0000000000..2579f95e83 --- /dev/null +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/CreateCafeteriaRatingFragment.kt @@ -0,0 +1,255 @@ +package de.tum.`in`.tumcampusapp.component.ui.cafeteria.rating + + +import android.Manifest +import android.content.ActivityNotFoundException +import android.content.Intent +import android.content.pm.PackageManager +import android.os.Build +import android.os.Bundle +import android.provider.MediaStore +import android.view.View +import android.widget.AdapterView +import android.widget.ArrayAdapter +import androidx.annotation.RequiresApi +import androidx.appcompat.app.AlertDialog +import androidx.core.content.ContextCompat +import androidx.core.content.FileProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.zhuinden.fragmentviewbindingdelegatekt.viewBinding +import de.tum.`in`.tumcampusapp.R +import de.tum.`in`.tumcampusapp.component.other.generic.fragment.FragmentForAccessingTumCabe +import de.tum.`in`.tumcampusapp.component.tumui.feedback.FeedbackPresenter +import de.tum.`in`.tumcampusapp.databinding.FragmentCafeteriaRatingBinding +import de.tum.`in`.tumcampusapp.utils.ImageUtils +import de.tum.`in`.tumcampusapp.utils.Utils +import java.io.File +import java.io.IOException + + +class CreateCafeteriaRatingFragment : FragmentForAccessingTumCabe>( + R.layout.fragment_cafeteria_rating, + R.string.create_cafeteria_rating +), AdapterView.OnItemSelectedListener { + + + // used to access the photo functionality + // todo potentially split to another camera "forwarder" + // @Inject + // lateinit var presenter: FeedbackContract.Presenter + + private val binding by viewBinding(FragmentCafeteriaRatingBinding::bind) + + + private val itemsList = ArrayList() + private lateinit var createTagRatingAdapter: CreateRatingAdapter + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val cafeterias = arrayOf("Mensa Garching", "mensa leopoldstrasse") + val meals = arrayOf("Only The Cafeteria", "Pizza Margeritha") + // binding.pickCafeteriaSpinner; + // val spinner = findViewById(R.id.pickCafeteriaSpinner) + if (binding.pickCafeteriaCreateSpinner != null) { + val adapter = ArrayAdapter( + requireContext(), + android.R.layout.simple_spinner_dropdown_item, cafeterias + ) + binding.pickCafeteriaCreateSpinner.adapter = adapter + } + + if (binding.pickDishCreateSpinner != null) { + val adapter = ArrayAdapter( + requireContext(), + android.R.layout.simple_spinner_dropdown_item, meals + ) + binding.pickDishCreateSpinner.adapter = adapter + } + prepareItems() + + // val recyclerView: RecyclerView = findViewById(R.id.recyclerView) + createTagRatingAdapter = CreateRatingAdapter(itemsList) + val layoutManager = LinearLayoutManager(requireContext()) + binding.tagOptionListRecyclerView.layoutManager = layoutManager + binding.tagOptionListRecyclerView.adapter = createTagRatingAdapter + +// todo eigeneer contract und co benötigt? + /*presenter.attachView(view) + + if (savedInstanceState != null) { + presenter.onRestoreInstanceState(savedInstanceState) + }*/ + + binding.addImageButton.setOnClickListener { showImageOptionsDialog() } + } + + private fun prepareItems() { + itemsList.add(CreateTagRatingElement("Waiting time")) + itemsList.add(CreateTagRatingElement("Variety General")) + itemsList.add(CreateTagRatingElement("Variety Vegetarian")) + itemsList.add(CreateTagRatingElement("Variety Vegan")) + itemsList.add(CreateTagRatingElement("Enough free tables")) + } + + + private var currentPhotoPath: String? = null + + + private fun showImageOptionsDialog() { + val options = + arrayOf(getString(R.string.feedback_take_picture), getString(R.string.gallery)) + val alertDialog = AlertDialog.Builder(requireContext()) + .setTitle(R.string.feedback_add_picture) + .setItems(options) { _, index -> onImageOptionSelected(index) } + .setNegativeButton(R.string.cancel, null) + .create() + alertDialog.window?.setBackgroundDrawableResource(R.drawable.rounded_corners_background) + alertDialog.show() + } + + fun onImageOptionSelected(option: Int) { + if (option == 0) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || checkPermission(Manifest.permission.CAMERA)) { + takePicture() + } + } else { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE)) { + openGallery() + } + } + } + + /** + * @return true if user has given permission before + */ + @RequiresApi(api = Build.VERSION_CODES.M) + private fun checkPermission(permission: String): Boolean { + val permissionCheck = ContextCompat.checkSelfPermission(requireContext(), permission) + + if (permissionCheck == PackageManager.PERMISSION_DENIED) { + val requestCode = when (permission) { + Manifest.permission.READ_EXTERNAL_STORAGE -> FeedbackPresenter.PERMISSION_FILES + Manifest.permission.CAMERA -> FeedbackPresenter.PERMISSION_CAMERA + else -> FeedbackPresenter.PERMISSION_LOCATION + } + + showPermissionRequestDialog(permission, requestCode) + return false + } + return true + } + + @RequiresApi(api = Build.VERSION_CODES.M) + fun showPermissionRequestDialog(permission: String, requestCode: Int) { + requestPermissions(arrayOf(permission), requestCode) + } + + fun takePicture() { + val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) + + // Create the file where the photo should go + var photoFile: File? = null + try { + photoFile = ImageUtils.createImageFile(requireContext()) + currentPhotoPath = photoFile.absolutePath + } catch (e: IOException) { + Utils.log(e) + } + + if (photoFile == null) { + return + } + + val authority = "de.tum.in.tumcampusapp.fileprovider" + val photoURI = FileProvider.getUriForFile(requireContext(), authority, photoFile) + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI) + try { + openCamera(takePictureIntent) + } catch (e: ActivityNotFoundException) { + photoFile.delete() + } + } + + fun openGallery() { + val intent = Intent() + intent.type = "image/*" + intent.action = Intent.ACTION_GET_CONTENT + + // val chooser = Intent.createChooser(intent, "Select file") + // openGallery(chooser) + } + + fun openCamera(intent: Intent) { + startActivityForResult(intent, FeedbackPresenter.REQUEST_TAKE_PHOTO) + } + // val cafeterias = arrayOf("mensa garching", "mensa leopoldstrasse") + + // Drop-down navigation +/* private val selectCafeteriasSpinner: Spinner + get() { + + val groupAdapter = object : ArrayAdapter( + context!!, + android.R.layout.simple_spinner_dropdown_item, + android.R.id.text1, + cafeterias + ) { + val inflater = LayoutInflater.from(context) + + override fun getDropDownView(pos: Int, ignored: View?, parent: ViewGroup): View { + val v = inflater.inflate(android.R.layout.simple_spinner_dropdown_item, parent, false) + val studyRoomGroup = getItem(pos) ?: return v + val nameTextView = v.findViewById(android.R.id.text1) + nameTextView.text = studyRoomGroup + return v + } + } + + groupAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) + return binding.pickCafeteriaSpinner.apply { + adapter = groupAdapter + onItemSelectedListener = this@CafeteriaRatingFragment + } + }*/ + + override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { +//todo toast mit id + } + + override fun onNothingSelected(adapterView: AdapterView<*>?) = Unit + + /*override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + val rootView: View = inflater.inflate(de.tum.`in`.tumcampusapp.R.layout.activity_cafeteria_rating, container, false) + displayCafeterias() + return rootView + }*/ + +// override fun onViewCreated(view: View, savedInstanceState: Bundle?) { +// super.onViewCreated(view, savedInstanceState) +// +// } + + + /* private fun displayCafeterias() { + selectCurrentSpinnerItem() + // binding.spinnerContainer.visibility = View.VISIBLE + // showLoadingEnded() + } + + private fun selectCurrentSpinnerItem() { + cafeterias.forEachIndexed { i, a -> + + // selectCafeteriasSpinner.setSelection(i) + + } + } + */ + companion object { + + private const val NONE_SELECTED = -1 + + @JvmStatic + fun newInstance() = CreateCafeteriaRatingFragment() + } + +} \ No newline at end of file diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/CreateRatingAdapter.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/CreateRatingAdapter.kt new file mode 100644 index 0000000000..980a7277e2 --- /dev/null +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/CreateRatingAdapter.kt @@ -0,0 +1,34 @@ +package de.tum.`in`.tumcampusapp.component.ui.cafeteria.rating + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.annotation.NonNull +import androidx.recyclerview.widget.RecyclerView +import de.tum.`in`.tumcampusapp.R + +class CreateRatingAdapter(private var itemsList: List) : +RecyclerView.Adapter() { + + + class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var itemTextView: TextView = view.findViewById(R.id.tagItemLabel) + } + + @NonNull + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val itemView = LayoutInflater.from(parent.context) + .inflate(R.layout.list_item_rating_tag_large, parent, false) + return ViewHolder(itemView) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val item = itemsList[position] + holder.itemTextView.text = item.tagLabel + } + + override fun getItemCount(): Int { + return itemsList.size + } +} \ No newline at end of file diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/CreateTagRatingElement.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/CreateTagRatingElement.kt new file mode 100644 index 0000000000..b0527d4532 --- /dev/null +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/CreateTagRatingElement.kt @@ -0,0 +1,10 @@ +package de.tum.`in`.tumcampusapp.component.ui.cafeteria.rating + +class CreateTagRatingElement { + var tagLabel: String="label" + private var points=1 + + constructor(tagLabel: String) { + this.tagLabel = tagLabel + } +} \ No newline at end of file diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/ShowCafeteriaRatingsFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/ShowCafeteriaRatingsFragment.kt new file mode 100644 index 0000000000..cd1ad220a7 --- /dev/null +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/ShowCafeteriaRatingsFragment.kt @@ -0,0 +1,124 @@ +package de.tum.`in`.tumcampusapp.component.ui.cafeteria.rating + +import android.os.Bundle +import android.view.View +import android.widget.ArrayAdapter +import androidx.recyclerview.widget.LinearLayoutManager +import com.zhuinden.fragmentviewbindingdelegatekt.viewBinding +import de.tum.`in`.tumcampusapp.R +import de.tum.`in`.tumcampusapp.component.other.generic.fragment.FragmentForAccessingTumCabe +import de.tum.`in`.tumcampusapp.databinding.FragmentShowCafeteriaRatingsBinding + + +class ShowCafeteriaRatingsFragment : FragmentForAccessingTumCabe>( + R.layout.fragment_show_cafeteria_ratings, + R.string.view_cafeteria_rating +) { + + + private val binding by viewBinding(FragmentShowCafeteriaRatingsBinding::bind) + + + private val itemsList = ArrayList() + private lateinit var showTagRatingAdapter: ShowRatingAdapter + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val cafeterias = arrayOf("Mensa Garching", "Mensa Leopoldstrasse") + val meals = arrayOf("Only The Cafeteria", "Pizza Margeritha") + + + + binding.pickCafeteriaShowSpinner.adapter = ArrayAdapter( + requireContext(), + android.R.layout.simple_spinner_dropdown_item, cafeterias + ) + + + binding.pickDishShowSpinner.adapter = ArrayAdapter( + requireContext(), + android.R.layout.simple_spinner_dropdown_item, meals + ) + + prepareItems() + + + showTagRatingAdapter = ShowRatingAdapter(itemsList) + val layoutManager = LinearLayoutManager(requireContext()) + binding.showSingleRatingsRecyclerView.layoutManager = layoutManager + binding.showSingleRatingsRecyclerView.adapter = showTagRatingAdapter + } + + + private fun prepareItems() { + val nameTagResults = listOf( + ShowTagRatingAverage("bad", 1.0, 1, 5, 1.0), + ShowTagRatingAverage("Variety Vegetarian", 2.0, 1, 5, 1.0), + ShowTagRatingAverage("Variety Vegan", 3.0, 1, 5, 1.0), + ShowTagRatingAverage("something", 4.0, 1, 5, 1.0), + ShowTagRatingAverage("clean", 5.0, 1, 5, 1.0) + ) + itemsList.add( + ShowRatingAverage( + false, + 1, + "Important comment on this beautiful rating. Sometimes, a comment must be longer than one line", + nameTagResults, + nameTagResults + ) + ) + itemsList.add( + ShowRatingAverage( + false, + 2, + "", + nameTagResults, + nameTagResults + ) + ) + itemsList.add( + ShowRatingAverage( + false, + 3, + "", + nameTagResults, + nameTagResults + ) + ) + itemsList.add( + ShowRatingAverage( + false, + 4, + "Important comment on this beautiful rating", + nameTagResults, + nameTagResults + ) + ) + itemsList.add( + ShowRatingAverage( + false, + 5, + "Important comment on this beautiful rating", + nameTagResults, + nameTagResults + ) + ) + itemsList.add( + ShowRatingAverage( + true, + 3, + "Important comment on this beautiful rating", + nameTagResults, + nameTagResults + ) + ) + + } + + + companion object { + @JvmStatic + fun newInstance() = CreateCafeteriaRatingFragment() + } + +} \ No newline at end of file diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/ShowRatingAdapter.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/ShowRatingAdapter.kt new file mode 100644 index 0000000000..ada8198c04 --- /dev/null +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/ShowRatingAdapter.kt @@ -0,0 +1,139 @@ +package de.tum.`in`.tumcampusapp.component.ui.cafeteria.rating + +import android.content.Context +import android.content.res.ColorStateList +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.RatingBar +import android.widget.TextView +import android.widget.Toast +import androidx.annotation.NonNull +import androidx.cardview.widget.CardView +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.chip.Chip +import com.google.android.material.chip.ChipGroup +import de.tum.`in`.tumcampusapp.R + +class ShowRatingAdapter(private var itemsList: List) : + RecyclerView.Adapter() { + + + private lateinit var context: Context + + class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var chipGroup: ChipGroup = view.findViewById(R.id.chipGroup) + var ratingCommentTextView: TextView = view.findViewById(R.id.ratingCommentTextView) + var showRatingImageViewHolder: CardView = view.findViewById(R.id.showRatingImageViewHolder) + var singleRatingPointsRatingBar: RatingBar = + view.findViewById(R.id.singleRatingPointsRatingBar) + + // var ratingResultNumberTextView: TextView = view.findViewById(R.id.ratingResultNumberTextView) + var listItemHolderCardView: LinearLayout = view.findViewById(R.id.listItemHolderCardView) + + } + + @NonNull + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val itemView = LayoutInflater.from(parent.context) + .inflate(R.layout.list_item_rating, parent, false) + context = parent.context + return ViewHolder(itemView) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val item = itemsList[position] + + if (item.img) { + holder.showRatingImageViewHolder.visibility = View.VISIBLE + } + if (item.comment.length > 0) { + holder.ratingCommentTextView.visibility = View.VISIBLE + holder.ratingCommentTextView.text = item.comment + } + + if (item.points == 1) { + holder.listItemHolderCardView.setBackgroundColor( + ContextCompat.getColor( + context, + R.color.rating_1 + ) + ) + } else if (item.points == 2) { + holder.listItemHolderCardView.setBackgroundColor( + ContextCompat.getColor( + context, + R.color.rating_2 + ) + ) + } else if (item.points == 3) { + holder.listItemHolderCardView.setBackgroundColor( + ContextCompat.getColor( + context, + R.color.rating_3 + ) + ) + } else if (item.points == 4) { + holder.listItemHolderCardView.setBackgroundColor( + ContextCompat.getColor( + context, + R.color.rating_4 + ) + ) + } else { + holder.listItemHolderCardView.setBackgroundColor( + ContextCompat.getColor( + context, + R.color.rating_5 + ) + ) + } + + holder.singleRatingPointsRatingBar.rating = item.points.toFloat() + setupChip(holder.chipGroup, item.RatingTagsResults) + } + + override fun getItemCount(): Int { + return itemsList.size + } + + private fun setupChip(chipGroup: ChipGroup, ratingTagsResults: List) { + + for (tag in ratingTagsResults) { + val chip = createChip(tag) + + chipGroup.addView(chip) + } + } + + private fun createChip(label: ShowTagRatingAverage): Chip { + val chip = Chip(context) + + var colorHelper = R.color.tum_light_gray + /*if (label.points == 2.0) { + colorHelper = R.color.rating_2_0 + } else if (label.points == 3.0) { + colorHelper = R.color.rating_3_0 + } else if (label.points == 4.0) { + colorHelper = R.color.rating_4_0 + } else if (label.points == 5.0) { + colorHelper = R.color.rating_5_0 + }*/ + + chip.chipBackgroundColor = ColorStateList.valueOf( + ContextCompat.getColor( + context, + colorHelper + ) + ) + chip.text = label.tagLabel + + chip.setOnClickListener { + Toast.makeText(context, "Rating: "+label.points, Toast.LENGTH_SHORT).show() + } + + return chip + } +} \ No newline at end of file diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/ShowRatingAverage.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/ShowRatingAverage.kt new file mode 100644 index 0000000000..3c323cef35 --- /dev/null +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/ShowRatingAverage.kt @@ -0,0 +1,9 @@ +package de.tum.`in`.tumcampusapp.component.ui.cafeteria.rating + +class ShowRatingAverage( + var img: Boolean, + var points: Int, + var comment: String, + var RatingTagsResults: List, + var NameTagsResults: List +) \ No newline at end of file diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/ShowTagRatingAverage.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/ShowTagRatingAverage.kt new file mode 100644 index 0000000000..69c3d4e65c --- /dev/null +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/rating/ShowTagRatingAverage.kt @@ -0,0 +1,11 @@ +package de.tum.`in`.tumcampusapp.component.ui.cafeteria.rating + +class ShowTagRatingAverage( + var tagLabel: String, + var points: Double, + var max: Int, + var min: Int, + var std: Double +) { + +} \ No newline at end of file diff --git a/app/src/main/java/de/tum/in/tumcampusapp/database/TcaDb.kt b/app/src/main/java/de/tum/in/tumcampusapp/database/TcaDb.kt index 15470e3688..22af628460 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/database/TcaDb.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/database/TcaDb.kt @@ -68,38 +68,34 @@ import de.tum.`in`.tumcampusapp.utils.sync.SyncDao import de.tum.`in`.tumcampusapp.utils.sync.model.Sync import java.util.concurrent.ExecutionException -@Database( - version = 7, - entities = [ - Cafeteria::class, - CafeteriaMenu::class, - FavoriteDish::class, - Sync::class, - BuildingToGps::class, - Kino::class, - Event::class, - Ticket::class, - TicketType::class, - ChatMessage::class, - Location::class, - News::class, - NewsSources::class, - CalendarItem::class, - EventSeriesMapping::class, - RoomLocations::class, - WidgetsTimetableBlacklist::class, - Recent::class, - StudyRoomGroup::class, - StudyRoom::class, - FcmNotification::class, - TransportFavorites::class, - WidgetsTransport::class, - ChatRoomDbRow::class, - ScheduledNotification::class, - ActiveAlarm::class, - EventColor::class - ] -) +@Database(version = 7, entities = [ + Cafeteria::class, + CafeteriaMenu::class, + FavoriteDish::class, + Sync::class, + BuildingToGps::class, + Kino::class, + Event::class, + Ticket::class, + TicketType::class, + ChatMessage::class, + Location::class, + News::class, + NewsSources::class, + CalendarItem::class, + EventSeriesMapping::class, + RoomLocations::class, + WidgetsTimetableBlacklist::class, + Recent::class, + StudyRoomGroup::class, + StudyRoom::class, + FcmNotification::class, + TransportFavorites::class, + WidgetsTransport::class, + ChatRoomDbRow::class, + ScheduledNotification::class, + ActiveAlarm::class, + EventColor::class]) @TypeConverters(Converters::class) abstract class TcaDb : RoomDatabase() { diff --git a/app/src/main/res/drawable/custom_ratingbar.xml b/app/src/main/res/drawable/custom_ratingbar.xml new file mode 100644 index 0000000000..3c91616cb7 --- /dev/null +++ b/app/src/main/res/drawable/custom_ratingbar.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_baseline_photo_camera_24.xml b/app/src/main/res/drawable/ic_baseline_photo_camera_24.xml new file mode 100644 index 0000000000..43a4fd5fd8 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_photo_camera_24.xml @@ -0,0 +1,6 @@ + + + + diff --git a/app/src/main/res/drawable/rating_circle.png b/app/src/main/res/drawable/rating_circle.png new file mode 100644 index 0000000000..71cdd158dd Binary files /dev/null and b/app/src/main/res/drawable/rating_circle.png differ diff --git a/app/src/main/res/layout/cafeteria_tag_chip.xml b/app/src/main/res/layout/cafeteria_tag_chip.xml new file mode 100644 index 0000000000..bcd2be9ee7 --- /dev/null +++ b/app/src/main/res/layout/cafeteria_tag_chip.xml @@ -0,0 +1,17 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/card_price_line_big.xml b/app/src/main/res/layout/card_price_line_big.xml index 54a689352c..d4181428d8 100644 --- a/app/src/main/res/layout/card_price_line_big.xml +++ b/app/src/main/res/layout/card_price_line_big.xml @@ -1,5 +1,7 @@ - - + android:orientation="horizontal" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/textView2" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + + + + + + - - - - + android:text="hello" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + diff --git a/app/src/main/res/layout/fragment_cafeteria.xml b/app/src/main/res/layout/fragment_cafeteria.xml index 0f76381290..c5ad7cabee 100644 --- a/app/src/main/res/layout/fragment_cafeteria.xml +++ b/app/src/main/res/layout/fragment_cafeteria.xml @@ -1,13 +1,17 @@ - + android:layout_width="match_parent" + android:layout_height="match_parent"> + android:layout_height="wrap_content" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> - + + + + + diff --git a/app/src/main/res/layout/fragment_cafeteria_rating.xml b/app/src/main/res/layout/fragment_cafeteria_rating.xml new file mode 100644 index 0000000000..14bc6dddf7 --- /dev/null +++ b/app/src/main/res/layout/fragment_cafeteria_rating.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_show_cafeteria_ratings.xml b/app/src/main/res/layout/fragment_show_cafeteria_ratings.xml new file mode 100644 index 0000000000..28768fc3af --- /dev/null +++ b/app/src/main/res/layout/fragment_show_cafeteria_ratings.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/list_item_rating.xml b/app/src/main/res/layout/list_item_rating.xml new file mode 100644 index 0000000000..7f22543f10 --- /dev/null +++ b/app/src/main/res/layout/list_item_rating.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_item_rating_small.xml b/app/src/main/res/layout/list_item_rating_small.xml new file mode 100644 index 0000000000..597039a21a --- /dev/null +++ b/app/src/main/res/layout/list_item_rating_small.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/list_item_rating_tag_large.xml b/app/src/main/res/layout/list_item_rating_tag_large.xml new file mode 100644 index 0000000000..d920bb9305 --- /dev/null +++ b/app/src/main/res/layout/list_item_rating_tag_large.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 58479afd2c..a5cb63afd1 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -181,6 +181,8 @@ Rückmeldung Allgemeine Informationen Mensen + Mensa Bewertung + View Mensa Bewertung Personensuche Roomfinder Öffnungszeiten @@ -300,7 +302,7 @@ \n11 mit einer Zuckerart und Süßungsmitteln Inhaltsstoffe Mensa Benachrichtigungen - + Neue Bewertung Ungültige Zeit ausgewählt. Wähle eine Uhrzeit im folgenden Intervall %1$d – %2$d. diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 45e03f3347..0df5ab1728 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -101,6 +101,22 @@ #FFFF0000 #7cbc49 + #1FD50000 + #1FD96B0C + #1FDCD618 + #1F87B315 + #1F318F11 + + #D50000 + #d73606 + #d96b0c + #daa112 + #dcd618 + #b1c416 + #87b315 + #5ca113 + #318f11 + #318F11 #3F9711 #4EA012 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9d0dff9010..0477f469f2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -219,6 +219,8 @@ Tuition Fees General Information Cafeterias + Cafeteria Rating + View Cafeteria Rating Person Search Roomfinder Study Rooms @@ -347,7 +349,7 @@ \n11 with sugar and sweeteners Ingredients Cafeteria Notification Settings - + Create Rating Invalid time. Pick a time ranging from %1$d to %2$d. diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0cc2dbf681..f79ee37c29 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -215,6 +215,13 @@ @dimen/material_default_padding + + +