Merge branch 'Sudoku-v3.0' of https://github.com/SecUSo/privacy-friendly-sudoku into Sudoku-v3.0

This commit is contained in:
uykek 2020-05-27 22:11:38 +02:00
commit 2a90d403cb
4 changed files with 186 additions and 303 deletions

View file

@ -111,6 +111,17 @@ public class GameController implements IModelChangedListener, Parcelable {
newLevelManager.checkAndRestock(); 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() { public int getTime() {
return time; return time;
} }

View file

@ -55,7 +55,7 @@ import org.secuso.privacyfriendlysudoku.ui.view.SudokuSpecialButtonLayout;
import org.secuso.privacyfriendlysudoku.ui.view.WinDialog; import org.secuso.privacyfriendlysudoku.ui.view.WinDialog;
import org.secuso.privacyfriendlysudoku.ui.view.databinding.DialogFragmentShareBoardBinding; import org.secuso.privacyfriendlysudoku.ui.view.databinding.DialogFragmentShareBoardBinding;
import java.util.Date;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -158,23 +158,29 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
gameController.loadLevel(container); gameController.loadLevel(container);
} else { } else {
boolean isDailySudoku = false;
if (extras != null) { if (extras != null) {
gameType = GameType.valueOf(extras.getString("gameType", GameType.Default_9x9.name())); gameType = GameType.valueOf(extras.getString("gameType", GameType.Default_9x9.name()));
gameDifficulty = GameDifficulty.valueOf(extras.getString("gameDifficulty", GameDifficulty.Moderate.name())); gameDifficulty = GameDifficulty.valueOf(extras.getString("gameDifficulty", GameDifficulty.Moderate.name()));
isDailySudoku = extras.getBoolean("isDailySudoku", false);
loadLevel = extras.getBoolean("loadLevel", false); loadLevel = extras.getBoolean("loadLevel", false);
if (loadLevel) { if (loadLevel) {
loadLevelID = extras.getInt("loadLevelID"); loadLevelID = extras.getInt("loadLevelID");
} }
} }
if (isDailySudoku) {
gameController.loadNewDailySudokuLevel(gameDifficulty);
} else {
List<GameInfoContainer> loadableGames = GameStateManager.getLoadableGameList(); List<GameInfoContainer> loadableGames = GameStateManager.getLoadableGameList();
if (loadLevel && loadableGames.size() > loadLevelID) { if (loadLevel && loadableGames.size() > loadLevelID) {
// load level from GameStateManager // load level from GameStateManager
gameController.loadLevel(loadableGames.get(loadLevelID)); gameController.loadLevel(loadableGames.get(loadLevelID));
} else { } else {
// load a new level // load a new level
gameController.loadNewLevel(gameType, gameDifficulty); gameController.loadNewLevel(gameType, gameDifficulty);
}
} }
} }
} else { } else {

View file

@ -1,16 +1,44 @@
package org.secuso.privacyfriendlysudoku.ui.view; package org.secuso.privacyfriendlysudoku.ui.view;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; 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.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import org.secuso.privacyfriendlysudoku.controller.helper.GameInfoContainer; 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.util.List; import java.util.List;
public class DailySudokuActivity extends AppCompatActivity {
List<GameInfoContainer> loadableGameList; public class DailySudokuActivity<Database> extends AppCompatActivity {
List<DailySudoku> sudokuList;
SharedPreferences settings; 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 @Override
@ -22,11 +50,118 @@ public class DailySudokuActivity extends AppCompatActivity {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
List<DailySudoku> sudokus = dbHelper.getDailySudokus();
TextView tw = findViewById(R.id.first_diff_text);
tw.setText(String.valueOf(sudokus.size()));
androidx.appcompat.app.ActionBar actionBar = getSupportActionBar(); androidx.appcompat.app.ActionBar actionBar = getSupportActionBar();
actionBar.setTitle("Daily Sudoku"); actionBar.setTitle("Daily Sudoku");
actionBar.setDisplayHomeAsUpEnabled(true); 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);
//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);
}
private class SudokuListAdapter extends BaseAdapter {
private Context context;
private List<DailySudoku> sudokuList;
public SudokuListAdapter(Context context, List<DailySudoku> 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;
}
}
} }

View file

