Setup adapter and empty test for ParentFolderPickerActivity.kt
MAILAND-2613
This commit is contained in:
parent
ffb2928fb7
commit
b331344c81
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Proton Technologies AG
|
||||
*
|
||||
* This file is part of ProtonMail.
|
||||
*
|
||||
* ProtonMail is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ProtonMail is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ProtonMail. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
package ch.protonmail.android.labels.presentation.ui
|
||||
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.ext.junit.rules.activityScenarioRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import ch.protonmail.android.R
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ParentFolderPickerActivityTest {
|
||||
|
||||
@get:Rule val activityScenarioRule = activityScenarioRule<ParentFolderPickerActivity>()
|
||||
|
||||
@Test
|
||||
fun justRuns() {
|
||||
onView(withId(R.id.parent_picker_toolbar)).check(matches(withText(R.string.parent_picker_title)))
|
||||
}
|
||||
}
|
|
@ -347,6 +347,10 @@
|
|||
android:exported="false"
|
||||
android:screenOrientation="portrait"
|
||||
android:label="@string/title_activity_address_chooser"/>
|
||||
<activity
|
||||
android:name=".labels.presentation.ui.ParentFolderPickerActivity"
|
||||
android:exported="true"/>
|
||||
|
||||
<service
|
||||
android:name=".api.services.MessagesService"
|
||||
android:exported="false"
|
||||
|
@ -365,6 +369,7 @@
|
|||
android:name=".api.services.ConnectivityService"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE" />
|
||||
|
||||
<!-- Core -->
|
||||
<activity
|
||||
android:name="me.proton.core.auth.presentation.ui.AuthHelpActivity"
|
||||
|
|
|
@ -19,10 +19,49 @@
|
|||
|
||||
package ch.protonmail.android.labels.presentation.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.PersistableBundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import ch.protonmail.android.R
|
||||
import ch.protonmail.android.databinding.ActivityParentFolderPickerBinding
|
||||
import ch.protonmail.android.databinding.ItemParentPickerFolderBinding
|
||||
import me.proton.core.presentation.ui.adapter.ProtonAdapter
|
||||
|
||||
class ParentFolderPickerActivity : AppCompatActivity(R.layout.activity_parent_folder_picker) {
|
||||
class ParentFolderPickerActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityParentFolderPickerBinding
|
||||
|
||||
private val adapter = ProtonAdapter(
|
||||
diffCallback = ParentFolderPickerUiModel.DiffCallback,
|
||||
getView = { parent, inflater ->
|
||||
ItemParentPickerFolderBinding.inflate(inflater, parent, false)
|
||||
},
|
||||
onBind = { model ->
|
||||
setMarginFor(folderLevel = model.folderLevel)
|
||||
parentPickerFolderIconImageView.apply {
|
||||
setColorFilter(model.colorInt)
|
||||
setImageResource(model.icon.drawableRes)
|
||||
contentDescription = getString(model.icon.contentDescriptionRes)
|
||||
}
|
||||
parentPickerFolderNameTextView.text = model.name
|
||||
}
|
||||
)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityParentFolderPickerBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
binding.parentPickerRecyclerView.apply {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
this.adapter = this@ParentFolderPickerActivity.adapter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ItemParentPickerFolderBinding.setMarginFor(folderLevel: Int) {
|
||||
(root.layoutParams as RecyclerView.LayoutParams).marginStart =
|
||||
folderLevel * root.context.resources.getDimensionPixelSize(R.dimen.gap_large)
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package ch.protonmail.android.labels.presentation.ui
|
|||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import ch.protonmail.android.R
|
||||
import ch.protonmail.android.labels.domain.model.LabelId
|
||||
import ch.protonmail.android.labels.presentation.ui.ParentFolderPickerUiModel.Icon.WithChildren
|
||||
|
@ -29,8 +30,9 @@ import ch.protonmail.android.labels.presentation.ui.ParentFolderPickerUiModel.Ic
|
|||
sealed class ParentFolderPickerUiModel(
|
||||
val id: LabelId,
|
||||
val name: String,
|
||||
val colorInt: Int,
|
||||
val icon: Icon,
|
||||
val level: Int
|
||||
val folderLevel: Int
|
||||
) {
|
||||
|
||||
/**
|
||||
|
@ -55,4 +57,13 @@ sealed class ParentFolderPickerUiModel(
|
|||
R.string.parent_picker_folder_icon_description
|
||||
)
|
||||
}
|
||||
|
||||
object DiffCallback : DiffUtil.ItemCallback<ParentFolderPickerUiModel>() {
|
||||
|
||||
override fun areItemsTheSame(oldItem: ParentFolderPickerUiModel, newItem: ParentFolderPickerUiModel) =
|
||||
oldItem.id == newItem.id
|
||||
|
||||
override fun areContentsTheSame(oldItem: ParentFolderPickerUiModel, newItem: ParentFolderPickerUiModel) =
|
||||
oldItem == newItem
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue