-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New Designs] Update Dashboard view to match new design (#631)
Fixes ooni/probe#2588 ## Proposed Changes - Update XML designs - Convert `ProgressFragment` to kotlin |.|.| |-|-| | ![Screenshot_20231031_172528](https://github.com/ooni/probe-android/assets/17911892/5b848e77-adf6-473c-889f-f8f119938aea) | ![Screenshot_20231031_172516](https://github.com/ooni/probe-android/assets/17911892/fe5f4d99-adc3-42b2-9571-737ae9db2b8f) | |![Screenshot_20231031_172436](https://github.com/ooni/probe-android/assets/17911892/1f30dbae-d8ae-43e1-b615-b34e295213bd) | ![Screenshot_20231031_172418](https://github.com/ooni/probe-android/assets/17911892/ea459e62-088e-4d37-886a-53347df94ca3)|
- Loading branch information
Showing
28 changed files
with
710 additions
and
448 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
111 changes: 111 additions & 0 deletions
111
app/src/main/java/org/openobservatory/ooniprobe/adapters/DashboardAdapter.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,111 @@ | ||
package org.openobservatory.ooniprobe.adapters | ||
|
||
import android.content.res.Resources | ||
import android.graphics.PorterDuff | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.cardview.widget.CardView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.openobservatory.ooniprobe.R | ||
import org.openobservatory.ooniprobe.common.PreferenceManager | ||
import org.openobservatory.ooniprobe.databinding.ItemSeperatorBinding | ||
import org.openobservatory.ooniprobe.databinding.ItemTestsuiteBinding | ||
import org.openobservatory.ooniprobe.test.suite.AbstractSuite | ||
|
||
class DashboardAdapter( | ||
private val items: List<Any>, | ||
private val onClickListener: View.OnClickListener, | ||
private val preferenceManager: PreferenceManager, | ||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { | ||
|
||
companion object { | ||
private const val VIEW_TYPE_TITLE = 0 | ||
private const val VIEW_TYPE_CARD = 1 | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
return when (viewType) { | ||
VIEW_TYPE_TITLE -> { | ||
CardGroupTitleViewHolder( | ||
ItemSeperatorBinding.inflate( | ||
LayoutInflater.from(parent.context), parent, false | ||
) | ||
) | ||
} | ||
|
||
else -> { | ||
CardViewHolder( | ||
ItemTestsuiteBinding.inflate( | ||
LayoutInflater.from(parent.context), parent, false | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { | ||
val item = items[position] | ||
when (holder.itemViewType) { | ||
VIEW_TYPE_TITLE -> { | ||
val separator = holder as CardGroupTitleViewHolder | ||
separator.binding.root.text = item as String | ||
} | ||
|
||
VIEW_TYPE_CARD -> { | ||
val cardHolder = holder as CardViewHolder | ||
if (item is AbstractSuite) { | ||
cardHolder.binding.apply { | ||
title.setText(item.title) | ||
desc.setText(item.cardDesc) | ||
icon.setImageResource(item.icon) | ||
} | ||
holder.itemView.tag = item | ||
if (item.isTestEmpty(preferenceManager)) { | ||
holder.setIsRecyclable(false) | ||
holder.itemView.apply { | ||
elevation = 0f | ||
isClickable = false | ||
} | ||
val resources: Resources = holder.itemView.context.resources | ||
(holder.itemView as CardView).setCardBackgroundColor(resources.getColor(R.color.disabled_test_background)) | ||
holder.binding.apply { | ||
title.setTextColor(resources.getColor(R.color.disabled_test_text)) | ||
desc.setTextColor(resources.getColor(R.color.disabled_test_text)) | ||
icon.setColorFilter( | ||
resources.getColor(R.color.disabled_test_text), | ||
PorterDuff.Mode.SRC_IN | ||
) | ||
} | ||
} else { | ||
holder.itemView.setOnClickListener(onClickListener) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return items.size | ||
} | ||
|
||
override fun getItemViewType(position: Int): Int { | ||
return when (items[position]) { | ||
is String -> VIEW_TYPE_TITLE | ||
else -> VIEW_TYPE_CARD | ||
} | ||
} | ||
|
||
/** | ||
* ViewHolder for a dashboard item group. | ||
* @param binding | ||
*/ | ||
class CardGroupTitleViewHolder(var binding: ItemSeperatorBinding) : | ||
RecyclerView.ViewHolder(binding.root) | ||
|
||
/** | ||
* ViewHolder for dashboard item. | ||
* @param binding | ||
*/ | ||
class CardViewHolder(var binding: ItemTestsuiteBinding) : RecyclerView.ViewHolder(binding.root) | ||
} |
140 changes: 0 additions & 140 deletions
140
app/src/main/java/org/openobservatory/ooniprobe/fragment/DashboardFragment.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.