mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-04-24 21:05:39 +02:00
Use binding in LoadFEN and EditPGN
This commit is contained in:
parent
0324409feb
commit
31d8ebab0e
DroidFishApp/src/main
java/org/petero/droidfish/activities
res
@ -18,27 +18,12 @@
|
||||
|
||||
package org.petero.droidfish.activities;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.petero.droidfish.ColorTheme;
|
||||
import org.petero.droidfish.DroidFishApp;
|
||||
import org.petero.droidfish.ObjectCache;
|
||||
import org.petero.droidfish.R;
|
||||
import org.petero.droidfish.Util;
|
||||
import org.petero.droidfish.activities.PGNFile.GameInfo;
|
||||
import org.petero.droidfish.activities.PGNFile.GameInfoResult;
|
||||
import org.petero.droidfish.gamelogic.Pair;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.ListActivity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
@ -49,14 +34,26 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import org.petero.droidfish.ColorTheme;
|
||||
import org.petero.droidfish.DroidFishApp;
|
||||
import org.petero.droidfish.ObjectCache;
|
||||
import org.petero.droidfish.R;
|
||||
import org.petero.droidfish.Util;
|
||||
import org.petero.droidfish.activities.PGNFile.GameInfo;
|
||||
import org.petero.droidfish.activities.PGNFile.GameInfoResult;
|
||||
import org.petero.droidfish.databinding.SelectGameBinding;
|
||||
import org.petero.droidfish.gamelogic.Pair;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
public abstract class EditPGN extends ListActivity {
|
||||
static ArrayList<GameInfo> gamesInFile = new ArrayList<>();
|
||||
@ -65,8 +62,6 @@ public abstract class EditPGN extends ListActivity {
|
||||
ProgressDialog progress;
|
||||
private GameInfo selectedGi = null;
|
||||
ArrayAdapter<GameInfo> aa = null;
|
||||
TextView hintText = null;
|
||||
EditText filterText = null;
|
||||
|
||||
SharedPreferences settings;
|
||||
int defaultItem = 0;
|
||||
@ -80,6 +75,8 @@ public abstract class EditPGN extends ListActivity {
|
||||
boolean loadGame; // True when loading game, false when saving
|
||||
String pgnToSave;
|
||||
|
||||
private SelectGameBinding binding;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -237,7 +234,7 @@ public abstract class EditPGN extends ListActivity {
|
||||
private void showList() {
|
||||
progress = null;
|
||||
removeDialog(PROGRESS_DIALOG);
|
||||
setContentView(R.layout.select_game);
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.select_game);
|
||||
Util.overrideViewAttribs(findViewById(android.R.id.content));
|
||||
aa = new ArrayAdapter<GameInfo>(this, R.layout.select_game_list_item, gamesInFile) {
|
||||
@Override
|
||||
@ -272,24 +269,26 @@ public abstract class EditPGN extends ListActivity {
|
||||
return true;
|
||||
});
|
||||
|
||||
filterText = findViewById(R.id.select_game_filter);
|
||||
filterText.addTextChangedListener(new TextWatcher() {
|
||||
binding.selectGameFilter.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) { }
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
aa.getFilter().filter(s);
|
||||
lastSearchString = s.toString();
|
||||
}
|
||||
});
|
||||
filterText.setText(lastSearchString);
|
||||
hintText = findViewById(R.id.select_game_hint);
|
||||
binding.selectGameFilter.setText(lastSearchString);
|
||||
if (loadGame) {
|
||||
hintText.setVisibility(View.GONE);
|
||||
binding.selectGameHint.setVisibility(View.GONE);
|
||||
} else {
|
||||
hintText.setText(R.string.save_game_hint);
|
||||
binding.selectGameHint.setText(R.string.save_game_hint);
|
||||
}
|
||||
lv.requestFocus();
|
||||
}
|
||||
@ -304,7 +303,9 @@ public abstract class EditPGN extends ListActivity {
|
||||
final static int SAVE_GAME_DIALOG = 2;
|
||||
final static int DELETE_PGN_FILE_DIALOG = 3;
|
||||
|
||||
/** Remove and show a dialog. */
|
||||
/**
|
||||
* Remove and show a dialog.
|
||||
*/
|
||||
private void reShowDialog(int id) {
|
||||
removeDialog(id);
|
||||
showDialog(id);
|
||||
@ -355,11 +356,18 @@ public abstract class EditPGN extends ListActivity {
|
||||
builder.setItems(items, (dialog, item) -> {
|
||||
GameInfo giToReplace;
|
||||
switch (item) {
|
||||
case 0: giToReplace = new GameInfo().setNull(gi.startPos); break;
|
||||
case 1: giToReplace = new GameInfo().setNull(gi.endPos); break;
|
||||
case 2: giToReplace = gi; break;
|
||||
case 0:
|
||||
giToReplace = new GameInfo().setNull(gi.startPos);
|
||||
break;
|
||||
case 1:
|
||||
giToReplace = new GameInfo().setNull(gi.endPos);
|
||||
break;
|
||||
case 2:
|
||||
giToReplace = gi;
|
||||
break;
|
||||
default:
|
||||
finish(); return;
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
pgnFile.replacePGN(pgnToSave, giToReplace);
|
||||
finish();
|
||||
@ -434,7 +442,7 @@ public abstract class EditPGN extends ListActivity {
|
||||
int pos = lv.pointToPosition(0, 0);
|
||||
aa = new ArrayAdapter<>(this, R.layout.select_game_list_item, gamesInFile);
|
||||
setListAdapter(aa);
|
||||
String s = filterText.getText().toString();
|
||||
String s = binding.selectGameFilter.getText().toString();
|
||||
aa.getFilter().filter(s);
|
||||
lv.setSelection(pos);
|
||||
// Update lastModTime, since current change has already been handled
|
||||
|
@ -18,22 +18,6 @@
|
||||
|
||||
package org.petero.droidfish.activities;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import org.petero.droidfish.ChessBoardPlay;
|
||||
import org.petero.droidfish.ColorTheme;
|
||||
import org.petero.droidfish.DroidFishApp;
|
||||
import org.petero.droidfish.R;
|
||||
import org.petero.droidfish.Util;
|
||||
import org.petero.droidfish.activities.FENFile.FenInfo;
|
||||
import org.petero.droidfish.activities.FENFile.FenInfoResult;
|
||||
import org.petero.droidfish.gamelogic.ChessParseError;
|
||||
import org.petero.droidfish.gamelogic.Pair;
|
||||
import org.petero.droidfish.gamelogic.Position;
|
||||
import org.petero.droidfish.gamelogic.TextIO;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
@ -48,16 +32,30 @@ import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import org.petero.droidfish.ColorTheme;
|
||||
import org.petero.droidfish.DroidFishApp;
|
||||
import org.petero.droidfish.R;
|
||||
import org.petero.droidfish.Util;
|
||||
import org.petero.droidfish.activities.FENFile.FenInfo;
|
||||
import org.petero.droidfish.activities.FENFile.FenInfoResult;
|
||||
import org.petero.droidfish.databinding.LoadFenBinding;
|
||||
import org.petero.droidfish.gamelogic.ChessParseError;
|
||||
import org.petero.droidfish.gamelogic.Pair;
|
||||
import org.petero.droidfish.gamelogic.Position;
|
||||
import org.petero.droidfish.gamelogic.TextIO;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class LoadFEN extends ListActivity {
|
||||
private static ArrayList<FenInfo> fensInFile = new ArrayList<>();
|
||||
@ -76,8 +74,7 @@ public class LoadFEN extends ListActivity {
|
||||
private CountDownLatch progressLatch = null;
|
||||
private boolean canceled = false;
|
||||
|
||||
private ChessBoardPlay cb;
|
||||
private Button okButton;
|
||||
LoadFenBinding binding;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -192,17 +189,13 @@ public class LoadFEN extends ListActivity {
|
||||
progress = null;
|
||||
removeProgressDialog();
|
||||
setContentView(R.layout.load_fen);
|
||||
|
||||
cb = findViewById(R.id.loadfen_chessboard);
|
||||
okButton = findViewById(R.id.loadfen_ok);
|
||||
Button cancelButton = findViewById(R.id.loadfen_cancel);
|
||||
|
||||
okButton.setEnabled(false);
|
||||
okButton.setOnClickListener(v -> {
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.load_fen);
|
||||
binding.loadfenOk.setEnabled(false);
|
||||
binding.loadfenOk.setOnClickListener(v -> {
|
||||
if (selectedFi != null)
|
||||
sendBackResult(selectedFi, false);
|
||||
});
|
||||
cancelButton.setOnClickListener(v -> {
|
||||
binding.loadfenCancel.setOnClickListener(v -> {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
});
|
||||
@ -235,8 +228,8 @@ public class LoadFEN extends ListActivity {
|
||||
chessPos = e2.pos;
|
||||
}
|
||||
if (chessPos != null) {
|
||||
cb.setPosition(chessPos);
|
||||
okButton.setEnabled(true);
|
||||
binding.loadfenChessboard.setPosition(chessPos);
|
||||
binding.loadfenOk.setEnabled(true);
|
||||
}
|
||||
});
|
||||
lv.setOnItemLongClickListener((parent, view, pos, id) -> {
|
||||
@ -260,11 +253,11 @@ public class LoadFEN extends ListActivity {
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
if (cb != null) {
|
||||
Position pos = cb.pos;
|
||||
if (binding.loadfenChessboard != null) {
|
||||
Position pos = binding.loadfenChessboard.pos;
|
||||
showList();
|
||||
cb.setPosition(pos);
|
||||
okButton.setEnabled(selectedFi != null);
|
||||
binding.loadfenChessboard.setPosition(pos);
|
||||
binding.loadfenOk.setEnabled(selectedFi != null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -279,6 +272,7 @@ public class LoadFEN extends ListActivity {
|
||||
a.progressLatch.countDown();
|
||||
return progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
super.onCancel(dialog);
|
||||
|
@ -17,6 +17,7 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
|
||||
</ScrollView>
|
||||
|
||||
<LinearLayout
|
||||
@ -44,6 +45,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@android:string/ok" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -1,54 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:focusable="false">
|
||||
</ListView>
|
||||
android:layout_weight="1"
|
||||
android:focusable="false" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_weight="2"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false">
|
||||
android:layout_weight="2"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<view
|
||||
class="org.petero.droidfish.ChessBoardPlay"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<org.petero.droidfish.ChessBoardPlay
|
||||
android:id="@+id/loadfen_chessboard"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
</view>
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/loadfen_cancel"
|
||||
android:text="@string/cancel"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
</Button>
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/cancel" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/loadfen_ok"
|
||||
android:text="@android:string/ok"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
</Button>
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="@android:string/ok" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</layout>
|
||||
|
@ -1,49 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false">
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<view
|
||||
class="org.petero.droidfish.ChessBoardPlay"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<org.petero.droidfish.ChessBoardPlay
|
||||
android:id="@+id/loadfen_chessboard"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
</view>
|
||||
android:layout_height="fill_parent" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/loadfen_cancel"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/cancel">
|
||||
</Button>
|
||||
android:text="@string/cancel" />
|
||||
|
||||
<Button
|
||||
android:text="@android:string/ok"
|
||||
android:id="@+id/loadfen_ok"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
</Button>
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@android:string/ok" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:focusable="false">
|
||||
</ListView>
|
||||
android:focusable="false" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</layout>
|
||||
|
@ -1,28 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/select_game_hint"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:includeFontPadding="true">
|
||||
</TextView>
|
||||
android:includeFontPadding="true" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/select_game_filter"
|
||||
android:hint="@string/filter_text"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:layout_margin="10dp"
|
||||
android:hint="@string/filter_text"
|
||||
android:inputType="text"
|
||||
android:layout_margin="10dp">
|
||||
</EditText>
|
||||
android:maxLines="1" />
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:focusable="false">
|
||||
</ListView>
|
||||
android:focusable="false" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</layout>
|
||||
|
@ -37,6 +37,7 @@
|
||||
android:gravity="center"
|
||||
android:text="Default Description"
|
||||
android:textColor="@color/White" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user