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:
Finn M Glas 2020-05-30 00:42:23 +02:00
parent 7b623e97d8
commit f40cee392e
No known key found for this signature in database
GPG key ID: 25037A2E81AB459C
5 changed files with 40 additions and 10 deletions

View file

@ -12,7 +12,6 @@ import com.finnmglas.launcher.choose.AppsRecyclerAdapter
import com.finnmglas.launcher.extern.*
import kotlinx.android.synthetic.main.activity_choose.*
class ChooseActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
@ -67,6 +66,10 @@ class ChooseActivity : AppCompatActivity() {
finish()
}
override fun onResume() {
super.onResume()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_UNINSTALL) {

View file

@ -3,20 +3,20 @@ package com.finnmglas.launcher.choose
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.PopupMenu
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.finnmglas.launcher.R
import com.finnmglas.launcher.extern.FontAwesome
import com.finnmglas.launcher.extern.REQUEST_CHOOSE_APP
import com.finnmglas.launcher.extern.REQUEST_UNINSTALL
import com.finnmglas.launcher.extern.openAppSettings
class AppsRecyclerAdapter(val activity: Activity, val action: String?, val forApp: String?):
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
@ -62,11 +62,30 @@ class AppsRecyclerAdapter(val activity: Activity, val action: String?, val forAp
viewHolder.textView.text = appLabel
viewHolder.img.setImageDrawable(appIcon)
viewHolder.delete.setOnClickListener{
viewHolder.delete.setOnClickListener{ //creating a popup menu
val popup = PopupMenu(activity, viewHolder.delete)
popup.inflate(R.menu.menu_app)
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

View file

@ -36,7 +36,7 @@
android:layout_width="20sp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/fas_trash"
android:text="@string/fas_three_dots"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"

View 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>

View file

@ -11,7 +11,8 @@
<string name="fas_donate" translatable="false">&#xf4b9;</string>
<string name="fas_share" translatable="false">&#xf064;</string>
<string name="fas_trash" translatable="false">&#xf1f8;</string>
<string name="fas_times" translatable="false">&#xf00d;</string>
<string name="fas_times" translatable="false">&#xf00d;</string> <!-- 'close' -->
<string name="fas_three_dots" translatable="false">&#xf142;</string> <!-- 'ellipsis-v' -->
<!-- icons that can be used with type="brands" -->
<string name="fab_apple" translatable="false">&#xf179;</string>