-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds structures to display descriptor reviews
- Loading branch information
Showing
9 changed files
with
344 additions
and
16 deletions.
There are no files selected for viewing
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
177 changes: 177 additions & 0 deletions
177
...observatory/ooniprobe/activity/reviewdescriptorupdates/ReviewDescriptorUpdatesActivity.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,177 @@ | ||
package org.openobservatory.ooniprobe.activity.reviewdescriptorupdates | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Build | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.Menu | ||
import android.view.MenuInflater | ||
import android.view.MenuItem | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import androidx.appcompat.widget.Toolbar | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentActivity | ||
import androidx.viewpager2.adapter.FragmentStateAdapter | ||
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback | ||
import com.google.gson.Gson | ||
import org.openobservatory.ooniprobe.R | ||
import org.openobservatory.ooniprobe.activity.AbstractActivity | ||
import org.openobservatory.ooniprobe.common.PreferenceManager | ||
import org.openobservatory.ooniprobe.common.TestDescriptorManager | ||
import org.openobservatory.ooniprobe.databinding.ActivityReviewDescriptorUpdatesBinding | ||
import org.openobservatory.ooniprobe.databinding.FragmentDescriptorUpdateBinding | ||
import org.openobservatory.ooniprobe.model.database.InstalledDescriptor | ||
import org.openobservatory.ooniprobe.model.database.TestDescriptor | ||
import javax.inject.Inject | ||
|
||
class ReviewDescriptorUpdatesActivity : AbstractActivity() { | ||
|
||
companion object { | ||
private const val DESCRIPTORS = "descriptors" | ||
|
||
/** | ||
* This method is used to create an intent to start this activity. | ||
* @param context is the context of the activity that calls this method | ||
* @param descriptors is the descriptors to review | ||
* @return an intent to start this activity | ||
*/ | ||
@JvmStatic | ||
fun newIntent(context: Context, descriptors: String?): Intent { | ||
return Intent(context, ReviewDescriptorUpdatesActivity::class.java).putExtra( | ||
DESCRIPTORS, | ||
descriptors | ||
) | ||
} | ||
} | ||
|
||
@Inject | ||
lateinit var preferenceManager: PreferenceManager | ||
|
||
@Inject | ||
lateinit var descriptorManager: TestDescriptorManager | ||
|
||
@Inject | ||
lateinit var gson: Gson | ||
|
||
private lateinit var reviewUpdatesPagingAdapter: ReviewUpdatesPagingAdapter | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
activityComponent.inject(this) | ||
val binding = ActivityReviewDescriptorUpdatesBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
setSupportActionBar(binding.toolbar) | ||
supportActionBar?.setDisplayHomeAsUpEnabled(false) | ||
supportActionBar?.setDisplayShowHomeEnabled(false) | ||
supportActionBar?.title = "Link Update" | ||
val descriptorJson = intent.getStringExtra(DESCRIPTORS) | ||
try { | ||
val descriptors: Array<TestDescriptor> = | ||
gson.fromJson(descriptorJson, Array<TestDescriptor>::class.java) | ||
|
||
binding.viewpager.isUserInputEnabled = false | ||
reviewUpdatesPagingAdapter = ReviewUpdatesPagingAdapter(this, descriptors.toList()) | ||
binding.viewpager.adapter = reviewUpdatesPagingAdapter | ||
|
||
|
||
val bottomBarOnMenuItemClickListener: Toolbar.OnMenuItemClickListener = | ||
Toolbar.OnMenuItemClickListener { item -> | ||
when (item.itemId) { | ||
R.id.update_descriptor -> { | ||
val currPos: Int = binding.viewpager.currentItem | ||
if ((currPos + 1) != binding.viewpager.adapter?.itemCount) { | ||
binding.viewpager.currentItem = currPos + 1 | ||
} else { | ||
/*preferenceManager.setLastUpdateDescriptorReview( | ||
descriptorManager.getDescriptorVersion() | ||
)*/ | ||
finish() | ||
} | ||
true | ||
} | ||
|
||
else -> false | ||
} | ||
} | ||
binding.bottomBar.setOnMenuItemClickListener(bottomBarOnMenuItemClickListener) | ||
|
||
binding.viewpager.registerOnPageChangeCallback(object : OnPageChangeCallback() { | ||
override fun onPageSelected(position: Int) { | ||
binding.bottomBar.menu.findItem(R.id.update_descriptor) | ||
?.setTitle("UPDATE (${position + 1} of ${binding.viewpager.adapter?.itemCount})") | ||
|
||
} | ||
}) | ||
|
||
} catch (e: Exception) { | ||
finish() | ||
} | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu): Boolean { | ||
val inflater: MenuInflater = menuInflater | ||
inflater.inflate(R.menu.close, menu) | ||
return true | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
return when (item.itemId) { | ||
R.id.close_button -> { | ||
finish() | ||
true | ||
} | ||
|
||
else -> super.onOptionsItemSelected(item) | ||
} | ||
} | ||
} | ||
|
||
class ReviewUpdatesPagingAdapter( | ||
fragmentActivity: FragmentActivity, | ||
private val descriptors: List<TestDescriptor> | ||
) : FragmentStateAdapter(fragmentActivity) { | ||
override fun getItemCount(): Int = descriptors.size | ||
|
||
override fun createFragment(position: Int): Fragment { | ||
val fragment = DescriptorUpdateFragment() | ||
fragment.arguments = Bundle().apply { | ||
putSerializable(DESCRIPTOR, descriptors[position]) | ||
} | ||
return fragment | ||
} | ||
} | ||
|
||
private const val DESCRIPTOR = "descriptor" | ||
|
||
class DescriptorUpdateFragment : Fragment() { | ||
|
||
private lateinit var binding: FragmentDescriptorUpdateBinding | ||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
binding = FragmentDescriptorUpdateBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
arguments?.takeIf { it.containsKey(DESCRIPTOR) }?.apply { | ||
val descriptor: TestDescriptor = | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | ||
getSerializable(DESCRIPTOR, TestDescriptor::class.java)!! | ||
} else { | ||
getSerializable(DESCRIPTOR) as TestDescriptor | ||
} | ||
val absDescriptor = InstalledDescriptor(descriptor) | ||
binding.apply { | ||
title.text = absDescriptor.title | ||
description.text = absDescriptor.description // Use markdown | ||
icon.setImageResource(absDescriptor.getDisplayIcon(requireContext())) | ||
} | ||
} | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
app/src/main/res/layout/activity_review_descriptor_updates.xml
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,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.coordinatorlayout.widget.CoordinatorLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".activity.reviewdescriptorupdates.ReviewDescriptorUpdatesActivity"> | ||
|
||
<com.google.android.material.appbar.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:elevation="0dp"> | ||
|
||
<androidx.appcompat.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:background="@color/color_gray0" | ||
app:menu="@menu/close" /> | ||
</com.google.android.material.appbar.AppBarLayout> | ||
|
||
<androidx.viewpager2.widget.ViewPager2 | ||
android:id="@+id/viewpager" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_marginTop="?android:attr/actionBarSize" | ||
android:layout_marginBottom="?android:attr/actionBarSize"/> | ||
|
||
|
||
<com.google.android.material.appbar.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom" | ||
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar"> | ||
|
||
<androidx.appcompat.widget.Toolbar | ||
android:id="@+id/bottomBar" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@color/color_gray0" | ||
app:menu="@menu/update_descriptor" | ||
app:titleTextAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title.App" /> | ||
</com.google.android.material.appbar.AppBarLayout> | ||
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
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,82 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingStart="16dp" | ||
android:paddingEnd="16dp" | ||
tools:context=".activity.reviewdescriptorupdates.DescriptorUpdateFragment"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<ImageView | ||
android:id="@+id/icon" | ||
android:layout_width="24dp" | ||
android:layout_height="24dp" | ||
android:layout_marginTop="16dp" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:src="@drawable/settings_icon" /> | ||
|
||
<TextView | ||
android:id="@+id/title" | ||
style="?attr/textAppearanceHeadline5" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="10dp" | ||
android:ellipsize="end" | ||
android:singleLine="true" | ||
android:textFontWeight="600" | ||
app:layout_constraintStart_toEndOf="@id/icon" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:text="@string/Test_Websites_Fullname" /> | ||
|
||
<View | ||
android:id="@+id/divider" | ||
android:layout_width="match_parent" | ||
android:layout_height="8dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/icon" /> | ||
|
||
<TextView | ||
android:id="@+id/author" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/divider" | ||
tools:text="Autho" /> | ||
|
||
<TextView | ||
android:id="@+id/description" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingVertical="8dp" | ||
android:textColor="@color/color_gray6" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/author" | ||
tools:text="lore ipsum" /> | ||
|
||
<TextView | ||
android:id="@+id/tests_llabel" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Tests" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/description" /> | ||
|
||
<org.openobservatory.ooniprobe.common.views.CustomExpandableListView | ||
android:id="@+id/expandable_list_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:groupIndicator="@null" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/tests_llabel" | ||
tools:listitem="@layout/nettest_group_list_item" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</androidx.core.widget.NestedScrollView> |
Oops, something went wrong.