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

Add thesaurus module and functionality #45

Merged
merged 16 commits into from
Dec 3, 2019
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
7 changes: 3 additions & 4 deletions about/src/main/res/layout/fragment_about.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<space.narrate.waylan.android.ui.widget.ScrimmedFrameLayout
<space.narrate.waylan.core.ui.widget.ScrimWindowLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/scrim_frame"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="?attr/colorScrim">
android:layout_width="match_parent">

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -96,4 +95,4 @@

</androidx.coordinatorlayout.widget.CoordinatorLayout>

</space.narrate.waylan.android.ui.widget.ScrimmedFrameLayout>
</space.narrate.waylan.core.ui.widget.ScrimWindowLayout>
7 changes: 3 additions & 4 deletions about/src/main/res/layout/fragment_third_party_libraries.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<space.narrate.waylan.android.ui.widget.ScrimmedFrameLayout
<space.narrate.waylan.core.ui.widget.ScrimWindowLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/scrim_frame"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="?attr/colorScrim">
android:layout_width="match_parent">

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
Expand Down Expand Up @@ -67,4 +66,4 @@

</androidx.coordinatorlayout.widget.CoordinatorLayout>

</space.narrate.waylan.android.ui.widget.ScrimmedFrameLayout>
</space.narrate.waylan.core.ui.widget.ScrimWindowLayout>
26 changes: 13 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ android {
}

// Dynamic feature modules
dynamicFeatures = [":about", ":merriamwebster"]
dynamicFeatures = [":about", ":merriamwebster", ":merriamwebster_thesaurus"]

