-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated ui and theme modules from Java to Kotlin (#5942)
* Rename .java to .kt * Migrated ui and theme module to Kotlin
- Loading branch information
1 parent
cb4ffd8
commit ed18a37
Showing
13 changed files
with
230 additions
and
245 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
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
66 changes: 0 additions & 66 deletions
66
app/src/main/java/fr/free/nrw/commons/theme/BaseActivity.java
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
app/src/main/java/fr/free/nrw/commons/theme/BaseActivity.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,65 @@ | ||
package fr.free.nrw.commons.theme | ||
|
||
import android.content.res.Configuration | ||
import android.os.Bundle | ||
import android.util.DisplayMetrics | ||
import android.view.WindowManager | ||
import javax.inject.Inject | ||
import javax.inject.Named | ||
import fr.free.nrw.commons.R | ||
import fr.free.nrw.commons.di.CommonsDaggerAppCompatActivity | ||
import fr.free.nrw.commons.kvstore.JsonKvStore | ||
import fr.free.nrw.commons.utils.SystemThemeUtils | ||
import io.reactivex.disposables.CompositeDisposable | ||
|
||
|
||
abstract class BaseActivity : CommonsDaggerAppCompatActivity() { | ||
|
||
@Inject | ||
@field:Named("default_preferences") | ||
lateinit var defaultKvStore: JsonKvStore | ||
|
||
@Inject | ||
lateinit var systemThemeUtils: SystemThemeUtils | ||
|
||
protected val compositeDisposable = CompositeDisposable() | ||
protected var wasPreviouslyDarkTheme: Boolean = false | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
wasPreviouslyDarkTheme = systemThemeUtils.isDeviceInNightMode() | ||
setTheme(if (wasPreviouslyDarkTheme) R.style.DarkAppTheme else R.style.LightAppTheme) | ||
|
||
val fontScale = android.provider.Settings.System.getFloat( | ||
baseContext.contentResolver, | ||
android.provider.Settings.System.FONT_SCALE, | ||
1f | ||
) | ||
adjustFontScale(resources.configuration, fontScale) | ||
} | ||
|
||
override fun onResume() { | ||
// Restart activity if theme is changed | ||
if (wasPreviouslyDarkTheme != systemThemeUtils.isDeviceInNightMode()) { | ||
recreate() | ||
} | ||
super.onResume() | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
compositeDisposable.clear() | ||
} | ||
|
||
/** | ||
* Apply fontScale on device | ||
*/ | ||
fun adjustFontScale(configuration: Configuration, scale: Float) { | ||
configuration.fontScale = scale | ||
val metrics = resources.displayMetrics | ||
val wm = getSystemService(WINDOW_SERVICE) as WindowManager | ||
wm.defaultDisplay.getMetrics(metrics) | ||
metrics.scaledDensity = configuration.fontScale * metrics.density | ||
baseContext.resources.updateConfiguration(configuration, metrics) | ||
} | ||
} |
65 changes: 0 additions & 65 deletions
65
app/src/main/java/fr/free/nrw/commons/ui/PasteSensitiveTextInputEditText.java
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
app/src/main/java/fr/free/nrw/commons/ui/PasteSensitiveTextInputEditText.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,60 @@ | ||
package fr.free.nrw.commons.ui | ||
|
||
import android.content.Context | ||
import android.content.res.TypedArray | ||
import android.os.Build | ||
import android.os.Build.VERSION | ||
import android.util.AttributeSet | ||
import com.google.android.material.textfield.TextInputEditText | ||
import fr.free.nrw.commons.R | ||
|
||
|
||
class PasteSensitiveTextInputEditText @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null | ||
) : TextInputEditText(context, attrs) { | ||
|
||
private var formattingAllowed: Boolean = true | ||
|
||
init { | ||
if (attrs != null) { | ||
formattingAllowed = extractFormattingAttribute(context, attrs) | ||
} | ||
} | ||
|
||
override fun onTextContextMenuItem(id: Int): Boolean { | ||
// if not paste command, or formatting is allowed, return default | ||
if (id != android.R.id.paste || formattingAllowed) { | ||
return super.onTextContextMenuItem(id) | ||
} | ||
|
||
// if it's paste and formatting not allowed | ||
val proceeded: Boolean = if (VERSION.SDK_INT >= 23) { | ||
super.onTextContextMenuItem(android.R.id.pasteAsPlainText) | ||
} else { | ||
val success = super.onTextContextMenuItem(id) | ||
if (success && text != null) { | ||
// rewrite with plain text so formatting is lost | ||
setText(text.toString()) | ||
setSelection(text?.length ?: 0) | ||
} | ||
success | ||
} | ||
return proceeded | ||
} | ||
|
||
private fun extractFormattingAttribute(context: Context, attrs: AttributeSet): Boolean { | ||
val a = context.theme.obtainStyledAttributes( | ||
attrs, R.styleable.PasteSensitiveTextInputEditText, 0, 0 | ||
) | ||
return try { | ||
a.getBoolean(R.styleable.PasteSensitiveTextInputEditText_allowFormatting, true) | ||
} finally { | ||
a.recycle() | ||
} | ||
} | ||
|
||
fun setFormattingAllowed(formattingAllowed: Boolean) { | ||
this.formattingAllowed = formattingAllowed | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
app/src/main/java/fr/free/nrw/commons/ui/widget/HtmlTextView.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.