diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/MainActivity.java b/app/src/main/java/dummydomain/yetanothercallblocker/MainActivity.java index 5dd8586..6977773 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/MainActivity.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/MainActivity.java @@ -14,7 +14,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.SwitchCompat; import androidx.recyclerview.widget.RecyclerView; import org.greenrobot.eventbus.EventBus; @@ -36,6 +35,8 @@ public class MainActivity extends AppCompatActivity { private final Settings settings = App.getSettings(); + private final UpdateScheduler updateScheduler = UpdateScheduler.get(App.getInstance()); + private CallLogItemRecyclerViewAdapter callLogAdapter; private List callLogItems = new ArrayList<>(); @@ -50,28 +51,6 @@ public class MainActivity extends AppCompatActivity { callLogAdapter = new CallLogItemRecyclerViewAdapter(callLogItems, this::onCallLogItemClicked); RecyclerView recyclerView = findViewById(R.id.callLogList); recyclerView.setAdapter(callLogAdapter); - - SwitchCompat notificationsSwitch = findViewById(R.id.notificationsEnabledSwitch); - notificationsSwitch.setChecked(settings.getIncomingCallNotifications()); - notificationsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { - settings.setIncomingCallNotifications(isChecked); - checkPermissions(); - }); - - SwitchCompat blockCallsSwitch = findViewById(R.id.blockCallsSwitch); - blockCallsSwitch.setChecked(settings.getBlockCalls()); - blockCallsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { - settings.setBlockCalls(isChecked); - checkPermissions(); - }); - - UpdateScheduler updateScheduler = UpdateScheduler.get(this); - SwitchCompat autoUpdateSwitch = findViewById(R.id.autoUpdateEnabledSwitch); - autoUpdateSwitch.setChecked(updateScheduler.isAutoUpdateScheduled()); - autoUpdateSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { - if (isChecked) updateScheduler.scheduleAutoUpdates(); - else updateScheduler.cancelAutoUpdateWorker(); - }); } @Override @@ -80,6 +59,20 @@ public class MainActivity extends AppCompatActivity { return true; } + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + menu.findItem(R.id.menu_show_notifications).setChecked( + settings.getIncomingCallNotifications()); + + menu.findItem(R.id.menu_block_calls).setChecked( + settings.getBlockCalls()); + + menu.findItem(R.id.menu_auto_updates).setChecked( + updateScheduler.isAutoUpdateScheduled()); + + return super.onPrepareOptionsMenu(menu); + } + @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { @@ -175,6 +168,21 @@ public class MainActivity extends AppCompatActivity { TaskService.start(this, TaskService.TASK_DOWNLOAD_MAIN_DB); } + public void onShowNotificationsChanged(MenuItem item) { + settings.setIncomingCallNotifications(!item.isChecked()); + checkPermissions(); + } + + public void onBlockCallsChanged(MenuItem item) { + settings.setBlockCalls(!item.isChecked()); + checkPermissions(); + } + + public void onAutoUpdatesChanged(MenuItem item) { + if (!item.isChecked()) updateScheduler.scheduleAutoUpdates(); + else updateScheduler.cancelAutoUpdateWorker(); + } + public void onOpenDebugActivity(MenuItem item) { startActivity(new Intent(this, DebugActivity.class)); } @@ -218,7 +226,7 @@ public class MainActivity extends AppCompatActivity { = new AsyncTask>() { @Override protected List doInBackground(Void... voids) { - List items = CallLogHelper.getRecentCalls(MainActivity.this, 10); + List items = CallLogHelper.getRecentCalls(MainActivity.this, 20); for (CallLogItem item : items) { item.numberInfo = DatabaseSingleton.getCommunityDatabase().isOperational() @@ -249,6 +257,9 @@ public class MainActivity extends AppCompatActivity { } private void setCallLogVisibility(boolean visible) { + findViewById(R.id.callLogPermissionMessage) + .setVisibility(visible ? View.GONE : View.VISIBLE); + int visibility = visible ? View.VISIBLE : View.GONE; findViewById(R.id.callLogTitle).setVisibility(visibility); findViewById(R.id.callLogList).setVisibility(visibility); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 7be3b0a..9a5dc7f 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -8,48 +8,16 @@ tools:context=".MainActivity"> - - - - - - - - - + android:text="@string/call_log_permission_message" + android:textAlignment="textStart" + android:visibility="gone" /> + + + + + + diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 9134e2c..e76c9e9 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -21,7 +21,7 @@ Робот/автомат Некоммерческая орг-я Блокировать нежелательные вызовы - Авто-обновление баз номеров + Авто-обновление баз номеров Открыть экран отладки Отладка Искать в общей базе @@ -30,10 +30,9 @@ Обновить базы Не найдено Обновление завершено. Версия: %d - Отображать уведомление при входящих + Отображать уведомление при входящих Отзывы Загружаем отзывы… - Основные настройки Факс Злонамеренный Нежелательный diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c34e461..3753da5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -54,7 +54,7 @@ Notification functionality may not work due to denied permissions Blocking functionality may not work due to denied permissions - General settings + Grant \"Phone\" permission to see recent calls Download main database Database is not present! For the app to perform most of its functions you need to download DB. It will take around 25 MB of traffic. @@ -68,9 +68,9 @@ Back No - Incoming call notifications enabled + Incoming call notifications Block unwanted calls - Auto-update enabled + Auto-update database Open debug screen Debug