From 9c9a0c12211c24e602f3114e8c874028e6813b9e Mon Sep 17 00:00:00 2001 From: uykek Date: Sat, 9 May 2020 18:37:00 +0200 Subject: [PATCH] Implement the functionality of the 'share' button of the ShareBoardDialogFragment, which is to share a board's code with other apps. --- .../ui/GameActivity.java | 20 +++++++++++++------ .../IShareDialogFragmentListener.java | 4 +++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java index 51b8847..891ea49 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java @@ -296,12 +296,12 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig case R.id.menu_share: ShareBoardDialog shareDialog = new ShareBoardDialog(); - shareDialog.setDisplayCode(gameController.getFieldAsString()); + shareDialog.setDisplayCode("sudoku://" + gameController.getCodeOfField()); shareDialog.setCopyClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 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); 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.LENGTH_LONG).show(); } 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 - public void onShareDialogPositiveClick() { - gameController.resetLevel(); + public void onShareDialogPositiveClick(String input) { + 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 @@ -520,7 +528,7 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig builder.setPositiveButton(R.string.share_confirmation_confirm, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { for(IShareDialogFragmentListener l : listeners) { - l.onShareDialogPositiveClick(); + l.onShareDialogPositiveClick(binding.ver3DisplaySudokuTextView.getText().toString()); } } }) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/listener/IShareDialogFragmentListener.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/listener/IShareDialogFragmentListener.java index 9b2eb45..d5c1629 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/listener/IShareDialogFragmentListener.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/listener/IShareDialogFragmentListener.java @@ -1,9 +1,11 @@ package org.secuso.privacyfriendlysudoku.ui.listener; +import org.secuso.privacyfriendlysudoku.ui.view.databinding.DialogFragmentShareBoardBinding; + /** * Created by Chris on 19.01.2016. */ public interface IShareDialogFragmentListener { - public void onShareDialogPositiveClick(); + public void onShareDialogPositiveClick(String input); public void onDialogNegativeClick(); }