Skip to content

Commit

Permalink
0.9.5 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FazziCLAY committed Oct 3, 2022
1 parent 0db5dbe commit f8b1a8a
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 73 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "ru.fazziclay.opentoday"
minSdk 26
targetSdk 32
versionCode 54
versionName "0.9.4 (build 54)"
versionCode 56
versionName "0.9.5 (build 56)"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
</activity>

<!-- Services -->
<service
android:name=".app.receiver.service.UITickService"
android:enabled="true"
android:exported="false" />

<!-- Receivers -->
<receiver
Expand Down
37 changes: 32 additions & 5 deletions app/src/main/java/ru/fazziclay/opentoday/app/App.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.fazziclay.opentoday.app;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
Expand All @@ -16,23 +15,24 @@
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import ru.fazziclay.javaneoutil.FileUtil;
import ru.fazziclay.opentoday.BuildConfig;
import ru.fazziclay.opentoday.R;
import ru.fazziclay.opentoday.app.datafixer.DataFixer;
import ru.fazziclay.opentoday.app.items.ItemManager;
import ru.fazziclay.opentoday.app.items.notifications.DayItemNotification;
import ru.fazziclay.opentoday.app.items.notifications.ItemNotification;
import ru.fazziclay.opentoday.app.receiver.ItemsTickReceiver;
import ru.fazziclay.opentoday.app.receiver.QuickNoteReceiver;
import ru.fazziclay.opentoday.app.settings.SettingsManager;
import ru.fazziclay.opentoday.debug.TestActivityFragment;
import ru.fazziclay.opentoday.debug.TestItemManager;
import ru.fazziclay.opentoday.debug.TestItemStorageDrawer;
import ru.fazziclay.opentoday.debug.TestItemViewGenerator;
import ru.fazziclay.opentoday.ui.activity.CrashReportActivity;
import ru.fazziclay.opentoday.ui.activity.MainActivity;
import ru.fazziclay.opentoday.util.DebugUtil;
import ru.fazziclay.opentoday.util.Profiler;

