From b863c7a88cb96580ccc6fe47836ea235074655fe Mon Sep 17 00:00:00 2001 From: ErikWaegerle Date: Tue, 26 May 2020 16:43:18 +0200 Subject: [PATCH 1/5] Implementing/adding the functionality of the "Menu Button" and the "Back Button" in the ActionBar. --- .../ui/view/DailySudokuActivity.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) 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 96aeba9..aa86113 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,16 +1,22 @@ package org.secuso.privacyfriendlysudoku.ui.view; + import android.content.SharedPreferences; import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; +import org.secuso.privacyfriendlysudoku.controller.SaveLoadStatistics; import org.secuso.privacyfriendlysudoku.controller.helper.GameInfoContainer; +import org.secuso.privacyfriendlysudoku.ui.StatsActivity; import java.util.List; public class DailySudokuActivity extends AppCompatActivity { List loadableGameList; SharedPreferences settings; + private StatsActivity.SectionsPagerAdapter mSectionsPagerAdapter; @Override @@ -29,4 +35,32 @@ public class DailySudokuActivity extends AppCompatActivity { } + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_stats, menu); + //getMenuInflater().inflate(R.menu.menu_stats, menu); + return true; + //return false; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + + //noinspection SimplifiableIfStatement + switch(item.getItemId()) { + case R.id.action_reset: + SaveLoadStatistics.resetStats(this); + mSectionsPagerAdapter.refresh(this); + return true; + case android.R.id.home: + finish(); + return true; + } + + return super.onOptionsItemSelected(item); + } + } \ No newline at end of file From 9f999b5512b090dfd0b621a28154cd71f7cbd9a6 Mon Sep 17 00:00:00 2001 From: ErikWaegerle Date: Wed, 27 May 2020 20:04:08 +0200 Subject: [PATCH 2/5] Added the method loadNewDailySudokuLevel. Is responsible for loading the DailySudoku. --- .../controller/GameController.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GameController.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GameController.java index f2bb7f0..e58ddd3 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GameController.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GameController.java @@ -111,6 +111,17 @@ public class GameController implements IModelChangedListener, Parcelable { newLevelManager.checkAndRestock(); } + public void loadNewDailySudokuLevel(GameDifficulty gameDifficulty) { + NewLevelManager newLevelManager = NewLevelManager.getInstance(context, settings); + + int[] level = newLevelManager.loadDailySudoku(); + + loadLevel(new GameInfoContainer(DAILY_SUDOKU_ID, gameDifficulty, GameType.Default_9x9, level, null, null)); + + newLevelManager.checkAndRestock(); + + } + public int getTime() { return time; } From 1dc60679d38c6993bb6521de6ef33e4e48cd2ede Mon Sep 17 00:00:00 2001 From: ErikWaegerle Date: Wed, 27 May 2020 20:15:28 +0200 Subject: [PATCH 3/5] Modify the onCreate() method to ensure that only in case of the DailySudoku the DailySudoku is loaded --- .../ui/GameActivity.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java index 7481a83..441e2ae 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java @@ -55,7 +55,7 @@ import org.secuso.privacyfriendlysudoku.ui.view.SudokuSpecialButtonLayout; import org.secuso.privacyfriendlysudoku.ui.view.WinDialog; import org.secuso.privacyfriendlysudoku.ui.view.databinding.DialogFragmentShareBoardBinding; -import java.util.Date; + import java.util.LinkedList; import java.util.List; @@ -158,23 +158,29 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig gameController.loadLevel(container); } else { + boolean isDailySudoku = false; if (extras != null) { gameType = GameType.valueOf(extras.getString("gameType", GameType.Default_9x9.name())); gameDifficulty = GameDifficulty.valueOf(extras.getString("gameDifficulty", GameDifficulty.Moderate.name())); + isDailySudoku = extras.getBoolean("isDailySudoku", false); loadLevel = extras.getBoolean("loadLevel", false); if (loadLevel) { loadLevelID = extras.getInt("loadLevelID"); } } + if (isDailySudoku) { + gameController.loadNewDailySudokuLevel(gameDifficulty); + } else { - List loadableGames = GameStateManager.getLoadableGameList(); + List loadableGames = GameStateManager.getLoadableGameList(); - if (loadLevel && loadableGames.size() > loadLevelID) { - // load level from GameStateManager - gameController.loadLevel(loadableGames.get(loadLevelID)); - } else { - // load a new level - gameController.loadNewLevel(gameType, gameDifficulty); + if (loadLevel && loadableGames.size() > loadLevelID) { + // load level from GameStateManager + gameController.loadLevel(loadableGames.get(loadLevelID)); + } else { + // load a new level + gameController.loadNewLevel(gameType, gameDifficulty); + } } } } else { From 644358ced8d9b3aad66805cadcd1e17af9b3eaff Mon Sep 17 00:00:00 2001 From: ErikWaegerle Date: Wed, 27 May 2020 21:41:40 +0200 Subject: [PATCH 4/5] Adjustment of the layout by adding the TextView from list_entry_layout.xml Is responsible for displaying the games already completed in Daily Sudoku. --- .../main/res/layout/activity_daily_sudoku.xml | 315 ++---------------- 1 file changed, 23 insertions(+), 292 deletions(-) diff --git a/app/src/main/res/layout/activity_daily_sudoku.xml b/app/src/main/res/layout/activity_daily_sudoku.xml index 18bfd7d..308b70d 100644 --- a/app/src/main/res/layout/activity_daily_sudoku.xml +++ b/app/src/main/res/layout/activity_daily_sudoku.xml @@ -52,7 +52,7 @@ + android:textSize="32dp" /> @@ -192,7 +200,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -505,6 +235,7 @@ android:layout_marginRight="30dp" android:layout_marginBottom="290dp" android:clickable="true" + android:onClick="onClick" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:srcCompat="@android:drawable/ic_media_play" /> From f179518f5aa659c10dc7e7068f599131c60965e4 Mon Sep 17 00:00:00 2001 From: ErikWaegerle Date: Wed, 27 May 2020 21:58:32 +0200 Subject: [PATCH 5/5] Adding the onClick() method, the SudokuListAdapter() and the getView() method This adds functionality to the button and the customization/implementation to display the completed DailySudoku in list form. --- .../ui/view/DailySudokuActivity.java | 107 +++++++++++++++++- 1 file changed, 104 insertions(+), 3 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 aa86113..3cc73d9 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,22 +1,44 @@ package org.secuso.privacyfriendlysudoku.ui.view; +import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Handler; +import android.preference.PreferenceManager; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; +import android.view.View; +import android.widget.RatingBar; +import org.secuso.privacyfriendlysudoku.controller.database.DatabaseHelper; +import org.secuso.privacyfriendlysudoku.controller.database.model.DailySudoku; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import org.secuso.privacyfriendlysudoku.controller.SaveLoadStatistics; -import org.secuso.privacyfriendlysudoku.controller.helper.GameInfoContainer; +import org.secuso.privacyfriendlysudoku.game.GameDifficulty; +import org.secuso.privacyfriendlysudoku.ui.GameActivity; import org.secuso.privacyfriendlysudoku.ui.StatsActivity; import java.util.List; -public class DailySudokuActivity extends AppCompatActivity { - List loadableGameList; +public class DailySudokuActivity extends AppCompatActivity { + + List sudokuList; SharedPreferences settings; + private final DatabaseHelper dbHelper = new DatabaseHelper(this); + RatingBar difficultyBar; + static final int MAIN_CONTENT_FADEOUT_DURATION = 150; + static final int MAIN_CONTENT_FADEIN_DURATION = 250; + private Handler mHandler; private StatsActivity.SectionsPagerAdapter mSectionsPagerAdapter; + private SudokuListAdapter sudokuListAdapter; @Override @@ -28,13 +50,39 @@ 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())); + androidx.appcompat.app.ActionBar actionBar = getSupportActionBar(); actionBar.setTitle("Daily Sudoku"); actionBar.setDisplayHomeAsUpEnabled(true); + 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); + listView.setAdapter(sudokuListAdapter); } + + public void onClick(View view) { + + int index = difficultyBar.getProgress()-1; + GameDifficulty gameDifficulty = GameDifficulty.getValidDifficultyList().get(index < 0 ? 0 : index); + //send everything to game activity + final Intent intent = new Intent(this,GameActivity.class); + intent.putExtra("gameDifficulty", gameDifficulty.name()); + intent.putExtra("isDailySudoku", true); + + startActivity(intent); + + } + public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_stats, menu); @@ -63,4 +111,57 @@ public class DailySudokuActivity extends AppCompatActivity { return super.onOptionsItemSelected(item); } + private class SudokuListAdapter extends BaseAdapter { + + private Context context; + private List sudokuList; + + public SudokuListAdapter(Context context, List sudokuList) { + this.context = context; + this.sudokuList = sudokuList; + } + + @Override + public int getCount() { + return sudokuList.size(); + } + + @Override + public Object getItem(int position) { + return sudokuList.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + DailySudoku sudoku = sudokuList.get(position); + + if (convertView == null) { + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + convertView = (View) inflater.inflate(R.layout.list_entry_layout, null); + } + + TextView gameType = (TextView)convertView.findViewById(R.id.loadgame_listentry_gametype); + TextView difficulty =(TextView)convertView.findViewById(R.id.loadgame_listentry_difficultytext); + RatingBar difficultyBar =(RatingBar)convertView.findViewById(R.id.loadgame_listentry_difficultybar); + TextView playedTime = (TextView)convertView.findViewById(R.id.loadgame_listentry_timeplayed); + TextView lastTimePlayed = (TextView)convertView.findViewById(R.id.loadgame_listentry_lasttimeplayed); + ImageView image = (ImageView)convertView.findViewById(R.id.loadgame_listentry_gametypeimage); + + + image.setImageResource(R.drawable.icon_default_9x9); + + gameType.setText(sudoku.getGameType().getStringResID()); + difficulty.setText(sudoku.getDifficulty().getStringResID()); + difficultyBar.setNumStars(GameDifficulty.getValidDifficultyList().size()); + difficultyBar.setMax(GameDifficulty.getValidDifficultyList().size()); + difficultyBar.setRating(GameDifficulty.getValidDifficultyList().indexOf(sudoku.getDifficulty())+1); + + return convertView; + } + } } \ No newline at end of file