diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt index 07e10db..d49cc59 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt @@ -1,6 +1,7 @@ package eu.ottop.yamlauncher import android.annotation.SuppressLint +import android.app.Activity import android.content.Context import android.content.pm.ApplicationInfo import android.content.pm.LauncherActivityInfo @@ -23,7 +24,7 @@ import androidx.preference.PreferenceManager import androidx.recyclerview.widget.RecyclerView class AppMenuAdapter( - private val activity: FragmentActivity, + private val activity: MainActivity, var apps: MutableList>>, private val itemClickListener: OnItemClickListener, private val shortcutListener: OnShortcutListener, diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuEdgeFactory.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuEdgeFactory.kt index 1dacd26..6b6ff51 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuEdgeFactory.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuEdgeFactory.kt @@ -1,15 +1,16 @@ package eu.ottop.yamlauncher +import android.app.Activity import android.widget.EdgeEffect import androidx.recyclerview.widget.RecyclerView -class AppMenuEdgeFactory(private val activity: MainActivity) : RecyclerView.EdgeEffectFactory() { +class AppMenuEdgeFactory(private val activity: Activity) : RecyclerView.EdgeEffectFactory() { override fun createEdgeEffect(view: RecyclerView, direction: Int): EdgeEffect { return AppMenuEdgeEffect(activity) } - inner class AppMenuEdgeEffect(activity: MainActivity) : EdgeEffect(activity) { + inner class AppMenuEdgeEffect(activity: Activity) : EdgeEffect(activity) { private val animationSpeedFactor = 0.75f override fun onAbsorb(velocity: Int) { super.onAbsorb((velocity * animationSpeedFactor).toInt()) diff --git a/app/src/main/java/eu/ottop/yamlauncher/ButtonPreference.kt b/app/src/main/java/eu/ottop/yamlauncher/ButtonPreference.kt deleted file mode 100644 index c54c4dc..0000000 --- a/app/src/main/java/eu/ottop/yamlauncher/ButtonPreference.kt +++ /dev/null @@ -1,31 +0,0 @@ -package eu.ottop.yamlauncher - -import android.content.Context -import android.util.AttributeSet -import androidx.preference.Preference -import androidx.preference.PreferenceViewHolder - - -class ButtonPreference(context: Context?, attrs: AttributeSet?) : - Preference(context!!, attrs) { - init { - widgetLayoutResource = R.layout.location_button; - } - - override fun onBindViewHolder(holder: PreferenceViewHolder) { - super.onBindViewHolder(holder) - - val view = holder.itemView - view.setOnClickListener { - when (this.key) { - "manual_location" -> { - println("Location pressed") - } - - "hidden_apps" -> { - println("Hidden apps pressed") - } - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt new file mode 100644 index 0000000..9c74d09 --- /dev/null +++ b/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt @@ -0,0 +1,172 @@ +package eu.ottop.yamlauncher + +import android.annotation.SuppressLint +import android.content.Context +import android.content.pm.ApplicationInfo +import android.content.pm.LauncherActivityInfo +import android.os.UserHandle +import android.view.Gravity +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.EditText +import android.widget.FrameLayout +import android.widget.LinearLayout +import android.widget.TextView +import androidx.core.content.res.ResourcesCompat +import androidx.fragment.app.FragmentActivity +import androidx.preference.PreferenceManager +import androidx.recyclerview.widget.RecyclerView + +class HiddenAppsAdapter( + private val activity: Context, + var apps: MutableList>>, + private val itemClickListener: OnItemClickListener, + private val shortcutListener: OnShortcutListener, + private val itemLongClickListener: OnItemLongClickListener +) : + RecyclerView.Adapter() { + + var menuMode: String = "app" + var shortcutTextView: TextView? = null + + private val sharedPreferenceManager = SharedPreferenceManager() + private var preferences = PreferenceManager.getDefaultSharedPreferences(activity) + + interface OnItemClickListener { + fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) + } + + interface OnShortcutListener { + fun onShortcut(appInfo: LauncherActivityInfo, userHandle: UserHandle, textView: TextView, userProfile: Int, shortcutView: TextView) + } + + interface OnItemLongClickListener { + fun onItemLongClick( + appInfo: LauncherActivityInfo, + userHandle: UserHandle, + userProfile: Int, + textView: TextView, + actionMenuLayout: LinearLayout, + editView: LinearLayout, + position: Int + ) + } + + inner class AppViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + private val listItem: FrameLayout = itemView.findViewById(R.id.list_item) + val textView: TextView = listItem.findViewById(R.id.app_name) + val actionMenuLayout: LinearLayout = listItem.findViewById(R.id.action_menu) + private val editView: LinearLayout = listItem.findViewById(R.id.rename_view) + val editText: EditText = editView.findViewById(R.id.app_name_edit) + + init { + actionMenuLayout.visibility = View.INVISIBLE + editView.visibility = View.INVISIBLE + + textView.setOnClickListener { + val position = bindingAdapterPosition + val app = apps[position].first + if (menuMode == "shortcut") { + shortcutListener.onShortcut(app, apps[position].second.first, textView, apps[position].second.second, shortcutTextView!!) + } + else if (menuMode == "app") { + itemClickListener.onItemClick(app, apps[position].second.first) + } + } + + if (menuMode == "app") { + textView.setOnLongClickListener { + val position = bindingAdapterPosition + + val app = apps[position].first + itemLongClickListener.onItemLongClick( + app, + apps[position].second.first, + apps[position].second.second, + textView, + actionMenuLayout, + editView, + position + ) + return@setOnLongClickListener true + } + + + } + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppViewHolder { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.app_item_layout, parent, false) + return AppViewHolder(view) + } + + override fun onBindViewHolder(holder: AppViewHolder, position: Int) { + val app = apps[position] + + if (app.second.second != 0) { + holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_work_app, null),null,null,null) + } + else { + holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null,null,null) + } + + when (preferences.getString("appMenuAlignment", "left")) { + "left" -> { + holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null, null, null) + holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.START + } + "center" -> { + holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null,holder.textView.compoundDrawables.filterNotNull().first(), null) + holder.textView.gravity = Gravity.CENTER + + } + "right" -> { + holder.textView.setCompoundDrawablesWithIntrinsicBounds(null,null, holder.textView.compoundDrawables.filterNotNull().first(), null) + holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.END + } + } + + when (preferences.getString("appMenuSize", "medium")) { + "small" -> { + holder.textView.textSize = 24F + holder.editText.textSize = 24F + } + + "medium" -> { + holder.textView.textSize = 26F + holder.editText.textSize = 26F + } + + "large" -> { + holder.textView.textSize = 28F + holder.editText.textSize = 28F + } + } + + val appInfo = app.first.activityInfo.applicationInfo + holder.textView.text = sharedPreferenceManager.getAppName(activity, app.first.applicationInfo.packageName,app.second.second, holder.itemView.context.packageManager.getApplicationLabel(appInfo)) + holder.editText.setText(holder.textView.text) + + if (appInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) { + holder.actionMenuLayout.findViewById(R.id.uninstall).visibility = View.GONE + } + else { + holder.actionMenuLayout.findViewById(R.id.uninstall).visibility = View.VISIBLE + } + + holder.textView.visibility = View.VISIBLE + } + + override fun getItemCount(): Int { + return apps.size + } + + @SuppressLint("NotifyDataSetChanged") + fun updateApps(newApps: List>>) { + apps = newApps.toMutableList() + notifyDataSetChanged() + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt new file mode 100644 index 0000000..130b397 --- /dev/null +++ b/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt @@ -0,0 +1,107 @@ +package eu.ottop.yamlauncher + +import android.app.Activity +import android.content.pm.LauncherActivityInfo +import android.os.Bundle +import android.os.UserHandle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +// TODO: Rename parameter arguments, choose names that match +// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER +private const val ARG_PARAM1 = "param1" +private const val ARG_PARAM2 = "param2" + +/** + * A simple [Fragment] subclass. + * Use the [HiddenAppsFragment.newInstance] factory method to + * create an instance of this fragment. + */ +class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener, HiddenAppsAdapter.OnShortcutListener, HiddenAppsAdapter.OnItemLongClickListener { + // TODO: Rename and change types of parameters + private var param1: String? = null + private var param2: String? = null + private val appUtils = AppUtils() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + arguments?.let { + param1 = it.getString(ARG_PARAM1) + param2 = it.getString(ARG_PARAM2) + } + + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_hidden_apps, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val adapter = HiddenAppsAdapter(requireContext(), appUtils.getHiddenApps(activity as Activity).toMutableList(), this, this, this) + val recyclerView = view.findViewById(R.id.hidden_app_recycler) + val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity()) + + recyclerView.edgeEffectFactory = appMenuEdgeFactory + recyclerView.adapter = adapter + recyclerView.scrollToPosition(0) + } + + companion object { + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param param1 Parameter 1. + * @param param2 Parameter 2. + * @return A new instance of fragment HiddenAppsFragment. + */ + // TODO: Rename and change types and number of parameters + @JvmStatic + fun newInstance(param1: String, param2: String) = + HiddenAppsFragment().apply { + arguments = Bundle().apply { + putString(ARG_PARAM1, param1) + putString(ARG_PARAM2, param2) + } + } + } + + override fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) { + TODO("Not yet implemented") + } + + override fun onShortcut( + appInfo: LauncherActivityInfo, + userHandle: UserHandle, + textView: TextView, + userProfile: Int, + shortcutView: TextView + ) { + TODO("Not yet implemented") + } + + override fun onItemLongClick( + appInfo: LauncherActivityInfo, + userHandle: UserHandle, + userProfile: Int, + textView: TextView, + actionMenuLayout: LinearLayout, + editView: LinearLayout, + position: Int + ) { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index 9444ecc..214fca1 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -77,9 +77,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh private lateinit var dateText: TextClock - private var cameraSwipeEnabled = true - private var phoneSwipeEnabled = true - private lateinit var preferences: SharedPreferences @SuppressLint("ClickableViewAccessibility") diff --git a/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt index d776dac..0a3dad7 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt @@ -20,6 +20,10 @@ class SettingsActivity : AppCompatActivity() { .commit() } + fun showHiddenApps() { + + } + /* private lateinit var binding: ActivitySettingsBinding diff --git a/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt index 6fee4e8..0ce61b1 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt @@ -11,7 +11,7 @@ class SettingsFragment : PreferenceFragmentCompat() { setPreferencesFromResource(R.xml.root_preferences, rootKey) val gpsLocationPref: SwitchPreference? = findPreference("gps_location") - val manualLocationPref: ButtonPreference? = findPreference("manual_location") + val manualLocationPref: Preference? = findPreference("manual_location") if (gpsLocationPref != null && manualLocationPref != null) { // Initial setup @@ -25,5 +25,14 @@ class SettingsFragment : PreferenceFragmentCompat() { true // Returning true means the change is persisted } } + + findPreference("hidden_apps")?.onPreferenceClickListener = + Preference.OnPreferenceClickListener { + activity?.supportFragmentManager + ?.beginTransaction() + ?.replace(R.id.settings_layout, HiddenAppsFragment()) + ?.addToBackStack(null) + ?.commit() + true } } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 08e0ddb..c708667 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -1,6 +1,6 @@ - - - + android:layout_height="match_parent" + android:paddingTop="40dp"> @@ -460,4 +457,4 @@ tools:layout_editor_absoluteY="810dp" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_hidden_apps.xml b/app/src/main/res/layout/fragment_hidden_apps.xml new file mode 100644 index 0000000..04731b3 --- /dev/null +++ b/app/src/main/res/layout/fragment_hidden_apps.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/location_button.xml b/app/src/main/res/layout/location_button.xml deleted file mode 100644 index 82ac2de..0000000 --- a/app/src/main/res/layout/location_button.xml +++ /dev/null @@ -1,5 +0,0 @@ - - \ No newline at end of file diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 948d819..c7fe46b 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -120,7 +120,7 @@ android:defaultValue="false" android:title="GPS Location" app:key="gps_location" /> - -