Skip to content

Commit

Permalink
Video player integration should now fixed
Browse files Browse the repository at this point in the history
App uninstall dialog would appear
  • Loading branch information
EmiyaSyahriel committed Nov 26, 2020
1 parent ee99844 commit 170b87f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 29 deletions.
12 changes: 9 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
package="id.psw.vshlauncher">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- Tell if touchscreen can be used but is not required -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<!-- Needed for the app to uninstall packages -->
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />

<!-- Tell if touchscreen can be used but is not required -->
<uses-feature
android:name="android.software.leanback"
android:required="false" /> <!-- Tell if touchscreen can be used but is not required -->
android:required="false" />
<!-- Tell if touchscreen can be used but is not required -->
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
Expand All @@ -26,7 +32,7 @@
<service
android:name=".mediaplayer.XMBAudioPlayerService"
android:enabled="true"
android:exported="true"></service>
android:exported="true"/>
<!-- Some attribute is unused on older version of Android, most of them were safe to ignore -->
<activity
android:name=".mediaplayer.XMBVideoPlayer"
Expand Down
21 changes: 6 additions & 15 deletions app/src/main/java/id/psw/vshlauncher/VSH.kt
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,6 @@ class VSH : AppCompatActivity(), VshDialogView.IDialogBackable {
return if(this) getString(R.string.common_yes) else getString(R.string.common_no)
}

private fun launchURL(url:String){
try{
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
}catch(e: PackageManager.NameNotFoundException){
Toast.makeText(this, "No default browser found in device.", Toast.LENGTH_SHORT).show()
}
}

private fun populateSettingSections(){
val settings = vsh.findById("SETT") ?: return

Expand Down Expand Up @@ -349,8 +341,7 @@ class VSH : AppCompatActivity(), VshDialogView.IDialogBackable {
val alert = VshDialogView(this)
alert.buttons.clear()
alert.buttons.add(VshDialogView.Button("OK", Runnable {
val thread = Thread(Runnable { loadApps() })
thread.start()
val thread = runOnOtherThread { loadApps() }
setContentView(vsh)
}))
alert.buttons.add(
Expand Down Expand Up @@ -485,11 +476,11 @@ class VSH : AppCompatActivity(), VshDialogView.IDialogBackable {
vsh.clockAsLoadingIndicator = false
}

fun uninstallApp(packageName: String){
val intent = Intent(Intent.ACTION_DELETE, Uri.fromParts("package", packageName, null))
startActivity(intent)
Timer("Uninstaller", true).schedule(5000){
Thread(Runnable {loadApps()}).start()
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when(requestCode){
// Reload when uninstall is requested
UNINSTALL_REQ_CODE -> if(resultCode == RESULT_OK) runOnOtherThread { loadApps() }
}
}

Expand Down
36 changes: 31 additions & 5 deletions app/src/main/java/id/psw/vshlauncher/VshActivityExtension.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
package id.psw.vshlauncher

import android.graphics.PointF
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.widget.Toast

/**
* A file that contains extensions for the main VSH Activity
* Due to the main class is too bloated for my PC to load
*/
val NOPE = 0

fun VSH.loadExtension(){
/** Does nothing */
val UNINSTALL_REQ_CODE : Int get() = 29734

fun VSH.uninstallApp(packageName:String){
try{
val intent = Intent(Intent.ACTION_DELETE)
intent.data = Uri.fromParts("package", packageName, null)
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
startActivityForResult(intent, UNINSTALL_REQ_CODE)
}catch(e:Exception){
Toast.makeText(this, "Failed to uninstall app: ${e.message}", Toast.LENGTH_LONG).show()
}
}

fun VSH.isPointInsideOption(touchPoint: PointF){
fun VSH.runOnOtherThread(what : () -> Unit) : Thread {
val thr = Thread {
what.invoke()
}

thr.start()
return thr
}

}
fun VSH.launchURL(url:String){
try{
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
}catch(e: PackageManager.NameNotFoundException){
Toast.makeText(this, "No default browser found in device.", Toast.LENGTH_SHORT).show()
}
}
8 changes: 2 additions & 6 deletions app/src/main/java/id/psw/vshlauncher/icontypes/AppIcon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import android.graphics.Bitmap
import android.net.Uri
import android.widget.Toast
import androidx.core.graphics.drawable.toBitmap
import id.psw.vshlauncher.VSH
import id.psw.vshlauncher.VshY
import id.psw.vshlauncher.toSize
import id.psw.vshlauncher.*
import java.io.File
import java.text.SimpleDateFormat
import java.time.format.DateTimeFormatter
Expand Down Expand Up @@ -135,9 +133,7 @@ class AppIcon(private var context: VSH, itemID: Int, private var resolveInfo: Re

private fun openOnPlayStore(){
try{
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse("http://play.google.com/store/apps/details?id=${packageName}")
context.startActivity(i)
context.launchURL("http://play.google.com/store/apps/details?id=${packageName}")
}catch (e:Exception){
Toast.makeText(context, "Cannot open play store for the specified application", Toast.LENGTH_LONG).show()
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/id/psw/vshlauncher/icontypes/VideoIcon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.graphics.Point
import android.media.ThumbnailUtils
import android.net.Uri
import android.provider.MediaStore
import android.widget.Toast
import android.widget.VideoView
import androidx.core.graphics.scale
import id.psw.vshlauncher.*
Expand Down Expand Up @@ -53,6 +54,7 @@ class VideoIcon(itemID:Int, private val vsh: VSH, private val path: String) : Vs
loadVideoPreview()
thumbnailStart = 0
thumbnailEnd = 30000
isValid=true
VideoMetadata(itemID, file, fileName, size, albumArt)
}catch(e:Exception){
e.printStackTrace()
Expand Down Expand Up @@ -161,6 +163,8 @@ class VideoIcon(itemID:Int, private val vsh: VSH, private val path: String) : Vs
if(isValid){
val uri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, metadata.id.toString())
vsh.openVideoFile(metadata.file!!)
}else{
Toast.makeText(vsh, "Invalid video file", Toast.LENGTH_LONG).show()
}
}

Expand Down

0 comments on commit 170b87f

Please sign in to comment.