Fetch real repositories
This commit is contained in:
@@ -43,6 +43,10 @@ dependencies {
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
|
||||
implementation 'com.squareup.moshi:moshi:1.14.0'
|
||||
implementation 'com.squareup.moshi:moshi-kotlin:1.14.0'
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
|
||||
implementation 'com.squareup.retrofit2:converter-moshi:2.9.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
|
@@ -24,7 +24,7 @@ class FileListAdapter(private val dataSet: List<VersionedFile>, private val onCl
|
||||
}
|
||||
|
||||
fun bind(file: VersionedFile) {
|
||||
fileNameView.text = file.fileName
|
||||
fileNameView.text = file.name
|
||||
currentFile = file
|
||||
}
|
||||
}
|
||||
|
@@ -3,35 +3,38 @@ package fr.uca.iut.clfreville2.teaiswarm
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.Repository
|
||||
import fr.uca.iut.clfreville2.teaiswarm.network.GiteaService
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
const val REPOSITORY_OWNER = "repository_owner"
|
||||
const val REPOSITORY_NAME = "repository_name"
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private val service = GiteaService()
|
||||
private lateinit var repositories: RecyclerView
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
repositories = findViewById(R.id.repositories_view)
|
||||
repositories.adapter = RepositoryListAdapter(
|
||||
listOf(
|
||||
"oki",
|
||||
"moshell",
|
||||
"scrabble-with-numbers",
|
||||
"vdn-tools",
|
||||
"codefirst-test",
|
||||
"iut-config",
|
||||
"Ebullition"
|
||||
).map { Repository(it, 0) }) { repo ->
|
||||
adapterOnClick(repo)
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val repos = service.listActiveRepositories("clement.freville2", 1)
|
||||
lifecycleScope.launch {
|
||||
repositories.adapter = RepositoryListAdapter(repos) { repo ->
|
||||
adapterOnClick(repo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun adapterOnClick(repository: Repository) {
|
||||
val intent = Intent(this, RepositoryDetailActivity()::class.java)
|
||||
intent.putExtra(REPOSITORY_OWNER, repository.owner.login)
|
||||
intent.putExtra(REPOSITORY_NAME, repository.name)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
@@ -3,11 +3,16 @@ package fr.uca.iut.clfreville2.teaiswarm
|
||||
import android.os.Bundle
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.VersionedFile
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.RepositoryIdentifier
|
||||
import fr.uca.iut.clfreville2.teaiswarm.network.GiteaService
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class RepositoryDetailActivity : AppCompatActivity() {
|
||||
|
||||
private val service = GiteaService()
|
||||
private lateinit var repositoryName: TextView
|
||||
private lateinit var versionedFiles: RecyclerView
|
||||
|
||||
@@ -17,9 +22,11 @@ class RepositoryDetailActivity : AppCompatActivity() {
|
||||
|
||||
repositoryName = findViewById(R.id.repository_detail_name)
|
||||
|
||||
var currentRepositoryOwner: String? = null
|
||||
var currentRepositoryName: String? = null
|
||||
val bundle: Bundle? = intent.extras
|
||||
if (bundle != null) {
|
||||
currentRepositoryOwner = bundle.getString(REPOSITORY_OWNER)
|
||||
currentRepositoryName = bundle.getString(REPOSITORY_NAME)
|
||||
}
|
||||
|
||||
@@ -28,18 +35,11 @@ class RepositoryDetailActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
versionedFiles = findViewById(R.id.versioned_files_view)
|
||||
versionedFiles.adapter = FileListAdapter(
|
||||
listOf(
|
||||
"cli",
|
||||
"doc",
|
||||
"sql",
|
||||
"test",
|
||||
"web",
|
||||
".drone.yml",
|
||||
".gitignore",
|
||||
"CONVENTIONS.md",
|
||||
"README.md"
|
||||
).map { VersionedFile(it) }
|
||||
) {}
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val repos = service.listFileContents(RepositoryIdentifier(currentRepositoryOwner!!, currentRepositoryName!!), "")
|
||||
lifecycleScope.launch {
|
||||
versionedFiles.adapter = FileListAdapter(repos) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,3 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.model
|
||||
|
||||
data class Owner(val id: Int, val login: String)
|
@@ -1,3 +1,3 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.model
|
||||
|
||||
data class Repository(val name: String, val stars: Int)
|
||||
data class Repository(val owner: Owner, val name: String, val stars: Int = 0)
|
||||
|
@@ -0,0 +1,6 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.model
|
||||
|
||||
interface RepositoryIdentifiable {
|
||||
|
||||
val identifier: RepositoryIdentifier
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.model
|
||||
|
||||
data class RepositoryIdentifier(val owner: String, val name: String) : RepositoryIdentifiable {
|
||||
|
||||
override val identifier: RepositoryIdentifier
|
||||
get() = this
|
||||
}
|
@@ -1,3 +1,3 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.model
|
||||
|
||||
data class VersionedFile(val fileName: String)
|
||||
data class VersionedFile(val name: String)
|
||||
|
@@ -0,0 +1,48 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.network
|
||||
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.Repository
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.RepositoryIdentifiable
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.VersionedFile
|
||||
import okhttp3.OkHttpClient
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Path
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface GiteaApiService {
|
||||
|
||||
@GET("users/{username}/repos")
|
||||
suspend fun listActiveRepositories(@Path("username") username: String, @Query("page") page: Int): List<Repository>
|
||||
|
||||
@GET("repos/{owner}/{repo}/contents/{filePath}")
|
||||
suspend fun listFileContents(@Path("owner") owner: String, @Path("repo") repo: String, @Path("filePath") filePath: String): List<VersionedFile>
|
||||
}
|
||||
|
||||
class GiteaService(private val handle: GiteaApiService) : RepositoryService {
|
||||
|
||||
constructor() : this(createRetrofit().create(GiteaApiService::class.java))
|
||||
|
||||
override suspend fun listActiveRepositories(username: String, page: Int): List<Repository> =
|
||||
handle.listActiveRepositories(username, page)
|
||||
|
||||
override suspend fun listFileContents(repository: RepositoryIdentifiable, filePath: String): List<VersionedFile> =
|
||||
handle.listFileContents(repository.identifier.owner, repository.identifier.name, filePath)
|
||||
}
|
||||
|
||||
private const val CODEFIRST_API_BASE = "https://codefirst.iut.uca.fr/git/api/v1/"
|
||||
|
||||
private val httpClient = OkHttpClient()
|
||||
|
||||
private fun createRetrofit(): Retrofit =
|
||||
Retrofit.Builder()
|
||||
.baseUrl(CODEFIRST_API_BASE)
|
||||
.addConverterFactory(MoshiConverterFactory.create(
|
||||
Moshi.Builder()
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
.build()))
|
||||
.client(httpClient)
|
||||
.build()
|
@@ -0,0 +1,12 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.network
|
||||
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.Repository
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.RepositoryIdentifiable
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.VersionedFile
|
||||
|
||||
interface RepositoryService {
|
||||
|
||||
suspend fun listActiveRepositories(username: String, page: Int): List<Repository>
|
||||
|
||||
suspend fun listFileContents(repository: RepositoryIdentifiable, filePath: String): List<VersionedFile>
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.network
|
||||
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.Owner
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.Repository
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.RepositoryIdentifiable
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.VersionedFile
|
||||
|
||||
class StubRepositoryService : RepositoryService {
|
||||
|
||||
override suspend fun listActiveRepositories(username: String, page: Int): List<Repository> =
|
||||
when (page) {
|
||||
1 -> listOf(
|
||||
"oki",
|
||||
"moshell",
|
||||
"scrabble-with-numbers",
|
||||
"vdn-tools",
|
||||
"codefirst-test",
|
||||
"iut-config",
|
||||
"Ebullition"
|
||||
)
|
||||
2 -> listOf(
|
||||
"api-ef",
|
||||
"codefirst-docdeployer",
|
||||
"TeaIsWarm",
|
||||
"Application",
|
||||
"silex"
|
||||
)
|
||||
else -> listOf()
|
||||
}.map { Repository(Owner(-1, ""), it) }
|
||||
|
||||
override suspend fun listFileContents(repository: RepositoryIdentifiable, filePath: String) =
|
||||
listOf(
|
||||
"cli",
|
||||
"doc",
|
||||
"sql",
|
||||
"test",
|
||||
"web",
|
||||
".drone.yml",
|
||||
".gitignore",
|
||||
"CONVENTIONS.md",
|
||||
"README.md"
|
||||
).map { VersionedFile(it) }
|
||||
}
|
Reference in New Issue
Block a user