Skip to content

Commit

Permalink
fix: inconsitent text result and ReviewDescriptorUpdatesActivity te…
Browse files Browse the repository at this point in the history
…xt cut off
  • Loading branch information
aanorbel committed May 23, 2024
1 parent 2879a6e commit 782ffbd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,57 +109,48 @@ class ReviewDescriptorUpdatesActivity : AbstractActivity() {
reviewUpdatesPagingAdapter = ReviewUpdatesPagingAdapter(this, descriptors)
binding.viewpager.adapter = reviewUpdatesPagingAdapter

/**
* The bottom bar menu item click listener.
* When the user clicks on the update button, the viewpager is swiped to the next page.
* When the user clicks on the last update, the activity is finished.
*/
val bottomBarOnMenuItemClickListener: Toolbar.OnMenuItemClickListener =
Toolbar.OnMenuItemClickListener { item ->
when (item.itemId) {
R.id.update_descriptor -> {
descriptorManager.updateFromNetwork(descriptors[binding.viewpager.currentItem])
/**
* **[currPos]** is the current position of the viewpager.
* If the current position is not the last position, the viewpager is swiped to the next page.
* If the current position is the last position, the last update is saved in the shared preferences and the activity is finished.
*/
val currPos: Int = binding.viewpager.currentItem
if ((currPos + 1) != binding.viewpager.adapter?.itemCount) {
binding.viewpager.currentItem = currPos + 1
} else {
setResult(
RESULT_OK,
Intent().putExtra(RESULT_MESSAGE, "Link(s) updated")
)
finish()
}
true
}

else -> false
binding.btnUpdate.setOnClickListener {
/*
* When the user clicks the update button, the descriptor is updated.
* If the current item is the last item in the viewpager, the result is set to "Link(s) updated" and the activity is finished.
* If the current item is not the last item in the viewpager, the viewpager is swiped to the next item.
*/
with(binding.viewpager) {
descriptorManager.updateFromNetwork(descriptors[currentItem])
when (currentItem) {
adapter?.itemCount?.minus(1) -> {
// Last update
setResult(
RESULT_OK,
Intent().putExtra(RESULT_MESSAGE, "Link(s) updated")
)
finish()
}

else -> {
// Not the last update
currentItem += 1
}
}
binding.bottomBar.setOnMenuItemClickListener(bottomBarOnMenuItemClickListener)
}
}

/**
* The viewpager page change callback.
* When the user swipes to the next page, the bottom bar menu item title is updated.
*/
binding.viewpager.registerOnPageChangeCallback(object : OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
binding.bottomBar.menu.findItem(R.id.update_descriptor)
?.let {
val countString =
"(${position + 1} of ${binding.viewpager.adapter?.itemCount})"
supportActionBar?.title = "Link Update $countString"
it.title = if ((position + 1) != binding.viewpager.adapter?.itemCount) {
"UPDATE $countString"
} else {
"UPDATE AND FINISH $countString"
}
}
/*
* When the user swipes to the next item in the viewpager, the title of the action bar is updated.
* If the current item is the last item in the viewpager, the text of the button is updated to "UPDATE AND FINISH".
* If the current item is not the last item in the viewpager, the text of the button is updated to "UPDATE".
*/
val countString = "(%d of %d)".format(position + 1, binding.viewpager.adapter?.itemCount)

supportActionBar?.title = "Link Update $countString"

binding.btnUpdate.text = when (position + 1) {
binding.viewpager.adapter?.itemCount -> "UPDATE AND FINISH $countString"

else -> "UPDATE $countString"
}
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.openobservatory.ooniprobe.activity.runtests.RunTestsActivity
import org.openobservatory.ooniprobe.activity.runtests.models.ChildItem
import org.openobservatory.ooniprobe.activity.runtests.models.GroupItem
import org.openobservatory.ooniprobe.model.database.TestDescriptor
import org.openobservatory.ooniprobe.model.database.Url
import org.openobservatory.ooniprobe.test.suite.DynamicTestSuite
import org.openobservatory.ooniprobe.test.test.*
import java.io.Serializable
Expand Down Expand Up @@ -123,6 +124,11 @@ abstract class AbstractDescriptor<T : BaseNettest>(
* @return [DynamicTestSuite] representing the test suite for the current descriptor.
*/
open fun getTest(context: Context): DynamicTestSuite {
this.nettests.forEach { nettest ->
nettest.inputs?.forEach { input ->
Url.checkExistingUrl(input)
}
}
return DynamicTestSuite(
name = this.name,
title = this.title,
Expand Down
26 changes: 21 additions & 5 deletions app/src/main/res/layout/activity_review_descriptor_updates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,28 @@
android:layout_gravity="bottom"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar">

<androidx.appcompat.widget.Toolbar
android:id="@+id/bottomBar"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_gray0"
app:menu="@menu/update_descriptor"
app:titleTextAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title.App" />
android:gravity="end">

<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />

<Button
android:id="@+id/btn_update"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:layout_gravity="center"
android:elevation="0dp"
android:text="@string/OONIRun_Update"
android:textColor="@color/color_base" />

</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

0 comments on commit 782ffbd

Please sign in to comment.