Skip to content

Commit

Permalink
Merge pull request #3 from JunkFood02/dev
Browse files Browse the repository at this point in the history
Match & paste for url in clipboard
  • Loading branch information
JunkFood02 authored Apr 21, 2022
2 parents c5d3406 + 7c5b166 commit 27e9ba1
Show file tree
Hide file tree
Showing 32 changed files with 101 additions and 52 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
def versionMajor = 0
def versionMinor = 0
def versionPatch = 3
def versionBuild = 1
def versionBuild = 2

android {
compileSdk 32
Expand Down
41 changes: 20 additions & 21 deletions app/src/main/java/com/junkfood/seal/BaseApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.junkfood.seal

import android.annotation.SuppressLint
import android.app.Application
import android.content.ClipboardManager
import android.content.Context
import android.os.Build
import android.os.Environment
Expand All @@ -26,6 +27,7 @@ class BaseApplication : Application() {
super.onCreate()

DynamicColors.applyToActivitiesIfAvailable(this)
clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
try {
YoutubeDL.getInstance().init(this)
FFmpeg.getInstance().init(this)
Expand Down Expand Up @@ -63,13 +65,9 @@ class BaseApplication : Application() {
}


fun printErrorLog(th: Throwable) {

}


companion object {
private const val TAG = "BaseApplication"
lateinit var clipboard: ClipboardManager
lateinit var downloadDir: String
fun updateDownloadDir() {
downloadDir = File(
Expand All @@ -79,25 +77,26 @@ class BaseApplication : Application() {
}

fun createLogFileOnDevice(th: Throwable) {
with(context.getExternalFilesDir(null)){
if (this?.canWrite() == true) {
val timeNow: String =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
LocalDateTime.now()
.format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"))
} else {
SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(Date())
with(context.getExternalFilesDir(null)) {
if (this?.canWrite() == true) {
val timeNow: String =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
LocalDateTime.now()
.format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"))
} else {
SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(Date())
}
with(File(this, "log$timeNow.txt")) {
if (!exists())
createNewFile()
val logWriter = FileWriter(this, true)
val out = BufferedWriter(logWriter)
out.append(th.stackTraceToString())
out.close()
}
with(File(this, "log$timeNow.txt")) {
if (!exists())
createNewFile()
val logWriter = FileWriter(this, true)
val out = BufferedWriter(logWriter)
out.append(th.stackTraceToString())
out.close()
}
}
}}
}

@SuppressLint("StaticFieldLeak")
lateinit var context: Context
Expand Down
31 changes: 29 additions & 2 deletions app/src/main/java/com/junkfood/seal/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.junkfood.seal.ui.home

import android.Manifest
import android.content.ClipDescription
import android.content.Intent
import android.os.*
import android.text.Editable
Expand All @@ -21,6 +22,7 @@ import com.junkfood.seal.R
import com.junkfood.seal.databinding.FragmentHomeBinding
import com.junkfood.seal.util.DownloadUtil
import java.io.File
import java.util.regex.Pattern


class HomeFragment : Fragment() {
Expand Down Expand Up @@ -110,15 +112,40 @@ class HomeFragment : Fragment() {
}
with(binding) {
inputTextUrl.editText?.setText(homeViewModel.url.value)

inputTextUrl.editText?.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
override fun afterTextChanged(p0: Editable?) {
homeViewModel.url.value = p0.toString()
}
})

pasteButton.setOnClickListener {
if (BaseApplication.clipboard.hasPrimaryClip()) {
if (BaseApplication.clipboard.primaryClipDescription?.hasMimeType(
ClipDescription.MIMETYPE_TEXT_PLAIN
) == true
) {
val item = BaseApplication.clipboard.primaryClip?.getItemAt(0)?.text
?: return@setOnClickListener
val pattern =
Pattern.compile("(http|https)://[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-.,@?^=%&:/~+#]*[\\w\\-@?^=%&/~+#])?")
with(pattern.matcher(item)) {
if (find()) {
inputTextUrl.editText?.setText(group())
Toast.makeText(
context,
getString(R.string.paste_msg),
Toast.LENGTH_SHORT
)
.show()
return@setOnClickListener
}
}
}
}
Toast.makeText(context, getString(R.string.paste_fail_msg), Toast.LENGTH_SHORT)
.show()
}
downloadButton.setOnClickListener {
activityResultLauncher.launch(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE))
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/outline_content_paste_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,2h-4.18C14.4,0.84 13.3,0 12,0S9.6,0.84 9.18,2L5,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM12,2c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM19,20L5,20L5,4h2v3h10L17,4h2v16z"/>
</vector>
65 changes: 37 additions & 28 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/inputTextUrl"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
app:layout_constraintEnd_toEndOf="parent"
Expand Down Expand Up @@ -55,40 +55,49 @@
app:layout_constraintStart_toEndOf="@id/downloadProgressBar"
app:layout_constraintTop_toTopOf="@id/downloadProgressBar" />

<!-- <androidx.appcompat.widget.SwitchCompat-->
<!-- android:id="@+id/audioSwitch"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_margin="24dp"-->
<!-- android:text="@string/extract_audio"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toBottomOf="@id/downloadProgressBar" />-->
<!-- <androidx.appcompat.widget.SwitchCompat-->
<!-- android:id="@+id/audioSwitch"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_margin="24dp"-->
<!-- android:text="@string/extract_audio"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toBottomOf="@id/downloadProgressBar" />-->

<!-- <androidx.appcompat.widget.SwitchCompat-->
<!-- android:id="@+id/thumbnailSwitch"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_margin="24dp"-->
<!-- android:text="@string/create_thumbnail"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintTop_toBottomOf="@id/downloadProgressBar" />-->
<!-- <androidx.appcompat.widget.SwitchCompat-->
<!-- android:id="@+id/thumbnailSwitch"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_margin="24dp"-->
<!-- android:text="@string/create_thumbnail"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintTop_toBottomOf="@id/downloadProgressBar" />-->

<!-- <TextView-->
<!-- android:id="@+id/downloadDirText"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_margin="24dp"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintTop_toBottomOf="@id/audioSwitch" />-->
<!-- <TextView-->
<!-- android:id="@+id/downloadDirText"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_margin="24dp"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintTop_toBottomOf="@id/audioSwitch" />-->

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/downloadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:layout_margin="24dp"
android:contentDescription="Download"
android:src="@drawable/outline_file_download_white_48"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:contentDescription="Download" />
app:layout_constraintEnd_toEndOf="parent" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/pasteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:src="@drawable/outline_content_paste_white_48"
app:layout_constraintBottom_toTopOf="@id/downloadButton"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
<string name="language_settings">设置界面语言</string>
<string name="language_settings_msg">此项设置将在应用重启后生效</string>
<string name="task_running">已有正在运行中的下载任务</string>
<string name="paste_msg">从剪贴板获取视频链接</string>
<string name="paste_fail_msg">未在剪贴板中匹配到视频链接</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@
<string name="language_settings">Set display language</string>
<string name="language_settings_msg">This preference would take effect after app restart</string>
<string name="task_running">An existing download task is already running</string>
<string name="paste_msg">Paste url from clipboard</string>
<string name="paste_fail_msg">Unable to match url in clipboard</string>
"
</resources>

0 comments on commit 27e9ba1

Please sign in to comment.