Implement the functionality of the 'share' button of the ShareBoardDialogFragment, which is to share a board's code with other apps.

This commit is contained in:
uykek 2020-05-09 18:37:00 +02:00
parent 5a098d8ac5
commit 9c9a0c1221
2 changed files with 17 additions and 7 deletions

View file

@ -296,12 +296,12 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
case R.id.menu_share: case R.id.menu_share:
ShareBoardDialog shareDialog = new ShareBoardDialog(); ShareBoardDialog shareDialog = new ShareBoardDialog();
shareDialog.setDisplayCode(gameController.getFieldAsString()); shareDialog.setDisplayCode("sudoku://" + gameController.getCodeOfField());
shareDialog.setCopyClickListener(new View.OnClickListener() { shareDialog.setCopyClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// remember to include alternate code for older android versions // remember to include alternate code for older android versions
String codeForClipboard = gameController.getFieldAsString().toString(); String codeForClipboard = "sudoku://" + gameController.getCodeOfField();
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null) { if (clipboard != null) {
@ -310,7 +310,9 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
Toast.makeText(GameActivity.this, R.string.copy_code_confirmation_toast, Toast.makeText(GameActivity.this, R.string.copy_code_confirmation_toast,
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
} else { } else {
// //remember to replace hardcoded string
Toast.makeText(GameActivity.this, "Cannot access clipboard",
Toast.LENGTH_LONG).show();
} }
} }
}); });
@ -465,8 +467,14 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
} }
@Override @Override
public void onShareDialogPositiveClick() { public void onShareDialogPositiveClick(String input) {
gameController.resetLevel(); Intent sendBoardIntent = new Intent();
sendBoardIntent.setAction(Intent.ACTION_SEND);
sendBoardIntent.putExtra(Intent.EXTRA_TEXT, input);
sendBoardIntent.setType("text/plain");
Intent shareBoardIntent = Intent.createChooser(sendBoardIntent, null);
startActivity(shareBoardIntent);
} }
@Override @Override
@ -520,7 +528,7 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
builder.setPositiveButton(R.string.share_confirmation_confirm, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.share_confirmation_confirm, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
for(IShareDialogFragmentListener l : listeners) { for(IShareDialogFragmentListener l : listeners) {
l.onShareDialogPositiveClick(); l.onShareDialogPositiveClick(binding.ver3DisplaySudokuTextView.getText().toString());
} }
} }
}) })

View file

@ -1,9 +1,11 @@
package org.secuso.privacyfriendlysudoku.ui.listener; package org.secuso.privacyfriendlysudoku.ui.listener;
import org.secuso.privacyfriendlysudoku.ui.view.databinding.DialogFragmentShareBoardBinding;
/** /**
* Created by Chris on 19.01.2016. * Created by Chris on 19.01.2016.
*/ */
public interface IShareDialogFragmentListener { public interface IShareDialogFragmentListener {
public void onShareDialogPositiveClick(); public void onShareDialogPositiveClick(String input);
public void onDialogNegativeClick(); public void onDialogNegativeClick();
} }