Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch sound-letter correspondences from Content Provider #23

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])

implementation 'com.github.elimu-ai:model:model-2.0.66' // See https://jitpack.io/#elimu-ai/model
implementation 'com.github.elimu-ai:content-provider:1.2.25@aar' // See https://jitpack.io/#elimu-ai/content-provider
implementation 'com.github.elimu-ai:content-provider:1.2.26@aar' // See https://jitpack.io/#elimu-ai/content-provider
implementation 'com.github.elimu-ai:analytics:3.1.11@aar' // See https://jitpack.io/#elimu-ai/analytics

implementation 'androidx.appcompat:appcompat:1.6.1'
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</intent-filter>
</activity>

<activity
android:name=".ui.LetterListActivity" />
<activity android:name=".ui.LetterListActivity" />
<activity android:name=".ui.LetterSoundListActivity" />
</application>
</manifest>
4 changes: 3 additions & 1 deletion app/src/main/java/ai/elimu/herufi/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import androidx.appcompat.app.AppCompatActivity;

import ai.elimu.herufi.ui.LetterListActivity;
import ai.elimu.herufi.ui.LetterSoundListActivity;

public class MainActivity extends AppCompatActivity {

Expand All @@ -26,7 +27,8 @@ protected void onStart() {
Log.i(getClass().getName(), "onStart");
super.onStart();

Intent intent = new Intent(getApplicationContext(), LetterListActivity.class);
// Intent intent = new Intent(getApplicationContext(), LetterListActivity.class);
Intent intent = new Intent(getApplicationContext(), LetterSoundListActivity.class);
startActivity(intent);
finish();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package ai.elimu.herufi.ui;

import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.flexbox.FlexboxLayout;

import java.util.List;

import ai.elimu.content_provider.utils.ContentProviderUtil;
import ai.elimu.herufi.BaseApplication;
import ai.elimu.herufi.BuildConfig;
import ai.elimu.herufi.R;
import ai.elimu.model.v2.gson.content.LetterSoundGson;

public class LetterSoundListActivity extends AppCompatActivity {

private FlexboxLayout flexboxLayout;

@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(getClass().getName(), "onCreate");
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_letter_sound_list);

flexboxLayout = findViewById(R.id.letter_sound_list_flexbox_layout);
}

@Override
protected void onStart() {
Log.i(getClass().getName(), "onStart");
super.onStart();

List<LetterSoundGson> letterSoundGsons = ContentProviderUtil.getAllLetterSoundGsons(getApplicationContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
Log.i(getClass().getName(), "letterSoundGsons.size(): " + letterSoundGsons.size());

// Create a view for each letter-sound correspondence in the list
flexboxLayout.removeAllViews();
for (final LetterSoundGson letterSoundGson : letterSoundGsons) {
View letterSoundView = LayoutInflater.from(this).inflate(R.layout.activity_letter_sound_list_letter_view, flexboxLayout, false);

TextView textView = letterSoundView.findViewById(R.id.letter_sound_view_text_view);
textView.setText("id " + letterSoundGson.getId());

// Play sound when pressed
letterSoundView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(getClass().getName(), "letterView onClick");

Log.i(getClass().getName(), "letterSoundGson.getId(): '" + letterSoundGson.getId() + "'");

BaseApplication baseApplication = (BaseApplication) getApplication();
TextToSpeech tts = baseApplication.getTTS();
// tts.speak(letterSoundGson.getText(), TextToSpeech.QUEUE_FLUSH, null, "letter_sound_" + letterSoundGson.getId());

// Report learning event to the Analytics application (https://github.com/elimu-ai/analytics)
// LearningEventUtil.reportLetterSoundLearningEvent(letterSoundGson, LearningEventType.LETTER_SOUND_PRESSED, getApplicationContext(), BuildConfig.ANALYTICS_APPLICATION_ID);
}
});

flexboxLayout.addView(letterSoundView);
}
}
}
22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_letter_sound_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient_background">

<com.google.android.flexbox.FlexboxLayout
android:id="@+id/letter_sound_list_flexbox_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:flexWrap="wrap"
app:justifyContent="center">

<include layout="@layout/activity_letter_sound_list_letter_view" />
</com.google.android.flexbox.FlexboxLayout>
</ScrollView>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="164dp"
android:layout_height="219dp"
android:layout_margin="8dp"
app:cardCornerRadius="16dp"
app:cardBackgroundColor="#F2FFFFFF"
android:foreground="?android:attr/selectableItemBackground">

<TextView
android:id="@+id/letter_sound_view_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="96sp"
android:text="क" />
</androidx.cardview.widget.CardView>
Loading