1
0
Fork 0

For #139 - Adds the sessions placeholder

master
Jeff Boek 2019-01-25 09:06:10 -08:00
parent 38431dac41
commit 4179a8ff78
8 changed files with 203 additions and 35 deletions

View File

@ -4,27 +4,20 @@
package org.mozilla.fenix.home
import android.content.Context
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.transition.TransitionInflater
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.navigation.Navigation
import androidx.navigation.fragment.FragmentNavigator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.fragment_home.*
import org.mozilla.fenix.R
import org.mozilla.fenix.home.sessions.SessionsAdapter
class HomeFragment : Fragment() {
override fun onCreateView(
@ -43,7 +36,7 @@ class HomeFragment : Fragment() {
menuButton.visibility = View.GONE
privateBrowsingButton.visibility = View.GONE
sessionsAdapter = SessionsAdapter(requireContext())
sessionsAdapter = SessionsAdapter()
toolbar_wrapper.clipToOutline = false
toolbar.setOnClickListener { it ->
@ -66,28 +59,3 @@ class HomeFragment : Fragment() {
exitTransition = TransitionInflater.from(context).inflateTransition(android.R.transition.fade)
}
}
// Temporary adapter
private class SessionsAdapter(val context: Context) : RecyclerView.Adapter<SessionsAdapter.ViewHolder>() {
class ViewHolder(val textView: TextView) : RecyclerView.ViewHolder(textView) {}
@RequiresApi(Build.VERSION_CODES.M)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val textView = TextView(context).apply {
val lp = RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, // Width of TextView
RelativeLayout.LayoutParams.WRAP_CONTENT
)
setLayoutParams(lp)
setText("This is a sample TextView...")
setTextColor(Color.parseColor("#ff0000"))
}
return ViewHolder(textView)
}
override fun getItemCount(): Int = 100
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.textView.text = "Cell: ${position}"
}
}

View File

