From 8f9daeecfe65573ba71d9c2ef1fe137f536d4255 Mon Sep 17 00:00:00 2001 From: Edmond Date: Thu, 25 Feb 2021 12:06:21 +0200 Subject: [PATCH] hello world --- app/build.gradle | 1 + .../Adapter/ParentAdapter.kt | 18 ++-- .../kotlingabywifiroom/MainActivity.kt | 56 +++++------ app/src/main/res/layout/activity_main.xml | 17 +--- .../main/res/layout/recyclerview_layout.xml | 93 ++++++------------- app/src/main/res/layout/timer.xml | 22 ----- app/src/main/res/menu/menu.xml | 5 + 7 files changed, 72 insertions(+), 140 deletions(-) delete mode 100644 app/src/main/res/layout/timer.xml diff --git a/app/build.gradle b/app/build.gradle index 5c0f861..8f35b4a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,6 +39,7 @@ android { } dependencies { + //bus implementation 'org.greenrobot:eventbus:3.0.0' diff --git a/app/src/main/java/com/example/kotlingabywifiroom/Adapter/ParentAdapter.kt b/app/src/main/java/com/example/kotlingabywifiroom/Adapter/ParentAdapter.kt index ccc3194..55dabe8 100644 --- a/app/src/main/java/com/example/kotlingabywifiroom/Adapter/ParentAdapter.kt +++ b/app/src/main/java/com/example/kotlingabywifiroom/Adapter/ParentAdapter.kt @@ -21,19 +21,13 @@ class ParentAdapter(private val users: ArrayList, var clickListner: OnNote class ParentViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val idView = itemView.findViewById(R.id.id) - val node_idView = itemView.findViewById(R.id.node_id) - val priView = itemView.findViewById(R.id.pri) - val nameView = itemView.findViewById(R.id.name) val full_nameView = itemView.findViewById(R.id.full_name) val ownerView = itemView.findViewById(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) } @@ -68,13 +62,13 @@ class ParentAdapter(private val users: ArrayList, var clickListner: OnNote } } - fun sortUsers() : List { - return this.users.sortedWith(compareBy({ it.id })) + fun sortUsers() { + this.users.sortedWith(compareBy({ it.id })) + notifyDataSetChanged() } - fun unsortUsers() :List { - return this.users.sortedWith(compareByDescending({ it.id })) - + fun unsortUsers() { + this.users.sortedWith(compareByDescending({ it.id })) } } diff --git a/app/src/main/java/com/example/kotlingabywifiroom/MainActivity.kt b/app/src/main/java/com/example/kotlingabywifiroom/MainActivity.kt index 64ac79e..0f377ff 100644 --- a/app/src/main/java/com/example/kotlingabywifiroom/MainActivity.kt +++ b/app/src/main/java/com/example/kotlingabywifiroom/MainActivity.kt @@ -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.* @@ -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) @@ -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(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) { @@ -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 @@ -135,6 +133,7 @@ class MainActivity : AppCompatActivity(), OnNoteClickListner { } recyclerView.adapter = adapter + nestedScrollView.setOnScrollChangeListener(object : NestedScrollView.OnScrollChangeListener { override fun onScrollChange( @@ -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) @@ -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 } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ab79224..bbcafc5 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,23 +6,12 @@ android:layout_height="match_parent" tools:context=".MainActivity"> - + + android:orientation="horizontal"> - - + + - - - - - - + android:maxLength="10" /> - - - - + android:maxLength="10" + android:textAlignment="textStart" /> + - + - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/timer.xml b/app/src/main/res/layout/timer.xml deleted file mode 100644 index d87fe8b..0000000 --- a/app/src/main/res/layout/timer.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/menu.xml b/app/src/main/res/menu/menu.xml index 0208db2..5c5dd29 100644 --- a/app/src/main/res/menu/menu.xml +++ b/app/src/main/res/menu/menu.xml @@ -10,4 +10,9 @@ android:title="" app:showAsAction="always" app:actionViewClass="androidx.appcompat.widget.SwitchCompat" /> +