forked from sduduzog/slim-launcher
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate additional dialog fragments to com.jkuester (#268)
- Loading branch information
Showing
15 changed files
with
470 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/jkuester/unlauncher/dialog/ClockTypeDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.jkuester.unlauncher.dialog | ||
|
||
import android.app.AlertDialog | ||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
import androidx.fragment.app.DialogFragment | ||
import com.jkuester.unlauncher.datasource.CorePreferencesRepository | ||
import com.jkuester.unlauncher.datasource.setClockType | ||
import com.jkuester.unlauncher.datastore.proto.ClockType | ||
import com.sduduzog.slimlauncher.R | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class ClockTypeDialog : DialogFragment() { | ||
@Inject | ||
lateinit var corePreferencesRepo: CorePreferencesRepository | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = AlertDialog | ||
.Builder(context) | ||
.setTitle(R.string.choose_clock_type_dialog_title) | ||
.setSingleChoiceItems( | ||
R.array.clock_type_array, | ||
corePreferencesRepo.get().clockType.number, | ||
this::onSelection | ||
) | ||
.create() | ||
|
||
private fun onSelection(dialogInterface: DialogInterface, i: Int) = dialogInterface | ||
.dismiss() | ||
.also { corePreferencesRepo.updateAsync(setClockType(ClockType.forNumber(i))) } | ||
} |
69 changes: 69 additions & 0 deletions
69
app/src/main/java/com/jkuester/unlauncher/dialog/QuickButtonIconDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.jkuester.unlauncher.dialog | ||
|
||
import android.app.AlertDialog | ||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
import androidx.fragment.app.DialogFragment | ||
import com.jkuester.unlauncher.datasource.QuickButtonIcon | ||
import com.jkuester.unlauncher.datasource.QuickButtonPreferencesRepository | ||
import com.jkuester.unlauncher.datasource.setCenterIconId | ||
import com.jkuester.unlauncher.datasource.setLeftIconId | ||
import com.jkuester.unlauncher.datasource.setRightIconId | ||
import com.jkuester.unlauncher.datastore.proto.QuickButtonPreferences | ||
import com.sduduzog.slimlauncher.R | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import javax.inject.Inject | ||
|
||
private fun getCurrentIconIdByDefault(defaultIconId: Int) = { quickButtonPrefs: QuickButtonPreferences -> | ||
when (defaultIconId) { | ||
QuickButtonIcon.IC_CALL.prefId -> quickButtonPrefs.leftButton.iconId | ||
QuickButtonIcon.IC_COG.prefId -> quickButtonPrefs.centerButton.iconId | ||
else -> quickButtonPrefs.rightButton.iconId | ||
} | ||
} | ||
|
||
private fun getIndexByIconId(iconId: Int) = when (iconId) { | ||
QuickButtonIcon.IC_EMPTY.prefId -> 1 | ||
else -> 0 | ||
} | ||
|
||
private fun getIconIdByIndex(defaultIconId: Int, index: Int) = when (index) { | ||
1 -> QuickButtonIcon.IC_EMPTY.prefId | ||
else -> defaultIconId | ||
} | ||
|
||
private fun getUpdateFunctionByDefault(defaultIconId: Int) = when (defaultIconId) { | ||
QuickButtonIcon.IC_CALL.prefId -> ::setLeftIconId | ||
QuickButtonIcon.IC_COG.prefId -> ::setCenterIconId | ||
else -> ::setRightIconId | ||
} | ||
|
||
@AndroidEntryPoint | ||
class QuickButtonIconDialog(private val defaultIconId: Int) : DialogFragment() { | ||
@Inject | ||
lateinit var repo: QuickButtonPreferencesRepository | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = AlertDialog | ||
.Builder(context) | ||
.setTitle(R.string.options_fragment_customize_quick_buttons) | ||
.setSingleChoiceItems( | ||
R.array.quick_button_array, | ||
getCurrentIndex(), | ||
this::onSelection | ||
) | ||
.create() | ||
|
||
private fun getCurrentIndex() = repo | ||
.get() | ||
.let(getCurrentIconIdByDefault(defaultIconId)) | ||
.let(::getIndexByIconId) | ||
|
||
private fun onSelection(dialogInterface: DialogInterface, i: Int) = dialogInterface | ||
.dismiss() | ||
.also { | ||
getIconIdByIndex(defaultIconId, i) | ||
.let(getUpdateFunctionByDefault(defaultIconId)) | ||
.let(repo::updateAsync) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/jkuester/unlauncher/dialog/SearchBarPositionDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.jkuester.unlauncher.dialog | ||
|
||
import android.app.AlertDialog | ||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
import androidx.fragment.app.DialogFragment | ||
import com.jkuester.unlauncher.datasource.CorePreferencesRepository | ||
import com.jkuester.unlauncher.datasource.setSearchBarPosition | ||
import com.jkuester.unlauncher.datastore.proto.SearchBarPosition | ||
import com.sduduzog.slimlauncher.R | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class SearchBarPositionDialog : DialogFragment() { | ||
@Inject | ||
lateinit var corePreferencesRepo: CorePreferencesRepository | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = AlertDialog | ||
.Builder(context) | ||
.setTitle(R.string.choose_search_bar_position_dialog_title) | ||
.setSingleChoiceItems( | ||
R.array.search_bar_position_array, | ||
corePreferencesRepo.get().searchBarPosition.number, | ||
this::onSelection | ||
) | ||
.create() | ||
|
||
private fun onSelection(dialogInterface: DialogInterface, i: Int) = dialogInterface | ||
.dismiss() | ||
.also { corePreferencesRepo.updateAsync(setSearchBarPosition(SearchBarPosition.forNumber(i))) } | ||
} |
35 changes: 0 additions & 35 deletions
35
app/src/main/java/com/sduduzog/slimlauncher/ui/dialogs/ChooseClockTypeDialog.kt
This file was deleted.
Oops, something went wrong.
74 changes: 0 additions & 74 deletions
74
app/src/main/java/com/sduduzog/slimlauncher/ui/dialogs/ChooseQuickButtonDialog.kt
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
app/src/main/java/com/sduduzog/slimlauncher/ui/dialogs/ChooseSearchBarPositionDialog.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.