Skip to content

Commit

Permalink
Revamp User Dictionary appearance
Browse files Browse the repository at this point in the history
- add icons "library_large" for the TTSManager view for the User
  Dictionary
- rearrange activity_nor_dict_info.xml: disable buttons depending on
  current editing state, replace icons & buttons & colors and change the
  text styles
- style the norm_dict_list_view in a better way, apply colors, text styles

Signed-off-by: Daniel Schnell <[email protected]>
  • Loading branch information
lumpidu committed Mar 27, 2024
1 parent f5f1648 commit 03fd26d
Show file tree
Hide file tree
Showing 20 changed files with 227 additions and 115 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ dependencies {
testImplementation 'com.google.truth:truth:1.1.3'

// implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'org.robolectric:robolectric:4.9'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
android:configChanges="orientation"
android:parentActivityName=".TTSManager"
android:exported="true"
android:launchMode="standard"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.speech.tts.engine.INSTALL_TTS_DATA" />
Expand Down
50 changes: 39 additions & 11 deletions app/src/main/java/com/grammatek/simaromur/NormDictInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.grammatek.simaromur.cache.CacheItem;
import com.grammatek.simaromur.db.NormDictEntry;
import com.grammatek.simaromur.device.TTSAudioControl;
Expand All @@ -31,11 +31,10 @@ public class NormDictInfo extends AppCompatActivity {
private EditText mReplacementText;
private boolean mTermTextEmpty = true;
private boolean mReplacementTextEmpty = true;
private Button mDeleteButton; // TODO: make it a delete button
private FloatingActionButton mDeleteButton;
private ImageButton mPlayButton1;

private ImageButton mPlayButton2;
private Button mSaveButton;
private FloatingActionButton mSaveButton;
private NormDictViewModel mViewModel;
boolean mIsPlaying1 = false;
boolean mIsPlaying2 = false;
Expand Down Expand Up @@ -123,12 +122,24 @@ private void updateUi() {
String termText = mTermText.getText().toString();
String replacementText = mReplacementText.getText().toString();
boolean saveEnabled = !termText.isEmpty() && !replacementText.isEmpty();
if (saveEnabled && mEntry != null) {
saveEnabled = !termText.equals(mEntry.term) || !replacementText.equals(mEntry.replacement);
}
// if the texts shown in mTermText and mReplacementText are not empty, then the play buttons
// should be enabled, otherwise they should be disabled
mPlayButton1.setEnabled(!mIsPlaying1 && !mTermTextEmpty);
mPlayButton2.setEnabled(!mIsPlaying2 && !mReplacementTextEmpty);

mSaveButton.setEnabled(saveEnabled);
boolean playButton1Enabled = !mIsPlaying1 && !mTermTextEmpty;
boolean playButton2Enabled = !mIsPlaying2 && !mReplacementTextEmpty;
int playButton1Alpha = playButton1Enabled ? 0xFF : 0x3F;
int playButton2Alpha = playButton2Enabled ? 0xFF : 0x3F;
int saveButtonVisibility = saveEnabled ? View.VISIBLE : View.GONE;
int deleteButtonVisibility = mEntryId > 0 ? View.VISIBLE : View.GONE;
mPlayButton1.setEnabled(playButton1Enabled);
mPlayButton1.setImageAlpha(playButton1Alpha);
mPlayButton2.setEnabled(playButton2Enabled);
mPlayButton2.setImageAlpha(playButton2Alpha);

mSaveButton.setVisibility(saveButtonVisibility);
mDeleteButton.setVisibility(deleteButtonVisibility);

setTitle("Símarómur / " + getResources().getString(R.string.simaromur_norm_dictionary));
}
Expand Down Expand Up @@ -169,17 +180,30 @@ private void onDeleteClicked(View v) {
d.show();

}

/**
* Updates the text fields in the entry with the current text in the text fields. This
* happens only, if the text fields have been updated.
*/
private void updateText() {
if (mEntry != null) {
boolean doUpdate = !mTermText.getText().toString().equals(mEntry.term) ||
!mReplacementText.getText().toString().equals(mEntry.replacement);
if (doUpdate) {
if (anyTextUpdated()) {
mEntry.term = mTermText.getText().toString();
mEntry.replacement = mReplacementText.getText().toString();
}
}
}

/**
* Checks if any of the text fields have been updated
*
* @return true if any of the text fields have been updated, false otherwise
*/
private boolean anyTextUpdated() {
return !mTermText.getText().toString().equals(mEntry.term) ||
!mReplacementText.getText().toString().equals(mEntry.replacement);
}

private void onSaveClicked(View v) {
Log.v(LOG_TAG, "onSaveClicked");
updateText();
Expand All @@ -202,19 +226,23 @@ public void onPlayCancelClicked(View v) {
if (v.getId() == R.id.playButton1) {
if (mIsPlaying1) {
mPlayButton2.setEnabled(true);
mPlayButton2.setImageAlpha(0xFF);
mIsPlaying1 = false;
} else {
text = mTermText.getText().toString();
mPlayButton2.setEnabled(false);
mPlayButton2.setImageAlpha(0x3F);
mIsPlaying1 = true;
}
} else if (v.getId() == R.id.playButton2) {
if (mIsPlaying2) {
mPlayButton1.setEnabled(true);
mPlayButton1.setImageAlpha(0xFF);
mIsPlaying2 = false;
} else {
text = mReplacementText.getText().toString();
mPlayButton1.setEnabled(false);
mPlayButton1.setImageAlpha(0x3F);
mIsPlaying2 = true;
}
} else {
Expand Down
35 changes: 27 additions & 8 deletions app/src/main/java/com/grammatek/simaromur/NormDictListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
Expand All @@ -15,29 +14,37 @@
public class NormDictListView extends AppCompatActivity {
private final static String LOG_TAG = "Simaromur_" + NormDictListView.class.getSimpleName();
public static final String EXTRA_DATA_DICT_ID = "EXTRA_DATA_DICT_ID";
NormDictListAdapter mAdapter = null;
RecyclerView mRecyclerView;

@Override
protected void onCreate(Bundle savedInstanceState) {
Log.v(LOG_TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_norm_dict_list_view);
mRecyclerView = findViewById(R.id.normDictRecyclerview);

RecyclerView recyclerView = findViewById(R.id.normDictRecyclerview);
final NormDictListAdapter adapter = new NormDictListAdapter(this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
if (mAdapter == null) {
Log.v(LOG_TAG, "onCreate - creating new NormDictListAdapter");
mAdapter = new NormDictListAdapter(this);
mAdapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY);
}

// Get new/existing ViewModel from ViewModelProvider.
ViewModelProvider.Factory factory =
ViewModelProvider.AndroidViewModelFactory.getInstance(App.getApplication());
NormDictViewModel normDictViewModel = new ViewModelProvider(this, factory).get(NormDictViewModel.class);
normDictViewModel.getEntries().observe(this, entries -> {
Log.v(LOG_TAG, "normDictViewModel.getEntries().observe - entries: " + entries.size());
adapter.setEntries(entries);
mAdapter.setEntries(entries);
if (mRecyclerView.getAdapter() != mAdapter) {
Log.v(LOG_TAG, "normDictViewModel.getEntries().observe setting adapter");
mRecyclerView.setAdapter(mAdapter);
}
});

adapter.setOnItemClickListener((v, position) -> {
NormDictEntry entry = adapter.getEntryAtPosition(position);
mAdapter.setOnItemClickListener((v, position) -> {
NormDictEntry entry = mAdapter.getEntryAtPosition(position);
Log.v(LOG_TAG, "onItemClick - selected: " + entry.term + " - " + entry.replacement);
launchNormDictEntryActivity(entry);
});
Expand All @@ -51,6 +58,18 @@ protected void onCreate(Bundle savedInstanceState) {
setTitle("Símarómur / " + getResources().getString(R.string.simaromur_norm_dictionary));
}

@Override
public void onResume() {
super.onResume();
Log.v(LOG_TAG, "onResume");
}

@Override
public void onDestroy() {
super.onDestroy();
Log.v(LOG_TAG, "onDestroy");
}

public void launchNormDictEntryActivity(NormDictEntry entry) {
Log.v(LOG_TAG, "launchNormDictEntryActivity for entry: " + entry);
Intent intent = new Intent(this, NormDictInfo.class);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/grammatek/simaromur/TTSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public class TTSManager extends Activity implements OnItemClickListener, TextToS

static final LauncherIcon[] ICONS = {
new LauncherIcon(R.drawable.simaromur_large, R.string.simaromur_voice_manager, VoiceManager.class),
new LauncherIcon(R.drawable.ic_action_book, R.string.simaromur_norm_dictionary, NormDictListView.class),
new LauncherIcon(R.drawable.library_large, R.string.simaromur_norm_dictionary, NormDictListView.class),
new LauncherIcon(R.drawable.custom_settings_large, R.string.tts_settings_label, TTSManager.class),
new LauncherIcon(R.drawable.custom_info_large, R.string.simaromur_info, InfoViewer.class),
new LauncherIcon(R.drawable.feedback_large, R.string.simaromur_feedback, EmailFeedback.class),
new LauncherIcon(R.drawable.custom_settings_large, R.string.tts_settings_label, TTSManager.class),
};

@SuppressLint("ClickableViewAccessibility")
Expand Down
Binary file added app/src/main/res/drawable-hdpi/library.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/library.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/library_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/library.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/library_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_fluent_checkmark_48_regular.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M40.139,12.871C40.624,13.362 40.62,14.153 40.129,14.639L17.879,36.639C17.395,37.118 16.616,37.121 16.128,36.646L6.878,27.646C6.384,27.164 6.373,26.373 6.854,25.878C7.336,25.383 8.127,25.373 8.622,25.854L16.993,33.999L38.371,12.861C38.862,12.376 39.653,12.38 40.139,12.871Z"
android:fillColor="#212121"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_fluent_delete_48_regular.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M20,10.5V11H28V10.5C28,8.291 26.209,6.5 24,6.5C21.791,6.5 20,8.291 20,10.5ZM17.5,11V10.5C17.5,6.91 20.41,4 24,4C27.59,4 30.5,6.91 30.5,10.5V11H41.75C42.44,11 43,11.56 43,12.25C43,12.94 42.44,13.5 41.75,13.5H38.833L36.833,37.356C36.518,41.112 33.377,44 29.608,44H18.392C14.623,44 11.483,41.112 11.168,37.356L9.167,13.5H6.25C5.56,13.5 5,12.94 5,12.25C5,11.56 5.56,11 6.25,11H17.5ZM13.659,37.147C13.865,39.608 15.923,41.5 18.392,41.5H29.608C32.078,41.5 34.135,39.608 34.342,37.147L36.324,13.5H11.676L13.659,37.147ZM21.5,20.25C21.5,19.56 20.94,19 20.25,19C19.56,19 19,19.56 19,20.25V34.75C19,35.44 19.56,36 20.25,36C20.94,36 21.5,35.44 21.5,34.75V20.25ZM27.75,19C28.44,19 29,19.56 29,20.25V34.75C29,35.44 28.44,36 27.75,36C27.06,36 26.5,35.44 26.5,34.75V20.25C26.5,19.56 27.06,19 27.75,19Z"
android:fillColor="#212121"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M18,16.75C18,16.06 18.56,15.5 19.25,15.5C19.94,15.5 20.5,16.06 20.5,16.75V31.25C20.5,31.94 19.94,32.5 19.25,32.5C18.56,32.5 18,31.94 18,31.25V16.75ZM28.75,15.5C28.06,15.5 27.5,16.06 27.5,16.75V31.25C27.5,31.94 28.06,32.5 28.75,32.5C29.44,32.5 30,31.94 30,31.25V16.75C30,16.06 29.44,15.5 28.75,15.5ZM24,4C35.046,4 44,12.954 44,24C44,35.046 35.046,44 24,44C12.954,44 4,35.046 4,24C4,12.954 12.954,4 24,4ZM24,6.5C14.335,6.5 6.5,14.335 6.5,24C6.5,33.665 14.335,41.5 24,41.5C33.665,41.5 41.5,33.665 41.5,24C41.5,14.335 33.665,6.5 24,6.5Z"
android:fillColor="#212121"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M33.765,22.713L21.404,15.325C19.904,14.429 18,15.51 18,17.257V30.744C18,32.491 19.904,33.572 21.404,32.675L33.765,25.288C34.739,24.706 34.739,23.295 33.765,22.713ZM24,44C35.046,44 44,35.046 44,24C44,12.954 35.046,4 24,4C12.954,4 4,12.954 4,24C4,35.046 12.954,44 24,44ZM24,6.5C33.665,6.5 41.5,14.335 41.5,24C41.5,33.665 33.665,41.5 24,41.5C14.335,41.5 6.5,33.665 6.5,24C6.5,14.335 14.335,6.5 24,6.5Z"
android:fillColor="#212121"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/play_drawable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:drawable="@android:drawable/ic_media_pause"
android:drawable="@drawable/ic_fluent_pause_circle_48_regular"
app:state_playing="true" />
<item
android:drawable="@android:drawable/ic_media_play"
android:drawable="@drawable/ic_fluent_play_circle_48_regular"
app:state_stopped="true" />
</selector>
Loading

0 comments on commit 03fd26d

Please sign in to comment.