@ -0,0 +1,53 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.home.sessions
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import org.mozilla.fenix.R
class SessionsAdapter() : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
return when(viewType) {
HeaderViewHolder.LAYOUT_ID -> HeaderViewHolder(view)
EmptyListViewHolder.LAYOUT_ID -> EmptyListViewHolder(view)
else -> EmptyListViewHolder(view)
}
}
override fun getItemViewType(position: Int) = when (position) {
0 -> HeaderViewHolder.LAYOUT_ID
1 -> EmptyListViewHolder.LAYOUT_ID
else -> -1
}
override fun getItemCount(): Int = 2
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is HeaderViewHolder) {
holder.headerText.text = "Today"
}
}
private class HeaderViewHolder(private val view: View): RecyclerView.ViewHolder(view) {
val headerText = view.findViewById<TextView>(R.id.header_text)
companion object {
const val LAYOUT_ID = R.layout.session_list_header
}
}
private class EmptyListViewHolder(private val view: View): RecyclerView.ViewHolder(view) {
companion object {
const val LAYOUT_ID = R.layout.session_list_empty
}
}
}

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="44dp"
android:height="60dp"
android:viewportWidth="44"
android:viewportHeight="60">
<path
android:pathData="M24,46C25.6569,46 27,47.3431 27,49C27,50.6569 25.6569,52 24,52L9,52C4.0294,52 0,47.9706 0,43L0,9C0,4.0294 4.0294,0 9,0L35,0C39.9706,0 44,4.0294 44,9L44,43C44,47.9706 39.9706,52 35,52L34,52C32.3431,52 31,50.6569 31,49C31,47.3431 32.3431,46 34,46L35,46C36.6569,46 38,44.6569 38,43L38,9C38,7.3431 36.6569,6 35,6L9,6C7.3431,6 6,7.3431 6,9L6,43C6,44.6569 7.3431,46 9,46L24,46Z"
android:strokeWidth="1"
android:fillColor="#665BFD"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M9,46h13v6h-13z"
android:strokeWidth="1"
android:fillType="evenOdd"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:startY="49"
android:startX="20.763313"
android:endY="49"
android:endX="9.27464"
android:type="linear">
<item android:offset="0" android:color="#A30B1043"/>
<item android:offset="0.40306628" android:color="#510B1043"/>
<item android:offset="1" android:color="#000B1043"/>
</gradient>
</aapt:attr>
</path>
<path
android:pathData="M13.8787,43.1213C12.7071,41.9497 12.7071,40.0503 13.8787,38.8787C15.0503,37.7071 16.9497,37.7071 18.1213,38.8787L26.1213,46.8787C27.2929,48.0503 27.2929,49.9497 26.1213,51.1213L18.1213,59.1213C16.9497,60.2929 15.0503,60.2929 13.8787,59.1213C12.7071,57.9497 12.7071,56.0503 13.8787,54.8787L19.7574,49L13.8787,43.1213Z"
android:strokeWidth="1"
android:fillColor="#665BFD"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M35,46.0281C37.4195,46.1246 39.3314,45.8435 40.7358,45.1849C42.5965,44.3123 43.6623,42.9675 43.933,41.1506L43.9128,31L37.9345,31L37.9345,42.3681C38.013,43.607 37.7233,44.5204 37.0655,45.1083C36.4642,45.6456 35.7757,45.9522 35,46.0281Z"
android:strokeWidth="1"
android:fillType="evenOdd"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:startY="46.1246"
android:startX="41.02018"
android:endY="34.49148"
android:endX="41.02018"
android:type="linear">
<item android:offset="0" android:color="#A30B1043"/>
<item android:offset="0.40306628" android:color="#510B1043"/>
<item android:offset="1" android:color="#000B1043"/>
</gradient>
</aapt:attr>
</path>
<path
android:pathData="M8.933,6.0185C6.5136,5.922 4.6016,6.2031 3.1973,6.8617C1.3365,7.7343 0.2708,9.0791 0,10.896L0.0202,21.0466L5.9986,21.0466L5.9986,9.6785C5.9201,8.4396 6.2098,7.5262 6.8676,6.9383C7.4688,6.401 8.1573,6.0943 8.933,6.0185Z"
android:strokeWidth="1"
android:fillType="evenOdd"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:startY="21.0466"
android:startX="6.020179"
android:endY="9.413482"
android:endX="6.020179"
android:type="linear">
<item android:offset="0" android:color="#A30B1043"/>
<item android:offset="0.40306628" android:color="#510B1043"/>
<item android:offset="1" android:color="#000B1043"/>
</gradient>
</aapt:attr>
</path>
</vector>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/session_list_empty_bg"/>
<padding android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/>
<corners android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp"/>
</shape>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/no_sessions"
android:background="@drawable/session_list_empty_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="44dp"
android:layout_height="60dp"
android:src="@drawable/ic_sessions_intro"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center_vertical"
android:textSize="16sp"
android:text="@string/sessions_intro_description"
android:textColor="@color/session_list_empty_fg"
android:layout_marginStart="23dp"
app:layout_constraintBottom_toBottomOf="@id/imageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toTopOf="@id/imageView" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header_text"
android:layout_marginBottom="8dp"
android:textSize="12dp"
android:textColor="@color/session_list_header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TextView>

View File

@ -11,4 +11,8 @@
<color name="searchText">#0C0C0D</color>
<color name="offwhite">#f9f9fa</color>
<color name="icons">#0C0C0D</color>
<color name="session_list_empty_bg">#1A665BFD</color>
<color name="session_list_empty_fg">#665BFD</color>
<color name="session_list_header">#6D6D6E</color>
</resources>

View File

@ -15,4 +15,7 @@
<string name="browser_menu_private_tab">Private Tab</string>
<string name="browser_menu_new_tab">New Tab</string>
<string name="browser_menu_report_issue">Report Issue</string>
<string name="sessions_intro_description">Fenix will collect your browsing sessions\n on your Home Screen for you to
retrieve\n later.
</string>
</resources>