Skip to content

Commit

Permalink
Merge pull request #4 from elimu-ai/#1-Fetch-letters-from-the-Content…
Browse files Browse the repository at this point in the history
…-Provider

#1 fetch letters from the content provider
  • Loading branch information
nya-elimu authored Jul 4, 2020
2 parents fc83121 + 9c864eb commit 6b7b2f6
Show file tree
Hide file tree
Showing 27 changed files with 225 additions and 279 deletions.
4 changes: 1 addition & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.google.android:flexbox:2.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
package="ai.elimu.herufi">

<application
android:name=".BaseApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name=".MainActivity"
android:label="@string/app_name">
Expand All @@ -18,5 +20,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".ui.LetterListActivity" />
</application>
</manifest>
42 changes: 42 additions & 0 deletions app/src/main/java/ai/elimu/herufi/BaseApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ai.elimu.herufi;

import android.app.Application;
import android.speech.tts.TextToSpeech;
import android.util.Log;

public class BaseApplication extends Application {

private TextToSpeech tts;

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

// Initialize Text-to-Speech
getTTS();
}

public TextToSpeech getTTS() {
if (tts == null) {
tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
Log.i(getClass().getName(), "TextToSpeech onInit");
}
});
}
return tts;
}

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

// Release the resources used by the TextToSpeech engine
if (tts != null) {
tts.shutdown();
}
}
}
23 changes: 6 additions & 17 deletions app/src/main/java/ai/elimu/herufi/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package ai.elimu.herufi;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.google.android.material.bottomnavigation.BottomNavigationView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import ai.elimu.herufi.ui.LetterListActivity;

public class MainActivity extends AppCompatActivity {

Expand All @@ -22,23 +19,15 @@ protected void onCreate(Bundle savedInstanceState) {

// Verify that the content-provider APK has been installed
// TODO

BottomNavigationView navView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_home, R.id.navigation_notifications)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);
}

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


Intent intent = new Intent(getApplicationContext(), LetterListActivity.class);
startActivity(intent);
finish();
}
}
69 changes: 69 additions & 0 deletions app/src/main/java/ai/elimu/herufi/ui/LetterListActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.flexbox.FlexboxLayout;

import java.util.List;

import ai.elimu.herufi.BaseApplication;
import ai.elimu.herufi.R;
import ai.elimu.herufi.util.ContentProviderHelper;
import ai.elimu.model.v2.gson.content.LetterGson;

public class LetterListActivity extends AppCompatActivity {

private FlexboxLayout flexboxLayout;

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

setContentView(R.layout.activity_letter_list);

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

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

List<LetterGson> letterGsons = ContentProviderHelper.getLetterGsons(getApplicationContext());
Log.i(getClass().getName(), "letterGsons.size(): " + letterGsons.size());

// Create a view for each letter in the list
flexboxLayout.removeAllViews();
for (final LetterGson letterGson : letterGsons) {
View letterView = LayoutInflater.from(this).inflate(R.layout.activity_letter_list_letter_view, flexboxLayout, false);

TextView textView = letterView.findViewById(R.id.letter_view_text_view);
textView.setText(letterGson.getText());

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

Log.i(getClass().getName(), "letterGson.getText(): '" + letterGson.getText() + "'");

BaseApplication baseApplication = (BaseApplication) getApplication();
TextToSpeech tts = baseApplication.getTTS();
tts.speak(letterGson.getText(), TextToSpeech.QUEUE_FLUSH, null, "letter_" + letterGson.getId());
}
});

flexboxLayout.addView(letterView);
}
}
}
49 changes: 0 additions & 49 deletions app/src/main/java/ai/elimu/herufi/ui/home/HomeFragment.java

This file was deleted.

19 changes: 0 additions & 19 deletions app/src/main/java/ai/elimu/herufi/ui/home/HomeViewModel.java

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 11 additions & 0 deletions app/src/main/res/drawable/gradient_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<gradient
android:angle="135"
android:endColor="@color/green_darken_2"
android:centerColor="@color/green"
android:startColor="@color/green_lighten_2"
android:type="linear" />
</shape>
9 changes: 0 additions & 9 deletions app/src/main/res/drawable/ic_home_black_24dp.xml

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/res/drawable/ic_notifications_black_24dp.xml

This file was deleted.

22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_letter_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_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_list_letter_view" />
</com.google.android.flexbox.FlexboxLayout>
</ScrollView>
Loading

0 comments on commit 6b7b2f6

Please sign in to comment.