Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- use xml in ui #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/render.experimental.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'androidx.navigation.safeargs.kotlin'
}

android {
Expand Down Expand Up @@ -35,18 +36,16 @@ android {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.21'
}

packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}

buildFeatures {
viewBinding true
}
}

dependencies {
Expand All @@ -66,8 +65,8 @@ dependencies {
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"

// Compose dependencies
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07"
implementation "androidx.navigation:navigation-compose:2.4.0-alpha08"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0-beta01"
implementation "androidx.navigation:navigation-compose:2.4.0-alpha09"
implementation "com.google.accompanist:accompanist-flowlayout:0.17.0"

// Coroutines
Expand All @@ -90,4 +89,11 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.2"
implementation "com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2"

//navigation component
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

//flow layout
implementation 'com.nex3z:flow-layout:1.3.3'
}
8 changes: 5 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.plcoding.cryptocurrencyappyt">

<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".CoinApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CryptocurrencyAppYT">
android:theme="@style/Theme.CryptocurrencyApp">
<activity
android:name=".MainActivity"
android:name=".presentation.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.CryptocurrencyAppYT.NoActionBar">
android:theme="@style/Theme.CryptocurrencyApp.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.plcoding.cryptocurrencyappyt

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class CoinApplication : Application() {
}
24 changes: 0 additions & 24 deletions app/src/main/java/com/plcoding/cryptocurrencyappyt/MainActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.plcoding.cryptocurrencyappyt.common

object Constants {

const val BASE_URL = "https://api.coinpaprika.com/"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.plcoding.cryptocurrencyappyt.common

sealed class Resource<T>(val data: T? = null, val message: String? = null) {
class Success<T>(data: T) : Resource<T>(data)
class Error<T>(message: String?, data: T? = null) : Resource<T>(data, message)
class Loading<T>(data: T? = null) : Resource<T>(data)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.plcoding.cryptocurrencyappyt.data.remote

import com.plcoding.cryptocurrencyappyt.data.remote.dto.CoinDetailDto
import com.plcoding.cryptocurrencyappyt.data.remote.dto.CoinDto
import retrofit2.http.GET
import retrofit2.http.Path

interface CoinPaprikaApi {
@GET("/v1/coins")
suspend fun getCoins(): List<CoinDto>

@GET("/v1/coins/{coinId}")
suspend fun getCoin(@Path("coinId") coinId: String): CoinDetailDto
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.plcoding.cryptocurrencyappyt.data.remote.dto

import com.plcoding.cryptocurrencyappyt.domain.model.CoinDetail

data class CoinDetailDto(
val description: String,
val development_status: String,
val first_data_at: String,
val hardware_wallet: Boolean,
val hash_algorithm: String,
val id: String,
val is_active: Boolean,
val is_new: Boolean,
val last_data_at: String,
val links: Links,
val links_extended: List<LinksExtended>,
val message: String,
val name: String,
val open_source: Boolean,
val org_structure: String,
val proof_type: String,
val rank: Int,
val started_at: String,
val symbol: String,
val tags: List<Tag>,
val team: List<TeamMember>,
val type: String,
val whitepaper: Whitepaper
)

fun CoinDetailDto.toCoinDetail() : CoinDetail = CoinDetail(
coinId = id,
name = name,
description = description,
symbol = symbol,
rank = rank,
isActive = is_active,
tags = tags.map { it.name },
team = team
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.plcoding.cryptocurrencyappyt.data.remote.dto

import com.plcoding.cryptocurrencyappyt.domain.model.Coin

data class CoinDto(
val id: String,
val is_active: Boolean,
val is_new: Boolean,
val name: String,
val rank: Int,
val symbol: String,
val type: String
)

fun CoinDto.toCoin() : Coin = Coin(
id = id,
isActive = is_active,
name = name,
rank = rank,
symbol = symbol
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.plcoding.cryptocurrencyappyt.data.remote.dto

data class Links(
val explorer: List<String>,
val facebook: List<String>,
val reddit: List<String>,
val source_code: List<String>,
val website: List<String>,
val youtube: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.plcoding.cryptocurrencyappyt.data.remote.dto

data class LinksExtended(
val stats: Stats,
val type: String,
val url: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.plcoding.cryptocurrencyappyt.data.remote.dto

data class Stats(
val contributors: Int,
val followers: Int,
val stars: Int,
val subscribers: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.plcoding.cryptocurrencyappyt.data.remote.dto

data class Tag(
val coin_counter: Int,
val ico_counter: Int,
val id: String,
val name: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.plcoding.cryptocurrencyappyt.data.remote.dto

data class TeamMember(
val id: String,
val name: String,
val position: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.plcoding.cryptocurrencyappyt.data.remote.dto

data class Whitepaper(
val link: String,
val thumbnail: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.plcoding.cryptocurrencyappyt.data.repository

import com.plcoding.cryptocurrencyappyt.data.remote.CoinPaprikaApi
import com.plcoding.cryptocurrencyappyt.data.remote.dto.CoinDetailDto
import com.plcoding.cryptocurrencyappyt.data.remote.dto.CoinDto
import com.plcoding.cryptocurrencyappyt.domain.repository.CoinRepository
import javax.inject.Inject

class CoinRepositoryImp @Inject constructor(
private val api: CoinPaprikaApi
) : CoinRepository {

override suspend fun getCoins(): List<CoinDto> {
return api.getCoins()
}

override suspend fun getCoinById(coinId: String): CoinDetailDto {
return api.getCoin(coinId)
}
}
32 changes: 32 additions & 0 deletions app/src/main/java/com/plcoding/cryptocurrencyappyt/di/AppModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.plcoding.cryptocurrencyappyt.di

import com.plcoding.cryptocurrencyappyt.common.Constants
import com.plcoding.cryptocurrencyappyt.data.remote.CoinPaprikaApi
import com.plcoding.cryptocurrencyappyt.data.repository.CoinRepositoryImp
import com.plcoding.cryptocurrencyappyt.domain.repository.CoinRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object AppModule {

@Provides
@Singleton
fun providePaprikaApi(): CoinPaprikaApi {
return Retrofit.Builder().baseUrl(Constants.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build().create(CoinPaprikaApi::class.java)
}

@Provides
@Singleton
fun provideCoinRepository(api: CoinPaprikaApi): CoinRepository {
return CoinRepositoryImp(api)
}
}
Loading