// Compile options
compileOptions {
Expand All @@ -63,18 +63,18 @@ android {
lintOptions {
checkReleaseBuilds false
}

// Testing
// Add shared test dir to be used by both unit and instrumented tests
sourceSets {
String sharedTestDir = 'src/sharedTest/java'
test {
java.srcDir sharedTestDir
}
androidTest {
java.srcDir sharedTestDir
}
}
//
// // Testing
// // Add shared test dir to be used by both unit and instrumented tests
// sourceSets {
// String sharedTestDir = 'src/sharedTest/java'
// test {
// java.srcDir sharedTestDir
// }
// androidTest {
// java.srcDir sharedTestDir
// }
// }

// Include Android resources for robolectric unit testing.
testOptions {
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="com.android.vending.BILLING" />


<application
android:name=".App"
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/Theme.Words.DayNight"
android:theme="@style/Theme.Waylan.DayNight"
tools:ignore="GoogleAppIndexingWarning">

<activity android:name=".ui.auth.AuthActivity">
Expand Down
17 changes: 16 additions & 1 deletion app/src/main/java/space/narrate/waylan/android/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,33 +93,48 @@ val appModule = module {
).newInstance() as DetailProviderFactory
}

// Details
single(named("merriamWebsterThesaurusDetailDataProviderFactory")) {
Class.forName(
"space.narrate.waylan.merriamwebster_thesaurus.di.MerriamWebsterThesaurusModuleProviderFactory"
).newInstance() as DetailProviderFactory
}

// DetailDataProviderRegistry
single {
val detailDataProviderRegistry = DetailDataProviderRegistry()

val merriamWebsterDetailProviderFactory: DetailProviderFactory =
get(named("merriamWebsterDetailProviderFactory"))

val merriamWebsterThesaurusDetailProviderFactory: DetailProviderFactory =
get(named("merriamWebsterThesaurusDetailDataProviderFactory"))

detailDataProviderRegistry.addProviders(
TitleDetailDataProvider(get()),
merriamWebsterDetailProviderFactory.getDetailDataProvider(),
merriamWebsterThesaurusDetailProviderFactory.getDetailDataProvider(),
WordsetDetailDataProvider(get()),
ExampleDetailDataProvider(get())
)

detailDataProviderRegistry
}

// DetailItemProviderRegistry
single {
val detailItemFactory = DetailItemProviderRegistry()

val merriamWebsterDetailProviderFactory: DetailProviderFactory =
get(named("merriamWebsterDetailProviderFactory"))

val merriamWebsterThesaurusDetailProviderFactory: DetailProviderFactory =
get(named("merriamWebsterThesaurusDetailDataProviderFactory"))

// Add the Merriam-Webster provider to the detailItemFactory
detailItemFactory.addProviders(
TitleDetailItemProvider(),
merriamWebsterDetailProviderFactory.getDetailItemProvider(),
merriamWebsterThesaurusDetailProviderFactory.getDetailItemProvider(),
WordsetDetailItemProvider(),
ExamplesDetailItemProvider()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ class MainActivity : AppCompatActivity() {
}


contextualSheetBehavior.bottomSheetCallback = contextualSheetCallback
searchSheetBehavior.bottomSheetCallback = searchSheetCallback
contextualSheetBehavior.addBottomSheetCallback(contextualSheetCallback)
searchSheetBehavior.addBottomSheetCallback(searchSheetCallback)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import android.view.View
import android.widget.LinearLayout
import android.widget.ProgressBar
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import androidx.appcompat.widget.AppCompatEditText
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
Expand Down Expand Up @@ -300,8 +302,14 @@ class AuthActivity : AppCompatActivity(), CoroutineScope {
bgTransition.isCrossFadeEnabled = true
bgTransition.startTransition(200)

val errorTextColor = getColorFromAttr(R.attr.colorOnErrorHighEmphasis)
val errorHintColor = getColorFromAttr(R.attr.colorOnErrorLowEmphasis)
val errorTextColor = ContextCompat.getColor(
this,
R.color.on_error_emphasis_high_type
)
val errorHintColor = ContextCompat.getColor(
this,
R.color.on_error_emphasis_disabled
)
TransitionManager.beginDelayedTransition(containerLayout)
emailEditText.setTextColor(errorTextColor)
emailEditText.setHintTextColor(errorHintColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class DetailItemListMediatorLiveData : MediatorLiveData<List<DetailItemModel>>()

private var titleModel: DetailItemModel? = null
private var mwModel: DetailItemModel? = null
private var mwThesaurusModel: DetailItemModel? = null
private var wordsetModel: DetailItemModel? = null
private var examplesModel: DetailItemModel? = null

Expand All @@ -30,6 +31,12 @@ class DetailItemListMediatorLiveData : MediatorLiveData<List<DetailItemModel>>()
updateList()
}
}
DetailItemType.MERRIAM_WEBSTER_THESAURUS -> {
if (shouldUpdateList(mwThesaurusModel, item)) {
mwThesaurusModel = item
updateList()
}
}
DetailItemType.WORDSET -> {
if (shouldUpdateList(wordsetModel, item)) {
wordsetModel = item
Expand All @@ -56,6 +63,7 @@ class DetailItemListMediatorLiveData : MediatorLiveData<List<DetailItemModel>>()
listOfNotNull(
titleModel,
mwModel,
mwThesaurusModel,
wordsetModel,
examplesModel
).sortedBy { it.itemType.order }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ class DetailsFragment: BaseFragment(), DetailAdapterListener {
viewModel.onMerriamWebsterPermissionPaneDismissClicked()
}

override fun onMwThesaurusChipClicked(word: String) {
sharedViewModel.onChangeCurrentWord(word)
}

private fun showSnackbar(model: SnackbarModel) {
val snackbar = Snackbar.make(coordinatorLayout, model.textRes, when (model.length) {
SnackbarModel.LENGTH_INDEFINITE -> Snackbar.LENGTH_INDEFINITE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sealed class ListItemViewHolder<T : ListItemModel>(val view: View): RecyclerView
wordTextView.text = item.userWord.word

//Set part of speech
partOfSpeechTextView.text = item.userWord.partOfSpeechPreview.keys.first()
partOfSpeechTextView.text = item.userWord.partOfSpeechPreview.keys.firstOrNull() ?: ""

//Set definition
item.userWord.defPreview.map { it.key }.firstOrNull()?.let {
Expand All @@ -64,8 +64,8 @@ sealed class ListItemViewHolder<T : ListItemModel>(val view: View): RecyclerView

//Set synonym chips
chipGroup.removeAllViews()
item.userWord.synonymPreview.forEach {
val synonym = Synonym(it.key, OffsetDateTime.now(), OffsetDateTime.now())
item.userWord.synonymPreview.forEach {syn ->
val synonym = Synonym(syn.key, OffsetDateTime.now(), OffsetDateTime.now())
chipGroup.addView(
synonym.toChip(view.context, view.expanded_chip_group) {
listener.onWordClicked(it.synonym)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,19 @@ class ContextualFragment : BaseFragment() {
val materialShapeDrawable = MaterialShapeDrawable(
requireContext(),
null,
R.attr.styleBottomSheetStandard,
R.style.Widget_Words_BottomSheet_Standard
DEF_STYLE_ATTR,
DEF_STYLE_RES
).apply {
initializeElevationOverlay(requireContext())
elevation = contextualFrame.elevation
fillColor = ColorStateList.valueOf(
requireContext().getColorFromAttr(R.attr.colorSurface)
)
// Add a stroke to emphasize the shadow on the top of this bottom sheet.
// The stroke is very light as the sheet moves towards the bottom of the screen
// due to how Android's light source, used for shadow calculation, works.
strokeColor = ColorStateList.valueOf(
ContextCompat.getColor(requireContext(), R.color.colorBlackAlpha005)
ContextCompat.getColor(requireContext(), R.color.shadow_emphasis_color)
)
strokeWidth = 2F
}
Expand Down Expand Up @@ -245,6 +248,10 @@ class ContextualFragment : BaseFragment() {
}

companion object {

private const val DEF_STYLE_ATTR = R.attr.styleBottomSheetStandard
private const val DEF_STYLE_RES = R.style.Widget_Waylan_BottomSheet_Standard

fun getPeekHeight(context: Context, insets: WindowInsetsCompat): Int {
return SearchFragment.getPeekHeight(context, insets) +
context.resources.getDimensionPixelSize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,19 @@ class SearchFragment : BaseFragment(), SearchItemAdapter.SearchItemListener, Tex
val materialShapeDrawable = MaterialShapeDrawable(
requireContext(),
null,
R.attr.styleBottomSheetStandard,
R.style.Widget_Words_BottomSheet_Standard
DEF_STYLE_ATTR,
DEF_STYLE_RES
).apply {
initializeElevationOverlay(requireContext())
elevation = collapsedContainer.elevation
fillColor = ColorStateList.valueOf(
requireContext().getColorFromAttr(R.attr.colorSurface)
)
// Add a stroke to emphasize the shadow on the top of this bottom sheet.
// The stroke is very light as the sheet moves towards the bottom of the screen
// due to how Android's light source, used for shadow calculation, works.
strokeColor = ColorStateList.valueOf(
ContextCompat.getColor(requireContext(), R.color.colorBlackAlpha005)
ContextCompat.getColor(requireContext(), R.color.shadow_emphasis_color)
)
strokeWidth = 3F
}
Expand Down Expand Up @@ -568,6 +571,9 @@ class SearchFragment : BaseFragment(), SearchItemAdapter.SearchItemListener, Tex

companion object {

private const val DEF_STYLE_ATTR = R.attr.styleBottomSheetStandard
private const val DEF_STYLE_RES = R.style.Widget_Waylan_BottomSheet_Standard

private fun getBottomInset(context: Context, insets: WindowInsetsCompat): Int {
return insets.systemWindowInsetBottom +
context.resources.getDimensionPixelSize(R.dimen.keyline_2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import space.narrate.waylan.android.data.disk.wordset.Synonym
import space.narrate.waylan.android.ui.MainViewModel
import space.narrate.waylan.core.ui.widget.ElasticAppBarBehavior
import space.narrate.waylan.core.util.setUpWithElasticBehavior
import space.narrate.waylan.core.util.toChip

fun AppBarLayout.setUpWithElasticBehavior(
currentDestination: String,
Expand Down Expand Up @@ -48,36 +49,7 @@ fun Synonym.toChip(
chipGroup: ChipGroup?,
onClick: ((synonym: Synonym) -> Unit)? = null
): Chip {
val chip: Chip = LayoutInflater.from(context).inflate(
R.layout.details_chip_layout,
chipGroup,
false
) as Chip
chip.text = this.synonym
chip.setOnClickListener {
if (onClick != null) onClick(this)
return synonym.toChip(context, chipGroup) {
if (onClick != null && it == synonym) onClick(this)
}
return chip
}

fun String.toRelatedChip(
context: Context,
chipGroup: ChipGroup?,
onClick: ((word: String) -> Unit)? = null
): Chip {
val chip: Chip = LayoutInflater.from(context).inflate(
R.layout.details_related_chip_layout,
chipGroup,
false
) as Chip
val underlinedString = SpannableString(this)
underlinedString.setSpan(UnderlineSpan(),0,this.length,0)
chip.text = underlinedString
chip.setOnClickListener {
if (onClick != null) onClick(this)
}
return chip
}



2 changes: 1 addition & 1 deletion app/src/main/res/drawable-hdpi/ic_round_close_24px.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?colorOnSurfaceLowEmphasis">
android:tint="@color/material_on_surface_disabled">
<path
android:fillColor="#FF000000"
android:pathData="M18.3,5.71L18.3,5.71c-0.39,-0.39 -1.02,-0.39 -1.41,0L12,10.59L7.11,5.7c-0.39,-0.39 -1.02,-0.39 -1.41,0l0,0c-0.39,0.39 -0.39,1.02 0,1.41L10.59,12L5.7,16.89c-0.39,0.39 -0.39,1.02 0,1.41h0c0.39,0.39 1.02,0.39 1.41,0L12,13.41l4.89,4.89c0.39,0.39 1.02,0.39 1.41,0l0,0c0.39,-0.39 0.39,-1.02 0,-1.41L13.41,12l4.89,-4.89C18.68,6.73 18.68,6.09 18.3,5.71z"/>
Expand Down
Loading