You can now delete entries in the continue game screen by long clicking them.
This commit is contained in:
parent
e2ecfe9292
commit
d2bed7b2a5
4 changed files with 99 additions and 6 deletions
|
@ -117,7 +117,7 @@ public class SaveLoadGameStateController {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteGameStateFile(GameInfoContainer gic) {
|
public void deleteGameStateFile(GameInfoContainer gic) {
|
||||||
File dir = context.getDir(SAVES_DIR, 0);
|
File dir = context.getDir(SAVES_DIR, 0);
|
||||||
|
|
||||||
File file = new File(dir, SAVE_PREFIX+gic.getID()+FILE_EXTENSION);
|
File file = new File(dir, SAVE_PREFIX+gic.getID()+FILE_EXTENSION);
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package tu_darmstadt.sudoku.ui;
|
||||||
|
|
||||||
|
import android.app.DialogFragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Chris on 24.11.2015.
|
||||||
|
*/
|
||||||
|
public interface IDeleteDialogFragmentListener {
|
||||||
|
public void onDialogPositiveClick(int position);
|
||||||
|
public void onDialogNegativeClick(int position);
|
||||||
|
}
|
|
@ -1,6 +1,12 @@
|
||||||
package tu_darmstadt.sudoku.ui;
|
package tu_darmstadt.sudoku.ui;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.app.DialogFragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
@ -10,6 +16,7 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
@ -17,9 +24,8 @@ import android.widget.RatingBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.FieldPosition;
|
|
||||||
import java.text.ParsePosition;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
@ -28,10 +34,11 @@ import tu_darmstadt.sudoku.controller.helper.GameInfoContainer;
|
||||||
import tu_darmstadt.sudoku.game.GameDifficulty;
|
import tu_darmstadt.sudoku.game.GameDifficulty;
|
||||||
import tu_darmstadt.sudoku.ui.view.R;
|
import tu_darmstadt.sudoku.ui.view.R;
|
||||||
|
|
||||||
public class LoadGameActivity extends AppCompatActivity {
|
public class LoadGameActivity extends AppCompatActivity implements IDeleteDialogFragmentListener {
|
||||||
|
|
||||||
List<GameInfoContainer> loadableGameList;
|
List<GameInfoContainer> loadableGameList;
|
||||||
SharedPreferences settings;
|
SharedPreferences settings;
|
||||||
|
LoadGameAdapter loadGameAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -41,6 +48,11 @@ public class LoadGameActivity extends AppCompatActivity {
|
||||||
|
|
||||||
settings = PreferenceManager.getDefaultSharedPreferences(this);
|
settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
|
||||||
SaveLoadGameStateController saveLoadGameStateController = new SaveLoadGameStateController(this, settings);
|
SaveLoadGameStateController saveLoadGameStateController = new SaveLoadGameStateController(this, settings);
|
||||||
loadableGameList = saveLoadGameStateController.loadGameStateInfo();
|
loadableGameList = saveLoadGameStateController.loadGameStateInfo();
|
||||||
|
|
||||||
|
@ -58,17 +70,77 @@ public class LoadGameActivity extends AppCompatActivity {
|
||||||
AdapterView.OnItemLongClickListener longClickListener = new AdapterView.OnItemLongClickListener() {
|
AdapterView.OnItemLongClickListener longClickListener = new AdapterView.OnItemLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
return false;
|
DeleteDialogFragment deleteDialog = new DeleteDialogFragment();
|
||||||
|
deleteDialog.setPosition(position);
|
||||||
|
deleteDialog.show(getFragmentManager(), "DeleteDialogFragment");
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ListView listView = (ListView)findViewById(R.id.load_game_list);
|
ListView listView = (ListView)findViewById(R.id.load_game_list);
|
||||||
listView.setAdapter(new LoadGameAdapter(this, loadableGameList));
|
loadGameAdapter = new LoadGameAdapter(this, loadableGameList);
|
||||||
|
listView.setAdapter(loadGameAdapter);
|
||||||
listView.setOnItemClickListener(clickListener);
|
listView.setOnItemClickListener(clickListener);
|
||||||
listView.setOnItemLongClickListener(longClickListener);
|
listView.setOnItemLongClickListener(longClickListener);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDialogPositiveClick(int position) {
|
||||||
|
SaveLoadGameStateController saveLoadGameStateController = new SaveLoadGameStateController(getApplicationContext(), settings);
|
||||||
|
saveLoadGameStateController.deleteGameStateFile(loadableGameList.get(position));
|
||||||
|
loadGameAdapter.delete(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDialogNegativeClick(int position) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ValidFragment")
|
||||||
|
public class DeleteDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
|
private int position = 0;
|
||||||
|
|
||||||
|
public void setPosition(int position) {
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
public int getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinkedList<IDeleteDialogFragmentListener> listeners = new LinkedList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Activity activity) {
|
||||||
|
super.onAttach(activity);
|
||||||
|
// Verify that the host activity implements the callback interface
|
||||||
|
if(activity instanceof IDeleteDialogFragmentListener) {
|
||||||
|
listeners.add((IDeleteDialogFragmentListener) activity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
// Use the Builder class for convenient dialog construction
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
builder.setMessage(R.string.loadgame_delete_confirmation)
|
||||||
|
.setPositiveButton(R.string.loadgame_delete_confirm, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
for(IDeleteDialogFragmentListener l : listeners) {
|
||||||
|
l.onDialogPositiveClick(getPosition());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.loadgame_delete_cancel, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
// User cancelled the dialog
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private class LoadGameAdapter extends BaseAdapter {
|
private class LoadGameAdapter extends BaseAdapter {
|
||||||
|
@ -81,6 +153,11 @@ public class LoadGameActivity extends AppCompatActivity {
|
||||||
this.loadableGameList = loadableGameList;
|
this.loadableGameList = loadableGameList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delete(int position) {
|
||||||
|
loadableGameList.remove(position);
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return loadableGameList.size();
|
return loadableGameList.size();
|
||||||
|
|
|
@ -62,4 +62,9 @@
|
||||||
<string name="gametype_x_9x9">X Sudoku 9x9</string>
|
<string name="gametype_x_9x9">X Sudoku 9x9</string>
|
||||||
<string name="gametype_hyper_9x9">Hyper Sudoku 9x9</string>
|
<string name="gametype_hyper_9x9">Hyper Sudoku 9x9</string>
|
||||||
|
|
||||||
|
<!-- ### Continue Game ### -->
|
||||||
|
<string name="loadgame_delete_confirmation">Are you sure you want to delete this save?</string>
|
||||||
|
<string name="loadgame_delete_confirm">Delete</string>
|
||||||
|
<string name="loadgame_delete_cancel">Cancel</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue