Skip to content
Snippets Groups Projects
Unverified Commit 1cb719f4 authored by Cseh Viktor's avatar Cseh Viktor
Browse files

Results added

parent 4a086990
No related branches found
No related tags found
No related merge requests found
Showing
with 310 additions and 11 deletions
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="XML">
<option name="FORCE_REARRANGE_MODE" value="1" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>
\ No newline at end of file
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
\ No newline at end of file
...@@ -7,12 +7,13 @@ ...@@ -7,12 +7,13 @@
<entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/drawable-v24/round_menu_20.xml" value="0.32685185185185184" /> <entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/drawable-v24/round_menu_20.xml" value="0.32685185185185184" />
<entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/drawable-v24/round_menu_24.xml" value="0.32685185185185184" /> <entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/drawable-v24/round_menu_24.xml" value="0.32685185185185184" />
<entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/drawable/ic_launcher_background.xml" value="0.2765625" /> <entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/drawable/ic_launcher_background.xml" value="0.2765625" />
<entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/activity_main.xml" value="0.3484375" /> <entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/activity_main.xml" value="0.19899103139013452" />
<entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/activity_question.xml" value="0.33" /> <entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/activity_question.xml" value="0.33" />
<entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/activity_question_list.xml" value="0.33" /> <entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/activity_question_list.xml" value="0.33" />
<entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/activity_user_name.xml" value="0.25" /> <entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/activity_user_name.xml" value="0.25" />
<entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/header_navigation_drawer.xml" value="0.20260416666666667" /> <entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/header_navigation_drawer.xml" value="0.20260416666666667" />
<entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/question_item.xml" value="0.33" /> <entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/question_item.xml" value="0.33" />
<entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/layout/result_item.xml" value="0.25" />
<entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/menu/navigation_drawer.xml" value="0.5" /> <entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/menu/navigation_drawer.xml" value="0.5" />
<entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/menu/top_app_bar.xml" value="0.2814814814814815" /> <entry key="..\:/Users/csehv/AndroidStudioProjects/Kikerdezo/app/src/main/res/menu/top_app_bar.xml" value="0.2814814814814815" />
</map> </map>
......
...@@ -16,10 +16,12 @@ ...@@ -16,10 +16,12 @@
android:theme="@style/Theme.Kikerdezo" android:theme="@style/Theme.Kikerdezo"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
tools:targetApi="m"> tools:targetApi="m">
<activity
android:name=".ResultsActivity"
android:exported="false" />
<activity <activity
android:name=".UserName" android:name=".UserName"
android:exported="false" > android:exported="false"></activity>
</activity>
<activity <activity
android:name=".QuestionListActivity" android:name=".QuestionListActivity"
android:exported="false" android:exported="false"
...@@ -30,6 +32,7 @@ ...@@ -30,6 +32,7 @@
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
......
package hu.bme.kszk.kikerdezo package hu.bme.kszk.kikerdezo
import android.content.ClipData
import android.content.Intent import android.content.Intent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
...@@ -8,7 +7,6 @@ import android.preference.PreferenceManager ...@@ -8,7 +7,6 @@ import android.preference.PreferenceManager
import android.provider.AlarmClock.EXTRA_MESSAGE import android.provider.AlarmClock.EXTRA_MESSAGE
import android.util.Log import android.util.Log
import android.widget.Button import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.core.view.GravityCompat import androidx.core.view.GravityCompat
...@@ -189,10 +187,13 @@ class MainActivity : AppCompatActivity() { ...@@ -189,10 +187,13 @@ class MainActivity : AppCompatActivity() {
navigationView.setNavigationItemSelectedListener { menuItem -> navigationView.setNavigationItemSelectedListener { menuItem ->
val id = menuItem.itemId val id = menuItem.itemId
if (id == R.id.eredmenyek) { if (id == R.id.eredmenyek) {
//startActivity(Intent(this, )) startActivity(Intent(this, ResultsActivity::class.java))
} else if (id == R.id.nev_megadas) { } else if (id == R.id.nev_megadas) {
startActivity(Intent(this, UserName::class.java)) startActivity(Intent(this, UserName::class.java))
} }
else if (id == R.id.kikerdezo) {
//semmi
}
drawerLayout.closeDrawer(GravityCompat.START) drawerLayout.closeDrawer(GravityCompat.START)
true true
} }
...@@ -244,11 +245,11 @@ class MainActivity : AppCompatActivity() { ...@@ -244,11 +245,11 @@ class MainActivity : AppCompatActivity() {
private fun loadToDatabase(recivedQuestionData: QuestionData?) { private fun loadToDatabase(recivedQuestionData: QuestionData?) {
thread{ thread{
AppDatabase.getInstance(this).clearAllTables() AppDatabase.getInstanceQuestion(this).clearAllTables()
if (recivedQuestionData != null) { if (recivedQuestionData != null) {
if(recivedQuestionData.data != null) { if(recivedQuestionData.data != null) {
for (question in recivedQuestionData.data!!) for (question in recivedQuestionData.data!!)
AppDatabase.getInstance(this).questionDao().insertQuestion( AppDatabase.getInstanceQuestion(this).questionDao().insertQuestion(
question question
) )
Log.d("DATABASE_LOADED", "database loaded to sqlite") Log.d("DATABASE_LOADED", "database loaded to sqlite")
......
...@@ -34,7 +34,7 @@ class QuestionListActivity : AppCompatActivity() { ...@@ -34,7 +34,7 @@ class QuestionListActivity : AppCompatActivity() {
questionAdapter = Adapter(this) questionAdapter = Adapter(this)
val rvMain: RecyclerView = findViewById(R.id.rvMain) val rvMain: RecyclerView = findViewById(R.id.rvMain)
rvMain.adapter = questionAdapter rvMain.adapter = questionAdapter
AppDatabase.getInstance(this).questionDao().getLabQuestion(b).observe(this, {questions -> AppDatabase.getInstanceQuestion(this).questionDao().getLabQuestion(b).observe(this, { questions ->
questionAdapter.submitList(questions) questionAdapter.submitList(questions)
}) })
} }
......
package hu.bme.kszk.kikerdezo
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.preference.PreferenceManager
import android.util.Log
import android.widget.TextView
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.navigation.NavigationView
import hu.bme.kszk.kikerdezo.adapter.ResultAdapter
import hu.bme.kszk.kikerdezo.database.AppDatabase
class ResultsActivity : AppCompatActivity() {
private lateinit var resAdapter : ResultAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_results)
setUserName()
val topAppBar = findViewById<MaterialToolbar>(R.id.topAppBar)
val drawerLayout = findViewById<DrawerLayout>(R.id.drawer_layout)
val navigationView = findViewById<NavigationView>(R.id.navigation_view)
topAppBar.setNavigationOnClickListener {
drawerLayout.openDrawer(navigationView)
}
navigationView.setNavigationItemSelectedListener { menuItem ->
val id = menuItem.itemId
if (id == R.id.eredmenyek) {
//Semmi, itt vagy pls
} else if (id == R.id.nev_megadas) {
startActivity(Intent(this, UserName::class.java))
} else if (id == R.id.kikerdezo) {
finish() //csak onnan lehet elinditani
}
drawerLayout.closeDrawer(GravityCompat.START)
true
}
initRecycleView()
}
private fun initRecycleView() {
resAdapter = ResultAdapter(this)
val rvResults: RecyclerView = findViewById(R.id.rvResults)
rvResults.adapter = resAdapter
AppDatabase.getInstanceResult(this).resultsDao().getResults().observe(this, { results ->
resAdapter.submitList(results)
})
}
private fun setUserName() {
val navigationView = findViewById<NavigationView>(R.id.navigation_view)
val headerView = navigationView.getHeaderView(0)
val name = headerView.findViewById<TextView>(R.id.playerName)
val sp = PreferenceManager.getDefaultSharedPreferences(this)
sp.getString("USERNAME", "PlayerOne")?.let { Log.d("USERNAME", it) }
name.text?.let { name.text = sp.getString("USERNAME", "PlayerOne").toString() }
}
}
\ No newline at end of file
package hu.bme.kszk.kikerdezo.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import hu.bme.kszk.kikerdezo.R
import hu.bme.kszk.kikerdezo.model.Result
class ResultAdapter(val context: Context) :
ListAdapter<Result, ResultAdapter.ResultViewHolder>(ResultDiffCallback){
class ResultViewHolder(itemView: View):
RecyclerView.ViewHolder(itemView) {
private val score: TextView = itemView.findViewById(R.id.score)
private val name: TextView = itemView.findViewById(R.id.name)
private val date: TextView = itemView.findViewById(R.id.date)
init{
}
fun bind(result: Result){
score.text = result.score.toString()
name.text = result.uname
date.text = result.date.toString()
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : ResultAdapter.ResultViewHolder {
// Create a new view, which defines the UI of the list item
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.result_item, parent, false)
return ResultAdapter.ResultViewHolder(view)
}
override fun onBindViewHolder(holder: ResultAdapter.ResultViewHolder, position: Int) {
val result = getItem(position)
holder.bind(result)
}
}
object ResultDiffCallback : DiffUtil.ItemCallback<Result>() {
override fun areItemsTheSame(oldItem: Result, newItem: Result): Boolean {
return oldItem == newItem
}
override fun areContentsTheSame(oldItem: Result, newItem: Result): Boolean {
return oldItem.id == newItem.id
}
}
\ No newline at end of file
...@@ -9,11 +9,12 @@ import hu.bme.kszk.kikerdezo.model.Question ...@@ -9,11 +9,12 @@ import hu.bme.kszk.kikerdezo.model.Question
@Database(entities = [Question::class], version = 1) @Database(entities = [Question::class], version = 1)
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
abstract fun questionDao(): QuestionDao abstract fun questionDao(): QuestionDao
abstract fun resultsDao(): ResultDao
companion object { companion object {
private var INSTANCE: AppDatabase? = null private var INSTANCE: AppDatabase? = null
fun getInstance(context: Context): AppDatabase { fun getInstanceQuestion(context: Context): AppDatabase {
if (INSTANCE == null) { if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(), INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
AppDatabase::class.java, "question.db") AppDatabase::class.java, "question.db")
...@@ -22,6 +23,15 @@ abstract class AppDatabase : RoomDatabase() { ...@@ -22,6 +23,15 @@ abstract class AppDatabase : RoomDatabase() {
} }
return INSTANCE!! return INSTANCE!!
} }
fun getInstanceResult(context: Context): AppDatabase {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
AppDatabase::class.java, "result.db")
.fallbackToDestructiveMigration()
.build()
}
return INSTANCE!!
}
fun destroyInstance() { fun destroyInstance() {
INSTANCE = null INSTANCE = null
......
package hu.bme.kszk.kikerdezo.database
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import hu.bme.kszk.kikerdezo.model.Result
@Dao
interface ResultDao {
@Query("SELECT * FROM result ORDER BY score")
fun getResults(): LiveData<List<Result>>
@Insert
fun insertResult(result: Result) : Long
}
\ No newline at end of file
package hu.bme.kszk.kikerdezo.model
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import java.util.*
@Entity(tableName = "result")
data class Result(
@PrimaryKey(autoGenerate = true) var id: Int,
@ColumnInfo(name = "uname") var uname: String,
@ColumnInfo(name = "score") var score: Int,
@ColumnInfo(name = "date") var date: Date
)
app/src/main/res/drawable-hdpi/baseline_quiz_black_18.png

287 B

app/src/main/res/drawable-hdpi/baseline_quiz_black_20.png

274 B

app/src/main/res/drawable-hdpi/baseline_quiz_black_24.png

309 B

app/src/main/res/drawable-hdpi/baseline_quiz_black_36.png

424 B

app/src/main/res/drawable-hdpi/baseline_quiz_black_48.png

539 B

app/src/main/res/drawable-mdpi/baseline_quiz_black_18.png

229 B

app/src/main/res/drawable-mdpi/baseline_quiz_black_20.png

192 B

app/src/main/res/drawable-mdpi/baseline_quiz_black_24.png

220 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment