Skip to content

Commit

Permalink
- Changed theme for OverviewActivity, ResultDetailActivity, `Meas…
Browse files Browse the repository at this point in the history
…urementDetailActivity`

- Customize xml with new attributes for color and animation
  • Loading branch information
aanorbel committed Aug 18, 2023
1 parent 6f85191 commit 7ab812a
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 89 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@
android:name=".activity.OverviewActivity"
android:launchMode="singleTop"
android:parentActivityName=".activity.MainActivity"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar"
android:screenOrientation="userPortrait" />
<activity
android:name=".activity.ResultDetailActivity"
android:launchMode="singleTop"
android:parentActivityName=".activity.MainActivity"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar"
android:screenOrientation="userPortrait" />
<activity
android:name=".activity.MeasurementDetailActivity"
android:launchMode="singleTop"
android:parentActivityName=".activity.ResultDetailActivity"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar"
android:screenOrientation="userPortrait" />
<activity
android:name=".activity.TextActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.Window;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;

import com.google.android.material.snackbar.Snackbar;
Expand All @@ -23,6 +21,7 @@
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ResubmitTask;
import org.openobservatory.ooniprobe.databinding.ActivityMeasurementDetailBinding;
import org.openobservatory.ooniprobe.domain.GetTestSuite;
import org.openobservatory.ooniprobe.domain.MeasurementsManager;
import org.openobservatory.ooniprobe.domain.callback.DomainCallback;
Expand All @@ -44,6 +43,7 @@
import org.openobservatory.ooniprobe.fragment.resultHeader.ResultHeaderDetailFragment;
import org.openobservatory.ooniprobe.model.database.Measurement;
import org.openobservatory.ooniprobe.model.database.Network;
import org.openobservatory.ooniprobe.test.suite.OONIRunSuite;
import org.openobservatory.ooniprobe.test.suite.PerformanceSuite;
import org.openobservatory.ooniprobe.test.test.Dash;
import org.openobservatory.ooniprobe.test.test.FacebookMessenger;
Expand All @@ -64,31 +64,19 @@

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import localhost.toolkit.app.fragment.ConfirmDialogFragment;
import ru.noties.markwon.Markwon;

public class MeasurementDetailActivity extends AbstractActivity implements ConfirmDialogFragment.OnConfirmedListener {
private static final String ID = "id";
private static final String RERUN_KEY = "rerun";

@BindView(R.id.coordinatorLayout)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.toolbar)
Toolbar toolbar;

private ActivityMeasurementDetailBinding binding;

private Measurement measurement;
private Snackbar snackbar;
private Boolean isInExplorer;
@BindView(R.id.log)
Button log;
@BindView(R.id.explorer)
Button explorer;
@BindView(R.id.data)
Button data;
@BindView(R.id.methodology)
TextView methodology;

@Inject
MeasurementsManager measurementsManager;
Expand All @@ -103,32 +91,50 @@ public class MeasurementDetailActivity extends AbstractActivity implements Confi
PreferenceManager preferenceManager;


