Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Update OverviewActivity to ViewBinding #594

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.text.TextUtilsCompat;
import androidx.core.view.ViewCompat;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.databinding.ActivityOverviewBinding;
import org.openobservatory.ooniprobe.model.database.Result;
import org.openobservatory.ooniprobe.test.suite.AbstractSuite;
import org.openobservatory.ooniprobe.test.suite.ExperimentalSuite;
Expand All @@ -27,20 +23,12 @@

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import ru.noties.markwon.Markwon;

public class OverviewActivity extends AbstractActivity {
private static final String TEST = "test";
@BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.icon) ImageView icon;
@BindView(R.id.runtime) TextView runtime;
@BindView(R.id.lastTime) TextView lastTime;
@BindView(R.id.desc) TextView desc;
@BindView(R.id.customUrl) Button customUrl;
@BindView(R.id.run) Button run;

ActivityOverviewBinding binding;
private AbstractSuite testSuite;

@Inject
Expand All @@ -55,41 +43,48 @@ public static Intent newIntent(Context context, AbstractSuite testSuite) {
getActivityComponent().inject(this);
testSuite = (AbstractSuite) getIntent().getSerializableExtra(TEST);
setTheme(testSuite.getThemeLight());
setContentView(R.layout.activity_overview);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
binding = ActivityOverviewBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(testSuite.getTitle());
icon.setImageResource(testSuite.getIcon());
customUrl.setVisibility(testSuite.getName().equals(WebsitesSuite.NAME) ? View.VISIBLE : View.GONE);
binding.icon.setImageResource(testSuite.getIcon());
binding.customUrl.setVisibility(testSuite.getName().equals(WebsitesSuite.NAME) ? View.VISIBLE : View.GONE);
if(testSuite.isTestEmpty(preferenceManager)){
run.setAlpha(0.5F);
run.setEnabled(false);
binding.run.setAlpha(0.5F);
binding.run.setEnabled(false);
}
if (testSuite.getName().equals(ExperimentalSuite.NAME)) {
String experimentalLinks =
"\n\n* [STUN Reachability](https://github.com/ooni/spec/blob/master/nettests/ts-025-stun-reachability.md)" +
"\n\n* [DNS Check](https://github.com/ooni/spec/blob/master/nettests/ts-028-dnscheck.md)" +
"\n\n* [Tor Snowflake](https://ooni.org/nettest/tor-snowflake/) "+ String.format(" ( %s )",getString(R.string.Settings_TestOptions_LongRunningTest))+
"\n\n* [Vanilla Tor](https://github.com/ooni/spec/blob/master/nettests/ts-016-vanilla-tor.md) " + String.format(" ( %s )",getString(R.string.Settings_TestOptions_LongRunningTest));
Markwon.setMarkdown(desc, getString(testSuite.getDesc1(), experimentalLinks));
Markwon.setMarkdown(binding.desc, getString(testSuite.getDesc1(), experimentalLinks));
if (TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL)
desc.setTextDirection(View.TEXT_DIRECTION_RTL);
binding.desc.setTextDirection(View.TEXT_DIRECTION_RTL);
}
else
Markwon.setMarkdown(desc, getString(testSuite.getDesc1()));
Markwon.setMarkdown(binding.desc, getString(testSuite.getDesc1()));
Result lastResult = Result.getLastResult(testSuite.getName());
if (lastResult == null)
lastTime.setText(R.string.Dashboard_Overview_LastRun_Never);
binding.lastTime.setText(R.string.Dashboard_Overview_LastRun_Never);
else
lastTime.setText(DateUtils.getRelativeTimeSpanString(lastResult.start_time.getTime()));
binding.lastTime.setText(DateUtils.getRelativeTimeSpanString(lastResult.start_time.getTime()));

setUpOnCLickListeners();
}

private void setUpOnCLickListeners() {
binding.run.setOnClickListener(view -> onRunClick());
binding.customUrl.setOnClickListener(view -> customUrlClick());
}

@Override protected void onResume() {
super.onResume();
testSuite.setTestList((AbstractTest[]) null);
testSuite.getTestList(preferenceManager);
runtime.setText(getString(R.string.twoParam, getString(testSuite.getDataUsage()), getString(R.string.Dashboard_Card_Seconds, testSuite.getRuntime(preferenceManager).toString())));
binding.runtime.setText(getString(R.string.twoParam, getString(testSuite.getDataUsage()), getString(R.string.Dashboard_Card_Seconds, testSuite.getRuntime(preferenceManager).toString())));
}

@Override
Expand All @@ -98,13 +93,13 @@ public boolean onSupportNavigateUp() {
return true;
}

@OnClick(R.id.run) void onRunClick() {
void onRunClick() {
if(!testSuite.isTestEmpty(preferenceManager)){
RunningActivity.runAsForegroundService(this, testSuite.asArray(), this::bindTestService, preferenceManager);
}
}

@OnClick(R.id.customUrl) void customUrlClick() {
void customUrlClick() {
startActivity(new Intent(this, CustomWebsiteActivity.class));
}
}
Loading