From 5db76e159e3cbef57a608e22db7e20c2a338ffe5 Mon Sep 17 00:00:00 2001 From: jiabaow Date: Sat, 28 May 2022 09:16:40 +0200 Subject: [PATCH 01/37] refactor DeleteSongsActivity.kt --- .../vibester/activity/DeleteSongsActivity.kt | 51 ++++++++++++++----- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/activity/DeleteSongsActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/DeleteSongsActivity.kt index 996d24413..d8713721e 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/DeleteSongsActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/DeleteSongsActivity.kt @@ -1,22 +1,23 @@ package ch.sdp.vibester.activity -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.os.Environment import android.view.Gravity import android.view.View import android.view.ViewGroup.LayoutParams +import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.view.Window import android.widget.Button import android.widget.LinearLayout import android.widget.LinearLayout.LayoutParams.MATCH_PARENT -import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.TextView import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity import ch.sdp.vibester.R import ch.sdp.vibester.helper.Helper import com.google.android.material.floatingactionbutton.FloatingActionButton import java.io.* + /** * Class that handles deleting files, more specifically songs in the scope of this project. */ @@ -28,7 +29,10 @@ class DeleteSongsActivity : AppCompatActivity() { setContentView(R.layout.activity_delete_songs) - Helper().setReturnToMainListener(findViewById(R.id.delete_returnToMain), this) + Helper().setReturnToMainListener( + findViewById(R.id.delete_returnToMain), + this + ) val layout: LinearLayout = findViewById(R.id.delete_songs_linear) generateButtons(layout) @@ -39,18 +43,21 @@ class DeleteSongsActivity : AppCompatActivity() { * Assigns each button a call to the "deleteDownloadedSong" function as a listener. */ private fun generateButtons(layout: LinearLayout) { - val records = File(applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "records.txt") + val records = File( + applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), + "records.txt" + ) - if(!records.exists() || records.length() == 0L) { + if (!records.exists() || records.length() == 0L) { createNoSongsView(layout) } else { val reader = BufferedReader(FileReader(records)) var currentLine = reader.readLine() var iterator = 0 - while(currentLine != null) { + while (currentLine != null) { val trimmed = currentLine.trim() - if(trimmed.isNotEmpty()) { + if (trimmed.isNotEmpty()) { val deleteButton = createButton(trimmed, iterator, layout) layout.addView(deleteButton) } @@ -81,8 +88,14 @@ class DeleteSongsActivity : AppCompatActivity() { * from the text file which keeps track of all downloads. */ private fun deleteDownloadedSong(btn: View, layout: LinearLayout): Boolean { - val records = File(applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "records.txt") - val tempRecords = File(applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "temp.txt") + val records = File( + applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), + "records.txt" + ) + val tempRecords = File( + applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), + "temp.txt" + ) val recordReader = BufferedReader(FileReader(records)) val recordWriter = BufferedWriter(FileWriter(tempRecords, true)) @@ -114,7 +127,10 @@ class DeleteSongsActivity : AppCompatActivity() { records.delete() if (tempRecords.renameTo(records) && removeFromProperties(buttonText)) { layout.removeView(btn) - val songToDelete = File(applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "extract_of_${button.text}") + val songToDelete = File( + applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), + "extract_of_${button.text}" + ) if (songToDelete.delete()) { Toast.makeText(applicationContext, "Song successfully removed!", Toast.LENGTH_LONG).show() return true @@ -125,12 +141,18 @@ class DeleteSongsActivity : AppCompatActivity() { } /** - * Removes the line correspoding to the song-to-be-deleted from the properties.txt file. + * Removes the line corresponding to the song-to-be-deleted from the properties.txt file. * @param buttonText: Text which contains song name - artist name */ private fun removeFromProperties(buttonText: String): Boolean { - val properties = File(applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "properties.txt") - val tempProp = File(applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "tempProp.txt") + val properties = File( + applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), + "properties.txt" + ) + val tempProp = File( + applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), + "tempProp.txt" + ) val propReader = BufferedReader(FileReader(properties)) val propWriter = BufferedWriter(FileWriter(tempProp, true)) @@ -149,7 +171,8 @@ class DeleteSongsActivity : AppCompatActivity() { val split = trimmed.split(" - ") if (split[0].trim().lowercase() == buttonSplit[0].trim().lowercase() - && split[1].trim().lowercase() == buttonSplit[1].trim().lowercase()) { + && split[1].trim().lowercase() == buttonSplit[1].trim().lowercase() + ) { currentLine = propReader.readLine() continue } From 2e23febca73a28e9ddd13cbd7ea56f6e616af902 Mon Sep 17 00:00:00 2001 From: jiabaow Date: Sat, 28 May 2022 09:28:45 +0200 Subject: [PATCH 02/37] refactor GameEndingActivity.kt --- .../sdp/vibester/activity/GameEndingActivity.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/activity/GameEndingActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/GameEndingActivity.kt index 5ef3457ea..b070a4d51 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/GameEndingActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/GameEndingActivity.kt @@ -12,7 +12,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import ch.sdp.vibester.R import ch.sdp.vibester.database.AppPreferences -import ch.sdp.vibester.helper.AdapterHelper import ch.sdp.vibester.helper.Helper import ch.sdp.vibester.model.SongListAdapter import ch.sdp.vibester.user.OnItemClickListener @@ -23,7 +22,8 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton */ class GameEndingActivity : DownloadFunctionalityActivity(), OnItemClickListener { - private val endStatArrayList = arrayListOf(R.id.end_stat1, R.id.end_stat2, R.id.end_stat3, R.id.end_stat4) + private val endStatArrayList = + arrayListOf(R.id.end_stat1, R.id.end_stat2, R.id.end_stat3, R.id.end_stat4) private var incorrectSongList: ArrayList = arrayListOf() private var correctSongList: ArrayList = arrayListOf() @@ -45,8 +45,7 @@ class GameEndingActivity : DownloadFunctionalityActivity(), OnItemClickListener if (gameMode == "local_typing" || gameMode == "local_lyrics") { setContentView(R.layout.activity_end_solo) getFromIntentSolo(intent) - } - else { + } else { setContentView(R.layout.activity_end_multiple) getFromIntentMultiple(intent) } @@ -76,8 +75,9 @@ class GameEndingActivity : DownloadFunctionalityActivity(), OnItemClickListener /** * Set text for game mode */ - private fun setGameMode(){ - val gameMode = AppPreferences.getStr(getString(R.string.preferences_game_mode))?.replace("_", " ")?.replaceFirstChar { it.uppercase() } + private fun setGameMode() { + val gameMode = + AppPreferences.getStr(getString(R.string.preferences_game_mode))?.replace("_", " ")?.replaceFirstChar { it.uppercase() } val gameGenre = AppPreferences.getStr(getString(R.string.preferences_game_genre)) findViewById(R.id.end_game_mode).text = "$gameMode - $gameGenre" } @@ -175,8 +175,8 @@ class GameEndingActivity : DownloadFunctionalityActivity(), OnItemClickListener //Logic to switch item visibility and start the download attempt val songList = incorrectSongList + correctSongList - if(downloadComplete) { - Log.d("-----------------------------","++++++++++++++++++++++++++++++++++++") + if (downloadComplete) { + Log.d("-----------------------------", "++++++++++++++++++++++++++++++++++++") downloadButton.visibility = View.INVISIBLE downloadOngoing.visibility = View.VISIBLE Log.d("name of button is ============================ ", "${downloadButton.id}") From e0303a791ab8f267dd08ee3e3e66073a14574a9e Mon Sep 17 00:00:00 2001 From: jiabaow Date: Sat, 28 May 2022 09:30:19 +0200 Subject: [PATCH 03/37] refactor SongListAdapter.kt --- .../main/java/ch/sdp/vibester/model/SongListAdapter.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/model/SongListAdapter.kt b/app/src/main/java/ch/sdp/vibester/model/SongListAdapter.kt index b832ccbc8..41f0a6cd7 100644 --- a/app/src/main/java/ch/sdp/vibester/model/SongListAdapter.kt +++ b/app/src/main/java/ch/sdp/vibester/model/SongListAdapter.kt @@ -1,14 +1,11 @@ package ch.sdp.vibester.model -import android.util.Log import android.view.View import android.view.ViewGroup -import android.widget.Adapter import android.widget.Button import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import ch.sdp.vibester.R -import ch.sdp.vibester.activity.DownloadFunctionalityActivity import ch.sdp.vibester.helper.AdapterHelper import ch.sdp.vibester.user.OnItemClickListener @@ -20,7 +17,7 @@ class SongListAdapter constructor( private val incorrectSongList: ArrayList, correctSongList: ArrayList, private val listener: OnItemClickListener? - ): RecyclerView.Adapter() { +) : RecyclerView.Adapter() { private val songList: ArrayList = arrayListOf() init { @@ -50,7 +47,8 @@ class SongListAdapter constructor( /** * Customer ViewHolder class for SongList. Each item contains the name of the song and a button. */ - inner class SongListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener { + inner class SongListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), + View.OnClickListener { fun bind(songName: String) { itemView.findViewById(R.id.song_name).text = songName From a93c0b7dc427f527c903356629ad9e0a9d157158 Mon Sep 17 00:00:00 2001 From: jiabaow Date: Sat, 28 May 2022 09:34:57 +0200 Subject: [PATCH 04/37] rename to SongListAdapterForEndGame.kt --- .../java/ch/sdp/vibester/activity/GameEndingActivity.kt | 6 +++--- .../{SongListAdapter.kt => SongListAdapterForEndGame.kt} | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename app/src/main/java/ch/sdp/vibester/model/{SongListAdapter.kt => SongListAdapterForEndGame.kt} (94%) diff --git a/app/src/main/java/ch/sdp/vibester/activity/GameEndingActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/GameEndingActivity.kt index b070a4d51..ae7260af3 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/GameEndingActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/GameEndingActivity.kt @@ -13,7 +13,7 @@ import androidx.recyclerview.widget.RecyclerView import ch.sdp.vibester.R import ch.sdp.vibester.database.AppPreferences import ch.sdp.vibester.helper.Helper -import ch.sdp.vibester.model.SongListAdapter +import ch.sdp.vibester.model.SongListAdapterForEndGame import ch.sdp.vibester.user.OnItemClickListener import com.google.android.material.floatingactionbutton.FloatingActionButton @@ -30,7 +30,7 @@ class GameEndingActivity : DownloadFunctionalityActivity(), OnItemClickListener private var statNames: ArrayList = arrayListOf() private var statValues: ArrayList = arrayListOf() - lateinit var songListAdapter: SongListAdapter + lateinit var songListAdapter: SongListAdapterForEndGame private var recyclerView: RecyclerView? = null /** @@ -68,7 +68,7 @@ class GameEndingActivity : DownloadFunctionalityActivity(), OnItemClickListener recyclerView!!.setHasFixedSize(true) recyclerView!!.layoutManager = LinearLayoutManager(this) - songListAdapter = SongListAdapter(incorrectSongList, correctSongList, this) + songListAdapter = SongListAdapterForEndGame(incorrectSongList, correctSongList, this) recyclerView!!.adapter = songListAdapter } diff --git a/app/src/main/java/ch/sdp/vibester/model/SongListAdapter.kt b/app/src/main/java/ch/sdp/vibester/model/SongListAdapterForEndGame.kt similarity index 94% rename from app/src/main/java/ch/sdp/vibester/model/SongListAdapter.kt rename to app/src/main/java/ch/sdp/vibester/model/SongListAdapterForEndGame.kt index 41f0a6cd7..6d0986ff3 100644 --- a/app/src/main/java/ch/sdp/vibester/model/SongListAdapter.kt +++ b/app/src/main/java/ch/sdp/vibester/model/SongListAdapterForEndGame.kt @@ -13,11 +13,11 @@ import ch.sdp.vibester.user.OnItemClickListener /** * SongListAdapter to set correct/wrong guessed songs in the game. */ -class SongListAdapter constructor( +class SongListAdapterForEndGame constructor( private val incorrectSongList: ArrayList, correctSongList: ArrayList, private val listener: OnItemClickListener? -) : RecyclerView.Adapter() { +) : RecyclerView.Adapter() { private val songList: ArrayList = arrayListOf() init { From 862e068f66788d12edf7fc8ab454f7b946f794bd Mon Sep 17 00:00:00 2001 From: jiabaow Date: Sat, 28 May 2022 09:36:14 +0200 Subject: [PATCH 05/37] rename to song_item_download_layout.xml --- .../java/ch/sdp/vibester/model/SongListAdapterForEndGame.kt | 2 +- .../{song_item_layout.xml => song_item_download_layout.xml} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename app/src/main/res/layout/{song_item_layout.xml => song_item_download_layout.xml} (100%) diff --git a/app/src/main/java/ch/sdp/vibester/model/SongListAdapterForEndGame.kt b/app/src/main/java/ch/sdp/vibester/model/SongListAdapterForEndGame.kt index 6d0986ff3..3007f2835 100644 --- a/app/src/main/java/ch/sdp/vibester/model/SongListAdapterForEndGame.kt +++ b/app/src/main/java/ch/sdp/vibester/model/SongListAdapterForEndGame.kt @@ -30,7 +30,7 @@ class SongListAdapterForEndGame constructor( */ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SongListViewHolder { return SongListViewHolder( - AdapterHelper().createViewForViewHolder(parent, R.layout.song_item_layout) + AdapterHelper().createViewForViewHolder(parent, R.layout.song_item_download_layout) ) } diff --git a/app/src/main/res/layout/song_item_layout.xml b/app/src/main/res/layout/song_item_download_layout.xml similarity index 100% rename from app/src/main/res/layout/song_item_layout.xml rename to app/src/main/res/layout/song_item_download_layout.xml From 761ad71e62cc62683e35d8c0dd5a35ab255c81bb Mon Sep 17 00:00:00 2001 From: jiabaow Date: Sat, 28 May 2022 09:41:05 +0200 Subject: [PATCH 06/37] create song_item_delete_layout.xml --- .../model/SongListAdapterForEndGame.kt | 2 +- .../res/layout/song_item_delete_layout.xml | 38 +++++++++++++++++++ .../res/layout/song_item_download_layout.xml | 8 ++-- 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/layout/song_item_delete_layout.xml diff --git a/app/src/main/java/ch/sdp/vibester/model/SongListAdapterForEndGame.kt b/app/src/main/java/ch/sdp/vibester/model/SongListAdapterForEndGame.kt index 3007f2835..dbdb042f3 100644 --- a/app/src/main/java/ch/sdp/vibester/model/SongListAdapterForEndGame.kt +++ b/app/src/main/java/ch/sdp/vibester/model/SongListAdapterForEndGame.kt @@ -51,7 +51,7 @@ class SongListAdapterForEndGame constructor( View.OnClickListener { fun bind(songName: String) { - itemView.findViewById(R.id.song_name).text = songName + itemView.findViewById(R.id.download_song_name).text = songName val downloadSongBtn = itemView.findViewById