@ -52,7 +52,7 @@
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="4" android:layout_weight="10"
android:weightSum="5"> android:weightSum="5">
<LinearLayout <LinearLayout
@ -65,15 +65,15 @@
android:id="@+id/statistic_image" android:id="@+id/statistic_image"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_gravity="center|start|center_horizontal|left" android:layout_gravity="center_horizontal"
android:layout_weight="2.0" android:layout_weight="1.0"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:src="@drawable/icon_default_9x9" /> android:src="@drawable/icon_default_9x9" />
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" android:layout_height="match_parent"
android:layout_weight="3.0" android:layout_weight="2.5"
android:gravity="center_horizontal"> android:gravity="center_horizontal">
<RatingBar <RatingBar
@ -82,17 +82,25 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/first_diff_text" android:layout_below="@+id/first_diff_text"
android:layout_gravity="start|right|center_horizontal" android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="31dp"
android:numStars="4" android:numStars="4"
android:rating="2" /> android:rating="2" />
<TextView <TextView
android:id="@+id/first_diff_text" android:id="@+id/first_diff_text"
android:layout_width="42dp" android:layout_width="match_parent"
android:layout_height="30dp" android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_centerHorizontal="true"
android:gravity="bottom|center|center_horizontal" android:gravity="bottom|center|center_horizontal"
android:text="diffi" android:text="diffi"
android:textSize="22dp" /> android:textSize="32dp" />
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
@ -192,7 +200,6 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="0dp" android:layout_height="0dp"
@ -209,288 +216,11 @@
</LinearLayout> </LinearLayout>
<LinearLayout <ListView
android:layout_width="fill_parent" android:id="@+id/sudoku_list"
android:layout_height="0dp" android:layout_width="match_parent"
android:layout_weight="4" android:layout_height="wrap_content"
android:orientation="vertical" android:layout_weight="1" />
android:weightSum="4">
<!-- ### first row -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="3">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="0.7"
android:gravity="center_vertical">
<ImageView
android:id="@+id/statistic_image2"
android:layout_width="180dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:src="@drawable/icon_default_9x9" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical">
<RatingBar
android:id="@+id/first_diff_bar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/first_diff_text"
android:layout_centerHorizontal="false"
android:numStars="4" />
<TextView
android:id="@+id/first_diff_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="diffi" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="1dp"
android:layout_weight="1"
android:gravity="right|center_vertical">
<TextView
android:id="@+id/first_min_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/min_time" />
<TextView
android:id="@+id/first_min_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/first_min_text"
android:gravity="center_vertical"
android:text="0" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="3">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="0.7"
android:gravity="center_vertical">
<ImageView
android:id="@+id/statistic_image2"
android:layout_width="180dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:src="@drawable/icon_default_9x9" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical">
<RatingBar
android:id="@+id/first_diff_bar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/first_diff_text"
android:layout_gravity="center"
android:numStars="4" />
<TextView
android:id="@+id/first_diff_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="diffi" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="right|center_vertical">
<TextView
android:id="@+id/first_min_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/min_time" />
<TextView
android:id="@+id/first_min_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/first_min_text"
android:gravity="center_vertical"
android:text="0" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="3">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="0.7"
android:gravity="center_vertical">
<ImageView
android:id="@+id/statistic_image2"
android:layout_width="180dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:src="@drawable/icon_default_9x9" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical">
<RatingBar
android:id="@+id/first_diff_bar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/first_diff_text"
android:layout_gravity="center"
android:numStars="4" />
<TextView
android:id="@+id/first_diff_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="diffi" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="right|center_vertical">
<TextView
android:id="@+id/first_min_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/min_time" />
<TextView
android:id="@+id/first_min_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/first_min_text"
android:gravity="center_vertical"
android:text="0" />
</RelativeLayout>
</LinearLayout>
<!-- ### second row -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="3">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.7"
android:gravity="center_vertical">
<ImageView
android:id="@+id/statistic_image6"
android:layout_width="180dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_weight="0.7"
android:adjustViewBounds="true"
android:src="@drawable/icon_default_9x9" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical">
<RatingBar
android:id="@+id/second_diff_bar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/second_diff_text"
android:layout_gravity="center"
android:numStars="4" />
<TextView
android:id="@+id/second_diff_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="diffi" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="right|center_vertical">
<TextView
android:id="@+id/second_min_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/min_time" />
<TextView
android:id="@+id/second_min_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/second_min_text"
android:gravity="center_vertical"
android:text="0" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>
@ -505,6 +235,7 @@
android:layout_marginRight="30dp" android:layout_marginRight="30dp"
android:layout_marginBottom="290dp" android:layout_marginBottom="290dp"
android:clickable="true" android:clickable="true"
android:onClick="onClick"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_media_play" /> app:srcCompat="@android:drawable/ic_media_play" />