Skip to content

Commit

Permalink
hello world
Browse files Browse the repository at this point in the history
  • Loading branch information
edyda99 committed Feb 25, 2021
1 parent 5d769e4 commit 8f9daee
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 140 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ android {
}

dependencies {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@ class ParentAdapter(private val users: ArrayList<Item>, var clickListner: OnNote

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

fun bind(user: Item) {
idView.setText(user.id.toString())
node_idView.setText(user.node_id)
priView.setText(user.pri.toString())
nameView.setText(user.name)
full_nameView.setText(user.full_name)
val ed: String = user.owner.id.toString() + " " + user.owner.login
val ed: String = user.owner.login
ownerView.setText(ed)
}

Expand Down Expand Up @@ -68,13 +62,13 @@ class ParentAdapter(private val users: ArrayList<Item>, var clickListner: OnNote
}
}

fun sortUsers() : List<Item> {
return this.users.sortedWith(compareBy({ it.id }))
fun sortUsers() {
this.users.sortedWith(compareBy({ it.id }))
notifyDataSetChanged()
}

fun unsortUsers() :List<Item> {
return this.users.sortedWith(compareByDescending({ it.id }))

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

}
Expand Down
56 changes: 29 additions & 27 deletions app/src/main/java/com/example/kotlingabywifiroom/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.example.kotlingabywifiroom.Parent.Parentt
import com.example.kotlingabywifiroom.ParentViewModel.ParentViewModel
import com.example.kotlingabywifiroom.util.Resource
import com.example.kotlingabywifiroom.util.Status
import com.google.android.material.slider.Slider
import kotlinx.coroutines.Dispatchers
import org.greenrobot.eventbus.EventBus
import java.util.*
Expand All @@ -44,7 +45,7 @@ class MainActivity : AppCompatActivity(), OnNoteClickListner {
private lateinit var mTextViewCountDown: TextView
private lateinit var chrono: Chronometer
private var ed: Long? = null
private lateinit var switcher : SwitchCompat
private lateinit var switcher: SwitchCompat
private val parentViewModel: ParentViewModel by lazy {
ViewModelProvider(this, ParentViewModel.Factory(application))
.get(ParentViewModel::class.java)
Expand Down Expand Up @@ -75,15 +76,14 @@ class MainActivity : AppCompatActivity(), OnNoteClickListner {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// mTextViewCountDown = findViewById(R.id.timer)
chrono = findViewById(R.id.chronometer)
nestedScrollView = findViewById(R.id.scrollView)
/* Adapting the recycleView */
recyclerView = findViewById<RecyclerView>(R.id.recyclerview)

recyclerView.setLayoutManager(LinearLayoutManager(this))
adapter = ParentAdapter(arrayListOf(), this)
recyclerView.setHasFixedSize(true)
recyclerView.adapter = adapter
recyclerView.setLayoutManager(LinearLayoutManager(this))
adapter = ParentAdapter(arrayListOf(), this)
recyclerView.setHasFixedSize(true)
recyclerView.adapter = adapter

Log.d(TAG, "ANA BL MAIN")
if (savedInstanceState != null) {
Expand All @@ -92,27 +92,25 @@ class MainActivity : AppCompatActivity(), OnNoteClickListner {
}
//timer
// startTimer()
ed?.let { chrono.setBase(it) }
chrono.start()
parentViewModel.parents().observe(this, Observer {
it?.let { resource ->
when (resource.status) {
Status.SUCCESS -> {
liveData(Dispatchers.IO) {
emit(
Resource.success(
ParentNetwork.devbytes.getTop(
"created:>2021-02-17",
"stars",
"desc",
"${MainActivity.page}"
)
liveData(Dispatchers.IO) {
emit(
Resource.success(
ParentNetwork.devbytes.getTop(
"created:>2021-02-17",
"stars",
"desc",
"${MainActivity.page}"
)
)
}
Log.d(TAG, "bl success")
recyclerView.visibility = View.VISIBLE
resource.data?.let { users -> retrieveList(users) }
)
}
Log.d(TAG, "bl success")
recyclerView.visibility = View.VISIBLE
resource.data?.let { users -> retrieveList(users) }
}
Status.ERROR -> {
recyclerView.visibility = View.VISIBLE
Expand All @@ -135,6 +133,7 @@ class MainActivity : AppCompatActivity(), OnNoteClickListner {
}

recyclerView.adapter = adapter

nestedScrollView.setOnScrollChangeListener(object :
NestedScrollView.OnScrollChangeListener {
override fun onScrollChange(
Expand Down Expand Up @@ -181,8 +180,11 @@ class MainActivity : AppCompatActivity(), OnNoteClickListner {

val layoutButton = menu?.findItem(R.id.menu)
val layoutSwitch = menu!!.findItem(R.id.switchOnOffItem)
switcher =layoutSwitch.actionView as SwitchCompat

switcher = layoutSwitch.actionView as SwitchCompat
val timer = menu!!.findItem(R.id.timer)
chrono = timer.actionView as Chronometer
ed?.let { chrono.setBase(it) }
chrono.start()
// Calls code to set the icon based on the LinearLayoutManager of the RecyclerView
setIcon(layoutButton)

Expand Down Expand Up @@ -217,16 +219,16 @@ class MainActivity : AppCompatActivity(), OnNoteClickListner {
private fun sortMyList() {
if (radioButtn)
adapter.apply {
val edy =sortUsers()
addUsers(edy)
sortUsers()

}
else
adapter.apply {
addUsers(unsortUsers())
unsortUsers()
notifyDataSetChanged()

}
recyclerView.adapter= adapter
recyclerView.adapter = adapter

}

Expand Down
17 changes: 3 additions & 14 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,12 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<Chronometer
android:id="@+id/chronometer"
android:layout_width="160dp"
android:layout_height="108dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:gravity="center"
android:textSize="@android:dimen/app_icon_size" />


<androidx.core.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="614dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="0dp"
Expand All @@ -31,7 +20,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="555dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="0dp"
Expand Down
93 changes: 28 additions & 65 deletions app/src/main/res/layout/recyclerview_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,44 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="horizontal">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<LinearLayout
android:layout_width="322dp"
android:layout_width="0dp"
android:layout_weight="0.7"
android:gravity="left"
android:layout_height="wrap_content"
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/id"
android:textAlignment="textStart"
style="@style/TextAppearance.AppCompat.Large"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/id"
style="@style/TextAppearance.AppCompat.Large"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:maxLength="10"/>

<androidx.appcompat.widget.AppCompatTextView

android:id="@+id/node_id"
style="@style/TextAppearance.AppCompat.Large"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:maxLength="10"/>

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/full_name"
style="@style/TextAppearance.AppCompat.Large"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:maxLength="10"/>
android:maxLength="10" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/owner"
style="@style/TextAppearance.AppCompat.Large"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:maxLength="10"/>
</LinearLayout>

<LinearLayout
style="@style/Theme.Design.Light"
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/full_name"
style="@style/TextAppearance.AppCompat.Large"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:maxLength="10"
android:textAlignment="textStart" />
</LinearLayout>

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/pri"
style="@style/TextAppearance.AppCompat.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:maxLength="10"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/owner"
android:textAlignment="gravity"
style="@style/TextAppearance.AppCompat.Large"
android:layout_width="0dp"
android:layout_weight="0.3"
android:layout_height="wrap_content"
android:maxLength="10" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/name"
style="@style/TextAppearance.AppCompat.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:maxLength="10"/>

</LinearLayout>
</LinearLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/white" />
</LinearLayout>


</androidx.cardview.widget.CardView>
22 changes: 0 additions & 22 deletions app/src/main/res/layout/timer.xml

This file was deleted.

5 changes: 5 additions & 0 deletions app/src/main/res/menu/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
android:title=""
app:showAsAction="always"
app:actionViewClass="androidx.appcompat.widget.SwitchCompat" />
<item
android:id="@+id/timer"
android:title=""
app:showAsAction="always"
app:actionViewClass="android.widget.Chronometer"/>
</menu>

0 comments on commit 8f9daee

Please sign in to comment.