mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Create a appmenu to be opened by three dots
This menu is located in the `ChooseActivity`, helps managing apps (info / delete)
This commit is contained in:
parent
7b623e97d8
commit
f40cee392e
5 changed files with 40 additions and 10 deletions
|
@ -12,7 +12,6 @@ import com.finnmglas.launcher.choose.AppsRecyclerAdapter
|
||||||
import com.finnmglas.launcher.extern.*
|
import com.finnmglas.launcher.extern.*
|
||||||
import kotlinx.android.synthetic.main.activity_choose.*
|
import kotlinx.android.synthetic.main.activity_choose.*
|
||||||
|
|
||||||
|
|
||||||
class ChooseActivity : AppCompatActivity() {
|
class ChooseActivity : AppCompatActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
@ -67,6 +66,10 @@ class ChooseActivity : AppCompatActivity() {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
if (requestCode == REQUEST_UNINSTALL) {
|
if (requestCode == REQUEST_UNINSTALL) {
|
||||||
|
|
|
@ -3,20 +3,20 @@ package com.finnmglas.launcher.choose
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ApplicationInfo
|
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import android.widget.PopupMenu
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.finnmglas.launcher.R
|
import com.finnmglas.launcher.R
|
||||||
import com.finnmglas.launcher.extern.FontAwesome
|
import com.finnmglas.launcher.extern.FontAwesome
|
||||||
import com.finnmglas.launcher.extern.REQUEST_CHOOSE_APP
|
import com.finnmglas.launcher.extern.REQUEST_CHOOSE_APP
|
||||||
import com.finnmglas.launcher.extern.REQUEST_UNINSTALL
|
import com.finnmglas.launcher.extern.REQUEST_UNINSTALL
|
||||||
|
import com.finnmglas.launcher.extern.openAppSettings
|
||||||
|
|
||||||
class AppsRecyclerAdapter(val activity: Activity, val action: String?, val forApp: String?):
|
class AppsRecyclerAdapter(val activity: Activity, val action: String?, val forApp: String?):
|
||||||
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
|
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
|
||||||
|
@ -62,11 +62,30 @@ class AppsRecyclerAdapter(val activity: Activity, val action: String?, val forAp
|
||||||
viewHolder.textView.text = appLabel
|
viewHolder.textView.text = appLabel
|
||||||
viewHolder.img.setImageDrawable(appIcon)
|
viewHolder.img.setImageDrawable(appIcon)
|
||||||
|
|
||||||
viewHolder.delete.setOnClickListener{
|
viewHolder.delete.setOnClickListener{ //creating a popup menu
|
||||||
val intent = Intent(Intent.ACTION_UNINSTALL_PACKAGE)
|
|
||||||
intent.data = Uri.parse("package:$appPackageName")
|
val popup = PopupMenu(activity, viewHolder.delete)
|
||||||
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
|
popup.inflate(R.menu.menu_app)
|
||||||
activity.startActivityForResult(intent, REQUEST_UNINSTALL)
|
|
||||||
|
popup.setOnMenuItemClickListener {
|
||||||
|
when (it.itemId) {
|
||||||
|
R.id.app_menu_delete -> { // delete
|
||||||
|
val intent = Intent(Intent.ACTION_UNINSTALL_PACKAGE)
|
||||||
|
intent.data = Uri.parse("package:$appPackageName")
|
||||||
|
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
|
||||||
|
activity.startActivityForResult(intent, REQUEST_UNINSTALL)
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
R.id.app_menu_info -> { // open app settings
|
||||||
|
openAppSettings(appPackageName, activity)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
popup.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
viewHolder.delete.visibility = if(isSystemApp || action == "pick") View.INVISIBLE else View.VISIBLE
|
viewHolder.delete.visibility = if(isSystemApp || action == "pick") View.INVISIBLE else View.VISIBLE
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
android:layout_width="20sp"
|
android:layout_width="20sp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="@string/fas_trash"
|
android:text="@string/fas_three_dots"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|
7
app/src/main/res/menu/menu_app.xml
Normal file
7
app/src/main/res/menu/menu_app.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:id="@+id/app_menu_delete"
|
||||||
|
android:title="Delete" />
|
||||||
|
<item android:id="@+id/app_menu_info"
|
||||||
|
android:title="Info" />
|
||||||
|
</menu>
|
|
@ -11,7 +11,8 @@
|
||||||
<string name="fas_donate" translatable="false"></string>
|
<string name="fas_donate" translatable="false"></string>
|
||||||
<string name="fas_share" translatable="false"></string>
|
<string name="fas_share" translatable="false"></string>
|
||||||
<string name="fas_trash" translatable="false"></string>
|
<string name="fas_trash" translatable="false"></string>
|
||||||
<string name="fas_times" translatable="false"></string>
|
<string name="fas_times" translatable="false"></string> <!-- 'close' -->
|
||||||
|
<string name="fas_three_dots" translatable="false"></string> <!-- 'ellipsis-v' -->
|
||||||
|
|
||||||
<!-- icons that can be used with type="brands" -->
|
<!-- icons that can be used with type="brands" -->
|
||||||
<string name="fab_apple" translatable="false"></string>
|
<string name="fab_apple" translatable="false"></string>
|
||||||
|
|
Loading…
Add table
Reference in a new issue