Skip to content

Commit

Permalink
Fix some UI issues
Browse files Browse the repository at this point in the history
  • Loading branch information
arrazyfathan committed Mar 19, 2023
1 parent b64f1da commit a739e68
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class DetailActivity : AppCompatActivity() {
handleIntent()
setupRecyclerView()
checkIfWordSaved()
observe()
setupView()
observe()
}

private fun observe() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ class HomeFragment : Fragment(R.layout.fragment_home) {
is Resource.Loading -> showLoading(true)
is Resource.Success -> {
showLoading(false)
navigateToDetail(result, word)
saveWordToHistory(word)
binding.editTextSearch.setText("")
navigateToDetail(result, word)
}
is Resource.Error -> {
showLoading(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ class HistoryAdapter(

fun isEmpty(): Boolean = differ.currentList.isEmpty()

override fun getItemCount() = differ.currentList.size.coerceAtMost(7)
override fun getItemCount() = differ.currentList.size
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package com.example.kbbikamusbesarbahasaindonesia.ui.words

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.*
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.kbbikamusbesarbahasaindonesia.R
import com.example.kbbikamusbesarbahasaindonesia.core.data.Resource
import com.example.kbbikamusbesarbahasaindonesia.core.data.source.local.KosaKata
import com.example.kbbikamusbesarbahasaindonesia.core.domain.model.ListWordModel
import com.example.kbbikamusbesarbahasaindonesia.core.domain.model.WordModel
import com.example.kbbikamusbesarbahasaindonesia.core.data.source.local.KosaKata
import com.example.kbbikamusbesarbahasaindonesia.databinding.FragmentWordBinding
import com.example.kbbikamusbesarbahasaindonesia.ui.adapter.KosaKataAdapter
import com.example.kbbikamusbesarbahasaindonesia.ui.detail.DetailActivity
import com.example.kbbikamusbesarbahasaindonesia.utils.toJson
import com.example.kbbikamusbesarbahasaindonesia.utils.viewBinding
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import com.jakewharton.rxbinding4.widget.textChanges
import org.koin.androidx.viewmodel.ext.android.viewModel
import java.io.IOException

Expand All @@ -30,13 +30,7 @@ class WordFragment : Fragment(R.layout.fragment_word) {
private val viewModel: WordViewModel by viewModel()
private lateinit var adapter: KosaKataAdapter

private var filtered = KosaKata()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}

@SuppressLint("CheckResult", "NotifyDataSetChanged")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

Expand All @@ -51,27 +45,21 @@ class WordFragment : Fragment(R.layout.fragment_word) {
}
binding.rvListKosaKata.adapter = adapter

binding.editTextSearchWord.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}

override fun onTextChanged(char: CharSequence?, p1: Int, p2: Int, p3: Int) {
}

override fun afterTextChanged(char: Editable?) {
if (char.toString().isEmpty()) {
binding.editTextSearchWord.textChanges()
.skipInitialValue()
.subscribe { text ->
if (text.toString().isEmpty()) {
binding.rvListKosaKata.adapter = KosaKataAdapter(list) {
getMeaningOfWord(it)
}
adapter.notifyDataSetChanged()
} else {
adapter.filter.filter(char)
adapter.filter.filter(text)
binding.rvListKosaKata.adapter = KosaKataAdapter(adapter.kataFilterList) {
getMeaningOfWord(it)
}
}
}
})
}

private fun getMeaningOfWord(word: String) {
Expand Down Expand Up @@ -100,11 +88,13 @@ class WordFragment : Fragment(R.layout.fragment_word) {
val listWordModel = ListWordModel(
word = word,
listWords = result.data!!,
).toJson()
startActivity(
Intent(requireActivity(), DetailActivity::class.java).putExtra(
"data",
listWordModel,
),
)
val dataJson = Gson().toJson(listWordModel)
val intent = Intent(requireActivity(), DetailActivity::class.java)
intent.putExtra("data", dataJson)
startActivity(intent)
}

private fun getJsonDataFromAsset(context: Context, fileName: String): String? {
Expand All @@ -118,7 +108,7 @@ class WordFragment : Fragment(R.layout.fragment_word) {
return jsonString
}

fun showLoadingState(state: Boolean) {
private fun showLoadingState(state: Boolean) {
if (state) {
binding.loadingState.visibility =
View.VISIBLE
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/color/text_selection_state.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/white" />
<item android:color="@color/text_p" />
</selector>
8 changes: 5 additions & 3 deletions app/src/main/res/layout/item_list_arti.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@

<TextView
android:id="@+id/lemma"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="16dp"
android:paddingVertical="4dp"
android:fontFamily="@font/inter_semibold"
android:text="de.mo.kra.si /démokrasi/"
tools:text="de.mo.kra.si /démokrasi/"
android:textColor="@color/text_h1"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="@id/container_number"
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/layout/item_list_child_arti.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/inter_regular"
android:justificationMode="inter_word"
android:textColor="@color/text_p"
android:layout_margin="4dp"
android:textColor="@color/text_selection_state"
android:textSize="16sp"
android:textIsSelectable="true"
android:textColorHighlight="@color/text_primary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="(bentuk atau sistem) pemerintahan yang seluruh rakyatnya turut serta memerintah dengan perantaraan wakilnya; pemerintahan rakyat" />
tools:text="(bentuk atau sistem) pemerintahan yang seluruh rakyatnya turut serta memerintah dengan perantaraan wakilnya; pemerintahan rakyat" />


</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/item_list_favorite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="4dp"
android:layout_width="wrap_content"
android:textColor="@color/text_p"
Expand Down
2 changes: 1 addition & 1 deletion app/version.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Sun Mar 19 21:17:31 WIB 2023
#Sun Mar 19 22:14:19 WIB 2023
VERSION_ALPHA=0
VERSION_MINOR=0
VERSION_DEV=0
Expand Down

0 comments on commit a739e68

Please sign in to comment.