public static Intent newIntent(Context context, int id) {
public static Intent newIntent(Context context, int id) {
return new Intent(context, MeasurementDetailActivity.class).putExtra(ID, id);
}

public void setThemeColor(int color) {
Window window = getWindow();
window.setStatusBarColor(color);
binding.appbarLayout.setBackgroundColor(color);
binding.appbarLayout.setBackgroundColor(color);
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivityComponent().inject(this);
measurement = measurementsManager.get(getIntent().getIntExtra(ID, 0));
assert measurement != null;
measurement.result.load();
setTheme(measurement.is_failed ?
R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Failed :
measurement.result.test_group_name.equals(PerformanceSuite.NAME) ?
measurement.result.getTestSuite().getThemeLight() :
measurement.is_anomaly ?
R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Failure :
R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Success);
setContentView(R.layout.activity_measurement_detail);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
if (measurement.is_failed) {
setTheme(R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Failed);
} else {
if (!measurement.result.test_group_name.equals(PerformanceSuite.NAME)) {
if (measurement.is_anomaly) {
setTheme(R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Failure);
} else {
setTheme(R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Success);
}
}
}
binding = ActivityMeasurementDetailBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);

// TODO(aanorbel) Handle performance suite
if (measurement.result.test_group_name.equals(OONIRunSuite.NAME)) {
setThemeColor(((OONIRunSuite)measurement.result.getTestSuite()).getDescriptor().getParsedColor());
}

ActionBar bar = getSupportActionBar();
if (bar != null) {
bar.setDisplayHomeAsUpEnabled(true);
bar.setTitle(measurement.getTest().getLabelResId());
}
setUpClickListeners();
Fragment detail = null;
Fragment head = null;
if (measurement.is_failed) {
Expand Down Expand Up @@ -237,7 +243,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
.replace(R.id.body, detail)
.replace(R.id.head, head)
.commit();
snackbar = Snackbar.make(coordinatorLayout, R.string.Snackbar_ResultsNotUploaded_Text, Snackbar.LENGTH_INDEFINITE)
snackbar = Snackbar.make(binding.coordinatorLayout, R.string.Snackbar_ResultsNotUploaded_Text, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.Snackbar_ResultsNotUploaded_Upload, v1 -> runAsyncTask());
Context c = this;
isInExplorer = !measurement.hasReportFile(c);
Expand All @@ -255,14 +261,20 @@ public void onError(String msg) {
});

if (!measurement.hasLogFile(this))
log.setVisibility(View.GONE);
binding.log.setVisibility(View.GONE);
if (!measurementsManager.hasReportId(measurement))
explorer.setVisibility(View.GONE);
Markwon.setMarkdown(methodology, getString(R.string.TestResults_Details_Methodology_Paragraph, getString(measurement.getTest().getUrlResId())));
binding.explorer.setVisibility(View.GONE);
Markwon.setMarkdown(binding.methodology, getString(R.string.TestResults_Details_Methodology_Paragraph, getString(measurement.getTest().getUrlResId())));
load();
}

