small touchups

This commit is contained in:
deniscerri 2023-03-18 18:40:47 +01:00
parent 678571685e
commit 800b82b7bd
No known key found for this signature in database
GPG key ID: 95C43D517D830350
3 changed files with 38 additions and 27 deletions

View file

@ -123,10 +123,10 @@ dependencies {
implementation "androidx.appcompat:appcompat:$appCompatVer" implementation "androidx.appcompat:appcompat:$appCompatVer"
implementation "androidx.constraintlayout:constraintlayout:2.1.4" implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation 'com.google.android.material:material:1.9.0-alpha02' implementation 'com.google.android.material:material:1.9.0-beta01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.core:core:1.9.0' implementation 'androidx.core:core:1.9.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'androidx.preference:preference:1.2.0' implementation 'androidx.preference:preference:1.2.0'
implementation "androidx.navigation:navigation-fragment-ktx:2.5.3" implementation "androidx.navigation:navigation-fragment-ktx:2.5.3"
implementation "androidx.navigation:navigation-ui-ktx:2.5.3" implementation "androidx.navigation:navigation-ui-ktx:2.5.3"
@ -137,7 +137,7 @@ dependencies {
androidTestImplementation "junit:junit:$junitVer" androidTestImplementation "junit:junit:$junitVer"
androidTestImplementation "androidx.test.ext:junit:$androidJunitVer" androidTestImplementation "androidx.test.ext:junit:$androidJunitVer"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVer" androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVer"
androidTestImplementation "androidx.benchmark:benchmark-macro-junit4:1.2.0-alpha10" androidTestImplementation "androidx.benchmark:benchmark-macro-junit4:1.2.0-alpha11"
androidTestImplementation "androidx.test:runner:1.5.2" androidTestImplementation "androidx.test:runner:1.5.2"
androidTestImplementation "androidx.test:core:1.5.0" androidTestImplementation "androidx.test:core:1.5.0"
androidTestImplementation "androidx.test:rules:1.5.0" androidTestImplementation "androidx.test:rules:1.5.0"

View file

@ -101,18 +101,22 @@ class CommandTemplateViewModel(private val application: Application) : AndroidVi
fun exportToClipboard() = viewModelScope.launch(Dispatchers.IO) { fun exportToClipboard() = viewModelScope.launch(Dispatchers.IO) {
val allTemplates = repository.getAll() try{
val allShortcuts = repository.getAllShortCuts() val allTemplates = repository.getAll()
val output = jsonFormat.encodeToString( val allShortcuts = repository.getAllShortCuts()
CommandTemplateExport( val output = jsonFormat.encodeToString(
CommandTemplateExport(
templates = allTemplates, templates = allTemplates,
shortcuts = allShortcuts shortcuts = allShortcuts
) )
) )
val clipboard: ClipboardManager = val clipboard: ClipboardManager =
application.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager application.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setText(output) clipboard.setText(output)
}catch (e: Exception){
e.printStackTrace()
}
} }
} }

View file

@ -215,24 +215,29 @@ class HomeFragment : Fragment(), HomeAdapter.OnItemClickListener, View.OnClickLi
val linkYouCopied = searchView.findViewById<ConstraintLayout>(R.id.link_you_copied) val linkYouCopied = searchView.findViewById<ConstraintLayout>(R.id.link_you_copied)
searchView.addTransitionListener { view, previousState, newState -> searchView.addTransitionListener { view, previousState, newState ->
if (newState == SearchView.TransitionState.SHOWN) { if (newState == SearchView.TransitionState.SHOWN) {
val clipboard = try{
requireContext().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager val clipboard =
val regex = requireContext().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
"(https?://(?:www\\.|(?!www))[a-zA-Z\\d][a-zA-Z\\d-]+[a-zA-Z\\d]\\.\\S{2,}|www\\.[a-zA-Z\\d][a-zA-Z\\d-]+[a-zA-Z\\d]\\.\\S{2,}|https?://(?:www\\.|(?!www))[a-zA-Z\\d]+\\.\\S{2,}|www\\.[a-zA-Z\\d]+\\.\\S{2,})".toRegex() val regex =
val clip = clipboard.primaryClip!!.getItemAt(0).text "(https?://(?:www\\.|(?!www))[a-zA-Z\\d][a-zA-Z\\d-]+[a-zA-Z\\d]\\.\\S{2,}|www\\.[a-zA-Z\\d][a-zA-Z\\d-]+[a-zA-Z\\d]\\.\\S{2,}|https?://(?:www\\.|(?!www))[a-zA-Z\\d]+\\.\\S{2,}|www\\.[a-zA-Z\\d]+\\.\\S{2,})".toRegex()
if (regex.containsMatchIn(clip.toString())) { val clip = clipboard.primaryClip!!.getItemAt(0).text
linkYouCopied.visibility = VISIBLE if (regex.containsMatchIn(clip.toString())) {
val textView = linkYouCopied.findViewById<TextView>(R.id.suggestion_text) linkYouCopied.visibility = VISIBLE
textView.text = getString(R.string.link_you_copied) val textView = linkYouCopied.findViewById<TextView>(R.id.suggestion_text)
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_language, 0, 0, 0) textView.text = getString(R.string.link_you_copied)
val mb = linkYouCopied.findViewById<ImageButton>(R.id.set_search_query_button) textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_language, 0, 0, 0)
mb.visibility = INVISIBLE val mb = linkYouCopied.findViewById<ImageButton>(R.id.set_search_query_button)
mb.visibility = INVISIBLE
textView.setOnClickListener { textView.setOnClickListener {
searchView.setText(clip.toString()) searchView.setText(clip.toString())
initSearch(searchView) initSearch(searchView)
}
}else{
linkYouCopied.visibility = GONE
} }
}else{ }catch (e: Exception){
e.printStackTrace()
linkYouCopied.visibility = GONE linkYouCopied.visibility = GONE
} }
} }
@ -289,7 +294,9 @@ class HomeFragment : Fragment(), HomeAdapter.OnItemClickListener, View.OnClickLi
} }
} }
searchHistoryLinearLayout!!.visibility = VISIBLE searchHistoryLinearLayout!!.visibility = VISIBLE
linkYouCopied!!.visibility = VISIBLE if (linkYouCopied.findViewById<TextView>(R.id.suggestion_text).text.isNotEmpty()){
linkYouCopied.visibility = VISIBLE
}
}else{ }else{
for (i in suggestions.indices) { for (i in suggestions.indices) {
val v = LayoutInflater.from(fragmentContext) val v = LayoutInflater.from(fragmentContext)