diff --git a/app/src/main/java/me/tsukanov/counter/activities/MainActivity.java b/app/src/main/java/me/tsukanov/counter/activities/MainActivity.java
index 34308741..84dd8334 100644
--- a/app/src/main/java/me/tsukanov/counter/activities/MainActivity.java
+++ b/app/src/main/java/me/tsukanov/counter/activities/MainActivity.java
@@ -6,23 +6,21 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
-import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.FrameLayout;
+
import androidx.annotation.NonNull;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.PreferenceManager;
+import com.google.android.material.appbar.MaterialToolbar;
import me.tsukanov.counter.CounterApplication;
import me.tsukanov.counter.R;
import me.tsukanov.counter.SharedPrefKeys;
@@ -39,9 +37,8 @@ public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
- private ActionBar actionBar;
+ private MaterialToolbar toolbar;
private DrawerLayout navigationLayout;
- private ActionBarDrawerToggle navigationToggle;
private SharedPreferences sharedPrefs;
private FrameLayout menuFrame;
private String selectedCounterName;
@@ -50,23 +47,20 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onCreate(final Bundle savedInstanceState) {
- actionBar = getSupportActionBar();
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
registerIntentReceivers(getApplicationContext());
super.onCreate(savedInstanceState);
- // Enable ActionBar home button to behave as action to toggle navigation drawer
- actionBar.setDisplayHomeAsUpEnabled(true);
- actionBar.setHomeButtonEnabled(true);
+ setContentView(R.layout.layout_main);
- setContentView(R.layout.drawer_layout);
+ toolbar = findViewById(R.id.mainToolbar);
+ setSupportActionBar(toolbar);
- navigationLayout = findViewById(R.id.drawer_layout);
- navigationToggle = generateActionBarToggle(this.actionBar, navigationLayout);
- navigationLayout.addDrawerListener(navigationToggle);
+ toolbar.setNavigationOnClickListener(view -> openDrawer());
- menuFrame = findViewById(R.id.menu_frame);
+ navigationLayout = findViewById(R.id.mainNavigationLayout);
+ menuFrame = findViewById(R.id.mainMenuFrame);
}
private void registerIntentReceivers(@NonNull final Context context) {
@@ -77,25 +71,7 @@ private void registerIntentReceivers(@NonNull final Context context) {
context,
new CounterChangeReceiver(),
counterSelectionFilter,
- ContextCompat.RECEIVER_NOT_EXPORTED);
- }
-
- private ActionBarDrawerToggle generateActionBarToggle(
- @NonNull final ActionBar actionBar, @NonNull final DrawerLayout drawerLayout) {
-
- return new ActionBarDrawerToggle(
- this, drawerLayout, null, R.string.drawer_open, R.string.drawer_close) {
-
- public void onDrawerClosed(View view) {
- actionBar.setTitle(selectedCounterName);
- supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
- }
-
- public void onDrawerOpened(View drawerView) {
- actionBar.setTitle(getTitle());
- supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
- }
- };
+ ContextCompat.RECEIVER_EXPORTED);
}
@Override
@@ -116,7 +92,7 @@ protected void onResume() {
private void initCountersList() {
final FragmentTransaction transaction = this.getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.menu_frame, new CountersListFragment());
+ transaction.replace(R.id.mainMenuFrame, new CountersListFragment());
transaction.commit();
}
@@ -130,14 +106,14 @@ private void switchCounter(@NonNull final String counterName) {
selectedCounterFragment.setArguments(bundle);
getSupportFragmentManager()
.beginTransaction()
- .replace(R.id.content_frame, selectedCounterFragment)
+ .replace(R.id.mainContentFrame, selectedCounterFragment)
.commitAllowingStateLoss();
- actionBar.setTitle(counterName);
+ toolbar.setTitle(counterName);
- if (isNavigationOpen()) {
- closeNavigation();
- }
+ if (isNavigationOpen()) {
+ closeNavigation();
+ }
}
/**
@@ -179,12 +155,6 @@ public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
- navigationToggle.syncState();
- }
-
@SuppressLint("ApplySharedPref")
@Override
protected void onPause() {
@@ -195,43 +165,36 @@ protected void onPause() {
prefsEditor.commit();
}
- @Override
- public void onConfigurationChanged(@NonNull final Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- navigationToggle.onConfigurationChanged(newConfig);
- }
-
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- if (isNavigationOpen()) {
- closeNavigation();
- } else {
- openDrawer();
- }
- return true;
-
- case R.id.menu_settings:
- startActivity(new Intent(this, SettingsActivity.class));
- return true;
-
- default:
- return super.onOptionsItemSelected(item);
+ return switch (item.getItemId()) {
+ case android.R.id.home -> {
+ if (isNavigationOpen()) {
+ closeNavigation();
+ } else {
+ openDrawer();
+ }
+ yield true;
+ }
+ case R.id.menu_settings -> {
+ startActivity(new Intent(this, SettingsActivity.class));
+ yield true;
+ }
+ default -> super.onOptionsItemSelected(item);
+ };
+ }
+
+ public boolean isNavigationOpen() {
+ return navigationLayout.isDrawerOpen(menuFrame);
}
- }
-
- public boolean isNavigationOpen() {
- return navigationLayout.isDrawerOpen(menuFrame);
- }
- private void closeNavigation() {
- navigationLayout.closeDrawer(menuFrame);
- }
+ private void closeNavigation() {
+ navigationLayout.closeDrawer(menuFrame);
+ }
- private void openDrawer() {
- navigationLayout.openDrawer(menuFrame);
- }
+ private void openDrawer() {
+ navigationLayout.openDrawer(menuFrame);
+ }
private class CounterChangeReceiver extends BroadcastReceiver {
diff --git a/app/src/main/java/me/tsukanov/counter/activities/SettingsActivity.java b/app/src/main/java/me/tsukanov/counter/activities/SettingsActivity.java
index 3ed6f6bb..c8f60b2d 100644
--- a/app/src/main/java/me/tsukanov/counter/activities/SettingsActivity.java
+++ b/app/src/main/java/me/tsukanov/counter/activities/SettingsActivity.java
@@ -15,6 +15,9 @@
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.Preference.OnPreferenceClickListener;
import androidx.preference.PreferenceManager;
+
+import com.google.android.material.appbar.MaterialToolbar;
+
import java.io.IOException;
import me.tsukanov.counter.CounterApplication;
import me.tsukanov.counter.R;
@@ -40,6 +43,11 @@ public class SettingsActivity extends AppCompatActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ setContentView(R.layout.layout_settings);
+
+ MaterialToolbar actionBar = findViewById(R.id.settingsToolbar);
+ setSupportActionBar(actionBar);
+
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Themes.initCurrentTheme(sharedPrefs);
@@ -57,7 +65,7 @@ private void initSettingsFragment() {
getSupportFragmentManager()
.beginTransaction()
- .replace(android.R.id.content, settingsFragment)
+ .replace(R.id.settingsFrame, settingsFragment)
.commit();
}
@@ -109,7 +117,7 @@ private OnPreferenceClickListener getOnTipClickListener() {
protected void onPostCreate(final Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getDelegate().onPostCreate(savedInstanceState);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
diff --git a/app/src/main/java/me/tsukanov/counter/infrastructure/Actions.java b/app/src/main/java/me/tsukanov/counter/infrastructure/Actions.java
index f4625a15..2ab0c16a 100644
--- a/app/src/main/java/me/tsukanov/counter/infrastructure/Actions.java
+++ b/app/src/main/java/me/tsukanov/counter/infrastructure/Actions.java
@@ -9,6 +9,6 @@ public enum Actions {
@NonNull
public String getActionName() {
- return String.format("%s.%s", CounterApplication.PACKAGE_NAME, this.toString());
+ return String.format("%s.%s", CounterApplication.PACKAGE_NAME, this);
}
}
diff --git a/app/src/main/java/me/tsukanov/counter/view/CounterFragment.java b/app/src/main/java/me/tsukanov/counter/view/CounterFragment.java
index f3405af4..4b3f271d 100644
--- a/app/src/main/java/me/tsukanov/counter/view/CounterFragment.java
+++ b/app/src/main/java/me/tsukanov/counter/view/CounterFragment.java
@@ -17,22 +17,24 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
-import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;
+import java.util.Locale;
+import java.util.Map;
import java.util.Objects;
import me.tsukanov.counter.CounterApplication;
import me.tsukanov.counter.R;
import me.tsukanov.counter.SharedPrefKeys;
-import me.tsukanov.counter.activities.MainActivity;
import me.tsukanov.counter.domain.IntegerCounter;
import me.tsukanov.counter.repository.CounterStorage;
import me.tsukanov.counter.repository.exceptions.MissingCounterException;
import me.tsukanov.counter.view.dialogs.DeleteDialog;
import me.tsukanov.counter.view.dialogs.EditDialog;
+import org.apache.commons.text.StringSubstitutor;
+import org.joda.time.format.DateTimeFormat;
public class CounterFragment extends Fragment {
@@ -50,8 +52,9 @@ public class CounterFragment extends Fragment {
private SharedPreferences sharedPrefs;
private Vibrator vibrator;
- private FrameLayout counterFrame;
+
private TextView counterLabel;
+ private TextView updateTimestampLabel;
private Button incrementButton;
private Button decrementButton;
@@ -133,14 +136,15 @@ public View onCreateView(
decrementButton.setOnClickListener(v -> decrement());
counterLabel = view.findViewById(R.id.counterLabel);
+ updateTimestampLabel = view.findViewById(R.id.updateTimestampLabel);
- counterFrame = view.findViewById(R.id.counterFrame);
- counterFrame.setOnClickListener(
- v -> {
- if (sharedPrefs.getBoolean(SharedPrefKeys.LABEL_CONTROL_ON.getName(), true)) {
- increment();
- }
- });
+ view.findViewById(R.id.counterFrame)
+ .setOnClickListener(
+ v -> {
+ if (sharedPrefs.getBoolean(SharedPrefKeys.LABEL_CONTROL_ON.getName(), true)) {
+ increment();
+ }
+ });
updateInterface();
@@ -152,20 +156,6 @@ public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInf
inflater.inflate(R.menu.counter_menu, menu);
}
- @Override
- public void onPrepareOptionsMenu(@NonNull final Menu menu) {
- boolean isDrawerOpen = ((MainActivity) requireActivity()).isNavigationOpen();
-
- MenuItem editItem = menu.findItem(R.id.menu_edit);
- editItem.setVisible(!isDrawerOpen);
-
- MenuItem deleteItem = menu.findItem(R.id.menu_delete);
- deleteItem.setVisible(!isDrawerOpen);
-
- MenuItem resetItem = menu.findItem(R.id.menu_reset);
- resetItem.setVisible(!isDrawerOpen);
- }
-
public boolean onKeyDown(int keyCode) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
@@ -264,6 +254,20 @@ private void reset() {
private void updateInterface() {
counterLabel.setText(Integer.toString(counter.getValue()));
+ if (counter.getLastUpdatedDate() != null) {
+ final String formattedTimestamp =
+ counter
+ .getLastUpdatedDate()
+ .toString(
+ DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withLocale(Locale.getDefault()));
+ updateTimestampLabel.setText(
+ StringSubstitutor.replace(
+ getResources().getText(R.string.last_update_timestamp),
+ Map.of("timestamp", formattedTimestamp),
+ "{",
+ "}"));
+ }
+
incrementButton.setEnabled(counter.getValue() < IntegerCounter.MAX_VALUE);
decrementButton.setEnabled(counter.getValue() > IntegerCounter.MIN_VALUE);
}
diff --git a/app/src/main/java/me/tsukanov/counter/view/CountersListFragment.java b/app/src/main/java/me/tsukanov/counter/view/CountersListFragment.java
index 8444dd36..df1b1ea0 100644
--- a/app/src/main/java/me/tsukanov/counter/view/CountersListFragment.java
+++ b/app/src/main/java/me/tsukanov/counter/view/CountersListFragment.java
@@ -58,7 +58,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
requireActivity().getApplication(),
new UpdateReceiver(),
counterSetChangeFilter,
- ContextCompat.RECEIVER_NOT_EXPORTED);
+ ContextCompat.RECEIVER_EXPORTED);
}
@Override
diff --git a/app/src/main/res/drawable/ic_back.xml b/app/src/main/res/drawable/ic_back.xml
new file mode 100644
index 00000000..77191eaa
--- /dev/null
+++ b/app/src/main/res/drawable/ic_back.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_menu.xml b/app/src/main/res/drawable/ic_menu.xml
new file mode 100644
index 00000000..24ccd115
--- /dev/null
+++ b/app/src/main/res/drawable/ic_menu.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_phone_android.xml b/app/src/main/res/drawable/ic_phone.xml
similarity index 100%
rename from app/src/main/res/drawable/ic_phone_android.xml
rename to app/src/main/res/drawable/ic_phone.xml
diff --git a/app/src/main/res/drawable/ic_exposure_plus_1.xml b/app/src/main/res/drawable/ic_plus_one.xml
similarity index 100%
rename from app/src/main/res/drawable/ic_exposure_plus_1.xml
rename to app/src/main/res/drawable/ic_plus_one.xml
diff --git a/app/src/main/res/drawable/ic_volume_up.xml b/app/src/main/res/drawable/ic_volume.xml
similarity index 100%
rename from app/src/main/res/drawable/ic_volume_up.xml
rename to app/src/main/res/drawable/ic_volume.xml
diff --git a/app/src/main/res/layout-land/counter.xml b/app/src/main/res/layout-land/counter.xml
index 09705a97..67bf6ba9 100644
--- a/app/src/main/res/layout-land/counter.xml
+++ b/app/src/main/res/layout-land/counter.xml
@@ -1,56 +1,78 @@
-
-
+ android:layout_marginLeft="16dp"
+ android:layout_marginTop="56dp"
+ android:layout_marginRight="16dp"
+ android:layout_marginBottom="16dp"
+ android:orientation="horizontal">
-
-
+ android:layout_weight="0.91"
+ android:orientation="vertical">
+
+
+
+
+
+
+
+
+
+
+ android:layout_width="150dp"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ android:id="@+id/incrementButton"
+ style="@style/increment_button"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_weight="0.65"
+ android:text="@string/plus" />
+ android:id="@+id/decrementButton"
+ style="@style/decrement_button"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:text="@string/minus" />
diff --git a/app/src/main/res/layout-xlarge-land/counter.xml b/app/src/main/res/layout-xlarge-land/counter.xml
deleted file mode 100644
index b7e79d77..00000000
--- a/app/src/main/res/layout-xlarge-land/counter.xml
+++ /dev/null
@@ -1,51 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/app/src/main/res/layout-xlarge/counter.xml b/app/src/main/res/layout-xlarge/counter.xml
deleted file mode 100644
index 5cea271b..00000000
--- a/app/src/main/res/layout-xlarge/counter.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/app/src/main/res/layout/counter.xml b/app/src/main/res/layout/counter.xml
index 1bf982f8..48cbeee9 100644
--- a/app/src/main/res/layout/counter.xml
+++ b/app/src/main/res/layout/counter.xml
@@ -1,56 +1,70 @@
-
-
-
-
+ android:layout_height="match_parent"
+ android:layout_marginLeft="16dp"
+ android:layout_marginTop="56dp"
+ android:layout_marginRight="16dp"
+ android:layout_marginBottom="16dp"
+ android:orientation="vertical">
+ android:id="@+id/counterFrame"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_above="@+id/incrementButton"
+ android:layout_alignParentStart="true"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentEnd="true">
+
+
+
+
+
+
+
+
-
diff --git a/app/src/main/res/layout/dialog_edit.xml b/app/src/main/res/layout/dialog_edit.xml
index 9af33666..cdd99875 100644
--- a/app/src/main/res/layout/dialog_edit.xml
+++ b/app/src/main/res/layout/dialog_edit.xml
@@ -1,46 +1,48 @@
-
-
-
-
+ android:layout_height="match_parent">
-
+ android:orientation="vertical"
+ android:padding="@dimen/dialog_layout_padding">
-
+
-
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/drawer_layout.xml b/app/src/main/res/layout/drawer_layout.xml
deleted file mode 100644
index acc3c818..00000000
--- a/app/src/main/res/layout/drawer_layout.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
diff --git a/app/src/main/res/layout/layout_main.xml b/app/src/main/res/layout/layout_main.xml
new file mode 100644
index 00000000..449b58f8
--- /dev/null
+++ b/app/src/main/res/layout/layout_main.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/layout_settings.xml b/app/src/main/res/layout/layout_settings.xml
new file mode 100644
index 00000000..8c99b63c
--- /dev/null
+++ b/app/src/main/res/layout/layout_settings.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/menu.xml b/app/src/main/res/layout/menu.xml
index 62245bb3..b2f29327 100644
--- a/app/src/main/res/layout/menu.xml
+++ b/app/src/main/res/layout/menu.xml
@@ -1,50 +1,49 @@
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ android:id="@+id/add_counter"
+ android:layout_width="match_parent"
+ android:layout_height="50dp"
+ android:layout_marginTop="10dp"
+ android:background="?attr/selectableItemBackground"
+ android:orientation="horizontal"
+ android:padding="10dp"
+ android:layout_marginBottom="10dp"
+ android:theme="@style/DrawerSelectTheme">
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:contentDescription="@string/menu_add"
+ android:src="?drawableAdd" />
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:gravity="center_vertical"
+ android:paddingStart="10dp"
+ android:paddingEnd="0dp"
+ android:text="@string/menu_add"
+ android:textAppearance="@android:style/TextAppearance.Medium"
+ android:textStyle="bold" />
+ android:id="@android:id/list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:choiceMode="singleChoice"
+ android:divider="@android:color/transparent"
+ android:dividerHeight="0dp"
+ android:listSelector="?attr/selectableItemBackground"
+ android:scrollbarAlwaysDrawVerticalTrack="true"
+ android:scrollbarThumbVertical="@drawable/menu_scrollbar"
+ android:scrollbars="vertical"
+ android:layout_marginBottom="40dp"
+ android:theme="@style/DrawerSelectTheme" />
diff --git a/app/src/main/res/layout/menu_row.xml b/app/src/main/res/layout/menu_row.xml
index 433968c9..039fd3f7 100644
--- a/app/src/main/res/layout/menu_row.xml
+++ b/app/src/main/res/layout/menu_row.xml
@@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:background="#000"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="16dp">
@@ -14,7 +13,6 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="@android:style/TextAppearance.Medium"
- android:textColor="#fff"
tools:text="Sample counter" />
diff --git a/app/src/main/res/menu/counter_menu.xml b/app/src/main/res/menu/counter_menu.xml
index 53cbd915..3ef4557d 100644
--- a/app/src/main/res/menu/counter_menu.xml
+++ b/app/src/main/res/menu/counter_menu.xml
@@ -7,7 +7,6 @@
android:icon="?drawableEdit"
android:orderInCategory="2"
android:title="@string/menu_edit"
- app:iconTint="?android:attr/textColorPrimary"
app:showAsAction="ifRoom" />
diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml
index e5fa5a3d..4663ad2d 100755
--- a/app/src/main/res/values-night/themes.xml
+++ b/app/src/main/res/values-night/themes.xml
@@ -1,6 +1,6 @@
-