diff --git a/android/app/src/main/java/org/toni/customfetch_android/SettingsActivity.kt b/android/app/src/main/java/org/toni/customfetch_android/SettingsActivity.kt index 2279eaf..ec3455d 100644 --- a/android/app/src/main/java/org/toni/customfetch_android/SettingsActivity.kt +++ b/android/app/src/main/java/org/toni/customfetch_android/SettingsActivity.kt @@ -75,18 +75,16 @@ private fun copyDirectory( return val destDir = File(destinationDir, sourceDir) - if (!destDir.exists() && !destDir.mkdirs()) { + if (!destDir.exists() && !destDir.mkdirs()) throw IOException("Failed to create directory: " + destDir.absolutePath) - } for (fileName in files) { val assetPath = "$sourceDir/$fileName" val destPath = destDir.path + "/" + fileName - if (isDirectory(assetManager, assetPath)) { + if (isDirectory(assetManager, assetPath)) copyDirectory(assetManager, assetPath, destinationDir) - } else { + else copyFile(assetManager, assetPath, destPath) - } } } @@ -102,9 +100,9 @@ private fun copyFile(assetManager: AssetManager, assetPath: String, destPath: St FileOutputStream(destPath).use { out -> val buffer = ByteArray(8192) var bytesRead: Int - while ((`in`.read(buffer).also { bytesRead = it }) != -1) { + while ((`in`.read(buffer).also { bytesRead = it }) != -1) out.write(buffer, 0, bytesRead) - } + Log.d(TAG, "File copied: $destPath") } } diff --git a/android/app/src/main/java/org/toni/customfetch_android/widget/customfetch.kt b/android/app/src/main/java/org/toni/customfetch_android/widget/customfetch.kt index b4ae083..67d06ca 100644 --- a/android/app/src/main/java/org/toni/customfetch_android/widget/customfetch.kt +++ b/android/app/src/main/java/org/toni/customfetch_android/widget/customfetch.kt @@ -99,7 +99,11 @@ internal fun updateAppWidget( val textSizePx = textSizeSp * context.resources.displayMetrics.scaledDensity textPaint.textSize = textSizePx - val width = WidgetSizeProvider(context).getWidgetsSize(appWidgetId).first.toFloat() + val additionalTruncateWidth = loadTruncateWidthPref(context, appWidgetId).toFloat() + var width = WidgetSizeProvider(context).getWidgetsSize(appWidgetId).first.toFloat() + if (additionalTruncateWidth > 0.20) + width *= additionalTruncateWidth + Log.d("widthTesting", "textSizePx = $textSizePx") Log.d("widthTesting", "width = $width") Log.d("wrappingTest", "disableLineWrap = $disableLineWrap") diff --git a/android/app/src/main/java/org/toni/customfetch_android/widget/customfetchConfigureActivity.kt b/android/app/src/main/java/org/toni/customfetch_android/widget/customfetchConfigureActivity.kt index 0483bf7..68a3256 100644 --- a/android/app/src/main/java/org/toni/customfetch_android/widget/customfetchConfigureActivity.kt +++ b/android/app/src/main/java/org/toni/customfetch_android/widget/customfetchConfigureActivity.kt @@ -20,6 +20,7 @@ import org.toni.customfetch_android.databinding.CustomfetchConfigureBinding import java.nio.file.Files import kotlin.io.path.Path +// truncate text var disableLineWrap = false /** @@ -28,6 +29,7 @@ var disableLineWrap = false class customfetchConfigureActivity : Activity() { private var appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID private lateinit var argumentsConfig: EditText + private lateinit var additionalTruncateWidth: EditText private lateinit var argsHelp: TextView private lateinit var showModulesList: CheckBox private lateinit var disableWrapLines: CheckBox @@ -35,8 +37,7 @@ class customfetchConfigureActivity : Activity() { val context = this@customfetchConfigureActivity // When the button is clicked, store the string locally - val widgetText = argumentsConfig.text.toString() - saveTitlePref(context, appWidgetId, widgetText) + saveTitlePref(context, appWidgetId, argumentsConfig.text.toString(), additionalTruncateWidth.text.toString()) // It is the responsibility of the configuration activity to update the app widget val appWidgetManager = AppWidgetManager.getInstance(context) @@ -64,6 +65,7 @@ class customfetchConfigureActivity : Activity() { copyToAssetFolder(assets, filesDir.absolutePath, "ascii") argumentsConfig = binding.argumentsConfigure + additionalTruncateWidth = binding.additionalTruncateN argsHelp = binding.argsHelp showModulesList = binding.showModulesList disableWrapLines = binding.disableWrapLines @@ -84,6 +86,7 @@ class customfetchConfigureActivity : Activity() { } argumentsConfig.setText(loadTitlePref(this@customfetchConfigureActivity, appWidgetId)) + additionalTruncateWidth.setText("0.81") argsHelp.text = customfetchRender.mainAndroid("customfetch --help") showModulesList.setOnCheckedChangeListener { _, isChecked -> @@ -137,10 +140,11 @@ private const val PREFS_NAME = "org.toni.customfetch_android.customfetch" private const val PREF_PREFIX_KEY = "appwidget_" // Write the prefix to the SharedPreferences object for this widget -internal fun saveTitlePref(context: Context, appWidgetId: Int, text: String) { +internal fun saveTitlePref(context: Context, appWidgetId: Int, text: String, truncateWidth: String) { val prefs = context.getSharedPreferences(PREFS_NAME, 0).edit() prefs.putString(PREF_PREFIX_KEY + appWidgetId, text) prefs.putBoolean(PREF_PREFIX_KEY + "bool_" + appWidgetId, disableLineWrap) + prefs.putString(PREF_PREFIX_KEY + "truncate_" + appWidgetId, truncateWidth) prefs.apply() } @@ -153,6 +157,12 @@ internal fun loadTitlePref(context: Context, appWidgetId: Int): String { return titleValue ?: "-D ${context.filesDir.absolutePath} -a small" } +internal fun loadTruncateWidthPref(context: Context, appWidgetId: Int): String { + val prefs = context.getSharedPreferences(PREFS_NAME, 0) + val truncateWidthValue = prefs.getString(PREF_PREFIX_KEY + "truncate_" + appWidgetId, null) + return truncateWidthValue ?: "0" +} + internal fun deleteTitlePref(context: Context, appWidgetId: Int) { val prefs = context.getSharedPreferences(PREFS_NAME, 0).edit() prefs.remove(PREF_PREFIX_KEY + appWidgetId) diff --git a/android/app/src/main/res/layout/customfetch_configure.xml b/android/app/src/main/res/layout/customfetch_configure.xml index ca66ebd..0d750da 100644 --- a/android/app/src/main/res/layout/customfetch_configure.xml +++ b/android/app/src/main/res/layout/customfetch_configure.xml @@ -26,6 +26,20 @@ android:labelFor="@+id/arguments_configure" android:text="@string/disable_wrap_lines" /> + + + +