Skip to content

Commit

Permalink
completed creating Time flashcards
Browse files Browse the repository at this point in the history
  • Loading branch information
klaus19 committed Mar 4, 2024
1 parent 748c872 commit 3961427
Show file tree
Hide file tree
Showing 24 changed files with 518 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 43 additions & 1 deletion app/src/main/java/com/example/visuallithuanian/Fill.kt
Original file line number Diff line number Diff line change
Expand Up @@ -817,4 +817,46 @@ package com.example.visuallithuanian
//
//"Air pollution" = "oro tarša"
//"road" = "kelias"
//"drug store" = "narkotikų parduotuvė"
//"drug store" = "narkotikų parduotuvė"

//Time flashcards

//"time" = "laikas"
//"morning" = "rytas"
//"day" = "diena"
//"evening" = "vakaras"
//"night" = "naktis"
//"hour" = "valanda"
//"today" = "šiandien"
//"tomorrow" = "rytoj"
//"yesterday" = "vakar"
//"month" = "mėnesį"
//
//"year" = "metus"
//"week" = "savaite"
//"every day" = "kiekvieną dieną"
//"What are you doing on Saturdays?" = "Ką tu veiki šeštadieniais?"
//"usually" = "paprastai"
//"in the afternoon" = "po pietų"
//"a week day" = "savaitės diena"
//"holiday" = "šventė"
//"What time is it now?" = "kiek dabar valandų?"
//"a quarter to 7." = "be penkiolika 7."
//
//"a quarter past 9." = "penkiolika po 9."
//"Half" = "pusė"
//"before 8 a.m." = "prieš 8 (aštuntą) val."
//"after 5 mins" = "po 5 min"
//"to start" = "pradėti"
//"to finish" = "pabaigti"
//"a break" = "poilsis"
//"one hour has 60 minutes" = "viena valanda turi 60 (šešiadešimt) minučiu"
//"a timetable" = "tvarkaraštis"
//"happy hours" = "laimės valandos"
//
//"an event" = "renginis"
//"Future" = "ateitis"
//"last year" = "praeitais metais"
//"last month" = "praeitą mėnesį"
//"vacation" = "atostogos"
//"registration time" = "registracijos laikas"
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class HouseholdFlashcardFragment : Fragment() {
}




