mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Add apps recycler to tab, other one is empty
The two tabs are only visible when an app is selected, not in the `view all apps` list
This commit is contained in:
parent
d71eacb7ef
commit
e692c0317b
10 changed files with 199 additions and 31 deletions
|
@ -7,13 +7,19 @@ import android.view.View
|
|||
import android.view.WindowManager
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.finnmglas.launcher.choose.AppsRecyclerAdapter
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.finnmglas.launcher.choose.ChooseSectionsPagerAdapter
|
||||
import com.finnmglas.launcher.extern.*
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import kotlinx.android.synthetic.main.activity_choose.*
|
||||
|
||||
var intendedChoosePause = false // know when to close
|
||||
|
||||
// TODO: Better solution for this (used in choose-fragments)
|
||||
var action = "view"
|
||||
var forApp = ""
|
||||
|
||||
|
||||
class ChooseActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -42,24 +48,27 @@ class ChooseActivity : AppCompatActivity() {
|
|||
|
||||
// get info about which action this activity is open for
|
||||
val bundle = intent.extras
|
||||
val action = bundle!!.getString("action") // why choose an app
|
||||
val forApp = bundle.getString("forApp") // which app we choose
|
||||
if (bundle != null) {
|
||||
action = bundle.getString("action")!! // why choose an app
|
||||
if (action != "view")
|
||||
forApp = bundle.getString("forApp")!! // which app we choose
|
||||
}
|
||||
|
||||
// Hide tabs for the "view" action
|
||||
if (action == "view") {
|
||||
activity_choose_tabs.visibility = View.GONE
|
||||
}
|
||||
|
||||
when (action) {
|
||||
"view" -> activity_choose_heading.text = getString(R.string.choose_title_view)
|
||||
"pick" -> activity_choose_heading.text = getString(R.string.choose_title)
|
||||
}
|
||||
|
||||
// set up the list / recycler
|
||||
viewManager = LinearLayoutManager(this)
|
||||
viewAdapter = AppsRecyclerAdapter( this, action, forApp)
|
||||
|
||||
/*activity_choose_apps_recycler_view.apply {
|
||||
// improve performance (since content changes don't change the layout size)
|
||||
setHasFixedSize(true)
|
||||
layoutManager = viewManager
|
||||
adapter = viewAdapter
|
||||
}*/
|
||||
val sectionsPagerAdapter = ChooseSectionsPagerAdapter(this, supportFragmentManager)
|
||||
val viewPager: ViewPager = findViewById(R.id.activity_choose_view_pager)
|
||||
viewPager.adapter = sectionsPagerAdapter
|
||||
val tabs: TabLayout = findViewById(R.id.activity_choose_tabs)
|
||||
tabs.setupWithViewPager(viewPager)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
|
|
@ -10,7 +10,7 @@ import android.view.WindowManager
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.finnmglas.launcher.extern.*
|
||||
import com.finnmglas.launcher.settings.SectionsPagerAdapter
|
||||
import com.finnmglas.launcher.settings.SettingsSectionsPagerAdapter
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
|
||||
|
@ -36,7 +36,7 @@ class SettingsActivity : AppCompatActivity() {
|
|||
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
||||
val sectionsPagerAdapter = SectionsPagerAdapter(this, supportFragmentManager)
|
||||
val sectionsPagerAdapter = SettingsSectionsPagerAdapter(this, supportFragmentManager)
|
||||
val viewPager: ViewPager = findViewById(R.id.activity_settings_view_pager)
|
||||
viewPager.adapter = sectionsPagerAdapter
|
||||
val tabs: TabLayout = findViewById(R.id.activity_settings_tabs)
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package com.finnmglas.launcher.choose
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.finnmglas.launcher.R
|
||||
import com.finnmglas.launcher.action
|
||||
import com.finnmglas.launcher.extern.*
|
||||
import com.finnmglas.launcher.forApp
|
||||
import kotlinx.android.synthetic.main.fragment_choose_apps.*
|
||||
|
||||
|
||||
/** The 'Apps' Tab associated Fragment in the Chooser */
|
||||
|
||||
class ChooseFragmentApps : Fragment() {
|
||||
|
||||
/** Lifecycle functions */
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
return inflater.inflate(R.layout.fragment_choose_apps, container, false)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
||||
if (getSavedTheme(context!!) == "custom") {
|
||||
fragment_choose_apps_container.setBackgroundColor(dominantColor)
|
||||
}
|
||||
|
||||
// set up the list / recycler
|
||||
val viewManager = LinearLayoutManager(context)
|
||||
val viewAdapter = AppsRecyclerAdapter( activity!!, action, forApp)
|
||||
|
||||
fragment_choose_apps_recycler_view.apply {
|
||||
// improve performance (since content changes don't change the layout size)
|
||||
setHasFixedSize(true)
|
||||
layoutManager = viewManager
|
||||
adapter = viewAdapter
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.finnmglas.launcher.choose
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.finnmglas.launcher.R
|
||||
import com.finnmglas.launcher.extern.dominantColor
|
||||
import com.finnmglas.launcher.extern.getSavedTheme
|
||||
import kotlinx.android.synthetic.main.fragment_choose_other.*
|
||||
|
||||
/** The 'Other' Tab associated Fragment in the Chooser */
|
||||
|
||||
class ChooseFragmentOther : Fragment() {
|
||||
|
||||
/** Lifecycle functions */
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
return inflater.inflate(R.layout.fragment_choose_other, container, false)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
if (getSavedTheme(context!!) == "custom") {
|
||||
fragment_choose_other_container.setBackgroundColor(dominantColor)
|
||||
}
|
||||
|
||||
super.onStart()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.finnmglas.launcher.choose
|
||||
|
||||
import android.content.Context
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentPagerAdapter
|
||||
import com.finnmglas.launcher.*
|
||||
|
||||
private val TAB_TITLES = arrayOf(
|
||||
R.string.choose_tab_app,
|
||||
R.string.choose_tab_other
|
||||
)
|
||||
|
||||
/** Returns the fragment corresponding to the selected tab.*/
|
||||
class ChooseSectionsPagerAdapter(private val context: Context, fm: FragmentManager)
|
||||
: FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return when (position){
|
||||
0 -> ChooseFragmentApps()
|
||||
1 -> ChooseFragmentOther()
|
||||
else -> Fragment()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
return context.resources.getString(TAB_TITLES[position])
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return when (action) {
|
||||
"view" -> 1
|
||||
else -> 2
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ private val TAB_TITLES = arrayOf(
|
|||
)
|
||||
|
||||
/** Returns the fragment corresponding to the selected tab.*/
|
||||
class SectionsPagerAdapter(private val context: Context, fm: FragmentManager)
|
||||
class SettingsSectionsPagerAdapter(private val context: Context, fm: FragmentManager)
|
||||
: FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
|
|
|
@ -74,18 +74,4 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/activity_choose_app_bar"
|
||||
custom:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
<!--androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/activity_choose_apps_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:scrollbars="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/activity_choose_app_bar" /-->
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
33
app/src/main/res/layout/fragment_choose_apps.xml
Normal file
33
app/src/main/res/layout/fragment_choose_apps.xml
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/fragment_choose_apps_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:gravity="center|top"
|
||||
android:orientation="vertical"
|
||||
tools:context=".choose.ChooseFragmentApps">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/fragment_choose_apps_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:scrollbars="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</LinearLayout>
|
19
app/src/main/res/layout/fragment_choose_other.xml
Normal file
19
app/src/main/res/layout/fragment_choose_other.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/fragment_choose_other_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:gravity="center|top"
|
||||
android:orientation="vertical"
|
||||
tools:context=".choose.ChooseFragmentOther">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -61,6 +61,9 @@
|
|||
<string name="choose_title">Choose App</string>
|
||||
<string name="choose_title_view">All Apps</string>
|
||||
|
||||
<string name="choose_tab_app" translatable="false">Apps</string>
|
||||
<string name="choose_tab_other" translatable="false">Other</string>
|
||||
|
||||
<string name="choose_back_settings">Back to Settings</string>
|
||||
|
||||
<string name="choose_removed_toast">Removed the selected application</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue