From 236be00504a2c63950f3904298a544852d9e2745 Mon Sep 17 00:00:00 2001 From: ErikWaegerle Date: Sun, 31 May 2020 18:15:32 +0200 Subject: [PATCH] Modification of the onCreate() method 1.) Display and output of the cumulated number of required hints 2.) Display and output of the game time from the DailySudokus 3.) Display and output of the cumulated total playing time of DailySudokus --- .../ui/view/DailySudokuActivity.java | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/DailySudokuActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/DailySudokuActivity.java index 6534d59..ecda78e 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/DailySudokuActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/DailySudokuActivity.java @@ -1,6 +1,5 @@ package org.secuso.privacyfriendlysudoku.ui.view; - import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -18,7 +17,6 @@ import android.widget.TextView; import android.view.View; import android.widget.RatingBar; import android.widget.Toast; - import org.secuso.privacyfriendlysudoku.controller.GameController; import org.secuso.privacyfriendlysudoku.controller.database.DatabaseHelper; import org.secuso.privacyfriendlysudoku.controller.database.model.DailySudoku; @@ -28,7 +26,7 @@ import org.secuso.privacyfriendlysudoku.controller.SaveLoadStatistics; import org.secuso.privacyfriendlysudoku.game.GameDifficulty; import org.secuso.privacyfriendlysudoku.ui.GameActivity; import org.secuso.privacyfriendlysudoku.ui.StatsActivity; - +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.List; @@ -55,9 +53,35 @@ public class DailySudokuActivity extends AppCompatActivity { setSupportActionBar(toolbar); - List sudokus = dbHelper.getDailySudokus(); - TextView tw = findViewById(R.id.first_diff_text); - tw.setText(String.valueOf(sudokus.size())); + //TODO: rename tw/tx/ty + sudokuList = dbHelper.getDailySudokus(); + TextView tw = findViewById(R.id.numb_of_total_games); + TextView tx = findViewById(R.id.numb_of_hints); + TextView ty = findViewById(R.id.numb_of_total_time); + tw.setText(String.valueOf(sudokuList.size())); + + + int sumHints = 0; + int sumTime = 0; + + + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss"); + + for (DailySudoku sudoku : sudokuList){ + sumHints += sudoku.getHintsUsed(); + //sumTime += sudoku.getTimeNeededInSeconds(); + + String[] split = sudoku.getTimeNeeded().split(":"); + sumTime += Integer.valueOf(split[0])*3600 + Integer.valueOf(split[1])*60 + Integer.valueOf(split[2]); + } + + int hours = sumTime / 3600; + int minutes = ( sumTime / 60 ) % 60; + int seconds = sumTime % 60; + String str = String.format("%02d:%02d:%02d", hours, minutes, seconds); + + tx.setText(String.valueOf(sumHints)); + ty.setText(str); androidx.appcompat.app.ActionBar actionBar = getSupportActionBar(); actionBar.setTitle("Daily Sudoku"); @@ -66,8 +90,7 @@ public class DailySudokuActivity extends AppCompatActivity { difficultyBar = findViewById(R.id.first_diff_bar); settings = PreferenceManager.getDefaultSharedPreferences(this); mHandler = new Handler(); - - sudokuList = dbHelper.getDailySudokus(); + ListView listView = (ListView)findViewById(R.id.sudoku_list); sudokuListAdapter = new DailySudokuActivity.SudokuListAdapter(this, sudokuList); @@ -183,7 +206,8 @@ public class DailySudokuActivity extends AppCompatActivity { difficultyBar.setNumStars(GameDifficulty.getValidDifficultyList().size()); difficultyBar.setMax(GameDifficulty.getValidDifficultyList().size()); difficultyBar.setRating(GameDifficulty.getValidDifficultyList().indexOf(sudoku.getDifficulty())+1); - + //lastTimePlayed.setText(sudoku.getTimeNeeded()); + playedTime.setText(sudoku.getTimeNeeded()); return convertView; } }