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

[Team-01][Android] Todo 화면 및 레포지토리 구현 #151

Open
wants to merge 11 commits into
base: team-01
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.example.todo_list.databinding.ActivityMainBinding
import com.example.todo_list.history.HistoryAdapter
import com.example.todo_list.history.HistoryViewModel
import com.example.todo_list.history.data.HistoryRepository
import com.example.todo_list.data.TasksRepository
import com.google.android.material.navigation.NavigationView

class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
Expand All @@ -22,7 +22,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)

historyViewModel = ViewModelProvider(this, ViewModelFactory(HistoryRepository())).get(HistoryViewModel::class.java)
historyViewModel = ViewModelProvider(this, ViewModelFactory(TasksRepository())).get(HistoryViewModel::class.java)

val adapter = HistoryAdapter()
binding.recyclerviewHistory.adapter = adapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.todo_list

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.example.todo_list.data.Repository
import com.example.todo_list.history.HistoryViewModel

class ViewModelFactory(private val repository: Repository) : ViewModelProvider.Factory {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.todo_list
package com.example.todo_list.data
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

패키지명이 todo_list 인가요? 특별한 이유가 없다면 소문자로 작성되는것이 컨벤션이라 맞추는게 좋을거 같습니다!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경 완료했습니다. 감사합니다!


import com.example.todo_list.history.data.HistoryCard
import retrofit2.Response
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.todo_list.data

import com.example.todo_list.history.data.HistoryCard
import com.example.todo_list.network.NetworkModule
import retrofit2.Response

class TasksRepository : Repository {
private val network = NetworkModule.service

override suspend fun getHistories(): Response<List<HistoryCard>> {
return network.getHistories("histories")
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.todo_list.Repository
import com.example.todo_list.data.Repository
import com.example.todo_list.history.data.HistoryCard
import kotlinx.coroutines.launch

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.todo_list.network

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

class NetworkModule {
companion object RetrofitApiObject {
private const val BASE_URL = "https://f278a12c-c825-466b-aa01-65337bbdf28a.mock.pstmn.io/"

private val retrofit =
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
val service: TodoService = retrofit.create(TodoService::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.todo_list.network

import com.example.todo_list.history.data.HistoryCard
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Path

interface TodoService {

@GET("api/{histories}")
suspend fun getHistories(
@Path("histories") variable: String
): Response<List<HistoryCard>>
}