Skip to content

Commit

Permalink
Revert "[New Designs] Implement Dashboard Link update loading and Rev…
Browse files Browse the repository at this point in the history
…iew Updates" (#701)

Reverts #655
  • Loading branch information
aanorbel authored Mar 21, 2024
1 parent 09613d9 commit 902dfbf
Show file tree
Hide file tree
Showing 29 changed files with 352 additions and 1,445 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ dependencies {
implementation libs.androidx.preference
implementation libs.androidx.localbroadcastmanager
implementation libs.androidx.legacy.support.v4
implementation libs.androidx.work.runtime

// Google
implementation libs.google.material
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@
android:exported="false"
android:parentActivityName=".activity.MainActivity"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar" />
<activity
android:name=".activity.reviewdescriptorupdates.ReviewDescriptorUpdatesActivity"
android:exported="false"
android:parentActivityName=".activity.MainActivity"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar" />
<activity
android:name=".activity.OnboardingActivity"
android:screenOrientation="userPortrait"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.openobservatory.ooniprobe.activity;

import android.view.View;

import androidx.annotation.IdRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.google.gson.Gson;

Expand Down Expand Up @@ -46,17 +42,4 @@ public void bindTestService() {
}
}


/**
* Remove the progress fragment.
* <p>
* This method is called when the task is completed.
*/
protected void removeProgressFragment(@IdRes int id) {
Fragment fragment = getSupportFragmentManager().findFragmentById(id);
if (fragment != null && fragment.isAdded()) {
getSupportFragmentManager().beginTransaction().remove(fragment).commit();
}
findViewById(id).setVisibility(View.GONE);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.openobservatory.ooniprobe.activity;

import static org.openobservatory.ooniprobe.common.service.RunTestService.CHANNEL_ID;
import static org.openobservatory.ooniprobe.common.worker.UpdateDescriptorsWorkerKt.PROGRESS;

import android.Manifest;
import android.content.Context;
Expand All @@ -13,51 +12,34 @@
import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;
import android.view.View;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.ContextCompat;
import androidx.work.Constraints;
import androidx.work.ExistingPeriodicWorkPolicy;
import androidx.work.ExistingWorkPolicy;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkInfo;
import androidx.work.WorkManager;

import com.google.android.material.snackbar.Snackbar;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.activity.reviewdescriptorupdates.ReviewDescriptorUpdatesActivity;
import org.openobservatory.ooniprobe.common.Application;
import org.openobservatory.ooniprobe.common.NotificationUtility;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.TestDescriptorManager;
import org.openobservatory.ooniprobe.common.ThirdPartyServices;
import org.openobservatory.ooniprobe.common.service.ServiceUtil;
import org.openobservatory.ooniprobe.common.worker.AutoUpdateDescriptorsWorker;
import org.openobservatory.ooniprobe.common.worker.ManualUpdateDescriptorsWorker;
import org.openobservatory.ooniprobe.databinding.ActivityMainBinding;
import org.openobservatory.ooniprobe.domain.UpdatesNotificationManager;
import org.openobservatory.ooniprobe.fragment.DashboardFragment;
import org.openobservatory.ooniprobe.fragment.PreferenceGlobalFragment;
import org.openobservatory.ooniprobe.fragment.ResultListFragment;
import org.openobservatory.ooniprobe.fragment.dynamicprogressbar.OONIRunDynamicProgressBar;
import org.openobservatory.ooniprobe.fragment.dynamicprogressbar.OnActionListener;
import org.openobservatory.ooniprobe.fragment.dynamicprogressbar.ProgressType;

import java.io.Serializable;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import localhost.toolkit.app.fragment.ConfirmDialogFragment;

public class MainActivity extends ReviewUpdatesAbstractActivity implements ConfirmDialogFragment.OnConfirmedListener {
public class MainActivity extends AbstractActivity implements ConfirmDialogFragment.OnConfirmedListener {
private static final String RES_ITEM = "resItem";
private static final String RES_SNACKBAR_MESSAGE = "resSnackbarMessage";
public static final String NOTIFICATION_DIALOG = "notification";
Expand All @@ -72,9 +54,6 @@ public class MainActivity extends ReviewUpdatesAbstractActivity implements Confi
@Inject
PreferenceManager preferenceManager;

@Inject
TestDescriptorManager descriptorManager;

private ActivityResultLauncher<String> requestPermissionLauncher;

public static Intent newIntent(Context context, int resItem) {
Expand Down Expand Up @@ -158,115 +137,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
}
requestNotificationPermission();
scheduleWorkers();
onNewIntent(getIntent());
}

private void scheduleWorkers() {
WorkManager.getInstance(this)
.enqueueUniquePeriodicWork(
AutoUpdateDescriptorsWorker.UPDATED_DESCRIPTORS_WORK_NAME,
ExistingPeriodicWorkPolicy.KEEP,
new PeriodicWorkRequest.Builder(AutoUpdateDescriptorsWorker.class, 24, TimeUnit.HOURS)
.setConstraints(
new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
).build()
);
// TODO(aanorbel): add rules before checking updates
fetchManualUpdate();
registerReviewLauncher(binding.bottomNavigation, () -> null);
}

public void fetchManualUpdate() {
OneTimeWorkRequest manualWorkRequest = new OneTimeWorkRequest.Builder(ManualUpdateDescriptorsWorker.class)
.setConstraints(
new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
).build();

WorkManager.getInstance(this)
.beginUniqueWork(
ManualUpdateDescriptorsWorker.UPDATED_DESCRIPTORS_WORK_NAME,
ExistingWorkPolicy.REPLACE,
manualWorkRequest
).enqueue();

WorkManager.getInstance(this)
.getWorkInfoByIdLiveData(manualWorkRequest.getId())
.observe(this, this::onManualUpdatesFetchComplete);
}


/**
* Listens to updates from the {@link ManualUpdateDescriptorsWorker}.
* <p>
* This method is called after the {@link ManualUpdateDescriptorsWorker} is enqueued.
* The {@link ManualUpdateDescriptorsWorker} task is to fetch updates for the descriptors.
* <p>
* If the task is successful, the {@link WorkInfo} object will contain the updated descriptors.
* Otherwise, the {@link WorkInfo} object will be null.
*
* @param workInfo The {@link WorkInfo} of the task.
*/
private void onManualUpdatesFetchComplete(WorkInfo workInfo) {
if (workInfo != null) {
if (workInfo.getProgress().getInt(PROGRESS,-1) >= 0) {
binding.reviewUpdateNotificationFragment.setVisibility(View.VISIBLE);
}
switch (workInfo.getState()) {
case SUCCEEDED -> {
String descriptor = workInfo.getOutputData().getString(ManualUpdateDescriptorsWorker.KEY_UPDATED_DESCRIPTORS);
if (descriptor == null) {
removeProgressFragment(R.id.review_update_notification_fragment);
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();
}

case ENQUEUED -> getSupportFragmentManager()
.beginTransaction()
.add(
R.id.review_update_notification_fragment,
OONIRunDynamicProgressBar.newInstance(ProgressType.UPDATE_LINK, null),
OONIRunDynamicProgressBar.getTAG() + "_review_update_enqueued_notification"
).commit();

case FAILED -> Snackbar.make(
binding.getRoot(),
R.string.Modal_Error,
Snackbar.LENGTH_LONG
).setAnchorView(binding.bottomNavigation).show();

default -> {
}
}
}
}

private void requestNotificationPermission() {
Expand Down Expand Up @@ -321,11 +191,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 @@ -16,28 +16,18 @@
import androidx.annotation.Nullable;
import androidx.core.text.TextUtilsCompat;
import androidx.core.view.ViewCompat;
import androidx.work.Constraints;
import androidx.work.Data;
import androidx.work.ExistingWorkPolicy;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkInfo;
import androidx.work.WorkManager;

import com.google.android.material.checkbox.MaterialCheckBox;
import com.google.android.material.snackbar.Snackbar;

import org.openobservatory.engine.BaseNettest;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.activity.customwebsites.CustomWebsiteActivity;
import org.openobservatory.ooniprobe.activity.overview.OverviewTestsExpandableListViewAdapter;
import org.openobservatory.ooniprobe.activity.overview.OverviewViewModel;
import org.openobservatory.ooniprobe.activity.reviewdescriptorupdates.ReviewDescriptorUpdatesActivity;
import org.openobservatory.ooniprobe.common.AbstractDescriptor;
import org.openobservatory.ooniprobe.common.OONITests;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ReadMorePlugin;
import org.openobservatory.ooniprobe.common.worker.ManualUpdateDescriptorsWorker;
import org.openobservatory.ooniprobe.databinding.ActivityOverviewBinding;
import org.openobservatory.ooniprobe.model.database.InstalledDescriptor;
import org.openobservatory.ooniprobe.model.database.Result;
Expand All @@ -51,7 +41,7 @@

import io.noties.markwon.Markwon;

public class OverviewActivity extends ReviewUpdatesAbstractActivity {
public class OverviewActivity extends AbstractActivity {
private static final String TEST = "test";

ActivityOverviewBinding binding;
Expand Down Expand Up @@ -165,10 +155,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}

setUpOnCLickListeners();
registerReviewLauncher(binding.getRoot(), () -> {
binding.reviewUpdates.setVisibility(View.GONE);
return null;
});
}

private void selectAllBtnStatusObserver(String selectAllBtnStatus) {
Expand Down Expand Up @@ -200,74 +186,6 @@ private void setUpOnCLickListeners() {
binding.customUrl.setOnClickListener(view -> customUrlClick());
binding.uninstallLink.setOnClickListener(view -> viewModel.uninstallLinkClicked(this, (InstalledDescriptor) descriptor));
binding.automaticUpdatesSwitch.setOnCheckedChangeListener((compoundButton, isChecked) -> viewModel.automaticUpdatesSwitchClicked(isChecked));
if (descriptor instanceof InstalledDescriptor) {
binding.swipeRefresh.setOnRefreshListener(() -> {
Data.Builder data = new Data.Builder();
data.putLongArray(ManualUpdateDescriptorsWorker.KEY_DESCRIPTOR_IDS, new long[]{Objects.requireNonNull(descriptor.getDescriptor()).getRunId()});
OneTimeWorkRequest manualWorkRequest = new OneTimeWorkRequest.Builder(ManualUpdateDescriptorsWorker.class)
.setConstraints(
new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
).setInputData(data.build())
.build();

WorkManager.getInstance(this)
.beginUniqueWork(
ManualUpdateDescriptorsWorker.UPDATED_DESCRIPTORS_WORK_NAME,
ExistingWorkPolicy.REPLACE,
manualWorkRequest
).enqueue();

WorkManager.getInstance(this)
.getWorkInfoByIdLiveData(manualWorkRequest.getId())
.observe(this, this::onManualUpdatesFetchComplete);

});
} else {
binding.swipeRefresh.setEnabled(false);
}
}


/**
* Listens to updates from the {@link ManualUpdateDescriptorsWorker}.
* <p>
* This method is called after the {@link ManualUpdateDescriptorsWorker} is enqueued.
* The {@link ManualUpdateDescriptorsWorker} task is to fetch updates for the descriptors.
* <p>
* If the task is successful, the {@link WorkInfo} object will contain the updated descriptors.
* Otherwise, the {@link WorkInfo} object will be null.
*
* @param workInfo The {@link WorkInfo} of the task.
*/
private void onManualUpdatesFetchComplete(WorkInfo workInfo) {
if (workInfo != null) {
switch (workInfo.getState()) {
case SUCCEEDED -> {
binding.reviewUpdates.setVisibility(View.VISIBLE);
binding.reviewUpdates.setOnClickListener(view -> getReviewUpdatesLauncher().launch(
ReviewDescriptorUpdatesActivity.newIntent(
OverviewActivity.this,
workInfo.getOutputData().getString(ManualUpdateDescriptorsWorker.KEY_UPDATED_DESCRIPTORS)
)
));
binding.swipeRefresh.setRefreshing(false);
}

case FAILED -> {
binding.swipeRefresh.setRefreshing(false);
Snackbar.make(
binding.getRoot(),
R.string.Modal_Error,
Snackbar.LENGTH_LONG
).show();
}

default -> {
}
}
}
}

@Override
Expand Down
Loading

0 comments on commit 902dfbf

Please sign in to comment.