...
This commit is contained in:
@@ -377,7 +377,7 @@ internal class AppDrawer : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
appQuery = newQ.sort(Pair("clickCount", Sort.DESCENDING),Pair("lastUseDate",Sort.DESCENDING)).limit(20).find()
|
||||
appQuery = newQ.sort(Pair("clickCount", Sort.DESCENDING),Pair("lastUseDate",Sort.DESCENDING)).limit(18).find()
|
||||
appQuery?.let {
|
||||
if(it.size > 0) {
|
||||
WorkersDb.getRealm().apply {
|
||||
@@ -416,7 +416,7 @@ internal class AppDrawer : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
contactQuery = newQ.sort(Pair("touchCount", Sort.DESCENDING),Pair("lastedTouchDateTime",Sort.DESCENDING)).find()
|
||||
contactQuery = newQ.sort(Pair("touchCount", Sort.DESCENDING),Pair("lastedTouchDateTime",Sort.DESCENDING)).limit(18).find()
|
||||
contactQuery?.let {
|
||||
if (it.size > 0)
|
||||
WorkersDb.getRealm().apply {
|
||||
|
||||
@@ -50,6 +50,7 @@ import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.button.MaterialButtonToggleGroup
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.gson.Gson
|
||||
import io.realm.kotlin.ext.query
|
||||
import rasel.lunar.launcher.LauncherActivity.Companion.lActivity
|
||||
import rasel.lunar.launcher.R
|
||||
import rasel.lunar.launcher.apps.AppDrawer.Companion.appNamesPrefs
|
||||
@@ -62,7 +63,9 @@ import rasel.lunar.launcher.helpers.Constants.Companion.PREFS_FAVORITE_APPS
|
||||
import rasel.lunar.launcher.helpers.UniUtils.Companion.copyToClipboard
|
||||
import rasel.lunar.launcher.helpers.UniUtils.Companion.screenHeight
|
||||
import rasel.lunar.launcher.helpers.UniUtils.Companion.screenWidth
|
||||
import rasel.lunar.launcher.model.AppInfo
|
||||
import rasel.lunar.launcher.utils.BLog
|
||||
import rasel.lunar.launcher.workers.WorkersDb
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
@@ -96,7 +99,36 @@ internal class AppMenu : BottomSheetDialogFragment() {
|
||||
/* get default app name */
|
||||
defAppName = packageManager.resolveActivity(Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
.setPackage(packageName), 0)?.loadLabel(packageManager).toString()
|
||||
WorkersDb.getRealm().apply {
|
||||
writeBlocking {
|
||||
var result = query<AppInfo>("pkgName == $0",packageName).find()
|
||||
if(result.size > 0) {
|
||||
val app = result.first()
|
||||
binding.totalTouch.text = "총 실행 횟수 : ".plus(app.clickCount.toString())
|
||||
binding.lastTouchDate.text = "최종 실행 일시 : ".plus(SimpleDateFormat("yyyy-MM-dd HH:mm").format(Date(app.lastUseDate)))
|
||||
// app.clickCount = app.clickCount + 15
|
||||
|
||||
// app.lastUseDate = Math.max(app.lastUseDate, System.currentTimeMillis())
|
||||
// app.clickCount = app.clickCount + 15
|
||||
// app.lastUseDate = Math.max(app.lastUseDate, System.currentTimeMillis())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun update() {
|
||||
WorkersDb.getRealm().apply {
|
||||
writeBlocking {
|
||||
var result = query<AppInfo>("pkgName == $0",packageName).find()
|
||||
if(result.size > 0) {
|
||||
val app = result.first()
|
||||
app.clickCount = app.clickCount + 15
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.totalTouch.setOnClickListener { update() }
|
||||
binding.lastTouchDate.setOnClickListener { update() }
|
||||
/* set application name and package name */
|
||||
binding.appName.apply {
|
||||
setText(appNamesPrefs?.getString(packageName, defAppName))
|
||||
@@ -104,9 +136,6 @@ internal class AppMenu : BottomSheetDialogFragment() {
|
||||
|
||||
}
|
||||
binding.appPackage.text = packageName
|
||||
/* favorite apps */
|
||||
favoriteApps()
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@@ -129,56 +158,7 @@ internal class AppMenu : BottomSheetDialogFragment() {
|
||||
binding.appUninstall.setOnClickListener { uninstall() }
|
||||
}
|
||||
|
||||
/* manage initial preview and clicks for favorite apps */
|
||||
@SuppressLint("PrivateResource")
|
||||
private fun favoriteApps() {
|
||||
val sharedPreferences = requireContext().getSharedPreferences(PREFS_FAVORITE_APPS, 0)
|
||||
val enabledStroke =
|
||||
ColorStateList.valueOf(requireContext().getColor(com.google.android.material.R.color.material_on_surface_stroke))
|
||||
val disabledStroke =
|
||||
ColorStateList.valueOf(requireContext().getColor(com.google.android.material.R.color.m3_chip_stroke_color))
|
||||
|
||||
for (position in 1..MAX_FAVORITE_APPS) {
|
||||
val button = outlinedButton
|
||||
val savedPackageName = sharedPreferences.getString(KEY_APP_NO_ + position, "")
|
||||
|
||||
/* set previews */
|
||||
if (packageName == savedPackageName) button.isChecked = true
|
||||
if (savedPackageName?.isNotEmpty() == true) button.strokeColor = enabledStroke
|
||||
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
|
||||
packageManager.getPackageInfo(savedPackageName!!, PackageManager.PackageInfoFlags.of(0))
|
||||
else
|
||||
packageManager.getPackageInfo(savedPackageName!!, 0)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
requireContext().getSharedPreferences(PREFS_FAVORITE_APPS, 0)
|
||||
.edit().remove(KEY_APP_NO_ + position).apply()
|
||||
button.strokeColor = disabledStroke
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
/* listen on clicks */
|
||||
binding.favGroup.addOnButtonCheckedListener { _: MaterialButtonToggleGroup?,
|
||||
checkedId: Int, isChecked: Boolean ->
|
||||
try {
|
||||
if (checkedId == button.id) {
|
||||
if (isChecked) {
|
||||
requireContext().getSharedPreferences(PREFS_FAVORITE_APPS, 0)
|
||||
.edit().putString(KEY_APP_NO_ + position, packageName).apply()
|
||||
button.strokeColor = enabledStroke
|
||||
} else {
|
||||
requireContext().getSharedPreferences(PREFS_FAVORITE_APPS, 0)
|
||||
.edit().remove(KEY_APP_NO_ + position).apply()
|
||||
button.strokeColor = disabledStroke
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun appName() {
|
||||
binding.appName.setOnFocusChangeListener { _, hasFocus ->
|
||||
@@ -234,10 +214,10 @@ internal class AppMenu : BottomSheetDialogFragment() {
|
||||
/* show infos */
|
||||
dialogBinding.mixed.text =
|
||||
"${resources.getString(R.string.version)}: ${packageInfo.versionName} (${PackageInfoCompat.getLongVersionCode(packageInfo).toInt()})\n" +
|
||||
"${resources.getString(R.string.sdk)}: ${appInfo.minSdkVersion} ~ ${appInfo.targetSdkVersion}\n" +
|
||||
"${resources.getString(R.string.uid)}: ${appInfo.uid}\n" +
|
||||
"${resources.getString(R.string.first_install)}: ${dateTimeFormat(packageInfo.firstInstallTime)}\n" +
|
||||
"${resources.getString(R.string.last_update)}: ${dateTimeFormat(packageInfo.lastUpdateTime)}"
|
||||
"${resources.getString(R.string.sdk)}: ${appInfo.minSdkVersion} ~ ${appInfo.targetSdkVersion}\n" +
|
||||
"${resources.getString(R.string.uid)}: ${appInfo.uid}\n" +
|
||||
"${resources.getString(R.string.first_install)}: ${dateTimeFormat(packageInfo.firstInstallTime)}\n" +
|
||||
"${resources.getString(R.string.last_update)}: ${dateTimeFormat(packageInfo.lastUpdateTime)}"
|
||||
|
||||
/* show permissions */
|
||||
dialogBinding.permissions.text = permissionsList
|
||||
@@ -382,18 +362,6 @@ internal class AppMenu : BottomSheetDialogFragment() {
|
||||
this.dismiss()
|
||||
}
|
||||
|
||||
/* create and add an outlined button to the toggle group */
|
||||
private val outlinedButton: MaterialButton get() {
|
||||
val style = com.google.android.material.R.attr.materialButtonOutlinedStyle
|
||||
val button = MaterialButton(requireContext(), null, style)
|
||||
button.layoutParams = LinearLayoutCompat.LayoutParams(
|
||||
LinearLayoutCompat.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayoutCompat.LayoutParams.WRAP_CONTENT, 1F
|
||||
)
|
||||
binding.favGroup.addView(button)
|
||||
return button
|
||||
}
|
||||
|
||||
/* long value to local date-time format */
|
||||
private fun dateTimeFormat(long: Long) : String = SimpleDateFormat.getDateTimeInstance().format(Date(long))
|
||||
|
||||
|
||||
@@ -93,6 +93,16 @@ internal class AppsAdapter(
|
||||
|
||||
/* on long click - open app menu */
|
||||
setOnLongClickListener {
|
||||
WorkersDb.getRealm().apply {
|
||||
writeBlocking {
|
||||
var result = query<AppInfo>("pkgName == $0",item.pkgName).find()
|
||||
if(result.size > 0) {
|
||||
val app = result.first()
|
||||
app.clickCount = app.clickCount + 15
|
||||
app.lastUseDate = Math.max(app.lastUseDate, System.currentTimeMillis())
|
||||
}
|
||||
}
|
||||
}
|
||||
AppMenu().apply {
|
||||
}.show(fragmentManager, item.pkgName)
|
||||
true
|
||||
|
||||
@@ -26,12 +26,14 @@ import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.realm.kotlin.ext.query
|
||||
import io.realm.kotlin.types.RealmObject
|
||||
import io.realm.kotlin.types.annotations.PrimaryKey
|
||||
import rasel.lunar.launcher.databinding.ContactItemBinding
|
||||
import rasel.lunar.launcher.utils.BLog
|
||||
import rasel.lunar.launcher.utils.JamoUtils
|
||||
import rasel.lunar.launcher.workers.RecentCallGetter
|
||||
import rasel.lunar.launcher.workers.WorkersDb
|
||||
import java.util.Date
|
||||
|
||||
|
||||
@@ -62,11 +64,22 @@ internal class ContactAdapter (
|
||||
holder.view.root.apply {
|
||||
/* on click - open app */
|
||||
setOnClickListener {
|
||||
|
||||
ContactMenu().show(fragmentManager, item.id.toString())
|
||||
}
|
||||
|
||||
/* on long click - open app menu */
|
||||
setOnLongClickListener {
|
||||
WorkersDb.getRealm().writeBlocking {
|
||||
if (item.id!=null && item.id?.length ?: 0 > 0) {
|
||||
val result = query<SimpleContact>().query("id == $0", item.id).find()
|
||||
if(result.size > 0){
|
||||
var contact = result.first()
|
||||
contact.touchCount = contact.touchCount + 1
|
||||
contact.lastedTouchDateTime = System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
}
|
||||
// BLog.LOGE("item.id.toString() >> ${item.id.toString()}")
|
||||
ContactMenu().show(fragmentManager, item.id.toString())
|
||||
true
|
||||
|
||||
@@ -18,65 +18,63 @@
|
||||
|
||||
package rasel.lunar.launcher.apps
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.ActivityOptions
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Rect
|
||||
import android.icu.text.SimpleDateFormat
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.ContactsContract
|
||||
import android.provider.Settings
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.widget.LinearLayoutCompat
|
||||
import androidx.core.content.FileProvider
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.button.MaterialButtonToggleGroup
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import io.realm.kotlin.ext.query
|
||||
import rasel.lunar.launcher.LauncherActivity.Companion.lActivity
|
||||
import rasel.lunar.launcher.R
|
||||
import rasel.lunar.launcher.databinding.ActivityBrowserDialogBinding
|
||||
import rasel.lunar.launcher.databinding.ContactMenuBinding
|
||||
import rasel.lunar.launcher.helpers.Constants.Companion.KEY_APP_NO_
|
||||
import rasel.lunar.launcher.helpers.Constants.Companion.MAX_FAVORITE_APPS
|
||||
import rasel.lunar.launcher.helpers.Constants.Companion.PREFS_FAVORITE_APPS
|
||||
import rasel.lunar.launcher.helpers.UniUtils.Companion.screenHeight
|
||||
import rasel.lunar.launcher.helpers.UniUtils.Companion.screenWidth
|
||||
import rasel.lunar.launcher.utils.BLog
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import rasel.lunar.launcher.workers.WorkersDb
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
|
||||
|
||||
internal class ContactMenu : BottomSheetDialogFragment() {
|
||||
|
||||
private lateinit var binding: ContactMenuBinding
|
||||
private lateinit var packageName: String
|
||||
private lateinit var packageManager: PackageManager
|
||||
private lateinit var appInfo: ApplicationInfo
|
||||
private lateinit var defAppName: String
|
||||
private lateinit var contactId: String
|
||||
|
||||
var contactName : String = ""
|
||||
var contactPhoneNumber : String = ""
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = ContactMenuBinding.inflate(inflater, container, false)
|
||||
|
||||
/* get package name from fragment's tag */
|
||||
packageName = tag.toString()
|
||||
contactId = tag.toString()
|
||||
|
||||
WorkersDb.getRealm().writeBlocking {
|
||||
if (contactId != null && contactId.length ?: 0 > 0) {
|
||||
val result = query<SimpleContact>().query("id == $0", contactId).find()
|
||||
if(result.size > 0){
|
||||
var contact = result.first()
|
||||
binding.totalTouch.text = "총 연락 횟수 : ".plus(contact.touchCount.toString())
|
||||
binding.lastTouchDate.text = "마지막 연락 시간 : ".plus(SimpleDateFormat("yyyy-MM-dd HH:mm").format(Date(contact.lastedTouchDateTime)))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun update() {
|
||||
WorkersDb.getRealm().writeBlocking {
|
||||
if (contactId != null && contactId.length ?: 0 > 0) {
|
||||
val result = query<SimpleContact>().query("id == $0", contactId).find()
|
||||
if(result.size > 0){
|
||||
var contact = result.first()
|
||||
contact.touchCount = contact.touchCount + 15
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.totalTouch.setOnClickListener { update() }
|
||||
binding.lastTouchDate.setOnClickListener { update() }
|
||||
|
||||
val resolver = lActivity!!.contentResolver
|
||||
val phoneUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI
|
||||
val projection = arrayOf(
|
||||
@@ -84,9 +82,9 @@ internal class ContactMenu : BottomSheetDialogFragment() {
|
||||
ContactsContract.CommonDataKinds.Phone.NUMBER,
|
||||
)
|
||||
|
||||
BLog.LOGE("GetContact", "packageName ${packageName}")
|
||||
BLog.LOGE("GetContact", "packageName ${contactId}")
|
||||
try {
|
||||
val cursor = resolver.query(phoneUri, projection, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + packageName, null , null)
|
||||
val cursor = resolver.query(phoneUri, projection, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null , null)
|
||||
if (cursor != null) {
|
||||
while (cursor.moveToNext()) {
|
||||
val nameIndex = cursor.getColumnIndex(projection[0])
|
||||
@@ -120,6 +118,8 @@ internal class ContactMenu : BottomSheetDialogFragment() {
|
||||
//
|
||||
appName()
|
||||
binding.detailedInfo.setOnClickListener { detailedInfo() }
|
||||
binding.call.setOnClickListener { callPhone() }
|
||||
binding.sms.setOnClickListener { sendSms() }
|
||||
// binding.activityBrowser.setOnClickListener { activityBrowser() }
|
||||
// binding.appStore.setOnClickListener { appStore() }
|
||||
// binding.appFreeform.setOnClickListener { freeform() }
|
||||
@@ -128,56 +128,7 @@ internal class ContactMenu : BottomSheetDialogFragment() {
|
||||
// binding.appUninstall.setOnClickListener { uninstall() }
|
||||
}
|
||||
|
||||
/* manage initial preview and clicks for favorite apps */
|
||||
@SuppressLint("PrivateResource")
|
||||
private fun favoriteApps() {
|
||||
val sharedPreferences = requireContext().getSharedPreferences(PREFS_FAVORITE_APPS, 0)
|
||||
val enabledStroke =
|
||||
ColorStateList.valueOf(requireContext().getColor(com.google.android.material.R.color.material_on_surface_stroke))
|
||||
val disabledStroke =
|
||||
ColorStateList.valueOf(requireContext().getColor(com.google.android.material.R.color.m3_chip_stroke_color))
|
||||
|
||||
for (position in 1..MAX_FAVORITE_APPS) {
|
||||
val button = outlinedButton
|
||||
val savedPackageName = sharedPreferences.getString(KEY_APP_NO_ + position, "")
|
||||
|
||||
/* set previews */
|
||||
if (packageName == savedPackageName) button.isChecked = true
|
||||
if (savedPackageName?.isNotEmpty() == true) button.strokeColor = enabledStroke
|
||||
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
|
||||
packageManager.getPackageInfo(savedPackageName!!, PackageManager.PackageInfoFlags.of(0))
|
||||
else
|
||||
packageManager.getPackageInfo(savedPackageName!!, 0)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
requireContext().getSharedPreferences(PREFS_FAVORITE_APPS, 0)
|
||||
.edit().remove(KEY_APP_NO_ + position).apply()
|
||||
button.strokeColor = disabledStroke
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
/* listen on clicks */
|
||||
binding.favGroup.addOnButtonCheckedListener { _: MaterialButtonToggleGroup?,
|
||||
checkedId: Int, isChecked: Boolean ->
|
||||
try {
|
||||
if (checkedId == button.id) {
|
||||
if (isChecked) {
|
||||
requireContext().getSharedPreferences(PREFS_FAVORITE_APPS, 0)
|
||||
.edit().putString(KEY_APP_NO_ + position, packageName).apply()
|
||||
button.strokeColor = enabledStroke
|
||||
} else {
|
||||
requireContext().getSharedPreferences(PREFS_FAVORITE_APPS, 0)
|
||||
.edit().remove(KEY_APP_NO_ + position).apply()
|
||||
button.strokeColor = disabledStroke
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun appName() {
|
||||
binding.appName.text = contactName
|
||||
@@ -187,195 +138,21 @@ internal class ContactMenu : BottomSheetDialogFragment() {
|
||||
|
||||
private fun detailedInfo() {
|
||||
var intent = Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(ContactsContract.Contacts.CONTENT_URI.toString() + "/" + packageName));
|
||||
intent.setData(Uri.parse(ContactsContract.Contacts.CONTENT_URI.toString() + "/" + contactId));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
/* activity browser dialog */
|
||||
private fun activityBrowser() {
|
||||
val dialogBinding = ActivityBrowserDialogBinding.inflate(lActivity!!.layoutInflater)
|
||||
val dialogBuilder = MaterialAlertDialogBuilder(lActivity!!)
|
||||
.setView(dialogBinding.root)
|
||||
.setPositiveButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
|
||||
/* show app name */
|
||||
dialogBinding.appName.text = packageManager.getApplicationLabel(appInfo)
|
||||
|
||||
/* get activity info */
|
||||
val activityInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
packageManager.getPackageInfo(
|
||||
packageName, PackageManager.PackageInfoFlags.of(PackageManager.GET_ACTIVITIES.toLong())
|
||||
)
|
||||
} else {
|
||||
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
|
||||
}
|
||||
|
||||
/* show activity list */
|
||||
val activityAdapter: ArrayAdapter<String> =
|
||||
ArrayAdapter(requireContext(), R.layout.list_item, R.id.itemText, ArrayList())
|
||||
if (activityInfo.activities.isNotEmpty()) {
|
||||
for (activity in activityInfo.activities) {
|
||||
activityAdapter.add(
|
||||
activity.toString().split(" ").toTypedArray()[1].replace("}", "")
|
||||
)
|
||||
}
|
||||
dialogBinding.activityList.adapter = activityAdapter
|
||||
}
|
||||
|
||||
/* listen item clicks */
|
||||
dialogBinding.activityList.onItemClickListener =
|
||||
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, i: Int, _: Long ->
|
||||
try {
|
||||
/* open activity */
|
||||
val intent = Intent()
|
||||
intent.component = ComponentName(packageName, activityAdapter.getItem(i).toString())
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
requireContext().startActivity(intent)
|
||||
} catch (exception: Exception) {
|
||||
/* couldn't open activity */
|
||||
exception.printStackTrace()
|
||||
val exceptionShort = (exception.toString().split(": ").toTypedArray())[0]
|
||||
Toast.makeText(requireContext(),
|
||||
"${resources.getString(R.string.unable_to_launch)} -\n$exceptionShort", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
dialogBuilder.dismiss()
|
||||
}
|
||||
private fun sendSms() {
|
||||
var intent = Intent(Intent.ACTION_SEND);
|
||||
intent.setData(Uri.parse("smsto:" + contactPhoneNumber));
|
||||
startActivity(intent);
|
||||
}
|
||||
private fun callPhone() {
|
||||
var intent = Intent(Intent.ACTION_DIAL);
|
||||
intent.setData(Uri.parse("tel:" + contactPhoneNumber));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
/* open app's page in app store/market */
|
||||
private fun appStore() {
|
||||
try {
|
||||
val storeIntent = Intent(Intent.ACTION_VIEW)
|
||||
storeIntent.data = Uri.parse("market://details?id=$packageName")
|
||||
storeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
requireContext().startActivity(storeIntent)
|
||||
} catch (activityNotFoundException: ActivityNotFoundException) {
|
||||
/* no app store found exception */
|
||||
Toast.makeText(requireContext(), requireContext().getString(R.string.null_app_store_message),
|
||||
Toast.LENGTH_SHORT).show()
|
||||
activityNotFoundException.printStackTrace()
|
||||
}
|
||||
this.dismiss()
|
||||
}
|
||||
|
||||
/* launch app as a freeform window */
|
||||
private fun freeform() {
|
||||
val freeformIntent = requireContext().packageManager.getLaunchIntentForPackage(packageName)
|
||||
freeformIntent!!.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT or
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
|
||||
val rect = Rect(0, screenHeight / 2, screenWidth, screenHeight)
|
||||
var activityOptions = activityOptions
|
||||
activityOptions = activityOptions.setLaunchBounds(rect)
|
||||
requireContext().startActivity(freeformIntent, activityOptions.toBundle())
|
||||
this.dismiss()
|
||||
}
|
||||
|
||||
/* open android's app info screen */
|
||||
private fun appInfo() {
|
||||
val infoIntent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||
infoIntent.data = Uri.parse("package:$packageName")
|
||||
infoIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
requireContext().startActivity(infoIntent)
|
||||
this.dismiss()
|
||||
}
|
||||
|
||||
private fun share() {
|
||||
try {
|
||||
// Create a temporary file to copy the APK
|
||||
val apkLabel = packageManager.getApplicationLabel(appInfo).toString().lowercase().replace(" ", "_")
|
||||
val tempApkFile = File(requireContext().externalCacheDir, "$apkLabel.apk")
|
||||
|
||||
// Copy the APK file
|
||||
FileInputStream(File(appInfo.sourceDir)).use { `in` ->
|
||||
FileOutputStream(tempApkFile).use { out ->
|
||||
val buffer = ByteArray(1024)
|
||||
var length: Int
|
||||
while (`in`.read(buffer).also { length = it } > 0) {
|
||||
out.write(buffer, 0, length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a content URI using FileProvider
|
||||
val contentUri =
|
||||
FileProvider.getUriForFile(requireContext(), "${requireContext().packageName}.fileprovider", tempApkFile)
|
||||
|
||||
//requireContext().grantUriPermission(receivers.package.name, contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
|
||||
// Create a Share Intent
|
||||
Intent(Intent.ACTION_SEND).apply {
|
||||
type = "application/vnd.android.package-archive"
|
||||
putExtra(Intent.EXTRA_STREAM, contentUri)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}.let {
|
||||
// Start the chooser activity
|
||||
startActivity(Intent.createChooser(it, getString(R.string.share_apk_message)))
|
||||
}
|
||||
}
|
||||
catch (e: PackageManager.NameNotFoundException) { e.printStackTrace() }
|
||||
catch (e: IOException) { e.printStackTrace() }
|
||||
this.dismiss()
|
||||
}
|
||||
|
||||
/* uninstall the app */
|
||||
private fun uninstall() {
|
||||
val uninstallIntent = Intent(Intent.ACTION_DELETE)
|
||||
uninstallIntent.data = Uri.parse("package:$packageName")
|
||||
uninstallIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
requireContext().startActivity(uninstallIntent)
|
||||
this.dismiss()
|
||||
}
|
||||
|
||||
/* create and add an outlined button to the toggle group */
|
||||
private val outlinedButton: MaterialButton get() {
|
||||
val style = com.google.android.material.R.attr.materialButtonOutlinedStyle
|
||||
val button = MaterialButton(requireContext(), null, style)
|
||||
button.layoutParams = LinearLayoutCompat.LayoutParams(
|
||||
LinearLayoutCompat.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayoutCompat.LayoutParams.WRAP_CONTENT, 1F
|
||||
)
|
||||
binding.favGroup.addView(button)
|
||||
return button
|
||||
}
|
||||
|
||||
/* long value to local date-time format */
|
||||
private fun dateTimeFormat(long: Long) : String = SimpleDateFormat.getDateTimeInstance().format(Date(long))
|
||||
|
||||
/* get and arrange all the permissions for an application */
|
||||
private val permissionsList : String get() {
|
||||
val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(PackageManager.GET_PERMISSIONS.toLong()))
|
||||
} else {
|
||||
packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)
|
||||
}
|
||||
|
||||
return if (packageInfo.requestedPermissions.isNotEmpty()) {
|
||||
val stringBuilder = StringBuilder()
|
||||
packageInfo.requestedPermissions.indices.forEach { i: Int ->
|
||||
if (i != packageInfo.requestedPermissions.size - 1)
|
||||
stringBuilder.append("${packageInfo.requestedPermissions[i]}\n\n")
|
||||
/* don't add any new line after the last entry */
|
||||
else
|
||||
stringBuilder.append(packageInfo.requestedPermissions[i])
|
||||
}
|
||||
stringBuilder.toString()
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
/* get activity options for launching app in freeform mode */
|
||||
private val activityOptions: ActivityOptions get() {
|
||||
val activityOptions = ActivityOptions.makeBasic()
|
||||
try {
|
||||
val method =
|
||||
ActivityOptions::class.java.getMethod("setLaunchWindowingMode", Int::class.javaPrimitiveType)
|
||||
method.invoke(activityOptions, 5)
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
}
|
||||
return activityOptions
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user