diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..aa724b770 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 000000000..657ac6520 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +DesafioAndroidApp \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 000000000..fb7f4a8a4 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 000000000..a2d7c2133 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..a154d8687 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..35eb1ddfb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 000000000..88c46f8ec --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,64 @@ +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' + id 'kotlin-parcelize' +} + +android { + compileSdk 32 + + defaultConfig { + applicationId "com.example.desafioandroidapp" + minSdk 27 + targetSdk 32 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + buildConfigField("String", "API_URL", "\"https://api.github.com/search/\"") + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + buildFeatures { + viewBinding = true + } + viewBinding { + enabled = true + } +} + +var retrofitVersion = "2.9.0" + +dependencies { + + implementation 'androidx.core:core-ktx:1.7.0' + implementation 'androidx.appcompat:appcompat:1.4.2' + implementation 'com.google.android.material:material:1.6.1' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1' + implementation 'androidx.navigation:navigation-ui-ktx:2.4.2' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + + implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" + implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion" + implementation "com.squareup.okhttp3:logging-interceptor:4.7.2" + + def picassoVersion = "2.71828" + implementation "com.squareup.picasso:picasso:$picassoVersion" +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/desafioandroidapp/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/example/desafioandroidapp/ExampleInstrumentedTest.kt new file mode 100644 index 000000000..d2916e473 --- /dev/null +++ b/app/src/androidTest/java/com/example/desafioandroidapp/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.desafioandroidapp + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.desafioandroidapp", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..587db08e4 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/desafioandroidapp/data/DesafioApiDataSource.kt b/app/src/main/java/com/example/desafioandroidapp/data/DesafioApiDataSource.kt new file mode 100644 index 000000000..85bbd4b4c --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/data/DesafioApiDataSource.kt @@ -0,0 +1,77 @@ +package com.example.desafioandroidapp.data + +import com.example.desafioandroidapp.data.dto.Repository +import com.example.desafioandroidapp.data.dto.Error +import com.example.desafioandroidapp.data.dto.Pull +import com.example.desafioandroidapp.data.util.RetrofitService +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class DesafioApiDataSource { + fun getRepositories(listener: RepositoryListener, page: Int) { + val service = RetrofitService.instance.create(DesafioApiService::class.java).getRepositories(page) + + service.enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + val callResponse = response.body() + if (response.isSuccessful && null != callResponse) { + listener.onResponse(callResponse) + } else { + listener.onError( + Error( + "Unexpected Error", + response.code() + ) + ) + } + } + + override fun onFailure(call: Call, t: Throwable) { + listener.onError( + Error( + "Unexpected Error", + 0 + ) + ) + } + + }) + } + + fun getPulls(listener: PullListener>, owner: String, repository: String) { + val service = RetrofitService.instance.create(DesafioApiService::class.java).getPulls(owner,repository) + + service.enqueue(object : Callback> { + override fun onResponse( + call: Call>, + response: Response> + ) { + val callResponse = response.body() + if (response.isSuccessful && null != callResponse) { + listener.onResponsePull(callResponse) + } else { + listener.onError( + Error( + "Unexpected Error", + response.code() + ) + ) + } + } + + override fun onFailure(call: Call>, t: Throwable) { + listener.onError( + Error( + "Unexpected Error", + 0 + ) + ) + } + + }) + } +} diff --git a/app/src/main/java/com/example/desafioandroidapp/data/DesafioApiRepository.kt b/app/src/main/java/com/example/desafioandroidapp/data/DesafioApiRepository.kt new file mode 100644 index 000000000..2e1a54c9c --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/data/DesafioApiRepository.kt @@ -0,0 +1,14 @@ +package com.example.desafioandroidapp.data + +import com.example.desafioandroidapp.data.dto.Pull +import com.example.desafioandroidapp.data.dto.Repository + +data class DesafioApiRepository(private val desafioApiDatasource: DesafioApiDataSource) { + fun getRepositories(listener: RepositoryListener, page: Int) { + this.desafioApiDatasource.getRepositories(listener,page) + } + + fun getPulls(listener: PullListener>, owner: String, repository: String) { + this.desafioApiDatasource.getPulls(listener, owner, repository) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/desafioandroidapp/data/DesafioApiService.kt b/app/src/main/java/com/example/desafioandroidapp/data/DesafioApiService.kt new file mode 100644 index 000000000..b5599d256 --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/data/DesafioApiService.kt @@ -0,0 +1,17 @@ +package com.example.desafioandroidapp.data + +import com.example.desafioandroidapp.data.dto.Pull +import com.example.desafioandroidapp.data.dto.Repository +import retrofit2.Call +import retrofit2.http.GET +import retrofit2.http.Path +import retrofit2.http.Query + +interface DesafioApiService { + + @GET("/search/repositories?q=language:Java&sort=stars") + fun getRepositories(@Query("page") page: Int): Call + + @GET("/repos/{owner}/{repository}/pulls") + fun getPulls(@Path("owner") owner: String, @Path("repository") repository: String): Call> +} \ No newline at end of file diff --git a/app/src/main/java/com/example/desafioandroidapp/data/PullListener.kt b/app/src/main/java/com/example/desafioandroidapp/data/PullListener.kt new file mode 100644 index 000000000..79cc0bb6a --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/data/PullListener.kt @@ -0,0 +1,11 @@ +package com.example.desafioandroidapp.data + +import com.example.desafioandroidapp.data.dto.Error +import com.example.desafioandroidapp.data.dto.Pull + +interface PullListener { + + fun onResponsePull(response: List) + + fun onError(repositoryError: Error) +} \ No newline at end of file diff --git a/app/src/main/java/com/example/desafioandroidapp/data/RepositoryListener.kt b/app/src/main/java/com/example/desafioandroidapp/data/RepositoryListener.kt new file mode 100644 index 000000000..08a088c9d --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/data/RepositoryListener.kt @@ -0,0 +1,11 @@ +package com.example.desafioandroidapp.data + +import com.example.desafioandroidapp.data.dto.* + +interface RepositoryListener { + + fun onResponse(response: Repository) + + fun onError(repositoryError: Error) + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/desafioandroidapp/data/dto/Error.kt b/app/src/main/java/com/example/desafioandroidapp/data/dto/Error.kt new file mode 100644 index 000000000..79c59a18a --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/data/dto/Error.kt @@ -0,0 +1,6 @@ +package com.example.desafioandroidapp.data.dto + +data class Error( + val message: String, + val code: Int +) diff --git a/app/src/main/java/com/example/desafioandroidapp/data/dto/Owner.kt b/app/src/main/java/com/example/desafioandroidapp/data/dto/Owner.kt new file mode 100644 index 000000000..259998695 --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/data/dto/Owner.kt @@ -0,0 +1,11 @@ +package com.example.desafioandroidapp.data.dto + +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +@Parcelize +data class Owner( + val login: String, + val id: Int, + val avatar_url: String +) : Parcelable diff --git a/app/src/main/java/com/example/desafioandroidapp/data/dto/Pull.kt b/app/src/main/java/com/example/desafioandroidapp/data/dto/Pull.kt new file mode 100644 index 000000000..1d9039dbe --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/data/dto/Pull.kt @@ -0,0 +1,16 @@ +package com.example.desafioandroidapp.data.dto + +import com.google.gson.annotations.SerializedName + +data class Pull( + @SerializedName("url") + val url: String, + @SerializedName("title") + val title: String, + @SerializedName("body") + val body: String, + @SerializedName("state") + val state: String, + @SerializedName("user") + val user: User +) diff --git a/app/src/main/java/com/example/desafioandroidapp/data/dto/Repository.kt b/app/src/main/java/com/example/desafioandroidapp/data/dto/Repository.kt new file mode 100644 index 000000000..c46b32d7c --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/data/dto/Repository.kt @@ -0,0 +1,12 @@ +package com.example.desafioandroidapp.data.dto + +import com.google.gson.annotations.SerializedName + +data class Repository( + @SerializedName("total_count") + val total_count: Int, + @SerializedName("incomplete_results") + val incomplete_results: Boolean, + @SerializedName("items") + val repositoryItems : List +) diff --git a/app/src/main/java/com/example/desafioandroidapp/data/dto/RepositoryItem.kt b/app/src/main/java/com/example/desafioandroidapp/data/dto/RepositoryItem.kt new file mode 100644 index 000000000..94885d512 --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/data/dto/RepositoryItem.kt @@ -0,0 +1,29 @@ +package com.example.desafioandroidapp.data.dto + +import android.os.Parcelable +import com.google.gson.annotations.SerializedName +import kotlinx.parcelize.Parcelize + +@Parcelize +data class RepositoryItem( + @SerializedName("id") + val id: Int, + @SerializedName("node_id") + val node_id: String, + @SerializedName("name") + val name: String, + @SerializedName("full_name") + val full_name: String, + @SerializedName("private") + val private : Boolean, + @SerializedName("owner") + val owner : Owner, + @SerializedName("stargazers_count") + val stargazers_count: String, + @SerializedName("forks_count") + val forks_count: String, + @SerializedName("description") + val description: String?, + @SerializedName("pulls_url") + val pulls_url: String +) : Parcelable diff --git a/app/src/main/java/com/example/desafioandroidapp/data/dto/User.kt b/app/src/main/java/com/example/desafioandroidapp/data/dto/User.kt new file mode 100644 index 000000000..4ab613021 --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/data/dto/User.kt @@ -0,0 +1,12 @@ +package com.example.desafioandroidapp.data.dto + +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +@Parcelize +data class User( + val login: String, + val id: Long, + val node_id: String, + val avatar_url: String, +) : Parcelable diff --git a/app/src/main/java/com/example/desafioandroidapp/data/util/RetrofitService.kt b/app/src/main/java/com/example/desafioandroidapp/data/util/RetrofitService.kt new file mode 100644 index 000000000..9eae4f6e6 --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/data/util/RetrofitService.kt @@ -0,0 +1,22 @@ +package com.example.desafioandroidapp.data.util + +import com.example.desafioandroidapp.BuildConfig +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory + +object RetrofitService { + val instance: Retrofit + get() { + val httpClient = OkHttpClient.Builder() + .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)) + .build() + + return Retrofit.Builder() + .baseUrl(BuildConfig.API_URL) + .addConverterFactory(GsonConverterFactory.create()) + .client(httpClient) + .build() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/desafioandroidapp/views/RepositoryDetail.kt b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryDetail.kt new file mode 100644 index 000000000..053224352 --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryDetail.kt @@ -0,0 +1,62 @@ +package com.example.desafioandroidapp.views + +import android.annotation.SuppressLint +import android.os.Bundle +import androidx.activity.viewModels +import androidx.appcompat.app.AppCompatActivity +import androidx.recyclerview.widget.LinearLayoutManager +import com.example.desafioandroidapp.R +import com.example.desafioandroidapp.data.dto.Pull +import com.example.desafioandroidapp.data.dto.RepositoryItem +import com.example.desafioandroidapp.databinding.RepositoryDetailBinding + +class RepositoryDetail : AppCompatActivity() { + + private lateinit var binding : RepositoryDetailBinding + private val viewModel: RepositoryDetailViewModel by viewModels( + factoryProducer = { RepositoryDetailViewModelFactory() } + ) + + private val adapter = RepositoryDetailAdapter(object: RepositoryDetailAdapter.PullsListener{ + override fun selectedItem(pull : Pull){ + TODO("Not yet implemented") + } + }) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val bundle = intent.extras + val repositoryItem = bundle?.getParcelable(R.string.ITEM.toString()) + binding = RepositoryDetailBinding.inflate(layoutInflater) + setContentView(binding.root) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.title = repositoryItem?.name + + binding.pullsList.layoutManager = LinearLayoutManager(this) + viewModel.getPulls(repositoryItem?.owner?.login ?: "", repositoryItem?.name ?: "") + setObservers() + } + + @SuppressLint("NotifyDataSetChanged") + private fun setObservers(){ + this.viewModel.data.observe(this){ value -> + if(value != null){ + binding.pullsList.adapter = adapter + adapter.setPulls(value) + adapter.notifyDataSetChanged() + } + } + this.viewModel.openedPullsNumber.observe(this){ value -> + if(value != 0){ + binding.openedNumber.text = viewModel.openedPullsNumber.value.toString() + println("abiertos: ${viewModel.openedPullsNumber.value}") + } + } + this.viewModel.closedPullsNumber.observe(this){ value -> + if(value != 0){ + binding.closedNumber.text = viewModel.closedPullsNumber.value.toString() + println("cerrados: ${viewModel.closedPullsNumber.value}") + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/desafioandroidapp/views/RepositoryDetailAdapter.kt b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryDetailAdapter.kt new file mode 100644 index 000000000..bd4a4d009 --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryDetailAdapter.kt @@ -0,0 +1,53 @@ +package com.example.desafioandroidapp.views + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.example.desafioandroidapp.data.dto.Pull +import com.example.desafioandroidapp.databinding.PullsItemBinding +import com.squareup.picasso.Picasso + +class RepositoryDetailAdapter(private val listener: PullsListener): RecyclerView.Adapter() { + + private var pullsList : ArrayList = ArrayList() + interface PullsListener{ + fun selectedItem( + pull : Pull) + } + + fun setPulls(newPullsList: List){ + if (this.pullsList.isEmpty()){ + this.pullsList = newPullsList as ArrayList + }else{ + this.pullsList.addAll(newPullsList) + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PullViewHolder { + val layoutInflater = LayoutInflater.from(parent.context) + val binding = PullsItemBinding.inflate(layoutInflater,parent,false) + return PullViewHolder(binding) + } + + override fun onBindViewHolder(holder: PullViewHolder, position: Int) { + holder.bind(this.pullsList[position], listener) + } + + override fun getItemCount(): Int { + return this.pullsList.size + } + + class PullViewHolder( + private val binding: PullsItemBinding + ): RecyclerView.ViewHolder(binding.root){ + fun bind(pull: Pull, listener: PullsListener) { + this.binding.title.text = pull.title + this.binding.body.text = pull.body + this.binding.ownerName.text = pull.user.login + Picasso.get().load(pull.user.avatar_url).into(this.binding.imageView) + this.binding.root.setOnClickListener{ + listener.selectedItem(pull) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/desafioandroidapp/views/RepositoryDetailViewModel.kt b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryDetailViewModel.kt new file mode 100644 index 000000000..a099b2b45 --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryDetailViewModel.kt @@ -0,0 +1,47 @@ +package com.example.desafioandroidapp.views + +import android.widget.Toast +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.example.desafioandroidapp.data.DesafioApiRepository +import com.example.desafioandroidapp.data.PullListener +import com.example.desafioandroidapp.data.dto.Error +import com.example.desafioandroidapp.data.dto.Pull + +class RepositoryDetailViewModel (private val desafioApiRepository: DesafioApiRepository) : ViewModel(){ + val success = MutableLiveData(false) + val data = MutableLiveData?>(null) + var openedPullsNumber = MutableLiveData(0) + var closedPullsNumber = MutableLiveData(0) + + fun getPulls(owner: String, repository: String){ + success.value = false + data.value = null + + desafioApiRepository.getPulls(object: PullListener> { + override fun onResponsePull(response: List) { + if(response.isNotEmpty()) { + data.value = response + pullStatusCount(data.value!!) + success.value = true + } + } + + override fun onError(repositoryError: Error) { + Toast.makeText(null, "Error getting imageSlider data", Toast.LENGTH_LONG).show() + } + + }, owner, repository) + } + + private fun pullStatusCount(pullsList : List){ + pullsList.forEach { + println("estado: ${it.state}") + if(it.state == "open"){ + openedPullsNumber.value = openedPullsNumber.value?.plus(1) + }else{ + closedPullsNumber.value = closedPullsNumber.value?.plus(1) + } + } + } +} diff --git a/app/src/main/java/com/example/desafioandroidapp/views/RepositoryDetailViewModelFactory.kt b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryDetailViewModelFactory.kt new file mode 100644 index 000000000..7e036b7c9 --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryDetailViewModelFactory.kt @@ -0,0 +1,14 @@ +package com.example.desafioandroidapp.views + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import com.example.desafioandroidapp.data.DesafioApiDataSource +import com.example.desafioandroidapp.data.DesafioApiRepository + +class RepositoryDetailViewModelFactory : ViewModelProvider.Factory { + override fun create(modelClass: Class): T { + val desafioApiDatasource = DesafioApiDataSource() + val desafioApiRepository = DesafioApiRepository(desafioApiDatasource) + return RepositoryDetailViewModel(desafioApiRepository) as T + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/desafioandroidapp/views/RepositoryMain.kt b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryMain.kt new file mode 100644 index 000000000..a0d261583 --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryMain.kt @@ -0,0 +1,83 @@ +package com.example.desafioandroidapp.views + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import androidx.activity.viewModels +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.example.desafioandroidapp.R +import com.example.desafioandroidapp.data.dto.RepositoryItem +//import com.example.desafioandroidapp.R +import com.example.desafioandroidapp.databinding.RepositoryMainBinding + +class RepositoryMain : AppCompatActivity() { + + private lateinit var binding : RepositoryMainBinding + private val viewModel: RepositoryMainViewModel by viewModels( + factoryProducer = { RepositoryMainViewModelFactory() } + ) + + private val adapter = RepositoryMainAdapter(object: RepositoryMainAdapter.ItemsListener { + override fun selectedItem(repositoryItem : RepositoryItem) { + val bundle = Bundle() + bundle.putParcelable(R.string.ITEM.toString(),repositoryItem) + val intent = Intent(applicationContext, RepositoryDetail::class.java) + intent.putExtras(bundle) + startActivity(intent) + } + }) + + private var page = 1 + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = RepositoryMainBinding.inflate(layoutInflater) + setContentView(binding.root) + + binding.repositoryList.layoutManager = LinearLayoutManager(this) + + viewModel.getRepositories(page) + addOnScrollListener() + setObservers() + //setListeners() + } + + private fun addOnScrollListener() { + binding.repositoryList.addOnScrollListener(object : RecyclerView.OnScrollListener() { + @SuppressLint("NotifyDataSetChanged") + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + super.onScrolled(recyclerView, dx, dy) + + val linearLayoutManager = recyclerView.layoutManager as LinearLayoutManager? + if (linearLayoutManager != null && isBottomOfList(linearLayoutManager) && viewModel.continueapi.value != false) { + ++page + viewModel.getRepositories(page) + } + } + }) + } + + fun isBottomOfList(linearLayoutManager : LinearLayoutManager): Boolean { + return linearLayoutManager.findLastCompletelyVisibleItemPosition() == adapter.repositoryItems.size - 1 + } + + + @SuppressLint("NotifyDataSetChanged") + private fun setObservers(){ + this.viewModel.data.observe(this){ value -> + if (value != null) { + binding.repositoryList.adapter = adapter + adapter.setRepositories(value) + adapter.notifyDataSetChanged() + } + } + } + + /*private fun setListeners(){ + TODO() + }*/ + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/desafioandroidapp/views/RepositoryMainAdapter.kt b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryMainAdapter.kt new file mode 100644 index 000000000..be567ff98 --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryMainAdapter.kt @@ -0,0 +1,56 @@ +package com.example.desafioandroidapp.views + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.example.desafioandroidapp.data.dto.RepositoryItem +import com.example.desafioandroidapp.databinding.RepositoryItemBinding +import com.squareup.picasso.Picasso + +class RepositoryMainAdapter(private val listener: ItemsListener): RecyclerView.Adapter() { + + var repositoryItems : ArrayList = ArrayList() + interface ItemsListener{ + fun selectedItem( + repositoryItem : RepositoryItem) + } + fun setRepositories(newRepositoryItem: List) { + if(this.repositoryItems.isEmpty()){ + this.repositoryItems = newRepositoryItem as ArrayList + }else { + this.repositoryItems.addAll(newRepositoryItem) + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val layoutInflater = LayoutInflater.from(parent.context) + val binding = RepositoryItemBinding.inflate(layoutInflater,parent,false) + return ItemViewHolder(binding) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + holder.bind(this.repositoryItems[position], listener) + } + + override fun getItemCount(): Int { + return this.repositoryItems.size + } + + class ItemViewHolder( + private val binding: RepositoryItemBinding + ): RecyclerView.ViewHolder(binding.root){ + fun bind(repositoryItem: RepositoryItem, listener: ItemsListener) { + this.binding.repoName.text = repositoryItem.name + this.binding.description.text = repositoryItem.description + this.binding.forkNumber.text = repositoryItem.forks_count + this.binding.starNumber.text = repositoryItem.stargazers_count + this.binding.ownerName.text = repositoryItem.owner.login + Picasso.get().load(repositoryItem.owner.avatar_url).into(this.binding.imageView) + this.binding.cardView.setOnClickListener{ + listener.selectedItem(repositoryItem) + } + } + + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/desafioandroidapp/views/RepositoryMainViewModel.kt b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryMainViewModel.kt new file mode 100644 index 000000000..bfcbdb337 --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryMainViewModel.kt @@ -0,0 +1,36 @@ +package com.example.desafioandroidapp.views + +import android.widget.Toast +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.example.desafioandroidapp.data.DesafioApiRepository +import com.example.desafioandroidapp.data.RepositoryListener +import com.example.desafioandroidapp.data.dto.RepositoryItem +import com.example.desafioandroidapp.data.dto.Repository +import com.example.desafioandroidapp.data.dto.Error + +class RepositoryMainViewModel(private val desafioApiRepository: DesafioApiRepository) : ViewModel(){ + val success = MutableLiveData(false) + val data = MutableLiveData?>(null) + val continueapi = MutableLiveData(true) + + fun getRepositories(page: Int) { + success.value = false + data.value = null + + desafioApiRepository.getRepositories(object: RepositoryListener { + override fun onResponse(response: Repository) { + if(response.total_count > 0) { + data.value = response.repositoryItems + continueapi.value = response.incomplete_results + success.value = true + } + } + + override fun onError(repositoryError: Error) { + Toast.makeText(null, "Error getting imageSlider data", Toast.LENGTH_LONG).show() + } + + }, page) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/desafioandroidapp/views/RepositoryMainViewModelFactory.kt b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryMainViewModelFactory.kt new file mode 100644 index 000000000..6b52d25ae --- /dev/null +++ b/app/src/main/java/com/example/desafioandroidapp/views/RepositoryMainViewModelFactory.kt @@ -0,0 +1,13 @@ +package com.example.desafioandroidapp.views + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import com.example.desafioandroidapp.data.* + +class RepositoryMainViewModelFactory : ViewModelProvider.Factory { + override fun create(modelClass: Class): T { + val desafioApiDatasource = DesafioApiDataSource() + val desafioApiRepository = DesafioApiRepository(desafioApiDatasource) + return RepositoryMainViewModel(desafioApiRepository) as T + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/fork_image.png b/app/src/main/res/drawable-v24/fork_image.png new file mode 100644 index 000000000..93cb30130 Binary files /dev/null and b/app/src/main/res/drawable-v24/fork_image.png differ diff --git a/app/src/main/res/drawable-v24/github_logo.png b/app/src/main/res/drawable-v24/github_logo.png new file mode 100644 index 000000000..9490ffc6d Binary files /dev/null and b/app/src/main/res/drawable-v24/github_logo.png differ diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 000000000..2b068d114 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/star_image.png b/app/src/main/res/drawable-v24/star_image.png new file mode 100644 index 000000000..e2df767be Binary files /dev/null and b/app/src/main/res/drawable-v24/star_image.png differ diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 000000000..07d5da9cb --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/font/archivo_black.xml b/app/src/main/res/font/archivo_black.xml new file mode 100644 index 000000000..d7074936d --- /dev/null +++ b/app/src/main/res/font/archivo_black.xml @@ -0,0 +1,7 @@ + + + diff --git a/app/src/main/res/font/archivo_medium.xml b/app/src/main/res/font/archivo_medium.xml new file mode 100644 index 000000000..989a7af63 --- /dev/null +++ b/app/src/main/res/font/archivo_medium.xml @@ -0,0 +1,7 @@ + + + diff --git a/app/src/main/res/layout/pulls_item.xml b/app/src/main/res/layout/pulls_item.xml new file mode 100644 index 000000000..668be53b1 --- /dev/null +++ b/app/src/main/res/layout/pulls_item.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/repository_detail.xml b/app/src/main/res/layout/repository_detail.xml new file mode 100644 index 000000000..2b6d5be21 --- /dev/null +++ b/app/src/main/res/layout/repository_detail.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/repository_item.xml b/app/src/main/res/layout/repository_item.xml new file mode 100644 index 000000000..9cb2a0092 --- /dev/null +++ b/app/src/main/res/layout/repository_item.xml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/repository_main.xml b/app/src/main/res/layout/repository_main.xml new file mode 100644 index 000000000..759d41402 --- /dev/null +++ b/app/src/main/res/layout/repository_main.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 000000000..eca70cfe5 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 000000000..eca70cfe5 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 000000000..c209e78ec Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 000000000..b2dfe3d1b Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 000000000..4f0f1d64e Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 000000000..62b611da0 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 000000000..948a3070f Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 000000000..1b9a6956b Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 000000000..28d4b77f9 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 000000000..9287f5083 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 000000000..aa7d6427e Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 000000000..9126ae37c Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml new file mode 100644 index 000000000..4038c1727 --- /dev/null +++ b/app/src/main/res/values-night/themes.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 000000000..2e00ddf0a --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,14 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #403F3F + #FFFFFF + #CCCCCC + #A17800 + #FF3949AB + \ No newline at end of file diff --git a/app/src/main/res/values/font_certs.xml b/app/src/main/res/values/font_certs.xml new file mode 100644 index 000000000..d2226ac01 --- /dev/null +++ b/app/src/main/res/values/font_certs.xml @@ -0,0 +1,17 @@ + + + + @array/com_google_android_gms_fonts_certs_dev + @array/com_google_android_gms_fonts_certs_prod + + + + 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 + + + diff --git a/app/src/main/res/values/preloaded_fonts.xml b/app/src/main/res/values/preloaded_fonts.xml new file mode 100644 index 000000000..f3761868a --- /dev/null +++ b/app/src/main/res/values/preloaded_fonts.xml @@ -0,0 +1,7 @@ + + + + @font/archivo_black + @font/archivo_medium + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 000000000..b9852a636 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,13 @@ + + GitHub Java Pop + Title + title + ownerName + item + Username photo + Username photo + Username photo + 0 + Opened + Closed + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 000000000..6bfd3cf4d --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/backup_rules.xml b/app/src/main/res/xml/backup_rules.xml new file mode 100644 index 000000000..fa0f996d2 --- /dev/null +++ b/app/src/main/res/xml/backup_rules.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/data_extraction_rules.xml b/app/src/main/res/xml/data_extraction_rules.xml new file mode 100644 index 000000000..9ee9997b0 --- /dev/null +++ b/app/src/main/res/xml/data_extraction_rules.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/test/java/com/example/desafioandroidapp/ExampleUnitTest.kt b/app/src/test/java/com/example/desafioandroidapp/ExampleUnitTest.kt new file mode 100644 index 000000000..687f86078 --- /dev/null +++ b/app/src/test/java/com/example/desafioandroidapp/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.example.desafioandroidapp + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 000000000..a7d4dc49e --- /dev/null +++ b/build.gradle @@ -0,0 +1,10 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + id 'com.android.application' version '7.3.0' apply false + id 'com.android.library' version '7.3.0' apply false + id 'org.jetbrains.kotlin.android' version '1.7.0' apply false +} + +task clean(type: Delete) { + delete rootProject.buildDir +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 000000000..cd0519bb2 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,23 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..e708b1c02 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..0a3c53111 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Jun 30 19:55:35 CLT 2022 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew new file mode 100755 index 000000000..4f906e0c8 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 000000000..107acd32c --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 000000000..5ac9927ad --- /dev/null +++ b/settings.gradle @@ -0,0 +1,16 @@ +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} +rootProject.name = "DesafioAndroidApp" +include ':app'