Есть класс модели
class AccountModelNode private constructor(val key: String, val isLeaf: Boolean) {
constructor(key: String, value: AccountCardViewModel) : this(key, true) {
this.value = value
}
constructor(key: String, list: List<AccountModelNode>) : this(key, false) {
this.list = list
}
var value: AccountCardViewModel? = null
private set
var list: List<AccountModelNode>? = null
private set
}
b класс AccoundCardViewModel это data class, который содержит некоторые поля:
data class AccountCardViewModel(
val isAutomatic: Boolean = false,
val currencyCode: String = "",
val description: String = "")
Как вместо класса AccoundCardViewModel в модели использовать только поля AccountCardViewModel
?
Пробую следующим образом
interface ApiInterface {
object Prop {
operator fun getValue(thisRef: Any, property: KProperty<*>): String = "message"
}
@Multipart
@POST(API_FEEDBACK_PATH)
fun postFeedback(@Part("message") message: RequestBody,
@PartMap files: HashMap<String, RequestBody>,
@Part database: MultipartBody.Part?): Call<FeedbackResponse>
}
val ApiInterface.prop: String by ApiInterface.Prop
вместо "message " в методе postFeedback подставить ApiInterface.Prop.getValue()
но не выходит
не могу въехать как можно десериализовать .json класс??
ну то есть у меня уже есть класс
мне нужно его десериализовать в тестах для проверки переменных в нём.
В тест создал переменную
private var gson: Gson = GsonBuilder().registerTypeAdapter(AuthTypeData::class.java, FixturesManager.getAuthTypes()).create()
где getAuthTypes у меня это подтягивания фикстур:
@Throws(Exception::class)
fun getAuthTypes() = streamToString(InstrumentationRegistry.getContext().resources.assets.open("${FixturesManager.DB_FIXTURES_PATH}AuthTypes.json"))
после этого пробую обращаться к одной из переменных класса AuthTypeData:
val authTypeData = AuthTypeData()
authTypeData.code = "code"
и уже в тесте проверяю совпадают ли данные переменной
assertThat((fragment.arguments.getSerializable(CredentialsFragment.KEY_AUTHTYPE_DATA) as AuthTypeData).code,
equalTo("code"))
но тест неверный, так как ума не приложу как запилить туда переменную из json файла
java.lang.NoClassDefFoundError: Could not initialize class MySingleton
Приглашаем на вебинар «С чего начать разработку под Android»!
Старт: 19.03.18 в 19:00
Спикер: Андрей Мирошниченко - Senior Software Enginee at Zeo Alliance. Более 6 лет занимается разработкой под Android, из них 2 года пишет на Kotlin и программирует под Embedded Linux.
О чем Вы узнаете во время вебинара:
А также вы получите ответ на любой интересующий Вас вопрос.
Ссылка на мероприятие: https://www.facebook.com/events/597512283922490/
@Parcelize
enum class Product: Parcelable {
FOO,
BAR,
BAZ;
companion object {
private fun list(): ArrayList<Product> {
return arrayListOf(FOO, BAR, BAZ)
}
}
}
XML Layout<layout>
<data>
<import type="data.Product" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout>
<Spinner
android:id="@+id/spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:entries="@{Product.list}" />
Sample Android Components Architecture on a Modular Word
focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack
.
Application is based, apply and strictly complies with each of the following 5 points:
single-activity architecture
, using the Navigation component to manage fragment operations.architecture components
, part of Android Jetpack give to project a robust design, testable and maintainable.Model-View-ViewModel
(MVVM) facilitating separation of development of the graphical user interface.S.O.L.I.D
design principles intended to make software designs more understandable, flexible and maintainable.Modular app architecture
allows being developed features in isolation, independently from other features.Project link: https://github.com/VMadalin/android-modular-architecture