This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For #6758 - Part 6: Add top site view
- Loading branch information
1 parent
dae8ebd
commit 058c5c2
Showing
10 changed files
with
216 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TopSiteViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* 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.sessioncontrol.viewholders | ||
|
||
import android.view.View | ||
import androidx.recyclerview.widget.GridLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import kotlinx.android.extensions.LayoutContainer | ||
import kotlinx.android.synthetic.main.component_top_sites.view.* | ||
import mozilla.components.feature.top.sites.TopSite | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.home.sessioncontrol.TopSiteInteractor | ||
import org.mozilla.fenix.home.sessioncontrol.viewholders.topsites.TopSitesAdapter | ||
|
||
class TopSiteViewHolder( | ||
view: View, | ||
interactor: TopSiteInteractor, | ||
override val containerView: View? = view | ||
) : RecyclerView.ViewHolder(view), LayoutContainer { | ||
private val topSitesAdapter = TopSitesAdapter(interactor) | ||
|
||
init { | ||
view.top_sites_list.apply { | ||
adapter = topSitesAdapter | ||
layoutManager = GridLayoutManager(view.context, NUM_COLUMNS) | ||
} | ||
} | ||
|
||
fun bind(topSites: List<TopSite>) { | ||
topSitesAdapter.submitList(topSites) | ||
} | ||
|
||
companion object { | ||
const val LAYOUT_ID = R.layout.component_top_sites | ||
const val NUM_COLUMNS = 5 | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../java/org/mozilla/fenix/home/sessioncontrol/viewholders/topsites/TopSiteItemViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* 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.sessioncontrol.viewholders.topsites | ||
|
||
import android.view.View | ||
import androidx.recyclerview.widget.RecyclerView | ||
import kotlinx.android.synthetic.main.top_site_item.view.* | ||
import mozilla.components.feature.top.sites.TopSite | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.ext.components | ||
import org.mozilla.fenix.ext.loadIntoView | ||
import org.mozilla.fenix.home.sessioncontrol.TopSiteInteractor | ||
|
||
class TopSiteItemViewHolder( | ||
private val view: View, | ||
private val interactor: TopSiteInteractor | ||
) : RecyclerView.ViewHolder(view) { | ||
private lateinit var topSite: TopSite | ||
|
||
init { | ||
view.top_site_item.setOnClickListener { | ||
interactor.onSelectTopSite(topSite.url) | ||
} | ||
} | ||
|
||
fun bind(topSite: TopSite) { | ||
this.topSite = topSite | ||
view.top_site_title.text = topSite.title | ||
view.context.components.core.icons.loadIntoView(view.favicon_image, topSite.url) | ||
} | ||
|
||
companion object { | ||
const val LAYOUT_ID = R.layout.top_site_item | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...c/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/topsites/TopSitesAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* 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.sessioncontrol.viewholders.topsites | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import mozilla.components.feature.top.sites.TopSite | ||
import org.mozilla.fenix.home.sessioncontrol.TopSiteInteractor | ||
|
||
class TopSitesAdapter( | ||
private val interactor: TopSiteInteractor | ||
) : ListAdapter<TopSite, TopSiteItemViewHolder>(DiffCallback) { | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TopSiteItemViewHolder { | ||
val view = LayoutInflater.from(parent.context) | ||
.inflate(TopSiteItemViewHolder.LAYOUT_ID, parent, false) | ||
return TopSiteItemViewHolder(view, interactor) | ||
} | ||
|
||
override fun onBindViewHolder(holder: TopSiteItemViewHolder, position: Int) { | ||
holder.bind(getItem(position)) | ||
} | ||
|
||
private object DiffCallback : DiffUtil.ItemCallback<TopSite>() { | ||
override fun areItemsTheSame(oldItem: TopSite, newItem: TopSite) = | ||
oldItem.id == newItem.id || oldItem.title == newItem.title || oldItem.url == newItem.url | ||
|
||
override fun areContentsTheSame(oldItem: TopSite, newItem: TopSite) = | ||
oldItem.id == newItem.id || oldItem.title == newItem.title || oldItem.url == newItem.url | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?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.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/top_sites_list" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
tools:listitem="@layout/top_site_item" /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?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/top_site_item" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="16dp" | ||
android:padding="4dp" | ||
android:paddingBottom="6dp"> | ||
|
||
<ImageView | ||
android:id="@+id/favicon_image" | ||
android:layout_width="40dp" | ||
android:layout_height="40dp" | ||
android:layout_marginBottom="2dp" | ||
android:adjustViewBounds="true" | ||
android:importantForAccessibility="no" | ||
android:scaleType="fitCenter" | ||
app:layout_constraintBottom_toTopOf="@id/top_site_title" | ||
app:layout_constraintDimensionRatio="1:1" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<TextView | ||
android:id="@+id/top_site_title" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:padding="2dp" | ||
android:singleLine="true" | ||
android:textColor="?primaryText" | ||
android:textSize="10sp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/favicon_image" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |