Skip to content

Commit

Permalink
Layout GuessMove / Depth is a String (Book) / Quit GuessMove
Browse files Browse the repository at this point in the history
  • Loading branch information
oers committed Nov 19, 2024
1 parent d5bd35a commit f39d57b
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 55 deletions.
8 changes: 4 additions & 4 deletions project/src/main/java/com/shurik/droidzebra/GameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class GameState {
private int lastMove;
private int nextMove;

private int reachedDepth;
private String reachedDepth = "0";
private ByteBoard byteBoard;
private GameStateListener handler = new GameStateListener() {
};
Expand Down Expand Up @@ -133,8 +133,8 @@ void setOpening(String opening) {
handler.onBoard(this);
}

void setReachedDepth(int reachedDepth) {
if(reachedDepth != this.reachedDepth) {
void setReachedDepth(String reachedDepth) {
if(!Objects.equals(reachedDepth, this.reachedDepth)) {
this.reachedDepth = reachedDepth;
handler.onBoard(this);
}
Expand All @@ -144,7 +144,7 @@ public String getOpening() {
return opening;
}

public int getReachedDepth() {
public String getReachedDepth() {
return reachedDepth;
}

Expand Down
4 changes: 1 addition & 3 deletions project/src/main/java/com/shurik/droidzebra/ZebraEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,7 @@ private JSONObject Callback(int msgcode, JSONObject data) {
String reachedDepth = split[1];
ZebraEngine.this.onDebugListener.onDebug("Depth: " + reachedDepth);
try {

int newDepth = Integer.parseInt(reachedDepth);
currentGameState.setReachedDepth(newDepth);
currentGameState.setReachedDepth(reachedDepth);
} catch (NumberFormatException e) {
Log.e("Status", e.toString(), e);
}
Expand Down
89 changes: 47 additions & 42 deletions project/src/main/java/de/earthlingz/oerszebra/DroidZebra.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,51 +298,56 @@ public void onDebug(String message) {

Log.i("Intent", type + " " + action);
engine.setOnErrorListener(this); //TODO don't forget to remove later to avoid memory leak



engine.onReady(() -> {
setContentView(R.layout.board_layout);
showActionBar();
getState().reset();
mBoardView = findViewById(R.id.board);
mBoardView.setBoardViewModel(getState());
mBoardView.setOnMakeMoveListener(this);
mBoardView.requestFocus();

//https://developer.android.com/develop/ui/views/layout/edge-to-edge?hl=de#java
ViewCompat.setOnApplyWindowInsetsListener(mBoardView, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
// Apply the insets as a margin to the view. This solution sets only the
// bottom, left, and right dimensions, but you can apply whichever insets are
// appropriate to your layout. You can also update the view padding if that's
// more appropriate.
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
mlp.topMargin = insets.top;
mlp.leftMargin = insets.left;
mlp.bottomMargin = insets.bottom;
mlp.rightMargin = insets.right;
v.setLayoutParams(mlp);

// Return CONSUMED if you don't want want the window insets to keep passing
// down to descendant views.
return WindowInsetsCompat.CONSUMED;
if(engine.getState() != ZebraEngine.ENGINE_STATE.ES_INITIAL) {
onReady(savedInstanceState, action, type, intent);
} else {
engine.onReady(() -> {
onReady(savedInstanceState, action, type, intent);
});
}
}

resetStatusView();
private void onReady(Bundle savedInstanceState, String action, String type, Intent intent) {
setContentView(R.layout.board_layout);
showActionBar();
getState().reset();
mBoardView = findViewById(R.id.board);
mBoardView.setBoardViewModel(getState());
mBoardView.setOnMakeMoveListener(this);
mBoardView.requestFocus();

//https://developer.android.com/develop/ui/views/layout/edge-to-edge?hl=de#java
ViewCompat.setOnApplyWindowInsetsListener(mBoardView, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
// Apply the insets as a margin to the view. This solution sets only the
// bottom, left, and right dimensions, but you can apply whichever insets are
// appropriate to your layout. You can also update the view padding if that's
// more appropriate.
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
mlp.topMargin = insets.top;
mlp.leftMargin = insets.left;
mlp.bottomMargin = insets.bottom;
mlp.rightMargin = insets.right;
v.setLayoutParams(mlp);

// Return CONSUMED if you don't want want the window insets to keep passing
// down to descendant views.
return WindowInsetsCompat.CONSUMED;
});

if (Intent.ACTION_SEND.equals(action) && type != null) {
handleIntent(intent);
} else if (savedInstanceState != null
&& savedInstanceState.containsKey("moves_played_count")
&& savedInstanceState.getInt("moves_played_count") > 0) {
startNewGameAndResetUI(savedInstanceState.getInt("moves_played_count"), savedInstanceState.getByteArray("moves_played"));
} else {
startNewGameAndResetUI();
}
resetStatusView();

mIsInitCompleted = true;
});
if (Intent.ACTION_SEND.equals(action) && type != null) {
handleIntent(intent);
} else if (savedInstanceState != null
&& savedInstanceState.containsKey("moves_played_count")
&& savedInstanceState.getInt("moves_played_count") > 0) {
startNewGameAndResetUI(savedInstanceState.getInt("moves_played_count"), savedInstanceState.getByteArray("moves_played"));
} else {
startNewGameAndResetUI();
}

mIsInitCompleted = true;
}

private void startNewGameAndResetUI(LinkedList<Move> moves) {
Expand Down Expand Up @@ -426,7 +431,7 @@ private void setStatus() {
if(viewById != null) {
int depth = settingsProvider.getSettingZebraDepth();
int depthExact = settingsProvider.getSettingZebraDepthExact();
int reachedDepth = 0;
String reachedDepth = "0";
int moveNumber = 1;
if(gameState != null) {
reachedDepth = gameState.getReachedDepth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import android.graphics.Color;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.innovattic.rangeseekbar.RangeSeekBar;
import com.shurik.droidzebra.EngineConfig;
import com.shurik.droidzebra.InvalidMove;
Expand Down Expand Up @@ -46,6 +51,26 @@ protected void onCreate(Bundle savedInstanceState) {
boardView = findViewById(R.id.guess_move_board);
boardViewModel = manager;
boardView.setBoardViewModel(boardViewModel);

//https://developer.android.com/develop/ui/views/layout/edge-to-edge?hl=de#java
ViewCompat.setOnApplyWindowInsetsListener(boardView, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
// Apply the insets as a margin to the view. This solution sets only the
// bottom, left, and right dimensions, but you can apply whichever insets are
// appropriate to your layout. You can also update the view padding if that's
// more appropriate.
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
mlp.topMargin = insets.top;
mlp.leftMargin = insets.left;
mlp.bottomMargin = insets.bottom;
mlp.rightMargin = insets.right;
v.setLayoutParams(mlp);

// Return CONSUMED if you don't want want the window insets to keep passing
// down to descendant views.
return WindowInsetsCompat.CONSUMED;
});

boardView.requestFocus();
sideToMoveCircle = findViewById(R.id.side_to_move_circle);
hintText = findViewById(R.id.guess_move_text);
Expand Down
2 changes: 1 addition & 1 deletion project/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<string name="dialog_pass_text">Du musst aussetzen</string>
<string name="dialog_quit_button_cancel">Abbrechen</string>
<string name="dialog_quit_title">Bist du sicher?</string>
<string name="display_depth">Move %4$d%nState: %5$s (%3$d)%nMid: %1$d Exact: %2$d</string>
<string name="display_depth">Move %4$d%nState: %5$s (%3$s)%nMid: %1$d Exact: %2$d</string>
<string name="gameover_choices_cancel">Brett anzeigen</string>
<string name="gameover_choices_email">Senden/Teilen</string>
<string name="gameover_choices_new_game">Neues Spiel</string>
Expand Down
2 changes: 1 addition & 1 deletion project/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<string name="dialog_ok">OK</string>
<string name="menu_item_mail">Envoyer/Partager</string>
<string name="spash_layout_message_2">(ceci peut prendre du temps)</string>
<string name="display_depth">Move %4$d%nState: %5$s (%3$d)%nMid: %1$d Exact: %2$d</string>
<string name="display_depth">Move %4$d%nState: %5$s (%3$s)%nMid: %1$d Exact: %2$d</string>
<string name="settings_title">Paramètres</string>
<string name="mail_generated">Généré par Reversatile (https://play.google.com/store/apps/details?id=de.earthlingz.oerszebra)</string>
<string name="mail_date">Date:</string>
Expand Down
2 changes: 1 addition & 1 deletion project/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<string name="dialog_ok">OK</string>
<string name="menu_item_mail">送信/共有</string>
<string name="spash_layout_message_2">(しばらくお待ちください)</string>
<string name="display_depth">Move %4$d%nState: %5$s (%3$d)%nMid: %1$d Exact: %2$d</string>
<string name="display_depth">Move %4$d%nState: %5$s (%3$s)%nMid: %1$d Exact: %2$d</string>
<string name="settings_title">設定</string>
<string name="mail_generated">作成:DroidZebra (https://play.google.com/store/apps/details?id=de.earthlingz.oerszebra)</string>
<string name="mail_date">日付:</string>
Expand Down
2 changes: 1 addition & 1 deletion project/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<string name="dialog_ok">네</string>
<string name="menu_item_mail">보내기/공유</string>
<string name="spash_layout_message_2">잠시만 기다려주십시오</string>
<string name="display_depth">Move %4$d%nState: %5$s (%3$d)%nMid: %1$d Exact: %2$d</string>
<string name="display_depth">Move %4$d%nState: %5$s (%3$s)%nMid: %1$d Exact: %2$d</string>
<string name="settings_title">환경설정</string>
<string name="mail_generated">드로이드제브라에 의해 생성됨 (https://play.google.com/store/apps/details?id=de.earthlingz.oerszebra)</string>
<string name="mail_date">날짜:</string>
Expand Down
2 changes: 1 addition & 1 deletion project/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<string name="dialog_ok">OK</string>
<string name="menu_item_mail">Отправить</string>
<string name="spash_layout_message_2">(это займет немного времени)</string>
<string name="display_depth">Move %4$d%nState: %5$s (%3$d)%nMid: %1$d Exact: %2$d</string>
<string name="display_depth">Move %4$d%nState: %5$s (%3$s)%nMid: %1$d Exact: %2$d</string>
<string name="settings_title">Настройки</string>
<string name="mail_generated">Сгенерировано с помощью Reversatile (https://play.google.com/store/apps/details?id=de.earthlingz.oerszebra)</string>
<string name="mail_date">Дата:</string>
Expand Down
2 changes: 1 addition & 1 deletion project/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<string name="dialog_cancel">Cancel</string>
<string name="menu_item_mail">share/send</string>
<string name="spash_layout_message_2">(this may take a few moments)</string>
<string name="display_depth">Move %4$d%nState: %5$s (%3$d)%nMid: %1$d Exact: %2$d</string>
<string name="display_depth">Move %4$d%nState: %5$s (%3$s)%nMid: %1$d Exact: %2$d</string>
<string name="settings_title">Settings</string>
<string name="mail_generated">Generated by Reversatile
(https://play.google.com/store/apps/details?id=de.earthlingz.oerszebra)
Expand Down

0 comments on commit f39d57b

Please sign in to comment.