@SuppressWarnings("PointlessBooleanExpression") // for debug variables
public class App extends Application {
Expand Down Expand Up @@ -74,6 +74,33 @@ public static App get() {
private JSONObject versionData;
private boolean appInForeground = false;

public static final MainActivity.QuickNoteInterface QUICK_NOTE = s -> {
List<ItemNotification> notifys = new ArrayList<>();
boolean parseTime = true;
if (parseTime) {
char[] chars = s.toCharArray();
int i = 0;
for (char aChar : chars) {
if (aChar == ':') {
try {
if (i >= 2 && chars.length >= 5) {
int hours = Integer.parseInt(String.valueOf(chars[i - 2]) + chars[i - 1]);
int minutes = Integer.parseInt(String.valueOf(chars[i + 1]) + chars[i + 2]);

DayItemNotification noti = new DayItemNotification();
noti.setTime((hours * 60 * 60) + (minutes * 60));
noti.setNotifyTextFromItemText(true);
notifys.add(noti);
}
} catch (Exception ignored) {
}
}
i++;
}
}
return notifys;
};

@Override
public void onCreate() {
super.onCreate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ private void load() {

} else {
try {
JSONObject jRoot = new JSONObject(FileUtil.getText(dataFile));
JSONArray jTabs = jRoot.getJSONArray("tabs");
JSONObject jRoot = new JSONObject(FileUtil.getText(dataFile, "{}"));
JSONArray jTabs;
if (jRoot.has("tabs")) {
jTabs = jRoot.getJSONArray("tabs");
} else {
jTabs = new JSONArray();
}

int i = 0;
while (i < jTabs.length()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public class QuickNoteReceiver extends BroadcastReceiver {
public static final String NOTIFICATION_CHANNEL = "quick_note";

public static void sendQuickNoteNotification(Context context) {
NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_launcher_foreground, context.getString(R.string.quickNote), PendingIntent.getBroadcast(context, 0, new Intent(context, QuickNoteReceiver.class), 0))
int flags = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
flags = PendingIntent.FLAG_MUTABLE;
}
NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_launcher_foreground, context.getString(R.string.quickNote), PendingIntent.getBroadcast(context, 0, new Intent(context, QuickNoteReceiver.class), flags))
.addRemoteInput(new RemoteInput.Builder(QuickNoteReceiver.REMOTE_INPUT_KEY).setLabel(context.getString(R.string.quickNote)).build())
.build();

Expand Down Expand Up @@ -54,7 +58,9 @@ public void onReceive(Context context, Intent intent) {
}
}
if (rawText != null) {
app.getItemManager().getMainTab().addItem(new TextItem(context.getString(R.string.quickNote) + ": " + rawText));
TextItem item = new TextItem(context.getString(R.string.quickNote) + ": " + rawText);
if (app.getSettingsManager().isParseTimeFromQuickNote()) item.getNotifications().addAll(App.QUICK_NOTE.run(rawText));
app.getItemManager().getMainTab().addItem(item);
if (!rawTextMode) sendQuickNoteNotification(context);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,36 @@
package ru.fazziclay.opentoday.app.receiver.service;
package ru.fazziclay.opentoday.ui;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;

import androidx.annotation.Nullable;

import ru.fazziclay.opentoday.app.receiver.ItemsTickReceiver;

// Тик во время активного интерфейса приложения (раз в секунду) для того что бы изменения
// Были видры резче
public class UITickService extends Service {
public class UITickService {
private final Context context;
private final Handler handler;
private final Runnable runnable = this::tick;

public UITickService() {
public UITickService(Context context) {
this.context = context;
this.handler = new Handler(Looper.myLooper());
}

public void tick() {
sendBroadcast(new Intent(this, ItemsTickReceiver.class));
context.sendBroadcast(new Intent(context, ItemsTickReceiver.class));
this.handler.removeCallbacks(runnable);
long millis = System.currentTimeMillis() % 1000;
this.handler.postDelayed(runnable, 1000 - millis);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
public void create() {
handler.post(runnable);
return super.onStartCommand(intent, flags, startId);
}

@Override
public void onDestroy() {
super.onDestroy();
public void destroy() {
handler.removeCallbacks(runnable);
}

@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.UUID;

Expand All @@ -35,19 +36,18 @@
import ru.fazziclay.opentoday.app.items.ItemStorage;
import ru.fazziclay.opentoday.app.items.ItemsTab;
import ru.fazziclay.opentoday.app.items.callback.OnTabsChanged;
import ru.fazziclay.opentoday.app.items.item.Item;
import ru.fazziclay.opentoday.app.items.item.TextItem;
import ru.fazziclay.opentoday.app.items.notifications.DayItemNotification;
import ru.fazziclay.opentoday.app.items.notifications.ItemNotification;
import ru.fazziclay.opentoday.app.receiver.QuickNoteReceiver;
import ru.fazziclay.opentoday.app.receiver.service.UITickService;
import ru.fazziclay.opentoday.ui.UITickService;
import ru.fazziclay.opentoday.app.updatechecker.UpdateChecker;
import ru.fazziclay.opentoday.callback.CallbackImportance;
import ru.fazziclay.opentoday.callback.Status;
import ru.fazziclay.opentoday.databinding.ActivityMainBinding;
import ru.fazziclay.opentoday.ui.fragment.ItemsEditorRootFragment;
import ru.fazziclay.opentoday.ui.interfaces.ContainBackStack;
import ru.fazziclay.opentoday.ui.interfaces.CurrentItemsTab;
import ru.fazziclay.opentoday.ui.interfaces.NavigationHost;
import ru.fazziclay.opentoday.ui.interfaces.ContainBackStack;
import ru.fazziclay.opentoday.ui.other.AppToolbar;

public class MainActivity extends AppCompatActivity implements NavigationHost, CurrentItemsTab {
Expand All @@ -56,6 +56,7 @@ public class MainActivity extends AppCompatActivity implements NavigationHost, C
private ItemManager itemManager;
private AppToolbar toolbar;
private ItemStorage currentItemStorage;
private UITickService uiTickService;

// Tabs
private UUID currentTab = null;
Expand All @@ -81,6 +82,7 @@ protected void onCreate(Bundle savedInstanceState) {
this.app.setAppInForeground(true);
this.app.getTelemetry().mainActivityStart();
this.itemManager = app.getItemManager();
this.uiTickService = new UITickService(this);
this.binding = ActivityMainBinding.inflate(getLayoutInflater());

// Tabs
Expand Down Expand Up @@ -125,50 +127,30 @@ protected void onCreate(Bundle savedInstanceState) {
setupUpdateAvailableNotify();
setupCurrentDate();

QuickNoteReceiver.sendQuickNoteNotification(this);
startService(new Intent(this, UITickService.class));
if (app.getSettingsManager().isQuickNote()) {
QuickNoteReceiver.sendQuickNoteNotification(this);
}
uiTickService.create();
}

private void setupQuickNote() {
QuickNoteInterface quickNote = s -> {
Item item = new TextItem(s);
boolean parseTime = app.getSettingsManager().isParseTimeFromQuickNote();
if (parseTime) {
char[] chars = s.toCharArray();
int i = 0;
for (char aChar : chars) {
if (aChar == ':') {
try {
if (i >= 2 && chars.length >= 5) {
int hours = Integer.parseInt(String.valueOf(chars[i - 2]) + chars[i - 1]);
int minutes = Integer.parseInt(String.valueOf(chars[i + 1]) + chars[i + 2]);

DayItemNotification noti = new DayItemNotification();
noti.setTime((hours * 60 * 60) + (minutes * 60));
noti.setNotifyTextFromItemText(true);
item.getNotifications().add(noti);
}
} catch (Exception ignored) {
}
}
i++;
}
}
return item;
};
binding.quickNoteAdd.setOnClickListener(v -> {
String s = binding.quickNoteText.getText().toString();
if (s.isEmpty()) return;
binding.quickNoteText.setText("");
if (currentItemStorage != null) {
currentItemStorage.addItem(quickNote.run(s));
TextItem item = new TextItem(s);
if (app.getSettingsManager().isParseTimeFromQuickNote()) item.getNotifications().addAll(App.QUICK_NOTE.run(s));
currentItemStorage.addItem(item);
}
});

binding.quickNoteAdd.setOnLongClickListener(v -> {
String s = binding.quickNoteText.getText().toString();
if (currentItemStorage != null) {
currentItemStorage.addItem(quickNote.run(s));
TextItem item = new TextItem(s);
if (app.getSettingsManager().isParseTimeFromQuickNote()) item.getNotifications().addAll(App.QUICK_NOTE.run(s));
currentItemStorage.addItem(item);
}
return true;
});
Expand All @@ -180,7 +162,7 @@ public void onBackPressed() {
Runnable exit = super::onBackPressed;
Runnable def = () -> {
if (System.currentTimeMillis() - lastExitClick > 1000) {
Toast.makeText(this, "Tap 2 count to exit", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.exit_tab_2_count, Toast.LENGTH_SHORT).show();
lastExitClick = System.currentTimeMillis();
} else {
exit.run();
Expand Down Expand Up @@ -208,8 +190,10 @@ protected void onDestroy() {
if (toolbar != null) {
toolbar.destroy();
}
if (uiTickService != null) {
uiTickService.destroy();
}
currentDateHandler.removeCallbacks(currentDateRunnable);
stopService(new Intent(this, UITickService.class));
}

@Override
Expand Down Expand Up @@ -453,7 +437,7 @@ private void d(Object... objects) {
if (ALOG) Log.e("------------D", stringBuilder.toString());
}

private interface QuickNoteInterface {
Item run(String text);
public interface QuickNoteInterface {
List<ItemNotification> run(String text);
}
}
8 changes: 8 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,12 @@
<string name="toolbar_more_file_import_success">Успешно</string>
<string name="toolbar_more_file_import_hint">Вставте экспортированный текст или ссылку</string>
<string name="toolbar_more_file_import_textHint">Введите сюда текст импорта или ссылку</string>
<string name="quickNote_hint">Введите текст</string>
<string name="quickNote_add">Добавить быструю заметку</string>
<string name="toolbar_more_items_tab_rename">Переименовать</string>
<string name="toolbar_more_items_tab_add">Создать</string>
<string name="toolbar_more_items_tab_delete">Удалить</string>
<string name="abc_cancel">Отмена</string>
<string name="tab_noEmptyName">Пустое имя недопустимо</string>
<string name="exit_tab_2_count">Нажмите 2 раза что бы выйти</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,5 @@
<string name="toolbar_more_items_tab_delete">Delete</string>
<string name="abc_cancel">Cancel</string>
<string name="tab_noEmptyName">Empty name</string>
<string name="exit_tab_2_count">Tab 2 count for exit from OpenToday</string>
</resources>

0 comments on commit f8b1a8a

Please sign in to comment.