clicking on the dictionary loading notification now opens the Settings
This commit is contained in:
parent
8a20bde82f
commit
7e61d8d180
3 changed files with 51 additions and 9 deletions
|
|
@ -51,7 +51,7 @@ public class DictionaryLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public DictionaryLoader(Context context) {
|
private DictionaryLoader(Context context) {
|
||||||
assets = context.getAssets();
|
assets = context.getAssets();
|
||||||
sqlite = SQLiteOpener.getInstance(context);
|
sqlite = SQLiteOpener.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package io.github.sspanak.tt9.preferences;
|
package io.github.sspanak.tt9.preferences;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
|
|
@ -18,6 +20,7 @@ import io.github.sspanak.tt9.db.DictionaryLoader;
|
||||||
import io.github.sspanak.tt9.db.LegacyDb;
|
import io.github.sspanak.tt9.db.LegacyDb;
|
||||||
import io.github.sspanak.tt9.db.WordStoreAsync;
|
import io.github.sspanak.tt9.db.WordStoreAsync;
|
||||||
import io.github.sspanak.tt9.ime.helpers.InputModeValidator;
|
import io.github.sspanak.tt9.ime.helpers.InputModeValidator;
|
||||||
|
import io.github.sspanak.tt9.ime.helpers.SystemSettings;
|
||||||
import io.github.sspanak.tt9.preferences.helpers.Hotkeys;
|
import io.github.sspanak.tt9.preferences.helpers.Hotkeys;
|
||||||
import io.github.sspanak.tt9.preferences.screens.AppearanceScreen;
|
import io.github.sspanak.tt9.preferences.screens.AppearanceScreen;
|
||||||
import io.github.sspanak.tt9.preferences.screens.DebugScreen;
|
import io.github.sspanak.tt9.preferences.screens.DebugScreen;
|
||||||
|
|
@ -64,6 +67,24 @@ public class PreferencesActivity extends AppCompatActivity implements Preference
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
if (!SystemSettings.isTT9Enabled(this)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Intent intent = getIntent();
|
||||||
|
String screenName = intent != null ? intent.getStringExtra("screen") : null;
|
||||||
|
screenName = screenName != null ? screenName : "";
|
||||||
|
|
||||||
|
Fragment screen = getScreen(screenName.replace("Screen", ""));
|
||||||
|
|
||||||
|
if (screen.getClass().getSimpleName().equals(screenName)) {
|
||||||
|
displayScreen(screen, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getScreenName
|
* getScreenName
|
||||||
|
|
@ -81,7 +102,11 @@ public class PreferencesActivity extends AppCompatActivity implements Preference
|
||||||
* Finds a screen fragment by name. If there is no fragment with such name, the main screen
|
* Finds a screen fragment by name. If there is no fragment with such name, the main screen
|
||||||
* fragment will be returned.
|
* fragment will be returned.
|
||||||
*/
|
*/
|
||||||
private Fragment getScreen(String name) {
|
private Fragment getScreen(@Nullable String name) {
|
||||||
|
if (name == null) {
|
||||||
|
return new MainSettingsScreen(this);
|
||||||
|
}
|
||||||
|
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "Appearance":
|
case "Appearance":
|
||||||
return new AppearanceScreen(this);
|
return new AppearanceScreen(this);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ package io.github.sspanak.tt9.ui;
|
||||||
|
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
@ -19,6 +21,8 @@ import io.github.sspanak.tt9.languages.InvalidLanguageCharactersException;
|
||||||
import io.github.sspanak.tt9.languages.InvalidLanguageException;
|
import io.github.sspanak.tt9.languages.InvalidLanguageException;
|
||||||
import io.github.sspanak.tt9.languages.Language;
|
import io.github.sspanak.tt9.languages.Language;
|
||||||
import io.github.sspanak.tt9.languages.LanguageCollection;
|
import io.github.sspanak.tt9.languages.LanguageCollection;
|
||||||
|
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
||||||
|
import io.github.sspanak.tt9.preferences.screens.DictionariesScreen;
|
||||||
|
|
||||||
|
|
||||||
public class DictionaryLoadingBar {
|
public class DictionaryLoadingBar {
|
||||||
|
|
@ -53,23 +57,36 @@ public class DictionaryLoadingBar {
|
||||||
resources = context.getResources();
|
resources = context.getResources();
|
||||||
|
|
||||||
manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
notificationBuilder = getNotificationBuilderCompat(context);
|
||||||
|
|
||||||
|
notificationBuilder
|
||||||
|
.setContentIntent(createNavigationIntent(context))
|
||||||
|
.setSmallIcon(android.R.drawable.stat_notify_sync)
|
||||||
|
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
||||||
|
.setOnlyAlertOnce(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private PendingIntent createNavigationIntent(Context context) {
|
||||||
|
Intent intent = new Intent(context, PreferencesActivity.class);
|
||||||
|
intent.putExtra("screen", DictionariesScreen.class.getSimpleName());
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
|
return PendingIntent.getActivity(context, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private NotificationCompat.Builder getNotificationBuilderCompat(Context context) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
manager.createNotificationChannel(new NotificationChannel(
|
manager.createNotificationChannel(new NotificationChannel(
|
||||||
NOTIFICATION_CHANNEL_ID,
|
NOTIFICATION_CHANNEL_ID,
|
||||||
"Dictionary Status",
|
"Dictionary Status",
|
||||||
NotificationManager.IMPORTANCE_LOW
|
NotificationManager.IMPORTANCE_LOW
|
||||||
));
|
));
|
||||||
notificationBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
|
return new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
|
||||||
} else {
|
} else {
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
notificationBuilder = new NotificationCompat.Builder(context);
|
return new NotificationCompat.Builder(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationBuilder
|
|
||||||
.setSmallIcon(android.R.drawable.stat_notify_sync)
|
|
||||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
|
||||||
.setOnlyAlertOnce(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue