Skip to content

Commit

Permalink
fixed issues #197 and #198
Browse files Browse the repository at this point in the history
  • Loading branch information
konradrenner committed Jul 11, 2019
1 parent cebfcc7 commit c287ffe
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

You can also have a look on the GitHub release page: https://github.com/konradrenner/kolabnotes-android/releases

## [3.2.1] - 2019-07-11
### Fixed
- GitHub issue 197
- GitHub issue 198

## [3.2.0] - 2018-11-06
### Added
- Polish translation thx to Waldemar Stoczkowski!
Expand Down Expand Up @@ -95,7 +100,8 @@ You can also have a look on the GitHub release page: https://github.com/konradre
### Fixed
- First stable release, support for all major features of the Kolab notes format

[Unreleased]: https://github.com/konradrenner/kolabnotes-android/compare/3.2.0...HEAD
[Unreleased]: https://github.com/konradrenner/kolabnotes-android/compare/3.2.1...HEAD
[3.2.1]: https://github.com/konradrenner/kolabnotes-android/compare/3.2.0...3.2.1
[3.2.0]: https://github.com/konradrenner/kolabnotes-android/compare/3.1.3...3.2.0
[3.1.3]: https://github.com/konradrenner/kolabnotes-android/compare/3.1.2...3.1.3
[3.1.2]: https://github.com/konradrenner/kolabnotes-android/compare/3.1.1...3.1.2
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "org.kore.kolabnotes.android"
minSdkVersion 16
targetSdkVersion 26
versionCode 99
versionName "3.2.0"
versionCode 100
versionName "3.2.1"

//Running test
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
Expand Down Expand Up @@ -132,6 +134,9 @@ public class DetailFragment extends Fragment implements OnAccountSwitchedListene

private String uuidForCreation;

// the onPause methode of the activity is always called, when the fragment is finished. This applies also to "back" action, where it is not necessary to store the note (because when selected back, the user don't wants to store the note)
private boolean saveNotRequiredAnymore = false;

//This map contains inline images in its base form, sadly the android webview destroys the correct form
private Map<String,String> base64Images = new HashMap<>();

Expand Down Expand Up @@ -1199,7 +1204,9 @@ public void onClick(DialogInterface dialog, int which) {

@Override
public void save() {
saveNote(false);
if(!saveNotRequiredAnymore){
saveNote(false);
}
}

void saveNote(boolean closeWhenSaved){
Expand Down Expand Up @@ -1491,7 +1498,7 @@ public void onClick(DialogInterface dialog, int which) {
}else{
goBack();
}
} else if (editor.getHtml() != null || !TextUtils.isEmpty(
} else if (/* GitHub issue 197 */(editor != null && editor.getHtml() != null) || !TextUtils.isEmpty(
((EditText) activity.findViewById(R.id.detail_summary)).getText().toString())) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);

Expand All @@ -1503,6 +1510,12 @@ public void onClick(DialogInterface dialog, int which) {
if(isNewNote){
final ActiveAccount activeAccount = activeAccountRepository.getActiveAccount();
new AttachmentRepository(activity).deleteForNote(activeAccount.getAccount(), activeAccount.getRootFolder(), getUUIDForCreation());

// If the activity was paused, the note got stored in the meantime
if(note != null) {
noteRepository.delete(activeAccount.getAccount(), activeAccount.getRootFolder(), note);
noteTagRepository.delete(activeAccount.getAccount(), activeAccount.getRootFolder(), note.getIdentification().getUid());
}
}
goBack();
}
Expand Down Expand Up @@ -1560,8 +1573,54 @@ private void printNote() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
PrintManager printManager = (PrintManager) activity.getSystemService(Context.PRINT_SERVICE);
String jobName = getString(R.string.app_name) + " Document";
PrintDocumentAdapter printAdapter = editor.createPrintDocumentAdapter();
PrintJob printJob = printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());

// GitHub issue 197
if(editor != null){
PrintDocumentAdapter printAdapter = editor.createPrintDocumentAdapter();
printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
}else if(editText != null){
printEditText(jobName);
}else{
Toast.makeText(activity, R.string.empty_note_description, Toast.LENGTH_LONG).show();
}

}
}

private void printEditText(final String jobName) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// Create a WebView object specifically for printing
WebView webView = new WebView(getActivity());
webView.setWebViewClient(new WebViewClient() {

public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}

@Override
public void onPageFinished(WebView view, String url) {
Log.i("printEditText", "page finished loading " + url);
createWebPrintJob(view, jobName);
}
});

String htmlDocument = Html.toHtml(editText.getText());
webView.loadDataWithBaseURL(null, htmlDocument, "text/HTML", "UTF-8", null);
}
}

private void createWebPrintJob(WebView webView, String jobName) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// Get a PrintManager instance
PrintManager printManager = (PrintManager) getActivity()
.getSystemService(Context.PRINT_SERVICE);

// Get a print adapter instance
PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();

// Create a print job with name and adapter instance
PrintJob printJob = printManager.print(jobName, printAdapter,
new PrintAttributes.Builder().build());
}
}

Expand All @@ -1581,6 +1640,8 @@ private void goBack(){
Intent returnIntent = new Intent();
returnIntent.putExtra("selectedNotebookName",givenNotebook);

saveNotRequiredAnymore = true;

((OnFragmentCallback)activity).fragmentFinished(returnIntent, OnFragmentCallback.ResultCode.BACK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
if(note == null){
views.setTextViewText(R.id.sticky_note_summary, context.getResources().getString(R.string.note_not_found));

//GitHub issue 198
views.setOnClickPendingIntent(R.id.sticky_note_summary, null);

views.setTextViewText(R.id.sticky_note_description, "");
}else {

Expand Down

0 comments on commit c287ffe

Please sign in to comment.