-
-
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
24 changed files
with
518 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
211 changes: 211 additions & 0 deletions
211
app/src/main/java/com/example/visuallithuanian/TimeFlashcardFragment.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,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 | ||
|
||
} | ||
|
||
|
||
} |
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
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/example/visuallithuanian/constants/TimeSingleton.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,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) | ||
} | ||
|
||
} |
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.