Skip to content

Commit

Permalink
latest update(still not finished)
Browse files Browse the repository at this point in the history
  • Loading branch information
edyda99 committed Feb 25, 2021
1 parent 8f9daee commit 0b8e0f7
Show file tree
Hide file tree
Showing 21 changed files with 385 additions and 274 deletions.
129 changes: 71 additions & 58 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ plugins {
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

buildFeatures {
dataBinding true
}
packagingOptions {
exclude 'META-INF/atomicfu.kotlin_module'
}
Expand Down Expand Up @@ -39,61 +41,72 @@ android {
}

dependencies {

//bus
implementation 'org.greenrobot:eventbus:3.0.0'

//Retrofit implementation
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation 'com.google.code.gson:gson:2.8.6'
implementation "com.squareup.retrofit2:converter-gson:2.9.0"


implementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion"
implementation "androidx.activity:activity-ktx:$rootProject.activityVersion"

// Dependencies for working with Architecture components
// You'll probably have to update the version numbers in build.gradle (Project)

// Room components
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.wear:wear:1.1.0'
compileOnly 'com.google.android.wearable:wearable:2.8.1'
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"

// Lifecycle components
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$rootProject.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-common-java8:$rootProject.lifecycleVersion"

// Kotlin components
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutines"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines"

// UI
implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintLayoutVersion"
implementation "com.google.android.material:material:$rootProject.materialVersion"

// Testing
testImplementation "junit:junit:$rootProject.junitVersion"
androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
androidTestImplementation ("androidx.test.espresso:espresso-core:$rootProject.espressoVersion", {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation "androidx.test.ext:junit:$rootProject.androidxJunitVersion"

implementation 'com.google.android.material:material:1.3.0'
def paging_version = "2.1.2"

implementation "androidx.paging:paging-runtime:$paging_version" // For Kotlin use paging-runtime-ktx

// alternatively - without Android dependencies for testing
testImplementation "androidx.paging:paging-common:$paging_version" // For Kotlin use paging-common-ktx

// optional - RxJava support
implementation "androidx.paging:paging-rxjava2:$paging_version" // For Kotlin use paging-rxjava2-ktx

//binding
annotationProcessor 'com.android.databinding:compiler:3.1.4'
//bus
implementation 'org.greenrobot:eventbus:3.0.0'

//Retrofit implementation
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation 'com.google.code.gson:gson:2.8.6'
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
implementation 'com.squareup.okhttp3:okhttp:3.14.9'
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
//add coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'

implementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion"
implementation "androidx.activity:activity-ktx:$rootProject.activityVersion"

// Dependencies for working with Architecture components
// You'll probably have to update the version numbers in build.gradle (Project)

// Room components
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.wear:wear:1.1.0'
compileOnly 'com.google.android.wearable:wearable:2.8.1'
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:2.2.6"

// Lifecycle components
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.3.0"

// Kotlin components
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutines"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1"

// UI
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
implementation "com.google.android.material:material:$rootProject.materialVersion"

// Testing
testImplementation "junit:junit:$rootProject.junitVersion"
androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
androidTestImplementation("androidx.test.espresso:espresso-core:$rootProject.espressoVersion", {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation "androidx.test.ext:junit:$rootProject.androidxJunitVersion"

implementation 'com.google.android.material:material:1.3.0'
def paging_version = "2.1.2"

implementation "androidx.paging:paging-runtime:$paging_version"
// For Kotlin use paging-runtime-ktx

// alternatively - without Android dependencies for testing
testImplementation "androidx.paging:paging-common:$paging_version"
// For Kotlin use paging-common-ktx

// optional - RxJava support
implementation "androidx.paging:paging-rxjava2:$paging_version"
// For Kotlin use paging-rxjava2-ktx
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.gms:play-services:12.0.1'
}
17 changes: 11 additions & 6 deletions app/src/main/java/com/example/kotlingabywifiroom/API/Api.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.example.kotlingabywifiroom.API

import android.telecom.Call
import androidx.room.ColumnInfo
//import com.example.kotlingabywifiroom.Parent.Items
import com.example.kotlingabywifiroom.Parent.Parentt
import com.example.kotlingabywifiroom.parentt.Parentt
import com.google.android.gms.ads.internal.gmsg.HttpClient
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
import com.squareup.okhttp.internal.http.OkHeaders
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query
//import com.example.kotlingabywifiroom.Parent.Parent as Pare
//?q=created:>2021-02-17&sort=stars&order=desc&page=0
Expand All @@ -16,15 +17,19 @@ interface Api {
suspend fun getTop(@Query("q") q: String,
@Query("sort") limit: String,
@Query("order") order: String,
@Query("page") page :String):Parentt
@Query("page") page :String): Parentt
}

object ParentNetwork {

const val FIRST_PAGE = 0
const val POST_PER_PAGE = 20
val client : OkHttpClient = OkHttpClient()
// Configure retrofit to parse JSON and use coroutines
private val retrofit = Retrofit.Builder()
.baseUrl("https://api.github.com/search/")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.client(client)
.build()

val devbytes :Api = retrofit.create(Api::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package com.example.kotlingabywifiroom.Activity2

import android.os.Bundle
import android.util.Log
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.kotlingabywifiroom.Parent.Item
import com.example.kotlingabywifiroom.parentt.Item
import com.example.kotlingabywifiroom.R
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,63 @@ package com.example.kotlingabywifiroom.Adapter

//import com.example.kotlingabywifiroom.Parent.Items
//import com.example.kotlingabywifiroom.Parent.Parent
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.example.kotlingabywifiroom.Parent.Item
import com.example.kotlingabywifiroom.Activity2.SingleSelectActivity
import com.example.kotlingabywifiroom.parentt.Item
import com.example.kotlingabywifiroom.R
import com.example.kotlingabywifiroom.databinding.ListItemLayoutBinding
//import com.example.kotlingabywifiroom.databinding.RecyclerviewLayoutBinding
import org.greenrobot.eventbus.EventBus
import java.util.*
import java.util.Arrays.sort
import java.util.Collections.sort
import kotlin.Comparator
import kotlin.collections.ArrayList


class ParentAdapter(private val users: ArrayList<Item>, var clickListner: OnNoteClickListner) :
class ParentAdapter(private val users: ArrayList<Item>, val context: Context) :
RecyclerView.Adapter<ParentAdapter.ParentViewHolder>() {

class ParentViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val idView = itemView.findViewById<TextView>(R.id.id)
val full_nameView = itemView.findViewById<TextView>(R.id.full_name)
val ownerView = itemView.findViewById<TextView>(R.id.owner)

class ParentViewHolder(
val context: Context,
val itemView: View
) :
RecyclerView.ViewHolder(itemView) {
val idItem = itemView.findViewById<AppCompatTextView>(R.id.idd)
val full_name = itemView.findViewById<AppCompatTextView>(R.id.full_name)
val owner = itemView.findViewById<AppCompatTextView>(R.id.owner)
fun bind(user: Item) {
idView.setText(user.id.toString())
full_nameView.setText(user.full_name)
val ed: String = user.owner.login
ownerView.setText(ed)
}

fun initialize(item: Item, action: OnNoteClickListner) {
idItem.setText(user.id.toString())
full_name.text = user.full_name
owner.text = user.owner.login
itemView.setOnClickListener {
action.onItemClick(item, adapterPosition)
EventBus.getDefault().postSticky(user)
val intent = Intent(context, SingleSelectActivity::class.java)
context.startActivity(intent)
}

}

}

override fun onCreateViewHolder(view: ViewGroup, viewType: Int): ParentViewHolder =
ParentViewHolder(
override fun onCreateViewHolder(view: ViewGroup, viewType: Int): ParentViewHolder {
return ParentViewHolder(context,
LayoutInflater.from(view.context).inflate(
R.layout.recyclerview_layout,
R.layout.list_item_layout,
view,
false
)
)

)
}
override fun getItemCount(): Int = users.size

override fun onBindViewHolder(holder: ParentViewHolder, position: Int) {
holder.initialize(users.get(position), clickListner)
holder.bind(users[position])
return holder.bind(users[position])
}


Expand All @@ -61,20 +68,7 @@ class ParentAdapter(private val users: ArrayList<Item>, var clickListner: OnNote
addAll(users)
}
}

fun sortUsers() {
this.users.sortedWith(compareBy({ it.id }))
notifyDataSetChanged()
}

fun unsortUsers() {
this.users.sortedWith(compareByDescending({ it.id }))
}

}

interface OnNoteClickListner {
fun onItemClick(item: Item, position: Int)
}


Loading

0 comments on commit 0b8e0f7

Please sign in to comment.