Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launcher ShortCuts: Open ToDo & QuickNote at bottom #1748

Merged
merged 2 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,14 @@ private void handleLaunchingIntent(final Intent intent) {
if (!intentIsSend && file != null) {
final Document doc = new Document(file);

int startLine = intent.getIntExtra(Document.EXTRA_FILE_LINE_NUMBER, -1);
if (startLine < 0 && intentData != null) {
Integer startLine = null;
if (intent.hasExtra(Document.EXTRA_FILE_LINE_NUMBER)) {
startLine = intent.getIntExtra(Document.EXTRA_FILE_LINE_NUMBER, -1);
} else if (intentData != null) {
startLine = StringUtils.tryParseInt(intentData.getQueryParameter("line"), -1);
}

final boolean startInPreview = (startLine < 0) && (
final boolean startInPreview = (startLine == null) && (
intent.getBooleanExtra(EXTRA_DO_PREVIEW, false) ||
_appSettings.getDocumentPreviewState(doc.getPath()) ||
file.getName().startsWith("index."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static DocumentEditFragment newInstance(final @NonNull Document document,
DocumentEditFragment f = new DocumentEditFragment();
Bundle args = new Bundle();
args.putSerializable(Document.EXTRA_DOCUMENT, document);
if (lineNumber != null && lineNumber >= 0) {
if (lineNumber != null) {
args.putInt(Document.EXTRA_FILE_LINE_NUMBER, lineNumber);
}
args.putBoolean(START_PREVIEW, preview);
Expand Down Expand Up @@ -232,8 +232,13 @@ public void onFragmentFirstTimeVisible() {
if (_savedInstanceState == null) {
if (isDisplayedAtMainActivity() || _appSettings.isEditorStartOnBotttom()) {
startPos = _hlEditor.length();
} else if (args != null && args.getInt(Document.EXTRA_FILE_LINE_NUMBER, -1) >= 0) {
startPos = StringUtils.getIndexFromLineOffset(_hlEditor.getText(), args.getInt(Document.EXTRA_FILE_LINE_NUMBER), 0);
} else if (args != null && args.containsKey(Document.EXTRA_FILE_LINE_NUMBER)) {
final int lno = args.getInt(Document.EXTRA_FILE_LINE_NUMBER);
if (lno >= 0) {
startPos = StringUtils.getIndexFromLineOffset(_hlEditor.getText(), lno, 0);
} else {
startPos = _hlEditor.length();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@
import java.io.File;

public class OpenEditorActivity extends MarkorBaseActivity {
protected void openEditorForFile(File file) {
Intent openIntent = new Intent(getApplicationContext(), DocumentActivity.class)

protected void openEditorForFile(final File file, final Integer line) {
final Intent openIntent = new Intent(getApplicationContext(), DocumentActivity.class)
.setAction(Intent.ACTION_CALL_BUTTON)
.putExtra(Document.EXTRA_PATH, file);

if (line != null) {
openIntent.putExtra(Document.EXTRA_FILE_LINE_NUMBER, line);
}

openActivityAndClose(openIntent, file);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
import android.os.Bundle;
import android.support.annotation.Nullable;

import net.gsantner.markor.model.Document;
import net.gsantner.markor.util.AppSettings;

public class OpenEditorQuickNoteActivity extends OpenEditorActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
openEditorForFile(new AppSettings(getApplicationContext()).getQuickNoteFile());
openEditorForFile(new AppSettings(getApplicationContext()).getQuickNoteFile(), Document.EXTRA_FILE_LINE_NUMBER_LAST);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
import android.os.Bundle;
import android.support.annotation.Nullable;

import net.gsantner.markor.model.Document;
import net.gsantner.markor.util.AppSettings;

public class OpenEditorTodoActivity extends OpenEditorActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
openEditorForFile(new AppSettings(getApplicationContext()).getTodoFile());
openEditorForFile(new AppSettings(getApplicationContext()).getTodoFile(), Document.EXTRA_FILE_LINE_NUMBER_LAST);
}
}
1 change: 1 addition & 0 deletions app/src/main/java/net/gsantner/markor/model/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class Document implements Serializable {
public static final String EXTRA_DOCUMENT = "EXTRA_DOCUMENT"; // Document
public static final String EXTRA_PATH = "EXTRA_PATH"; // java.io.File
public static final String EXTRA_FILE_LINE_NUMBER = "EXTRA_FILE_LINE_NUMBER"; // int
public static final int EXTRA_FILE_LINE_NUMBER_LAST = -1; // Flag for last line. Any -ve number will work

private final File _file;
private final String _fileExtension;
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/net/gsantner/markor/util/ShortcutUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import net.gsantner.markor.R;
import net.gsantner.markor.activity.openeditor.OpenEditorFromShortcutOrWidgetActivity;
import net.gsantner.markor.model.Document;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -63,7 +64,8 @@ public static void setShortcuts(@NonNull Context context) {
// Create the to-do shortcut
final Intent openTodo = new Intent(context, OpenEditorFromShortcutOrWidgetActivity.class)
.setAction(Intent.ACTION_EDIT)
.setData(Uri.fromFile(appSettings.getTodoFile()));
.setData(Uri.fromFile(appSettings.getTodoFile()))
.putExtra(Document.EXTRA_FILE_LINE_NUMBER, Document.EXTRA_FILE_LINE_NUMBER_LAST);

final ShortcutInfo shortcutToDo = new ShortcutInfo.Builder(context, ID_TO_DO)
.setShortLabel(createShortLabel(context.getString(R.string.todo)))
Expand All @@ -76,7 +78,8 @@ public static void setShortcuts(@NonNull Context context) {
// Create the QuickNote shortcut
final Intent openQuickNote = new Intent(context, OpenEditorFromShortcutOrWidgetActivity.class)
.setAction(Intent.ACTION_EDIT)
.setData(Uri.fromFile(appSettings.getQuickNoteFile()));
.setData(Uri.fromFile(appSettings.getQuickNoteFile()))
.putExtra(Document.EXTRA_FILE_LINE_NUMBER, Document.EXTRA_FILE_LINE_NUMBER_LAST);

final ShortcutInfo shortcutQuickNote = new ShortcutInfo.Builder(context, ID_QUICK_NOTE)
.setShortLabel(createShortLabel(context.getString(R.string.quicknote)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
// Open To-do
final Intent openTodo = new Intent(context, OpenEditorFromShortcutOrWidgetActivity.class)
.setAction(Intent.ACTION_EDIT)
.putExtra(Document.EXTRA_PATH, appSettings.getTodoFile());
.putExtra(Document.EXTRA_PATH, appSettings.getTodoFile())
.putExtra(Document.EXTRA_FILE_LINE_NUMBER, Document.EXTRA_FILE_LINE_NUMBER_LAST);
views.setOnClickPendingIntent(R.id.widget_todo, PendingIntent.getActivity(context, requestCode++, openTodo, PendingIntent.FLAG_UPDATE_CURRENT));

// Open QuickNote
final Intent openQuickNote = new Intent(context, OpenEditorFromShortcutOrWidgetActivity.class)
.setAction(Intent.ACTION_EDIT)
.putExtra(Document.EXTRA_PATH, appSettings.getQuickNoteFile());
.putExtra(Document.EXTRA_PATH, appSettings.getQuickNoteFile())
.putExtra(Document.EXTRA_FILE_LINE_NUMBER, Document.EXTRA_FILE_LINE_NUMBER_LAST);
views.setOnClickPendingIntent(R.id.widget_quicknote, PendingIntent.getActivity(context, requestCode++, openQuickNote, PendingIntent.FLAG_UPDATE_CURRENT));

// Open Notebook
Expand Down