Add the font variant
This commit is contained in:
@ -21,9 +21,12 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.chibatching.kotpref.blockingBulk
|
||||
import com.koolio.library.Font
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
|
||||
import com.tommasoberlose.anotherwidget.databinding.ActivityCustomFontBinding
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.DateHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.CustomFontViewModel
|
||||
import kotlinx.android.synthetic.main.activity_choose_application.*
|
||||
import kotlinx.coroutines.*
|
||||
@ -98,7 +101,17 @@ class CustomFontActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
injector.clicked(R.id.text) {
|
||||
saveFont(item)
|
||||
if (item.fontVariants.size <= 1) {
|
||||
saveFont(item)
|
||||
} else {
|
||||
val dialog = BottomSheetMenu<String>(this, header = item.fontFamily)
|
||||
item.fontVariants.filter { !it.contains("italic") }.forEach {
|
||||
dialog.addItem(SettingsStringHelper.getVariantLabel(this, it), it)
|
||||
}
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
saveFont(item, value)
|
||||
}.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
.attachTo(list_view)
|
||||
@ -154,12 +167,13 @@ class CustomFontActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveFont(font: Font) {
|
||||
private fun saveFont(font: Font, variant: String = "") {
|
||||
val resultIntent = Intent()
|
||||
Preferences.blockingBulk {
|
||||
customFont = Constants.CUSTOM_FONT_DOWNLOADED
|
||||
customFontName = font.fontFamily
|
||||
customFontFile = font.queryString
|
||||
customFontVariant = variant
|
||||
}
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
|
@ -295,6 +295,20 @@ class GeneralTabFragment : Fragment() {
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.customFontName.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
custom_font_label?.text = SettingsStringHelper.getCustomFontLabel(requireContext(), Preferences.customFont)
|
||||
MainWidget.updateWidget(requireContext())
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.customFontVariant.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
custom_font_label?.text = SettingsStringHelper.getCustomFontLabel(requireContext(), Preferences.customFont)
|
||||
MainWidget.updateWidget(requireContext())
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.showDividers.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
show_dividers_label?.text =
|
||||
@ -492,21 +506,10 @@ class GeneralTabFragment : Fragment() {
|
||||
customFont = value
|
||||
customFontFile = ""
|
||||
customFontName = ""
|
||||
customFontVariant = ""
|
||||
}
|
||||
}
|
||||
}.show()
|
||||
|
||||
/*
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||
intent.type = "* / *" TO FIX WITHOUT SPACE
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
|
||||
try {
|
||||
startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), Constants.CUSTOM_FONT_CHOOSER_REQUEST_CODE)
|
||||
} catch (ex: android.content.ActivityNotFoundException) {
|
||||
Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
action_show_dividers.setOnClickListener {
|
||||
@ -518,17 +521,6 @@ class GeneralTabFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
when (requestCode) {
|
||||
RequestCode.CUSTOM_FONT_CHOOSER_REQUEST_CODE.code -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
private fun maintainScrollPosition(callback: () -> Unit) {
|
||||
scrollView.isScrollable = false
|
||||
callback.invoke()
|
||||
|
@ -9,6 +9,7 @@ import androidx.lifecycle.viewModelScope
|
||||
import com.koolio.library.DownloadableFontList
|
||||
import com.koolio.library.Font
|
||||
import com.koolio.library.FontList
|
||||
import com.tommasoberlose.anotherwidget.BuildConfig
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@ -33,7 +34,7 @@ class CustomFontViewModel(application: Application) : AndroidViewModel(applicati
|
||||
}
|
||||
}
|
||||
|
||||
DownloadableFontList.requestDownloadableFontList(fontListCallback, "AIzaSyCT_v2Qw1zCWfmc_ywsovj_4poSXr7k5f0")
|
||||
DownloadableFontList.requestDownloadableFontList(fontListCallback, BuildConfig.GOOGLE_API_KEY)
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,8 @@ class MainViewModel : ViewModel() {
|
||||
val textShadowDark = Preferences.asLiveData(Preferences::textShadowDark)
|
||||
val customFont = Preferences.asLiveData(Preferences::customFont)
|
||||
val customFontFile = Preferences.asLiveData(Preferences::customFontFile)
|
||||
val customFontName = Preferences.asLiveData(Preferences::customFontName)
|
||||
val customFontVariant = Preferences.asLiveData(Preferences::customFontVariant)
|
||||
val secondRowInformation = Preferences.asLiveData(Preferences::secondRowInformation)
|
||||
val showDividers = Preferences.asLiveData(Preferences::showDividers)
|
||||
val secondRowTopMargin = Preferences.asLiveData(Preferences::secondRowTopMargin)
|
||||
|
Reference in New Issue
Block a user