-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
470 additions
and
0 deletions.
There are no files selected for viewing
207 changes: 207 additions & 0 deletions
207
app/src/main/java/com/example/visuallithuanian/AnimalFlashcardFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
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.AnimalsSingleton | ||
import com.example.visuallithuanian.constants.CinemaSingleton | ||
import com.example.visuallithuanian.database.FlashcardPair | ||
import com.example.visuallithuanian.databinding.FragmentCinemaBinding | ||
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 AnimalFlashcardFragment : Fragment() { | ||
lateinit var binding: FragmentCinemaBinding | ||
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 = 39 // 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 = FragmentCinemaBinding.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 = AnimalsSingleton.hashMapAnimals.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 >= AnimalsSingleton.hashMapAnimals.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 = AnimalsSingleton.hashMapAnimals.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 < AnimalsSingleton.hashMapAnimals.size) { | ||
// Remove the item at the current index from your data structure (e.g., HashMap) | ||
val removedTriple = AnimalsSingleton.hashMapAnimals.entries.elementAt(currentTripleIndex) | ||
AnimalsSingleton.hashMapAnimals.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 = AnimalsSingleton.hashMapAnimals.entries.elementAt(currentTripleIndex) | ||
|
||
} | ||
} | ||
} | ||
|
||
//Navigating from one fragment to another | ||
binding.cardLearning.setOnClickListener { | ||
findNavController().navigate(R.id.action_animalFlashcardFragment_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) % AnimalsSingleton.hashMapAnimals.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 = AnimalsSingleton.hashMapAnimals.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 | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app/src/main/java/com/example/visuallithuanian/constants/AnimalsSingleton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.example.visuallithuanian.constants | ||
|
||
import com.example.visuallithuanian.R | ||
|
||
object AnimalsSingleton { | ||
|
||
val hashMapAnimals = HashMap<String,Triple<String,Int,Int>>() | ||
|
||
init { | ||
hashMapAnimals["flight"] = Triple("skrydis", R.drawable.flight, R.raw.computer) | ||
hashMapAnimals["fish"] = Triple("žuvis", R.drawable.fish, R.raw.computer) | ||
hashMapAnimals["rabbit"] = Triple("triušis", R.drawable.rabbit, R.raw.computer) | ||
hashMapAnimals["hen"] = Triple("višta", R.drawable.hen, R.raw.computer) | ||
hashMapAnimals["deer"] = Triple("elnias", R.drawable.deer, R.raw.computer) | ||
hashMapAnimals["goat"] = Triple("ožka", R.drawable.goat, R.raw.computer) | ||
hashMapAnimals["zebras"] = Triple("zebras", R.drawable.zebra, R.raw.computer) | ||
hashMapAnimals["worm"] = Triple("kirminas", R.drawable.worm, R.raw.computer) | ||
hashMapAnimals["shark"] = Triple("Ryklys", R.drawable.shark, R.raw.computer) | ||
hashMapAnimals["voras"] = Triple("spider", R.drawable.spider, R.raw.computer) | ||
|
||
hashMapAnimals["seagull"] = Triple("žuvėdra", R.drawable.seagull, R.raw.computer) | ||
hashMapAnimals["chimpanzee"] = Triple("šimpanzė", R.drawable.chimpanzee, R.raw.computer) | ||
hashMapAnimals["crocodile"] = Triple("krokodilas", R.drawable.crocodile, R.raw.computer) | ||
hashMapAnimals["Lions"] = Triple("Liūtas", R.drawable.lion, R.raw.computer) | ||
hashMapAnimals["dolphin"] = Triple("delfinas", R.drawable.dolphin, R.raw.computer) | ||
hashMapAnimals["snake"] = Triple("gyvatė", R.drawable.snake, R.raw.computer) | ||
hashMapAnimals["donkey"] = Triple("asilas", R.drawable.donkey, R.raw.computer) | ||
hashMapAnimals["tiger"] = Triple("tigras", R.drawable.tiger, R.raw.computer) | ||
hashMapAnimals["mosquito"] = Triple("uodas", R.drawable.mosquito, R.raw.computer) | ||
hashMapAnimals["pig"] = Triple("kiaulė", R.drawable.pig, R.raw.computer) | ||
|
||
hashMapAnimals["jellyfish"] = Triple("medūza", R.drawable.jellyfish, R.raw.computer) | ||
hashMapAnimals["bull"] = Triple("bulius", R.drawable.bull, R.raw.computer) | ||
hashMapAnimals["gorilla"] = Triple("gorila", R.drawable.gorilla, R.raw.computer) | ||
hashMapAnimals["elephant"] = Triple("dramblys", R.drawable.elephant, R.raw.computer) | ||
hashMapAnimals["bird"] = Triple("paukštis", R.drawable.birds, R.raw.computer) | ||
hashMapAnimals["sheep"] = Triple("avis", R.drawable.sheep, R.raw.computer) | ||
hashMapAnimals["giraffe"] = Triple("žirafa", R.drawable.giraffe, R.raw.computer) | ||
hashMapAnimals["cow"] = Triple("karvė", R.drawable.cow, R.raw.computer) | ||
hashMapAnimals["parrot"] = Triple("papūga", R.drawable.parrot, R.raw.computer) | ||
hashMapAnimals["bee"] = Triple("bitė", R.drawable.bee, R.raw.computer) | ||
|
||
hashMapAnimals["monkey"] = Triple("beždžionė", R.drawable.monkey, R.raw.computer) | ||
hashMapAnimals["chicken"] = Triple("vištiena", R.drawable.chicken, R.raw.computer) | ||
hashMapAnimals["whale"] = Triple("banginis", R.drawable.whale, R.raw.computer) | ||
hashMapAnimals["butterfly"] = Triple("drugelis", R.drawable.butterfly, R.raw.computer) | ||
hashMapAnimals["kangaroo"] = Triple("kengūra", R.drawable.kangaroo, R.raw.computer) | ||
hashMapAnimals["bear"] = Triple("meška", R.drawable.bear, R.raw.computer) | ||
hashMapAnimals["horse"] = Triple("arklys", R.drawable.horse, R.raw.computer) | ||
hashMapAnimals["camel"] = Triple("kupranugaris", R.drawable.camel, R.raw.computer) | ||
hashMapAnimals["beetle"] = Triple("vabalas", R.drawable.beetle, R.raw.computer) | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.