Add the font variant
This commit is contained in:
parent
6ab8e40d45
commit
c38b7a335c
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@
|
||||
.externalNativeBuild
|
||||
/tasksintegration/build
|
||||
/app/google-services.json
|
||||
apikey.properties
|
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@ -10,7 +10,12 @@ apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
apply plugin: 'realm-android'
|
||||
|
||||
def apikeyPropertiesFile = rootProject.file("apikey.properties")
|
||||
def apikeyProperties = new Properties()
|
||||
apikeyProperties.load(new FileInputStream(apikeyPropertiesFile))
|
||||
|
||||
android {
|
||||
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.3"
|
||||
|
||||
@ -22,6 +27,7 @@ android {
|
||||
versionName "2.0.13"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
buildConfigField("String", "GOOGLE_API_KEY", apikeyProperties['GOOGLE_API_KEY'])
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
@ -94,6 +94,7 @@ object Preferences : KotprefModel() {
|
||||
var customFont by intPref(key = "PREF_CUSTOM_FONT", default = Constants.CUSTOM_FONT_GOOGLE_SANS)
|
||||
var customFontFile by stringPref(default = "")
|
||||
var customFontName by stringPref(default = "")
|
||||
var customFontVariant by stringPref(default = "")
|
||||
var showNextEvent by booleanPref(key = "PREF_SHOW_NEXT_EVENT", default = true)
|
||||
|
||||
var showDividers by booleanPref(default = true)
|
||||
|
@ -63,6 +63,19 @@ object SettingsStringHelper {
|
||||
}
|
||||
}
|
||||
|
||||
fun getVariantLabel(context: Context, variant: String): String = when {
|
||||
variant.contains("100") -> context.getString(R.string.font_100)
|
||||
variant.contains("200") -> context.getString(R.string.font_200)
|
||||
variant.contains("300") -> context.getString(R.string.font_300)
|
||||
variant.contains("regular") || variant.contains("400") -> context.getString(R.string.font_400)
|
||||
variant.contains("500") -> context.getString(R.string.font_500)
|
||||
variant.contains("600") -> context.getString(R.string.font_600)
|
||||
variant.contains("700") -> context.getString(R.string.font_700)
|
||||
variant.contains("800") -> context.getString(R.string.font_800)
|
||||
variant.contains("900") -> context.getString(R.string.font_900)
|
||||
else -> context.getString(R.string.font_400)
|
||||
}
|
||||
|
||||
fun getDifferenceText(context: Context, now: Long, start: Long): String {
|
||||
val nowDate = DateTime(now)
|
||||
val eventDate = DateTime(start)
|
||||
|
@ -57,6 +57,7 @@ object WidgetHelper {
|
||||
|
||||
fun runWithCustomTypeface(context: Context, function: (typeface: Typeface?) -> Unit) {
|
||||
if (Preferences.customFontFile != "") {
|
||||
Log.d("ciao", Preferences.customFontFile)
|
||||
val request = FontRequest(
|
||||
"com.google.android.gms.fonts",
|
||||
"com.google.android.gms",
|
||||
|
@ -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)
|
||||
|
@ -27,7 +27,16 @@
|
||||
<string name="settings_date_format_title">Formato data</string>
|
||||
<string name="header_widget_background">Sfondo widget</string>
|
||||
<string name="settings_secondary_row_top_margin_title">Margine</string>
|
||||
<string name="action_custom_font_to_search">Cerca font...</string>
|
||||
<string name="action_custom_font_to_search">Cerca font…</string>
|
||||
<string name="font_100">Thin</string>
|
||||
<string name="font_200">Leggero</string>
|
||||
<string name="font_300">Lettura</string>
|
||||
<string name="font_400">Normale</string>
|
||||
<string name="font_500">Medio</string>
|
||||
<string name="font_600">Semigrassetto</string>
|
||||
<string name="font_700">Grassetto</string>
|
||||
<string name="font_800">Nero</string>
|
||||
<string name="font_900">Molto nero</string>
|
||||
|
||||
<!-- Calendar -->
|
||||
<string name="settings_calendar_title">Calendario</string>
|
||||
|
@ -30,6 +30,15 @@
|
||||
<string name="header_widget_background">Widget background</string>
|
||||
<string name="settings_secondary_row_top_margin_title">Margin</string>
|
||||
<string name="action_custom_font_to_search">Custom font...</string>
|
||||
<string name="font_100">Thin</string>
|
||||
<string name="font_200">Light</string>
|
||||
<string name="font_300">Book</string>
|
||||
<string name="font_400">Regular</string>
|
||||
<string name="font_500">Medium</string>
|
||||
<string name="font_600">Semi-bold</string>
|
||||
<string name="font_700">Bold</string>
|
||||
<string name="font_800">Black</string>
|
||||
<string name="font_900">Heavy</string>
|
||||
|
||||
<!-- Calendar -->
|
||||
<string name="settings_calendar_title">Calendar</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user