counterViewModel.counter.observe(requireActivity()){count->
binding.textCounter.text = count.toString()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
package com.example.visuallithuanian

import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.media.MediaPlayer
import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import com.example.visuallithuanian.constants.CafeSingleton
import com.example.visuallithuanian.constants.TimeSingleton
import com.example.visuallithuanian.database.FlashcardPair
import com.example.visuallithuanian.databinding.FragmentCafeFlashcardsBinding
import com.example.visuallithuanian.databinding.FragmentTimeFlashcardBinding
import com.example.visuallithuanian.ui.activities.FirstScreen
import com.example.visuallithuanian.viewModel.BottomNavigationViewModel
import com.example.visuallithuanian.viewModel.FlashCardViewmodel
import com.example.visuallithuanian.viewModel.ToLearnViewModel
import com.example.visuallithuanian.viewModel.WordViewModelFactory
import com.google.android.material.bottomnavigation.BottomNavigationView


class TimeFlashcardFragment : Fragment() {

lateinit var binding: FragmentTimeFlashcardBinding
lateinit var viewModel: BottomNavigationViewModel

lateinit var bottomNavigationView: BottomNavigationView
private val counterViewModel: ToLearnViewModel by viewModels()

private var currentTripleIndex =0
private lateinit var currentTriple:Map.Entry<String,Triple<String,Int,Int>>

var isFront=true
private val totalTriples = 47 // change the value to the actual number of entries in your hashMap

// declaring viewmodel
private val cardViewModel: FlashCardViewmodel by viewModels {
WordViewModelFactory((requireActivity().application as MyApp).repository)
}


@SuppressLint("ResourceType", "SuspiciousIndentation")
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentTimeFlashcardBinding.inflate(inflater,container,false)

bottomNavigationView = (activity as? FirstScreen)?.findViewById(R.id.bottomNavigationView)!!
viewModel = ViewModelProvider(requireActivity())[BottomNavigationViewModel::class.java]


bottomNavigationView.visibility = View.GONE


// setting up listener for back Icon
binding.backIcon.setOnClickListener {
activity?.onBackPressed()
}

// binding.floatingActionButton.setOnClickListener {
// findNavController().navigate(R.id.action_dailyBasic_to_flashCards)
// }
//changing color of progress bar progress
binding.progressHorizontal.progressTintList = ColorStateList.valueOf(
ContextCompat.getColor(requireContext()
,R.color.float1))

//changing color of background color of progress bar
binding.progressHorizontal.progressBackgroundTintList = ColorStateList.valueOf(
ContextCompat.getColor(requireContext(),
R.color.silver))


// Initialize Media Player
val mediaPlayer = MediaPlayer()
binding.btnPlay.setOnClickListener {
// get the audio resource ID from currentTriple
val audioResource = currentTriple.value.third
mediaPlayer.apply {
reset()
// Set the audio resource using the context and resource ID
setDataSource(requireContext(), Uri.parse("android.resource://${requireContext().packageName}/$audioResource"))

// Prepare the MediaPlayer asynchronously
prepareAsync()
}
// Set an OnPreparedListener to start playing when the media is prepared
mediaPlayer.setOnPreparedListener {
it.start()
}

}
counterViewModel.counter.observe(requireActivity()){count->
binding.textCounter.text = count.toString()
}
currentTriple =TimeSingleton.hashMapTime.entries.elementAt(currentTripleIndex)
binding.textCardFront.text = currentTriple.key
binding.textCardBack.text = currentTriple.value.first
binding.imagecardsHelper.setImageResource(currentTriple.value.second)
binding.btnPlay.setImageResource(currentTriple.value.third)

// onclick listener on the image to save the image for learning
binding.imageFlashCard.setOnClickListener {
binding.imageFlashCard.visibility = View.GONE
binding.imageFlashCardSaveWhite.visibility = View.VISIBLE

counterViewModel.incrementCounter()
// increment currentTripleIndex and get the next Triple
currentTripleIndex++
if (currentTripleIndex >= TimeSingleton.hashMapTime.size) {
// if we have reached the end of the hashmap, start again from the beginning
currentTripleIndex = 0
}
val front = binding.textCardFront.text.toString()
val back = binding.textCardBack.text.toString()
val imageHelper = currentTriple.value.second
val voiceClip = currentTriple.value.third


val Triple = FlashcardPair(front, back, imageHelper,voiceClip)
cardViewModel.insertCards(Triple)
//Toast.makeText(requireContext(),"saved data", Toast.LENGTH_SHORT).show()
Log.d("Main","$Triple")
currentTriple = TimeSingleton.hashMapTime.entries.elementAt(currentTripleIndex)

}
//On Event of clicking on the image to unsave the image
binding.imageFlashCardSaveWhite.setOnClickListener {
with(binding){
imageFlashCardSaveWhite.visibility = View.GONE
imageFlashCard.visibility = View.VISIBLE

if (currentTripleIndex >= 0 && currentTripleIndex < TimeSingleton.hashMapTime.size) {
// Remove the item at the current index from your data structure (e.g., HashMap)
val removedTriple = TimeSingleton.hashMapTime.entries.elementAt(currentTripleIndex)
TimeSingleton.hashMapTime.remove(removedTriple.key)

// Decrease the counter
counterViewModel.decrementCounter()
val front = binding.textCardFront.text.toString()
val back = binding.textCardBack.text.toString()
val imageHelper = currentTriple.value.second
val voiceClip = currentTriple.value.third

val Triple = FlashcardPair(front, back, imageHelper,voiceClip)
cardViewModel.deleteCards(Triple)
//Toast.makeText(requireContext(),"saved data", Toast.LENGTH_SHORT).show()
Log.d("Main","$Triple")
currentTriple = TimeSingleton.hashMapTime.entries.elementAt(currentTripleIndex)

}
}
}

//Navigating from one fragment to another
binding.cardLearning.setOnClickListener {
findNavController().navigate(R.id.action_timeFlashcardFragment_to_toLearnFlashCards)
}

//onclick listener for the Flip button
with(binding) {
btnFlip.setOnClickListener {
imageFlashCardSaveWhite.visibility = View.GONE
imageFlashCard.visibility = View.VISIBLE


val progress = ((currentTripleIndex + 1) * 100) / totalTriples
binding.progressHorizontal.progress = progress

// initialize currentTripleIndex to 0 if it hasn't been initialized yet
if (currentTripleIndex < 0) {
currentTripleIndex = 0
}
if (isFront) {
isFront = false
textCardBack.visibility = View.VISIBLE
textCardFront.visibility = View.VISIBLE
imageFlashCard.visibility = View.VISIBLE
cardViewQuestions.setCardBackgroundColor(ContextCompat.getColor(requireContext(), R.color.green1))

} else {
currentTripleIndex = (currentTripleIndex + 1) % TimeSingleton.hashMapTime.size
textCardFront.visibility = View.VISIBLE
textCardBack.visibility = View.VISIBLE
imageFlashCard.visibility = View.VISIBLE
cardViewQuestions.setCardBackgroundColor(ContextCompat.getColor(requireContext(), R.color.orange1))
isFront = true
}
// retrieve the current Triple from the hashMap
currentTriple = TimeSingleton.hashMapTime.entries.elementAt(currentTripleIndex)
binding.textCardFront.text = currentTriple.key
binding.textCardBack.text = currentTriple.value.first
binding.imagecardsHelper.setImageResource(currentTriple.value.second)
binding.btnPlay.setImageResource(currentTriple.value.third)
}
}
return binding.root

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class FlashcardsMediumAdapter(private val imageList: List<FlashCardInfo>
"Veganism" -> navController.navigate(R.id.action_flashCards_to_veganFlashcardsFragment)
"Cafe" -> navController.navigate(R.id.action_flashCards_to_cafeFlashcardsFragment)
"Towns and Villages" -> navController.navigate(R.id.action_flashCards_to_villageFragment)
"Time" -> navController.navigate(R.id.action_flashCards_to_timeFlashcardFragment)
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.example.visuallithuanian.constants

import com.example.visuallithuanian.R

object TimeSingleton {

val hashMapTime = HashMap<String, Triple<String, Int, Int>>()

init {
hashMapTime["time"] = Triple("laikas", R.drawable.time, R.raw.computer)
hashMapTime["morning"] = Triple("rytas", R.drawable.morning, R.raw.computer)
hashMapTime["day"] = Triple("diena", R.drawable.day, R.raw.computer)
hashMapTime["evening"] = Triple("vakaras", R.drawable.evening, R.raw.computer)
hashMapTime["night"] = Triple("naktis", R.drawable.midnight, R.raw.computer)
hashMapTime["hour"] = Triple("valanda", R.drawable.hour, R.raw.computer)
hashMapTime["today"] = Triple("šiandien", R.drawable.today, R.raw.computer)
hashMapTime["tomorrow"] = Triple("rytoj", R.drawable.tomorrow, R.raw.computer)
hashMapTime["yesterday"] = Triple("vakar", R.drawable.yesterday, R.raw.computer)
hashMapTime["month"] = Triple("mėnesį", R.drawable.month, R.raw.computer)

hashMapTime["year"] = Triple("metus", R.drawable.year, R.raw.computer)
hashMapTime["week"] = Triple("savaite", R.drawable.week, R.raw.computer)
hashMapTime["every day"] = Triple("kiekvieną dieną", R.drawable.everyday, R.raw.computer)
hashMapTime["What are you doing on Saturdays?"] = Triple("Ką tu veiki šeštadieniais?", R.drawable.saturday, R.raw.computer)
hashMapTime["usually"] = Triple("paprastai", R.drawable.usually, R.raw.computer)
hashMapTime["in the afternoon"] = Triple("po pietų", R.drawable.inafternoon, R.raw.computer)
hashMapTime["a week day"] = Triple("savaitės diena", R.drawable.weekday, R.raw.computer)
hashMapTime["holiday"] = Triple("šventė", R.drawable.holiday1, R.raw.computer)
hashMapTime["What time is it now?"] = Triple("kiek dabar valandų?", R.drawable.whattime1, R.raw.computer)
hashMapTime["a quarter to 7."] = Triple("be penkiolika 7.", R.drawable.quarter7, R.raw.computer)

hashMapTime["a quarter past 9."] = Triple("penkiolika po 9.", R.drawable.past9, R.raw.computer)
hashMapTime["Half"] = Triple("pusė", R.drawable.half, R.raw.computer)
hashMapTime["before 8 a.m."] = Triple("prieš 8 (aštuntą) val.", R.drawable.ic_launcher_background, R.raw.computer)
hashMapTime["after 5 mins"] = Triple("po 5 min", R.drawable.ic_launcher_background, R.raw.computer)
hashMapTime["to start"] = Triple("pradėti", R.drawable.start1, R.raw.computer)
hashMapTime["to finish"] = Triple("pabaigti", R.drawable.finish1, R.raw.computer)
hashMapTime["a break"] = Triple("poilsis", R.drawable.abreak1, R.raw.computer)
hashMapTime["one hour has 60 minutes"] = Triple("viena valanda turi 60 (šešiadešimt) minučiu", R.drawable.minutes60, R.raw.computer)
hashMapTime["a timetable"] = Triple("tvarkaraštis", R.drawable.timetable, R.raw.computer)
hashMapTime["happy hours"] = Triple("laimės valandos", R.drawable.happyhours, R.raw.computer)

hashMapTime["an event"] = Triple("renginis", R.drawable.event1, R.raw.computer)
hashMapTime["Future"] = Triple("ateitis", R.drawable.future, R.raw.computer)
hashMapTime["last year"] = Triple("praeitais metais", R.drawable.lastyear, R.raw.computer)
hashMapTime["last month"] = Triple("praeitą mėnesį", R.drawable.lastmonth, R.raw.computer)
hashMapTime["vacation"] = Triple("atostogos", R.drawable.vacation1, R.raw.computer)
hashMapTime["registration time"] = Triple("registracijos laikas", R.drawable.registration, R.raw.computer)
}

}
Binary file added app/src/main/res/drawable/abreak1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/everyday.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/future.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/half.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/happyhours.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/lastmonth.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/lastyear.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/minutes60.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/past9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/quarter7.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/registration.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/timetable.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/usually.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/weekday.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/whattime1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/yesterday.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3961427

Please sign in to comment.