diff --git a/app/src/main/java/org/openobservatory/ooniprobe/fragment/DashboardFragment.java b/app/src/main/java/org/openobservatory/ooniprobe/fragment/DashboardFragment.java index 0ebeb4d8d..7eee1ca50 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/fragment/DashboardFragment.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/fragment/DashboardFragment.java @@ -1,31 +1,27 @@ package org.openobservatory.ooniprobe.fragment; -import android.content.Intent; import android.os.Bundle; import android.text.format.DateUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; import androidx.core.app.ActivityCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import org.openobservatory.ooniprobe.R; import org.openobservatory.ooniprobe.activity.AbstractActivity; -import org.openobservatory.ooniprobe.activity.MainActivity; import org.openobservatory.ooniprobe.activity.OverviewActivity; import org.openobservatory.ooniprobe.activity.RunningActivity; import org.openobservatory.ooniprobe.common.Application; import org.openobservatory.ooniprobe.common.PreferenceManager; import org.openobservatory.ooniprobe.common.ReachabilityManager; import org.openobservatory.ooniprobe.common.ThirdPartyServices; +import org.openobservatory.ooniprobe.databinding.FragmentDashboardBinding; import org.openobservatory.ooniprobe.item.SeperatorItem; import org.openobservatory.ooniprobe.item.TestsuiteItem; import org.openobservatory.ooniprobe.model.database.Result; @@ -33,43 +29,38 @@ import org.openobservatory.ooniprobe.test.suite.AbstractSuite; import java.util.ArrayList; -import java.util.Objects; import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerAdapter; import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; public class DashboardFragment extends Fragment implements View.OnClickListener { - @BindView(R.id.recycler) RecyclerView recycler; - @BindView(R.id.toolbar) Toolbar toolbar; - @BindView(R.id.last_tested) TextView lastTested; - @BindView(R.id.run_all) TextView runAll; - @BindView(R.id.vpn) TextView vpn; @Inject PreferenceManager preferenceManager; private ArrayList items; + private ArrayList testSuites; + private HeterogeneousRecyclerAdapter adapter; + private FragmentDashboardBinding binding; + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_dashboard, container, false); - ButterKnife.bind(this, v); + binding = FragmentDashboardBinding.inflate(inflater,container,false); ((Application) getActivity().getApplication()).getFragmentComponent().inject(this); - ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); + ((AppCompatActivity) getActivity()).setSupportActionBar(binding.toolbar); ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(null); items = new ArrayList<>(); testSuites = new ArrayList<>(); adapter = new HeterogeneousRecyclerAdapter<>(getActivity(), items); - recycler.setAdapter(adapter); - recycler.setLayoutManager(new LinearLayoutManager(getActivity())); - runAll.setOnClickListener(v1 -> runAll()); - vpn.setOnClickListener(view -> ((Application) getActivity().getApplication()).openVPNSettings()); - return v; + binding.recycler.setAdapter(adapter); + binding.recycler.setLayoutManager(new LinearLayoutManager(getActivity())); + binding.runAll.setOnClickListener(v1 -> runAll()); + binding.vpn.setOnClickListener(view -> ((Application) getActivity().getApplication()).openVPNSettings()); + return binding.getRoot(); } @Override public void onResume() { @@ -100,19 +91,19 @@ public class DashboardFragment extends Fragment implements View.OnClickListener adapter.notifyTypesChanged(); if (ReachabilityManager.isVPNinUse(this.getContext()) && preferenceManager.isWarnVPNInUse()) - vpn.setVisibility(View.VISIBLE); + binding.vpn.setVisibility(View.VISIBLE); else - vpn.setVisibility(View.GONE); + binding.vpn.setVisibility(View.GONE); } private void setLastTest() { Result lastResult = Result.getLastResult(); if (lastResult == null) - lastTested.setText(getString(R.string.Dashboard_Overview_LatestTest) + binding.lastTested.setText(getString(R.string.Dashboard_Overview_LatestTest) + " " + getString(R.string.Dashboard_Overview_LastRun_Never)); else - lastTested.setText(getString(R.string.Dashboard_Overview_LatestTest) + binding.lastTested.setText(getString(R.string.Dashboard_Overview_LatestTest) + " " + DateUtils.getRelativeTimeSpanString(lastResult.start_time.getTime())); }