diff --git a/app/build.gradle b/app/build.gradle index dbea0279..c0b9ce2a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -123,10 +123,10 @@ dependencies { implementation "androidx.appcompat:appcompat:$appCompatVer" 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.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.navigation:navigation-fragment-ktx:2.5.3" implementation "androidx.navigation:navigation-ui-ktx:2.5.3" @@ -137,7 +137,7 @@ dependencies { androidTestImplementation "junit:junit:$junitVer" androidTestImplementation "androidx.test.ext:junit:$androidJunitVer" 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:core:1.5.0" androidTestImplementation "androidx.test:rules:1.5.0" diff --git a/app/src/main/java/com/deniscerri/ytdlnis/database/viewmodel/CommandTemplateViewModel.kt b/app/src/main/java/com/deniscerri/ytdlnis/database/viewmodel/CommandTemplateViewModel.kt index e2176126..27c823e3 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/database/viewmodel/CommandTemplateViewModel.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/database/viewmodel/CommandTemplateViewModel.kt @@ -101,18 +101,22 @@ class CommandTemplateViewModel(private val application: Application) : AndroidVi fun exportToClipboard() = viewModelScope.launch(Dispatchers.IO) { - val allTemplates = repository.getAll() - val allShortcuts = repository.getAllShortCuts() - val output = jsonFormat.encodeToString( - CommandTemplateExport( + try{ + val allTemplates = repository.getAll() + val allShortcuts = repository.getAllShortCuts() + val output = jsonFormat.encodeToString( + CommandTemplateExport( templates = allTemplates, shortcuts = allShortcuts ) ) - val clipboard: ClipboardManager = - application.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager - clipboard.setText(output) + val clipboard: ClipboardManager = + application.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager + clipboard.setText(output) + }catch (e: Exception){ + e.printStackTrace() + } } } \ No newline at end of file diff --git a/app/src/main/java/com/deniscerri/ytdlnis/ui/HomeFragment.kt b/app/src/main/java/com/deniscerri/ytdlnis/ui/HomeFragment.kt index 9515dec6..05f50667 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/ui/HomeFragment.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/ui/HomeFragment.kt @@ -215,24 +215,29 @@ class HomeFragment : Fragment(), HomeAdapter.OnItemClickListener, View.OnClickLi val linkYouCopied = searchView.findViewById(R.id.link_you_copied) searchView.addTransitionListener { view, previousState, newState -> if (newState == SearchView.TransitionState.SHOWN) { - val clipboard = - requireContext().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager - val regex = - "(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 clip = clipboard.primaryClip!!.getItemAt(0).text - if (regex.containsMatchIn(clip.toString())) { - linkYouCopied.visibility = VISIBLE - val textView = linkYouCopied.findViewById(R.id.suggestion_text) - textView.text = getString(R.string.link_you_copied) - textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_language, 0, 0, 0) - val mb = linkYouCopied.findViewById(R.id.set_search_query_button) - mb.visibility = INVISIBLE + try{ + val clipboard = + requireContext().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager + val regex = + "(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 clip = clipboard.primaryClip!!.getItemAt(0).text + if (regex.containsMatchIn(clip.toString())) { + linkYouCopied.visibility = VISIBLE + val textView = linkYouCopied.findViewById(R.id.suggestion_text) + textView.text = getString(R.string.link_you_copied) + textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_language, 0, 0, 0) + val mb = linkYouCopied.findViewById(R.id.set_search_query_button) + mb.visibility = INVISIBLE - textView.setOnClickListener { - searchView.setText(clip.toString()) - initSearch(searchView) + textView.setOnClickListener { + searchView.setText(clip.toString()) + initSearch(searchView) + } + }else{ + linkYouCopied.visibility = GONE } - }else{ + }catch (e: Exception){ + e.printStackTrace() linkYouCopied.visibility = GONE } } @@ -289,7 +294,9 @@ class HomeFragment : Fragment(), HomeAdapter.OnItemClickListener, View.OnClickLi } } searchHistoryLinearLayout!!.visibility = VISIBLE - linkYouCopied!!.visibility = VISIBLE + if (linkYouCopied.findViewById(R.id.suggestion_text).text.isNotEmpty()){ + linkYouCopied.visibility = VISIBLE + } }else{ for (i in suggestions.indices) { val v = LayoutInflater.from(fragmentContext)