simplified the auto-update notification
This commit is contained in:
parent
2c77c5aa96
commit
97baa394fe
4 changed files with 18 additions and 86 deletions
|
|
@ -44,7 +44,7 @@
|
|||
<activity
|
||||
android:excludeFromRecents="true"
|
||||
android:label=""
|
||||
android:name="io.github.sspanak.tt9.ui.dialogs.PopupDialogActivity"
|
||||
android:name="io.github.sspanak.tt9.ui.dialogs.AutoUpdateMonologActivity"
|
||||
android:theme="@style/TTheme.AddWord" />
|
||||
|
||||
<activity
|
||||
|
|
|
|||
|
|
@ -2,53 +2,43 @@ package io.github.sspanak.tt9.ui.dialogs;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import io.github.sspanak.tt9.db.words.DictionaryLoader;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.languages.LanguageCollection;
|
||||
import io.github.sspanak.tt9.util.ConsumerCompat;
|
||||
import io.github.sspanak.tt9.util.Logger;
|
||||
|
||||
public class AutoUpdateMonolog extends PopupDialog {
|
||||
public static final String TYPE = "tt9.popup_dialog.confirm_words_update";
|
||||
public class AutoUpdateMonologActivity extends AppCompatActivity {
|
||||
public static final String PARAMETER_LANGUAGE = "lang";
|
||||
|
||||
private Language language;
|
||||
|
||||
|
||||
AutoUpdateMonolog(@NonNull Context context, @NonNull Intent intent, ConsumerCompat<String> activityFinisher) {
|
||||
super(context, activityFinisher);
|
||||
LanguageCollection.init(context);
|
||||
parseIntent(intent);
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
processIntent(getIntent());
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
private void parseIntent(@NonNull Intent intent) {
|
||||
private void processIntent(@NonNull Intent intent) {
|
||||
LanguageCollection.init(this);
|
||||
int languageId = intent.getIntExtra(PARAMETER_LANGUAGE, -1);
|
||||
language = LanguageCollection.getLanguage(languageId);
|
||||
Language language = LanguageCollection.getLanguage(languageId);
|
||||
|
||||
if (language == null) {
|
||||
Logger.e(getClass().getSimpleName(), "Auto-updating is not possible. Intent parameter '" + PARAMETER_LANGUAGE + "' is invalid: " + languageId);
|
||||
} else {
|
||||
DictionaryLoader.load(this, language);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void show() {
|
||||
if (language != null) {
|
||||
DictionaryLoader.load(context, language);
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
public static Intent generateShowIntent(Context context, int language) {
|
||||
Intent intent = new Intent(context, PopupDialogActivity.class);
|
||||
Intent intent = new Intent(context, AutoUpdateMonologActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
|
||||
intent.putExtra(PARAMETER_DIALOG_TYPE, TYPE);
|
||||
intent.putExtra(PARAMETER_LANGUAGE, language);
|
||||
|
||||
return intent;
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
package io.github.sspanak.tt9.ui.dialogs;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import io.github.sspanak.tt9.ime.TraditionalT9;
|
||||
import io.github.sspanak.tt9.util.Logger;
|
||||
|
||||
public class PopupDialogActivity extends AppCompatActivity {
|
||||
private static final String LOG_TAG = PopupDialogActivity.class.getSimpleName();
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedData) {
|
||||
super.onCreate(savedData);
|
||||
PopupDialog dialog = getDialog();
|
||||
if (dialog != null) {
|
||||
dialog.show();
|
||||
} else {
|
||||
onDialogClose("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private PopupDialog getDialog() {
|
||||
Intent i = getIntent();
|
||||
|
||||
String popupType = i != null ? i.getStringExtra(PopupDialog.PARAMETER_DIALOG_TYPE) : "";
|
||||
popupType = popupType != null ? popupType : "";
|
||||
|
||||
return switch (popupType) {
|
||||
case AutoUpdateMonolog.TYPE -> new AutoUpdateMonolog(this, i, this::onDialogClose);
|
||||
default -> {
|
||||
Logger.w(LOG_TAG, "Unknown popup type: '" + popupType + "'. Not displaying anything.");
|
||||
yield null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void onDialogClose(String message) {
|
||||
finish();
|
||||
Intent intent = new Intent(this, TraditionalT9.class);
|
||||
if (message != null) {
|
||||
intent.putExtra(PopupDialog.INTENT_CLOSE, message);
|
||||
}
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
onDialogClose(null);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ import androidx.core.app.NotificationCompat;
|
|||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.ui.dialogs.AutoUpdateMonolog;
|
||||
import io.github.sspanak.tt9.ui.dialogs.AutoUpdateMonologActivity;
|
||||
|
||||
public class DictionaryUpdateNotification extends DictionaryNotification {
|
||||
private final Language language;
|
||||
|
|
@ -25,7 +25,7 @@ public class DictionaryUpdateNotification extends DictionaryNotification {
|
|||
|
||||
@Override
|
||||
protected PendingIntent createNavigationIntent(@NonNull Context context, @Nullable Language language) {
|
||||
Intent intent = AutoUpdateMonolog.generateShowIntent(context, language != null ? language.getId() : -1);
|
||||
Intent intent = AutoUpdateMonologActivity.generateShowIntent(context, language != null ? language.getId() : -1);
|
||||
return PendingIntent.getActivity(context, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue