Skip to content

Commit

Permalink
Merge branch '1_2_release' into fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VolgoAK committed Sep 7, 2019
2 parents ba51675 + 07e0ee3 commit 4356381
Show file tree
Hide file tree
Showing 26 changed files with 408 additions and 218 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

29 changes: 8 additions & 21 deletions app/src/main/java/com/example/sergey/shlypa2/db/DataProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.example.sergey.shlypa2.beans.Word
import com.example.sergey.shlypa2.game.GameState
import com.example.sergey.shlypa2.game.PlayerType
import com.example.sergey.shlypa2.utils.Functions
import com.example.sergey.shlypa2.utils.GameStateSaver
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import timber.log.Timber
Expand All @@ -21,7 +22,8 @@ import java.util.*
class DataProvider(
db: DataBase,
private val gson: Gson,
private val context: Context
private val context: Context,
private val gameStateSaver:GameStateSaver
) {

private val playersDao = db.playersDao()
Expand Down Expand Up @@ -65,35 +67,20 @@ class DataProvider(
}

fun getSavedStates(): List<GameState> {
var savedList = stateDao.getAllStates()

//keep only 5 states
if (savedList.size > 5) {
val sortesList = savedList.sortedByDescending { it.time }
sortesList.subList(4, sortesList.size - 1)
.forEach { stateDao.deleteState(it.gameId) }

savedList = stateDao.getAllStates()
}

return savedList.map { gson.fromJson(it.state, GameState::class.java) }
return gameStateSaver.loadState()
}

fun getLastSavedState(): GameState? {
val savedList = stateDao.getAllStates()
val lastSaved = savedList.maxBy { it.time }

return lastSaved?.let { gson.fromJson(lastSaved.state, GameState::class.java) }
return gameStateSaver.getLastSavedState()
}

fun insertState(state: GameState) {
val represent = StateRepresent(0, state.gameId, System.currentTimeMillis(), gson.toJson(state))
Timber.d(represent.state)
stateDao.insertState(represent)
gameStateSaver.insertState(state)
}

fun deleteState(gameId: Int) {
stateDao.deleteState(gameId)
//stateDao.deleteState(gameId)
gameStateSaver.deleteState(gameId)
}

fun getListOfAvatars(): List<String> {
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/example/sergey/shlypa2/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.example.sergey.shlypa2.screens.settings.SettingsViewModel
import com.example.sergey.shlypa2.screens.splash.LaunchViewModel
import com.example.sergey.shlypa2.screens.words_in.WordsViewModel
import com.example.sergey.shlypa2.utils.DbExporter
import com.example.sergey.shlypa2.utils.GameStateSaver
import com.example.sergey.shlypa2.utils.PreferencesProvider
import com.example.sergey.shlypa2.utils.SoundManager
import com.example.sergey.shlypa2.utils.anal.AnalSender
Expand Down Expand Up @@ -49,13 +50,15 @@ val appModule = module {

single { createGson() }

single{GameStateSaver(get())}

single { createDb(get()) }
single { (db: DataBase) -> db.typesDap() }
single { (db: DataBase) -> db.playersDao() }
single { (db: DataBase) -> db.stateDao() }
single { (db: DataBase) -> db.wordDao() }

single { DataProvider(get(), get(), get()) }
single { DataProvider(get(), get(), get(),get()) }

single { FirebaseAnalytics.getInstance(get()) }
single { if (BuildConfig.DEBUG) FlurryFacadeDebug() else FlurryFacadeRelease() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import android.app.Activity
import android.content.Context
import android.content.res.Resources
import android.os.Handler
import android.view.MotionEvent
import android.view.View
import android.view.ViewTreeObserver
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.SeekBar
Expand Down Expand Up @@ -99,6 +101,43 @@ fun View.onPreDraw(block: () -> Unit) {
}
})
}
fun EditText.onActionDone(returnCompleted: Boolean = true,
returnNotCompleted: Boolean = true, block: () -> Unit) {
onAction(EditorInfo.IME_ACTION_DONE, returnCompleted, returnNotCompleted, block)
}

fun EditText.onActionNext(returnCompleted: Boolean = true,
returnNotCompleted: Boolean = true,
block: () -> Unit) {
onAction(EditorInfo.IME_ACTION_NEXT, returnCompleted, returnNotCompleted, block)
}

fun EditText.onTouchRightDrawable(block: () -> Unit) {
setOnTouchListener { _, event ->
if (event.action == MotionEvent.ACTION_UP) {
if (event.rawX >= (right - compoundDrawables[2].bounds.width())) {
block.invoke()
return@setOnTouchListener true
}
}
false
}
}

fun EditText.onAction(action: Int,
returnCompleted: Boolean = true,
returnNotCompleted: Boolean = true,
block: () -> Unit) {
setOnEditorActionListener { _, actionId, _ ->
return@setOnEditorActionListener when (actionId) {
action -> {
block.invoke()
returnCompleted
}
else -> returnNotCompleted
}
}
}

/**
* Returns a random element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RoundStartFragment : Fragment() {
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.hint_menu, menu)
inflater.inflate(R.menu.hint_team_menu, menu)
super.onCreateOptionsMenu(menu, inflater)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TurnStartFragment : Fragment() {
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.hint_menu, menu)
inflater.inflate(R.menu.hint_team_menu, menu)
super.onCreateOptionsMenu(menu, inflater)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.example.sergey.shlypa2.screens.words_in


import android.view.View
import android.widget.ImageButton
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.sergey.shlypa2.R
import com.example.sergey.shlypa2.beans.Word
import com.example.sergey.shlypa2.extensions.gone
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import eu.davidea.flexibleadapter.items.IFlexible
import eu.davidea.viewholders.FlexibleViewHolder


class WordItem(private val flagChange: Boolean,
private val word: Word,
private val listenerAction:(Pair<WordAct,Int>)->Unit) : AbstractFlexibleItem<WordItem.ViewHolder>() {

override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?,
holder: ViewHolder,
position: Int,
payloads: MutableList<Any>) {
with(holder){
tvName.text = word.word
if (!flagChange) ibChangeWord.gone()

ibDeleteWord.setOnClickListener {
listenerAction.invoke(Pair(WordAct.DELETE,position))
}

ibChangeWord.setOnClickListener {
listenerAction.invoke(Pair(WordAct.CHANGE,position))
}
}

}

override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?) = WordItem.ViewHolder(view, adapter)

override fun equals(other: Any?) = other is WordItem

override fun getLayoutRes() = R.layout.holder_word

class ViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?)
: FlexibleViewHolder(view, adapter) {
val tvName: TextView = view.findViewById(R.id.wordInject)
val ibDeleteWord: ImageButton = view.findViewById(R.id.ibDelWord)
val ibChangeWord: ImageButton = view.findViewById(R.id.ibChangeWord)
}
}

enum class WordAct{
DELETE,
CHANGE
}
Loading

0 comments on commit 4356381

Please sign in to comment.