Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasily Horodetskyi committed Dec 2, 2022
1 parent f69f8e0 commit 6f0d0bd
Show file tree
Hide file tree
Showing 19 changed files with 554 additions and 78 deletions.
1 change: 1 addition & 0 deletions .idea/misc.xml

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

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

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

58 changes: 35 additions & 23 deletions .idea/sonarlint/issuestore/index.pb

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

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId "com.maestrovs.slovo"
minSdk 23
targetSdk 32
versionCode 2
versionName "1.1"
versionCode 3
versionName "1.3.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/maestrovs/slovo/data/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import androidx.room.PrimaryKey
@Entity
data class Game(
@ColumnInfo(name = "slovo") val slovo: String?,
@ColumnInfo(name = "step") val step: Int?
@ColumnInfo(name = "step") val step: Int?,
@ColumnInfo(name = "num") val num: Int?,
@ColumnInfo(name = "result") val result: Boolean?
){
@PrimaryKey(autoGenerate = true)
var id: Int = 0
Expand Down
54 changes: 32 additions & 22 deletions app/src/main/java/com/maestrovs/slovo/screens/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class MainViewModel(application: Application) : BaseViewModel(application) {

var slovo: String? = null

var attempt = 0
var attemptSlovo: String? = null;


//private var savedSlovo: String? = null
private var savedWords: HashSet<String> = hashSetOf()
Expand Down Expand Up @@ -96,30 +99,37 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
}
}



if(restoredSlovo != null && !savedSteps.isNullOrEmpty()){
slovo = restoredSlovo!!
callback(Game(restoredSlovo!!, 0), list)
}else {

BehaviorSubject.create { emitter: ObservableEmitter<List<Game>> ->
val games = db.userDao().getRandomSlovo()
emitter.onNext(games)
}.hide()
.observeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.newThread())
.subscribe({
if (it.isEmpty()) {
callback(Game("ФІНІШ", 0),null)
} else {
slovo = it[0].slovo
callback(it[0], null)
}
attemptSlovo = null; attempt = 0;
callback(Game(restoredSlovo!!, 0,0,false), list)
}else if(attemptSlovo != null) {
slovo = attemptSlovo!!
callback(Game(attemptSlovo!!, 0,0,false), list)
}else{
attemptSlovo = null; attempt = 0;
BehaviorSubject.create { emitter: ObservableEmitter<List<Game>> ->
val games = db.userDao().getRandomSlovo()
emitter.onNext(games)
}.hide()
.observeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.newThread())
.subscribe({
if (it.isEmpty()) {
callback(Game("ФІНІШ", 0,0,false),null)
} else {
slovo = it[0].slovo
callback(it[0], null)
}

}, {
errorMessage.postValue(it.localizedMessage)
}).addTo(disposable)
}

}, {
errorMessage.postValue(it.localizedMessage)
}).addTo(disposable)
}
}

fun updateSlovoStepInDB(game: Game){
Expand Down Expand Up @@ -217,7 +227,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
var count = 0
dictionary.map {
Completable.create { emitter ->
db.userDao().insertAll(Game(it.uppercase(),0))
db.userDao().insertAll(Game(it.uppercase(),0,0,false))
emitter.onComplete()}
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.newThread())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package com.maestrovs.slovo.screens.game_end

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.maestrovs.slovo.R
import com.maestrovs.slovo.databinding.FragmentGameEndBinding
import com.maestrovs.slovo.screens.base.BaseFragment
import com.maestrovs.slovo.screens.extensions.applyFont
import com.maestrovs.slovo.screens.MainActivity
import com.maestrovs.slovo.screens.MainViewModel
import com.maestrovs.slovo.screens.main.MainScreenFragmentDirections


class GameEndFragment : BaseFragment() {

private val mainScreenViewModel by lazy {
ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java).apply {
lifecycle.addObserver(this)
}
}

private val gameEndViewModel by lazy {
ViewModelProvider(this).get(GameEndViewModel::class.java).apply {
lifecycle.addObserver(this)
}
}
private var _binding: FragmentGameEndBinding? = null
private val binding get() = _binding!!
lateinit var mainActivity: MainActivity

private val safeArgs: GameEndFragmentArgs by navArgs()

var canShowMeaningOfWord = true;

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
gameEndViewModel.navController = findNavController()
_binding = FragmentGameEndBinding.inflate(inflater, container, false)
val root: View = binding.root
applyFont(requireContext(), root, "fonts/Comfortaa-Regular.ttf")

// binding.title.text = safeArgs.slovo

canShowMeaningOfWord = safeArgs.isWin

binding.tvTitle.setTextColor(ContextCompat.getColor(requireContext(),
if(safeArgs.isWin) {
R.color.green
}else{
R.color.red
}
))

binding.tvTitle.text = if(safeArgs.isWin) {
"Вірно!"
}else{
"Не вгадали"
}

binding.tvSlovo.visibility = if(safeArgs.isWin) {
View.VISIBLE
}else{
View.VISIBLE
}


binding.tvSlovo.text = if(safeArgs.isWin) {
safeArgs.slovo
}else{
safeArgs.slovo //"✜ ✜ ✜ ✜ ✜"
}

binding.btShow.visibility = if(safeArgs.isWin) {
View.GONE
}else{
View.GONE
}

binding.btAgain.visibility = if(safeArgs.isWin) {
View.GONE
}else{
View.GONE
}

binding.btMeaning.visibility = if(safeArgs.isWin) {
View.VISIBLE
}else{
//View.GONE
View.VISIBLE
}

binding.ivResult.setImageDrawable(ContextCompat.getDrawable(requireContext(),
if(safeArgs.isWin){
R.drawable.ic_orn_green
}else{
R.drawable.ic_orn_red
}
))

binding.btMeaning.setOnClickListener {
safeArgs.slovo.let {
findNavController().navigate(GameEndFragmentDirections.actionGameEndFragmentToWebViewFragment(it))
}
}

binding.btNext.setOnClickListener {
findNavController().popBackStack()
}


/*mainScreenViewModel.getGamesCount {
Log.d("Game", "Games count = $it")
if (it == null || it == 0)
{
binding.dicText.visibility = View.VISIBLE
mainScreenViewModel.readDictionary { dic ->
var totalCnt = dic.size
binding.dicProgress.max = totalCnt
mainScreenViewModel.writeDictionaryToDB(dic, { progress ->
// Log.d("Game", "Progress = $progress")
binding.dicProgress.progress = progress
},
{
launchGame(false)
})
}
} else {
launchGame(true)
}
}*/

/// findNavController().navigate(SplashScreenFragmentDirections.actionSplashScreenFragmentToWebViewFragment("слово"))

return root
}

private fun launchGame(withDelay: Boolean) {
/* Handler(Looper.getMainLooper()).postDelayed(
{
splashViewModel.onMainScreen()
}, if (withDelay) {
delay
} else {
0
}
)*/
}


override fun onDestroyView() {
super.onDestroyView()
// binding.clMessage.animate().cancel()
_binding = null
}


}
Loading

0 comments on commit 6f0d0bd

Please sign in to comment.