Skip to content

Commit

Permalink
feat (OONI Run v2): Add support for updated badge
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed May 8, 2024
1 parent 13ddead commit 04c7c8c
Show file tree
Hide file tree
Showing 14 changed files with 281 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.android.material.snackbar.Snackbar;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.activity.reviewdescriptorupdates.AvailableUpdatesViewModel;
import org.openobservatory.ooniprobe.activity.reviewdescriptorupdates.ReviewDescriptorUpdatesActivity;
import org.openobservatory.ooniprobe.common.Application;
import org.openobservatory.ooniprobe.common.NotificationUtility;
Expand Down Expand Up @@ -75,6 +76,9 @@ public class MainActivity extends ReviewUpdatesAbstractActivity implements Confi
@Inject
TestDescriptorManager descriptorManager;

@Inject
AvailableUpdatesViewModel updatesViewModel;

private ActivityResultLauncher<String> requestPermissionLauncher;

public static Intent newIntent(Context context, int resItem) {
Expand Down Expand Up @@ -213,7 +217,7 @@ public void fetchManualUpdate() {
*/
private void onManualUpdatesFetchComplete(WorkInfo workInfo) {
if (workInfo != null) {
if (workInfo.getProgress().getInt(PROGRESS,-1) >= 0) {
if (workInfo.getProgress().getInt(PROGRESS, -1) >= 0) {
binding.reviewUpdateNotificationFragment.setVisibility(View.VISIBLE);
}
switch (workInfo.getState()) {
Expand All @@ -224,29 +228,32 @@ private void onManualUpdatesFetchComplete(WorkInfo workInfo) {
return;
}
getSupportFragmentManager()
.beginTransaction()
.add(
R.id.review_update_notification_fragment,
OONIRunDynamicProgressBar.newInstance(ProgressType.REVIEW_LINK, new OnActionListener() {
@Override
public void onActionButtonCLicked() {

getReviewUpdatesLauncher().launch(
ReviewDescriptorUpdatesActivity.newIntent(
MainActivity.this,
descriptor
)
);
removeProgressFragment(R.id.review_update_notification_fragment);
}

@Override
public void onCloseButtonClicked() {
removeProgressFragment(R.id.review_update_notification_fragment);
}
}),
OONIRunDynamicProgressBar.getTAG() + "_review_update_success_notification"
).commit();
.beginTransaction()
.add(
R.id.review_update_notification_fragment,
OONIRunDynamicProgressBar.newInstance(ProgressType.REVIEW_LINK, new OnActionListener() {
@Override
public void onActionButtonCLicked() {

getReviewUpdatesLauncher().launch(
ReviewDescriptorUpdatesActivity.newIntent(
MainActivity.this,
descriptor,
true
)
);
removeProgressFragment(R.id.review_update_notification_fragment);
}

@Override
public void onCloseButtonClicked() {
updatesViewModel.setDescriptorsWith(descriptor);
//TODO: Add a method to reload the list of descriptors.
removeProgressFragment(R.id.review_update_notification_fragment);
}
}),
OONIRunDynamicProgressBar.getTAG() + "_review_update_success_notification"
).commit();
}

case ENQUEUED -> getSupportFragmentManager()
Expand Down Expand Up @@ -321,11 +328,11 @@ protected void onNewIntent(Intent intent) {
binding.bottomNavigation.setSelectedItemId(intent.getIntExtra(RES_ITEM, R.id.dashboard));
} else if (intent.getExtras().containsKey(NOTIFICATION_DIALOG)) {
new ConfirmDialogFragment.Builder()
.withTitle(intent.getExtras().getString("title"))
.withMessage(intent.getExtras().getString("message"))
.withNegativeButton("")
.withPositiveButton(getString(R.string.Modal_OK))
.build().show(getSupportFragmentManager(), null);
.withTitle(intent.getExtras().getString("title"))
.withMessage(intent.getExtras().getString("message"))
.withNegativeButton("")
.withPositiveButton(getString(R.string.Modal_OK))
.build().show(getSupportFragmentManager(), null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.openobservatory.ooniprobe.activity.overview.OverviewTestsExpandableListViewAdapter;
import org.openobservatory.ooniprobe.activity.overview.OverviewViewModel;
import org.openobservatory.ooniprobe.activity.overview.RevisionsFragment;
import org.openobservatory.ooniprobe.activity.reviewdescriptorupdates.AvailableUpdatesViewModel;
import org.openobservatory.ooniprobe.activity.reviewdescriptorupdates.ReviewDescriptorUpdatesActivity;
import org.openobservatory.ooniprobe.common.AbstractDescriptor;
import org.openobservatory.ooniprobe.common.OONITests;
Expand Down Expand Up @@ -67,6 +68,10 @@ public class OverviewActivity extends ReviewUpdatesAbstractActivity implements C
@Inject
OverviewViewModel viewModel;


@Inject
AvailableUpdatesViewModel updatesViewModel;

OverviewTestsExpandableListViewAdapter adapter;

private AbstractDescriptor<BaseNettest> descriptor;
Expand Down Expand Up @@ -112,6 +117,22 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
if (Boolean.TRUE.equals(testDescriptor.isExpired())) {
binding.expiredTag.getRoot().setVisibility(View.VISIBLE);
}

InstalledDescriptor installedDescriptor = ((InstalledDescriptor) descriptor);
if (installedDescriptor.isUpdateAvailable()) {
binding.updatedTag.getRoot().setVisibility(View.VISIBLE);


binding.reviewUpdates.setVisibility(View.VISIBLE);
binding.reviewUpdates.setOnClickListener(view -> getReviewUpdatesLauncher().launch(
ReviewDescriptorUpdatesActivity.newIntent(
OverviewActivity.this,
updatesViewModel.getUpdatedDescriptor(testDescriptor.getRunId())
)
));


}
} else {
markwon.setMarkdown(binding.desc, descriptor.getDescription());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ class AddDescriptorActivity : AbstractActivity() {
StringUtils.camelToSnake(
iconName
), "drawable", imageView.context.packageName
)
).let {
if (it == 0) R.drawable.ooni_empty_state else it
}
).apply {
color?.let {
imageView.setColorFilter(it)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.openobservatory.ooniprobe.activity.reviewdescriptorupdates

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.google.gson.Gson
import org.openobservatory.ooniprobe.model.database.ITestDescriptor
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class AvailableUpdatesViewModel @Inject() constructor(var gson: Gson) : ViewModel() {
var descriptors: MutableLiveData<List<ITestDescriptor>> = MutableLiveData()
var descriptorString: MutableLiveData<String> = MutableLiveData()

fun setDescriptorsWith(descriptorJson: String) {
descriptorString.value = descriptorJson
descriptors.value = gson.fromJson(descriptorJson, Array<ITestDescriptor>::class.java).toList()
}

fun getUpdatedDescriptor(runId: Long): String {
return gson.toJson(arrayOf(descriptors.value?.find { it.runId == runId }))
}
}
Loading

0 comments on commit 04c7c8c

Please sign in to comment.