-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from AmosKorir/develop
Develop
- Loading branch information
Showing
22 changed files
with
445 additions
and
221 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 38 additions & 31 deletions
69
app/src/main/java/com/avatarfirst/avatagen/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,48 @@ | ||
package com.avatarfirst.avatagen | ||
|
||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.avatarfirst.avatargenlib.AvatarConstants | ||
import com.avatarfirst.avatargenlib.AvatarGenerator | ||
import com.bumptech.glide.Glide | ||
import com.squareup.picasso.Picasso | ||
import kotlinx.android.synthetic.main.activity_main.imageView | ||
import kotlinx.android.synthetic.main.activity_main.imageView2 | ||
import kotlinx.android.synthetic.main.activity_main.imageView3 | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.avatarfirst.avatagen.apis.ApiData | ||
import com.avatarfirst.avatagen.apis.GithubUserApiResponseItem | ||
import io.reactivex.android.schedulers.AndroidSchedulers | ||
import io.reactivex.disposables.CompositeDisposable | ||
import io.reactivex.schedulers.Schedulers | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
imageView.setImageDrawable( | ||
AvatarGenerator.avatarImage( | ||
this, | ||
200, | ||
AvatarConstants.RECTANGLE, | ||
"Skyways" | ||
) | ||
) | ||
//picaso | ||
Picasso.get() | ||
.load("https://brokenfortest") | ||
.resize(50, 50) | ||
.placeholder(AvatarGenerator.avatarImage(this, 200, AvatarConstants.CIRCLE, "Android",AvatarConstants.COLOR900)) | ||
.into(imageView2) | ||
class MainActivity : AppCompatActivity() { | ||
private val apiCall = ApiData() | ||
private var compositeDisposable = CompositeDisposable() | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
loadData() | ||
} | ||
|
||
//Glide | ||
Glide.with(this) | ||
.load("http://brokenfortest") | ||
.placeholder(AvatarGenerator.avatarImage(this, 200, AvatarConstants.CIRCLE, "Kotjav")) | ||
.into(imageView3) | ||
private fun showUSer(users: List<GithubUserApiResponseItem>) { | ||
usersRecyclerView.layoutManager = LinearLayoutManager(this) | ||
usersRecyclerView.adapter = UsersAdapter(this, users) | ||
} | ||
|
||
} | ||
private fun loadData() { | ||
val disposable = apiCall.getUsersApi().getUsers() | ||
.subscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe( | ||
{ | ||
showUSer(it) | ||
}, | ||
{ | ||
Toast.makeText(this, "error occurred", Toast.LENGTH_LONG).show() | ||
} | ||
) | ||
compositeDisposable.add(disposable) | ||
} | ||
|
||
override fun onStop() { | ||
super.onStop() | ||
compositeDisposable.dispose() | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/avatarfirst/avatagen/UsersAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.avatarfirst.avatagen | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.avatarfirst.avatagen.apis.GithubUserApiResponseItem | ||
import com.avatarfirst.avatargenlib.AvatarConstants | ||
import com.avatarfirst.avatargenlib.AvatarGenerator | ||
import kotlinx.android.synthetic.main.user_layout.view.* | ||
|
||
class UsersAdapter( | ||
var context: Context, | ||
var users: List<GithubUserApiResponseItem> | ||
) : RecyclerView.Adapter<UsersAdapter.UserViewHolder>() { | ||
|
||
class UserViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
|
||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserViewHolder { | ||
return UserViewHolder( | ||
LayoutInflater.from(context).inflate(R.layout.user_layout, parent, false) | ||
) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return users.size | ||
} | ||
|
||
override fun onBindViewHolder(holder: UserViewHolder, position: Int) { | ||
holder.itemView.usename.text = users[position].login | ||
holder.itemView.userAvatar.setImageDrawable( | ||
AvatarGenerator.avatarImage( | ||
context, | ||
200, | ||
AvatarConstants.CIRCLE, | ||
users[position].login | ||
) | ||
) | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/avatarfirst/avatagen/apis/ApiData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.avatarfirst.avatagen.apis | ||
|
||
import com.google.gson.FieldNamingPolicy | ||
import com.google.gson.Gson | ||
import com.google.gson.GsonBuilder | ||
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory | ||
import okhttp3.OkHttpClient | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
class ApiData { | ||
private fun provideUseApi(retrofit: Retrofit): GithubApi { | ||
return retrofit.create(GithubApi::class.java) | ||
} | ||
|
||
|
||
|
||
private fun provideGson(): Gson { | ||
return GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create() | ||
} | ||
|
||
private fun provideHttpClient(): OkHttpClient { | ||
val okHttpClientBuilder = OkHttpClient.Builder() | ||
|
||
return okHttpClientBuilder.build() | ||
} | ||
|
||
private fun provideRetrofit(factory: Gson, client: OkHttpClient): Retrofit { | ||
return Retrofit.Builder() | ||
.baseUrl("https://api.github.com/") | ||
.addConverterFactory(GsonConverterFactory.create(factory)) | ||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
.client(client) | ||
.build() | ||
} | ||
|
||
fun getUsersApi(): GithubApi { | ||
val retrofit=provideRetrofit(provideGson(),provideHttpClient()) | ||
return provideUseApi(retrofit) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.avatarfirst.avatagen.apis | ||
|
||
import io.reactivex.Single | ||
import retrofit2.http.GET | ||
|
||
interface GithubApi { | ||
@GET("users/amoskorir/followers") | ||
fun getUsers(): Single<List<GithubUserApiResponseItem>> | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/avatarfirst/avatagen/apis/GithubUserApiResponseItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.avatarfirst.avatagen.apis | ||
|
||
data class GithubUserApiResponseItem( | ||
val avatar_url: String, | ||
val events_url: String, | ||
val followers_url: String, | ||
val following_url: String, | ||
val gists_url: String, | ||
val gravatar_id: String, | ||
val html_url: String, | ||
val id: Int, | ||
val login: String, | ||
val node_id: String, | ||
val organizations_url: String, | ||
val received_events_url: String, | ||
val repos_url: String, | ||
val site_admin: Boolean, | ||
val starred_url: String, | ||
val subscriptions_url: String, | ||
val type: String, | ||
val url: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.