private void runAsyncTask() {
private void setUpClickListeners() {
binding.log.setOnClickListener((view) -> logClick());
binding.data.setOnClickListener((view) -> dataClick());
binding.explorer.setOnClickListener((view) -> explorerClick());
}

private void runAsyncTask() {
new ResubmitAsyncTask(this, pm.getProxyURL()).execute(null, measurement.id);
}

Expand Down Expand Up @@ -305,17 +317,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

@OnClick(R.id.log)
void logClick() {
startActivity(TextActivity.newIntent(this, TextActivity.TYPE_LOG, measurement));
}

@OnClick(R.id.data)
void dataClick() {
startActivity(TextActivity.newIntent(this, TextActivity.TYPE_JSON, measurement));
}

@OnClick(R.id.explorer)
void explorerClick() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(measurementsManager.getExplorerUrl(measurement))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.core.text.TextUtilsCompat;
import androidx.core.view.ViewCompat;
import androidx.databinding.BindingAdapter;
import androidx.lifecycle.ViewModelProvider;

import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar;
Expand All @@ -28,7 +29,6 @@
import org.openobservatory.ooniprobe.test.suite.AbstractSuite;
import org.openobservatory.ooniprobe.test.suite.ExperimentalSuite;
import org.openobservatory.ooniprobe.test.suite.OONIRunSuite;
import org.openobservatory.ooniprobe.test.test.AbstractTest;

import java.util.Locale;
import java.util.Objects;
Expand Down Expand Up @@ -57,7 +57,6 @@ public static Intent newIntent(Context context, AbstractSuite testSuite) {
super.onCreate(savedInstanceState);
getActivityComponent().inject(this);
testSuite = (AbstractSuite) getIntent().getSerializableExtra(TEST);
setTheme(testSuite.getThemeLight());
binding = ActivityOverviewBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
Expand All @@ -71,13 +70,21 @@ public static Intent newIntent(Context context, AbstractSuite testSuite) {
}

if (testSuite.getName().equals(OONIRunSuite.NAME)) {
setThemeColor(((OONIRunSuite)testSuite).getDescriptor().getParsedColor());
binding.swipeRefresh.setOnRefreshListener(this::initiateRefresh);
} else {
binding.swipeRefresh.setEnabled(false);
}
setUpOnCLickListeners();
}

public void setThemeColor(int color) {
Window window = getWindow();
window.setStatusBarColor(color);
binding.run.setTextColor(color);
binding.appbarLayout.setBackgroundColor(color);
}

private void onTestSuiteChanged() {
setTitle(testSuite.getTitle());
viewModel.onTestSuiteChanged(testSuite);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ResubmitTask;
import org.openobservatory.ooniprobe.databinding.ActivityResultDetailBinding;
import org.openobservatory.ooniprobe.domain.GetResults;
import org.openobservatory.ooniprobe.domain.GetTestSuite;
import org.openobservatory.ooniprobe.fragment.resultHeader.ResultHeaderDetailFragment;
Expand All @@ -43,6 +40,7 @@
import org.openobservatory.ooniprobe.test.suite.ExperimentalSuite;
import org.openobservatory.ooniprobe.test.suite.InstantMessagingSuite;
import org.openobservatory.ooniprobe.test.suite.MiddleBoxesSuite;
import org.openobservatory.ooniprobe.test.suite.OONIRunSuite;
import org.openobservatory.ooniprobe.test.suite.PerformanceSuite;
import org.openobservatory.ooniprobe.test.suite.WebsitesSuite;

Expand All @@ -52,8 +50,6 @@

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import localhost.toolkit.app.fragment.ConfirmDialogFragment;
import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerAdapter;
import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem;
Expand All @@ -62,17 +58,9 @@ public class ResultDetailActivity extends AbstractActivity implements View.OnCli
private static final String ID = "id";
private static final String UPLOAD_KEY = "upload";
private static final String RERUN_KEY = "rerun";
@BindView(R.id.coordinatorLayout)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.tabLayout)
TabLayout tabLayout;
@BindView(R.id.pager)
ViewPager2 pager;
@BindView(R.id.recyclerView)
RecyclerView recycler;
private ArrayList<HeterogeneousRecyclerItem> items;
private ActivityResultDetailBinding binding;

private ArrayList<HeterogeneousRecyclerItem> items;
private HeterogeneousRecyclerAdapter<HeterogeneousRecyclerItem> adapter;
private Result result;
private Snackbar snackbar;
Expand All @@ -86,38 +74,46 @@ public class ResultDetailActivity extends AbstractActivity implements View.OnCli
@Inject
PreferenceManager preferenceManager;

public static Intent newIntent(Context context, int id) {
public static Intent newIntent(Context context, int id) {
return new Intent(context, ResultDetailActivity.class).putExtra(ID, id);
}
public void setThemeColor(int color) {
Window window = getWindow();
window.setStatusBarColor(color);
binding.appbarLayout.setBackgroundColor(color);
binding.tabLayout.setBackgroundColor(color);
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivityComponent().inject(this);
result = getResults.get(getIntent().getIntExtra(ID, 0));
assert result != null;
setTheme(result.getTestSuite().getThemeLight());
setContentView(R.layout.activity_result_detail);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
binding = ActivityResultDetailBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
if (result.test_group_name.equals(OONIRunSuite.NAME)) {
setThemeColor(((OONIRunSuite)result.getTestSuite()).getDescriptor().getParsedColor());
}
ActionBar bar = getSupportActionBar();
if (bar != null) {
bar.setDisplayHomeAsUpEnabled(true);
bar.setTitle(result.getTestSuite().getTitle());
}
pager.setAdapter(new ResultHeaderAdapter(this));
new TabLayoutMediator(tabLayout, pager, (tab, position) ->
binding.pager.setAdapter(new ResultHeaderAdapter(this));
new TabLayoutMediator(binding.tabLayout, binding.pager, (tab, position) ->
tab.setText("●")
).attach();
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recycler.setLayoutManager(layoutManager);
recycler.addItemDecoration(new DividerItemDecoration(this, layoutManager.getOrientation()));
binding.recyclerView.setLayoutManager(layoutManager);
binding.recyclerView.addItemDecoration(new DividerItemDecoration(this, layoutManager.getOrientation()));
result.is_viewed = true;
result.save();
items = new ArrayList<>();
adapter = new HeterogeneousRecyclerAdapter<>(this, items);
recycler.setAdapter(adapter);
snackbar = Snackbar.make(coordinatorLayout, R.string.Snackbar_ResultsSomeNotUploaded_Text, Snackbar.LENGTH_INDEFINITE)
binding.recyclerView.setAdapter(adapter);
snackbar = Snackbar.make(binding.coordinatorLayout, R.string.Snackbar_ResultsSomeNotUploaded_Text, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.Snackbar_ResultsSomeNotUploaded_UploadAll, v1 -> runAsyncTask());
}

Expand Down
Loading

0 comments on commit 7ab812a

Please sign in to comment.