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

Chore fixes in TextEditorActivity and FtpNotification #3964

Merged
merged 2 commits into from
Oct 30, 2023
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 @@ -123,6 +123,9 @@ public void onCreate(Bundle savedInstanceState) {
downButton.setOnClickListener(this);
// downButton.setEnabled(false);

if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(!useNewStack);
}
mainTextView = findViewById(R.id.textEditorMainEditText);
scrollView = findViewById(R.id.textEditorScrollView);

Expand Down Expand Up @@ -469,15 +472,15 @@ public void afterTextChanged(Editable editable) {
}
};

if (mainTextView.getText() == null) return;

searchTextTask =
new SearchTextTask(
mainTextView.getText().toString(),
editable.toString(),
onProgressUpdate,
onAsyncTaskFinished);
searchTextTask.execute();
if (mainTextView.getText() != null) {
searchTextTask =
new SearchTextTask(
mainTextView.getText().toString(),
editable.toString(),
onProgressUpdate,
onAsyncTaskFinished);
searchTextTask.execute();
}
}
}

Expand Down Expand Up @@ -583,26 +586,26 @@ private void highlightCurrentSearchResult(final TextEditorActivityViewModel view
colorSearchResult(keyValueNew, getAccent());

// scrolling to the highlighted element
if (getSupportActionBar() != null) return;

scrollView.scrollTo(
0,
(Integer) keyValueNew.getLineNumber()
+ mainTextView.getLineHeight()
+ Math.round(mainTextView.getLineSpacingExtra())
- getSupportActionBar().getHeight());
if (getSupportActionBar() != null) {
scrollView.scrollTo(
0,
(Integer) keyValueNew.getLineNumber()
+ mainTextView.getLineHeight()
+ Math.round(mainTextView.getLineSpacingExtra())
- getSupportActionBar().getHeight());
}
}

private void colorSearchResult(SearchResultIndex resultIndex, @ColorInt int color) {
if (mainTextView.getText() == null) return;

mainTextView
.getText()
.setSpan(
new BackgroundColorSpan(color),
(Integer) resultIndex.getStartCharNumber(),
(Integer) resultIndex.getEndCharNumber(),
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
if (mainTextView.getText() != null) {
mainTextView
.getText()
.setSpan(
new BackgroundColorSpan(color),
(Integer) resultIndex.getStartCharNumber(),
(Integer) resultIndex.getEndCharNumber(),
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
}

private void cleanSpans(TextEditorActivityViewModel viewModel) {
Expand All @@ -612,12 +615,12 @@ private void cleanSpans(TextEditorActivityViewModel viewModel) {
viewModel.setLine(0);

// clearing textView spans
if (mainTextView.getText() == null) return;

BackgroundColorSpan[] colorSpans =
mainTextView.getText().getSpans(0, mainTextView.length(), BackgroundColorSpan.class);
for (BackgroundColorSpan colorSpan : colorSpans) {
mainTextView.getText().removeSpan(colorSpan);
if (mainTextView.getText() != null) {
BackgroundColorSpan[] colorSpans =
mainTextView.getText().getSpans(0, mainTextView.length(), BackgroundColorSpan.class);
for (BackgroundColorSpan colorSpan : colorSpans) {
mainTextView.getText().removeSpan(colorSpan);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
import com.amaze.filemanager.utils.NetworkUtil;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

import androidx.annotation.StringRes;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.preference.PreferenceManager;

/**
Expand Down Expand Up @@ -96,9 +96,7 @@ public static Notification startNotification(Context context, boolean noStopButt
}

public static void updateNotification(Context context, boolean noStopButton) {
String notificationService = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(notificationService);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
int port = sharedPreferences.getInt(FtpService.PORT_PREFERENCE_KEY, FtpService.DEFAULT_PORT);
Expand Down Expand Up @@ -129,8 +127,6 @@ public static void updateNotification(Context context, boolean noStopButton) {
}

private static void removeNotification(Context context) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager nm = (NotificationManager) context.getSystemService(ns);
nm.cancelAll();
NotificationManagerCompat.from(context).cancelAll();
}
}