Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
maltaisn committed Jan 5, 2020
2 parents 878d8c5 + f0d4090 commit 4703f5d
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 75 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v3.1.0
- Added progress bar in dialog for when icon pack is not loaded yet.
- Fixed `IconDialogSettings.dialogTitle` having no effect.

# v3.0.0
- Complete rewrite in Kotlin with MVP architecture.
- Now based on Google's Material Components with out of the box support for dark theme.
Expand Down
38 changes: 10 additions & 28 deletions app/src/main/kotlin/com/maltaisn/icondialog/demo/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import androidx.annotation.ArrayRes
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -55,12 +53,10 @@ class MainFragment : Fragment(), IconDialog.Callback {

private val coroutineScope = CoroutineScope(Dispatchers.Main + SupervisorJob())
private var packLoadJob: Job? = null
private var progressVisbJob: Job? = null

private lateinit var iconDialog: IconDialog
private lateinit var iconsAdapter: IconsAdapter
private lateinit var iconPackPb: ProgressBar
private lateinit var fab: FloatingActionButton
private lateinit var fakeLoadingCheck: CheckBox

private lateinit var iconPackLoader: IconPackLoader

Expand All @@ -84,7 +80,6 @@ class MainFragment : Fragment(), IconDialog.Callback {
setupDropdown(view.findViewById(R.id.dropdown_icon_pack), R.array.icon_packs) {
changeIconPack(it)
}
iconPackPb = view.findViewById(R.id.pb_icon_pack)

var titleVisbIndex = 2
setupDropdown(view.findViewById(R.id.dropdown_title_visibility), R.array.title_visibility) {
Expand Down Expand Up @@ -142,16 +137,15 @@ class MainFragment : Fragment(), IconDialog.Callback {
})
}

fakeLoadingCheck = view.findViewById(R.id.chk_fake_loading)

val iconsRcv: RecyclerView = view.findViewById(R.id.rcv_icon_list)
iconsAdapter = IconsAdapter()
iconsRcv.adapter = iconsAdapter
iconsRcv.layoutManager = LinearLayoutManager(context)

fab = view.findViewById(R.id.fab)
fab.isVisible = (app.iconPack != null)
val fab: FloatingActionButton = view.findViewById(R.id.fab)
fab.setOnClickListener {
if (app.iconPack == null) return@setOnClickListener

// Create new settings and set them.
iconDialog.settings = IconDialogSettings {
this.iconFilter = iconFilter
Expand Down Expand Up @@ -241,29 +235,17 @@ class MainFragment : Fragment(), IconDialog.Callback {
// Load drawables
pack.loadDrawables(iconPackLoader.drawableLoader)

if (fakeLoadingCheck.isChecked) {
delay(4000)
}

pack
}

iconPackPb.isInvisible = true
fab.show()

updateSelectedIcons()

progressVisbJob?.cancel()
progressVisbJob = null
packLoadJob = null
}

// Start new job to show progress after some delay.
progressVisbJob?.cancel()
progressVisbJob = coroutineScope.launch(Dispatchers.Default) {
delay(250)
withContext(Dispatchers.Main) {
iconPackPb.isInvisible = false
fab.hide()
}
progressVisbJob = null
}
}

private fun changeIconPack(index: Int) {
Expand Down Expand Up @@ -293,8 +275,8 @@ class MainFragment : Fragment(), IconDialog.Callback {
}

// Called by icon dialog to get the icon pack.
override val iconDialogIconPack: IconPack
get() = app.iconPack!!
override val iconDialogIconPack: IconPack?
get() = app.iconPack

override fun onIconDialogIconsSelected(dialog: IconDialog, icons: List<Icon>) {
// Called by icon dialog when icons were selected.
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@
android:layout_margin="16dp"
android:layout_gravity="bottom|end"
android:src="@drawable/ic_edit"
android:visibility="gone"
app:fabSize="normal"
tools:visibility="visible"
/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Expand Down
25 changes: 10 additions & 15 deletions app/src/main/res/layout/layout_options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,6 @@
/>
</com.google.android.material.textfield.TextInputLayout>

<ProgressBar
android:id="@+id/pb_icon_pack"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="@id/layout_icon_pack_dropdown"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/layout_icon_pack_dropdown"
app:layout_constraintTop_toTopOf="@id/layout_icon_pack_dropdown"
android:visibility="invisible"
tools:visibility="visible"
/>

<TextView
android:id="@+id/txv_title_visibility_label"
style="@style/OptionTextStyle"
Expand Down Expand Up @@ -275,4 +260,14 @@
android:text="@string/option_dark_theme"
/>

<CheckBox
android:id="@+id/chk_fake_loading"
style="@style/OptionTextStyle"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/chk_dark_theme"
android:text="@string/option_fake_loading"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<string name="option_show_select_btn">Show select button</string>
<string name="option_show_clear_btn">Show clear button</string>
<string name="option_dark_theme">Dark theme</string>
<string name="option_fake_loading">Fake loading time</string>

<string name="icon_pack_default">Default</string>
<string name="icon_pack_fa">Font Awesome</string>
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Library
libVersion=3.0.0
libVersion=3.0.1

# Icon packs
iconPackDefaultVersion=1.0.0
Expand Down
32 changes: 30 additions & 2 deletions lib/src/main/kotlin/com/maltaisn/icondialog/IconDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
/** The settings used for the dialog. */
override lateinit var settings: IconDialogSettings

override val iconPack: IconPack
override val iconPack: IconPack?
get() = callback.iconDialogIconPack

/**
Expand All @@ -77,6 +77,7 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
private lateinit var searchEdt: EditText
private lateinit var searchClearBtn: ImageView
private lateinit var noResultTxv: TextView
private lateinit var progressBar: ProgressBar
private lateinit var footerDiv: View
private lateinit var selectBtn: Button
private lateinit var cancelBtn: Button
Expand All @@ -86,6 +87,9 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
private lateinit var listAdapter: IconAdapter
private lateinit var listLayout: IconLayoutManager

private lateinit var progressHandler: Handler
private var progressCallback: Runnable? = null

private lateinit var searchHandler: Handler
private val searchCallback = Runnable {
presenter?.onSearchQueryEntered(searchEdt.text.toString())
Expand Down Expand Up @@ -117,6 +121,7 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
iconColorSelected = getColor(it.getResourceId(R.styleable.IconDialog_icdSelectedIconColor, 0))
}

progressHandler = Handler()
searchHandler = Handler()

// Create the dialog view
Expand All @@ -127,6 +132,7 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
searchEdt = dialogView.findViewById(R.id.icd_edt_search)
searchClearBtn = dialogView.findViewById(R.id.icd_imv_clear_search)
noResultTxv = dialogView.findViewById(R.id.icd_txv_no_result)
progressBar = dialogView.findViewById(R.id.icd_progress_bar)

// Search
searchEdt.addTextChangedListener {
Expand Down Expand Up @@ -235,6 +241,17 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
presenter?.onDialogCancelled()
}

override fun postDelayed(delay: Long, action: () -> Unit) {
val callback = Runnable(action)
progressHandler.post(callback)
progressCallback = callback
}

override fun cancelCallbacks() {
progressHandler.removeCallbacks(progressCallback ?: return)
progressCallback = null
}

override fun exit() {
dismiss()
}
Expand All @@ -259,6 +276,10 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
titleTxv.isVisible = visible
}

override fun updateTitle(titleRes: Int) {
titleTxv.text = getString(titleRes)
}

override fun setSearchBarVisible(visible: Boolean) {
searchImv.isVisible = visible
searchEdt.isVisible = visible
Expand All @@ -277,6 +298,10 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
noResultTxv.isVisible = visible
}

override fun setProgressBarVisible(visible: Boolean) {
progressBar.isVisible = visible
}

override fun setFooterVisible(visible: Boolean) {
clearBtn.isVisible = visible
cancelBtn.isVisible = visible
Expand Down Expand Up @@ -404,8 +429,11 @@ class IconDialog : DialogFragment(), IconDialogContract.View {
/**
* The icon pack to be displayed by the dialog.
* All icon drawables in the pack must have been loaded, or they won't be displayed.
*
* If `null` is returned, the icon dialog will periodically try to get the icon
* pack while showing a progress indicator, until it no longer returns `null`.
*/
val iconDialogIconPack: IconPack
val iconDialogIconPack: IconPack?

/**
* Called when icons are selected and user confirms the selection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.maltaisn.icondialog

import android.os.Bundle
import androidx.annotation.StringRes
import com.maltaisn.icondialog.data.Category
import com.maltaisn.icondialog.data.Icon
import com.maltaisn.icondialog.pack.IconPack
Expand All @@ -27,20 +28,24 @@ internal interface IconDialogContract {

interface View {
val settings: IconDialogSettings
val iconPack: IconPack
val iconPack: IconPack?
val selectedIconIds: List<Int>
val locale: Locale

fun postDelayed(delay: Long, action: () -> Unit)
fun cancelCallbacks()

fun exit()
fun hideKeyboard()

fun setCancelResult()
fun setSelectionResult(selected: List<Icon>)

fun setTitleVisible(visible: Boolean)
fun updateTitle(@StringRes titleRes: Int)
fun setSearchBarVisible(visible: Boolean)
fun setClearSearchBtnVisible(visible: Boolean)
fun setClearBtnVisible(visible: Boolean)
fun setProgressBarVisible(visible: Boolean)
fun setNoResultLabelVisible(visible: Boolean)
fun setFooterVisible(visible: Boolean)
fun removeLayoutPadding()
Expand Down
Loading

0 comments on commit 4703f5d

Please sign in to comment.