Skip to content

Commit

Permalink
Merge pull request #3964 from TeamAmaze/bugfix/768
Browse files Browse the repository at this point in the history
Chore fixes in TextEditorActivity and FtpNotification
  • Loading branch information
VishalNehra authored Oct 30, 2023
2 parents 68a1f93 + d7091be commit 2c9f9e6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 39 deletions.
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();
}
}

0 comments on commit 2c9f9e6

Please sign in to comment.