Skip to content

Commit

Permalink
agrep support, gsantner#1202
Browse files Browse the repository at this point in the history
  • Loading branch information
adelobosko committed May 18, 2021
1 parent 2b76207 commit bb36b92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import net.gsantner.opoc.activity.GsFragmentBase;
import net.gsantner.opoc.util.Callback;
import net.gsantner.opoc.util.ShareUtil;
import net.gsantner.opoc.util.StringUtils;

import java.io.File;

Expand Down Expand Up @@ -206,16 +207,22 @@ private void handleLaunchingIntent(Intent intent) {
}

if (!intentIsSend && file != null) {
int lineNumber = intent.getIntExtra(DocumentIO.EXTRA_FILE_LINE_NUMBER, -1);
if(lineNumber < 0 && intentData != null){
lineNumber = StringUtils.tryParseInt(intentData.getQueryParameter("line"), -1);
}

boolean preview = intent.getBooleanExtra(EXTRA_DO_PREVIEW, false)
|| (file.exists() && file.isFile() && _appSettings.getDocumentPreviewState(file.getPath()))
|| file.getName().startsWith("index.");

final int lineNumber = intent.getIntExtra(DocumentIO.EXTRA_FILE_LINE_NUMBER, -1);

if (lineNumber >= 0) {
preview = false;
}
showTextEditor(null, file, fileIsFolder, preview, lineNumber);
}

}

private void showNotSupportedMessage() {
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/net/gsantner/opoc/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,12 @@ public static int getIndexByLineNumber(final String text, final int lineNumber)

return index;
}

public static int tryParseInt(final String value, int defaultValue) {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
return defaultValue;
}
}
}

0 comments on commit bb36b92

Please sign in to comment.